| OLD | NEW |
| 1 #include <vector> | 1 #include <vector> |
| 2 | 2 |
| 3 #include "base/command_line.h" | 3 #include "base/command_line.h" |
| 4 #include "base/file_path.h" | 4 #include "base/file_path.h" |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/extensions/extensions_service.h" | 8 #include "chrome/browser/extensions/extensions_service.h" |
| 9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| 10 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/notification_details.h" | 13 #include "chrome/common/notification_details.h" |
| 13 #include "chrome/common/notification_observer.h" | 14 #include "chrome/common/notification_observer.h" |
| 14 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
| 15 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 16 #include "chrome/common/notification_type.h" | 17 #include "chrome/common/notification_type.h" |
| 17 #include "chrome/test/in_process_browser_test.h" | 18 #include "chrome/test/in_process_browser_test.h" |
| 18 #include "chrome/test/ui_test_utils.h" | 19 #include "chrome/test/ui_test_utils.h" |
| 19 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 20 | 21 |
| 21 // This file contains high-level regression tests for the extensions system. The | 22 // This file contains high-level startup tests for the extensions system. We've |
| 22 // goal here is not to test everything in depth, but to run the system as close | 23 // had many silly bugs where command line flags did not get propagated correctly |
| 23 // as possible end-to-end to find any gaps in test coverage in the lower-level | 24 // into the services, so we didn't start correctly. |
| 24 // unit tests. | |
| 25 | 25 |
| 26 class ExtensionStartupTestBase | 26 class ExtensionStartupTestBase |
| 27 : public InProcessBrowserTest, public NotificationObserver { | 27 : public InProcessBrowserTest, public NotificationObserver { |
| 28 public: | 28 public: |
| 29 ExtensionStartupTestBase() | 29 ExtensionStartupTestBase() |
| 30 : enable_extensions_(false), enable_user_scripts_(false) { | 30 : enable_extensions_(false), enable_user_scripts_(false) { |
| 31 EnableDOMAutomation(); | |
| 32 } | 31 } |
| 33 | 32 |
| 34 protected: | 33 protected: |
| 35 // InProcessBrowserTest | 34 // InProcessBrowserTest |
| 36 virtual void SetUpCommandLine(CommandLine* command_line) { | 35 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 36 EnableDOMAutomation(); |
| 37 |
| 37 FilePath profile_dir; | 38 FilePath profile_dir; |
| 38 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); | 39 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); |
| 39 profile_dir = profile_dir.AppendASCII("Default"); | 40 profile_dir = profile_dir.AppendASCII("Default"); |
| 40 file_util::CreateDirectory(profile_dir); | 41 file_util::CreateDirectory(profile_dir); |
| 41 | 42 |
| 42 preferences_file_ = profile_dir.AppendASCII("Preferences"); | 43 preferences_file_ = profile_dir.AppendASCII("Preferences"); |
| 43 user_scripts_dir_ = profile_dir.AppendASCII("User Scripts"); | 44 user_scripts_dir_ = profile_dir.AppendASCII("User Scripts"); |
| 44 extensions_dir_ = profile_dir.AppendASCII("Extensions"); | 45 extensions_dir_ = profile_dir.AppendASCII("Extensions"); |
| 45 | 46 |
| 46 if (enable_extensions_) { | 47 if (enable_extensions_) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 test_file = test_file.AppendASCII("extensions") | 139 test_file = test_file.AppendASCII("extensions") |
| 139 .AppendASCII("test_file.html"); | 140 .AppendASCII("test_file.html"); |
| 140 | 141 |
| 141 // Now we should be able to load a page affected by the content script and see | 142 // Now we should be able to load a page affected by the content script and see |
| 142 // the effect. | 143 // the effect. |
| 143 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file)); | 144 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file)); |
| 144 | 145 |
| 145 // Test that the content script ran. | 146 // Test that the content script ran. |
| 146 bool result = false; | 147 bool result = false; |
| 147 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 148 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 148 browser()->GetSelectedTabContents(), L"", | 149 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 149 L"window.domAutomationController.send(" | 150 L"window.domAutomationController.send(" |
| 150 L"document.defaultView.getComputedStyle(document.body, null)." | 151 L"document.defaultView.getComputedStyle(document.body, null)." |
| 151 L"getPropertyValue('background-color') == 'rgb(245, 245, 220)')", | 152 L"getPropertyValue('background-color') == 'rgb(245, 245, 220)')", |
| 152 &result); | 153 &result); |
| 153 EXPECT_TRUE(result); | 154 EXPECT_TRUE(result); |
| 154 | 155 |
| 155 result = false; | 156 result = false; |
| 156 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 157 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 157 browser()->GetSelectedTabContents(), L"", | 158 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 158 L"window.domAutomationController.send(document.title == 'Modified')", | 159 L"window.domAutomationController.send(document.title == 'Modified')", |
| 159 &result); | 160 &result); |
| 160 EXPECT_TRUE(result); | 161 EXPECT_TRUE(result); |
| 161 | |
| 162 // Load an extension page into the tab area to make sure it works. | |
| 163 result = false; | |
| 164 ui_test_utils::NavigateToURL( | |
| 165 browser(), | |
| 166 GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html")); | |
| 167 ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
| 168 browser()->GetSelectedTabContents(), L"", L"testTabsAPI()", &result); | |
| 169 EXPECT_TRUE(result); | |
| 170 | |
| 171 // TODO(aa): Move the stuff in ExtensionBrowserTest here? | |
| 172 } | 162 } |
| 173 | 163 |
| 174 | 164 |
| 175 // ExtensionsStartupUserScriptTest | 165 // ExtensionsStartupUserScriptTest |
| 176 // Tests that we can startup with --enable-user-scripts and run user sripts and | 166 // Tests that we can startup with --enable-user-scripts and run user sripts and |
| 177 // see them do basic things. | 167 // see them do basic things. |
| 178 | 168 |
| 179 class ExtensionsStartupUserScriptTest : public ExtensionStartupTestBase { | 169 class ExtensionsStartupUserScriptTest : public ExtensionStartupTestBase { |
| 180 public: | 170 public: |
| 181 ExtensionsStartupUserScriptTest() { | 171 ExtensionsStartupUserScriptTest() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 200 test_file = test_file.AppendASCII("extensions") | 190 test_file = test_file.AppendASCII("extensions") |
| 201 .AppendASCII("test_file.html"); | 191 .AppendASCII("test_file.html"); |
| 202 | 192 |
| 203 // Now we should be able to load a page affected by the content script and see | 193 // Now we should be able to load a page affected by the content script and see |
| 204 // the effect. | 194 // the effect. |
| 205 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file)); | 195 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file)); |
| 206 | 196 |
| 207 // Test that the user script ran. | 197 // Test that the user script ran. |
| 208 bool result = false; | 198 bool result = false; |
| 209 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 199 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 210 browser()->GetSelectedTabContents(), L"", | 200 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 211 L"window.domAutomationController.send(document.title == 'Modified')", | 201 L"window.domAutomationController.send(document.title == 'Modified')", |
| 212 &result); | 202 &result); |
| 213 EXPECT_TRUE(result); | 203 EXPECT_TRUE(result); |
| 214 } | 204 } |
| OLD | NEW |