OLD | NEW |
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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 InProcessBrowserTest::TearDown(); | 77 InProcessBrowserTest::TearDown(); |
78 } | 78 } |
79 | 79 |
80 void WaitForServicesToStart(int num_expected_extensions, | 80 void WaitForServicesToStart(int num_expected_extensions, |
81 bool expect_extensions_enabled) { | 81 bool expect_extensions_enabled) { |
82 ExtensionService* service = browser()->profile()->GetExtensionService(); | 82 ExtensionService* service = browser()->profile()->GetExtensionService(); |
83 | 83 |
84 // Count the number of non-component extensions. | 84 // Count the number of non-component extensions. |
85 int found_extensions = 0; | 85 int found_extensions = 0; |
86 for (size_t i = 0; i < service->extensions()->size(); i++) | 86 for (ExtensionSet::const_iterator it = service->extensions()->begin(); |
87 if (service->extensions()->at(i)->location() != Extension::COMPONENT) | 87 it != service->extensions()->end(); ++it) { |
| 88 if ((*it)->location() != Extension::COMPONENT) |
88 found_extensions++; | 89 found_extensions++; |
| 90 } |
89 | 91 |
90 ASSERT_EQ(static_cast<uint32>(num_expected_extensions), | 92 ASSERT_EQ(static_cast<uint32>(num_expected_extensions), |
91 static_cast<uint32>(found_extensions)); | 93 static_cast<uint32>(found_extensions)); |
92 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled()); | 94 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled()); |
93 | 95 |
94 ui_test_utils::WindowedNotificationObserver user_scripts_observer( | 96 ui_test_utils::WindowedNotificationObserver user_scripts_observer( |
95 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 97 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
96 content::NotificationService::AllSources()); | 98 content::NotificationService::AllSources()); |
97 UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); | 99 UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); |
98 if (!master->ScriptsReady()) | 100 if (!master->ScriptsReady()) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 #define MAYBE_NoFileAccess DISABLED_NoFileAccess | 159 #define MAYBE_NoFileAccess DISABLED_NoFileAccess |
158 #else | 160 #else |
159 #define MAYBE_NoFileAccess NoFileAccess | 161 #define MAYBE_NoFileAccess NoFileAccess |
160 #endif | 162 #endif |
161 // Tests that disallowing file access on an extension prevents it from injecting | 163 // Tests that disallowing file access on an extension prevents it from injecting |
162 // script into a page with a file URL. | 164 // script into a page with a file URL. |
163 IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) { | 165 IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) { |
164 WaitForServicesToStart(num_expected_extensions_, true); | 166 WaitForServicesToStart(num_expected_extensions_, true); |
165 | 167 |
166 ExtensionService* service = browser()->profile()->GetExtensionService(); | 168 ExtensionService* service = browser()->profile()->GetExtensionService(); |
167 for (size_t i = 0; i < service->extensions()->size(); ++i) { | 169 for (ExtensionSet::const_iterator it = service->extensions()->begin(); |
168 if (service->extensions()->at(i)->location() == Extension::COMPONENT) | 170 it != service->extensions()->end(); ++it) { |
| 171 if ((*it)->location() == Extension::COMPONENT) |
169 continue; | 172 continue; |
170 if (service->AllowFileAccess(service->extensions()->at(i))) { | 173 if (service->AllowFileAccess(*it)) { |
171 ui_test_utils::WindowedNotificationObserver user_scripts_observer( | 174 ui_test_utils::WindowedNotificationObserver user_scripts_observer( |
172 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 175 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
173 content::NotificationService::AllSources()); | 176 content::NotificationService::AllSources()); |
174 service->SetAllowFileAccess(service->extensions()->at(i), false); | 177 service->SetAllowFileAccess(*it, false); |
175 user_scripts_observer.Wait(); | 178 user_scripts_observer.Wait(); |
176 } | 179 } |
177 } | 180 } |
178 | 181 |
179 TestInjection(false, false); | 182 TestInjection(false, false); |
180 } | 183 } |
181 | 184 |
182 // ExtensionsLoadTest | 185 // ExtensionsLoadTest |
183 // Ensures that we can startup the browser with --load-extension and see them | 186 // Ensures that we can startup the browser with --load-extension and see them |
184 // run. | 187 // run. |
(...skipping 16 matching lines...) Expand all Loading... |
201 #if defined(OS_LINUX) && defined(ARCH_CPU_64_BITS) | 204 #if defined(OS_LINUX) && defined(ARCH_CPU_64_BITS) |
202 #define Maybe_Test FLAKY_Test | 205 #define Maybe_Test FLAKY_Test |
203 #else | 206 #else |
204 #define Maybe_Test Test | 207 #define Maybe_Test Test |
205 #endif | 208 #endif |
206 | 209 |
207 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Maybe_Test) { | 210 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Maybe_Test) { |
208 WaitForServicesToStart(1, true); | 211 WaitForServicesToStart(1, true); |
209 TestInjection(true, true); | 212 TestInjection(true, true); |
210 } | 213 } |
OLD | NEW |