OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
10 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
11 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/debugger/devtools_window.h" | 14 #include "chrome/browser/debugger/devtools_window.h" |
14 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/unpacked_installer.h" | 17 #include "chrome/browser/extensions/unpacked_installer.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
24 #include "content/browser/renderer_host/render_view_host.h" | 26 #include "content/browser/renderer_host/render_view_host.h" |
25 #include "content/browser/tab_contents/tab_contents.h" | 27 #include "content/browser/tab_contents/tab_contents.h" |
26 #include "content/browser/worker_host/worker_process_host.h" | 28 #include "content/browser/worker_host/worker_process_host.h" |
27 #include "content/browser/worker_host/worker_service.h" | 29 #include "content/browser/worker_host/worker_service.h" |
28 #include "content/browser/worker_host/worker_service_observer.h" | 30 #include "content/browser/worker_host/worker_service_observer.h" |
29 #include "content/public/browser/devtools_agent_host_registry.h" | 31 #include "content/public/browser/devtools_agent_host_registry.h" |
30 #include "content/public/browser/devtools_client_host.h" | 32 #include "content/public/browser/devtools_client_host.h" |
31 #include "content/public/browser/devtools_manager.h" | 33 #include "content/public/browser/devtools_manager.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const char kNavigateBackTestPage[] = | 77 const char kNavigateBackTestPage[] = |
76 "files/devtools/navigate_back.html"; | 78 "files/devtools/navigate_back.html"; |
77 const char kChunkedTestPage[] = "chunked"; | 79 const char kChunkedTestPage[] = "chunked"; |
78 const char kSlowTestPage[] = | 80 const char kSlowTestPage[] = |
79 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; | 81 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; |
80 const char kSharedWorkerTestPage[] = | 82 const char kSharedWorkerTestPage[] = |
81 "files/workers/workers_ui_shared_worker.html"; | 83 "files/workers/workers_ui_shared_worker.html"; |
82 const char kReloadSharedWorkerTestPage[] = | 84 const char kReloadSharedWorkerTestPage[] = |
83 "files/workers/debug_shared_worker_initialization.html"; | 85 "files/workers/debug_shared_worker_initialization.html"; |
84 | 86 |
85 void RunTestFuntion(DevToolsWindow* window, const char* test_name) { | 87 void RunTestFunction(DevToolsWindow* window, const char* test_name) { |
86 std::string result; | 88 std::string result; |
87 | 89 |
88 // At first check that JavaScript part of the front-end is loaded by | 90 // At first check that JavaScript part of the front-end is loaded by |
89 // checking that global variable uiTests exists(it's created after all js | 91 // checking that global variable uiTests exists(it's created after all js |
90 // files have been loaded) and has runTest method. | 92 // files have been loaded) and has runTest method. |
91 ASSERT_TRUE( | 93 ASSERT_TRUE( |
92 ui_test_utils::ExecuteJavaScriptAndExtractString( | 94 ui_test_utils::ExecuteJavaScriptAndExtractString( |
93 window->GetRenderViewHost(), | 95 window->GetRenderViewHost(), |
94 L"", | 96 L"", |
95 L"window.domAutomationController.send(" | 97 L"window.domAutomationController.send(" |
(...skipping 19 matching lines...) Expand all Loading... |
115 DevToolsSanityTest() | 117 DevToolsSanityTest() |
116 : window_(NULL), | 118 : window_(NULL), |
117 inspected_rvh_(NULL) { | 119 inspected_rvh_(NULL) { |
118 set_show_window(true); | 120 set_show_window(true); |
119 EnableDOMAutomation(); | 121 EnableDOMAutomation(); |
120 } | 122 } |
121 | 123 |
122 protected: | 124 protected: |
123 void RunTest(const std::string& test_name, const std::string& test_page) { | 125 void RunTest(const std::string& test_name, const std::string& test_page) { |
124 OpenDevToolsWindow(test_page); | 126 OpenDevToolsWindow(test_page); |
125 RunTestFuntion(window_, test_name.c_str()); | 127 RunTestFunction(window_, test_name.c_str()); |
126 CloseDevToolsWindow(); | 128 CloseDevToolsWindow(); |
127 } | 129 } |
128 | 130 |
129 void OpenDevToolsWindow(const std::string& test_page) { | 131 void OpenDevToolsWindow(const std::string& test_page) { |
130 ASSERT_TRUE(test_server()->Start()); | 132 ASSERT_TRUE(test_server()->Start()); |
131 GURL url = test_server()->GetURL(test_page); | 133 GURL url = test_server()->GetURL(test_page); |
132 ui_test_utils::NavigateToURL(browser(), url); | 134 ui_test_utils::NavigateToURL(browser(), url); |
133 | 135 |
134 ui_test_utils::WindowedNotificationObserver observer( | 136 ui_test_utils::WindowedNotificationObserver observer( |
135 content::NOTIFICATION_LOAD_STOP, | 137 content::NOTIFICATION_LOAD_STOP, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 break; | 247 break; |
246 default: | 248 default: |
247 NOTREACHED(); | 249 NOTREACHED(); |
248 break; | 250 break; |
249 } | 251 } |
250 } | 252 } |
251 | 253 |
252 FilePath test_extensions_dir_; | 254 FilePath test_extensions_dir_; |
253 }; | 255 }; |
254 | 256 |
| 257 class DevToolsExtensionAPITest : public DevToolsExtensionDebugTest { |
| 258 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 259 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 260 } |
| 261 }; |
255 | 262 |
256 class WorkerDevToolsSanityTest : public InProcessBrowserTest { | 263 class WorkerDevToolsSanityTest : public InProcessBrowserTest { |
257 public: | 264 public: |
258 WorkerDevToolsSanityTest() : window_(NULL) { | 265 WorkerDevToolsSanityTest() : window_(NULL) { |
259 set_show_window(true); | 266 set_show_window(true); |
260 EnableDOMAutomation(); | 267 EnableDOMAutomation(); |
261 } | 268 } |
262 | 269 |
263 protected: | 270 protected: |
264 struct WorkerData : public base::RefCountedThreadSafe<WorkerData> { | 271 struct WorkerData : public base::RefCountedThreadSafe<WorkerData> { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 scoped_refptr<WorkerData> worker_data_; | 330 scoped_refptr<WorkerData> worker_data_; |
324 }; | 331 }; |
325 | 332 |
326 void RunTest(const char* test_name, const char* test_page) { | 333 void RunTest(const char* test_name, const char* test_page) { |
327 ASSERT_TRUE(test_server()->Start()); | 334 ASSERT_TRUE(test_server()->Start()); |
328 GURL url = test_server()->GetURL(test_page); | 335 GURL url = test_server()->GetURL(test_page); |
329 ui_test_utils::NavigateToURL(browser(), url); | 336 ui_test_utils::NavigateToURL(browser(), url); |
330 | 337 |
331 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker(); | 338 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker(); |
332 OpenDevToolsWindowForSharedWorker(worker_data.get()); | 339 OpenDevToolsWindowForSharedWorker(worker_data.get()); |
333 RunTestFuntion(window_, test_name); | 340 RunTestFunction(window_, test_name); |
334 CloseDevToolsWindow(); | 341 CloseDevToolsWindow(); |
335 } | 342 } |
336 | 343 |
337 static void TerminateWorkerOnIOThread( | 344 static void TerminateWorkerOnIOThread( |
338 scoped_refptr<WorkerData> worker_data) { | 345 scoped_refptr<WorkerData> worker_data) { |
339 for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); | 346 for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); |
340 !iter.Done(); ++iter) { | 347 !iter.Done(); ++iter) { |
341 if (iter->id() == worker_data->worker_process_id) { | 348 if (iter->id() == worker_data->worker_process_id) { |
342 WorkerProcessHost* host = static_cast<WorkerProcessHost*>(*iter); | 349 WorkerProcessHost* host = static_cast<WorkerProcessHost*>(*iter); |
343 host->TerminateWorker(worker_data->worker_route_id); | 350 host->TerminateWorker(worker_data->worker_route_id); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 FAILS_TestScriptsTabIsPopulatedOnInspectedPageRefresh) { | 437 FAILS_TestScriptsTabIsPopulatedOnInspectedPageRefresh) { |
431 // Clear inspector settings to ensure that Elements will be | 438 // Clear inspector settings to ensure that Elements will be |
432 // current panel when DevTools window is open. | 439 // current panel when DevTools window is open. |
433 content::GetContentClient()->browser()->ClearInspectorSettings( | 440 content::GetContentClient()->browser()->ClearInspectorSettings( |
434 GetInspectedTab()->render_view_host()); | 441 GetInspectedTab()->render_view_host()); |
435 RunTest("testScriptsTabIsPopulatedOnInspectedPageRefresh", | 442 RunTest("testScriptsTabIsPopulatedOnInspectedPageRefresh", |
436 kDebuggerTestPage); | 443 kDebuggerTestPage); |
437 } | 444 } |
438 | 445 |
439 // Tests that a content script is in the scripts list. | 446 // Tests that a content script is in the scripts list. |
440 // This test is disabled, see bug 28961. | 447 IN_PROC_BROWSER_TEST_F(DevToolsExtensionAPITest, |
| 448 TestDevToolsExtensionAPI) { |
| 449 LoadExtension("devtools_extension"); |
| 450 RunTest("testWaitForResultsInConsole", kPageWithContentScript); |
| 451 } |
| 452 |
| 453 // Tests that a content script is in the scripts list. |
441 IN_PROC_BROWSER_TEST_F(DevToolsExtensionDebugTest, | 454 IN_PROC_BROWSER_TEST_F(DevToolsExtensionDebugTest, |
442 TestContentScriptIsPresent) { | 455 TestContentScriptIsPresent) { |
443 LoadExtension("simple_content_script"); | 456 LoadExtension("simple_content_script"); |
444 RunTest("testContentScriptIsPresent", kPageWithContentScript); | 457 RunTest("testContentScriptIsPresent", kPageWithContentScript); |
445 } | 458 } |
446 | 459 |
447 // Tests that scripts are not duplicated after Scripts Panel switch. | 460 // Tests that scripts are not duplicated after Scripts Panel switch. |
448 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, | 461 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, |
449 TestNoScriptDuplicatesOnPanelSwitch) { | 462 TestNoScriptDuplicatesOnPanelSwitch) { |
450 RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage); | 463 RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 OpenDevToolsWindow(kDebuggerTestPage); | 512 OpenDevToolsWindow(kDebuggerTestPage); |
500 | 513 |
501 ui_test_utils::CrashTab(GetInspectedTab()); | 514 ui_test_utils::CrashTab(GetInspectedTab()); |
502 ui_test_utils::WindowedNotificationObserver observer( | 515 ui_test_utils::WindowedNotificationObserver observer( |
503 content::NOTIFICATION_LOAD_STOP, | 516 content::NOTIFICATION_LOAD_STOP, |
504 content::Source<NavigationController>( | 517 content::Source<NavigationController>( |
505 &browser()->GetSelectedTabContentsWrapper()->controller())); | 518 &browser()->GetSelectedTabContentsWrapper()->controller())); |
506 browser()->Reload(CURRENT_TAB); | 519 browser()->Reload(CURRENT_TAB); |
507 observer.Wait(); | 520 observer.Wait(); |
508 | 521 |
509 RunTestFuntion(window_, "testReattachAfterCrash"); | 522 RunTestFunction(window_, "testReattachAfterCrash"); |
510 CloseDevToolsWindow(); | 523 CloseDevToolsWindow(); |
511 } | 524 } |
512 | 525 |
513 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) { | 526 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) { |
514 OpenDevToolsWindow("about:blank"); | 527 OpenDevToolsWindow("about:blank"); |
515 std::string result; | 528 std::string result; |
516 ASSERT_TRUE( | 529 ASSERT_TRUE( |
517 ui_test_utils::ExecuteJavaScriptAndExtractString( | 530 ui_test_utils::ExecuteJavaScriptAndExtractString( |
518 window_->GetRenderViewHost(), | 531 window_->GetRenderViewHost(), |
519 L"", | 532 L"", |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 | 568 |
556 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker(); | 569 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker(); |
557 OpenDevToolsWindowForSharedWorker(worker_data.get()); | 570 OpenDevToolsWindowForSharedWorker(worker_data.get()); |
558 | 571 |
559 TerminateWorker(worker_data); | 572 TerminateWorker(worker_data); |
560 | 573 |
561 // Reload page to restart the worker. | 574 // Reload page to restart the worker. |
562 ui_test_utils::NavigateToURL(browser(), url); | 575 ui_test_utils::NavigateToURL(browser(), url); |
563 | 576 |
564 // Wait until worker script is paused on the debugger statement. | 577 // Wait until worker script is paused on the debugger statement. |
565 RunTestFuntion(window_, "testPauseInSharedWorkerInitialization"); | 578 RunTestFunction(window_, "testPauseInSharedWorkerInitialization"); |
566 CloseDevToolsWindow(); | 579 CloseDevToolsWindow(); |
567 } | 580 } |
568 | 581 |
569 } // namespace | 582 } // namespace |
OLD | NEW |