blob: b2a4778b08264ca897c57feb2729a7e6b1900e24 [file] [log] [blame]
[email protected]98cd15122012-01-05 16:27:481// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]cc273402009-05-12 09:20:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]900c3b22011-10-22 00:55:295#include "base/bind.h"
[email protected]4207d2b2011-11-28 18:09:216#include "base/cancelable_callback.h"
[email protected]cc273402009-05-12 09:20:337#include "base/command_line.h"
[email protected]ec6d5352011-12-19 14:48:348#include "base/compiler_specific.h"
[email protected]cf3b40e32011-08-02 06:45:039#include "base/memory/ref_counted.h"
[email protected]3985ba82010-07-29 21:44:1210#include "base/path_service.h"
[email protected]eabbfb12013-04-05 23:28:3511#include "base/prefs/pref_service.h"
[email protected]340f55d7c2013-06-10 20:49:1112#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2013#include "base/strings/utf_string_conversions.h"
[email protected]c711fe712011-07-25 12:43:3014#include "base/test/test_timeouts.h"
[email protected]fdf40f3e2013-07-11 23:55:4615#include "chrome/browser/chrome_notification_types.h"
[email protected]ead056352013-03-12 08:47:5416#include "chrome/browser/devtools/browser_list_tabcontents_provider.h"
[email protected]70019152012-12-19 11:44:1917#include "chrome/browser/devtools/devtools_window.h"
[email protected]965901382013-04-03 07:38:3918#include "chrome/browser/extensions/extension_apitest.h"
[email protected]ead056352013-03-12 08:47:5419#include "chrome/browser/extensions/extension_browsertest.h"
[email protected]eaa7dd182010-12-14 11:09:0020#include "chrome/browser/extensions/extension_service.h"
[email protected]d8c8f25f2011-11-02 18:18:0121#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]90354712013-11-16 00:06:3022#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]8ecad5e2010-12-02 21:18:3323#include "chrome/browser/profiles/profile.h"
[email protected]90354712013-11-16 00:06:3024#include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
25#include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
[email protected]7b5dc002010-11-16 23:08:1026#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1027#include "chrome/browser/ui/browser_commands.h"
[email protected]1692b80f72013-11-28 20:08:5828#include "chrome/browser/ui/browser_iterator.h"
[email protected]0d56fa7212012-11-15 23:34:0229#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]2c7b4d72009-10-21 07:17:1730#include "chrome/common/chrome_paths.h"
[email protected]ec6d5352011-12-19 14:48:3431#include "chrome/common/chrome_switches.h"
[email protected]eabbfb12013-04-05 23:28:3532#include "chrome/common/pref_names.h"
[email protected]0a57375a2013-03-07 22:18:5933#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3234#include "chrome/test/base/in_process_browser_test.h"
[email protected]b65d4bdcc2013-07-31 00:37:3335#include "chrome/test/base/test_switches.h"
[email protected]af44e7fb2011-07-29 18:32:3236#include "chrome/test/base/ui_test_utils.h"
[email protected]4967f792012-01-20 22:14:4037#include "content/public/browser/child_process_data.h"
[email protected]b0b67cfe2012-01-18 21:59:5738#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3639#include "content/public/browser/devtools_agent_host.h"
[email protected]0e12d7d2011-12-01 16:21:4440#include "content/public/browser/devtools_client_host.h"
[email protected]ead056352013-03-12 08:47:5441#include "content/public/browser/devtools_http_handler.h"
[email protected]0e12d7d2011-12-01 16:21:4442#include "content/public/browser/devtools_manager.h"
[email protected]87f3c082011-10-19 18:07:4443#include "content/public/browser/notification_registrar.h"
[email protected]ad50def52011-10-19 23:17:0744#include "content/public/browser/notification_service.h"
[email protected]9c1662b2012-03-06 15:44:3345#include "content/public/browser/render_view_host.h"
[email protected]6acde6352012-01-04 16:52:2046#include "content/public/browser/web_contents.h"
[email protected]724214ae2011-12-29 23:58:0047#include "content/public/browser/worker_service.h"
48#include "content/public/browser/worker_service_observer.h"
[email protected]965901382013-04-03 07:38:3949#include "content/public/common/content_switches.h"
[email protected]7d478cb2012-07-24 17:19:4250#include "content/public/test/browser_test_utils.h"
[email protected]59b0e602014-01-30 00:41:2451#include "extensions/browser/extension_system.h"
[email protected]c8d02992013-07-31 22:16:5152#include "extensions/common/switches.h"
[email protected]1946d9e2013-04-09 01:43:3753#include "net/socket/tcp_listen_socket.h"
[email protected]89b32522013-05-07 20:04:2154#include "net/test/spawned_test_server/spawned_test_server.h"
[email protected]cc273402009-05-12 09:20:3355
[email protected]631bb742011-11-02 11:29:3956using content::BrowserThread;
[email protected]0e12d7d2011-12-01 16:21:4457using content::DevToolsManager;
58using content::DevToolsAgentHost;
[email protected]c5eed492012-01-04 17:07:5059using content::NavigationController;
[email protected]eaabba22012-03-07 15:02:1160using content::RenderViewHost;
[email protected]6acde6352012-01-04 16:52:2061using content::WebContents;
[email protected]724214ae2011-12-29 23:58:0062using content::WorkerService;
63using content::WorkerServiceObserver;
[email protected]631bb742011-11-02 11:29:3964
[email protected]cc273402009-05-12 09:20:3365namespace {
66
[email protected]f72a1cc2010-04-30 07:17:3067const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html";
[email protected]f72a1cc2010-04-30 07:17:3068const char kPauseWhenLoadingDevTools[] =
69 "files/devtools/pause_when_loading_devtools.html";
70const char kPauseWhenScriptIsRunning[] =
71 "files/devtools/pause_when_script_is_running.html";
[email protected]f72a1cc2010-04-30 07:17:3072const char kPageWithContentScript[] =
73 "files/devtools/page_with_content_script.html";
[email protected]e344c392011-09-28 06:36:0374const char kNavigateBackTestPage[] =
75 "files/devtools/navigate_back.html";
[email protected]74568b052011-05-20 09:36:1476const char kChunkedTestPage[] = "chunked";
77const char kSlowTestPage[] =
78 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2";
[email protected]1fcef592011-07-20 07:16:3679const char kSharedWorkerTestPage[] =
80 "files/workers/workers_ui_shared_worker.html";
[email protected]867fd9232011-10-17 06:32:3481const char kReloadSharedWorkerTestPage[] =
82 "files/workers/debug_shared_worker_initialization.html";
[email protected]81762dd2009-09-24 15:16:1883
[email protected]ec6d5352011-12-19 14:48:3484void RunTestFunction(DevToolsWindow* window, const char* test_name) {
[email protected]1fcef592011-07-20 07:16:3685 std::string result;
86
87 // At first check that JavaScript part of the front-end is loaded by
88 // checking that global variable uiTests exists(it's created after all js
89 // files have been loaded) and has runTest method.
90 ASSERT_TRUE(
[email protected]b6987e02013-01-04 18:30:4391 content::ExecuteScriptAndExtractString(
[email protected]1fcef592011-07-20 07:16:3692 window->GetRenderViewHost(),
[email protected]06bc5d92013-01-02 22:44:1393 "window.domAutomationController.send("
94 " '' + (window.uiTests && (typeof uiTests.runTest)));",
[email protected]1fcef592011-07-20 07:16:3695 &result));
96
[email protected]b946b422014-03-18 22:53:4097 ASSERT_EQ("function", result) << "DevTools front-end is broken.";
98 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
99 window->GetRenderViewHost(),
100 base::StringPrintf("uiTests.runTest('%s')", test_name),
101 &result));
102 EXPECT_EQ("[OK]", result);
[email protected]1fcef592011-07-20 07:16:36103}
[email protected]cc273402009-05-12 09:20:33104
[email protected]b9c5d50b2014-01-16 20:37:43105} // namespace
106
[email protected]cc273402009-05-12 09:20:33107class DevToolsSanityTest : public InProcessBrowserTest {
108 public:
[email protected]1fcef592011-07-20 07:16:36109 DevToolsSanityTest()
110 : window_(NULL),
[email protected]90ca44272012-07-18 18:15:48111 inspected_rvh_(NULL) {}
[email protected]cc273402009-05-12 09:20:33112
[email protected]ff7a8f6f2009-06-10 09:44:36113 protected:
[email protected]f72a1cc2010-04-30 07:17:30114 void RunTest(const std::string& test_name, const std::string& test_page) {
[email protected]b9c5d50b2014-01-16 20:37:43115 OpenDevToolsWindow(test_page, false);
[email protected]ec6d5352011-12-19 14:48:34116 RunTestFunction(window_, test_name.c_str());
[email protected]ff7a8f6f2009-06-10 09:44:36117 CloseDevToolsWindow();
118 }
119
[email protected]5da96a42013-11-21 06:49:21120 void LoadTestPage(const std::string& test_page) {
[email protected]95409e12010-08-17 20:07:11121 GURL url = test_server()->GetURL(test_page);
[email protected]cc273402009-05-12 09:20:33122 ui_test_utils::NavigateToURL(browser(), url);
[email protected]5da96a42013-11-21 06:49:21123 }
124
[email protected]b9c5d50b2014-01-16 20:37:43125 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) {
[email protected]5da96a42013-11-21 06:49:21126 ASSERT_TRUE(test_server()->Start());
127 LoadTestPage(test_page);
[email protected]cc273402009-05-12 09:20:33128
[email protected]151a63d2011-12-20 22:32:52129 inspected_rvh_ = GetInspectedTab()->GetRenderViewHost();
[email protected]b9c5d50b2014-01-16 20:37:43130 window_ =
131 DevToolsWindow::OpenDevToolsWindowForTest(inspected_rvh_, is_docked);
[email protected]9fc94c6d2014-02-12 14:48:48132 ui_test_utils::WaitUntilDevToolsWindowLoaded(window_);
[email protected]cc273402009-05-12 09:20:33133 }
134
[email protected]6acde6352012-01-04 16:52:20135 WebContents* GetInspectedTab() {
[email protected]36953572013-01-14 18:38:10136 return browser()->tab_strip_model()->GetWebContentsAt(0);
[email protected]13a6abf82009-10-31 08:42:21137 }
138
[email protected]a1406cb2013-10-16 14:30:43139 void ToggleDevToolsWindow() {
140 content::WindowedNotificationObserver close_observer(
141 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
142 content::Source<content::WebContents>(window_->web_contents()));
143 DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false,
[email protected]c934c382013-11-01 00:36:01144 DevToolsToggleAction::Toggle());
[email protected]a1406cb2013-10-16 14:30:43145 close_observer.Wait();
146 }
147
[email protected]b9c5d50b2014-01-16 20:37:43148 void ToggleDevToolsWindowDontWait() {
149 DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false,
150 DevToolsToggleAction::Toggle());
151 }
152
[email protected]1b91f5102009-06-09 15:31:30153 void CloseDevToolsWindow() {
[email protected]d9f9b792009-06-24 13:17:12154 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]a1406cb2013-10-16 14:30:43155 content::WindowedNotificationObserver close_observer(
156 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
157 content::Source<content::WebContents>(window_->web_contents()));
[email protected]94305ee92013-04-01 14:19:58158 devtools_manager->CloseAllClientHosts();
[email protected]a1406cb2013-10-16 14:30:43159 close_observer.Wait();
[email protected]1b91f5102009-06-09 15:31:30160 }
161
[email protected]1b91f5102009-06-09 15:31:30162 DevToolsWindow* window_;
163 RenderViewHost* inspected_rvh_;
[email protected]cc273402009-05-12 09:20:33164};
165
[email protected]a1406cb2013-10-16 14:30:43166// Used to block until a dev tools window gets beforeunload event.
167class DevToolsWindowBeforeUnloadObserver
168 : public content::WebContentsObserver {
169 public:
[email protected]90354712013-11-16 00:06:30170 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*);
171 void Wait();
[email protected]a1406cb2013-10-16 14:30:43172 private:
173 // Invoked when the beforeunload handler fires.
174 virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE;
175
176 bool m_fired;
[email protected]90354712013-11-16 00:06:30177 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
[email protected]a1406cb2013-10-16 14:30:43178 DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver);
179};
180
181DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver(
[email protected]90354712013-11-16 00:06:30182 DevToolsWindow* devtools_window)
183 : WebContentsObserver(devtools_window->web_contents()),
[email protected]a1406cb2013-10-16 14:30:43184 m_fired(false) {
185}
186
[email protected]90354712013-11-16 00:06:30187void DevToolsWindowBeforeUnloadObserver::Wait() {
188 if (m_fired)
189 return;
190 message_loop_runner_ = new content::MessageLoopRunner;
191 message_loop_runner_->Run();
[email protected]a1406cb2013-10-16 14:30:43192}
193
194void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired(
195 const base::TimeTicks& proceed_time) {
196 m_fired = true;
[email protected]90354712013-11-16 00:06:30197 if (message_loop_runner_.get())
198 message_loop_runner_->Quit();
[email protected]a1406cb2013-10-16 14:30:43199}
200
[email protected]90354712013-11-16 00:06:30201class DevToolsBeforeUnloadTest: public DevToolsSanityTest {
202 public:
[email protected]f9631b92013-12-10 22:19:48203 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
204 command_line->AppendSwitch(
205 switches::kDisableHangMonitor);
206 }
207
[email protected]90354712013-11-16 00:06:30208 void CloseInspectedTab() {
209 browser()->tab_strip_model()->CloseWebContentsAt(0,
210 TabStripModel::CLOSE_NONE);
211 }
212
213 void CloseDockedDevTools() {
[email protected]b9c5d50b2014-01-16 20:37:43214 ToggleDevToolsWindowDontWait();
[email protected]90354712013-11-16 00:06:30215 }
216
217 void CloseUndockedDevTools() {
218 chrome::CloseWindow(window_->browser());
219 }
220
221 void CloseInspectedBrowser() {
222 chrome::CloseWindow(browser());
223 }
224 protected:
225 void InjectBeforeUnloadListener(content::WebContents* web_contents) {
226 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
227 "window.addEventListener('beforeunload',"
228 "function(event) { event.returnValue = 'Foo'; });"));
229 }
230
[email protected]b9c5d50b2014-01-16 20:37:43231 void RunBeforeUnloadSanityTest(bool is_docked,
232 base::Callback<void(void)> close_method,
233 bool wait_for_browser_close = true) {
234 OpenDevToolsWindow(kDebuggerTestPage, is_docked);
[email protected]90354712013-11-16 00:06:30235 content::WindowedNotificationObserver devtools_close_observer(
236 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
237 content::Source<content::WebContents>(window_->web_contents()));
238 InjectBeforeUnloadListener(window_->web_contents());
239 {
240 DevToolsWindowBeforeUnloadObserver before_unload_observer(window_);
241 close_method.Run();
242 CancelModalDialog();
243 before_unload_observer.Wait();
244 }
245 {
246 content::WindowedNotificationObserver close_observer(
247 chrome::NOTIFICATION_BROWSER_CLOSED,
248 content::Source<Browser>(browser()));
249 close_method.Run();
250 AcceptModalDialog();
251 if (wait_for_browser_close)
252 close_observer.Wait();
253 }
254 devtools_close_observer.Wait();
255 }
256
257 DevToolsWindow* OpenDevToolWindowOnWebContents(
[email protected]b9c5d50b2014-01-16 20:37:43258 content::WebContents* contents, bool is_docked) {
[email protected]b9c5d50b2014-01-16 20:37:43259 DevToolsWindow* window = DevToolsWindow::OpenDevToolsWindowForTest(
260 contents->GetRenderViewHost(), is_docked);
[email protected]9fc94c6d2014-02-12 14:48:48261 ui_test_utils::WaitUntilDevToolsWindowLoaded(window);
[email protected]90354712013-11-16 00:06:30262 return window;
263 }
264
[email protected]1692b80f72013-11-28 20:08:58265 void OpenDevToolsPopupWindow(DevToolsWindow* devtools_window) {
266 content::WindowedNotificationObserver observer(
267 content::NOTIFICATION_LOAD_STOP,
268 content::NotificationService::AllSources());
269 ASSERT_TRUE(content::ExecuteScript(
270 devtools_window->web_contents()->GetRenderViewHost(),
271 "window.open(\"\", \"\", \"location=0\");"));
272 observer.Wait();
273 }
274
275 void CloseDevToolsPopupWindow(DevToolsWindow* devtools_window) {
276 Browser* popup_browser = NULL;
277 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
278 if (it->is_devtools()) {
279 content::WebContents* contents =
280 it->tab_strip_model()->GetWebContentsAt(0);
281 if (devtools_window->web_contents() != contents) {
282 popup_browser = *it;
283 break;
284 }
285 }
286 }
287 ASSERT_FALSE(popup_browser == NULL);
288 content::WindowedNotificationObserver close_observer(
289 chrome::NOTIFICATION_BROWSER_CLOSED,
290 content::Source<Browser>(popup_browser));
291 chrome::CloseWindow(popup_browser);
292 close_observer.Wait();
293 }
294
[email protected]90354712013-11-16 00:06:30295 void AcceptModalDialog() {
296 NativeAppModalDialog* native_dialog = GetDialog();
297 native_dialog->AcceptAppModalDialog();
298 }
299
300 void CancelModalDialog() {
301 NativeAppModalDialog* native_dialog = GetDialog();
302 native_dialog->CancelAppModalDialog();
303 }
304
305 NativeAppModalDialog* GetDialog() {
306 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
307 EXPECT_TRUE(dialog->IsJavaScriptModalDialog());
308 JavaScriptAppModalDialog* js_dialog =
309 static_cast<JavaScriptAppModalDialog*>(dialog);
310 NativeAppModalDialog* native_dialog = js_dialog->native_dialog();
311 EXPECT_TRUE(native_dialog);
312 return native_dialog;
313 }
314};
315
[email protected]f9631b92013-12-10 22:19:48316class DevToolsUnresponsiveBeforeUnloadTest: public DevToolsBeforeUnloadTest {
317 public:
318 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {}
319};
320
[email protected]4207d2b2011-11-28 18:09:21321void TimeoutCallback(const std::string& timeout_message) {
[email protected]b946b422014-03-18 22:53:40322 ADD_FAILURE() << timeout_message;
[email protected]b3a25092013-05-28 22:08:16323 base::MessageLoop::current()->Quit();
[email protected]4207d2b2011-11-28 18:09:21324}
[email protected]680bc222009-10-27 10:46:22325
[email protected]2c7b4d72009-10-21 07:17:17326// Base class for DevTools tests that test devtools functionality for
327// extensions and content scripts.
[email protected]fb996d32011-12-21 12:55:30328class DevToolsExtensionTest : public DevToolsSanityTest,
329 public content::NotificationObserver {
[email protected]2c7b4d72009-10-21 07:17:17330 public:
[email protected]fb996d32011-12-21 12:55:30331 DevToolsExtensionTest() : DevToolsSanityTest() {
[email protected]2c7b4d72009-10-21 07:17:17332 PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_);
333 test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools");
334 test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions");
335 }
336
337 protected:
[email protected]4207d2b2011-11-28 18:09:21338 // Load an extension from test\data\devtools\extensions\<extension_name>
[email protected]2c7b4d72009-10-21 07:17:17339 void LoadExtension(const char* extension_name) {
[email protected]650b2d52013-02-10 03:41:45340 base::FilePath path = test_extensions_dir_.AppendASCII(extension_name);
[email protected]2c7b4d72009-10-21 07:17:17341 ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension.";
342 }
343
344 private:
[email protected]650b2d52013-02-10 03:41:45345 bool LoadExtensionFromPath(const base::FilePath& path) {
[email protected]06bdd2b2012-11-30 18:47:13346 ExtensionService* service = extensions::ExtensionSystem::Get(
347 browser()->profile())->extension_service();
[email protected]2c7b4d72009-10-21 07:17:17348 size_t num_before = service->extensions()->size();
349 {
[email protected]6c2381d2011-10-19 02:52:53350 content::NotificationRegistrar registrar;
[email protected]432115822011-07-10 15:52:27351 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
[email protected]ad50def52011-10-19 23:17:07352 content::NotificationService::AllSources());
[email protected]d4d57df2011-11-30 20:33:52353 base::CancelableClosure timeout(
[email protected]4207d2b2011-11-28 18:09:21354 base::Bind(&TimeoutCallback, "Extension load timed out."));
[email protected]b3a25092013-05-28 22:08:16355 base::MessageLoop::current()->PostDelayedTask(
[email protected]4173deb2013-06-07 15:21:04356 FROM_HERE, timeout.callback(), TestTimeouts::action_timeout());
[email protected]d8c8f25f2011-11-02 18:18:01357 extensions::UnpackedInstaller::Create(service)->Load(path);
[email protected]729eb632012-07-26 04:45:26358 content::RunMessageLoop();
[email protected]4207d2b2011-11-28 18:09:21359 timeout.Cancel();
[email protected]2c7b4d72009-10-21 07:17:17360 }
361 size_t num_after = service->extensions()->size();
[email protected]680bc222009-10-27 10:46:22362 if (num_after != (num_before + 1))
363 return false;
364
[email protected]d1fe1352012-04-26 00:47:32365 return WaitForExtensionViewsToLoad();
[email protected]680bc222009-10-27 10:46:22366 }
367
[email protected]d1fe1352012-04-26 00:47:32368 bool WaitForExtensionViewsToLoad() {
369 // Wait for all the extension render views that exist to finish loading.
370 // NOTE: This assumes that the extension views list is not changing while
[email protected]680bc222009-10-27 10:46:22371 // this method is running.
372
[email protected]6c2381d2011-10-19 02:52:53373 content::NotificationRegistrar registrar;
[email protected]432115822011-07-10 15:52:27374 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
[email protected]ad50def52011-10-19 23:17:07375 content::NotificationService::AllSources());
[email protected]d4d57df2011-11-30 20:33:52376 base::CancelableClosure timeout(
[email protected]4207d2b2011-11-28 18:09:21377 base::Bind(&TimeoutCallback, "Extension host load timed out."));
[email protected]b3a25092013-05-28 22:08:16378 base::MessageLoop::current()->PostDelayedTask(
[email protected]4173deb2013-06-07 15:21:04379 FROM_HERE, timeout.callback(), TestTimeouts::action_timeout());
[email protected]680bc222009-10-27 10:46:22380
[email protected]98b6d942013-11-10 00:34:07381 extensions::ProcessManager* manager =
[email protected]be93bba02012-10-24 16:44:03382 extensions::ExtensionSystem::Get(browser()->profile())->
383 process_manager();
[email protected]98b6d942013-11-10 00:34:07384 extensions::ProcessManager::ViewSet all_views = manager->GetAllViews();
385 for (extensions::ProcessManager::ViewSet::const_iterator iter =
[email protected]d1fe1352012-04-26 00:47:32386 all_views.begin();
387 iter != all_views.end();) {
388 if (!(*iter)->IsLoading())
[email protected]680bc222009-10-27 10:46:22389 ++iter;
390 else
[email protected]729eb632012-07-26 04:45:26391 content::RunMessageLoop();
[email protected]680bc222009-10-27 10:46:22392 }
393
[email protected]4207d2b2011-11-28 18:09:21394 timeout.Cancel();
[email protected]680bc222009-10-27 10:46:22395 return true;
[email protected]2c7b4d72009-10-21 07:17:17396 }
397
[email protected]b94584a2013-02-07 03:02:08398 virtual void Observe(int type,
399 const content::NotificationSource& source,
400 const content::NotificationDetails& details) OVERRIDE {
[email protected]432115822011-07-10 15:52:27401 switch (type) {
402 case chrome::NOTIFICATION_EXTENSION_LOADED:
403 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING:
[email protected]b3a25092013-05-28 22:08:16404 base::MessageLoopForUI::current()->Quit();
[email protected]2c7b4d72009-10-21 07:17:17405 break;
[email protected]2c7b4d72009-10-21 07:17:17406 default:
407 NOTREACHED();
408 break;
409 }
410 }
411
[email protected]650b2d52013-02-10 03:41:45412 base::FilePath test_extensions_dir_;
[email protected]2c7b4d72009-10-21 07:17:17413};
414
[email protected]e89c05a2011-12-26 08:51:57415class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest {
416 public:
[email protected]b94584a2013-02-07 03:02:08417 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]c8d02992013-07-31 22:16:51418 command_line->AppendSwitch(
419 extensions::switches::kEnableExperimentalExtensionApis);
[email protected]e89c05a2011-12-26 08:51:57420 }
421};
422
[email protected]1fcef592011-07-20 07:16:36423class WorkerDevToolsSanityTest : public InProcessBrowserTest {
424 public:
[email protected]90ca44272012-07-18 18:15:48425 WorkerDevToolsSanityTest() : window_(NULL) {}
[email protected]1fcef592011-07-20 07:16:36426
427 protected:
[email protected]649d1c02012-04-27 02:56:21428 class WorkerData : public base::RefCountedThreadSafe<WorkerData> {
429 public:
[email protected]d9ddc0d2011-10-12 08:40:12430 WorkerData() : worker_process_id(0), worker_route_id(0) {}
[email protected]cf3b40e32011-08-02 06:45:03431 int worker_process_id;
432 int worker_route_id;
[email protected]649d1c02012-04-27 02:56:21433
434 private:
435 friend class base::RefCountedThreadSafe<WorkerData>;
436 ~WorkerData() {}
[email protected]d9ddc0d2011-10-12 08:40:12437 };
438
439 class WorkerCreationObserver : public WorkerServiceObserver {
440 public:
441 explicit WorkerCreationObserver(WorkerData* worker_data)
442 : worker_data_(worker_data) {
443 }
444
445 private:
446 virtual ~WorkerCreationObserver() {}
447
448 virtual void WorkerCreated (
[email protected]62151052012-02-01 18:40:48449 const GURL& url,
[email protected]96920152013-12-04 21:00:16450 const base::string16& name,
[email protected]62151052012-02-01 18:40:48451 int process_id,
452 int route_id) OVERRIDE {
453 worker_data_->worker_process_id = process_id;
454 worker_data_->worker_route_id = route_id;
[email protected]d9ddc0d2011-10-12 08:40:12455 WorkerService::GetInstance()->RemoveObserver(this);
456 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
[email protected]b3a25092013-05-28 22:08:16457 base::MessageLoop::QuitClosure());
[email protected]d9ddc0d2011-10-12 08:40:12458 delete this;
459 }
[email protected]d9ddc0d2011-10-12 08:40:12460 scoped_refptr<WorkerData> worker_data_;
[email protected]cf3b40e32011-08-02 06:45:03461 };
462
[email protected]867fd9232011-10-17 06:32:34463 class WorkerTerminationObserver : public WorkerServiceObserver {
464 public:
465 explicit WorkerTerminationObserver(WorkerData* worker_data)
466 : worker_data_(worker_data) {
467 }
468
469 private:
470 virtual ~WorkerTerminationObserver() {}
471
[email protected]62151052012-02-01 18:40:48472 virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE {
473 ASSERT_EQ(worker_data_->worker_process_id, process_id);
474 ASSERT_EQ(worker_data_->worker_route_id, route_id);
[email protected]867fd9232011-10-17 06:32:34475 WorkerService::GetInstance()->RemoveObserver(this);
476 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
[email protected]b3a25092013-05-28 22:08:16477 base::MessageLoop::QuitClosure());
[email protected]867fd9232011-10-17 06:32:34478 delete this;
479 }
[email protected]867fd9232011-10-17 06:32:34480 scoped_refptr<WorkerData> worker_data_;
481 };
482
[email protected]1fcef592011-07-20 07:16:36483 void RunTest(const char* test_name, const char* test_page) {
484 ASSERT_TRUE(test_server()->Start());
485 GURL url = test_server()->GetURL(test_page);
486 ui_test_utils::NavigateToURL(browser(), url);
487
[email protected]867fd9232011-10-17 06:32:34488 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker();
489 OpenDevToolsWindowForSharedWorker(worker_data.get());
[email protected]ec6d5352011-12-19 14:48:34490 RunTestFunction(window_, test_name);
[email protected]1fcef592011-07-20 07:16:36491 CloseDevToolsWindow();
492 }
493
[email protected]62151052012-02-01 18:40:48494 static void TerminateWorkerOnIOThread(scoped_refptr<WorkerData> worker_data) {
[email protected]b946b422014-03-18 22:53:40495 if (!WorkerService::GetInstance()->TerminateWorker(
496 worker_data->worker_process_id, worker_data->worker_route_id))
497 FAIL() << "Failed to terminate worker.\n";
498 WorkerService::GetInstance()->AddObserver(
499 new WorkerTerminationObserver(worker_data.get()));
[email protected]867fd9232011-10-17 06:32:34500 }
501
502 static void TerminateWorker(scoped_refptr<WorkerData> worker_data) {
[email protected]900c3b22011-10-22 00:55:29503 BrowserThread::PostTask(
504 BrowserThread::IO, FROM_HERE,
505 base::Bind(&TerminateWorkerOnIOThread, worker_data));
[email protected]729eb632012-07-26 04:45:26506 content::RunMessageLoop();
[email protected]867fd9232011-10-17 06:32:34507 }
508
[email protected]cf3b40e32011-08-02 06:45:03509 static void WaitForFirstSharedWorkerOnIOThread(
[email protected]d9ddc0d2011-10-12 08:40:12510 scoped_refptr<WorkerData> worker_data) {
[email protected]62151052012-02-01 18:40:48511 std::vector<WorkerService::WorkerInfo> worker_info =
512 WorkerService::GetInstance()->GetWorkers();
513 if (!worker_info.empty()) {
514 worker_data->worker_process_id = worker_info[0].process_id;
515 worker_data->worker_route_id = worker_info[0].route_id;
516 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
[email protected]b3a25092013-05-28 22:08:16517 base::MessageLoop::QuitClosure());
[email protected]62151052012-02-01 18:40:48518 return;
[email protected]1fcef592011-07-20 07:16:36519 }
[email protected]d9ddc0d2011-10-12 08:40:12520
521 WorkerService::GetInstance()->AddObserver(
522 new WorkerCreationObserver(worker_data.get()));
[email protected]1fcef592011-07-20 07:16:36523 }
524
[email protected]867fd9232011-10-17 06:32:34525 static scoped_refptr<WorkerData> WaitForFirstSharedWorker() {
[email protected]cf3b40e32011-08-02 06:45:03526 scoped_refptr<WorkerData> worker_data(new WorkerData());
[email protected]900c3b22011-10-22 00:55:29527 BrowserThread::PostTask(
528 BrowserThread::IO, FROM_HERE,
529 base::Bind(&WaitForFirstSharedWorkerOnIOThread, worker_data));
[email protected]729eb632012-07-26 04:45:26530 content::RunMessageLoop();
[email protected]867fd9232011-10-17 06:32:34531 return worker_data;
532 }
[email protected]cf3b40e32011-08-02 06:45:03533
[email protected]867fd9232011-10-17 06:32:34534 void OpenDevToolsWindowForSharedWorker(WorkerData* worker_data) {
[email protected]cf3b40e32011-08-02 06:45:03535 Profile* profile = browser()->profile();
[email protected]70fd1e82012-12-26 15:08:10536 scoped_refptr<DevToolsAgentHost> agent_host(
[email protected]98f66112012-12-25 12:59:36537 DevToolsAgentHost::GetForWorker(
[email protected]b3762af2011-09-08 06:23:46538 worker_data->worker_process_id,
[email protected]70fd1e82012-12-26 15:08:10539 worker_data->worker_route_id));
[email protected]b9c5d50b2014-01-16 20:37:43540 window_ = DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host);
[email protected]1fcef592011-07-20 07:16:36541 RenderViewHost* client_rvh = window_->GetRenderViewHost();
[email protected]7320a44e2012-05-22 17:01:11542 WebContents* client_contents = WebContents::FromRenderViewHost(client_rvh);
[email protected]9fc94c6d2014-02-12 14:48:48543 content::WaitForLoadStop(client_contents);
[email protected]1fcef592011-07-20 07:16:36544 }
545
546 void CloseDevToolsWindow() {
547 Browser* browser = window_->browser();
[email protected]a1406cb2013-10-16 14:30:43548 content::WindowedNotificationObserver close_observer(
549 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
550 content::Source<content::WebContents>(window_->web_contents()));
[email protected]0d56fa7212012-11-15 23:34:02551 browser->tab_strip_model()->CloseAllTabs();
[email protected]a1406cb2013-10-16 14:30:43552 close_observer.Wait();
[email protected]1fcef592011-07-20 07:16:36553 }
554
555 DevToolsWindow* window_;
556};
557
[email protected]90354712013-11-16 00:06:30558// Tests that BeforeUnload event gets called on docked devtools if
559// we try to close them.
560IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) {
[email protected]b9c5d50b2014-01-16 20:37:43561 RunBeforeUnloadSanityTest(true, base::Bind(
[email protected]90354712013-11-16 00:06:30562 &DevToolsBeforeUnloadTest::CloseDockedDevTools, this), false);
563}
564
565// Tests that BeforeUnload event gets called on docked devtools if
566// we try to close the inspected page.
567IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
568 TestDockedDevToolsInspectedTabClose) {
[email protected]b9c5d50b2014-01-16 20:37:43569 RunBeforeUnloadSanityTest(true, base::Bind(
[email protected]90354712013-11-16 00:06:30570 &DevToolsBeforeUnloadTest::CloseInspectedTab, this));
571}
572
573// Tests that BeforeUnload event gets called on docked devtools if
574// we try to close the inspected browser.
575IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
576 TestDockedDevToolsInspectedBrowserClose) {
[email protected]b9c5d50b2014-01-16 20:37:43577 RunBeforeUnloadSanityTest(true, base::Bind(
[email protected]90354712013-11-16 00:06:30578 &DevToolsBeforeUnloadTest::CloseInspectedBrowser, this));
579}
580
581// Tests that BeforeUnload event gets called on undocked devtools if
582// we try to close them.
583IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) {
[email protected]b9c5d50b2014-01-16 20:37:43584 RunBeforeUnloadSanityTest(false, base::Bind(
[email protected]90354712013-11-16 00:06:30585 &DevToolsBeforeUnloadTest::CloseUndockedDevTools, this), false);
586}
587
588// Tests that BeforeUnload event gets called on undocked devtools if
589// we try to close the inspected page.
590IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
591 TestUndockedDevToolsInspectedTabClose) {
[email protected]b9c5d50b2014-01-16 20:37:43592 RunBeforeUnloadSanityTest(false, base::Bind(
[email protected]90354712013-11-16 00:06:30593 &DevToolsBeforeUnloadTest::CloseInspectedTab, this));
594}
595
596// Tests that BeforeUnload event gets called on undocked devtools if
597// we try to close the inspected browser.
598IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
599 TestUndockedDevToolsInspectedBrowserClose) {
[email protected]b9c5d50b2014-01-16 20:37:43600 RunBeforeUnloadSanityTest(false, base::Bind(
[email protected]90354712013-11-16 00:06:30601 &DevToolsBeforeUnloadTest::CloseInspectedBrowser, this));
602}
603
604// Tests that BeforeUnload event gets called on undocked devtools if
605// we try to exit application.
606IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
607 TestUndockedDevToolsApplicationClose) {
[email protected]b9c5d50b2014-01-16 20:37:43608 RunBeforeUnloadSanityTest(false, base::Bind(
[email protected]90354712013-11-16 00:06:30609 &chrome::CloseAllBrowsers));
610}
611
[email protected]c0da7c12013-11-27 19:07:00612// Tests that inspected tab gets closed if devtools renderer
613// becomes unresponsive during beforeunload event interception.
614// @see http://crbug.com/322380
[email protected]f9631b92013-12-10 22:19:48615IN_PROC_BROWSER_TEST_F(DevToolsUnresponsiveBeforeUnloadTest,
[email protected]c0da7c12013-11-27 19:07:00616 TestUndockedDevToolsUnresponsive) {
617 ASSERT_TRUE(test_server()->Start());
618 LoadTestPage(kDebuggerTestPage);
619 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
[email protected]b9c5d50b2014-01-16 20:37:43620 GetInspectedTab(), false);
[email protected]c0da7c12013-11-27 19:07:00621 content::WindowedNotificationObserver devtools_close_observer(
622 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
623 content::Source<content::WebContents>(
624 devtools_window->web_contents()));
625
626 ASSERT_TRUE(content::ExecuteScript(
627 devtools_window->web_contents()->GetRenderViewHost(),
628 "window.addEventListener('beforeunload',"
629 "function(event) { while (true); });"));
630 CloseInspectedTab();
631 devtools_close_observer.Wait();
632}
633
[email protected]1692b80f72013-11-28 20:08:58634// Tests that closing worker inspector window does not cause browser crash
635// @see http://crbug.com/323031
636IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
637 TestWorkerWindowClosing) {
638 ASSERT_TRUE(test_server()->Start());
639 LoadTestPage(kDebuggerTestPage);
640 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
[email protected]b9c5d50b2014-01-16 20:37:43641 GetInspectedTab(), false);
[email protected]1692b80f72013-11-28 20:08:58642 content::WindowedNotificationObserver devtools_close_observer(
643 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
644 content::Source<content::WebContents>(
645 devtools_window->web_contents()));
646
647 OpenDevToolsPopupWindow(devtools_window);
648 CloseDevToolsPopupWindow(devtools_window);
649}
650
[email protected]90354712013-11-16 00:06:30651// Tests that BeforeUnload event gets called on devtools that are opened
652// on another devtools.
[email protected]68b36ac2013-11-19 23:56:03653IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
[email protected]21f0b4c42014-01-21 12:59:26654 TestDevToolsOnDevTools) {
[email protected]90354712013-11-16 00:06:30655 ASSERT_TRUE(test_server()->Start());
[email protected]5da96a42013-11-21 06:49:21656 LoadTestPage(kDebuggerTestPage);
[email protected]90354712013-11-16 00:06:30657
658 std::vector<DevToolsWindow*> windows;
659 std::vector<content::WindowedNotificationObserver*> close_observers;
660 content::WebContents* inspected_web_contents = GetInspectedTab();
661 for (int i = 0; i < 3; ++i) {
662 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
[email protected]b9c5d50b2014-01-16 20:37:43663 inspected_web_contents, i == 0);
[email protected]90354712013-11-16 00:06:30664 windows.push_back(devtools_window);
665 content::WindowedNotificationObserver* close_observer =
666 new content::WindowedNotificationObserver(
667 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
668 content::Source<content::WebContents>(
669 devtools_window->web_contents()));
670 close_observers.push_back(close_observer);
671 inspected_web_contents = devtools_window->web_contents();
672 }
673
674 InjectBeforeUnloadListener(windows[0]->web_contents());
675 InjectBeforeUnloadListener(windows[2]->web_contents());
676 // Try to close second devtools.
677 {
678 content::WindowedNotificationObserver cancel_browser(
679 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
680 content::NotificationService::AllSources());
681 chrome::CloseWindow(windows[1]->browser());
682 CancelModalDialog();
683 cancel_browser.Wait();
684 }
685 // Try to close browser window.
686 {
687 content::WindowedNotificationObserver cancel_browser(
688 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
689 content::NotificationService::AllSources());
690 chrome::CloseWindow(browser());
691 AcceptModalDialog();
692 CancelModalDialog();
693 cancel_browser.Wait();
694 }
695 // Try to exit application.
696 {
697 content::WindowedNotificationObserver close_observer(
698 chrome::NOTIFICATION_BROWSER_CLOSED,
699 content::Source<Browser>(browser()));
[email protected]9a718b22014-02-25 15:17:27700 chrome::IncrementKeepAliveCount();
[email protected]90354712013-11-16 00:06:30701 chrome::CloseAllBrowsers();
702 AcceptModalDialog();
703 AcceptModalDialog();
704 close_observer.Wait();
705 }
706 for (size_t i = 0; i < close_observers.size(); ++i) {
707 close_observers[i]->Wait();
708 delete close_observers[i];
709 }
[email protected]a1406cb2013-10-16 14:30:43710}
[email protected]1fcef592011-07-20 07:16:36711
[email protected]3f5866e2009-07-01 07:25:16712// Tests scripts panel showing.
[email protected]92094f312013-11-12 18:09:26713// TODO(pfeldman): figure out flake.
714IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_TestShowScriptsTab) {
[email protected]3f5866e2009-07-01 07:25:16715 RunTest("testShowScriptsTab", kDebuggerTestPage);
[email protected]a2f20232009-06-30 15:06:57716}
717
[email protected]13a6abf82009-10-31 08:42:21718// Tests that scripts tab is populated with inspected scripts even if it
719// hadn't been shown by the moment inspected paged refreshed.
720// @see http://crbug.com/26312
[email protected]a9b82d32012-01-25 19:55:38721IN_PROC_BROWSER_TEST_F(
722 DevToolsSanityTest,
[email protected]53cd43d2013-11-02 17:15:07723 TestScriptsTabIsPopulatedOnInspectedPageRefresh) {
[email protected]45aafc92010-06-07 14:18:53724 // Clear inspector settings to ensure that Elements will be
[email protected]13a6abf82009-10-31 08:42:21725 // current panel when DevTools window is open.
[email protected]eabbfb12013-04-05 23:28:35726 content::BrowserContext* browser_context =
727 GetInspectedTab()->GetBrowserContext();
728 Profile::FromBrowserContext(browser_context)->GetPrefs()->
729 ClearPref(prefs::kWebKitInspectorSettings);
730
[email protected]13a6abf82009-10-31 08:42:21731 RunTest("testScriptsTabIsPopulatedOnInspectedPageRefresh",
732 kDebuggerTestPage);
733}
734
[email protected]e89c05a2011-12-26 08:51:57735// Tests that chrome.devtools extension is correctly exposed.
[email protected]fb996d32011-12-21 12:55:30736IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
[email protected]e89c05a2011-12-26 08:51:57737 TestDevToolsExtensionAPI) {
[email protected]ec6d5352011-12-19 14:48:34738 LoadExtension("devtools_extension");
[email protected]007b3f82013-04-09 08:46:45739 RunTest("waitForTestResultsInConsole", std::string());
[email protected]ec6d5352011-12-19 14:48:34740}
741
[email protected]43466b92013-12-27 22:00:11742// Disabled on Windows due to flakiness. http://crbug.com/183649
743#if defined(OS_WIN)
[email protected]4319aa302013-06-12 19:59:45744#define MAYBE_TestDevToolsExtensionMessaging DISABLED_TestDevToolsExtensionMessaging
745#else
746#define MAYBE_TestDevToolsExtensionMessaging TestDevToolsExtensionMessaging
747#endif
748
[email protected]6dcc9432012-02-28 12:59:37749// Tests that chrome.devtools extension can communicate with background page
750// using extension messaging.
751IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
[email protected]4319aa302013-06-12 19:59:45752 MAYBE_TestDevToolsExtensionMessaging) {
[email protected]6dcc9432012-02-28 12:59:37753 LoadExtension("devtools_messaging");
[email protected]007b3f82013-04-09 08:46:45754 RunTest("waitForTestResultsInConsole", std::string());
[email protected]6dcc9432012-02-28 12:59:37755}
756
[email protected]e89c05a2011-12-26 08:51:57757// Tests that chrome.experimental.devtools extension is correctly exposed
758// when the extension has experimental permission.
759IN_PROC_BROWSER_TEST_F(DevToolsExperimentalExtensionTest,
760 TestDevToolsExperimentalExtensionAPI) {
761 LoadExtension("devtools_experimental");
[email protected]007b3f82013-04-09 08:46:45762 RunTest("waitForTestResultsInConsole", std::string());
[email protected]e89c05a2011-12-26 08:51:57763}
764
[email protected]92094f312013-11-12 18:09:26765// Tests that a content script is in the scripts list.
766// History of flakiness: http://crbug.com/114104, http://crbug.com/315288.
767IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
768 DISABLED_TestContentScriptIsPresent) {
[email protected]2c7b4d72009-10-21 07:17:17769 LoadExtension("simple_content_script");
770 RunTest("testContentScriptIsPresent", kPageWithContentScript);
771}
772
[email protected]77b9ab82013-11-11 16:11:34773// Fails quite consistently on Win XP: crbug.com/317725.
[email protected]3af10422013-12-27 06:22:39774#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]77b9ab82013-11-11 16:11:34775#define MAYBE_TestNoScriptDuplicatesOnPanelSwitch \
776 DISABLED_TestNoScriptDuplicatesOnPanelSwitch
777#else
778#define MAYBE_TestNoScriptDuplicatesOnPanelSwitch \
779 TestNoScriptDuplicatesOnPanelSwitch
780#endif
781
[email protected]f099ba32009-09-18 13:43:17782// Tests that scripts are not duplicated after Scripts Panel switch.
783IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
[email protected]77b9ab82013-11-11 16:11:34784 MAYBE_TestNoScriptDuplicatesOnPanelSwitch) {
[email protected]f099ba32009-09-18 13:43:17785 RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage);
786}
787
[email protected]53976e82009-11-11 17:08:31788// Tests that debugger works correctly if pause event occurs when DevTools
789// frontend is being loaded.
[email protected]4c9fd7c502013-12-18 10:18:02790// Disabled because of flakiness on all platforms: crbug.com/329036
[email protected]e043c2a2011-12-02 00:08:17791IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
[email protected]4c9fd7c502013-12-18 10:18:02792 DISABLED_TestPauseWhenLoadingDevTools) {
[email protected]53976e82009-11-11 17:08:31793 RunTest("testPauseWhenLoadingDevTools", kPauseWhenLoadingDevTools);
794}
795
[email protected]28ce8eb2009-11-30 09:20:45796// Tests that pressing 'Pause' will pause script execution if the script
797// is already running.
[email protected]b1179ef2013-04-08 12:33:48798#if defined(OS_WIN)
799// Timing out on windows tryservers: http://crbug.com/219515
800#define MAYBE_TestPauseWhenScriptIsRunning DISABLED_TestPauseWhenScriptIsRunning
[email protected]5808fe12013-05-10 02:42:45801#elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
802// Timing out on linux ARM bot: https://crbug/238453
803#define MAYBE_TestPauseWhenScriptIsRunning DISABLED_TestPauseWhenScriptIsRunning
[email protected]b1179ef2013-04-08 12:33:48804#else
805#define MAYBE_TestPauseWhenScriptIsRunning TestPauseWhenScriptIsRunning
806#endif
[email protected]81284382013-10-21 23:08:54807IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
[email protected]53cd43d2013-11-02 17:15:07808 MAYBE_TestPauseWhenScriptIsRunning) {
[email protected]6303b282012-02-14 00:55:37809 RunTest("testPauseWhenScriptIsRunning", kPauseWhenScriptIsRunning);
[email protected]28ce8eb2009-11-30 09:20:45810}
811
[email protected]74568b052011-05-20 09:36:14812// Tests network timing.
[email protected]5c80747a12011-08-26 01:35:57813IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkTiming) {
[email protected]74568b052011-05-20 09:36:14814 RunTest("testNetworkTiming", kSlowTestPage);
815}
816
817// Tests network size.
[email protected]689a4802012-10-12 15:12:22818IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSize) {
[email protected]74568b052011-05-20 09:36:14819 RunTest("testNetworkSize", kChunkedTestPage);
820}
821
822// Tests raw headers text.
[email protected]689a4802012-10-12 15:12:22823IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSyncSize) {
[email protected]74568b052011-05-20 09:36:14824 RunTest("testNetworkSyncSize", kChunkedTestPage);
825}
826
827// Tests raw headers text.
[email protected]689a4802012-10-12 15:12:22828IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkRawHeadersText) {
[email protected]74568b052011-05-20 09:36:14829 RunTest("testNetworkRawHeadersText", kChunkedTestPage);
830}
831
[email protected]e344c392011-09-28 06:36:03832// Tests that console messages are not duplicated on navigation back.
[email protected]3045cb842013-12-04 14:09:55833IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestConsoleOnNavigateBack) {
[email protected]e344c392011-09-28 06:36:03834 RunTest("testConsoleOnNavigateBack", kNavigateBackTestPage);
835}
836
[email protected]0a57375a2013-03-07 22:18:59837
838// Tests that external navigation from inspector page is always handled by
839// DevToolsWindow and results in inspected page navigation.
840IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsExternalNavigation) {
[email protected]b9c5d50b2014-01-16 20:37:43841 OpenDevToolsWindow(kDebuggerTestPage, true);
[email protected]0a57375a2013-03-07 22:18:59842 GURL url = test_server()->GetURL(kNavigateBackTestPage);
[email protected]9fc94c6d2014-02-12 14:48:48843 // TODO(dgozman): remove this once notifications are gone.
844 // Right now notifications happen after observers, so DevTools window is
845 // already loaded, but we still catch it's notification when looking for
846 // all sources.
847 content::WaitForLoadStop(window_->web_contents());
[email protected]0a57375a2013-03-07 22:18:59848 content::WindowedNotificationObserver observer(
849 content::NOTIFICATION_LOAD_STOP,
850 content::NotificationService::AllSources());
851 ASSERT_TRUE(content::ExecuteScript(
852 window_->web_contents(),
853 std::string("window.location = \"") + url.spec() + "\""));
854 observer.Wait();
855
856 ASSERT_TRUE(window_->web_contents()->GetURL().
[email protected]b3690f72014-02-17 00:32:48857 SchemeIs(content::kChromeDevToolsScheme));
[email protected]9fc94c6d2014-02-12 14:48:48858 ASSERT_EQ(url, GetInspectedTab()->GetURL());
[email protected]a1406cb2013-10-16 14:30:43859 CloseDevToolsWindow();
[email protected]0a57375a2013-03-07 22:18:59860}
861
[email protected]c5eb493a2013-12-28 00:14:41862#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]f25da5e22013-07-01 11:21:13863// Flakily times out: http://crbug.com/163411
864#define MAYBE_TestReattachAfterCrash DISABLED_TestReattachAfterCrash
865#else
866#define MAYBE_TestReattachAfterCrash TestReattachAfterCrash
867#endif
[email protected]a88511b2011-11-09 06:53:07868// Tests that inspector will reattach to inspected page when it is reloaded
869// after a crash. See http://crbug.com/101952
[email protected]f25da5e22013-07-01 11:21:13870IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, MAYBE_TestReattachAfterCrash) {
[email protected]b9c5d50b2014-01-16 20:37:43871 OpenDevToolsWindow(kDebuggerTestPage, false);
[email protected]a88511b2011-11-09 06:53:07872
[email protected]e0f3e142012-07-26 03:31:34873 content::CrashTab(GetInspectedTab());
[email protected]a7fe9112012-07-20 02:34:45874 content::WindowedNotificationObserver observer(
[email protected]a88511b2011-11-09 06:53:07875 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50876 content::Source<NavigationController>(
[email protected]36953572013-01-14 18:38:10877 &browser()->tab_strip_model()->GetActiveWebContents()->
878 GetController()));
[email protected]a37d4b02012-06-25 21:56:10879 chrome::Reload(browser(), CURRENT_TAB);
[email protected]a88511b2011-11-09 06:53:07880 observer.Wait();
881
[email protected]ec6d5352011-12-19 14:48:34882 RunTestFunction(window_, "testReattachAfterCrash");
[email protected]a88511b2011-11-09 06:53:07883 CloseDevToolsWindow();
884}
885
[email protected]3766a362011-06-21 17:56:18886IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) {
[email protected]b9c5d50b2014-01-16 20:37:43887 OpenDevToolsWindow("about:blank", false);
[email protected]3766a362011-06-21 17:56:18888 std::string result;
889 ASSERT_TRUE(
[email protected]b6987e02013-01-04 18:30:43890 content::ExecuteScriptAndExtractString(
[email protected]1fcef592011-07-20 07:16:36891 window_->GetRenderViewHost(),
[email protected]06bc5d92013-01-02 22:44:13892 "window.domAutomationController.send("
893 " '' + (window.uiTests && (typeof uiTests.runTest)));",
[email protected]3766a362011-06-21 17:56:18894 &result));
895 ASSERT_EQ("function", result) << "DevTools front-end is broken.";
896 CloseDevToolsWindow();
897}
898
[email protected]72e7af02011-11-28 09:11:09899#if defined(OS_MACOSX)
900#define MAYBE_InspectSharedWorker DISABLED_InspectSharedWorker
901#else
902#define MAYBE_InspectSharedWorker InspectSharedWorker
903#endif
[email protected]1b1dc99b2011-07-26 11:23:14904// Flakily fails with 25s timeout: http://crbug.com/89845
[email protected]72e7af02011-11-28 09:11:09905IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, MAYBE_InspectSharedWorker) {
[email protected]988e6582013-07-22 19:32:47906#if defined(OS_WIN) && defined(USE_ASH)
907 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
[email protected]b65d4bdcc2013-07-31 00:37:33908 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
[email protected]988e6582013-07-22 19:32:47909 return;
910#endif
911
[email protected]1fcef592011-07-20 07:16:36912 RunTest("testSharedWorker", kSharedWorkerTestPage);
913}
914
[email protected]72e7af02011-11-28 09:11:09915// http://crbug.com/100538
[email protected]3292ee02012-12-21 19:24:13916#if defined(OS_MACOSX) || defined(OS_WIN)
[email protected]72e7af02011-11-28 09:11:09917#define MAYBE_PauseInSharedWorkerInitialization DISABLED_PauseInSharedWorkerInitialization
[email protected]72e7af02011-11-28 09:11:09918#else
919#define MAYBE_PauseInSharedWorkerInitialization PauseInSharedWorkerInitialization
920#endif
[email protected]e043c2a2011-12-02 00:08:17921
[email protected]8d54beb2011-12-02 20:39:32922// http://crbug.com/106114 is masking
923// MAYBE_PauseInSharedWorkerInitialization into
924// DISABLED_PauseInSharedWorkerInitialization
[email protected]867fd9232011-10-17 06:32:34925IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest,
[email protected]0f391bf02012-05-18 13:02:52926 MAYBE_PauseInSharedWorkerInitialization) {
[email protected]9e1ee54c2012-03-12 17:47:13927 ASSERT_TRUE(test_server()->Start());
928 GURL url = test_server()->GetURL(kReloadSharedWorkerTestPage);
929 ui_test_utils::NavigateToURL(browser(), url);
[email protected]867fd9232011-10-17 06:32:34930
[email protected]9e1ee54c2012-03-12 17:47:13931 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker();
932 OpenDevToolsWindowForSharedWorker(worker_data.get());
[email protected]867fd9232011-10-17 06:32:34933
[email protected]9e1ee54c2012-03-12 17:47:13934 TerminateWorker(worker_data);
[email protected]867fd9232011-10-17 06:32:34935
[email protected]9e1ee54c2012-03-12 17:47:13936 // Reload page to restart the worker.
937 ui_test_utils::NavigateToURL(browser(), url);
[email protected]867fd9232011-10-17 06:32:34938
[email protected]9e1ee54c2012-03-12 17:47:13939 // Wait until worker script is paused on the debugger statement.
940 RunTestFunction(window_, "testPauseInSharedWorkerInitialization");
941 CloseDevToolsWindow();
942}
943
[email protected]a2dcc6732013-03-14 13:28:08944class DevToolsAgentHostTest : public InProcessBrowserTest {};
945
946// Tests DevToolsAgentHost retention by its target.
947IN_PROC_BROWSER_TEST_F(DevToolsAgentHostTest, TestAgentHostReleased) {
948 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
949 RenderViewHost* rvh = browser()->tab_strip_model()->GetWebContentsAt(0)->
950 GetRenderViewHost();
[email protected]cadac622013-06-11 16:46:36951 DevToolsAgentHost* agent_raw = DevToolsAgentHost::GetOrCreateFor(rvh).get();
[email protected]a2dcc6732013-03-14 13:28:08952 const std::string agent_id = agent_raw->GetId();
953 ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id)) <<
954 "DevToolsAgentHost cannot be found by id";
955 browser()->tab_strip_model()->
956 CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
[email protected]cadac622013-06-11 16:46:36957 ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get())
958 << "DevToolsAgentHost is not released when the tab is closed";
[email protected]a2dcc6732013-03-14 13:28:08959}
960
[email protected]965901382013-04-03 07:38:39961class RemoteDebuggingTest: public ExtensionApiTest {
962 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
963 ExtensionApiTest::SetUpCommandLine(command_line);
964 command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222");
[email protected]ead056352013-03-12 08:47:54965
[email protected]965901382013-04-03 07:38:39966 // Override the extension root path.
967 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
968 test_data_dir_ = test_data_dir_.AppendASCII("devtools");
[email protected]ead056352013-03-12 08:47:54969 }
970};
971
[email protected]8971c802013-10-26 01:44:57972IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) {
[email protected]988e6582013-07-22 19:32:47973#if defined(OS_WIN) && defined(USE_ASH)
974 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
[email protected]b65d4bdcc2013-07-31 00:37:33975 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
[email protected]988e6582013-07-22 19:32:47976 return;
977#endif
978
[email protected]965901382013-04-03 07:38:39979 ASSERT_TRUE(RunExtensionTest("target_list")) << message_;
[email protected]ead056352013-03-12 08:47:54980}