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

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

Issue 11724002: Move ContentScripts out of Extension (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
Patch Set: Created 7 years, 9 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/extensions/api/commands/commands_handler.h" 16 #include "chrome/common/extensions/api/commands/commands_handler.h"
17 #include "chrome/common/extensions/api/content_scripts/content_scripts_handler.h "
17 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 18 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
18 #include "chrome/common/extensions/background_info.h" 19 #include "chrome/common/extensions/background_info.h"
19 #include "chrome/common/extensions/command.h" 20 #include "chrome/common/extensions/command.h"
20 #include "chrome/common/extensions/extension_file_util.h" 21 #include "chrome/common/extensions/extension_file_util.h"
21 #include "chrome/common/extensions/extension_manifest_constants.h" 22 #include "chrome/common/extensions/extension_manifest_constants.h"
22 #include "chrome/common/extensions/extension_resource.h" 23 #include "chrome/common/extensions/extension_resource.h"
23 #include "chrome/common/extensions/features/feature.h" 24 #include "chrome/common/extensions/features/feature.h"
24 #include "chrome/common/extensions/manifest.h" 25 #include "chrome/common/extensions/manifest.h"
25 #include "chrome/common/extensions/manifest_handler.h" 26 #include "chrome/common/extensions/manifest_handler.h"
26 #include "chrome/common/extensions/permissions/api_permission.h" 27 #include "chrome/common/extensions/permissions/api_permission.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 100 }
100 101
101 } // namespace 102 } // namespace
102 103
103 class ExtensionTest : public testing::Test { 104 class ExtensionTest : public testing::Test {
104 protected: 105 protected:
105 virtual void SetUp() OVERRIDE { 106 virtual void SetUp() OVERRIDE {
106 testing::Test::SetUp(); 107 testing::Test::SetUp();
107 (new BackgroundManifestHandler)->Register(); 108 (new BackgroundManifestHandler)->Register();
108 (new CommandsHandler)->Register(); 109 (new CommandsHandler)->Register();
110 (new ContentScriptsHandler)->Register();
109 (new PluginsHandler)->Register(); 111 (new PluginsHandler)->Register();
110 } 112 }
111 113
112 virtual void TearDown() OVERRIDE { 114 virtual void TearDown() OVERRIDE {
113 ManifestHandler::ClearRegistryForTesting(); 115 ManifestHandler::ClearRegistryForTesting();
114 } 116 }
115 }; 117 };
116 118
117 // We persist location values in the preferences, so this is a sanity test that 119 // We persist location values in the preferences, so this is a sanity test that
118 // someone doesn't accidentally change them. 120 // someone doesn't accidentally change them.
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 extension = LoadManifest("permissions", "permissions_http_scheme.json", 497 extension = LoadManifest("permissions", "permissions_http_scheme.json",
496 Extension::ALLOW_FILE_ACCESS); 498 Extension::ALLOW_FILE_ACCESS);
497 EXPECT_FALSE(extension->wants_file_access()); 499 EXPECT_FALSE(extension->wants_file_access());
498 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 500 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
499 file_url, file_url, -1, NULL, NULL)); 501 file_url, file_url, -1, NULL, NULL));
500 502
501 // <all_urls> content script match 503 // <all_urls> content script match
502 extension = LoadManifest("permissions", "content_script_all_urls.json"); 504 extension = LoadManifest("permissions", "content_script_all_urls.json");
503 EXPECT_TRUE(extension->wants_file_access()); 505 EXPECT_TRUE(extension->wants_file_access());
504 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 506 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
505 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 507 file_url,
508 file_url,
509 -1,
510 &ContentScriptsInfo::GetContentScripts(extension)[0],
511 NULL));
506 extension = LoadManifest("permissions", "content_script_all_urls.json", 512 extension = LoadManifest("permissions", "content_script_all_urls.json",
507 Extension::ALLOW_FILE_ACCESS); 513 Extension::ALLOW_FILE_ACCESS);
508 EXPECT_TRUE(extension->wants_file_access()); 514 EXPECT_TRUE(extension->wants_file_access());
509 EXPECT_TRUE(extension->CanExecuteScriptOnPage( 515 EXPECT_TRUE(extension->CanExecuteScriptOnPage(
510 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 516 file_url,
517 file_url,
518 -1,
519 &ContentScriptsInfo::GetContentScripts(extension)[0],
520 NULL));
511 521
512 // file:///* content script match 522 // file:///* content script match
513 extension = LoadManifest("permissions", "content_script_file_scheme.json"); 523 extension = LoadManifest("permissions", "content_script_file_scheme.json");
514 EXPECT_TRUE(extension->wants_file_access()); 524 EXPECT_TRUE(extension->wants_file_access());
515 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 525 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
516 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 526 file_url,
527 file_url,
528 -1,
529 &ContentScriptsInfo::GetContentScripts(extension)[0],
530 NULL));
517 extension = LoadManifest("permissions", "content_script_file_scheme.json", 531 extension = LoadManifest("permissions", "content_script_file_scheme.json",
518 Extension::ALLOW_FILE_ACCESS); 532 Extension::ALLOW_FILE_ACCESS);
519 EXPECT_TRUE(extension->wants_file_access()); 533 EXPECT_TRUE(extension->wants_file_access());
520 EXPECT_TRUE(extension->CanExecuteScriptOnPage( 534 EXPECT_TRUE(extension->CanExecuteScriptOnPage(
521 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 535 file_url,
536 file_url,
537 -1,
538 &ContentScriptsInfo::GetContentScripts(extension)[0],
539 NULL));
522 540
523 // http://* content script match 541 // http://* content script match
524 extension = LoadManifest("permissions", "content_script_http_scheme.json"); 542 extension = LoadManifest("permissions", "content_script_http_scheme.json");
525 EXPECT_FALSE(extension->wants_file_access()); 543 EXPECT_FALSE(extension->wants_file_access());
526 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 544 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
527 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 545 file_url,
546 file_url,
547 -1,
548 &ContentScriptsInfo::GetContentScripts(extension)[0],
549 NULL));
528 extension = LoadManifest("permissions", "content_script_http_scheme.json", 550 extension = LoadManifest("permissions", "content_script_http_scheme.json",
529 Extension::ALLOW_FILE_ACCESS); 551 Extension::ALLOW_FILE_ACCESS);
530 EXPECT_FALSE(extension->wants_file_access()); 552 EXPECT_FALSE(extension->wants_file_access());
531 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 553 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
532 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 554 file_url,
555 file_url,
556 -1,
557 &ContentScriptsInfo::GetContentScripts(extension)[0],
558 NULL));
533 } 559 }
534 560
535 TEST_F(ExtensionTest, ExtraFlags) { 561 TEST_F(ExtensionTest, ExtraFlags) {
536 scoped_refptr<Extension> extension; 562 scoped_refptr<Extension> extension;
537 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE); 563 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE);
538 EXPECT_TRUE(extension->from_webstore()); 564 EXPECT_TRUE(extension->from_webstore());
539 565
540 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK); 566 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK);
541 EXPECT_TRUE(extension->from_bookmark()); 567 EXPECT_TRUE(extension->from_bookmark());
542 568
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 scoped_refptr<Extension> extension( 1114 scoped_refptr<Extension> extension(
1089 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1115 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1090 Manifest::INTERNAL, 2, base::FilePath(), 1116 Manifest::INTERNAL, 2, base::FilePath(),
1091 Extension::NO_FLAGS)); 1117 Extension::NO_FLAGS));
1092 if (extension) 1118 if (extension)
1093 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1119 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1094 } 1120 }
1095 #endif // !defined(OS_CHROMEOS) 1121 #endif // !defined(OS_CHROMEOS)
1096 1122
1097 } // namespace extensions 1123 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698