Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: chrome/common/extensions/extension_manifests_unittest.cc

Issue 7347011: Update URLPatternSet to contain a std::set instead of std::vector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile errors. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/extension_messages.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #if defined(TOOLKIT_GTK) 7 #if defined(TOOLKIT_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
(...skipping 12 matching lines...) Expand all
23 #include "chrome/common/extensions/extension.h" 23 #include "chrome/common/extensions/extension.h"
24 #include "chrome/common/extensions/extension_constants.h" 24 #include "chrome/common/extensions/extension_constants.h"
25 #include "chrome/common/extensions/extension_error_utils.h" 25 #include "chrome/common/extensions/extension_error_utils.h"
26 #include "chrome/common/extensions/extension_sidebar_defaults.h" 26 #include "chrome/common/extensions/extension_sidebar_defaults.h"
27 #include "chrome/common/extensions/file_browser_handler.h" 27 #include "chrome/common/extensions/file_browser_handler.h"
28 #include "chrome/common/extensions/url_pattern.h" 28 #include "chrome/common/extensions/url_pattern.h"
29 #include "content/common/json_value_serializer.h" 29 #include "content/common/json_value_serializer.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
32 32
33
34 namespace {
35
36 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
37 int schemes = URLPattern::SCHEME_ALL;
38 extent->AddPattern(URLPattern(schemes, pattern));
39 }
40
41 }
42
33 namespace errors = extension_manifest_errors; 43 namespace errors = extension_manifest_errors;
34 namespace keys = extension_manifest_keys; 44 namespace keys = extension_manifest_keys;
35 45
36 class ExtensionManifestTest : public testing::Test { 46 class ExtensionManifestTest : public testing::Test {
37 public: 47 public:
38 ExtensionManifestTest() : enable_apps_(true) {} 48 ExtensionManifestTest() : enable_apps_(true) {}
39 49
40 protected: 50 protected:
41 DictionaryValue* LoadManifestFile(const std::string& filename, 51 DictionaryValue* LoadManifestFile(const std::string& filename,
42 std::string* error) { 52 std::string* error) {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // backwards compatibility (we renamed it to "unlimitedStorage"). 305 // backwards compatibility (we renamed it to "unlimitedStorage").
296 TEST_F(ExtensionManifestTest, OldUnlimitedStoragePermission) { 306 TEST_F(ExtensionManifestTest, OldUnlimitedStoragePermission) {
297 scoped_refptr<Extension> extension = LoadStrictAndExpectSuccess( 307 scoped_refptr<Extension> extension = LoadStrictAndExpectSuccess(
298 "old_unlimited_storage.json"); 308 "old_unlimited_storage.json");
299 EXPECT_TRUE(extension->HasAPIPermission( 309 EXPECT_TRUE(extension->HasAPIPermission(
300 ExtensionAPIPermission::kUnlimitedStorage)); 310 ExtensionAPIPermission::kUnlimitedStorage));
301 } 311 }
302 312
303 TEST_F(ExtensionManifestTest, ValidApp) { 313 TEST_F(ExtensionManifestTest, ValidApp) {
304 scoped_refptr<Extension> extension(LoadAndExpectSuccess("valid_app.json")); 314 scoped_refptr<Extension> extension(LoadAndExpectSuccess("valid_app.json"));
305 ASSERT_EQ(2u, extension->web_extent().patterns().size()); 315 URLPatternSet expected_patterns;
306 EXPECT_EQ("http://www.google.com/mail/*", 316 AddPattern(&expected_patterns, "http://www.google.com/mail/*");
307 extension->web_extent().patterns()[0].GetAsString()); 317 AddPattern(&expected_patterns, "http://www.google.com/foobar/*");
308 EXPECT_EQ("http://www.google.com/foobar/*", 318 EXPECT_EQ(expected_patterns, extension->web_extent());
309 extension->web_extent().patterns()[1].GetAsString());
310 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); 319 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container());
311 EXPECT_EQ("http://www.google.com/mail/", extension->launch_web_url()); 320 EXPECT_EQ("http://www.google.com/mail/", extension->launch_web_url());
312 } 321 }
313 322
314 TEST_F(ExtensionManifestTest, AppWebUrls) { 323 TEST_F(ExtensionManifestTest, AppWebUrls) {
315 LoadAndExpectError("web_urls_wrong_type.json", 324 LoadAndExpectError("web_urls_wrong_type.json",
316 errors::kInvalidWebURLs); 325 errors::kInvalidWebURLs);
317 LoadAndExpectError( 326 LoadAndExpectError(
318 "web_urls_invalid_1.json", 327 "web_urls_invalid_1.json",
319 ExtensionErrorUtils::FormatErrorMessage( 328 ExtensionErrorUtils::FormatErrorMessage(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 ExtensionErrorUtils::FormatErrorMessage( 367 ExtensionErrorUtils::FormatErrorMessage(
359 errors::kInvalidWebURL, 368 errors::kInvalidWebURL,
360 base::IntToString(1), 369 base::IntToString(1),
361 URLPattern::GetParseResultString(URLPattern::PARSE_ERROR_HAS_COLON))); 370 URLPattern::GetParseResultString(URLPattern::PARSE_ERROR_HAS_COLON)));
362 371
363 372
364 scoped_refptr<Extension> extension( 373 scoped_refptr<Extension> extension(
365 LoadAndExpectSuccess("web_urls_default.json")); 374 LoadAndExpectSuccess("web_urls_default.json"));
366 ASSERT_EQ(1u, extension->web_extent().patterns().size()); 375 ASSERT_EQ(1u, extension->web_extent().patterns().size());
367 EXPECT_EQ("*://www.google.com/*", 376 EXPECT_EQ("*://www.google.com/*",
368 extension->web_extent().patterns()[0].GetAsString()); 377 extension->web_extent().patterns().begin()->GetAsString());
369 } 378 }
370 379
371 TEST_F(ExtensionManifestTest, AppLaunchContainer) { 380 TEST_F(ExtensionManifestTest, AppLaunchContainer) {
372 scoped_refptr<Extension> extension; 381 scoped_refptr<Extension> extension;
373 382
374 extension = LoadAndExpectSuccess("launch_tab.json"); 383 extension = LoadAndExpectSuccess("launch_tab.json");
375 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); 384 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container());
376 385
377 extension = LoadAndExpectSuccess("launch_panel.json"); 386 extension = LoadAndExpectSuccess("launch_panel.json");
378 EXPECT_EQ(extension_misc::LAUNCH_PANEL, extension->launch_container()); 387 EXPECT_EQ(extension_misc::LAUNCH_PANEL, extension->launch_container());
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 694
686 extension = LoadAndExpectSuccess("homepage_externally_hosted.json"); 695 extension = LoadAndExpectSuccess("homepage_externally_hosted.json");
687 EXPECT_EQ(GURL(), extension->GetHomepageURL()); 696 EXPECT_EQ(GURL(), extension->GetHomepageURL());
688 } 697 }
689 698
690 TEST_F(ExtensionManifestTest, DefaultPathForExtent) { 699 TEST_F(ExtensionManifestTest, DefaultPathForExtent) {
691 scoped_refptr<Extension> extension( 700 scoped_refptr<Extension> extension(
692 LoadAndExpectSuccess("default_path_for_extent.json")); 701 LoadAndExpectSuccess("default_path_for_extent.json"));
693 702
694 ASSERT_EQ(1u, extension->web_extent().patterns().size()); 703 ASSERT_EQ(1u, extension->web_extent().patterns().size());
695 EXPECT_EQ("/*", extension->web_extent().patterns()[0].path()); 704 EXPECT_EQ("/*", extension->web_extent().patterns().begin()->path());
696 EXPECT_TRUE(extension->web_extent().MatchesURL( 705 EXPECT_TRUE(extension->web_extent().MatchesURL(
697 GURL("http://www.google.com/monkey"))); 706 GURL("http://www.google.com/monkey")));
698 } 707 }
699 708
700 TEST_F(ExtensionManifestTest, DefaultLocale) { 709 TEST_F(ExtensionManifestTest, DefaultLocale) {
701 LoadAndExpectError("default_locale_invalid.json", 710 LoadAndExpectError("default_locale_invalid.json",
702 extension_manifest_errors::kInvalidDefaultLocale); 711 extension_manifest_errors::kInvalidDefaultLocale);
703 712
704 scoped_refptr<Extension> extension( 713 scoped_refptr<Extension> extension(
705 LoadAndExpectSuccess("default_locale_valid.json")); 714 LoadAndExpectSuccess("default_locale_valid.json"));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 "http:*.html")); 792 "http:*.html"));
784 793
785 scoped_refptr<Extension> extension( 794 scoped_refptr<Extension> extension(
786 LoadAndExpectSuccess("filebrowser_valid.json")); 795 LoadAndExpectSuccess("filebrowser_valid.json"));
787 ASSERT_TRUE(extension->file_browser_handlers() != NULL); 796 ASSERT_TRUE(extension->file_browser_handlers() != NULL);
788 ASSERT_EQ(extension->file_browser_handlers()->size(), 1U); 797 ASSERT_EQ(extension->file_browser_handlers()->size(), 1U);
789 const FileBrowserHandler* action = 798 const FileBrowserHandler* action =
790 extension->file_browser_handlers()->at(0).get(); 799 extension->file_browser_handlers()->at(0).get();
791 EXPECT_EQ(action->title(), "Default title"); 800 EXPECT_EQ(action->title(), "Default title");
792 EXPECT_EQ(action->icon_path(), "icon.png"); 801 EXPECT_EQ(action->icon_path(), "icon.png");
793 const URLPatternList& patterns = action->file_url_patterns(); 802 const URLPatternSet& patterns = action->file_url_patterns();
794 ASSERT_EQ(patterns.size(), 1U); 803 ASSERT_EQ(patterns.patterns().size(), 1U);
795 ASSERT_TRUE(action->MatchesURL( 804 ASSERT_TRUE(action->MatchesURL(
796 GURL("filesystem:chrome-extension://foo/local/test.txt"))); 805 GURL("filesystem:chrome-extension://foo/local/test.txt")));
797 } 806 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/extension_messages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698