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