| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/test/ui_test_utils.h" | 23 #include "chrome/test/ui_test_utils.h" |
| 24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 | 25 |
| 26 // This file contains high-level startup tests for the extensions system. We've | 26 // This file contains high-level startup tests for the extensions system. We've |
| 27 // had many silly bugs where command line flags did not get propagated correctly | 27 // had many silly bugs where command line flags did not get propagated correctly |
| 28 // into the services, so we didn't start correctly. | 28 // into the services, so we didn't start correctly. |
| 29 | 29 |
| 30 class ExtensionStartupTestBase | 30 class ExtensionStartupTestBase |
| 31 : public InProcessBrowserTest, public NotificationObserver { | 31 : public InProcessBrowserTest, public NotificationObserver { |
| 32 public: | 32 public: |
| 33 ExtensionStartupTestBase() | 33 ExtensionStartupTestBase() : enable_extensions_(false) { |
| 34 : enable_extensions_(false), enable_user_scripts_(false) { | |
| 35 } | 34 } |
| 36 | 35 |
| 37 protected: | 36 protected: |
| 38 // InProcessBrowserTest | 37 // InProcessBrowserTest |
| 39 virtual void SetUpCommandLine(CommandLine* command_line) { | 38 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 40 EnableDOMAutomation(); | 39 EnableDOMAutomation(); |
| 41 | 40 |
| 42 FilePath profile_dir; | 41 FilePath profile_dir; |
| 43 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); | 42 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); |
| 44 profile_dir = profile_dir.AppendASCII("Default"); | 43 profile_dir = profile_dir.AppendASCII("Default"); |
| 45 file_util::CreateDirectory(profile_dir); | 44 file_util::CreateDirectory(profile_dir); |
| 46 | 45 |
| 47 preferences_file_ = profile_dir.AppendASCII("Preferences"); | 46 preferences_file_ = profile_dir.AppendASCII("Preferences"); |
| 48 user_scripts_dir_ = profile_dir.AppendASCII("User Scripts"); | 47 user_scripts_dir_ = profile_dir.AppendASCII("User Scripts"); |
| 49 extensions_dir_ = profile_dir.AppendASCII("Extensions"); | 48 extensions_dir_ = profile_dir.AppendASCII("Extensions"); |
| 50 | 49 |
| 51 if (enable_extensions_) { | 50 if (enable_extensions_) { |
| 52 FilePath src_dir; | 51 FilePath src_dir; |
| 53 PathService::Get(chrome::DIR_TEST_DATA, &src_dir); | 52 PathService::Get(chrome::DIR_TEST_DATA, &src_dir); |
| 54 src_dir = src_dir.AppendASCII("extensions").AppendASCII("good"); | 53 src_dir = src_dir.AppendASCII("extensions").AppendASCII("good"); |
| 55 | 54 |
| 56 file_util::CopyFile(src_dir.AppendASCII("Preferences"), | 55 file_util::CopyFile(src_dir.AppendASCII("Preferences"), |
| 57 preferences_file_); | 56 preferences_file_); |
| 58 file_util::CopyDirectory(src_dir.AppendASCII("Extensions"), | 57 file_util::CopyDirectory(src_dir.AppendASCII("Extensions"), |
| 59 profile_dir, true); // recursive | 58 profile_dir, true); // recursive |
| 60 } else { | 59 } else { |
| 61 command_line->AppendSwitch(switches::kDisableExtensions); | 60 command_line->AppendSwitch(switches::kDisableExtensions); |
| 62 } | 61 } |
| 63 | 62 |
| 64 if (enable_user_scripts_) { | |
| 65 command_line->AppendSwitch(switches::kEnableUserScripts); | |
| 66 | |
| 67 FilePath src_dir; | |
| 68 PathService::Get(chrome::DIR_TEST_DATA, &src_dir); | |
| 69 src_dir = src_dir.AppendASCII("extensions").AppendASCII("good") | |
| 70 .AppendASCII("Extensions") | |
| 71 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 72 .AppendASCII("1.0.0.0"); | |
| 73 | |
| 74 file_util::CreateDirectory(user_scripts_dir_); | |
| 75 file_util::CopyFile(src_dir.AppendASCII("script2.js"), | |
| 76 user_scripts_dir_.AppendASCII("script2.user.js")); | |
| 77 } | |
| 78 | |
| 79 if (!load_extension_.value().empty()) { | 63 if (!load_extension_.value().empty()) { |
| 80 command_line->AppendSwitchWithValue(switches::kLoadExtension, | 64 command_line->AppendSwitchWithValue(switches::kLoadExtension, |
| 81 load_extension_.ToWStringHack()); | 65 load_extension_.ToWStringHack()); |
| 82 } | 66 } |
| 83 } | 67 } |
| 84 | 68 |
| 85 // NotificationObserver | 69 // NotificationObserver |
| 86 virtual void Observe(NotificationType type, | 70 virtual void Observe(NotificationType type, |
| 87 const NotificationSource& source, | 71 const NotificationSource& source, |
| 88 const NotificationDetails& details) { | 72 const NotificationDetails& details) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 browser()->GetSelectedTabContents()->render_view_host(), L"", | 133 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 150 L"window.domAutomationController.send(document.title == 'Modified')", | 134 L"window.domAutomationController.send(document.title == 'Modified')", |
| 151 &result); | 135 &result); |
| 152 EXPECT_EQ(expect_script, result); | 136 EXPECT_EQ(expect_script, result); |
| 153 } | 137 } |
| 154 | 138 |
| 155 FilePath preferences_file_; | 139 FilePath preferences_file_; |
| 156 FilePath extensions_dir_; | 140 FilePath extensions_dir_; |
| 157 FilePath user_scripts_dir_; | 141 FilePath user_scripts_dir_; |
| 158 bool enable_extensions_; | 142 bool enable_extensions_; |
| 159 bool enable_user_scripts_; | |
| 160 FilePath load_extension_; | 143 FilePath load_extension_; |
| 161 NotificationRegistrar registrar_; | 144 NotificationRegistrar registrar_; |
| 162 }; | 145 }; |
| 163 | 146 |
| 164 | 147 |
| 165 // ExtensionsStartupTest | 148 // ExtensionsStartupTest |
| 166 // Ensures that we can startup the browser with --enable-extensions and some | 149 // Ensures that we can startup the browser with --enable-extensions and some |
| 167 // extensions installed and see them run and do basic things. | 150 // extensions installed and see them run and do basic things. |
| 168 | 151 |
| 169 class ExtensionsStartupTest : public ExtensionStartupTestBase { | 152 class ExtensionsStartupTest : public ExtensionStartupTestBase { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 194 .AppendASCII("Extensions") | 177 .AppendASCII("Extensions") |
| 195 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 178 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 196 .AppendASCII("1.0.0.0"); | 179 .AppendASCII("1.0.0.0"); |
| 197 } | 180 } |
| 198 }; | 181 }; |
| 199 | 182 |
| 200 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Test) { | 183 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Test) { |
| 201 WaitForServicesToStart(1, false); | 184 WaitForServicesToStart(1, false); |
| 202 TestInjection(true, true); | 185 TestInjection(true, true); |
| 203 } | 186 } |
| 204 | |
| 205 | |
| 206 // ExtensionsStartupUserScriptTest | |
| 207 // Tests that we can startup with --enable-user-scripts and run user scripts and | |
| 208 // see them do basic things. | |
| 209 | |
| 210 class ExtensionsStartupUserScriptTest : public ExtensionStartupTestBase { | |
| 211 public: | |
| 212 ExtensionsStartupUserScriptTest() { | |
| 213 enable_user_scripts_ = true; | |
| 214 } | |
| 215 }; | |
| 216 | |
| 217 IN_PROC_BROWSER_TEST_F(ExtensionsStartupUserScriptTest, Test) { | |
| 218 WaitForServicesToStart(0, false); | |
| 219 TestInjection(false, true); | |
| 220 } | |
| 221 | |
| 222 // Ensure we don't inject into chrome:// URLs | |
| 223 IN_PROC_BROWSER_TEST_F(ExtensionsStartupUserScriptTest, NoInjectIntoChrome) { | |
| 224 WaitForServicesToStart(0, false); | |
| 225 | |
| 226 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab")); | |
| 227 | |
| 228 bool result = false; | |
| 229 ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
| 230 browser()->GetSelectedTabContents()->render_view_host(), L"", | |
| 231 L"window.domAutomationController.send(document.title == 'Modified')", | |
| 232 &result); | |
| 233 EXPECT_FALSE(result); | |
| 234 } | |
| OLD | NEW |