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++; |
89 | 90 |
90 ASSERT_EQ(static_cast<uint32>(num_expected_extensions), | 91 ASSERT_EQ(static_cast<uint32>(num_expected_extensions), |
91 static_cast<uint32>(found_extensions)); | 92 static_cast<uint32>(found_extensions)); |
92 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled()); | 93 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled()); |
93 | 94 |
94 ui_test_utils::WindowedNotificationObserver user_scripts_observer( | 95 ui_test_utils::WindowedNotificationObserver user_scripts_observer( |
95 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 96 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
96 content::NotificationService::AllSources()); | 97 content::NotificationService::AllSources()); |
97 UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); | 98 UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 #if defined(OS_MACOSX) | 157 #if defined(OS_MACOSX) |
157 #define MAYBE_NoFileAccess DISABLED_NoFileAccess | 158 #define MAYBE_NoFileAccess DISABLED_NoFileAccess |
158 #else | 159 #else |
159 #define MAYBE_NoFileAccess NoFileAccess | 160 #define MAYBE_NoFileAccess NoFileAccess |
160 #endif | 161 #endif |
161 // Tests that disallowing file access on an extension prevents it from injecting | 162 // Tests that disallowing file access on an extension prevents it from injecting |
162 // script into a page with a file URL. | 163 // script into a page with a file URL. |
163 IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) { | 164 IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) { |
164 WaitForServicesToStart(num_expected_extensions_, true); | 165 WaitForServicesToStart(num_expected_extensions_, true); |
165 | 166 |
| 167 // Keep a separate list of extensions for which to disable file access, since |
| 168 // doing so reloads them. |
| 169 std::vector<const Extension*> extension_list; |
| 170 |
166 ExtensionService* service = browser()->profile()->GetExtensionService(); | 171 ExtensionService* service = browser()->profile()->GetExtensionService(); |
167 for (size_t i = 0; i < service->extensions()->size(); ++i) { | 172 for (ExtensionSet::const_iterator it = service->extensions()->begin(); |
168 if (service->extensions()->at(i)->location() == Extension::COMPONENT) | 173 it != service->extensions()->end(); ++it) { |
| 174 if ((*it)->location() == Extension::COMPONENT) |
169 continue; | 175 continue; |
170 if (service->AllowFileAccess(service->extensions()->at(i))) { | 176 if (service->AllowFileAccess(*it)) |
171 ui_test_utils::WindowedNotificationObserver user_scripts_observer( | 177 extension_list.push_back(*it); |
172 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 178 } |
173 content::NotificationService::AllSources()); | 179 |
174 service->SetAllowFileAccess(service->extensions()->at(i), false); | 180 for (size_t i = 0; i < extension_list.size(); ++i) { |
175 user_scripts_observer.Wait(); | 181 ui_test_utils::WindowedNotificationObserver user_scripts_observer( |
176 } | 182 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
| 183 content::NotificationService::AllSources()); |
| 184 service->SetAllowFileAccess(extension_list[i], false); |
| 185 user_scripts_observer.Wait(); |
177 } | 186 } |
178 | 187 |
179 TestInjection(false, false); | 188 TestInjection(false, false); |
180 } | 189 } |
181 | 190 |
182 // ExtensionsLoadTest | 191 // ExtensionsLoadTest |
183 // Ensures that we can startup the browser with --load-extension and see them | 192 // Ensures that we can startup the browser with --load-extension and see them |
184 // run. | 193 // run. |
185 | 194 |
186 class ExtensionsLoadTest : public ExtensionStartupTestBase { | 195 class ExtensionsLoadTest : public ExtensionStartupTestBase { |
(...skipping 14 matching lines...) Expand all Loading... |
201 #if defined(OS_LINUX) && defined(ARCH_CPU_64_BITS) | 210 #if defined(OS_LINUX) && defined(ARCH_CPU_64_BITS) |
202 #define Maybe_Test FLAKY_Test | 211 #define Maybe_Test FLAKY_Test |
203 #else | 212 #else |
204 #define Maybe_Test Test | 213 #define Maybe_Test Test |
205 #endif | 214 #endif |
206 | 215 |
207 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Maybe_Test) { | 216 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Maybe_Test) { |
208 WaitForServicesToStart(1, true); | 217 WaitForServicesToStart(1, true); |
209 TestInjection(true, true); | 218 TestInjection(true, true); |
210 } | 219 } |
OLD | NEW |