OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 5 #include <vector> |
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/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
15 #include "chrome/browser/extensions/extension_util.h" | 15 #include "chrome/browser/extensions/extension_util.h" |
16 #include "chrome/browser/extensions/user_script_master.h" | 16 #include "chrome/browser/extensions/user_script_master.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
24 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 29 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/extension_set.h" |
29 #include "extensions/common/feature_switch.h" | 31 #include "extensions/common/feature_switch.h" |
30 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
31 | 33 |
32 using extensions::FeatureSwitch; | 34 using extensions::FeatureSwitch; |
33 | 35 |
34 // This file contains high-level startup tests for the extensions system. We've | 36 // This file contains high-level startup tests for the extensions system. We've |
35 // had many silly bugs where command line flags did not get propagated correctly | 37 // had many silly bugs where command line flags did not get propagated correctly |
36 // into the services, so we didn't start correctly. | 38 // into the services, so we didn't start correctly. |
37 | 39 |
38 class ExtensionStartupTestBase : public InProcessBrowserTest { | 40 class ExtensionStartupTestBase : public InProcessBrowserTest { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 InProcessBrowserTest::TearDown(); | 90 InProcessBrowserTest::TearDown(); |
89 } | 91 } |
90 | 92 |
91 void WaitForServicesToStart(int num_expected_extensions, | 93 void WaitForServicesToStart(int num_expected_extensions, |
92 bool expect_extensions_enabled) { | 94 bool expect_extensions_enabled) { |
93 ExtensionService* service = extensions::ExtensionSystem::Get( | 95 ExtensionService* service = extensions::ExtensionSystem::Get( |
94 browser()->profile())->extension_service(); | 96 browser()->profile())->extension_service(); |
95 | 97 |
96 // Count the number of non-component extensions. | 98 // Count the number of non-component extensions. |
97 int found_extensions = 0; | 99 int found_extensions = 0; |
98 for (ExtensionSet::const_iterator it = service->extensions()->begin(); | 100 for (extensions::ExtensionSet::const_iterator it = |
| 101 service->extensions()->begin(); |
99 it != service->extensions()->end(); ++it) | 102 it != service->extensions()->end(); ++it) |
100 if ((*it)->location() != extensions::Manifest::COMPONENT) | 103 if ((*it)->location() != extensions::Manifest::COMPONENT) |
101 found_extensions++; | 104 found_extensions++; |
102 | 105 |
103 ASSERT_EQ(static_cast<uint32>(num_expected_extensions), | 106 ASSERT_EQ(static_cast<uint32>(num_expected_extensions), |
104 static_cast<uint32>(found_extensions)); | 107 static_cast<uint32>(found_extensions)); |
105 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled()); | 108 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled()); |
106 | 109 |
107 content::WindowedNotificationObserver user_scripts_observer( | 110 content::WindowedNotificationObserver user_scripts_observer( |
108 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 111 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // script into a page with a file URL. | 181 // script into a page with a file URL. |
179 IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) { | 182 IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) { |
180 WaitForServicesToStart(num_expected_extensions_, true); | 183 WaitForServicesToStart(num_expected_extensions_, true); |
181 | 184 |
182 // Keep a separate list of extensions for which to disable file access, since | 185 // Keep a separate list of extensions for which to disable file access, since |
183 // doing so reloads them. | 186 // doing so reloads them. |
184 std::vector<const extensions::Extension*> extension_list; | 187 std::vector<const extensions::Extension*> extension_list; |
185 | 188 |
186 ExtensionService* service = extensions::ExtensionSystem::Get( | 189 ExtensionService* service = extensions::ExtensionSystem::Get( |
187 browser()->profile())->extension_service(); | 190 browser()->profile())->extension_service(); |
188 for (ExtensionSet::const_iterator it = service->extensions()->begin(); | 191 for (extensions::ExtensionSet::const_iterator it = |
| 192 service->extensions()->begin(); |
189 it != service->extensions()->end(); ++it) { | 193 it != service->extensions()->end(); ++it) { |
190 if ((*it)->location() == extensions::Manifest::COMPONENT) | 194 if ((*it)->location() == extensions::Manifest::COMPONENT) |
191 continue; | 195 continue; |
192 if (extension_util::AllowFileAccess(it->get(), service)) | 196 if (extension_util::AllowFileAccess(it->get(), service)) |
193 extension_list.push_back(it->get()); | 197 extension_list.push_back(it->get()); |
194 } | 198 } |
195 | 199 |
196 for (size_t i = 0; i < extension_list.size(); ++i) { | 200 for (size_t i = 0; i < extension_list.size(); ++i) { |
197 content::WindowedNotificationObserver user_scripts_observer( | 201 content::WindowedNotificationObserver user_scripts_observer( |
198 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 202 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 .AppendASCII("extensions") | 273 .AppendASCII("extensions") |
270 .AppendASCII("app2"); | 274 .AppendASCII("app2"); |
271 load_extensions_.push_back(fourth_extension_path.value()); | 275 load_extensions_.push_back(fourth_extension_path.value()); |
272 } | 276 } |
273 }; | 277 }; |
274 | 278 |
275 IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) { | 279 IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) { |
276 WaitForServicesToStart(4, true); | 280 WaitForServicesToStart(4, true); |
277 TestInjection(true, true); | 281 TestInjection(true, true); |
278 } | 282 } |
OLD | NEW |