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" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/devtools/browser_list_tabcontents_provider.h" |
14 #include "chrome/browser/devtools/devtools_window.h" | 15 #include "chrome/browser/devtools/devtools_window.h" |
| 16 #include "chrome/browser/extensions/extension_browsertest.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
17 #include "chrome/browser/extensions/unpacked_installer.h" | 19 #include "chrome/browser/extensions/unpacked_installer.h" |
18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
26 #include "chrome/test/base/in_process_browser_test.h" | 28 #include "chrome/test/base/in_process_browser_test.h" |
27 #include "chrome/test/base/ui_test_utils.h" | 29 #include "chrome/test/base/ui_test_utils.h" |
28 #include "content/public/browser/child_process_data.h" | 30 #include "content/public/browser/child_process_data.h" |
29 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" |
30 #include "content/public/browser/devtools_agent_host.h" | 32 #include "content/public/browser/devtools_agent_host.h" |
31 #include "content/public/browser/devtools_client_host.h" | 33 #include "content/public/browser/devtools_client_host.h" |
| 34 #include "content/public/browser/devtools_http_handler.h" |
32 #include "content/public/browser/devtools_manager.h" | 35 #include "content/public/browser/devtools_manager.h" |
33 #include "content/public/browser/notification_registrar.h" | 36 #include "content/public/browser/notification_registrar.h" |
34 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
35 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
36 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
37 #include "content/public/browser/worker_service.h" | 40 #include "content/public/browser/worker_service.h" |
38 #include "content/public/browser/worker_service_observer.h" | 41 #include "content/public/browser/worker_service_observer.h" |
39 #include "content/public/test/browser_test_utils.h" | 42 #include "content/public/test/browser_test_utils.h" |
| 43 #include "net/base/tcp_listen_socket.h" |
40 #include "net/test/test_server.h" | 44 #include "net/test/test_server.h" |
41 | 45 |
42 using content::BrowserThread; | 46 using content::BrowserThread; |
43 using content::DevToolsManager; | 47 using content::DevToolsManager; |
44 using content::DevToolsAgentHost; | 48 using content::DevToolsAgentHost; |
45 using content::NavigationController; | 49 using content::NavigationController; |
46 using content::RenderViewHost; | 50 using content::RenderViewHost; |
47 using content::WebContents; | 51 using content::WebContents; |
48 using content::WorkerService; | 52 using content::WorkerService; |
49 using content::WorkerServiceObserver; | 53 using content::WorkerServiceObserver; |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 devtools_manager->AddMessageToConsole(agent_host, | 607 devtools_manager->AddMessageToConsole(agent_host, |
604 content::CONSOLE_MESSAGE_LEVEL_LOG, | 608 content::CONSOLE_MESSAGE_LEVEL_LOG, |
605 "log"); | 609 "log"); |
606 devtools_manager->AddMessageToConsole(agent_host, | 610 devtools_manager->AddMessageToConsole(agent_host, |
607 content::CONSOLE_MESSAGE_LEVEL_ERROR, | 611 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
608 "error"); | 612 "error"); |
609 RunTestFunction(window_, "checkLogAndErrorMessages"); | 613 RunTestFunction(window_, "checkLogAndErrorMessages"); |
610 CloseDevToolsWindow(); | 614 CloseDevToolsWindow(); |
611 } | 615 } |
612 | 616 |
| 617 class RemoteDebuggingTest : public ExtensionBrowserTest { |
| 618 |
| 619 class ResultCatcher : public content::NotificationObserver { |
| 620 public: |
| 621 ResultCatcher() |
| 622 : notification_(chrome::NOTIFICATION_CHROME_END) { |
| 623 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_PASSED, |
| 624 content::NotificationService::AllSources()); |
| 625 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_FAILED, |
| 626 content::NotificationService::AllSources()); |
| 627 } |
| 628 |
| 629 virtual ~ResultCatcher() { |
| 630 } |
| 631 |
| 632 // Pumps the UI loop until a notification is received that an API test |
| 633 // succeeded or failed. Returns true if the test succeeded, false otherwise. |
| 634 bool GetNextResult() { |
| 635 if (!received()) |
| 636 content::RunMessageLoop(); |
| 637 |
| 638 if (!received()) |
| 639 NOTREACHED(); |
| 640 |
| 641 return notification_ == chrome::NOTIFICATION_EXTENSION_TEST_PASSED; |
| 642 } |
| 643 |
| 644 private: |
| 645 virtual void Observe(int type, |
| 646 const content::NotificationSource& source, |
| 647 const content::NotificationDetails& details) OVERRIDE { |
| 648 if (received()) |
| 649 return; |
| 650 notification_ = static_cast<chrome::NotificationType>(type); |
| 651 MessageLoopForUI::current()->Quit(); |
| 652 } |
| 653 |
| 654 content::NotificationRegistrar registrar_; |
| 655 |
| 656 chrome::NotificationType notification_; |
| 657 |
| 658 bool received() { return notification_ != chrome::NOTIFICATION_CHROME_END; } |
| 659 }; |
| 660 |
| 661 protected: |
| 662 |
| 663 bool RunExtensionTest(const std::string& directory) { |
| 664 content::DevToolsHttpHandler* devtools_http_handler_ = |
| 665 content::DevToolsHttpHandler::Start( |
| 666 new net::TCPListenSocketFactory("127.0.0.1", 9222), |
| 667 "", |
| 668 new BrowserListTabContentsProvider( |
| 669 profile(), chrome::HOST_DESKTOP_TYPE_NATIVE)); |
| 670 |
| 671 base::FilePath test_data_path; |
| 672 PathService::Get(chrome::DIR_TEST_DATA, &test_data_path); |
| 673 LoadExtension( |
| 674 test_data_path.AppendASCII("devtools").AppendASCII(directory)); |
| 675 |
| 676 ResultCatcher catcher; |
| 677 bool result = catcher.GetNextResult(); |
| 678 devtools_http_handler_->Stop(); |
| 679 return result; |
| 680 } |
| 681 }; |
| 682 |
| 683 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, TargetList) { |
| 684 ASSERT_TRUE(RunExtensionTest("target_list")); |
| 685 } |
| 686 |
613 } // namespace | 687 } // namespace |
OLD | NEW |