blob: 318cdfb219f56b33a6d1036004e5e4957d567bb0 [file] [log] [blame]
[email protected]98cd15122012-01-05 16:27:481// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]cc273402009-05-12 09:20:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avie4d7b6f2015-12-26 00:59:185#include <stddef.h>
6
dcheng18ec0b542016-04-26 19:28:537#include <memory>
8
[email protected]900c3b22011-10-22 00:55:299#include "base/bind.h"
[email protected]4207d2b2011-11-28 18:09:2110#include "base/cancelable_callback.h"
[email protected]cc273402009-05-12 09:20:3311#include "base/command_line.h"
[email protected]ec6d5352011-12-19 14:48:3412#include "base/compiler_specific.h"
caseqe8340bc92016-04-20 00:02:5713#include "base/files/file_path.h"
skyostil02598352015-06-12 12:37:2514#include "base/location.h"
caseqc1edde1a2015-09-29 00:17:0715#include "base/macros.h"
dcheng18ec0b542016-04-26 19:28:5316#include "base/memory/ptr_util.h"
[email protected]cf3b40e32011-08-02 06:45:0317#include "base/memory/ref_counted.h"
[email protected]3985ba82010-07-29 21:44:1218#include "base/path_service.h"
skyostil02598352015-06-12 12:37:2519#include "base/single_thread_task_runner.h"
vkuzkokov00700c32015-03-17 16:04:0720#include "base/strings/string_number_conversions.h"
nick32e53c152015-12-17 19:48:5421#include "base/strings/string_util.h"
[email protected]340f55d7c2013-06-10 20:49:1122#include "base/strings/stringprintf.h"
[email protected]135cb802013-06-09 16:44:2023#include "base/strings/utf_string_conversions.h"
[email protected]c711fe712011-07-25 12:43:3024#include "base/test/test_timeouts.h"
gabb15e19072016-05-11 20:45:4125#include "base/threading/thread_task_runner_handle.h"
avie4d7b6f2015-12-26 00:59:1826#include "build/build_config.h"
[email protected]fdf40f3e2013-07-11 23:55:4627#include "chrome/browser/chrome_notification_types.h"
yurys4e413a12015-07-07 10:14:5228#include "chrome/browser/devtools/device/tcp_device_provider.h"
[email protected]d118ad72014-07-21 14:07:0129#include "chrome/browser/devtools/devtools_window_testing.h"
[email protected]965901382013-04-03 07:38:3930#include "chrome/browser/extensions/extension_apitest.h"
[email protected]ead056352013-03-12 08:47:5431#include "chrome/browser/extensions/extension_browsertest.h"
[email protected]eaa7dd182010-12-14 11:09:0032#include "chrome/browser/extensions/extension_service.h"
nick32e53c152015-12-17 19:48:5433#include "chrome/browser/extensions/test_extension_dir.h"
[email protected]d8c8f25f2011-11-02 18:18:0134#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]90354712013-11-16 00:06:3035#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]8ecad5e2010-12-02 21:18:3336#include "chrome/browser/profiles/profile.h"
[email protected]7b5dc002010-11-16 23:08:1037#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1038#include "chrome/browser/ui/browser_commands.h"
[email protected]0d56fa7212012-11-15 23:34:0239#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]2c7b4d72009-10-21 07:17:1740#include "chrome/common/chrome_paths.h"
[email protected]ec6d5352011-12-19 14:48:3441#include "chrome/common/chrome_switches.h"
peletskyi5ec60bf2015-03-12 09:53:1842#include "chrome/common/pref_names.h"
[email protected]0a57375a2013-03-07 22:18:5943#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3244#include "chrome/test/base/in_process_browser_test.h"
kozyatinskiy3ac94392016-07-14 00:07:4745#include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
[email protected]af44e7fb2011-07-29 18:32:3246#include "chrome/test/base/ui_test_utils.h"
oshimaf65398422014-11-18 23:30:4247#include "components/app_modal/javascript_app_modal_dialog.h"
48#include "components/app_modal/native_app_modal_dialog.h"
brettwb1fc1b82016-02-02 00:19:0849#include "components/prefs/pref_service.h"
[email protected]4967f792012-01-20 22:14:4050#include "content/public/browser/child_process_data.h"
[email protected]b0b67cfe2012-01-18 21:59:5751#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3652#include "content/public/browser/devtools_agent_host.h"
[email protected]87f3c082011-10-19 18:07:4453#include "content/public/browser/notification_registrar.h"
[email protected]ad50def52011-10-19 23:17:0754#include "content/public/browser/notification_service.h"
[email protected]9c1662b2012-03-06 15:44:3355#include "content/public/browser/render_view_host.h"
caseqcfbb3faf2016-02-18 19:15:0656#include "content/public/browser/render_widget_host.h"
57#include "content/public/browser/render_widget_host_view.h"
kozyatinskiy3ac94392016-07-14 00:07:4758#include "content/public/browser/url_data_source.h"
[email protected]6acde6352012-01-04 16:52:2059#include "content/public/browser/web_contents.h"
kozyatinskiy3ac94392016-07-14 00:07:4760#include "content/public/browser/web_ui_controller.h"
[email protected]724214ae2011-12-29 23:58:0061#include "content/public/browser/worker_service.h"
62#include "content/public/browser/worker_service_observer.h"
[email protected]965901382013-04-03 07:38:3963#include "content/public/common/content_switches.h"
[email protected]7d478cb2012-07-24 17:19:4264#include "content/public/test/browser_test_utils.h"
caseqc1edde1a2015-09-29 00:17:0765#include "content/public/test/test_navigation_observer.h"
reillyga3acbc12014-11-11 23:17:1266#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2467#include "extensions/browser/extension_system.h"
[email protected]adf5a102014-07-31 12:44:0668#include "extensions/browser/notification_types.h"
[email protected]c8d02992013-07-31 22:16:5169#include "extensions/common/switches.h"
nick32e53c152015-12-17 19:48:5470#include "extensions/common/value_builder.h"
71#include "net/dns/mock_host_resolver.h"
[email protected]89b32522013-05-07 20:04:2172#include "net/test/spawned_test_server/spawned_test_server.h"
caseqe8340bc92016-04-20 00:02:5773#include "net/test/url_request/url_request_mock_http_job.h"
74#include "net/url_request/url_request_context.h"
75#include "net/url_request/url_request_filter.h"
76#include "net/url_request/url_request_http_job.h"
caseqcfbb3faf2016-02-18 19:15:0677#include "third_party/WebKit/public/web/WebInputEvent.h"
caseqc5e166832015-07-10 07:40:4778#include "ui/compositor/compositor_switches.h"
79#include "ui/gl/gl_switches.h"
caseqe8340bc92016-04-20 00:02:5780#include "url/gurl.h"
[email protected]cc273402009-05-12 09:20:3381
oshima0929be2a2014-11-19 22:21:0382using app_modal::AppModalDialog;
83using app_modal::JavaScriptAppModalDialog;
84using app_modal::NativeAppModalDialog;
[email protected]631bb742011-11-02 11:29:3985using content::BrowserThread;
[email protected]0e12d7d2011-12-01 16:21:4486using content::DevToolsAgentHost;
[email protected]c5eed492012-01-04 17:07:5087using content::NavigationController;
[email protected]eaabba22012-03-07 15:02:1188using content::RenderViewHost;
[email protected]6acde6352012-01-04 16:52:2089using content::WebContents;
[email protected]724214ae2011-12-29 23:58:0090using content::WorkerService;
91using content::WorkerServiceObserver;
nick32e53c152015-12-17 19:48:5492using extensions::Extension;
[email protected]631bb742011-11-02 11:29:3993
[email protected]cc273402009-05-12 09:20:3394namespace {
95
[email protected]f72a1cc2010-04-30 07:17:3096const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html";
[email protected]f72a1cc2010-04-30 07:17:3097const char kPauseWhenLoadingDevTools[] =
98 "files/devtools/pause_when_loading_devtools.html";
99const char kPauseWhenScriptIsRunning[] =
100 "files/devtools/pause_when_script_is_running.html";
[email protected]f72a1cc2010-04-30 07:17:30101const char kPageWithContentScript[] =
102 "files/devtools/page_with_content_script.html";
[email protected]e344c392011-09-28 06:36:03103const char kNavigateBackTestPage[] =
104 "files/devtools/navigate_back.html";
dgozmanab680412016-02-04 02:21:37105const char kWindowOpenTestPage[] = "files/devtools/window_open.html";
caseqcfbb3faf2016-02-18 19:15:06106const char kLatencyInfoTestPage[] = "files/devtools/latency_info.html";
[email protected]74568b052011-05-20 09:36:14107const char kChunkedTestPage[] = "chunked";
caseqe8340bc92016-04-20 00:02:57108const char kPushTestPage[] = "files/devtools/push_test_page.html";
109// The resource is not really pushed, but mock url request job pretends it is.
110const char kPushTestResource[] = "devtools/image.png";
111const char kPushUseNullEndTime[] = "pushUseNullEndTime";
[email protected]74568b052011-05-20 09:36:14112const char kSlowTestPage[] =
113 "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2";
[email protected]1fcef592011-07-20 07:16:36114const char kSharedWorkerTestPage[] =
115 "files/workers/workers_ui_shared_worker.html";
yurys48be075f2014-10-16 09:04:21116const char kSharedWorkerTestWorker[] =
117 "files/workers/workers_ui_shared_worker.js";
[email protected]867fd9232011-10-17 06:32:34118const char kReloadSharedWorkerTestPage[] =
119 "files/workers/debug_shared_worker_initialization.html";
yurys48be075f2014-10-16 09:04:21120const char kReloadSharedWorkerTestWorker[] =
121 "files/workers/debug_shared_worker_initialization.js";
dgozman6ca18e32016-06-29 19:30:29122const char kEmulateNetworkConditionsPage[] =
123 "files/devtools/emulate_network_conditions.html";
[email protected]81762dd2009-09-24 15:16:18124
caseqc1edde1a2015-09-29 00:17:07125template <typename... T>
caseqcfbb3faf2016-02-18 19:15:06126void DispatchOnTestSuiteSkipCheck(DevToolsWindow* window,
127 const char* method,
128 T... args) {
129 RenderViewHost* rvh = DevToolsWindowTesting::Get(window)
130 ->main_web_contents()
131 ->GetRenderViewHost();
132 std::string result;
133 const char* args_array[] = {method, args...};
134 std::ostringstream script;
135 script << "uiTests.dispatchOnTestSuite([";
136 for (size_t i = 0; i < arraysize(args_array); ++i)
137 script << (i ? "," : "") << '\"' << args_array[i] << '\"';
138 script << "])";
139 ASSERT_TRUE(
140 content::ExecuteScriptAndExtractString(rvh, script.str(), &result));
141 EXPECT_EQ("[OK]", result);
142}
143
144template <typename... T>
caseqc1edde1a2015-09-29 00:17:07145void DispatchOnTestSuite(DevToolsWindow* window,
146 const char* method,
147 T... args) {
[email protected]1fcef592011-07-20 07:16:36148 std::string result;
caseqc1edde1a2015-09-29 00:17:07149 RenderViewHost* rvh = DevToolsWindowTesting::Get(window)
150 ->main_web_contents()
151 ->GetRenderViewHost();
[email protected]1fcef592011-07-20 07:16:36152 // At first check that JavaScript part of the front-end is loaded by
153 // checking that global variable uiTests exists(it's created after all js
154 // files have been loaded) and has runTest method.
155 ASSERT_TRUE(
[email protected]b6987e02013-01-04 18:30:43156 content::ExecuteScriptAndExtractString(
[email protected]d118ad72014-07-21 14:07:01157 rvh,
[email protected]06bc5d92013-01-02 22:44:13158 "window.domAutomationController.send("
caseqc1edde1a2015-09-29 00:17:07159 " '' + (window.uiTests && (typeof uiTests.dispatchOnTestSuite)));",
[email protected]1fcef592011-07-20 07:16:36160 &result));
[email protected]b946b422014-03-18 22:53:40161 ASSERT_EQ("function", result) << "DevTools front-end is broken.";
caseqcfbb3faf2016-02-18 19:15:06162 DispatchOnTestSuiteSkipCheck(window, method, args...);
[email protected]1fcef592011-07-20 07:16:36163}
[email protected]cc273402009-05-12 09:20:33164
caseqc1edde1a2015-09-29 00:17:07165void RunTestFunction(DevToolsWindow* window, const char* test_name) {
166 DispatchOnTestSuite(window, test_name);
167}
168
169void SwitchToPanel(DevToolsWindow* window, const char* panel) {
170 DispatchOnTestSuite(window, "switchToPanel", panel);
171}
172
nick32e53c152015-12-17 19:48:54173// Version of SwitchToPanel that works with extension-created panels.
174void SwitchToExtensionPanel(DevToolsWindow* window,
175 const Extension* devtools_extension,
176 const char* panel_name) {
177 // The full name is the concatenation of the extension URL (stripped of its
178 // trailing '/') and the |panel_name| that was passed to panels.create().
179 std::string prefix = base::TrimString(devtools_extension->url().spec(), "/",
180 base::TRIM_TRAILING)
181 .as_string();
182 SwitchToPanel(window, (prefix + panel_name).c_str());
183}
184
caseqe8340bc92016-04-20 00:02:57185class PushTimesMockURLRequestJob : public net::URLRequestMockHTTPJob {
186 public:
187 PushTimesMockURLRequestJob(net::URLRequest* request,
188 net::NetworkDelegate* network_delegate,
189 base::FilePath file_path)
190 : net::URLRequestMockHTTPJob(
191 request,
192 network_delegate,
193 file_path,
194 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
195 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {}
196
197 void Start() override {
198 load_timing_info_.socket_reused = true;
199 load_timing_info_.request_start_time = base::Time::Now();
200 load_timing_info_.request_start = base::TimeTicks::Now();
201 load_timing_info_.send_start = base::TimeTicks::Now();
202 load_timing_info_.send_end = base::TimeTicks::Now();
203 load_timing_info_.receive_headers_end = base::TimeTicks::Now();
204
205 net::URLRequestMockHTTPJob::Start();
206 }
207
208 void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override {
209 load_timing_info_.push_start = load_timing_info_.request_start -
210 base::TimeDelta::FromMilliseconds(100);
211 if (load_timing_info_.push_end.is_null() &&
212 request()->url().query() != kPushUseNullEndTime) {
213 load_timing_info_.push_end = base::TimeTicks::Now();
214 }
215 *load_timing_info = load_timing_info_;
216 }
217
218 private:
219 mutable net::LoadTimingInfo load_timing_info_;
220 DISALLOW_COPY_AND_ASSIGN(PushTimesMockURLRequestJob);
221};
222
223class TestInterceptor : public net::URLRequestInterceptor {
224 public:
225 // Creates TestInterceptor and registers it with the URLRequestFilter,
226 // which takes ownership of it.
227 static void Register(const GURL& url, const base::FilePath& file_path) {
228 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
229 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor(
230 url.scheme(), url.host(),
dcheng18ec0b542016-04-26 19:28:53231 base::WrapUnique(new TestInterceptor(url, file_path)));
caseqe8340bc92016-04-20 00:02:57232 }
233
234 // Unregisters previously created TestInterceptor, which should delete it.
235 static void Unregister(const GURL& url) {
236 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
237 net::URLRequestFilter::GetInstance()->RemoveHostnameHandler(url.scheme(),
238 url.host());
239 }
240
241 // net::URLRequestJobFactory::ProtocolHandler implementation:
242 net::URLRequestJob* MaybeInterceptRequest(
243 net::URLRequest* request,
244 net::NetworkDelegate* network_delegate) const override {
245 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
246 if (request->url().path() != url_.path())
247 return nullptr;
248 return new PushTimesMockURLRequestJob(request, network_delegate,
249 file_path_);
250 }
251
252 private:
253 TestInterceptor(const GURL& url, const base::FilePath& file_path)
254 : url_(url), file_path_(file_path) {}
255
256 const GURL url_;
257 const base::FilePath file_path_;
258
259 DISALLOW_COPY_AND_ASSIGN(TestInterceptor);
260};
261
[email protected]b9c5d50b2014-01-16 20:37:43262} // namespace
263
[email protected]cc273402009-05-12 09:20:33264class DevToolsSanityTest : public InProcessBrowserTest {
265 public:
[email protected]b3f957e62014-08-08 10:09:02266 DevToolsSanityTest() : window_(NULL) {}
[email protected]cc273402009-05-12 09:20:33267
nick32e53c152015-12-17 19:48:54268 void SetUpOnMainThread() override {
269 host_resolver()->AddRule("*", "127.0.0.1");
270 }
271
[email protected]ff7a8f6f2009-06-10 09:44:36272 protected:
[email protected]f72a1cc2010-04-30 07:17:30273 void RunTest(const std::string& test_name, const std::string& test_page) {
[email protected]b9c5d50b2014-01-16 20:37:43274 OpenDevToolsWindow(test_page, false);
[email protected]ec6d5352011-12-19 14:48:34275 RunTestFunction(window_, test_name.c_str());
[email protected]ff7a8f6f2009-06-10 09:44:36276 CloseDevToolsWindow();
277 }
278
caseqcfbb3faf2016-02-18 19:15:06279 template <typename... T>
280 void RunTestMethod(const char* method, T... args) {
281 DispatchOnTestSuiteSkipCheck(window_, method, args...);
282 }
283
284 template <typename... T>
285 void DispatchAndWait(const char* method, T... args) {
286 DispatchOnTestSuiteSkipCheck(window_, "waitForAsync", method, args...);
287 }
288
289 template <typename... T>
290 void DispatchInPageAndWait(const char* method, T... args) {
291 DispatchAndWait("invokePageFunctionAsync", method, args...);
292 }
293
[email protected]5da96a42013-11-21 06:49:21294 void LoadTestPage(const std::string& test_page) {
svaldeza01f7d92015-11-18 17:47:56295 GURL url = spawned_test_server()->GetURL(test_page);
[email protected]cc273402009-05-12 09:20:33296 ui_test_utils::NavigateToURL(browser(), url);
[email protected]5da96a42013-11-21 06:49:21297 }
298
[email protected]b9c5d50b2014-01-16 20:37:43299 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) {
svaldeza01f7d92015-11-18 17:47:56300 ASSERT_TRUE(spawned_test_server()->Start());
[email protected]5da96a42013-11-21 06:49:21301 LoadTestPage(test_page);
[email protected]cc273402009-05-12 09:20:33302
[email protected]b3f957e62014-08-08 10:09:02303 window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(),
304 is_docked);
[email protected]cc273402009-05-12 09:20:33305 }
306
[email protected]6acde6352012-01-04 16:52:20307 WebContents* GetInspectedTab() {
[email protected]36953572013-01-14 18:38:10308 return browser()->tab_strip_model()->GetWebContentsAt(0);
[email protected]13a6abf82009-10-31 08:42:21309 }
310
[email protected]1b91f5102009-06-09 15:31:30311 void CloseDevToolsWindow() {
[email protected]d118ad72014-07-21 14:07:01312 DevToolsWindowTesting::CloseDevToolsWindowSync(window_);
313 }
314
315 WebContents* main_web_contents() {
316 return DevToolsWindowTesting::Get(window_)->main_web_contents();
317 }
318
319 WebContents* toolbox_web_contents() {
320 return DevToolsWindowTesting::Get(window_)->toolbox_web_contents();
[email protected]1b91f5102009-06-09 15:31:30321 }
322
[email protected]1b91f5102009-06-09 15:31:30323 DevToolsWindow* window_;
[email protected]cc273402009-05-12 09:20:33324};
325
[email protected]a1406cb2013-10-16 14:30:43326// Used to block until a dev tools window gets beforeunload event.
327class DevToolsWindowBeforeUnloadObserver
328 : public content::WebContentsObserver {
329 public:
[email protected]90354712013-11-16 00:06:30330 explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*);
331 void Wait();
[email protected]a1406cb2013-10-16 14:30:43332 private:
333 // Invoked when the beforeunload handler fires.
dcheng03748a42014-10-21 10:19:13334 void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
[email protected]a1406cb2013-10-16 14:30:43335
336 bool m_fired;
[email protected]90354712013-11-16 00:06:30337 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
[email protected]a1406cb2013-10-16 14:30:43338 DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver);
339};
340
341DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver(
[email protected]90354712013-11-16 00:06:30342 DevToolsWindow* devtools_window)
[email protected]d118ad72014-07-21 14:07:01343 : WebContentsObserver(
344 DevToolsWindowTesting::Get(devtools_window)->main_web_contents()),
[email protected]a1406cb2013-10-16 14:30:43345 m_fired(false) {
346}
347
[email protected]90354712013-11-16 00:06:30348void DevToolsWindowBeforeUnloadObserver::Wait() {
349 if (m_fired)
350 return;
351 message_loop_runner_ = new content::MessageLoopRunner;
352 message_loop_runner_->Run();
[email protected]a1406cb2013-10-16 14:30:43353}
354
355void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired(
356 const base::TimeTicks& proceed_time) {
357 m_fired = true;
[email protected]90354712013-11-16 00:06:30358 if (message_loop_runner_.get())
359 message_loop_runner_->Quit();
[email protected]a1406cb2013-10-16 14:30:43360}
361
[email protected]90354712013-11-16 00:06:30362class DevToolsBeforeUnloadTest: public DevToolsSanityTest {
363 public:
avi3ef9ec9e2014-12-22 22:50:17364 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]f9631b92013-12-10 22:19:48365 command_line->AppendSwitch(
366 switches::kDisableHangMonitor);
367 }
368
[email protected]90354712013-11-16 00:06:30369 void CloseInspectedTab() {
370 browser()->tab_strip_model()->CloseWebContentsAt(0,
371 TabStripModel::CLOSE_NONE);
372 }
373
[email protected]d118ad72014-07-21 14:07:01374 void CloseDevToolsWindowAsync() {
375 DevToolsWindowTesting::CloseDevToolsWindow(window_);
[email protected]90354712013-11-16 00:06:30376 }
377
378 void CloseInspectedBrowser() {
379 chrome::CloseWindow(browser());
380 }
[email protected]d118ad72014-07-21 14:07:01381
[email protected]90354712013-11-16 00:06:30382 protected:
383 void InjectBeforeUnloadListener(content::WebContents* web_contents) {
384 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
385 "window.addEventListener('beforeunload',"
386 "function(event) { event.returnValue = 'Foo'; });"));
387 }
388
[email protected]b9c5d50b2014-01-16 20:37:43389 void RunBeforeUnloadSanityTest(bool is_docked,
390 base::Callback<void(void)> close_method,
391 bool wait_for_browser_close = true) {
392 OpenDevToolsWindow(kDebuggerTestPage, is_docked);
[email protected]d118ad72014-07-21 14:07:01393 scoped_refptr<content::MessageLoopRunner> runner =
394 new content::MessageLoopRunner;
395 DevToolsWindowTesting::Get(window_)->
396 SetCloseCallback(runner->QuitClosure());
397 InjectBeforeUnloadListener(main_web_contents());
[email protected]90354712013-11-16 00:06:30398 {
399 DevToolsWindowBeforeUnloadObserver before_unload_observer(window_);
400 close_method.Run();
401 CancelModalDialog();
402 before_unload_observer.Wait();
403 }
404 {
405 content::WindowedNotificationObserver close_observer(
406 chrome::NOTIFICATION_BROWSER_CLOSED,
407 content::Source<Browser>(browser()));
408 close_method.Run();
409 AcceptModalDialog();
410 if (wait_for_browser_close)
411 close_observer.Wait();
412 }
[email protected]d118ad72014-07-21 14:07:01413 runner->Run();
[email protected]90354712013-11-16 00:06:30414 }
415
416 DevToolsWindow* OpenDevToolWindowOnWebContents(
[email protected]b9c5d50b2014-01-16 20:37:43417 content::WebContents* contents, bool is_docked) {
[email protected]b3f957e62014-08-08 10:09:02418 DevToolsWindow* window =
419 DevToolsWindowTesting::OpenDevToolsWindowSync(contents, is_docked);
[email protected]90354712013-11-16 00:06:30420 return window;
421 }
422
[email protected]1692b80f72013-11-28 20:08:58423 void OpenDevToolsPopupWindow(DevToolsWindow* devtools_window) {
424 content::WindowedNotificationObserver observer(
425 content::NOTIFICATION_LOAD_STOP,
426 content::NotificationService::AllSources());
427 ASSERT_TRUE(content::ExecuteScript(
[email protected]d118ad72014-07-21 14:07:01428 DevToolsWindowTesting::Get(devtools_window)->
429 main_web_contents()->GetRenderViewHost(),
[email protected]1692b80f72013-11-28 20:08:58430 "window.open(\"\", \"\", \"location=0\");"));
431 observer.Wait();
432 }
433
434 void CloseDevToolsPopupWindow(DevToolsWindow* devtools_window) {
[email protected]d118ad72014-07-21 14:07:01435 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window);
[email protected]1692b80f72013-11-28 20:08:58436 }
437
[email protected]90354712013-11-16 00:06:30438 void AcceptModalDialog() {
439 NativeAppModalDialog* native_dialog = GetDialog();
440 native_dialog->AcceptAppModalDialog();
441 }
442
443 void CancelModalDialog() {
444 NativeAppModalDialog* native_dialog = GetDialog();
445 native_dialog->CancelAppModalDialog();
446 }
447
448 NativeAppModalDialog* GetDialog() {
449 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
450 EXPECT_TRUE(dialog->IsJavaScriptModalDialog());
451 JavaScriptAppModalDialog* js_dialog =
452 static_cast<JavaScriptAppModalDialog*>(dialog);
453 NativeAppModalDialog* native_dialog = js_dialog->native_dialog();
454 EXPECT_TRUE(native_dialog);
455 return native_dialog;
456 }
457};
458
[email protected]f9631b92013-12-10 22:19:48459class DevToolsUnresponsiveBeforeUnloadTest: public DevToolsBeforeUnloadTest {
460 public:
avi3ef9ec9e2014-12-22 22:50:17461 void SetUpCommandLine(base::CommandLine* command_line) override {}
[email protected]f9631b92013-12-10 22:19:48462};
463
[email protected]4207d2b2011-11-28 18:09:21464void TimeoutCallback(const std::string& timeout_message) {
[email protected]b946b422014-03-18 22:53:40465 ADD_FAILURE() << timeout_message;
ki.stfuc4f8e242015-10-09 20:40:20466 base::MessageLoop::current()->QuitWhenIdle();
[email protected]4207d2b2011-11-28 18:09:21467}
[email protected]680bc222009-10-27 10:46:22468
[email protected]2c7b4d72009-10-21 07:17:17469// Base class for DevTools tests that test devtools functionality for
470// extensions and content scripts.
[email protected]fb996d32011-12-21 12:55:30471class DevToolsExtensionTest : public DevToolsSanityTest,
472 public content::NotificationObserver {
[email protected]2c7b4d72009-10-21 07:17:17473 public:
[email protected]fb996d32011-12-21 12:55:30474 DevToolsExtensionTest() : DevToolsSanityTest() {
[email protected]2c7b4d72009-10-21 07:17:17475 PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_);
476 test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools");
477 test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions");
478 }
479
480 protected:
[email protected]4207d2b2011-11-28 18:09:21481 // Load an extension from test\data\devtools\extensions\<extension_name>
[email protected]2c7b4d72009-10-21 07:17:17482 void LoadExtension(const char* extension_name) {
[email protected]650b2d52013-02-10 03:41:45483 base::FilePath path = test_extensions_dir_.AppendASCII(extension_name);
[email protected]2c7b4d72009-10-21 07:17:17484 ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension.";
485 }
486
nick32e53c152015-12-17 19:48:54487 const Extension* LoadExtensionFromPath(const base::FilePath& path) {
[email protected]06bdd2b2012-11-30 18:47:13488 ExtensionService* service = extensions::ExtensionSystem::Get(
489 browser()->profile())->extension_service();
reillyga3acbc12014-11-11 23:17:12490 extensions::ExtensionRegistry* registry =
491 extensions::ExtensionRegistry::Get(browser()->profile());
492 size_t num_before = registry->enabled_extensions().size();
[email protected]2c7b4d72009-10-21 07:17:17493 {
[email protected]6c2381d2011-10-19 02:52:53494 content::NotificationRegistrar registrar;
[email protected]fdc76192014-04-20 21:54:41495 registrar.Add(this,
[email protected]adf5a102014-07-31 12:44:06496 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]ad50def52011-10-19 23:17:07497 content::NotificationService::AllSources());
[email protected]d4d57df2011-11-30 20:33:52498 base::CancelableClosure timeout(
[email protected]4207d2b2011-11-28 18:09:21499 base::Bind(&TimeoutCallback, "Extension load timed out."));
skyostil02598352015-06-12 12:37:25500 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]4173deb2013-06-07 15:21:04501 FROM_HERE, timeout.callback(), TestTimeouts::action_timeout());
[email protected]d8c8f25f2011-11-02 18:18:01502 extensions::UnpackedInstaller::Create(service)->Load(path);
[email protected]729eb632012-07-26 04:45:26503 content::RunMessageLoop();
[email protected]4207d2b2011-11-28 18:09:21504 timeout.Cancel();
[email protected]2c7b4d72009-10-21 07:17:17505 }
reillyga3acbc12014-11-11 23:17:12506 size_t num_after = registry->enabled_extensions().size();
[email protected]680bc222009-10-27 10:46:22507 if (num_after != (num_before + 1))
nick32e53c152015-12-17 19:48:54508 return nullptr;
[email protected]680bc222009-10-27 10:46:22509
nick32e53c152015-12-17 19:48:54510 if (!WaitForExtensionViewsToLoad())
511 return nullptr;
512
513 return GetExtensionByPath(registry->enabled_extensions(), path);
514 }
515
516 private:
517 const Extension* GetExtensionByPath(
518 const extensions::ExtensionSet& extensions,
519 const base::FilePath& path) {
520 base::FilePath extension_path = base::MakeAbsoluteFilePath(path);
521 EXPECT_TRUE(!extension_path.empty());
522 for (const scoped_refptr<const Extension>& extension : extensions) {
523 if (extension->path() == extension_path) {
524 return extension.get();
525 }
526 }
527 return nullptr;
[email protected]680bc222009-10-27 10:46:22528 }
529
[email protected]d1fe1352012-04-26 00:47:32530 bool WaitForExtensionViewsToLoad() {
531 // Wait for all the extension render views that exist to finish loading.
532 // NOTE: This assumes that the extension views list is not changing while
[email protected]680bc222009-10-27 10:46:22533 // this method is running.
534
[email protected]6c2381d2011-10-19 02:52:53535 content::NotificationRegistrar registrar;
[email protected]adf5a102014-07-31 12:44:06536 registrar.Add(this,
kalmanfd474fa2015-03-16 22:30:57537 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD,
[email protected]ad50def52011-10-19 23:17:07538 content::NotificationService::AllSources());
[email protected]d4d57df2011-11-30 20:33:52539 base::CancelableClosure timeout(
[email protected]4207d2b2011-11-28 18:09:21540 base::Bind(&TimeoutCallback, "Extension host load timed out."));
skyostil02598352015-06-12 12:37:25541 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]4173deb2013-06-07 15:21:04542 FROM_HERE, timeout.callback(), TestTimeouts::action_timeout());
[email protected]680bc222009-10-27 10:46:22543
[email protected]98b6d942013-11-10 00:34:07544 extensions::ProcessManager* manager =
reillyg0ea3fa902014-10-28 15:30:23545 extensions::ProcessManager::Get(browser()->profile());
rdevlin.cronin6ae04a012015-04-03 20:19:40546 extensions::ProcessManager::FrameSet all_frames = manager->GetAllFrames();
547 for (extensions::ProcessManager::FrameSet::const_iterator iter =
548 all_frames.begin();
549 iter != all_frames.end();) {
550 if (!content::WebContents::FromRenderFrameHost(*iter)->IsLoading())
[email protected]680bc222009-10-27 10:46:22551 ++iter;
552 else
[email protected]729eb632012-07-26 04:45:26553 content::RunMessageLoop();
[email protected]680bc222009-10-27 10:46:22554 }
555
[email protected]4207d2b2011-11-28 18:09:21556 timeout.Cancel();
[email protected]680bc222009-10-27 10:46:22557 return true;
[email protected]2c7b4d72009-10-21 07:17:17558 }
559
dcheng03748a42014-10-21 10:19:13560 void Observe(int type,
561 const content::NotificationSource& source,
562 const content::NotificationDetails& details) override {
[email protected]432115822011-07-10 15:52:27563 switch (type) {
[email protected]adf5a102014-07-31 12:44:06564 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED:
kalmanfd474fa2015-03-16 22:30:57565 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD:
ki.stfuc4f8e242015-10-09 20:40:20566 base::MessageLoopForUI::current()->QuitWhenIdle();
[email protected]2c7b4d72009-10-21 07:17:17567 break;
[email protected]2c7b4d72009-10-21 07:17:17568 default:
569 NOTREACHED();
570 break;
571 }
572 }
573
[email protected]650b2d52013-02-10 03:41:45574 base::FilePath test_extensions_dir_;
[email protected]2c7b4d72009-10-21 07:17:17575};
576
[email protected]e89c05a2011-12-26 08:51:57577class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest {
578 public:
avi3ef9ec9e2014-12-22 22:50:17579 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]c8d02992013-07-31 22:16:51580 command_line->AppendSwitch(
581 extensions::switches::kEnableExperimentalExtensionApis);
[email protected]e89c05a2011-12-26 08:51:57582 }
583};
584
[email protected]1fcef592011-07-20 07:16:36585class WorkerDevToolsSanityTest : public InProcessBrowserTest {
586 public:
[email protected]90ca44272012-07-18 18:15:48587 WorkerDevToolsSanityTest() : window_(NULL) {}
[email protected]1fcef592011-07-20 07:16:36588
589 protected:
[email protected]649d1c02012-04-27 02:56:21590 class WorkerData : public base::RefCountedThreadSafe<WorkerData> {
591 public:
[email protected]d9ddc0d2011-10-12 08:40:12592 WorkerData() : worker_process_id(0), worker_route_id(0) {}
[email protected]cf3b40e32011-08-02 06:45:03593 int worker_process_id;
594 int worker_route_id;
[email protected]649d1c02012-04-27 02:56:21595
596 private:
597 friend class base::RefCountedThreadSafe<WorkerData>;
598 ~WorkerData() {}
[email protected]d9ddc0d2011-10-12 08:40:12599 };
600
601 class WorkerCreationObserver : public WorkerServiceObserver {
602 public:
yurys48be075f2014-10-16 09:04:21603 explicit WorkerCreationObserver(const std::string& path,
604 WorkerData* worker_data)
605 : path_(path), worker_data_(worker_data) {}
[email protected]d9ddc0d2011-10-12 08:40:12606
607 private:
dcheng03748a42014-10-21 10:19:13608 ~WorkerCreationObserver() override {}
[email protected]d9ddc0d2011-10-12 08:40:12609
dcheng03748a42014-10-21 10:19:13610 void WorkerCreated(const GURL& url,
611 const base::string16& name,
612 int process_id,
613 int route_id) override {
yurys48be075f2014-10-16 09:04:21614 if (url.path().rfind(path_) == std::string::npos)
615 return;
[email protected]62151052012-02-01 18:40:48616 worker_data_->worker_process_id = process_id;
617 worker_data_->worker_route_id = route_id;
[email protected]d9ddc0d2011-10-12 08:40:12618 WorkerService::GetInstance()->RemoveObserver(this);
619 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
ki.stfuc4f8e242015-10-09 20:40:20620 base::MessageLoop::QuitWhenIdleClosure());
[email protected]d9ddc0d2011-10-12 08:40:12621 delete this;
622 }
yurys48be075f2014-10-16 09:04:21623 std::string path_;
[email protected]d9ddc0d2011-10-12 08:40:12624 scoped_refptr<WorkerData> worker_data_;
[email protected]cf3b40e32011-08-02 06:45:03625 };
626
[email protected]867fd9232011-10-17 06:32:34627 class WorkerTerminationObserver : public WorkerServiceObserver {
628 public:
629 explicit WorkerTerminationObserver(WorkerData* worker_data)
630 : worker_data_(worker_data) {
631 }
632
633 private:
dcheng03748a42014-10-21 10:19:13634 ~WorkerTerminationObserver() override {}
[email protected]867fd9232011-10-17 06:32:34635
dcheng03748a42014-10-21 10:19:13636 void WorkerDestroyed(int process_id, int route_id) override {
[email protected]62151052012-02-01 18:40:48637 ASSERT_EQ(worker_data_->worker_process_id, process_id);
638 ASSERT_EQ(worker_data_->worker_route_id, route_id);
[email protected]867fd9232011-10-17 06:32:34639 WorkerService::GetInstance()->RemoveObserver(this);
640 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
ki.stfuc4f8e242015-10-09 20:40:20641 base::MessageLoop::QuitWhenIdleClosure());
[email protected]867fd9232011-10-17 06:32:34642 delete this;
643 }
[email protected]867fd9232011-10-17 06:32:34644 scoped_refptr<WorkerData> worker_data_;
645 };
646
yurys48be075f2014-10-16 09:04:21647 void RunTest(const char* test_name,
648 const char* test_page,
649 const char* worker_path) {
svaldeza01f7d92015-11-18 17:47:56650 ASSERT_TRUE(spawned_test_server()->Start());
651 GURL url = spawned_test_server()->GetURL(test_page);
[email protected]1fcef592011-07-20 07:16:36652 ui_test_utils::NavigateToURL(browser(), url);
653
yurys48be075f2014-10-16 09:04:21654 scoped_refptr<WorkerData> worker_data =
655 WaitForFirstSharedWorker(worker_path);
[email protected]867fd9232011-10-17 06:32:34656 OpenDevToolsWindowForSharedWorker(worker_data.get());
[email protected]ec6d5352011-12-19 14:48:34657 RunTestFunction(window_, test_name);
[email protected]1fcef592011-07-20 07:16:36658 CloseDevToolsWindow();
659 }
660
[email protected]62151052012-02-01 18:40:48661 static void TerminateWorkerOnIOThread(scoped_refptr<WorkerData> worker_data) {
[email protected]b946b422014-03-18 22:53:40662 if (!WorkerService::GetInstance()->TerminateWorker(
663 worker_data->worker_process_id, worker_data->worker_route_id))
664 FAIL() << "Failed to terminate worker.\n";
665 WorkerService::GetInstance()->AddObserver(
666 new WorkerTerminationObserver(worker_data.get()));
[email protected]867fd9232011-10-17 06:32:34667 }
668
669 static void TerminateWorker(scoped_refptr<WorkerData> worker_data) {
[email protected]900c3b22011-10-22 00:55:29670 BrowserThread::PostTask(
671 BrowserThread::IO, FROM_HERE,
672 base::Bind(&TerminateWorkerOnIOThread, worker_data));
[email protected]729eb632012-07-26 04:45:26673 content::RunMessageLoop();
[email protected]867fd9232011-10-17 06:32:34674 }
675
[email protected]cf3b40e32011-08-02 06:45:03676 static void WaitForFirstSharedWorkerOnIOThread(
yurys48be075f2014-10-16 09:04:21677 const std::string& path,
[email protected]d9ddc0d2011-10-12 08:40:12678 scoped_refptr<WorkerData> worker_data) {
[email protected]62151052012-02-01 18:40:48679 std::vector<WorkerService::WorkerInfo> worker_info =
680 WorkerService::GetInstance()->GetWorkers();
yurys48be075f2014-10-16 09:04:21681 for (size_t i = 0; i < worker_info.size(); i++) {
682 if (worker_info[i].url.path().rfind(path) == std::string::npos)
683 continue;
[email protected]62151052012-02-01 18:40:48684 worker_data->worker_process_id = worker_info[0].process_id;
685 worker_data->worker_route_id = worker_info[0].route_id;
686 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
ki.stfuc4f8e242015-10-09 20:40:20687 base::MessageLoop::QuitWhenIdleClosure());
[email protected]62151052012-02-01 18:40:48688 return;
[email protected]1fcef592011-07-20 07:16:36689 }
[email protected]d9ddc0d2011-10-12 08:40:12690
691 WorkerService::GetInstance()->AddObserver(
yurys48be075f2014-10-16 09:04:21692 new WorkerCreationObserver(path, worker_data.get()));
[email protected]1fcef592011-07-20 07:16:36693 }
694
yurys48be075f2014-10-16 09:04:21695 static scoped_refptr<WorkerData> WaitForFirstSharedWorker(const char* path) {
[email protected]cf3b40e32011-08-02 06:45:03696 scoped_refptr<WorkerData> worker_data(new WorkerData());
[email protected]900c3b22011-10-22 00:55:29697 BrowserThread::PostTask(
yurys48be075f2014-10-16 09:04:21698 BrowserThread::IO,
699 FROM_HERE,
700 base::Bind(&WaitForFirstSharedWorkerOnIOThread, path, worker_data));
[email protected]729eb632012-07-26 04:45:26701 content::RunMessageLoop();
[email protected]867fd9232011-10-17 06:32:34702 return worker_data;
703 }
[email protected]cf3b40e32011-08-02 06:45:03704
[email protected]867fd9232011-10-17 06:32:34705 void OpenDevToolsWindowForSharedWorker(WorkerData* worker_data) {
[email protected]cf3b40e32011-08-02 06:45:03706 Profile* profile = browser()->profile();
[email protected]70fd1e82012-12-26 15:08:10707 scoped_refptr<DevToolsAgentHost> agent_host(
[email protected]98f66112012-12-25 12:59:36708 DevToolsAgentHost::GetForWorker(
[email protected]b3762af2011-09-08 06:23:46709 worker_data->worker_process_id,
[email protected]70fd1e82012-12-26 15:08:10710 worker_data->worker_route_id));
[email protected]d118ad72014-07-21 14:07:01711 window_ = DevToolsWindowTesting::OpenDevToolsWindowForWorkerSync(
dchengf4b56572014-08-27 06:59:37712 profile, agent_host.get());
[email protected]1fcef592011-07-20 07:16:36713 }
714
715 void CloseDevToolsWindow() {
[email protected]d118ad72014-07-21 14:07:01716 DevToolsWindowTesting::CloseDevToolsWindowSync(window_);
[email protected]1fcef592011-07-20 07:16:36717 }
718
719 DevToolsWindow* window_;
720};
721
[email protected]90354712013-11-16 00:06:30722// Tests that BeforeUnload event gets called on docked devtools if
723// we try to close them.
724IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) {
[email protected]b9c5d50b2014-01-16 20:37:43725 RunBeforeUnloadSanityTest(true, base::Bind(
tzike04a1472016-08-02 21:00:33726 &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync,
727 base::Unretained(this)), false);
[email protected]90354712013-11-16 00:06:30728}
729
730// Tests that BeforeUnload event gets called on docked devtools if
731// we try to close the inspected page.
732IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
733 TestDockedDevToolsInspectedTabClose) {
[email protected]b9c5d50b2014-01-16 20:37:43734 RunBeforeUnloadSanityTest(true, base::Bind(
tzike04a1472016-08-02 21:00:33735 &DevToolsBeforeUnloadTest::CloseInspectedTab,
736 base::Unretained(this)));
[email protected]90354712013-11-16 00:06:30737}
738
739// Tests that BeforeUnload event gets called on docked devtools if
740// we try to close the inspected browser.
741IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
742 TestDockedDevToolsInspectedBrowserClose) {
[email protected]b9c5d50b2014-01-16 20:37:43743 RunBeforeUnloadSanityTest(true, base::Bind(
tzike04a1472016-08-02 21:00:33744 &DevToolsBeforeUnloadTest::CloseInspectedBrowser,
745 base::Unretained(this)));
[email protected]90354712013-11-16 00:06:30746}
747
748// Tests that BeforeUnload event gets called on undocked devtools if
749// we try to close them.
750IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) {
[email protected]b9c5d50b2014-01-16 20:37:43751 RunBeforeUnloadSanityTest(false, base::Bind(
tzike04a1472016-08-02 21:00:33752 &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync,
753 base::Unretained(this)), false);
[email protected]90354712013-11-16 00:06:30754}
755
756// Tests that BeforeUnload event gets called on undocked devtools if
757// we try to close the inspected page.
758IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
759 TestUndockedDevToolsInspectedTabClose) {
[email protected]b9c5d50b2014-01-16 20:37:43760 RunBeforeUnloadSanityTest(false, base::Bind(
tzike04a1472016-08-02 21:00:33761 &DevToolsBeforeUnloadTest::CloseInspectedTab,
762 base::Unretained(this)));
[email protected]90354712013-11-16 00:06:30763}
764
765// Tests that BeforeUnload event gets called on undocked devtools if
766// we try to close the inspected browser.
767IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
768 TestUndockedDevToolsInspectedBrowserClose) {
[email protected]b9c5d50b2014-01-16 20:37:43769 RunBeforeUnloadSanityTest(false, base::Bind(
tzike04a1472016-08-02 21:00:33770 &DevToolsBeforeUnloadTest::CloseInspectedBrowser,
771 base::Unretained(this)));
[email protected]90354712013-11-16 00:06:30772}
773
774// Tests that BeforeUnload event gets called on undocked devtools if
775// we try to exit application.
776IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
777 TestUndockedDevToolsApplicationClose) {
[email protected]b9c5d50b2014-01-16 20:37:43778 RunBeforeUnloadSanityTest(false, base::Bind(
[email protected]90354712013-11-16 00:06:30779 &chrome::CloseAllBrowsers));
780}
781
[email protected]c0da7c12013-11-27 19:07:00782// Tests that inspected tab gets closed if devtools renderer
783// becomes unresponsive during beforeunload event interception.
784// @see http://crbug.com/322380
lushnikovcf05b642015-11-04 00:10:13785// Disabled because of http://crbug.com/410327
[email protected]f9631b92013-12-10 22:19:48786IN_PROC_BROWSER_TEST_F(DevToolsUnresponsiveBeforeUnloadTest,
lushnikovcf05b642015-11-04 00:10:13787 DISABLED_TestUndockedDevToolsUnresponsive) {
svaldeza01f7d92015-11-18 17:47:56788 ASSERT_TRUE(spawned_test_server()->Start());
[email protected]c0da7c12013-11-27 19:07:00789 LoadTestPage(kDebuggerTestPage);
790 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
[email protected]b9c5d50b2014-01-16 20:37:43791 GetInspectedTab(), false);
[email protected]d118ad72014-07-21 14:07:01792
793 scoped_refptr<content::MessageLoopRunner> runner =
794 new content::MessageLoopRunner;
795 DevToolsWindowTesting::Get(devtools_window)->SetCloseCallback(
796 runner->QuitClosure());
[email protected]c0da7c12013-11-27 19:07:00797
798 ASSERT_TRUE(content::ExecuteScript(
[email protected]d118ad72014-07-21 14:07:01799 DevToolsWindowTesting::Get(devtools_window)->main_web_contents()->
800 GetRenderViewHost(),
[email protected]c0da7c12013-11-27 19:07:00801 "window.addEventListener('beforeunload',"
802 "function(event) { while (true); });"));
803 CloseInspectedTab();
[email protected]d118ad72014-07-21 14:07:01804 runner->Run();
[email protected]c0da7c12013-11-27 19:07:00805}
806
[email protected]1692b80f72013-11-28 20:08:58807// Tests that closing worker inspector window does not cause browser crash
808// @see http://crbug.com/323031
809IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
810 TestWorkerWindowClosing) {
svaldeza01f7d92015-11-18 17:47:56811 ASSERT_TRUE(spawned_test_server()->Start());
[email protected]1692b80f72013-11-28 20:08:58812 LoadTestPage(kDebuggerTestPage);
813 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
[email protected]b9c5d50b2014-01-16 20:37:43814 GetInspectedTab(), false);
[email protected]1692b80f72013-11-28 20:08:58815
816 OpenDevToolsPopupWindow(devtools_window);
817 CloseDevToolsPopupWindow(devtools_window);
818}
819
[email protected]90354712013-11-16 00:06:30820// Tests that BeforeUnload event gets called on devtools that are opened
821// on another devtools.
[email protected]68b36ac2013-11-19 23:56:03822IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
kozyatinskiy6e281632016-06-09 18:08:56823 TestDevToolsOnDevTools) {
svaldeza01f7d92015-11-18 17:47:56824 ASSERT_TRUE(spawned_test_server()->Start());
[email protected]5da96a42013-11-21 06:49:21825 LoadTestPage(kDebuggerTestPage);
[email protected]90354712013-11-16 00:06:30826
827 std::vector<DevToolsWindow*> windows;
828 std::vector<content::WindowedNotificationObserver*> close_observers;
829 content::WebContents* inspected_web_contents = GetInspectedTab();
830 for (int i = 0; i < 3; ++i) {
831 DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
[email protected]b9c5d50b2014-01-16 20:37:43832 inspected_web_contents, i == 0);
[email protected]90354712013-11-16 00:06:30833 windows.push_back(devtools_window);
834 content::WindowedNotificationObserver* close_observer =
835 new content::WindowedNotificationObserver(
836 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
837 content::Source<content::WebContents>(
[email protected]d118ad72014-07-21 14:07:01838 DevToolsWindowTesting::Get(devtools_window)->
839 main_web_contents()));
[email protected]90354712013-11-16 00:06:30840 close_observers.push_back(close_observer);
[email protected]d118ad72014-07-21 14:07:01841 inspected_web_contents =
842 DevToolsWindowTesting::Get(devtools_window)->main_web_contents();
[email protected]90354712013-11-16 00:06:30843 }
844
[email protected]d118ad72014-07-21 14:07:01845 InjectBeforeUnloadListener(
846 DevToolsWindowTesting::Get(windows[0])->main_web_contents());
847 InjectBeforeUnloadListener(
848 DevToolsWindowTesting::Get(windows[2])->main_web_contents());
[email protected]90354712013-11-16 00:06:30849 // Try to close second devtools.
850 {
851 content::WindowedNotificationObserver cancel_browser(
852 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
853 content::NotificationService::AllSources());
[email protected]d118ad72014-07-21 14:07:01854 chrome::CloseWindow(DevToolsWindowTesting::Get(windows[1])->browser());
[email protected]90354712013-11-16 00:06:30855 CancelModalDialog();
856 cancel_browser.Wait();
857 }
858 // Try to close browser window.
859 {
860 content::WindowedNotificationObserver cancel_browser(
861 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
862 content::NotificationService::AllSources());
863 chrome::CloseWindow(browser());
864 AcceptModalDialog();
865 CancelModalDialog();
866 cancel_browser.Wait();
867 }
868 // Try to exit application.
869 {
870 content::WindowedNotificationObserver close_observer(
871 chrome::NOTIFICATION_BROWSER_CLOSED,
872 content::Source<Browser>(browser()));
873 chrome::CloseAllBrowsers();
874 AcceptModalDialog();
875 AcceptModalDialog();
876 close_observer.Wait();
877 }
878 for (size_t i = 0; i < close_observers.size(); ++i) {
879 close_observers[i]->Wait();
880 delete close_observers[i];
881 }
[email protected]a1406cb2013-10-16 14:30:43882}
[email protected]1fcef592011-07-20 07:16:36883
[email protected]3f5866e2009-07-01 07:25:16884// Tests scripts panel showing.
[email protected]2565b872014-08-01 11:57:52885IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestShowScriptsTab) {
[email protected]3f5866e2009-07-01 07:25:16886 RunTest("testShowScriptsTab", kDebuggerTestPage);
[email protected]a2f20232009-06-30 15:06:57887}
888
[email protected]13a6abf82009-10-31 08:42:21889// Tests that scripts tab is populated with inspected scripts even if it
890// hadn't been shown by the moment inspected paged refreshed.
891// @see http://crbug.com/26312
[email protected]a9b82d32012-01-25 19:55:38892IN_PROC_BROWSER_TEST_F(
893 DevToolsSanityTest,
oshima98205bc2015-06-19 19:52:42894 TestScriptsTabIsPopulatedOnInspectedPageRefresh) {
[email protected]13a6abf82009-10-31 08:42:21895 RunTest("testScriptsTabIsPopulatedOnInspectedPageRefresh",
896 kDebuggerTestPage);
897}
898
[email protected]e89c05a2011-12-26 08:51:57899// Tests that chrome.devtools extension is correctly exposed.
[email protected]fb996d32011-12-21 12:55:30900IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
[email protected]e89c05a2011-12-26 08:51:57901 TestDevToolsExtensionAPI) {
[email protected]ec6d5352011-12-19 14:48:34902 LoadExtension("devtools_extension");
[email protected]007b3f82013-04-09 08:46:45903 RunTest("waitForTestResultsInConsole", std::string());
[email protected]ec6d5352011-12-19 14:48:34904}
905
nick32e53c152015-12-17 19:48:54906// Tests a chrome.devtools extension panel that embeds an http:// iframe.
907IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionWithHttpIframe) {
908 ASSERT_TRUE(embedded_test_server()->Start());
909
910 // Our extension must load an URL from the test server, whose port is only
911 // known at runtime. So, to embed the URL, we must dynamically generate the
912 // extension, rather than loading it from static content.
dchengb8eac3a2016-04-13 02:03:23913 std::unique_ptr<extensions::TestExtensionDir> dir(
nick32e53c152015-12-17 19:48:54914 new extensions::TestExtensionDir());
915
916 extensions::DictionaryBuilder manifest;
917 dir->WriteManifest(extensions::DictionaryBuilder()
918 .Set("name", "Devtools Panel w/ HTTP Iframe")
919 .Set("version", "1")
920 .Set("manifest_version", 2)
921 .Set("devtools_page", "devtools.html")
922 .ToJSON());
923
924 dir->WriteFile(
925 FILE_PATH_LITERAL("devtools.html"),
926 "<html><head><script src='devtools.js'></script></head></html>");
927
928 dir->WriteFile(
929 FILE_PATH_LITERAL("devtools.js"),
930 "chrome.devtools.panels.create('iframe_panel',\n"
931 " null,\n"
932 " 'panel.html',\n"
933 " function(panel) {\n"
934 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n"
935 " }\n"
936 ");\n");
937
938 GURL http_iframe =
939 embedded_test_server()->GetURL("a.com", "/popup_iframe.html");
940 dir->WriteFile(FILE_PATH_LITERAL("panel.html"),
941 "<html><body>Extension panel.<iframe src='" +
942 http_iframe.spec() + "'></iframe>");
943
944 // Install the extension.
vabr9142fe22016-09-08 13:19:22945 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath());
nick32e53c152015-12-17 19:48:54946 ASSERT_TRUE(extension);
947
948 // Open a devtools window.
949 OpenDevToolsWindow(kDebuggerTestPage, false);
950
951 // Wait for the panel extension to finish loading -- it'll output 'PASS'
952 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'.
953 RunTestFunction(window_, "waitForTestResultsInConsole");
954
955 // Now that we know the panel is loaded, switch to it. We'll wait until we
956 // see a 'DONE' message sent from popup_iframe.html, indicating that it
957 // loaded successfully.
958 content::DOMMessageQueue message_queue;
959 SwitchToExtensionPanel(window_, extension, "iframe_panel");
960 std::string message;
961 while (true) {
962 ASSERT_TRUE(message_queue.WaitForMessage(&message));
963 if (message == "\"DONE\"")
964 break;
965 }
966}
967
[email protected]43466b92013-12-27 22:00:11968// Disabled on Windows due to flakiness. http://crbug.com/183649
969#if defined(OS_WIN)
[email protected]4319aa302013-06-12 19:59:45970#define MAYBE_TestDevToolsExtensionMessaging DISABLED_TestDevToolsExtensionMessaging
971#else
972#define MAYBE_TestDevToolsExtensionMessaging TestDevToolsExtensionMessaging
973#endif
974
[email protected]6dcc9432012-02-28 12:59:37975// Tests that chrome.devtools extension can communicate with background page
976// using extension messaging.
977IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
[email protected]4319aa302013-06-12 19:59:45978 MAYBE_TestDevToolsExtensionMessaging) {
[email protected]6dcc9432012-02-28 12:59:37979 LoadExtension("devtools_messaging");
[email protected]007b3f82013-04-09 08:46:45980 RunTest("waitForTestResultsInConsole", std::string());
[email protected]6dcc9432012-02-28 12:59:37981}
982
[email protected]e89c05a2011-12-26 08:51:57983// Tests that chrome.experimental.devtools extension is correctly exposed
984// when the extension has experimental permission.
985IN_PROC_BROWSER_TEST_F(DevToolsExperimentalExtensionTest,
986 TestDevToolsExperimentalExtensionAPI) {
987 LoadExtension("devtools_experimental");
[email protected]007b3f82013-04-09 08:46:45988 RunTest("waitForTestResultsInConsole", std::string());
[email protected]e89c05a2011-12-26 08:51:57989}
990
[email protected]92094f312013-11-12 18:09:26991// Tests that a content script is in the scripts list.
[email protected]92094f312013-11-12 18:09:26992IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
[email protected]2565b872014-08-01 11:57:52993 TestContentScriptIsPresent) {
[email protected]2c7b4d72009-10-21 07:17:17994 LoadExtension("simple_content_script");
995 RunTest("testContentScriptIsPresent", kPageWithContentScript);
996}
997
lushnikov6d007922016-08-31 02:59:44998// Tests that console selector shows correct context names.
999IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
1000 TestConsoleContextNames) {
1001 LoadExtension("simple_content_script");
1002 RunTest("testConsoleContextNames", kPageWithContentScript);
1003}
1004
[email protected]f099ba32009-09-18 13:43:171005// Tests that scripts are not duplicated after Scripts Panel switch.
1006IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
[email protected]2565b872014-08-01 11:57:521007 TestNoScriptDuplicatesOnPanelSwitch) {
[email protected]f099ba32009-09-18 13:43:171008 RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage);
1009}
1010
[email protected]53976e82009-11-11 17:08:311011// Tests that debugger works correctly if pause event occurs when DevTools
1012// frontend is being loaded.
[email protected]e043c2a2011-12-02 00:08:171013IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
mukai9f72da922015-03-14 01:54:541014 TestPauseWhenLoadingDevTools) {
[email protected]53976e82009-11-11 17:08:311015 RunTest("testPauseWhenLoadingDevTools", kPauseWhenLoadingDevTools);
1016}
1017
[email protected]28ce8eb2009-11-30 09:20:451018// Tests that pressing 'Pause' will pause script execution if the script
1019// is already running.
sergeyvb4eb2472015-03-17 10:51:131020#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
[email protected]5808fe12013-05-10 02:42:451021// Timing out on linux ARM bot: https://crbug/238453
1022#define MAYBE_TestPauseWhenScriptIsRunning DISABLED_TestPauseWhenScriptIsRunning
sergeyvb4eb2472015-03-17 10:51:131023#else
1024#define MAYBE_TestPauseWhenScriptIsRunning TestPauseWhenScriptIsRunning
1025#endif
[email protected]81284382013-10-21 23:08:541026IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
sergeyvb4eb2472015-03-17 10:51:131027 MAYBE_TestPauseWhenScriptIsRunning) {
[email protected]6303b282012-02-14 00:55:371028 RunTest("testPauseWhenScriptIsRunning", kPauseWhenScriptIsRunning);
[email protected]28ce8eb2009-11-30 09:20:451029}
1030
[email protected]74568b052011-05-20 09:36:141031// Tests network timing.
[email protected]5c80747a12011-08-26 01:35:571032IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkTiming) {
[email protected]74568b052011-05-20 09:36:141033 RunTest("testNetworkTiming", kSlowTestPage);
1034}
1035
1036// Tests network size.
oshima98205bc2015-06-19 19:52:421037IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSize) {
[email protected]74568b052011-05-20 09:36:141038 RunTest("testNetworkSize", kChunkedTestPage);
1039}
1040
1041// Tests raw headers text.
[email protected]689a4802012-10-12 15:12:221042IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSyncSize) {
[email protected]74568b052011-05-20 09:36:141043 RunTest("testNetworkSyncSize", kChunkedTestPage);
1044}
1045
1046// Tests raw headers text.
oshima98205bc2015-06-19 19:52:421047IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkRawHeadersText) {
[email protected]74568b052011-05-20 09:36:141048 RunTest("testNetworkRawHeadersText", kChunkedTestPage);
1049}
1050
caseqe8340bc92016-04-20 00:02:571051IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkPushTime) {
1052 OpenDevToolsWindow(kPushTestPage, false);
1053 GURL push_url = spawned_test_server()->GetURL(kPushTestResource);
1054 base::FilePath file_path =
1055 spawned_test_server()->document_root().AppendASCII(kPushTestResource);
1056
1057 BrowserThread::PostTask(
1058 BrowserThread::IO, FROM_HERE,
1059 base::Bind(&TestInterceptor::Register, push_url, file_path));
1060
1061 DispatchOnTestSuite(window_, "testPushTimes", push_url.spec().c_str());
1062
1063 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1064 base::Bind(&TestInterceptor::Unregister, push_url));
1065
1066 CloseDevToolsWindow();
1067}
1068
[email protected]e344c392011-09-28 06:36:031069// Tests that console messages are not duplicated on navigation back.
oshima98205bc2015-06-19 19:52:421070#if defined(OS_WIN)
tim3c2889b2014-08-30 01:49:571071// Flaking on windows swarm try runs: crbug.com/409285.
1072#define MAYBE_TestConsoleOnNavigateBack DISABLED_TestConsoleOnNavigateBack
1073#else
1074#define MAYBE_TestConsoleOnNavigateBack TestConsoleOnNavigateBack
1075#endif
1076IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, MAYBE_TestConsoleOnNavigateBack) {
[email protected]e344c392011-09-28 06:36:031077 RunTest("testConsoleOnNavigateBack", kNavigateBackTestPage);
1078}
1079
dgozman8388f062015-09-04 19:03:511080IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDeviceEmulation) {
[email protected]05401dc2014-05-13 20:08:421081 RunTest("testDeviceMetricsOverrides", "about:blank");
1082}
1083
dgozman204daf32016-07-13 03:51:011084IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDispatchKeyEventDoesNotCrash) {
1085 RunTest("testDispatchKeyEventDoesNotCrash", "about:blank");
1086}
1087
dgozman0fced85f42015-06-10 15:06:031088// Tests that settings are stored in profile correctly.
1089IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestSettings) {
1090 OpenDevToolsWindow("about:blank", true);
1091 RunTestFunction(window_, "testSettings");
1092 CloseDevToolsWindow();
1093}
1094
[email protected]0a57375a2013-03-07 22:18:591095// Tests that external navigation from inspector page is always handled by
1096// DevToolsWindow and results in inspected page navigation.
1097IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsExternalNavigation) {
[email protected]b9c5d50b2014-01-16 20:37:431098 OpenDevToolsWindow(kDebuggerTestPage, true);
svaldeza01f7d92015-11-18 17:47:561099 GURL url = spawned_test_server()->GetURL(kNavigateBackTestPage);
[email protected]d118ad72014-07-21 14:07:011100 ui_test_utils::UrlLoadObserver observer(url,
[email protected]0a57375a2013-03-07 22:18:591101 content::NotificationService::AllSources());
1102 ASSERT_TRUE(content::ExecuteScript(
[email protected]d118ad72014-07-21 14:07:011103 main_web_contents(),
[email protected]0a57375a2013-03-07 22:18:591104 std::string("window.location = \"") + url.spec() + "\""));
1105 observer.Wait();
1106
[email protected]d118ad72014-07-21 14:07:011107 ASSERT_TRUE(main_web_contents()->GetURL().
[email protected]b3690f72014-02-17 00:32:481108 SchemeIs(content::kChromeDevToolsScheme));
[email protected]9fc94c6d2014-02-12 14:48:481109 ASSERT_EQ(url, GetInspectedTab()->GetURL());
[email protected]a1406cb2013-10-16 14:30:431110 CloseDevToolsWindow();
[email protected]0a57375a2013-03-07 22:18:591111}
1112
[email protected]d118ad72014-07-21 14:07:011113// Tests that toolbox window is loaded when DevTools window is undocked.
1114IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxLoadedUndocked) {
1115 OpenDevToolsWindow(kDebuggerTestPage, false);
1116 ASSERT_TRUE(toolbox_web_contents());
[email protected]b3f957e62014-08-08 10:09:021117 DevToolsWindow* on_self =
1118 DevToolsWindowTesting::OpenDevToolsWindowSync(main_web_contents(), false);
[email protected]d118ad72014-07-21 14:07:011119 ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents());
1120 DevToolsWindowTesting::CloseDevToolsWindowSync(on_self);
1121 CloseDevToolsWindow();
1122}
1123
1124// Tests that toolbox window is not loaded when DevTools window is docked.
1125IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxNotLoadedDocked) {
1126 OpenDevToolsWindow(kDebuggerTestPage, true);
1127 ASSERT_FALSE(toolbox_web_contents());
[email protected]b3f957e62014-08-08 10:09:021128 DevToolsWindow* on_self =
1129 DevToolsWindowTesting::OpenDevToolsWindowSync(main_web_contents(), false);
[email protected]d118ad72014-07-21 14:07:011130 ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents());
1131 DevToolsWindowTesting::CloseDevToolsWindowSync(on_self);
1132 CloseDevToolsWindow();
1133}
1134
[email protected]a88511b2011-11-09 06:53:071135// Tests that inspector will reattach to inspected page when it is reloaded
1136// after a crash. See http://crbug.com/101952
sergeyv27f196c2015-02-25 14:25:151137// Disabled. it doesn't check anything right now: http://crbug.com/461790
1138IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_TestReattachAfterCrash) {
[email protected]ebb10bb2014-04-16 17:16:011139 RunTest("testReattachAfterCrash", std::string());
[email protected]a88511b2011-11-09 06:53:071140}
1141
[email protected]3766a362011-06-21 17:56:181142IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) {
[email protected]b9c5d50b2014-01-16 20:37:431143 OpenDevToolsWindow("about:blank", false);
[email protected]3766a362011-06-21 17:56:181144 std::string result;
1145 ASSERT_TRUE(
[email protected]b6987e02013-01-04 18:30:431146 content::ExecuteScriptAndExtractString(
[email protected]d118ad72014-07-21 14:07:011147 main_web_contents()->GetRenderViewHost(),
[email protected]06bc5d92013-01-02 22:44:131148 "window.domAutomationController.send("
caseqc1edde1a2015-09-29 00:17:071149 " '' + (window.uiTests && (typeof uiTests.dispatchOnTestSuite)));",
[email protected]3766a362011-06-21 17:56:181150 &result));
1151 ASSERT_EQ("function", result) << "DevTools front-end is broken.";
1152 CloseDevToolsWindow();
1153}
1154
dgozman54cc54e2016-02-23 03:47:301155class DevToolsAutoOpenerTest : public DevToolsSanityTest {
1156 public:
1157 void SetUpCommandLine(base::CommandLine* command_line) override {
1158 command_line->AppendSwitch(switches::kAutoOpenDevToolsForTabs);
dgozman010f9e0e2016-02-24 21:25:531159 observer_.reset(new DevToolsWindowCreationObserver());
dgozman54cc54e2016-02-23 03:47:301160 }
dgozman010f9e0e2016-02-24 21:25:531161 protected:
dchengb8eac3a2016-04-13 02:03:231162 std::unique_ptr<DevToolsWindowCreationObserver> observer_;
dgozman54cc54e2016-02-23 03:47:301163};
1164
1165IN_PROC_BROWSER_TEST_F(DevToolsAutoOpenerTest, TestAutoOpenForTabs) {
1166 {
dgozman54cc54e2016-02-23 03:47:301167 DevToolsWindowCreationObserver observer;
1168 AddTabAtIndexToBrowser(browser(), 0, GURL("about:blank"),
1169 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false);
1170 observer.WaitForLoad();
dgozman010f9e0e2016-02-24 21:25:531171 }
1172 Browser* new_browser = nullptr;
1173 {
1174 DevToolsWindowCreationObserver observer;
1175 new_browser = CreateBrowser(browser()->profile());
1176 observer.WaitForLoad();
dgozman54cc54e2016-02-23 03:47:301177 }
1178 {
1179 DevToolsWindowCreationObserver observer;
dgozman54cc54e2016-02-23 03:47:301180 AddTabAtIndexToBrowser(new_browser, 0, GURL("about:blank"),
1181 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false);
1182 observer.WaitForLoad();
dgozman54cc54e2016-02-23 03:47:301183 }
dgozman010f9e0e2016-02-24 21:25:531184 observer_->CloseAllSync();
dgozman54cc54e2016-02-23 03:47:301185}
1186
caseqc1edde1a2015-09-29 00:17:071187class DevToolsReattachAfterCrashTest : public DevToolsSanityTest {
1188 protected:
1189 void RunTestWithPanel(const char* panel_name) {
1190 OpenDevToolsWindow("about:blank", false);
1191 SwitchToPanel(window_, panel_name);
1192 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
1193
1194 content::RenderProcessHostWatcher crash_observer(
1195 GetInspectedTab(),
1196 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
1197 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL));
1198 crash_observer.Wait();
1199 content::TestNavigationObserver navigation_observer(GetInspectedTab(), 1);
nick3b04f322016-08-31 19:29:191200 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
caseqc1edde1a2015-09-29 00:17:071201 navigation_observer.Wait();
1202 }
1203};
1204
1205IN_PROC_BROWSER_TEST_F(DevToolsReattachAfterCrashTest,
1206 TestReattachAfterCrashOnTimeline) {
1207 RunTestWithPanel("timeline");
1208}
1209
1210IN_PROC_BROWSER_TEST_F(DevToolsReattachAfterCrashTest,
1211 TestReattachAfterCrashOnNetwork) {
1212 RunTestWithPanel("network");
1213}
1214
dgozmanab680412016-02-04 02:21:371215IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, AutoAttachToWindowOpen) {
1216 OpenDevToolsWindow(kWindowOpenTestPage, false);
1217 DispatchOnTestSuite(window_, "enableAutoAttachToCreatedPages");
1218 DevToolsWindowCreationObserver observer;
1219 ASSERT_TRUE(content::ExecuteScript(
1220 GetInspectedTab(), "window.open('window_open.html', '_blank');"));
1221 observer.WaitForLoad();
1222 DispatchOnTestSuite(observer.devtools_window(), "waitForDebuggerPaused");
1223 DevToolsWindowTesting::CloseDevToolsWindowSync(observer.devtools_window());
1224 CloseDevToolsWindow();
1225}
1226
sergeyvb4eb2472015-03-17 10:51:131227IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, InspectSharedWorker) {
yurys48be075f2014-10-16 09:04:211228 RunTest("testSharedWorker", kSharedWorkerTestPage, kSharedWorkerTestWorker);
[email protected]1fcef592011-07-20 07:16:361229}
1230
[email protected]867fd9232011-10-17 06:32:341231IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest,
sergeyvdf73f162016-01-12 17:37:091232 PauseInSharedWorkerInitialization) {
svaldeza01f7d92015-11-18 17:47:561233 ASSERT_TRUE(spawned_test_server()->Start());
1234 GURL url = spawned_test_server()->GetURL(kReloadSharedWorkerTestPage);
[email protected]9e1ee54c2012-03-12 17:47:131235 ui_test_utils::NavigateToURL(browser(), url);
[email protected]867fd9232011-10-17 06:32:341236
yurys48be075f2014-10-16 09:04:211237 scoped_refptr<WorkerData> worker_data =
1238 WaitForFirstSharedWorker(kReloadSharedWorkerTestWorker);
[email protected]9e1ee54c2012-03-12 17:47:131239 OpenDevToolsWindowForSharedWorker(worker_data.get());
[email protected]867fd9232011-10-17 06:32:341240
vsevika9852412014-10-29 14:20:501241 // We should make sure that the worker inspector has loaded before
1242 // terminating worker.
1243 RunTestFunction(window_, "testPauseInSharedWorkerInitialization1");
1244
[email protected]9e1ee54c2012-03-12 17:47:131245 TerminateWorker(worker_data);
[email protected]867fd9232011-10-17 06:32:341246
[email protected]9e1ee54c2012-03-12 17:47:131247 // Reload page to restart the worker.
1248 ui_test_utils::NavigateToURL(browser(), url);
[email protected]867fd9232011-10-17 06:32:341249
[email protected]9e1ee54c2012-03-12 17:47:131250 // Wait until worker script is paused on the debugger statement.
vsevika9852412014-10-29 14:20:501251 RunTestFunction(window_, "testPauseInSharedWorkerInitialization2");
[email protected]9e1ee54c2012-03-12 17:47:131252 CloseDevToolsWindow();
1253}
1254
[email protected]a2dcc6732013-03-14 13:28:081255class DevToolsAgentHostTest : public InProcessBrowserTest {};
1256
1257// Tests DevToolsAgentHost retention by its target.
1258IN_PROC_BROWSER_TEST_F(DevToolsAgentHostTest, TestAgentHostReleased) {
1259 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]b3f957e62014-08-08 10:09:021260 WebContents* web_contents = browser()->tab_strip_model()->GetWebContentsAt(0);
1261 DevToolsAgentHost* agent_raw =
1262 DevToolsAgentHost::GetOrCreateFor(web_contents).get();
[email protected]a2dcc6732013-03-14 13:28:081263 const std::string agent_id = agent_raw->GetId();
dchengf4b56572014-08-27 06:59:371264 ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id).get())
1265 << "DevToolsAgentHost cannot be found by id";
[email protected]a2dcc6732013-03-14 13:28:081266 browser()->tab_strip_model()->
1267 CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
[email protected]cadac622013-06-11 16:46:361268 ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get())
1269 << "DevToolsAgentHost is not released when the tab is closed";
[email protected]a2dcc6732013-03-14 13:28:081270}
1271
vkuzkokov00700c32015-03-17 16:04:071272class RemoteDebuggingTest : public ExtensionApiTest {
avi3ef9ec9e2014-12-22 22:50:171273 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]965901382013-04-03 07:38:391274 ExtensionApiTest::SetUpCommandLine(command_line);
1275 command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222");
[email protected]ead056352013-03-12 08:47:541276
[email protected]965901382013-04-03 07:38:391277 // Override the extension root path.
1278 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
1279 test_data_dir_ = test_data_dir_.AppendASCII("devtools");
[email protected]ead056352013-03-12 08:47:541280 }
1281};
1282
Nicolas Zea4c8a23e2014-11-07 20:50:161283// Fails on CrOS. crbug.com/431399
1284#if defined(OS_CHROMEOS)
1285#define MAYBE_RemoteDebugger DISABLED_RemoteDebugger
1286#else
1287#define MAYBE_RemoteDebugger RemoteDebugger
1288#endif
1289IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, MAYBE_RemoteDebugger) {
[email protected]965901382013-04-03 07:38:391290 ASSERT_TRUE(RunExtensionTest("target_list")) << message_;
[email protected]ead056352013-03-12 08:47:541291}
peletskyi5ec60bf2015-03-12 09:53:181292
1293using DevToolsPolicyTest = InProcessBrowserTest;
1294IN_PROC_BROWSER_TEST_F(DevToolsPolicyTest, PolicyTrue) {
1295 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDevToolsDisabled, true);
1296 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
1297 content::WebContents* web_contents =
1298 browser()->tab_strip_model()->GetWebContentsAt(0);
1299 scoped_refptr<content::DevToolsAgentHost> agent(
1300 content::DevToolsAgentHost::GetOrCreateFor(web_contents));
1301 DevToolsWindow::OpenDevToolsWindow(web_contents);
1302 DevToolsWindow* window = DevToolsWindow::FindDevToolsWindow(agent.get());
1303 ASSERT_FALSE(window);
1304}
caseqc5e166832015-07-10 07:40:471305
1306class DevToolsPixelOutputTests : public DevToolsSanityTest {
1307 public:
1308 void SetUpCommandLine(base::CommandLine* command_line) override {
1309 command_line->AppendSwitch(switches::kEnablePixelOutputInTests);
1310 command_line->AppendSwitch(switches::kUseGpuInTests);
1311 }
1312};
1313
eugenis2580a3352015-07-10 22:04:541314// This test enables switches::kUseGpuInTests which causes false positives
ccameron606eb382016-09-06 18:57:541315// with MemorySanitizer. This is also flakey on many configurations.
robertshield954f48e2016-01-14 18:09:161316#if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || \
ccameron606eb382016-09-06 18:57:541317 defined(OS_WIN)|| (defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD))
eugenis2580a3352015-07-10 22:04:541318#define MAYBE_TestScreenshotRecording DISABLED_TestScreenshotRecording
1319#else
1320#define MAYBE_TestScreenshotRecording TestScreenshotRecording
1321#endif
eugenis2580a3352015-07-10 22:04:541322IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests,
1323 MAYBE_TestScreenshotRecording) {
caseqc5e166832015-07-10 07:40:471324 RunTest("testScreenshotRecording", std::string());
1325}
caseqcfbb3faf2016-02-18 19:15:061326
1327// This test enables switches::kUseGpuInTests which causes false positives
1328// with MemorySanitizer.
petewil07b58cc02016-06-29 23:14:081329#if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || defined(OS_WIN)
caseqcfbb3faf2016-02-18 19:15:061330#define MAYBE_TestLatencyInfoInstrumentation \
1331 DISABLED_TestLatencyInfoInstrumentation
1332#else
1333#define MAYBE_TestLatencyInfoInstrumentation TestLatencyInfoInstrumentation
1334#endif
1335IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests,
1336 MAYBE_TestLatencyInfoInstrumentation) {
1337 WebContents* web_contents = GetInspectedTab();
1338 OpenDevToolsWindow(kLatencyInfoTestPage, false);
caseqcfbb3faf2016-02-18 19:15:061339 DispatchAndWait("startTimeline");
1340
1341 for (int i = 0; i < 3; ++i) {
1342 SimulateMouseEvent(web_contents, blink::WebInputEvent::MouseMove,
1343 gfx::Point(30, 60));
1344 DispatchInPageAndWait("waitForEvent", "mousemove");
1345 }
1346
nzolghadr656569e2016-08-19 16:53:001347 SimulateMouseClickAt(web_contents, 0,
1348 blink::WebPointerProperties::Button::Left,
caseqcfbb3faf2016-02-18 19:15:061349 gfx::Point(30, 60));
1350 DispatchInPageAndWait("waitForEvent", "click");
1351
1352 SimulateMouseWheelEvent(web_contents, gfx::Point(300, 100),
1353 gfx::Vector2d(0, 120));
1354 DispatchInPageAndWait("waitForEvent", "wheel");
1355
1356 SimulateTapAt(web_contents, gfx::Point(30, 60));
1357 DispatchInPageAndWait("waitForEvent", "gesturetap");
1358
1359 DispatchAndWait("stopTimeline");
1360 RunTestMethod("checkInputEventsPresent", "MouseMove", "MouseDown",
1361 "MouseWheel", "GestureTap");
1362
1363 CloseDevToolsWindow();
1364}
dgozman6ca18e32016-06-29 19:30:291365
1366class DevToolsNetInfoTest : public DevToolsSanityTest {
1367 protected:
1368 void SetUpCommandLine(base::CommandLine* command_line) override {
1369 command_line->AppendSwitch(switches::kEnableNetworkInformation);
1370 command_line->AppendSwitch(
1371 switches::kEnableExperimentalWebPlatformFeatures);
1372 }
1373};
1374
1375IN_PROC_BROWSER_TEST_F(DevToolsNetInfoTest, EmulateNetworkConditions) {
1376 RunTest("testEmulateNetworkConditions", kEmulateNetworkConditionsPage);
1377}
kozyatinskiy3ac94392016-07-14 00:07:471378
1379class StaticURLDataSource : public content::URLDataSource {
1380 public:
1381 StaticURLDataSource(const std::string& source, const std::string& content)
1382 : source_(source), content_(content) {}
1383
1384 std::string GetSource() const override { return source_; }
jamedcd8b012016-09-20 02:03:581385 void StartDataRequest(
1386 const std::string& path,
1387 const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
1388 const GotDataCallback& callback) override {
kozyatinskiy3ac94392016-07-14 00:07:471389 std::string data(content_);
1390 callback.Run(base::RefCountedString::TakeString(&data));
1391 }
1392 std::string GetMimeType(const std::string& path) const override {
1393 return "text/html";
1394 }
1395 bool ShouldAddContentSecurityPolicy() const override { return false; }
1396
1397 private:
1398 std::string source_;
1399 std::string content_;
1400 DISALLOW_COPY_AND_ASSIGN(StaticURLDataSource);
1401};
1402
1403class MockWebUIProvider
1404 : public TestChromeWebUIControllerFactory::WebUIProvider {
1405 public:
1406 MockWebUIProvider(const std::string& source, const std::string& content)
1407 : source_(source), content_(content) {}
1408
1409 content::WebUIController* NewWebUI(content::WebUI* web_ui,
1410 const GURL& url) override {
1411 content::URLDataSource::Add(Profile::FromWebUI(web_ui),
1412 new StaticURLDataSource(source_, content_));
1413 return new content::WebUIController(web_ui);
1414 }
1415
1416 private:
1417 std::string source_;
1418 std::string content_;
1419 DISALLOW_COPY_AND_ASSIGN(MockWebUIProvider);
1420};
1421
1422// This tests checks that window is correctly initialized when DevTools is
1423// opened while navigation through history with forward and back actions.
1424// (crbug.com/627407)
vabr4d9b40392016-07-26 15:56:181425// Flaky on Windows. http://crbug.com/628174#c4
1426#if defined(OS_WIN)
1427#define MAYBE_TestWindowInitializedOnNavigateBack \
1428 DISABLED_TestWindowInitializedOnNavigateBack
1429#else
1430#define MAYBE_TestWindowInitializedOnNavigateBack \
1431 TestWindowInitializedOnNavigateBack
1432#endif
kozyatinskiy3ac94392016-07-14 00:07:471433IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
vabr4d9b40392016-07-26 15:56:181434 MAYBE_TestWindowInitializedOnNavigateBack) {
kozyatinskiy3ac94392016-07-14 00:07:471435 TestChromeWebUIControllerFactory test_factory;
1436 MockWebUIProvider mock_provider("dummyurl",
1437 "<script>\n"
1438 " window.abc = 239;\n"
1439 " console.log(abc);\n"
1440 "</script>");
1441 test_factory.AddFactoryOverride(GURL("chrome://dummyurl").host(),
1442 &mock_provider);
1443 content::WebUIControllerFactory::RegisterFactory(&test_factory);
1444
1445 ui_test_utils::NavigateToURL(browser(), GURL("chrome://dummyurl"));
1446 DevToolsWindow* window =
1447 DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), true);
1448 chrome::DuplicateTab(browser());
1449 chrome::SelectPreviousTab(browser());
1450 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
nick3b04f322016-08-31 19:29:191451 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB);
kozyatinskiy3ac94392016-07-14 00:07:471452 RunTestFunction(window, "testWindowInitializedOnNavigateBack");
1453
1454 DevToolsWindowTesting::CloseDevToolsWindowSync(window);
1455 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory);
1456}