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/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/devtools/browser_list_tabcontents_provider.h" | 16 #include "chrome/browser/devtools/browser_list_tabcontents_provider.h" |
17 #include "chrome/browser/devtools/devtools_window_testing.h" | 17 #include "chrome/browser/devtools/devtools_window_testing.h" |
18 #include "chrome/browser/extensions/extension_apitest.h" | 18 #include "chrome/browser/extensions/extension_apitest.h" |
19 #include "chrome/browser/extensions/extension_browsertest.h" | 19 #include "chrome/browser/extensions/extension_browsertest.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/unpacked_installer.h" | 21 #include "chrome/browser/extensions/unpacked_installer.h" |
22 #include "chrome/browser/lifetime/application_lifetime.h" | 22 #include "chrome/browser/lifetime/application_lifetime.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
26 #include "chrome/browser/ui/browser_iterator.h" | 26 #include "chrome/browser/ui/browser_iterator.h" |
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
28 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
30 #include "chrome/common/pref_names.h" | |
30 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
31 #include "chrome/test/base/in_process_browser_test.h" | 32 #include "chrome/test/base/in_process_browser_test.h" |
32 #include "chrome/test/base/test_switches.h" | 33 #include "chrome/test/base/test_switches.h" |
33 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
34 #include "components/app_modal/javascript_app_modal_dialog.h" | 35 #include "components/app_modal/javascript_app_modal_dialog.h" |
35 #include "components/app_modal/native_app_modal_dialog.h" | 36 #include "components/app_modal/native_app_modal_dialog.h" |
36 #include "content/public/browser/child_process_data.h" | 37 #include "content/public/browser/child_process_data.h" |
37 #include "content/public/browser/content_browser_client.h" | 38 #include "content/public/browser/content_browser_client.h" |
38 #include "content/public/browser/devtools_agent_host.h" | 39 #include "content/public/browser/devtools_agent_host.h" |
39 #include "content/public/browser/devtools_http_handler.h" | 40 #include "content/public/browser/devtools_http_handler.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 } | 129 } |
129 | 130 |
130 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { | 131 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { |
131 ASSERT_TRUE(test_server()->Start()); | 132 ASSERT_TRUE(test_server()->Start()); |
132 LoadTestPage(test_page); | 133 LoadTestPage(test_page); |
133 | 134 |
134 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), | 135 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), |
135 is_docked); | 136 is_docked); |
136 } | 137 } |
137 | 138 |
139 void OpenDevToolsWindowAndAgentHost(const std::string& test_page) { | |
140 ASSERT_TRUE(test_server()->Start()); | |
141 LoadTestPage(test_page); | |
142 content::WebContents* web_contents = GetInspectedTab(); | |
143 scoped_refptr<content::DevToolsAgentHost> agent( | |
144 content::DevToolsAgentHost::GetOrCreateFor(web_contents)); | |
145 DevToolsWindow::OpenDevToolsWindow(web_contents); | |
146 window_ = DevToolsWindow::FindDevToolsWindow(agent.get()); | |
147 } | |
148 | |
138 WebContents* GetInspectedTab() { | 149 WebContents* GetInspectedTab() { |
139 return browser()->tab_strip_model()->GetWebContentsAt(0); | 150 return browser()->tab_strip_model()->GetWebContentsAt(0); |
140 } | 151 } |
141 | 152 |
142 void CloseDevToolsWindow() { | 153 void CloseDevToolsWindow() { |
143 DevToolsWindowTesting::CloseDevToolsWindowSync(window_); | 154 DevToolsWindowTesting::CloseDevToolsWindowSync(window_); |
144 } | 155 } |
145 | 156 |
146 WebContents* main_web_contents() { | 157 WebContents* main_web_contents() { |
147 return DevToolsWindowTesting::Get(window_)->main_web_contents(); | 158 return DevToolsWindowTesting::Get(window_)->main_web_contents(); |
148 } | 159 } |
149 | 160 |
150 WebContents* toolbox_web_contents() { | 161 WebContents* toolbox_web_contents() { |
151 return DevToolsWindowTesting::Get(window_)->toolbox_web_contents(); | 162 return DevToolsWindowTesting::Get(window_)->toolbox_web_contents(); |
152 } | 163 } |
153 | 164 |
165 void SetPolicyDevToolsDisabled(bool value) { | |
166 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDevToolsDisabled, | |
167 value); | |
168 } | |
169 | |
170 bool WindowExists() { return window_; } | |
171 | |
154 DevToolsWindow* window_; | 172 DevToolsWindow* window_; |
155 }; | 173 }; |
156 | 174 |
157 // Used to block until a dev tools window gets beforeunload event. | 175 // Used to block until a dev tools window gets beforeunload event. |
158 class DevToolsWindowBeforeUnloadObserver | 176 class DevToolsWindowBeforeUnloadObserver |
159 : public content::WebContentsObserver { | 177 : public content::WebContentsObserver { |
160 public: | 178 public: |
161 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); | 179 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); |
162 void Wait(); | 180 void Wait(); |
163 private: | 181 private: |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 ASSERT_TRUE( | 884 ASSERT_TRUE( |
867 content::ExecuteScriptAndExtractString( | 885 content::ExecuteScriptAndExtractString( |
868 main_web_contents()->GetRenderViewHost(), | 886 main_web_contents()->GetRenderViewHost(), |
869 "window.domAutomationController.send(" | 887 "window.domAutomationController.send(" |
870 " '' + (window.uiTests && (typeof uiTests.runTest)));", | 888 " '' + (window.uiTests && (typeof uiTests.runTest)));", |
871 &result)); | 889 &result)); |
872 ASSERT_EQ("function", result) << "DevTools front-end is broken."; | 890 ASSERT_EQ("function", result) << "DevTools front-end is broken."; |
873 CloseDevToolsWindow(); | 891 CloseDevToolsWindow(); |
874 } | 892 } |
875 | 893 |
894 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, PolicyTrue) { | |
Andrew T Wilson (Slow)
2015/03/03 19:13:31
Maybe also test the case where you set the DevTool
| |
895 SetPolicyDevToolsDisabled(true); | |
896 OpenDevToolsWindowAndAgentHost(kDebuggerTestPage); | |
897 ASSERT_FALSE(WindowExists()); | |
898 } | |
899 | |
876 IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, InspectSharedWorker) { | 900 IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, InspectSharedWorker) { |
877 #if defined(OS_WIN) && defined(USE_ASH) | 901 #if defined(OS_WIN) && defined(USE_ASH) |
878 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 902 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
879 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 903 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
880 switches::kAshBrowserTests)) | 904 switches::kAshBrowserTests)) |
881 return; | 905 return; |
882 #endif | 906 #endif |
883 | 907 |
884 RunTest("testSharedWorker", kSharedWorkerTestPage, kSharedWorkerTestWorker); | 908 RunTest("testSharedWorker", kSharedWorkerTestPage, kSharedWorkerTestWorker); |
885 } | 909 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
946 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, MAYBE_RemoteDebugger) { | 970 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, MAYBE_RemoteDebugger) { |
947 #if defined(OS_WIN) && defined(USE_ASH) | 971 #if defined(OS_WIN) && defined(USE_ASH) |
948 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 972 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
949 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 973 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
950 switches::kAshBrowserTests)) | 974 switches::kAshBrowserTests)) |
951 return; | 975 return; |
952 #endif | 976 #endif |
953 | 977 |
954 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; | 978 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; |
955 } | 979 } |
OLD | NEW |