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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 "files/devtools/pause_when_script_is_running.html"; | 69 "files/devtools/pause_when_script_is_running.html"; |
70 const char kPageWithContentScript[] = | 70 const char kPageWithContentScript[] = |
71 "files/devtools/page_with_content_script.html"; | 71 "files/devtools/page_with_content_script.html"; |
72 const char kNavigateBackTestPage[] = | 72 const char kNavigateBackTestPage[] = |
73 "files/devtools/navigate_back.html"; | 73 "files/devtools/navigate_back.html"; |
74 const char kChunkedTestPage[] = "chunked"; | 74 const char kChunkedTestPage[] = "chunked"; |
75 const char kSlowTestPage[] = | 75 const char kSlowTestPage[] = |
76 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; | 76 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; |
77 const char kSharedWorkerTestPage[] = | 77 const char kSharedWorkerTestPage[] = |
78 "files/workers/workers_ui_shared_worker.html"; | 78 "files/workers/workers_ui_shared_worker.html"; |
| 79 const char kSharedWorkerTestWorker[] = |
| 80 "files/workers/workers_ui_shared_worker.js"; |
79 const char kReloadSharedWorkerTestPage[] = | 81 const char kReloadSharedWorkerTestPage[] = |
80 "files/workers/debug_shared_worker_initialization.html"; | 82 "files/workers/debug_shared_worker_initialization.html"; |
| 83 const char kReloadSharedWorkerTestWorker[] = |
| 84 "files/workers/debug_shared_worker_initialization.js"; |
81 | 85 |
82 void RunTestFunction(DevToolsWindow* window, const char* test_name) { | 86 void RunTestFunction(DevToolsWindow* window, const char* test_name) { |
83 std::string result; | 87 std::string result; |
84 | 88 |
85 RenderViewHost* rvh = DevToolsWindowTesting::Get(window)-> | 89 RenderViewHost* rvh = DevToolsWindowTesting::Get(window)-> |
86 main_web_contents()->GetRenderViewHost(); | 90 main_web_contents()->GetRenderViewHost(); |
87 // At first check that JavaScript part of the front-end is loaded by | 91 // 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 | 92 // checking that global variable uiTests exists(it's created after all js |
89 // files have been loaded) and has runTest method. | 93 // files have been loaded) and has runTest method. |
90 ASSERT_TRUE( | 94 ASSERT_TRUE( |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 int worker_process_id; | 404 int worker_process_id; |
401 int worker_route_id; | 405 int worker_route_id; |
402 | 406 |
403 private: | 407 private: |
404 friend class base::RefCountedThreadSafe<WorkerData>; | 408 friend class base::RefCountedThreadSafe<WorkerData>; |
405 ~WorkerData() {} | 409 ~WorkerData() {} |
406 }; | 410 }; |
407 | 411 |
408 class WorkerCreationObserver : public WorkerServiceObserver { | 412 class WorkerCreationObserver : public WorkerServiceObserver { |
409 public: | 413 public: |
410 explicit WorkerCreationObserver(WorkerData* worker_data) | 414 explicit WorkerCreationObserver(const std::string& path, |
411 : worker_data_(worker_data) { | 415 WorkerData* worker_data) |
412 } | 416 : path_(path), worker_data_(worker_data) {} |
413 | 417 |
414 private: | 418 private: |
415 virtual ~WorkerCreationObserver() {} | 419 virtual ~WorkerCreationObserver() {} |
416 | 420 |
417 virtual void WorkerCreated ( | 421 virtual void WorkerCreated ( |
418 const GURL& url, | 422 const GURL& url, |
419 const base::string16& name, | 423 const base::string16& name, |
420 int process_id, | 424 int process_id, |
421 int route_id) override { | 425 int route_id) override { |
| 426 if (url.path().rfind(path_) == std::string::npos) |
| 427 return; |
422 worker_data_->worker_process_id = process_id; | 428 worker_data_->worker_process_id = process_id; |
423 worker_data_->worker_route_id = route_id; | 429 worker_data_->worker_route_id = route_id; |
424 WorkerService::GetInstance()->RemoveObserver(this); | 430 WorkerService::GetInstance()->RemoveObserver(this); |
425 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 431 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
426 base::MessageLoop::QuitClosure()); | 432 base::MessageLoop::QuitClosure()); |
427 delete this; | 433 delete this; |
428 } | 434 } |
| 435 std::string path_; |
429 scoped_refptr<WorkerData> worker_data_; | 436 scoped_refptr<WorkerData> worker_data_; |
430 }; | 437 }; |
431 | 438 |
432 class WorkerTerminationObserver : public WorkerServiceObserver { | 439 class WorkerTerminationObserver : public WorkerServiceObserver { |
433 public: | 440 public: |
434 explicit WorkerTerminationObserver(WorkerData* worker_data) | 441 explicit WorkerTerminationObserver(WorkerData* worker_data) |
435 : worker_data_(worker_data) { | 442 : worker_data_(worker_data) { |
436 } | 443 } |
437 | 444 |
438 private: | 445 private: |
439 virtual ~WorkerTerminationObserver() {} | 446 virtual ~WorkerTerminationObserver() {} |
440 | 447 |
441 virtual void WorkerDestroyed(int process_id, int route_id) override { | 448 virtual void WorkerDestroyed(int process_id, int route_id) override { |
442 ASSERT_EQ(worker_data_->worker_process_id, process_id); | 449 ASSERT_EQ(worker_data_->worker_process_id, process_id); |
443 ASSERT_EQ(worker_data_->worker_route_id, route_id); | 450 ASSERT_EQ(worker_data_->worker_route_id, route_id); |
444 WorkerService::GetInstance()->RemoveObserver(this); | 451 WorkerService::GetInstance()->RemoveObserver(this); |
445 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 452 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
446 base::MessageLoop::QuitClosure()); | 453 base::MessageLoop::QuitClosure()); |
447 delete this; | 454 delete this; |
448 } | 455 } |
449 scoped_refptr<WorkerData> worker_data_; | 456 scoped_refptr<WorkerData> worker_data_; |
450 }; | 457 }; |
451 | 458 |
452 void RunTest(const char* test_name, const char* test_page) { | 459 void RunTest(const char* test_name, |
| 460 const char* test_page, |
| 461 const char* worker_path) { |
453 ASSERT_TRUE(test_server()->Start()); | 462 ASSERT_TRUE(test_server()->Start()); |
454 GURL url = test_server()->GetURL(test_page); | 463 GURL url = test_server()->GetURL(test_page); |
455 ui_test_utils::NavigateToURL(browser(), url); | 464 ui_test_utils::NavigateToURL(browser(), url); |
456 | 465 |
457 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker(); | 466 scoped_refptr<WorkerData> worker_data = |
| 467 WaitForFirstSharedWorker(worker_path); |
458 OpenDevToolsWindowForSharedWorker(worker_data.get()); | 468 OpenDevToolsWindowForSharedWorker(worker_data.get()); |
459 RunTestFunction(window_, test_name); | 469 RunTestFunction(window_, test_name); |
460 CloseDevToolsWindow(); | 470 CloseDevToolsWindow(); |
461 } | 471 } |
462 | 472 |
463 static void TerminateWorkerOnIOThread(scoped_refptr<WorkerData> worker_data) { | 473 static void TerminateWorkerOnIOThread(scoped_refptr<WorkerData> worker_data) { |
464 if (!WorkerService::GetInstance()->TerminateWorker( | 474 if (!WorkerService::GetInstance()->TerminateWorker( |
465 worker_data->worker_process_id, worker_data->worker_route_id)) | 475 worker_data->worker_process_id, worker_data->worker_route_id)) |
466 FAIL() << "Failed to terminate worker.\n"; | 476 FAIL() << "Failed to terminate worker.\n"; |
467 WorkerService::GetInstance()->AddObserver( | 477 WorkerService::GetInstance()->AddObserver( |
468 new WorkerTerminationObserver(worker_data.get())); | 478 new WorkerTerminationObserver(worker_data.get())); |
469 } | 479 } |
470 | 480 |
471 static void TerminateWorker(scoped_refptr<WorkerData> worker_data) { | 481 static void TerminateWorker(scoped_refptr<WorkerData> worker_data) { |
472 BrowserThread::PostTask( | 482 BrowserThread::PostTask( |
473 BrowserThread::IO, FROM_HERE, | 483 BrowserThread::IO, FROM_HERE, |
474 base::Bind(&TerminateWorkerOnIOThread, worker_data)); | 484 base::Bind(&TerminateWorkerOnIOThread, worker_data)); |
475 content::RunMessageLoop(); | 485 content::RunMessageLoop(); |
476 } | 486 } |
477 | 487 |
478 static void WaitForFirstSharedWorkerOnIOThread( | 488 static void WaitForFirstSharedWorkerOnIOThread( |
| 489 const std::string& path, |
479 scoped_refptr<WorkerData> worker_data) { | 490 scoped_refptr<WorkerData> worker_data) { |
480 std::vector<WorkerService::WorkerInfo> worker_info = | 491 std::vector<WorkerService::WorkerInfo> worker_info = |
481 WorkerService::GetInstance()->GetWorkers(); | 492 WorkerService::GetInstance()->GetWorkers(); |
482 if (!worker_info.empty()) { | 493 for (size_t i = 0; i < worker_info.size(); i++) { |
| 494 if (worker_info[i].url.path().rfind(path) == std::string::npos) |
| 495 continue; |
483 worker_data->worker_process_id = worker_info[0].process_id; | 496 worker_data->worker_process_id = worker_info[0].process_id; |
484 worker_data->worker_route_id = worker_info[0].route_id; | 497 worker_data->worker_route_id = worker_info[0].route_id; |
485 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 498 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
486 base::MessageLoop::QuitClosure()); | 499 base::MessageLoop::QuitClosure()); |
487 return; | 500 return; |
488 } | 501 } |
489 | 502 |
490 WorkerService::GetInstance()->AddObserver( | 503 WorkerService::GetInstance()->AddObserver( |
491 new WorkerCreationObserver(worker_data.get())); | 504 new WorkerCreationObserver(path, worker_data.get())); |
492 } | 505 } |
493 | 506 |
494 static scoped_refptr<WorkerData> WaitForFirstSharedWorker() { | 507 static scoped_refptr<WorkerData> WaitForFirstSharedWorker(const char* path) { |
495 scoped_refptr<WorkerData> worker_data(new WorkerData()); | 508 scoped_refptr<WorkerData> worker_data(new WorkerData()); |
496 BrowserThread::PostTask( | 509 BrowserThread::PostTask( |
497 BrowserThread::IO, FROM_HERE, | 510 BrowserThread::IO, |
498 base::Bind(&WaitForFirstSharedWorkerOnIOThread, worker_data)); | 511 FROM_HERE, |
| 512 base::Bind(&WaitForFirstSharedWorkerOnIOThread, path, worker_data)); |
499 content::RunMessageLoop(); | 513 content::RunMessageLoop(); |
500 return worker_data; | 514 return worker_data; |
501 } | 515 } |
502 | 516 |
503 void OpenDevToolsWindowForSharedWorker(WorkerData* worker_data) { | 517 void OpenDevToolsWindowForSharedWorker(WorkerData* worker_data) { |
504 Profile* profile = browser()->profile(); | 518 Profile* profile = browser()->profile(); |
505 scoped_refptr<DevToolsAgentHost> agent_host( | 519 scoped_refptr<DevToolsAgentHost> agent_host( |
506 DevToolsAgentHost::GetForWorker( | 520 DevToolsAgentHost::GetForWorker( |
507 worker_data->worker_process_id, | 521 worker_data->worker_process_id, |
508 worker_data->worker_route_id)); | 522 worker_data->worker_route_id)); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 content::ExecuteScriptAndExtractString( | 863 content::ExecuteScriptAndExtractString( |
850 main_web_contents()->GetRenderViewHost(), | 864 main_web_contents()->GetRenderViewHost(), |
851 "window.domAutomationController.send(" | 865 "window.domAutomationController.send(" |
852 " '' + (window.uiTests && (typeof uiTests.runTest)));", | 866 " '' + (window.uiTests && (typeof uiTests.runTest)));", |
853 &result)); | 867 &result)); |
854 ASSERT_EQ("function", result) << "DevTools front-end is broken."; | 868 ASSERT_EQ("function", result) << "DevTools front-end is broken."; |
855 CloseDevToolsWindow(); | 869 CloseDevToolsWindow(); |
856 } | 870 } |
857 | 871 |
858 // Flakily fails: http://crbug.com/403007 http://crbug.com/89845 | 872 // Flakily fails: http://crbug.com/403007 http://crbug.com/89845 |
859 IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, DISABLED_InspectSharedWorker) { | 873 IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, InspectSharedWorker) { |
860 #if defined(OS_WIN) && defined(USE_ASH) | 874 #if defined(OS_WIN) && defined(USE_ASH) |
861 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 875 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
862 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 876 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
863 return; | 877 return; |
864 #endif | 878 #endif |
865 | 879 |
866 RunTest("testSharedWorker", kSharedWorkerTestPage); | 880 RunTest("testSharedWorker", kSharedWorkerTestPage, kSharedWorkerTestWorker); |
867 } | 881 } |
868 | 882 |
869 // http://crbug.com/100538 | 883 // http://crbug.com/100538 |
870 IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, | 884 IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, |
871 DISABLED_PauseInSharedWorkerInitialization) { | 885 DISABLED_PauseInSharedWorkerInitialization) { |
872 ASSERT_TRUE(test_server()->Start()); | 886 ASSERT_TRUE(test_server()->Start()); |
873 GURL url = test_server()->GetURL(kReloadSharedWorkerTestPage); | 887 GURL url = test_server()->GetURL(kReloadSharedWorkerTestPage); |
874 ui_test_utils::NavigateToURL(browser(), url); | 888 ui_test_utils::NavigateToURL(browser(), url); |
875 | 889 |
876 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker(); | 890 scoped_refptr<WorkerData> worker_data = |
| 891 WaitForFirstSharedWorker(kReloadSharedWorkerTestWorker); |
877 OpenDevToolsWindowForSharedWorker(worker_data.get()); | 892 OpenDevToolsWindowForSharedWorker(worker_data.get()); |
878 | 893 |
879 TerminateWorker(worker_data); | 894 TerminateWorker(worker_data); |
880 | 895 |
881 // Reload page to restart the worker. | 896 // Reload page to restart the worker. |
882 ui_test_utils::NavigateToURL(browser(), url); | 897 ui_test_utils::NavigateToURL(browser(), url); |
883 | 898 |
884 // Wait until worker script is paused on the debugger statement. | 899 // Wait until worker script is paused on the debugger statement. |
885 RunTestFunction(window_, "testPauseInSharedWorkerInitialization"); | 900 RunTestFunction(window_, "testPauseInSharedWorkerInitialization"); |
886 CloseDevToolsWindow(); | 901 CloseDevToolsWindow(); |
(...skipping 29 matching lines...) Expand all Loading... |
916 | 931 |
917 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { | 932 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { |
918 #if defined(OS_WIN) && defined(USE_ASH) | 933 #if defined(OS_WIN) && defined(USE_ASH) |
919 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 934 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
920 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 935 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
921 return; | 936 return; |
922 #endif | 937 #endif |
923 | 938 |
924 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; | 939 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; |
925 } | 940 } |
OLD | NEW |