summaryrefslogtreecommitdiff
path: root/chromium/chrome/common/extensions/manifest_tests/extension_manifests_homepage_unittest.cc
blob: 7bc29b6b11d6e65eebaf2cff3aed4b8a83179d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_url_handlers.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace errors = extensions::manifest_errors;

class HomepageURLManifestTest : public ChromeManifestTest {
};

TEST_F(HomepageURLManifestTest, ParseHomepageURLs) {
  scoped_refptr<extensions::Extension> extension(
      LoadAndExpectSuccess("homepage_valid.json"));

  Testcase testcases[] = {
    Testcase("homepage_empty.json",
             errors::kInvalidHomepageURL),
    Testcase("homepage_invalid.json",
             errors::kInvalidHomepageURL),
    Testcase("homepage_bad_schema.json",
             errors::kInvalidHomepageURL)
  };
  RunTestcases(testcases, base::size(testcases), EXPECT_TYPE_ERROR);
}

TEST_F(HomepageURLManifestTest, GetHomepageURL) {
  scoped_refptr<extensions::Extension> extension(
      LoadAndExpectSuccess("homepage_valid.json"));
  EXPECT_EQ(GURL("http://foo.com#bar"),
            extensions::ManifestURL::GetHomepageURL(extension.get()));

  // The Google Gallery URL ends with the id, which depends on the path, which
  // can be different in testing, so we just check the part before id.
  extension = LoadAndExpectSuccess("homepage_google_hosted.json");
  EXPECT_TRUE(base::StartsWith(
      extensions::ManifestURL::GetHomepageURL(extension.get()).spec(),
      "https://chrome.google.com/webstore/detail/",
      base::CompareCase::INSENSITIVE_ASCII));

  extension = LoadAndExpectSuccess("homepage_externally_hosted.json");
  EXPECT_EQ(GURL(), extensions::ManifestURL::GetHomepageURL(extension.get()));
}