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

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: Latest master for CQ 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
11 #include "base/json/json_file_value_serializer.h" 11 #include "base/json/json_file_value_serializer.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/extensions/api/commands/commands_handler.h" 18 #include "chrome/common/extensions/api/commands/commands_handler.h"
19 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 19 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
20 #include "chrome/common/extensions/background_info.h" 20 #include "chrome/common/extensions/background_info.h"
21 #include "chrome/common/extensions/command.h" 21 #include "chrome/common/extensions/command.h"
22 #include "chrome/common/extensions/extension_file_util.h" 22 #include "chrome/common/extensions/extension_file_util.h"
23 #include "chrome/common/extensions/extension_manifest_constants.h" 23 #include "chrome/common/extensions/extension_manifest_constants.h"
24 #include "chrome/common/extensions/features/feature.h" 24 #include "chrome/common/extensions/features/feature.h"
25 #include "chrome/common/extensions/manifest.h" 25 #include "chrome/common/extensions/manifest.h"
26 #include "chrome/common/extensions/manifest_handler.h" 26 #include "chrome/common/extensions/manifest_handler.h"
27 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
27 #include "chrome/common/extensions/permissions/api_permission.h" 28 #include "chrome/common/extensions/permissions/api_permission.h"
28 #include "chrome/common/extensions/permissions/permission_set.h" 29 #include "chrome/common/extensions/permissions/permission_set.h"
29 #include "chrome/common/extensions/permissions/socket_permission.h" 30 #include "chrome/common/extensions/permissions/socket_permission.h"
30 #include "chrome/common/extensions/permissions/usb_device_permission.h" 31 #include "chrome/common/extensions/permissions/usb_device_permission.h"
31 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
32 #include "extensions/common/error_utils.h" 33 #include "extensions/common/error_utils.h"
33 #include "extensions/common/extension_resource.h" 34 #include "extensions/common/extension_resource.h"
34 #include "extensions/common/id_util.h" 35 #include "extensions/common/id_util.h"
35 #include "googleurl/src/gurl.h" 36 #include "googleurl/src/gurl.h"
36 #include "net/base/mime_sniffer.h" 37 #include "net/base/mime_sniffer.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 103 }
103 104
104 } // namespace 105 } // namespace
105 106
106 class ExtensionTest : public testing::Test { 107 class ExtensionTest : public testing::Test {
107 protected: 108 protected:
108 virtual void SetUp() OVERRIDE { 109 virtual void SetUp() OVERRIDE {
109 testing::Test::SetUp(); 110 testing::Test::SetUp();
110 (new BackgroundManifestHandler)->Register(); 111 (new BackgroundManifestHandler)->Register();
111 (new CommandsHandler)->Register(); 112 (new CommandsHandler)->Register();
113 (new ContentScriptsHandler)->Register();
112 (new PluginsHandler)->Register(); 114 (new PluginsHandler)->Register();
113 } 115 }
114 116
115 virtual void TearDown() OVERRIDE { 117 virtual void TearDown() OVERRIDE {
116 ManifestHandler::ClearRegistryForTesting(); 118 ManifestHandler::ClearRegistryForTesting();
117 } 119 }
118 }; 120 };
119 121
120 // We persist location values in the preferences, so this is a sanity test that 122 // We persist location values in the preferences, so this is a sanity test that
121 // someone doesn't accidentally change them. 123 // someone doesn't accidentally change them.
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 extension = LoadManifest("permissions", "permissions_http_scheme.json", 474 extension = LoadManifest("permissions", "permissions_http_scheme.json",
473 Extension::ALLOW_FILE_ACCESS); 475 Extension::ALLOW_FILE_ACCESS);
474 EXPECT_FALSE(extension->wants_file_access()); 476 EXPECT_FALSE(extension->wants_file_access());
475 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 477 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
476 file_url, file_url, -1, NULL, NULL)); 478 file_url, file_url, -1, NULL, NULL));
477 479
478 // <all_urls> content script match 480 // <all_urls> content script match
479 extension = LoadManifest("permissions", "content_script_all_urls.json"); 481 extension = LoadManifest("permissions", "content_script_all_urls.json");
480 EXPECT_TRUE(extension->wants_file_access()); 482 EXPECT_TRUE(extension->wants_file_access());
481 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 483 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
482 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 484 file_url,
485 file_url,
486 -1,
487 &ContentScriptsInfo::GetContentScripts(extension)[0],
488 NULL));
483 extension = LoadManifest("permissions", "content_script_all_urls.json", 489 extension = LoadManifest("permissions", "content_script_all_urls.json",
484 Extension::ALLOW_FILE_ACCESS); 490 Extension::ALLOW_FILE_ACCESS);
485 EXPECT_TRUE(extension->wants_file_access()); 491 EXPECT_TRUE(extension->wants_file_access());
486 EXPECT_TRUE(extension->CanExecuteScriptOnPage( 492 EXPECT_TRUE(extension->CanExecuteScriptOnPage(
487 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 493 file_url,
494 file_url,
495 -1,
496 &ContentScriptsInfo::GetContentScripts(extension)[0],
497 NULL));
488 498
489 // file:///* content script match 499 // file:///* content script match
490 extension = LoadManifest("permissions", "content_script_file_scheme.json"); 500 extension = LoadManifest("permissions", "content_script_file_scheme.json");
491 EXPECT_TRUE(extension->wants_file_access()); 501 EXPECT_TRUE(extension->wants_file_access());
492 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 502 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
493 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 503 file_url,
504 file_url,
505 -1,
506 &ContentScriptsInfo::GetContentScripts(extension)[0],
507 NULL));
494 extension = LoadManifest("permissions", "content_script_file_scheme.json", 508 extension = LoadManifest("permissions", "content_script_file_scheme.json",
495 Extension::ALLOW_FILE_ACCESS); 509 Extension::ALLOW_FILE_ACCESS);
496 EXPECT_TRUE(extension->wants_file_access()); 510 EXPECT_TRUE(extension->wants_file_access());
497 EXPECT_TRUE(extension->CanExecuteScriptOnPage( 511 EXPECT_TRUE(extension->CanExecuteScriptOnPage(
498 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 512 file_url,
513 file_url,
514 -1,
515 &ContentScriptsInfo::GetContentScripts(extension)[0],
516 NULL));
499 517
500 // http://* content script match 518 // http://* content script match
501 extension = LoadManifest("permissions", "content_script_http_scheme.json"); 519 extension = LoadManifest("permissions", "content_script_http_scheme.json");
502 EXPECT_FALSE(extension->wants_file_access()); 520 EXPECT_FALSE(extension->wants_file_access());
503 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 521 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
504 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 522 file_url,
523 file_url,
524 -1,
525 &ContentScriptsInfo::GetContentScripts(extension)[0],
526 NULL));
505 extension = LoadManifest("permissions", "content_script_http_scheme.json", 527 extension = LoadManifest("permissions", "content_script_http_scheme.json",
506 Extension::ALLOW_FILE_ACCESS); 528 Extension::ALLOW_FILE_ACCESS);
507 EXPECT_FALSE(extension->wants_file_access()); 529 EXPECT_FALSE(extension->wants_file_access());
508 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 530 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
509 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 531 file_url,
532 file_url,
533 -1,
534 &ContentScriptsInfo::GetContentScripts(extension)[0],
535 NULL));
510 } 536 }
511 537
512 TEST_F(ExtensionTest, ExtraFlags) { 538 TEST_F(ExtensionTest, ExtraFlags) {
513 scoped_refptr<Extension> extension; 539 scoped_refptr<Extension> extension;
514 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE); 540 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE);
515 EXPECT_TRUE(extension->from_webstore()); 541 EXPECT_TRUE(extension->from_webstore());
516 542
517 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK); 543 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK);
518 EXPECT_TRUE(extension->from_bookmark()); 544 EXPECT_TRUE(extension->from_bookmark());
519 545
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 scoped_refptr<Extension> extension( 1172 scoped_refptr<Extension> extension(
1147 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1173 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1148 Manifest::INTERNAL, 2, base::FilePath(), 1174 Manifest::INTERNAL, 2, base::FilePath(),
1149 Extension::NO_FLAGS)); 1175 Extension::NO_FLAGS));
1150 if (extension) 1176 if (extension)
1151 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1177 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1152 } 1178 }
1153 #endif // !defined(OS_CHROMEOS) 1179 #endif // !defined(OS_CHROMEOS)
1154 1180
1155 } // namespace extensions 1181 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698