OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/cancelable_callback.h" | 6 #include "base/cancelable_callback.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 }; | 148 }; |
149 | 149 |
150 // Used to block until a dev tools window gets beforeunload event. | 150 // Used to block until a dev tools window gets beforeunload event. |
151 class DevToolsWindowBeforeUnloadObserver | 151 class DevToolsWindowBeforeUnloadObserver |
152 : public content::WebContentsObserver { | 152 : public content::WebContentsObserver { |
153 public: | 153 public: |
154 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); | 154 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); |
155 void Wait(); | 155 void Wait(); |
156 private: | 156 private: |
157 // Invoked when the beforeunload handler fires. | 157 // Invoked when the beforeunload handler fires. |
158 virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE; | 158 virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) override; |
159 | 159 |
160 bool m_fired; | 160 bool m_fired; |
161 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 161 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
162 DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver); | 162 DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver); |
163 }; | 163 }; |
164 | 164 |
165 DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver( | 165 DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver( |
166 DevToolsWindow* devtools_window) | 166 DevToolsWindow* devtools_window) |
167 : WebContentsObserver( | 167 : WebContentsObserver( |
168 DevToolsWindowTesting::Get(devtools_window)->main_web_contents()), | 168 DevToolsWindowTesting::Get(devtools_window)->main_web_contents()), |
169 m_fired(false) { | 169 m_fired(false) { |
170 } | 170 } |
171 | 171 |
172 void DevToolsWindowBeforeUnloadObserver::Wait() { | 172 void DevToolsWindowBeforeUnloadObserver::Wait() { |
173 if (m_fired) | 173 if (m_fired) |
174 return; | 174 return; |
175 message_loop_runner_ = new content::MessageLoopRunner; | 175 message_loop_runner_ = new content::MessageLoopRunner; |
176 message_loop_runner_->Run(); | 176 message_loop_runner_->Run(); |
177 } | 177 } |
178 | 178 |
179 void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( | 179 void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( |
180 const base::TimeTicks& proceed_time) { | 180 const base::TimeTicks& proceed_time) { |
181 m_fired = true; | 181 m_fired = true; |
182 if (message_loop_runner_.get()) | 182 if (message_loop_runner_.get()) |
183 message_loop_runner_->Quit(); | 183 message_loop_runner_->Quit(); |
184 } | 184 } |
185 | 185 |
186 class DevToolsBeforeUnloadTest: public DevToolsSanityTest { | 186 class DevToolsBeforeUnloadTest: public DevToolsSanityTest { |
187 public: | 187 public: |
188 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 188 virtual void SetUpCommandLine(CommandLine* command_line) override { |
189 command_line->AppendSwitch( | 189 command_line->AppendSwitch( |
190 switches::kDisableHangMonitor); | 190 switches::kDisableHangMonitor); |
191 } | 191 } |
192 | 192 |
193 void CloseInspectedTab() { | 193 void CloseInspectedTab() { |
194 browser()->tab_strip_model()->CloseWebContentsAt(0, | 194 browser()->tab_strip_model()->CloseWebContentsAt(0, |
195 TabStripModel::CLOSE_NONE); | 195 TabStripModel::CLOSE_NONE); |
196 } | 196 } |
197 | 197 |
198 void CloseDevToolsWindowAsync() { | 198 void CloseDevToolsWindowAsync() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 JavaScriptAppModalDialog* js_dialog = | 275 JavaScriptAppModalDialog* js_dialog = |
276 static_cast<JavaScriptAppModalDialog*>(dialog); | 276 static_cast<JavaScriptAppModalDialog*>(dialog); |
277 NativeAppModalDialog* native_dialog = js_dialog->native_dialog(); | 277 NativeAppModalDialog* native_dialog = js_dialog->native_dialog(); |
278 EXPECT_TRUE(native_dialog); | 278 EXPECT_TRUE(native_dialog); |
279 return native_dialog; | 279 return native_dialog; |
280 } | 280 } |
281 }; | 281 }; |
282 | 282 |
283 class DevToolsUnresponsiveBeforeUnloadTest: public DevToolsBeforeUnloadTest { | 283 class DevToolsUnresponsiveBeforeUnloadTest: public DevToolsBeforeUnloadTest { |
284 public: | 284 public: |
285 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {} | 285 virtual void SetUpCommandLine(CommandLine* command_line) override {} |
286 }; | 286 }; |
287 | 287 |
288 void TimeoutCallback(const std::string& timeout_message) { | 288 void TimeoutCallback(const std::string& timeout_message) { |
289 ADD_FAILURE() << timeout_message; | 289 ADD_FAILURE() << timeout_message; |
290 base::MessageLoop::current()->Quit(); | 290 base::MessageLoop::current()->Quit(); |
291 } | 291 } |
292 | 292 |
293 // Base class for DevTools tests that test devtools functionality for | 293 // Base class for DevTools tests that test devtools functionality for |
294 // extensions and content scripts. | 294 // extensions and content scripts. |
295 class DevToolsExtensionTest : public DevToolsSanityTest, | 295 class DevToolsExtensionTest : public DevToolsSanityTest, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 else | 359 else |
360 content::RunMessageLoop(); | 360 content::RunMessageLoop(); |
361 } | 361 } |
362 | 362 |
363 timeout.Cancel(); | 363 timeout.Cancel(); |
364 return true; | 364 return true; |
365 } | 365 } |
366 | 366 |
367 virtual void Observe(int type, | 367 virtual void Observe(int type, |
368 const content::NotificationSource& source, | 368 const content::NotificationSource& source, |
369 const content::NotificationDetails& details) OVERRIDE { | 369 const content::NotificationDetails& details) override { |
370 switch (type) { | 370 switch (type) { |
371 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: | 371 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: |
372 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: | 372 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: |
373 base::MessageLoopForUI::current()->Quit(); | 373 base::MessageLoopForUI::current()->Quit(); |
374 break; | 374 break; |
375 default: | 375 default: |
376 NOTREACHED(); | 376 NOTREACHED(); |
377 break; | 377 break; |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 base::FilePath test_extensions_dir_; | 381 base::FilePath test_extensions_dir_; |
382 }; | 382 }; |
383 | 383 |
384 class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest { | 384 class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest { |
385 public: | 385 public: |
386 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 386 virtual void SetUpCommandLine(CommandLine* command_line) override { |
387 command_line->AppendSwitch( | 387 command_line->AppendSwitch( |
388 extensions::switches::kEnableExperimentalExtensionApis); | 388 extensions::switches::kEnableExperimentalExtensionApis); |
389 } | 389 } |
390 }; | 390 }; |
391 | 391 |
392 class WorkerDevToolsSanityTest : public InProcessBrowserTest { | 392 class WorkerDevToolsSanityTest : public InProcessBrowserTest { |
393 public: | 393 public: |
394 WorkerDevToolsSanityTest() : window_(NULL) {} | 394 WorkerDevToolsSanityTest() : window_(NULL) {} |
395 | 395 |
396 protected: | 396 protected: |
(...skipping 14 matching lines...) Expand all Loading... |
411 : worker_data_(worker_data) { | 411 : worker_data_(worker_data) { |
412 } | 412 } |
413 | 413 |
414 private: | 414 private: |
415 virtual ~WorkerCreationObserver() {} | 415 virtual ~WorkerCreationObserver() {} |
416 | 416 |
417 virtual void WorkerCreated ( | 417 virtual void WorkerCreated ( |
418 const GURL& url, | 418 const GURL& url, |
419 const base::string16& name, | 419 const base::string16& name, |
420 int process_id, | 420 int process_id, |
421 int route_id) OVERRIDE { | 421 int route_id) override { |
422 worker_data_->worker_process_id = process_id; | 422 worker_data_->worker_process_id = process_id; |
423 worker_data_->worker_route_id = route_id; | 423 worker_data_->worker_route_id = route_id; |
424 WorkerService::GetInstance()->RemoveObserver(this); | 424 WorkerService::GetInstance()->RemoveObserver(this); |
425 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 425 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
426 base::MessageLoop::QuitClosure()); | 426 base::MessageLoop::QuitClosure()); |
427 delete this; | 427 delete this; |
428 } | 428 } |
429 scoped_refptr<WorkerData> worker_data_; | 429 scoped_refptr<WorkerData> worker_data_; |
430 }; | 430 }; |
431 | 431 |
432 class WorkerTerminationObserver : public WorkerServiceObserver { | 432 class WorkerTerminationObserver : public WorkerServiceObserver { |
433 public: | 433 public: |
434 explicit WorkerTerminationObserver(WorkerData* worker_data) | 434 explicit WorkerTerminationObserver(WorkerData* worker_data) |
435 : worker_data_(worker_data) { | 435 : worker_data_(worker_data) { |
436 } | 436 } |
437 | 437 |
438 private: | 438 private: |
439 virtual ~WorkerTerminationObserver() {} | 439 virtual ~WorkerTerminationObserver() {} |
440 | 440 |
441 virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE { | 441 virtual void WorkerDestroyed(int process_id, int route_id) override { |
442 ASSERT_EQ(worker_data_->worker_process_id, process_id); | 442 ASSERT_EQ(worker_data_->worker_process_id, process_id); |
443 ASSERT_EQ(worker_data_->worker_route_id, route_id); | 443 ASSERT_EQ(worker_data_->worker_route_id, route_id); |
444 WorkerService::GetInstance()->RemoveObserver(this); | 444 WorkerService::GetInstance()->RemoveObserver(this); |
445 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 445 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
446 base::MessageLoop::QuitClosure()); | 446 base::MessageLoop::QuitClosure()); |
447 delete this; | 447 delete this; |
448 } | 448 } |
449 scoped_refptr<WorkerData> worker_data_; | 449 scoped_refptr<WorkerData> worker_data_; |
450 }; | 450 }; |
451 | 451 |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 const std::string agent_id = agent_raw->GetId(); | 897 const std::string agent_id = agent_raw->GetId(); |
898 ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id).get()) | 898 ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id).get()) |
899 << "DevToolsAgentHost cannot be found by id"; | 899 << "DevToolsAgentHost cannot be found by id"; |
900 browser()->tab_strip_model()-> | 900 browser()->tab_strip_model()-> |
901 CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 901 CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
902 ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get()) | 902 ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get()) |
903 << "DevToolsAgentHost is not released when the tab is closed"; | 903 << "DevToolsAgentHost is not released when the tab is closed"; |
904 } | 904 } |
905 | 905 |
906 class RemoteDebuggingTest: public ExtensionApiTest { | 906 class RemoteDebuggingTest: public ExtensionApiTest { |
907 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 907 virtual void SetUpCommandLine(CommandLine* command_line) override { |
908 ExtensionApiTest::SetUpCommandLine(command_line); | 908 ExtensionApiTest::SetUpCommandLine(command_line); |
909 command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222"); | 909 command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222"); |
910 | 910 |
911 // Override the extension root path. | 911 // Override the extension root path. |
912 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 912 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
913 test_data_dir_ = test_data_dir_.AppendASCII("devtools"); | 913 test_data_dir_ = test_data_dir_.AppendASCII("devtools"); |
914 } | 914 } |
915 }; | 915 }; |
916 | 916 |
917 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { | 917 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { |
918 #if defined(OS_WIN) && defined(USE_ASH) | 918 #if defined(OS_WIN) && defined(USE_ASH) |
919 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 919 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
920 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 920 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
921 return; | 921 return; |
922 #endif | 922 #endif |
923 | 923 |
924 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; | 924 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; |
925 } | 925 } |
OLD | NEW |