1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/common/extensions/extension.h" 6 #include "chrome/common/extensions/extension_manifest_constants.h" 7 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" 8 #include "chrome/common/extensions/manifest_url_handler.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "ui/base/l10n/l10n_util.h" 11 12 namespace errors = extension_manifest_errors; 13 14 class HomepageURLManifestTest : public ExtensionManifestTest { 15 }; 16 17 TEST_F(HomepageURLManifestTest, ParseHomepageURLs) { 18 scoped_refptr<extensions::Extension> extension( 19 LoadAndExpectSuccess("homepage_valid.json")); 20 21 Testcase testcases[] = { 22 Testcase("homepage_empty.json", 23 errors::kInvalidHomepageURL), 24 Testcase("homepage_invalid.json", 25 errors::kInvalidHomepageURL), 26 Testcase("homepage_bad_schema.json", 27 errors::kInvalidHomepageURL) 28 }; 29 RunTestcases(testcases, arraysize(testcases), 30 EXPECT_TYPE_ERROR); 31 } 32 33 TEST_F(HomepageURLManifestTest, GetHomepageURL) { 34 scoped_refptr<extensions::Extension> extension( 35 LoadAndExpectSuccess("homepage_valid.json")); 36 EXPECT_EQ(GURL("http://foo.com#bar"), 37 extensions::ManifestURL::GetHomepageURL(extension.get())); 38 39 // The Google Gallery URL ends with the id, which depends on the path, which 40 // can be different in testing, so we just check the part before id. 41 extension = LoadAndExpectSuccess("homepage_google_hosted.json"); 42 EXPECT_TRUE(StartsWithASCII( 43 extensions::ManifestURL::GetHomepageURL(extension.get()).spec(), 44 "https://chrome.google.com/webstore/detail/", 45 false)); 46 47 extension = LoadAndExpectSuccess("homepage_externally_hosted.json"); 48 EXPECT_EQ(GURL(), extensions::ManifestURL::GetHomepageURL(extension.get())); 49 } 50