| 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" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/user_script_master.h" | 12 #include "chrome/browser/extensions/user_script_master.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.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/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
| 21 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_service.h" |
| 22 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 23 | 24 |
| 24 // This file contains high-level startup tests for the extensions system. We've | 25 // This file contains high-level startup tests for the extensions system. We've |
| 25 // had many silly bugs where command line flags did not get propagated correctly | 26 // had many silly bugs where command line flags did not get propagated correctly |
| 26 // into the services, so we didn't start correctly. | 27 // into the services, so we didn't start correctly. |
| 27 | 28 |
| 28 class ExtensionStartupTestBase : public InProcessBrowserTest { | 29 class ExtensionStartupTestBase : public InProcessBrowserTest { |
| 29 public: | 30 public: |
| 30 ExtensionStartupTestBase() : enable_extensions_(false) { | 31 ExtensionStartupTestBase() : enable_extensions_(false) { |
| 31 num_expected_extensions_ = 3; | 32 num_expected_extensions_ = 3; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 for (size_t i = 0; i < service->extensions()->size(); i++) | 86 for (size_t i = 0; i < service->extensions()->size(); i++) |
| 86 if (service->extensions()->at(i)->location() != Extension::COMPONENT) | 87 if (service->extensions()->at(i)->location() != Extension::COMPONENT) |
| 87 found_extensions++; | 88 found_extensions++; |
| 88 | 89 |
| 89 ASSERT_EQ(static_cast<uint32>(num_expected_extensions), | 90 ASSERT_EQ(static_cast<uint32>(num_expected_extensions), |
| 90 static_cast<uint32>(found_extensions)); | 91 static_cast<uint32>(found_extensions)); |
| 91 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled()); | 92 ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled()); |
| 92 | 93 |
| 93 ui_test_utils::WindowedNotificationObserver user_scripts_observer( | 94 ui_test_utils::WindowedNotificationObserver user_scripts_observer( |
| 94 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 95 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
| 95 NotificationService::AllSources()); | 96 content::NotificationService::AllSources()); |
| 96 UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); | 97 UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); |
| 97 if (!master->ScriptsReady()) | 98 if (!master->ScriptsReady()) |
| 98 user_scripts_observer.Wait(); | 99 user_scripts_observer.Wait(); |
| 99 ASSERT_TRUE(master->ScriptsReady()); | 100 ASSERT_TRUE(master->ScriptsReady()); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void TestInjection(bool expect_css, bool expect_script) { | 103 void TestInjection(bool expect_css, bool expect_script) { |
| 103 // Load a page affected by the content script and test to see the effect. | 104 // Load a page affected by the content script and test to see the effect. |
| 104 FilePath test_file; | 105 FilePath test_file; |
| 105 PathService::Get(chrome::DIR_TEST_DATA, &test_file); | 106 PathService::Get(chrome::DIR_TEST_DATA, &test_file); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) { | 163 IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) { |
| 163 WaitForServicesToStart(num_expected_extensions_, true); | 164 WaitForServicesToStart(num_expected_extensions_, true); |
| 164 | 165 |
| 165 ExtensionService* service = browser()->profile()->GetExtensionService(); | 166 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 166 for (size_t i = 0; i < service->extensions()->size(); ++i) { | 167 for (size_t i = 0; i < service->extensions()->size(); ++i) { |
| 167 if (service->extensions()->at(i)->location() == Extension::COMPONENT) | 168 if (service->extensions()->at(i)->location() == Extension::COMPONENT) |
| 168 continue; | 169 continue; |
| 169 if (service->AllowFileAccess(service->extensions()->at(i))) { | 170 if (service->AllowFileAccess(service->extensions()->at(i))) { |
| 170 ui_test_utils::WindowedNotificationObserver user_scripts_observer( | 171 ui_test_utils::WindowedNotificationObserver user_scripts_observer( |
| 171 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 172 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
| 172 NotificationService::AllSources()); | 173 content::NotificationService::AllSources()); |
| 173 service->SetAllowFileAccess(service->extensions()->at(i), false); | 174 service->SetAllowFileAccess(service->extensions()->at(i), false); |
| 174 user_scripts_observer.Wait(); | 175 user_scripts_observer.Wait(); |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 | 178 |
| 178 TestInjection(false, false); | 179 TestInjection(false, false); |
| 179 } | 180 } |
| 180 | 181 |
| 181 // ExtensionsLoadTest | 182 // ExtensionsLoadTest |
| 182 // Ensures that we can startup the browser with --load-extension and see them | 183 // Ensures that we can startup the browser with --load-extension and see them |
| (...skipping 17 matching lines...) Expand all Loading... |
| 200 #if defined(OS_LINUX) && defined(ARCH_CPU_64_BITS) | 201 #if defined(OS_LINUX) && defined(ARCH_CPU_64_BITS) |
| 201 #define Maybe_Test FLAKY_Test | 202 #define Maybe_Test FLAKY_Test |
| 202 #else | 203 #else |
| 203 #define Maybe_Test Test | 204 #define Maybe_Test Test |
| 204 #endif | 205 #endif |
| 205 | 206 |
| 206 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Maybe_Test) { | 207 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Maybe_Test) { |
| 207 WaitForServicesToStart(1, true); | 208 WaitForServicesToStart(1, true); |
| 208 TestInjection(true, true); | 209 TestInjection(true, true); |
| 209 } | 210 } |
| OLD | NEW |