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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/debugger/devtools_window.h" | 11 #include "chrome/browser/debugger/devtools_window.h" |
12 #include "chrome/browser/extensions/extension_host.h" | 12 #include "chrome/browser/extensions/extension_host.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.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/debugger/devtools_client_host.h" | 20 #include "content/browser/debugger/devtools_client_host.h" |
21 #include "content/browser/debugger/devtools_manager.h" | 21 #include "content/browser/debugger/devtools_manager.h" |
22 #include "content/browser/debugger/worker_devtools_manager.h" | 22 #include "content/browser/debugger/worker_devtools_manager.h" |
23 #include "content/browser/renderer_host/render_view_host.h" | 23 #include "content/browser/renderer_host/render_view_host.h" |
24 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
25 #include "content/browser/worker_host/worker_process_host.h" | 25 #include "content/browser/worker_host/worker_process_host.h" |
26 #include "content/browser/worker_host/worker_service.h" | 26 #include "content/browser/worker_host/worker_service.h" |
27 #include "content/browser/worker_host/worker_service_observer.h" | 27 #include "content/browser/worker_host/worker_service_observer.h" |
28 #include "content/common/worker_messages.h" | 28 #include "content/common/worker_messages.h" |
29 #include "content/common/notification_service.h" | |
30 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
31 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
| 31 #include "content/public/browser/notification_service.h" |
32 #include "net/test/test_server.h" | 32 #include "net/test/test_server.h" |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 // Used to block until a dev tools client window's browser is closed. | 36 // Used to block until a dev tools client window's browser is closed. |
37 class BrowserClosedObserver : public content::NotificationObserver { | 37 class BrowserClosedObserver : public content::NotificationObserver { |
38 public: | 38 public: |
39 explicit BrowserClosedObserver(Browser* browser) { | 39 explicit BrowserClosedObserver(Browser* browser) { |
40 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, | 40 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, |
41 content::Source<Browser>(browser)); | 41 content::Source<Browser>(browser)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 RunTestFuntion(window_, test_name.c_str()); | 117 RunTestFuntion(window_, test_name.c_str()); |
118 CloseDevToolsWindow(); | 118 CloseDevToolsWindow(); |
119 } | 119 } |
120 | 120 |
121 void OpenDevToolsWindow(const std::string& test_page) { | 121 void OpenDevToolsWindow(const std::string& test_page) { |
122 ASSERT_TRUE(test_server()->Start()); | 122 ASSERT_TRUE(test_server()->Start()); |
123 GURL url = test_server()->GetURL(test_page); | 123 GURL url = test_server()->GetURL(test_page); |
124 ui_test_utils::NavigateToURL(browser(), url); | 124 ui_test_utils::NavigateToURL(browser(), url); |
125 | 125 |
126 ui_test_utils::WindowedNotificationObserver observer( | 126 ui_test_utils::WindowedNotificationObserver observer( |
127 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources()); | 127 content::NOTIFICATION_LOAD_STOP, |
| 128 content::NotificationService::AllSources()); |
128 inspected_rvh_ = GetInspectedTab()->render_view_host(); | 129 inspected_rvh_ = GetInspectedTab()->render_view_host(); |
129 window_ = DevToolsWindow::OpenDevToolsWindow(inspected_rvh_); | 130 window_ = DevToolsWindow::OpenDevToolsWindow(inspected_rvh_); |
130 observer.Wait(); | 131 observer.Wait(); |
131 } | 132 } |
132 | 133 |
133 TabContents* GetInspectedTab() { | 134 TabContents* GetInspectedTab() { |
134 return browser()->GetTabContentsAt(0); | 135 return browser()->GetTabContentsAt(0); |
135 } | 136 } |
136 | 137 |
137 void CloseDevToolsWindow() { | 138 void CloseDevToolsWindow() { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension."; | 196 ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension."; |
196 } | 197 } |
197 | 198 |
198 private: | 199 private: |
199 bool LoadExtensionFromPath(const FilePath& path) { | 200 bool LoadExtensionFromPath(const FilePath& path) { |
200 ExtensionService* service = browser()->profile()->GetExtensionService(); | 201 ExtensionService* service = browser()->profile()->GetExtensionService(); |
201 size_t num_before = service->extensions()->size(); | 202 size_t num_before = service->extensions()->size(); |
202 { | 203 { |
203 content::NotificationRegistrar registrar; | 204 content::NotificationRegistrar registrar; |
204 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 205 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
205 NotificationService::AllSources()); | 206 content::NotificationService::AllSources()); |
206 CancelableQuitTask* delayed_quit = | 207 CancelableQuitTask* delayed_quit = |
207 new CancelableQuitTask("Extension load timed out."); | 208 new CancelableQuitTask("Extension load timed out."); |
208 MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, | 209 MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, |
209 4*1000); | 210 4*1000); |
210 service->LoadExtension(path); | 211 service->LoadExtension(path); |
211 ui_test_utils::RunMessageLoop(); | 212 ui_test_utils::RunMessageLoop(); |
212 delayed_quit->cancel(); | 213 delayed_quit->cancel(); |
213 } | 214 } |
214 size_t num_after = service->extensions()->size(); | 215 size_t num_after = service->extensions()->size(); |
215 if (num_after != (num_before + 1)) | 216 if (num_after != (num_before + 1)) |
216 return false; | 217 return false; |
217 | 218 |
218 return WaitForExtensionHostsToLoad(); | 219 return WaitForExtensionHostsToLoad(); |
219 } | 220 } |
220 | 221 |
221 bool WaitForExtensionHostsToLoad() { | 222 bool WaitForExtensionHostsToLoad() { |
222 // Wait for all the extension hosts that exist to finish loading. | 223 // Wait for all the extension hosts that exist to finish loading. |
223 // NOTE: This assumes that the extension host list is not changing while | 224 // NOTE: This assumes that the extension host list is not changing while |
224 // this method is running. | 225 // this method is running. |
225 | 226 |
226 content::NotificationRegistrar registrar; | 227 content::NotificationRegistrar registrar; |
227 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 228 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
228 NotificationService::AllSources()); | 229 content::NotificationService::AllSources()); |
229 CancelableQuitTask* delayed_quit = | 230 CancelableQuitTask* delayed_quit = |
230 new CancelableQuitTask("Extension host load timed out."); | 231 new CancelableQuitTask("Extension host load timed out."); |
231 MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, | 232 MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, |
232 4*1000); | 233 4*1000); |
233 | 234 |
234 ExtensionProcessManager* manager = | 235 ExtensionProcessManager* manager = |
235 browser()->profile()->GetExtensionProcessManager(); | 236 browser()->profile()->GetExtensionProcessManager(); |
236 for (ExtensionProcessManager::const_iterator iter = manager->begin(); | 237 for (ExtensionProcessManager::const_iterator iter = manager->begin(); |
237 iter != manager->end();) { | 238 iter != manager->end();) { |
238 if ((*iter)->did_stop_loading()) | 239 if ((*iter)->did_stop_loading()) |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 542 |
542 // Reload page to restart the worker. | 543 // Reload page to restart the worker. |
543 ui_test_utils::NavigateToURL(browser(), url); | 544 ui_test_utils::NavigateToURL(browser(), url); |
544 | 545 |
545 // Wait until worker script is paused on the debugger statement. | 546 // Wait until worker script is paused on the debugger statement. |
546 RunTestFuntion(window_, "testPauseInSharedWorkerInitialization"); | 547 RunTestFuntion(window_, "testPauseInSharedWorkerInitialization"); |
547 CloseDevToolsWindow(); | 548 CloseDevToolsWindow(); |
548 } | 549 } |
549 | 550 |
550 } // namespace | 551 } // namespace |
OLD | NEW |