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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 }; | 152 }; |
153 | 153 |
154 // Used to block until a dev tools window gets beforeunload event. | 154 // Used to block until a dev tools window gets beforeunload event. |
155 class DevToolsWindowBeforeUnloadObserver | 155 class DevToolsWindowBeforeUnloadObserver |
156 : public content::WebContentsObserver { | 156 : public content::WebContentsObserver { |
157 public: | 157 public: |
158 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); | 158 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); |
159 void Wait(); | 159 void Wait(); |
160 private: | 160 private: |
161 // Invoked when the beforeunload handler fires. | 161 // Invoked when the beforeunload handler fires. |
162 virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) override; | 162 void BeforeUnloadFired(const base::TimeTicks& proceed_time) override; |
163 | 163 |
164 bool m_fired; | 164 bool m_fired; |
165 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 165 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
166 DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver); | 166 DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver); |
167 }; | 167 }; |
168 | 168 |
169 DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver( | 169 DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver( |
170 DevToolsWindow* devtools_window) | 170 DevToolsWindow* devtools_window) |
171 : WebContentsObserver( | 171 : WebContentsObserver( |
172 DevToolsWindowTesting::Get(devtools_window)->main_web_contents()), | 172 DevToolsWindowTesting::Get(devtools_window)->main_web_contents()), |
173 m_fired(false) { | 173 m_fired(false) { |
174 } | 174 } |
175 | 175 |
176 void DevToolsWindowBeforeUnloadObserver::Wait() { | 176 void DevToolsWindowBeforeUnloadObserver::Wait() { |
177 if (m_fired) | 177 if (m_fired) |
178 return; | 178 return; |
179 message_loop_runner_ = new content::MessageLoopRunner; | 179 message_loop_runner_ = new content::MessageLoopRunner; |
180 message_loop_runner_->Run(); | 180 message_loop_runner_->Run(); |
181 } | 181 } |
182 | 182 |
183 void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( | 183 void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( |
184 const base::TimeTicks& proceed_time) { | 184 const base::TimeTicks& proceed_time) { |
185 m_fired = true; | 185 m_fired = true; |
186 if (message_loop_runner_.get()) | 186 if (message_loop_runner_.get()) |
187 message_loop_runner_->Quit(); | 187 message_loop_runner_->Quit(); |
188 } | 188 } |
189 | 189 |
190 class DevToolsBeforeUnloadTest: public DevToolsSanityTest { | 190 class DevToolsBeforeUnloadTest: public DevToolsSanityTest { |
191 public: | 191 public: |
192 virtual void SetUpCommandLine(CommandLine* command_line) override { | 192 void SetUpCommandLine(CommandLine* command_line) override { |
193 command_line->AppendSwitch( | 193 command_line->AppendSwitch( |
194 switches::kDisableHangMonitor); | 194 switches::kDisableHangMonitor); |
195 } | 195 } |
196 | 196 |
197 void CloseInspectedTab() { | 197 void CloseInspectedTab() { |
198 browser()->tab_strip_model()->CloseWebContentsAt(0, | 198 browser()->tab_strip_model()->CloseWebContentsAt(0, |
199 TabStripModel::CLOSE_NONE); | 199 TabStripModel::CLOSE_NONE); |
200 } | 200 } |
201 | 201 |
202 void CloseDevToolsWindowAsync() { | 202 void CloseDevToolsWindowAsync() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 JavaScriptAppModalDialog* js_dialog = | 279 JavaScriptAppModalDialog* js_dialog = |
280 static_cast<JavaScriptAppModalDialog*>(dialog); | 280 static_cast<JavaScriptAppModalDialog*>(dialog); |
281 NativeAppModalDialog* native_dialog = js_dialog->native_dialog(); | 281 NativeAppModalDialog* native_dialog = js_dialog->native_dialog(); |
282 EXPECT_TRUE(native_dialog); | 282 EXPECT_TRUE(native_dialog); |
283 return native_dialog; | 283 return native_dialog; |
284 } | 284 } |
285 }; | 285 }; |
286 | 286 |
287 class DevToolsUnresponsiveBeforeUnloadTest: public DevToolsBeforeUnloadTest { | 287 class DevToolsUnresponsiveBeforeUnloadTest: public DevToolsBeforeUnloadTest { |
288 public: | 288 public: |
289 virtual void SetUpCommandLine(CommandLine* command_line) override {} | 289 void SetUpCommandLine(CommandLine* command_line) override {} |
290 }; | 290 }; |
291 | 291 |
292 void TimeoutCallback(const std::string& timeout_message) { | 292 void TimeoutCallback(const std::string& timeout_message) { |
293 ADD_FAILURE() << timeout_message; | 293 ADD_FAILURE() << timeout_message; |
294 base::MessageLoop::current()->Quit(); | 294 base::MessageLoop::current()->Quit(); |
295 } | 295 } |
296 | 296 |
297 // Base class for DevTools tests that test devtools functionality for | 297 // Base class for DevTools tests that test devtools functionality for |
298 // extensions and content scripts. | 298 // extensions and content scripts. |
299 class DevToolsExtensionTest : public DevToolsSanityTest, | 299 class DevToolsExtensionTest : public DevToolsSanityTest, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 if (!(*iter)->IsLoading()) | 361 if (!(*iter)->IsLoading()) |
362 ++iter; | 362 ++iter; |
363 else | 363 else |
364 content::RunMessageLoop(); | 364 content::RunMessageLoop(); |
365 } | 365 } |
366 | 366 |
367 timeout.Cancel(); | 367 timeout.Cancel(); |
368 return true; | 368 return true; |
369 } | 369 } |
370 | 370 |
371 virtual void Observe(int type, | 371 void Observe(int type, |
372 const content::NotificationSource& source, | 372 const content::NotificationSource& source, |
373 const content::NotificationDetails& details) override { | 373 const content::NotificationDetails& details) override { |
374 switch (type) { | 374 switch (type) { |
375 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: | 375 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: |
376 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: | 376 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: |
377 base::MessageLoopForUI::current()->Quit(); | 377 base::MessageLoopForUI::current()->Quit(); |
378 break; | 378 break; |
379 default: | 379 default: |
380 NOTREACHED(); | 380 NOTREACHED(); |
381 break; | 381 break; |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
385 base::FilePath test_extensions_dir_; | 385 base::FilePath test_extensions_dir_; |
386 }; | 386 }; |
387 | 387 |
388 class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest { | 388 class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest { |
389 public: | 389 public: |
390 virtual void SetUpCommandLine(CommandLine* command_line) override { | 390 void SetUpCommandLine(CommandLine* command_line) override { |
391 command_line->AppendSwitch( | 391 command_line->AppendSwitch( |
392 extensions::switches::kEnableExperimentalExtensionApis); | 392 extensions::switches::kEnableExperimentalExtensionApis); |
393 } | 393 } |
394 }; | 394 }; |
395 | 395 |
396 class WorkerDevToolsSanityTest : public InProcessBrowserTest { | 396 class WorkerDevToolsSanityTest : public InProcessBrowserTest { |
397 public: | 397 public: |
398 WorkerDevToolsSanityTest() : window_(NULL) {} | 398 WorkerDevToolsSanityTest() : window_(NULL) {} |
399 | 399 |
400 protected: | 400 protected: |
401 class WorkerData : public base::RefCountedThreadSafe<WorkerData> { | 401 class WorkerData : public base::RefCountedThreadSafe<WorkerData> { |
402 public: | 402 public: |
403 WorkerData() : worker_process_id(0), worker_route_id(0) {} | 403 WorkerData() : worker_process_id(0), worker_route_id(0) {} |
404 int worker_process_id; | 404 int worker_process_id; |
405 int worker_route_id; | 405 int worker_route_id; |
406 | 406 |
407 private: | 407 private: |
408 friend class base::RefCountedThreadSafe<WorkerData>; | 408 friend class base::RefCountedThreadSafe<WorkerData>; |
409 ~WorkerData() {} | 409 ~WorkerData() {} |
410 }; | 410 }; |
411 | 411 |
412 class WorkerCreationObserver : public WorkerServiceObserver { | 412 class WorkerCreationObserver : public WorkerServiceObserver { |
413 public: | 413 public: |
414 explicit WorkerCreationObserver(const std::string& path, | 414 explicit WorkerCreationObserver(const std::string& path, |
415 WorkerData* worker_data) | 415 WorkerData* worker_data) |
416 : path_(path), worker_data_(worker_data) {} | 416 : path_(path), worker_data_(worker_data) {} |
417 | 417 |
418 private: | 418 private: |
419 virtual ~WorkerCreationObserver() {} | 419 ~WorkerCreationObserver() override {} |
420 | 420 |
421 virtual void WorkerCreated ( | 421 void WorkerCreated(const GURL& url, |
422 const GURL& url, | 422 const base::string16& name, |
423 const base::string16& name, | 423 int process_id, |
424 int process_id, | 424 int route_id) override { |
425 int route_id) override { | |
426 if (url.path().rfind(path_) == std::string::npos) | 425 if (url.path().rfind(path_) == std::string::npos) |
427 return; | 426 return; |
428 worker_data_->worker_process_id = process_id; | 427 worker_data_->worker_process_id = process_id; |
429 worker_data_->worker_route_id = route_id; | 428 worker_data_->worker_route_id = route_id; |
430 WorkerService::GetInstance()->RemoveObserver(this); | 429 WorkerService::GetInstance()->RemoveObserver(this); |
431 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 430 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
432 base::MessageLoop::QuitClosure()); | 431 base::MessageLoop::QuitClosure()); |
433 delete this; | 432 delete this; |
434 } | 433 } |
435 std::string path_; | 434 std::string path_; |
436 scoped_refptr<WorkerData> worker_data_; | 435 scoped_refptr<WorkerData> worker_data_; |
437 }; | 436 }; |
438 | 437 |
439 class WorkerTerminationObserver : public WorkerServiceObserver { | 438 class WorkerTerminationObserver : public WorkerServiceObserver { |
440 public: | 439 public: |
441 explicit WorkerTerminationObserver(WorkerData* worker_data) | 440 explicit WorkerTerminationObserver(WorkerData* worker_data) |
442 : worker_data_(worker_data) { | 441 : worker_data_(worker_data) { |
443 } | 442 } |
444 | 443 |
445 private: | 444 private: |
446 virtual ~WorkerTerminationObserver() {} | 445 ~WorkerTerminationObserver() override {} |
447 | 446 |
448 virtual void WorkerDestroyed(int process_id, int route_id) override { | 447 void WorkerDestroyed(int process_id, int route_id) override { |
449 ASSERT_EQ(worker_data_->worker_process_id, process_id); | 448 ASSERT_EQ(worker_data_->worker_process_id, process_id); |
450 ASSERT_EQ(worker_data_->worker_route_id, route_id); | 449 ASSERT_EQ(worker_data_->worker_route_id, route_id); |
451 WorkerService::GetInstance()->RemoveObserver(this); | 450 WorkerService::GetInstance()->RemoveObserver(this); |
452 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 451 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
453 base::MessageLoop::QuitClosure()); | 452 base::MessageLoop::QuitClosure()); |
454 delete this; | 453 delete this; |
455 } | 454 } |
456 scoped_refptr<WorkerData> worker_data_; | 455 scoped_refptr<WorkerData> worker_data_; |
457 }; | 456 }; |
458 | 457 |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 const std::string agent_id = agent_raw->GetId(); | 911 const std::string agent_id = agent_raw->GetId(); |
913 ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id).get()) | 912 ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id).get()) |
914 << "DevToolsAgentHost cannot be found by id"; | 913 << "DevToolsAgentHost cannot be found by id"; |
915 browser()->tab_strip_model()-> | 914 browser()->tab_strip_model()-> |
916 CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 915 CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
917 ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get()) | 916 ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get()) |
918 << "DevToolsAgentHost is not released when the tab is closed"; | 917 << "DevToolsAgentHost is not released when the tab is closed"; |
919 } | 918 } |
920 | 919 |
921 class RemoteDebuggingTest: public ExtensionApiTest { | 920 class RemoteDebuggingTest: public ExtensionApiTest { |
922 virtual void SetUpCommandLine(CommandLine* command_line) override { | 921 void SetUpCommandLine(CommandLine* command_line) override { |
923 ExtensionApiTest::SetUpCommandLine(command_line); | 922 ExtensionApiTest::SetUpCommandLine(command_line); |
924 command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222"); | 923 command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222"); |
925 | 924 |
926 // Override the extension root path. | 925 // Override the extension root path. |
927 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 926 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
928 test_data_dir_ = test_data_dir_.AppendASCII("devtools"); | 927 test_data_dir_ = test_data_dir_.AppendASCII("devtools"); |
929 } | 928 } |
930 }; | 929 }; |
931 | 930 |
932 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { | 931 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { |
933 #if defined(OS_WIN) && defined(USE_ASH) | 932 #if defined(OS_WIN) && defined(USE_ASH) |
934 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 933 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
935 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 934 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
936 return; | 935 return; |
937 #endif | 936 #endif |
938 | 937 |
939 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; | 938 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; |
940 } | 939 } |
OLD | NEW |