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

Side by Side Diff: chrome/browser/extensions/all_urls_apitest.cc

Issue 11365181: Remove GetExtensionService from Profile. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: replace missing extension_system include Created 8 years 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) 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/browser/extensions/extension_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/browser/extensions/extension_service.h" 6 #include "chrome/browser/extensions/extension_service.h"
7 #include "chrome/browser/extensions/extension_system.h"
7 #include "chrome/browser/extensions/extension_test_message_listener.h" 8 #include "chrome/browser/extensions/extension_test_message_listener.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
10 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
11 #include "chrome/test/base/ui_test_utils.h" 12 #include "chrome/test/base/ui_test_utils.h"
12 13
13 const std::string kAllUrlsTarget = 14 const std::string kAllUrlsTarget =
14 "files/extensions/api_test/all_urls/index.html"; 15 "files/extensions/api_test/all_urls/index.html";
15 16
16 typedef ExtensionApiTest AllUrlsApiTest; 17 typedef ExtensionApiTest AllUrlsApiTest;
17 18
18 IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, WhitelistedExtension) { 19 IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, WhitelistedExtension) {
19 // First setup the two extensions. 20 // First setup the two extensions.
20 FilePath extension_dir1 = test_data_dir_.AppendASCII("all_urls") 21 FilePath extension_dir1 = test_data_dir_.AppendASCII("all_urls")
21 .AppendASCII("content_script"); 22 .AppendASCII("content_script");
22 FilePath extension_dir2 = test_data_dir_.AppendASCII("all_urls") 23 FilePath extension_dir2 = test_data_dir_.AppendASCII("all_urls")
23 .AppendASCII("execute_script"); 24 .AppendASCII("execute_script");
24 25
25 // Then add the two extensions to the whitelist. 26 // Then add the two extensions to the whitelist.
26 extensions::Extension::ScriptingWhitelist whitelist; 27 extensions::Extension::ScriptingWhitelist whitelist;
27 whitelist.push_back(extensions::Extension::GenerateIdForPath(extension_dir1)); 28 whitelist.push_back(extensions::Extension::GenerateIdForPath(extension_dir1));
28 whitelist.push_back(extensions::Extension::GenerateIdForPath(extension_dir2)); 29 whitelist.push_back(extensions::Extension::GenerateIdForPath(extension_dir2));
29 extensions::Extension::SetScriptingWhitelist(whitelist); 30 extensions::Extension::SetScriptingWhitelist(whitelist);
30 31
31 // Then load extensions. 32 // Then load extensions.
32 ExtensionService* service = browser()->profile()->GetExtensionService(); 33 ExtensionService* service = extensions::ExtensionSystem::Get(
34 browser()->profile())->extension_service();
33 const size_t size_before = service->extensions()->size(); 35 const size_t size_before = service->extensions()->size();
34 ASSERT_TRUE(LoadExtension(extension_dir1)); 36 ASSERT_TRUE(LoadExtension(extension_dir1));
35 ASSERT_TRUE(LoadExtension(extension_dir2)); 37 ASSERT_TRUE(LoadExtension(extension_dir2));
36 EXPECT_EQ(size_before + 2, service->extensions()->size()); 38 EXPECT_EQ(size_before + 2, service->extensions()->size());
37 39
38 std::string url; 40 std::string url;
39 41
40 // Now verify we run content scripts on chrome://newtab/. 42 // Now verify we run content scripts on chrome://newtab/.
41 url = "chrome://newtab/"; 43 url = "chrome://newtab/";
42 ExtensionTestMessageListener listener1a("content script: " + url, false); 44 ExtensionTestMessageListener listener1a("content script: " + url, false);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 84
83 // Test that an extension NOT whitelisted for scripting can ask for <all_urls> 85 // Test that an extension NOT whitelisted for scripting can ask for <all_urls>
84 // and run scripts on non-restricted all pages. 86 // and run scripts on non-restricted all pages.
85 IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, RegularExtensions) { 87 IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, RegularExtensions) {
86 // First load the two extensions. 88 // First load the two extensions.
87 FilePath extension_dir1 = test_data_dir_.AppendASCII("all_urls") 89 FilePath extension_dir1 = test_data_dir_.AppendASCII("all_urls")
88 .AppendASCII("content_script"); 90 .AppendASCII("content_script");
89 FilePath extension_dir2 = test_data_dir_.AppendASCII("all_urls") 91 FilePath extension_dir2 = test_data_dir_.AppendASCII("all_urls")
90 .AppendASCII("execute_script"); 92 .AppendASCII("execute_script");
91 93
92 94 ExtensionService* service = extensions::ExtensionSystem::Get(
93 ExtensionService* service = browser()->profile()->GetExtensionService(); 95 browser()->profile())->extension_service();
94 const size_t size_before = service->extensions()->size(); 96 const size_t size_before = service->extensions()->size();
95 ASSERT_TRUE(LoadExtension(extension_dir1)); 97 ASSERT_TRUE(LoadExtension(extension_dir1));
96 ASSERT_TRUE(LoadExtension(extension_dir2)); 98 ASSERT_TRUE(LoadExtension(extension_dir2));
97 EXPECT_EQ(size_before + 2, service->extensions()->size()); 99 EXPECT_EQ(size_before + 2, service->extensions()->size());
98 100
99 // Now verify we can script a regular http page. 101 // Now verify we can script a regular http page.
100 ASSERT_TRUE(test_server()->Start()); 102 ASSERT_TRUE(test_server()->Start());
101 GURL page_url = test_server()->GetURL(kAllUrlsTarget); 103 GURL page_url = test_server()->GetURL(kAllUrlsTarget);
102 ExtensionTestMessageListener listener1a("content script: " + page_url.spec(), 104 ExtensionTestMessageListener listener1a("content script: " + page_url.spec(),
103 false); 105 false);
104 ExtensionTestMessageListener listener1b("execute: " + page_url.spec(), false); 106 ExtensionTestMessageListener listener1b("execute: " + page_url.spec(), false);
105 ui_test_utils::NavigateToURL(browser(), page_url); 107 ui_test_utils::NavigateToURL(browser(), page_url);
106 ASSERT_TRUE(listener1a.WaitUntilSatisfied()); 108 ASSERT_TRUE(listener1a.WaitUntilSatisfied());
107 ASSERT_TRUE(listener1b.WaitUntilSatisfied()); 109 ASSERT_TRUE(listener1b.WaitUntilSatisfied());
108 } 110 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_crx_util.cc ('k') | chrome/browser/extensions/api/app/app_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698