| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 rvh, | 102 rvh, |
| 103 base::StringPrintf("uiTests.runTest('%s')", test_name), | 103 base::StringPrintf("uiTests.runTest('%s')", test_name), |
| 104 &result)); | 104 &result)); |
| 105 EXPECT_EQ("[OK]", result); | 105 EXPECT_EQ("[OK]", result); |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace | 108 } // namespace |
| 109 | 109 |
| 110 class DevToolsSanityTest : public InProcessBrowserTest { | 110 class DevToolsSanityTest : public InProcessBrowserTest { |
| 111 public: | 111 public: |
| 112 DevToolsSanityTest() | 112 DevToolsSanityTest() : window_(NULL) {} |
| 113 : window_(NULL), | |
| 114 inspected_rvh_(NULL) {} | |
| 115 | 113 |
| 116 protected: | 114 protected: |
| 117 void RunTest(const std::string& test_name, const std::string& test_page) { | 115 void RunTest(const std::string& test_name, const std::string& test_page) { |
| 118 OpenDevToolsWindow(test_page, false); | 116 OpenDevToolsWindow(test_page, false); |
| 119 RunTestFunction(window_, test_name.c_str()); | 117 RunTestFunction(window_, test_name.c_str()); |
| 120 CloseDevToolsWindow(); | 118 CloseDevToolsWindow(); |
| 121 } | 119 } |
| 122 | 120 |
| 123 void LoadTestPage(const std::string& test_page) { | 121 void LoadTestPage(const std::string& test_page) { |
| 124 GURL url = test_server()->GetURL(test_page); | 122 GURL url = test_server()->GetURL(test_page); |
| 125 ui_test_utils::NavigateToURL(browser(), url); | 123 ui_test_utils::NavigateToURL(browser(), url); |
| 126 } | 124 } |
| 127 | 125 |
| 128 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { | 126 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { |
| 129 ASSERT_TRUE(test_server()->Start()); | 127 ASSERT_TRUE(test_server()->Start()); |
| 130 LoadTestPage(test_page); | 128 LoadTestPage(test_page); |
| 131 | 129 |
| 132 inspected_rvh_ = GetInspectedTab()->GetRenderViewHost(); | 130 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), |
| 133 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync( | 131 is_docked); |
| 134 inspected_rvh_, is_docked); | |
| 135 } | 132 } |
| 136 | 133 |
| 137 WebContents* GetInspectedTab() { | 134 WebContents* GetInspectedTab() { |
| 138 return browser()->tab_strip_model()->GetWebContentsAt(0); | 135 return browser()->tab_strip_model()->GetWebContentsAt(0); |
| 139 } | 136 } |
| 140 | 137 |
| 141 void CloseDevToolsWindow() { | 138 void CloseDevToolsWindow() { |
| 142 DevToolsWindowTesting::CloseDevToolsWindowSync(window_); | 139 DevToolsWindowTesting::CloseDevToolsWindowSync(window_); |
| 143 } | 140 } |
| 144 | 141 |
| 145 WebContents* main_web_contents() { | 142 WebContents* main_web_contents() { |
| 146 return DevToolsWindowTesting::Get(window_)->main_web_contents(); | 143 return DevToolsWindowTesting::Get(window_)->main_web_contents(); |
| 147 } | 144 } |
| 148 | 145 |
| 149 WebContents* toolbox_web_contents() { | 146 WebContents* toolbox_web_contents() { |
| 150 return DevToolsWindowTesting::Get(window_)->toolbox_web_contents(); | 147 return DevToolsWindowTesting::Get(window_)->toolbox_web_contents(); |
| 151 } | 148 } |
| 152 | 149 |
| 153 DevToolsWindow* window_; | 150 DevToolsWindow* window_; |
| 154 RenderViewHost* inspected_rvh_; | |
| 155 }; | 151 }; |
| 156 | 152 |
| 157 // Used to block until a dev tools window gets beforeunload event. | 153 // Used to block until a dev tools window gets beforeunload event. |
| 158 class DevToolsWindowBeforeUnloadObserver | 154 class DevToolsWindowBeforeUnloadObserver |
| 159 : public content::WebContentsObserver { | 155 : public content::WebContentsObserver { |
| 160 public: | 156 public: |
| 161 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); | 157 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); |
| 162 void Wait(); | 158 void Wait(); |
| 163 private: | 159 private: |
| 164 // Invoked when the beforeunload handler fires. | 160 // Invoked when the beforeunload handler fires. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 close_method.Run(); | 235 close_method.Run(); |
| 240 AcceptModalDialog(); | 236 AcceptModalDialog(); |
| 241 if (wait_for_browser_close) | 237 if (wait_for_browser_close) |
| 242 close_observer.Wait(); | 238 close_observer.Wait(); |
| 243 } | 239 } |
| 244 runner->Run(); | 240 runner->Run(); |
| 245 } | 241 } |
| 246 | 242 |
| 247 DevToolsWindow* OpenDevToolWindowOnWebContents( | 243 DevToolsWindow* OpenDevToolWindowOnWebContents( |
| 248 content::WebContents* contents, bool is_docked) { | 244 content::WebContents* contents, bool is_docked) { |
| 249 DevToolsWindow* window = DevToolsWindowTesting::OpenDevToolsWindowSync( | 245 DevToolsWindow* window = |
| 250 contents->GetRenderViewHost(), is_docked); | 246 DevToolsWindowTesting::OpenDevToolsWindowSync(contents, is_docked); |
| 251 return window; | 247 return window; |
| 252 } | 248 } |
| 253 | 249 |
| 254 void OpenDevToolsPopupWindow(DevToolsWindow* devtools_window) { | 250 void OpenDevToolsPopupWindow(DevToolsWindow* devtools_window) { |
| 255 content::WindowedNotificationObserver observer( | 251 content::WindowedNotificationObserver observer( |
| 256 content::NOTIFICATION_LOAD_STOP, | 252 content::NOTIFICATION_LOAD_STOP, |
| 257 content::NotificationService::AllSources()); | 253 content::NotificationService::AllSources()); |
| 258 ASSERT_TRUE(content::ExecuteScript( | 254 ASSERT_TRUE(content::ExecuteScript( |
| 259 DevToolsWindowTesting::Get(devtools_window)-> | 255 DevToolsWindowTesting::Get(devtools_window)-> |
| 260 main_web_contents()->GetRenderViewHost(), | 256 main_web_contents()->GetRenderViewHost(), |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 ASSERT_TRUE(main_web_contents()->GetURL(). | 807 ASSERT_TRUE(main_web_contents()->GetURL(). |
| 812 SchemeIs(content::kChromeDevToolsScheme)); | 808 SchemeIs(content::kChromeDevToolsScheme)); |
| 813 ASSERT_EQ(url, GetInspectedTab()->GetURL()); | 809 ASSERT_EQ(url, GetInspectedTab()->GetURL()); |
| 814 CloseDevToolsWindow(); | 810 CloseDevToolsWindow(); |
| 815 } | 811 } |
| 816 | 812 |
| 817 // Tests that toolbox window is loaded when DevTools window is undocked. | 813 // Tests that toolbox window is loaded when DevTools window is undocked. |
| 818 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxLoadedUndocked) { | 814 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxLoadedUndocked) { |
| 819 OpenDevToolsWindow(kDebuggerTestPage, false); | 815 OpenDevToolsWindow(kDebuggerTestPage, false); |
| 820 ASSERT_TRUE(toolbox_web_contents()); | 816 ASSERT_TRUE(toolbox_web_contents()); |
| 821 DevToolsWindow* on_self = DevToolsWindowTesting::OpenDevToolsWindowSync( | 817 DevToolsWindow* on_self = |
| 822 main_web_contents()->GetRenderViewHost(), false); | 818 DevToolsWindowTesting::OpenDevToolsWindowSync(main_web_contents(), false); |
| 823 ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents()); | 819 ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents()); |
| 824 DevToolsWindowTesting::CloseDevToolsWindowSync(on_self); | 820 DevToolsWindowTesting::CloseDevToolsWindowSync(on_self); |
| 825 CloseDevToolsWindow(); | 821 CloseDevToolsWindow(); |
| 826 } | 822 } |
| 827 | 823 |
| 828 // Tests that toolbox window is not loaded when DevTools window is docked. | 824 // Tests that toolbox window is not loaded when DevTools window is docked. |
| 829 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxNotLoadedDocked) { | 825 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxNotLoadedDocked) { |
| 830 OpenDevToolsWindow(kDebuggerTestPage, true); | 826 OpenDevToolsWindow(kDebuggerTestPage, true); |
| 831 ASSERT_FALSE(toolbox_web_contents()); | 827 ASSERT_FALSE(toolbox_web_contents()); |
| 832 DevToolsWindow* on_self = DevToolsWindowTesting::OpenDevToolsWindowSync( | 828 DevToolsWindow* on_self = |
| 833 main_web_contents()->GetRenderViewHost(), false); | 829 DevToolsWindowTesting::OpenDevToolsWindowSync(main_web_contents(), false); |
| 834 ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents()); | 830 ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents()); |
| 835 DevToolsWindowTesting::CloseDevToolsWindowSync(on_self); | 831 DevToolsWindowTesting::CloseDevToolsWindowSync(on_self); |
| 836 CloseDevToolsWindow(); | 832 CloseDevToolsWindow(); |
| 837 } | 833 } |
| 838 | 834 |
| 839 // Tests that inspector will reattach to inspected page when it is reloaded | 835 // Tests that inspector will reattach to inspected page when it is reloaded |
| 840 // after a crash. See http://crbug.com/101952 | 836 // after a crash. See http://crbug.com/101952 |
| 841 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestReattachAfterCrash) { | 837 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestReattachAfterCrash) { |
| 842 RunTest("testReattachAfterCrash", std::string()); | 838 RunTest("testReattachAfterCrash", std::string()); |
| 843 } | 839 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 // Wait until worker script is paused on the debugger statement. | 885 // Wait until worker script is paused on the debugger statement. |
| 890 RunTestFunction(window_, "testPauseInSharedWorkerInitialization"); | 886 RunTestFunction(window_, "testPauseInSharedWorkerInitialization"); |
| 891 CloseDevToolsWindow(); | 887 CloseDevToolsWindow(); |
| 892 } | 888 } |
| 893 | 889 |
| 894 class DevToolsAgentHostTest : public InProcessBrowserTest {}; | 890 class DevToolsAgentHostTest : public InProcessBrowserTest {}; |
| 895 | 891 |
| 896 // Tests DevToolsAgentHost retention by its target. | 892 // Tests DevToolsAgentHost retention by its target. |
| 897 IN_PROC_BROWSER_TEST_F(DevToolsAgentHostTest, TestAgentHostReleased) { | 893 IN_PROC_BROWSER_TEST_F(DevToolsAgentHostTest, TestAgentHostReleased) { |
| 898 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 894 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 899 RenderViewHost* rvh = browser()->tab_strip_model()->GetWebContentsAt(0)-> | 895 WebContents* web_contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 900 GetRenderViewHost(); | 896 DevToolsAgentHost* agent_raw = |
| 901 DevToolsAgentHost* agent_raw = DevToolsAgentHost::GetOrCreateFor(rvh).get(); | 897 DevToolsAgentHost::GetOrCreateFor(web_contents).get(); |
| 902 const std::string agent_id = agent_raw->GetId(); | 898 const std::string agent_id = agent_raw->GetId(); |
| 903 ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id)) << | 899 ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id)) << |
| 904 "DevToolsAgentHost cannot be found by id"; | 900 "DevToolsAgentHost cannot be found by id"; |
| 905 browser()->tab_strip_model()-> | 901 browser()->tab_strip_model()-> |
| 906 CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 902 CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
| 907 ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get()) | 903 ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get()) |
| 908 << "DevToolsAgentHost is not released when the tab is closed"; | 904 << "DevToolsAgentHost is not released when the tab is closed"; |
| 909 } | 905 } |
| 910 | 906 |
| 911 class RemoteDebuggingTest: public ExtensionApiTest { | 907 class RemoteDebuggingTest: public ExtensionApiTest { |
| 912 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 908 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 913 ExtensionApiTest::SetUpCommandLine(command_line); | 909 ExtensionApiTest::SetUpCommandLine(command_line); |
| 914 command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222"); | 910 command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222"); |
| 915 | 911 |
| 916 // Override the extension root path. | 912 // Override the extension root path. |
| 917 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 913 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 918 test_data_dir_ = test_data_dir_.AppendASCII("devtools"); | 914 test_data_dir_ = test_data_dir_.AppendASCII("devtools"); |
| 919 } | 915 } |
| 920 }; | 916 }; |
| 921 | 917 |
| 922 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { | 918 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { |
| 923 #if defined(OS_WIN) && defined(USE_ASH) | 919 #if defined(OS_WIN) && defined(USE_ASH) |
| 924 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 920 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 925 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 921 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| 926 return; | 922 return; |
| 927 #endif | 923 #endif |
| 928 | 924 |
| 929 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; | 925 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; |
| 930 } | 926 } |
| OLD | NEW |