[email protected] | 98cd1512 | 2012-01-05 16:27:48 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | |
dcheng | 18ec0b54 | 2016-04-26 19:28:53 | [diff] [blame] | 7 | #include <memory> |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 8 | #include <vector> |
dcheng | 18ec0b54 | 2016-04-26 19:28:53 | [diff] [blame] | 9 | |
[email protected] | 900c3b2 | 2011-10-22 00:55:29 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 11 | #include "base/cancelable_callback.h" |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
skyostil | 0259835 | 2015-06-12 12:37:25 | [diff] [blame] | 15 | #include "base/location.h" |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 16 | #include "base/macros.h" |
dcheng | 18ec0b54 | 2016-04-26 19:28:53 | [diff] [blame] | 17 | #include "base/memory/ptr_util.h" |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 18 | #include "base/memory/ref_counted.h" |
gab | f64a25e | 2017-05-12 19:42:56 | [diff] [blame] | 19 | #include "base/message_loop/message_loop.h" |
Tarun Bansal | 65a2abd | 2018-01-22 23:20:19 | [diff] [blame] | 20 | #include "base/optional.h" |
[email protected] | 3985ba8 | 2010-07-29 21:44:12 | [diff] [blame] | 21 | #include "base/path_service.h" |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 22 | #include "base/run_loop.h" |
skyostil | 0259835 | 2015-06-12 12:37:25 | [diff] [blame] | 23 | #include "base/single_thread_task_runner.h" |
vkuzkokov | 00700c3 | 2015-03-17 16:04:07 | [diff] [blame] | 24 | #include "base/strings/string_number_conversions.h" |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 25 | #include "base/strings/string_util.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 26 | #include "base/strings/utf_string_conversions.h" |
[email protected] | c711fe71 | 2011-07-25 12:43:30 | [diff] [blame] | 27 | #include "base/test/test_timeouts.h" |
jam | 3f2d393 | 2017-04-26 20:28:51 | [diff] [blame] | 28 | #include "base/threading/thread_restrictions.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 29 | #include "base/threading/thread_task_runner_handle.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 30 | #include "build/build_config.h" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 31 | #include "chrome/browser/chrome_notification_types.h" |
yurys | 4e413a1 | 2015-07-07 10:14:52 | [diff] [blame] | 32 | #include "chrome/browser/devtools/device/tcp_device_provider.h" |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 33 | #include "chrome/browser/devtools/devtools_window_testing.h" |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 34 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 35 | #include "chrome/browser/extensions/extension_browsertest.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 36 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 37 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 38 | #include "chrome/browser/lifetime/application_lifetime.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 39 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 7b5dc00 | 2010-11-16 23:08:10 | [diff] [blame] | 40 | #include "chrome/browser/ui/browser.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 41 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 0d56fa721 | 2012-11-15 23:34:02 | [diff] [blame] | 42 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 43 | #include "chrome/common/chrome_paths.h" |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 44 | #include "chrome/common/chrome_switches.h" |
peletskyi | 5ec60bf | 2015-03-12 09:53:18 | [diff] [blame] | 45 | #include "chrome/common/pref_names.h" |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 46 | #include "chrome/common/url_constants.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 47 | #include "chrome/test/base/in_process_browser_test.h" |
kozyatinskiy | 3ac9439 | 2016-07-14 00:07:47 | [diff] [blame] | 48 | #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 49 | #include "chrome/test/base/ui_test_utils.h" |
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 50 | #include "components/app_modal/javascript_app_modal_dialog.h" |
| 51 | #include "components/app_modal/native_app_modal_dialog.h" |
Blaise | bcad00c | 2017-07-25 00:19:49 | [diff] [blame] | 52 | #include "components/autofill/content/browser/content_autofill_driver.h" |
| 53 | #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
| 54 | #include "components/autofill/core/browser/autofill_manager.h" |
| 55 | #include "components/autofill/core/browser/autofill_manager_test_delegate.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 56 | #include "components/prefs/pref_service.h" |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 57 | #include "content/public/browser/child_process_data.h" |
[email protected] | b0b67cfe | 2012-01-18 21:59:57 | [diff] [blame] | 58 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 59 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 60 | #include "content/public/browser/notification_registrar.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 61 | #include "content/public/browser/notification_service.h" |
avi | 64b8b65b | 2017-03-29 18:50:34 | [diff] [blame] | 62 | #include "content/public/browser/render_frame_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 63 | #include "content/public/browser/render_view_host.h" |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 64 | #include "content/public/browser/render_widget_host.h" |
| 65 | #include "content/public/browser/render_widget_host_view.h" |
kozyatinskiy | 3ac9439 | 2016-07-14 00:07:47 | [diff] [blame] | 66 | #include "content/public/browser/url_data_source.h" |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 67 | #include "content/public/browser/web_contents.h" |
kozyatinskiy | 3ac9439 | 2016-07-14 00:07:47 | [diff] [blame] | 68 | #include "content/public/browser/web_ui_controller.h" |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 69 | #include "content/public/common/content_switches.h" |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 70 | #include "content/public/common/url_constants.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 71 | #include "content/public/test/browser_test_utils.h" |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 72 | #include "content/public/test/test_navigation_observer.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 73 | #include "extensions/browser/extension_registry.h" |
limasdf | f3a0c5ef | 2017-02-28 01:30:38 | [diff] [blame] | 74 | #include "extensions/browser/extension_registry_observer.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 75 | #include "extensions/browser/extension_system.h" |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 76 | #include "extensions/browser/notification_types.h" |
limasdf | f3a0c5ef | 2017-02-28 01:30:38 | [diff] [blame] | 77 | #include "extensions/browser/test_extension_registry_observer.h" |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 78 | #include "extensions/common/switches.h" |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 79 | #include "extensions/common/value_builder.h" |
Devlin Cronin | 4f455a2 | 2018-01-25 01:36:45 | [diff] [blame] | 80 | #include "extensions/test/test_extension_dir.h" |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 81 | #include "net/dns/mock_host_resolver.h" |
[email protected] | 89b3252 | 2013-05-07 20:04:21 | [diff] [blame] | 82 | #include "net/test/spawned_test_server/spawned_test_server.h" |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 83 | #include "net/test/url_request/url_request_mock_http_job.h" |
| 84 | #include "net/url_request/url_request_context.h" |
Andrey Kosyakov | 2e893e6 | 2017-08-31 17:00:52 | [diff] [blame] | 85 | #include "net/url_request/url_request_context_getter.h" |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 86 | #include "net/url_request/url_request_filter.h" |
| 87 | #include "net/url_request/url_request_http_job.h" |
dtapuska | 836e1f9 | 2016-11-15 00:38:06 | [diff] [blame] | 88 | #include "third_party/WebKit/public/platform/WebInputEvent.h" |
caseq | c5e16683 | 2015-07-10 07:40:47 | [diff] [blame] | 89 | #include "ui/compositor/compositor_switches.h" |
| 90 | #include "ui/gl/gl_switches.h" |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 91 | #include "url/gurl.h" |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 92 | |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 93 | using app_modal::JavaScriptAppModalDialog; |
| 94 | using app_modal::NativeAppModalDialog; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 95 | using content::BrowserThread; |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 96 | using content::DevToolsAgentHost; |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 97 | using content::DevToolsAgentHostObserver; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 98 | using content::NavigationController; |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 99 | using content::RenderFrameHost; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 100 | using content::RenderViewHost; |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 101 | using content::WebContents; |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 102 | using extensions::Extension; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 103 | |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 104 | namespace { |
| 105 | |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 106 | const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html"; |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 107 | const char kPauseWhenLoadingDevTools[] = |
| 108 | "files/devtools/pause_when_loading_devtools.html"; |
| 109 | const char kPauseWhenScriptIsRunning[] = |
| 110 | "files/devtools/pause_when_script_is_running.html"; |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 111 | const char kPageWithContentScript[] = |
| 112 | "files/devtools/page_with_content_script.html"; |
[email protected] | e344c39 | 2011-09-28 06:36:03 | [diff] [blame] | 113 | const char kNavigateBackTestPage[] = |
| 114 | "files/devtools/navigate_back.html"; |
dgozman | ab68041 | 2016-02-04 02:21:37 | [diff] [blame] | 115 | const char kWindowOpenTestPage[] = "files/devtools/window_open.html"; |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 116 | const char kLatencyInfoTestPage[] = "files/devtools/latency_info.html"; |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 117 | const char kChunkedTestPage[] = "chunked"; |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 118 | const char kPushTestPage[] = "files/devtools/push_test_page.html"; |
| 119 | // The resource is not really pushed, but mock url request job pretends it is. |
| 120 | const char kPushTestResource[] = "devtools/image.png"; |
| 121 | const char kPushUseNullEndTime[] = "pushUseNullEndTime"; |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 122 | const char kSlowTestPage[] = |
| 123 | "chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2"; |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 124 | const char kSharedWorkerTestPage[] = |
| 125 | "files/workers/workers_ui_shared_worker.html"; |
yurys | 48be075f | 2014-10-16 09:04:21 | [diff] [blame] | 126 | const char kSharedWorkerTestWorker[] = |
| 127 | "files/workers/workers_ui_shared_worker.js"; |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 128 | const char kReloadSharedWorkerTestPage[] = |
| 129 | "files/workers/debug_shared_worker_initialization.html"; |
yurys | 48be075f | 2014-10-16 09:04:21 | [diff] [blame] | 130 | const char kReloadSharedWorkerTestWorker[] = |
| 131 | "files/workers/debug_shared_worker_initialization.js"; |
dgozman | 6ca18e3 | 2016-06-29 19:30:29 | [diff] [blame] | 132 | const char kEmulateNetworkConditionsPage[] = |
| 133 | "files/devtools/emulate_network_conditions.html"; |
Blaise | bcad00c | 2017-07-25 00:19:49 | [diff] [blame] | 134 | const char kDispatchKeyEventShowsAutoFill[] = |
| 135 | "files/devtools/dispatch_key_event_shows_auto_fill.html"; |
Nathanael Alcock | 90cb98d | 2017-09-29 21:55:20 | [diff] [blame] | 136 | const char kDOMWarningsTestPage[] = "files/devtools/dom_warnings_page.html"; |
[email protected] | 81762dd | 2009-09-24 15:16:18 | [diff] [blame] | 137 | |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 138 | template <typename... T> |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 139 | void DispatchOnTestSuiteSkipCheck(DevToolsWindow* window, |
| 140 | const char* method, |
| 141 | T... args) { |
| 142 | RenderViewHost* rvh = DevToolsWindowTesting::Get(window) |
| 143 | ->main_web_contents() |
| 144 | ->GetRenderViewHost(); |
| 145 | std::string result; |
| 146 | const char* args_array[] = {method, args...}; |
| 147 | std::ostringstream script; |
| 148 | script << "uiTests.dispatchOnTestSuite(["; |
| 149 | for (size_t i = 0; i < arraysize(args_array); ++i) |
| 150 | script << (i ? "," : "") << '\"' << args_array[i] << '\"'; |
| 151 | script << "])"; |
| 152 | ASSERT_TRUE( |
| 153 | content::ExecuteScriptAndExtractString(rvh, script.str(), &result)); |
| 154 | EXPECT_EQ("[OK]", result); |
| 155 | } |
| 156 | |
| 157 | template <typename... T> |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 158 | void DispatchOnTestSuite(DevToolsWindow* window, |
| 159 | const char* method, |
| 160 | T... args) { |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 161 | std::string result; |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 162 | RenderViewHost* rvh = DevToolsWindowTesting::Get(window) |
| 163 | ->main_web_contents() |
| 164 | ->GetRenderViewHost(); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 165 | // At first check that JavaScript part of the front-end is loaded by |
| 166 | // checking that global variable uiTests exists(it's created after all js |
| 167 | // files have been loaded) and has runTest method. |
| 168 | ASSERT_TRUE( |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 169 | content::ExecuteScriptAndExtractString( |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 170 | rvh, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 171 | "window.domAutomationController.send(" |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 172 | " '' + (window.uiTests && (typeof uiTests.dispatchOnTestSuite)));", |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 173 | &result)); |
[email protected] | b946b42 | 2014-03-18 22:53:40 | [diff] [blame] | 174 | ASSERT_EQ("function", result) << "DevTools front-end is broken."; |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 175 | DispatchOnTestSuiteSkipCheck(window, method, args...); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 176 | } |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 177 | |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 178 | void RunTestFunction(DevToolsWindow* window, const char* test_name) { |
| 179 | DispatchOnTestSuite(window, test_name); |
| 180 | } |
| 181 | |
| 182 | void SwitchToPanel(DevToolsWindow* window, const char* panel) { |
| 183 | DispatchOnTestSuite(window, "switchToPanel", panel); |
| 184 | } |
| 185 | |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 186 | // Version of SwitchToPanel that works with extension-created panels. |
| 187 | void SwitchToExtensionPanel(DevToolsWindow* window, |
| 188 | const Extension* devtools_extension, |
| 189 | const char* panel_name) { |
| 190 | // The full name is the concatenation of the extension URL (stripped of its |
| 191 | // trailing '/') and the |panel_name| that was passed to panels.create(). |
| 192 | std::string prefix = base::TrimString(devtools_extension->url().spec(), "/", |
| 193 | base::TRIM_TRAILING) |
| 194 | .as_string(); |
| 195 | SwitchToPanel(window, (prefix + panel_name).c_str()); |
| 196 | } |
| 197 | |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 198 | class PushTimesMockURLRequestJob : public net::URLRequestMockHTTPJob { |
| 199 | public: |
| 200 | PushTimesMockURLRequestJob(net::URLRequest* request, |
| 201 | net::NetworkDelegate* network_delegate, |
| 202 | base::FilePath file_path) |
Gabriel Charette | cf00b108 | 2017-06-16 19:42:39 | [diff] [blame] | 203 | : net::URLRequestMockHTTPJob(request, network_delegate, file_path) {} |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 204 | |
| 205 | void Start() override { |
| 206 | load_timing_info_.socket_reused = true; |
| 207 | load_timing_info_.request_start_time = base::Time::Now(); |
| 208 | load_timing_info_.request_start = base::TimeTicks::Now(); |
| 209 | load_timing_info_.send_start = base::TimeTicks::Now(); |
| 210 | load_timing_info_.send_end = base::TimeTicks::Now(); |
| 211 | load_timing_info_.receive_headers_end = base::TimeTicks::Now(); |
| 212 | |
| 213 | net::URLRequestMockHTTPJob::Start(); |
| 214 | } |
| 215 | |
| 216 | void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override { |
| 217 | load_timing_info_.push_start = load_timing_info_.request_start - |
| 218 | base::TimeDelta::FromMilliseconds(100); |
| 219 | if (load_timing_info_.push_end.is_null() && |
| 220 | request()->url().query() != kPushUseNullEndTime) { |
| 221 | load_timing_info_.push_end = base::TimeTicks::Now(); |
| 222 | } |
| 223 | *load_timing_info = load_timing_info_; |
| 224 | } |
| 225 | |
| 226 | private: |
| 227 | mutable net::LoadTimingInfo load_timing_info_; |
| 228 | DISALLOW_COPY_AND_ASSIGN(PushTimesMockURLRequestJob); |
| 229 | }; |
| 230 | |
| 231 | class TestInterceptor : public net::URLRequestInterceptor { |
| 232 | public: |
| 233 | // Creates TestInterceptor and registers it with the URLRequestFilter, |
| 234 | // which takes ownership of it. |
| 235 | static void Register(const GURL& url, const base::FilePath& file_path) { |
| 236 | EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 237 | net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( |
| 238 | url.scheme(), url.host(), |
dcheng | 18ec0b54 | 2016-04-26 19:28:53 | [diff] [blame] | 239 | base::WrapUnique(new TestInterceptor(url, file_path))); |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // Unregisters previously created TestInterceptor, which should delete it. |
| 243 | static void Unregister(const GURL& url) { |
| 244 | EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 245 | net::URLRequestFilter::GetInstance()->RemoveHostnameHandler(url.scheme(), |
| 246 | url.host()); |
| 247 | } |
| 248 | |
| 249 | // net::URLRequestJobFactory::ProtocolHandler implementation: |
| 250 | net::URLRequestJob* MaybeInterceptRequest( |
| 251 | net::URLRequest* request, |
| 252 | net::NetworkDelegate* network_delegate) const override { |
| 253 | EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 254 | if (request->url().path() != url_.path()) |
| 255 | return nullptr; |
| 256 | return new PushTimesMockURLRequestJob(request, network_delegate, |
| 257 | file_path_); |
| 258 | } |
| 259 | |
| 260 | private: |
| 261 | TestInterceptor(const GURL& url, const base::FilePath& file_path) |
| 262 | : url_(url), file_path_(file_path) {} |
| 263 | |
| 264 | const GURL url_; |
| 265 | const base::FilePath file_path_; |
| 266 | |
| 267 | DISALLOW_COPY_AND_ASSIGN(TestInterceptor); |
| 268 | }; |
| 269 | |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 270 | } // namespace |
| 271 | |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 272 | class DevToolsSanityTest : public InProcessBrowserTest { |
| 273 | public: |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 274 | DevToolsSanityTest() : window_(NULL) {} |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 275 | |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 276 | void SetUpOnMainThread() override { |
| 277 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 278 | } |
| 279 | |
[email protected] | ff7a8f6f | 2009-06-10 09:44:36 | [diff] [blame] | 280 | protected: |
[email protected] | f72a1cc | 2010-04-30 07:17:30 | [diff] [blame] | 281 | void RunTest(const std::string& test_name, const std::string& test_page) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 282 | OpenDevToolsWindow(test_page, false); |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 283 | RunTestFunction(window_, test_name.c_str()); |
[email protected] | ff7a8f6f | 2009-06-10 09:44:36 | [diff] [blame] | 284 | CloseDevToolsWindow(); |
| 285 | } |
| 286 | |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 287 | template <typename... T> |
| 288 | void RunTestMethod(const char* method, T... args) { |
| 289 | DispatchOnTestSuiteSkipCheck(window_, method, args...); |
| 290 | } |
| 291 | |
| 292 | template <typename... T> |
| 293 | void DispatchAndWait(const char* method, T... args) { |
| 294 | DispatchOnTestSuiteSkipCheck(window_, "waitForAsync", method, args...); |
| 295 | } |
| 296 | |
| 297 | template <typename... T> |
| 298 | void DispatchInPageAndWait(const char* method, T... args) { |
| 299 | DispatchAndWait("invokePageFunctionAsync", method, args...); |
| 300 | } |
| 301 | |
[email protected] | 5da96a4 | 2013-11-21 06:49:21 | [diff] [blame] | 302 | void LoadTestPage(const std::string& test_page) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 303 | GURL url = spawned_test_server()->GetURL(test_page); |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 304 | ui_test_utils::NavigateToURL(browser(), url); |
[email protected] | 5da96a4 | 2013-11-21 06:49:21 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 307 | void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 308 | ASSERT_TRUE(spawned_test_server()->Start()); |
[email protected] | 5da96a4 | 2013-11-21 06:49:21 | [diff] [blame] | 309 | LoadTestPage(test_page); |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 310 | |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 311 | window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), |
| 312 | is_docked); |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 313 | } |
| 314 | |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 315 | WebContents* GetInspectedTab() { |
[email protected] | 3695357 | 2013-01-14 18:38:10 | [diff] [blame] | 316 | return browser()->tab_strip_model()->GetWebContentsAt(0); |
[email protected] | 13a6abf8 | 2009-10-31 08:42:21 | [diff] [blame] | 317 | } |
| 318 | |
[email protected] | 1b91f510 | 2009-06-09 15:31:30 | [diff] [blame] | 319 | void CloseDevToolsWindow() { |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 320 | DevToolsWindowTesting::CloseDevToolsWindowSync(window_); |
| 321 | } |
| 322 | |
| 323 | WebContents* main_web_contents() { |
| 324 | return DevToolsWindowTesting::Get(window_)->main_web_contents(); |
| 325 | } |
| 326 | |
| 327 | WebContents* toolbox_web_contents() { |
| 328 | return DevToolsWindowTesting::Get(window_)->toolbox_web_contents(); |
[email protected] | 1b91f510 | 2009-06-09 15:31:30 | [diff] [blame] | 329 | } |
| 330 | |
[email protected] | 1b91f510 | 2009-06-09 15:31:30 | [diff] [blame] | 331 | DevToolsWindow* window_; |
[email protected] | cc27340 | 2009-05-12 09:20:33 | [diff] [blame] | 332 | }; |
| 333 | |
Dmitry Gozman | 902bffab | 2018-01-27 15:20:46 | [diff] [blame] | 334 | class SitePerProcessDevToolsSanityTest : public DevToolsSanityTest { |
| 335 | public: |
| 336 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 337 | DevToolsSanityTest::SetUpCommandLine(command_line); |
| 338 | content::IsolateAllSitesForTesting(command_line); |
| 339 | }; |
| 340 | |
| 341 | void SetUpOnMainThread() override { |
| 342 | DevToolsSanityTest::SetUpOnMainThread(); |
| 343 | content::SetupCrossSiteRedirector(embedded_test_server()); |
| 344 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 345 | } |
| 346 | }; |
| 347 | |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 348 | // Used to block until a dev tools window gets beforeunload event. |
| 349 | class DevToolsWindowBeforeUnloadObserver |
| 350 | : public content::WebContentsObserver { |
| 351 | public: |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 352 | explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*); |
| 353 | void Wait(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 354 | private: |
| 355 | // Invoked when the beforeunload handler fires. |
dcheng | 03748a4 | 2014-10-21 10:19:13 | [diff] [blame] | 356 | void BeforeUnloadFired(const base::TimeTicks& proceed_time) override; |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 357 | |
| 358 | bool m_fired; |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 359 | scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 360 | DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver); |
| 361 | }; |
| 362 | |
| 363 | DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 364 | DevToolsWindow* devtools_window) |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 365 | : WebContentsObserver( |
| 366 | DevToolsWindowTesting::Get(devtools_window)->main_web_contents()), |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 367 | m_fired(false) { |
| 368 | } |
| 369 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 370 | void DevToolsWindowBeforeUnloadObserver::Wait() { |
| 371 | if (m_fired) |
| 372 | return; |
| 373 | message_loop_runner_ = new content::MessageLoopRunner; |
| 374 | message_loop_runner_->Run(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired( |
| 378 | const base::TimeTicks& proceed_time) { |
| 379 | m_fired = true; |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 380 | if (message_loop_runner_.get()) |
| 381 | message_loop_runner_->Quit(); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 382 | } |
| 383 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 384 | class DevToolsBeforeUnloadTest: public DevToolsSanityTest { |
| 385 | public: |
| 386 | void CloseInspectedTab() { |
| 387 | browser()->tab_strip_model()->CloseWebContentsAt(0, |
| 388 | TabStripModel::CLOSE_NONE); |
| 389 | } |
| 390 | |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 391 | void CloseDevToolsWindowAsync() { |
| 392 | DevToolsWindowTesting::CloseDevToolsWindow(window_); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | void CloseInspectedBrowser() { |
| 396 | chrome::CloseWindow(browser()); |
| 397 | } |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 398 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 399 | protected: |
| 400 | void InjectBeforeUnloadListener(content::WebContents* web_contents) { |
| 401 | ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), |
| 402 | "window.addEventListener('beforeunload'," |
| 403 | "function(event) { event.returnValue = 'Foo'; });")); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 404 | content::PrepContentsForBeforeUnloadTest(web_contents); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 405 | } |
| 406 | |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 407 | void RunBeforeUnloadSanityTest(bool is_docked, |
| 408 | base::Callback<void(void)> close_method, |
| 409 | bool wait_for_browser_close = true) { |
| 410 | OpenDevToolsWindow(kDebuggerTestPage, is_docked); |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 411 | scoped_refptr<content::MessageLoopRunner> runner = |
| 412 | new content::MessageLoopRunner; |
| 413 | DevToolsWindowTesting::Get(window_)-> |
| 414 | SetCloseCallback(runner->QuitClosure()); |
| 415 | InjectBeforeUnloadListener(main_web_contents()); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 416 | { |
| 417 | DevToolsWindowBeforeUnloadObserver before_unload_observer(window_); |
| 418 | close_method.Run(); |
| 419 | CancelModalDialog(); |
| 420 | before_unload_observer.Wait(); |
| 421 | } |
| 422 | { |
| 423 | content::WindowedNotificationObserver close_observer( |
| 424 | chrome::NOTIFICATION_BROWSER_CLOSED, |
| 425 | content::Source<Browser>(browser())); |
| 426 | close_method.Run(); |
| 427 | AcceptModalDialog(); |
| 428 | if (wait_for_browser_close) |
| 429 | close_observer.Wait(); |
| 430 | } |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 431 | runner->Run(); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | DevToolsWindow* OpenDevToolWindowOnWebContents( |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 435 | content::WebContents* contents, bool is_docked) { |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 436 | DevToolsWindow* window = |
| 437 | DevToolsWindowTesting::OpenDevToolsWindowSync(contents, is_docked); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 438 | return window; |
| 439 | } |
| 440 | |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 441 | void OpenDevToolsPopupWindow(DevToolsWindow* devtools_window) { |
| 442 | content::WindowedNotificationObserver observer( |
| 443 | content::NOTIFICATION_LOAD_STOP, |
| 444 | content::NotificationService::AllSources()); |
| 445 | ASSERT_TRUE(content::ExecuteScript( |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 446 | DevToolsWindowTesting::Get(devtools_window)-> |
| 447 | main_web_contents()->GetRenderViewHost(), |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 448 | "window.open(\"\", \"\", \"location=0\");")); |
| 449 | observer.Wait(); |
| 450 | } |
| 451 | |
| 452 | void CloseDevToolsPopupWindow(DevToolsWindow* devtools_window) { |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 453 | DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 454 | } |
| 455 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 456 | void AcceptModalDialog() { |
| 457 | NativeAppModalDialog* native_dialog = GetDialog(); |
| 458 | native_dialog->AcceptAppModalDialog(); |
| 459 | } |
| 460 | |
| 461 | void CancelModalDialog() { |
| 462 | NativeAppModalDialog* native_dialog = GetDialog(); |
| 463 | native_dialog->CancelAppModalDialog(); |
| 464 | } |
| 465 | |
| 466 | NativeAppModalDialog* GetDialog() { |
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 467 | JavaScriptAppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| 468 | NativeAppModalDialog* native_dialog = dialog->native_dialog(); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 469 | EXPECT_TRUE(native_dialog); |
| 470 | return native_dialog; |
| 471 | } |
| 472 | }; |
| 473 | |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 474 | void TimeoutCallback(const std::string& timeout_message) { |
[email protected] | b946b42 | 2014-03-18 22:53:40 | [diff] [blame] | 475 | ADD_FAILURE() << timeout_message; |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 476 | base::RunLoop::QuitCurrentWhenIdleDeprecated(); |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 477 | } |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 478 | |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 479 | // Base class for DevTools tests that test devtools functionality for |
| 480 | // extensions and content scripts. |
[email protected] | fb996d3 | 2011-12-21 12:55:30 | [diff] [blame] | 481 | class DevToolsExtensionTest : public DevToolsSanityTest, |
| 482 | public content::NotificationObserver { |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 483 | public: |
[email protected] | fb996d3 | 2011-12-21 12:55:30 | [diff] [blame] | 484 | DevToolsExtensionTest() : DevToolsSanityTest() { |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 485 | PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_); |
| 486 | test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools"); |
| 487 | test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions"); |
| 488 | } |
| 489 | |
| 490 | protected: |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 491 | // Load an extension from test\data\devtools\extensions\<extension_name> |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 492 | void LoadExtension(const char* extension_name) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 493 | base::FilePath path = test_extensions_dir_.AppendASCII(extension_name); |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 494 | ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension."; |
| 495 | } |
| 496 | |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 497 | const Extension* LoadExtensionFromPath(const base::FilePath& path) { |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 498 | ExtensionService* service = extensions::ExtensionSystem::Get( |
| 499 | browser()->profile())->extension_service(); |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 500 | extensions::ExtensionRegistry* registry = |
| 501 | extensions::ExtensionRegistry::Get(browser()->profile()); |
limasdf | f3a0c5ef | 2017-02-28 01:30:38 | [diff] [blame] | 502 | extensions::TestExtensionRegistryObserver observer(registry); |
| 503 | extensions::UnpackedInstaller::Create(service)->Load(path); |
| 504 | observer.WaitForExtensionLoaded(); |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 505 | |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 506 | if (!WaitForExtensionViewsToLoad()) |
| 507 | return nullptr; |
| 508 | |
| 509 | return GetExtensionByPath(registry->enabled_extensions(), path); |
| 510 | } |
| 511 | |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 512 | // Loads a dynamically generated extension populated with a bunch of test |
| 513 | // pages. |name| is the extension name to use in the manifest. |
| 514 | // |devtools_page|, if non-empty, indicates which test page should be be |
| 515 | // listed as a devtools_page in the manifest. If |devtools_page| is empty, a |
| 516 | // non-devtools extension is created instead. |panel_iframe_src| controls the |
| 517 | // src= attribute of the <iframe> element in the 'panel.html' test page. |
| 518 | const Extension* LoadExtensionForTest(const std::string& name, |
| 519 | const std::string& devtools_page, |
| 520 | const std::string& panel_iframe_src) { |
| 521 | test_extension_dirs_.push_back( |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 522 | std::make_unique<extensions::TestExtensionDir>()); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 523 | extensions::TestExtensionDir* dir = test_extension_dirs_.back().get(); |
| 524 | |
| 525 | extensions::DictionaryBuilder manifest; |
| 526 | manifest.Set("name", name) |
| 527 | .Set("version", "1") |
| 528 | .Set("manifest_version", 2) |
| 529 | // simple_test_page.html is currently the only page referenced outside |
| 530 | // of its own extension in the tests |
| 531 | .Set("web_accessible_resources", |
| 532 | extensions::ListBuilder().Append("simple_test_page.html").Build()); |
| 533 | |
| 534 | // If |devtools_page| isn't empty, make it a devtools extension in the |
| 535 | // manifest. |
| 536 | if (!devtools_page.empty()) |
| 537 | manifest.Set("devtools_page", devtools_page); |
| 538 | |
| 539 | dir->WriteManifest(manifest.ToJSON()); |
| 540 | |
| 541 | GURL http_frame_url = |
| 542 | embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); |
| 543 | |
| 544 | // If this is a devtools extension, |devtools_page| will indicate which of |
| 545 | // these devtools_pages will end up being used. Different tests use |
| 546 | // different devtools_pages. |
| 547 | dir->WriteFile(FILE_PATH_LITERAL("web_devtools_page.html"), |
| 548 | "<html><body><iframe src='" + http_frame_url.spec() + |
| 549 | "'></iframe></body></html>"); |
| 550 | |
| 551 | dir->WriteFile(FILE_PATH_LITERAL("simple_devtools_page.html"), |
| 552 | "<html><body></body></html>"); |
| 553 | |
| 554 | dir->WriteFile( |
| 555 | FILE_PATH_LITERAL("panel_devtools_page.html"), |
| 556 | "<html><head><script " |
| 557 | "src='panel_devtools_page.js'></script></head><body></body></html>"); |
| 558 | |
| 559 | dir->WriteFile(FILE_PATH_LITERAL("panel_devtools_page.js"), |
| 560 | "chrome.devtools.panels.create('iframe_panel',\n" |
| 561 | " null,\n" |
| 562 | " 'panel.html',\n" |
| 563 | " function(panel) {\n" |
| 564 | " chrome.devtools.inspectedWindow.eval(\n" |
| 565 | " 'console.log(\"PASS\")');\n" |
| 566 | " }\n" |
| 567 | ");\n"); |
| 568 | |
| 569 | dir->WriteFile(FILE_PATH_LITERAL("sidebarpane_devtools_page.html"), |
| 570 | "<html><head><script src='sidebarpane_devtools_page.js'>" |
| 571 | "</script></head><body></body></html>"); |
| 572 | |
| 573 | dir->WriteFile( |
| 574 | FILE_PATH_LITERAL("sidebarpane_devtools_page.js"), |
| 575 | "chrome.devtools.panels.elements.createSidebarPane('iframe_pane',\n" |
| 576 | " function(sidebar) {\n" |
| 577 | " chrome.devtools.inspectedWindow.eval(\n" |
| 578 | " 'console.log(\"PASS\")');\n" |
| 579 | " sidebar.setPage('panel.html');\n" |
| 580 | " }\n" |
| 581 | ");\n"); |
| 582 | |
| 583 | dir->WriteFile(FILE_PATH_LITERAL("panel.html"), |
| 584 | "<html><body><iframe src='" + panel_iframe_src + |
| 585 | "'></iframe></body></html>"); |
| 586 | |
| 587 | dir->WriteFile(FILE_PATH_LITERAL("simple_test_page.html"), |
| 588 | "<html><body>This is a test</body></html>"); |
| 589 | |
| 590 | GURL web_url = embedded_test_server()->GetURL("a.com", "/title3.html"); |
| 591 | |
| 592 | dir->WriteFile(FILE_PATH_LITERAL("multi_frame_page.html"), |
| 593 | "<html><body><iframe src='about:blank'>" |
| 594 | "</iframe><iframe src='data:text/html,foo'>" |
| 595 | "</iframe><iframe src='" + |
| 596 | web_url.spec() + "'></iframe></body></html>"); |
| 597 | |
| 598 | // Install the extension. |
| 599 | return LoadExtensionFromPath(dir->UnpackedPath()); |
| 600 | } |
| 601 | |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 602 | private: |
| 603 | const Extension* GetExtensionByPath( |
| 604 | const extensions::ExtensionSet& extensions, |
| 605 | const base::FilePath& path) { |
Francois Doray | e6fb2d0 | 2017-10-18 21:29:13 | [diff] [blame] | 606 | base::ScopedAllowBlockingForTesting allow_blocking; |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 607 | base::FilePath extension_path = base::MakeAbsoluteFilePath(path); |
| 608 | EXPECT_TRUE(!extension_path.empty()); |
| 609 | for (const scoped_refptr<const Extension>& extension : extensions) { |
| 610 | if (extension->path() == extension_path) { |
| 611 | return extension.get(); |
| 612 | } |
| 613 | } |
| 614 | return nullptr; |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 615 | } |
| 616 | |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 617 | bool WaitForExtensionViewsToLoad() { |
| 618 | // Wait for all the extension render views that exist to finish loading. |
| 619 | // NOTE: This assumes that the extension views list is not changing while |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 620 | // this method is running. |
| 621 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 622 | content::NotificationRegistrar registrar; |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 623 | registrar.Add(this, |
kalman | fd474fa | 2015-03-16 22:30:57 | [diff] [blame] | 624 | extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 625 | content::NotificationService::AllSources()); |
[email protected] | d4d57df | 2011-11-30 20:33:52 | [diff] [blame] | 626 | base::CancelableClosure timeout( |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 627 | base::Bind(&TimeoutCallback, "Extension host load timed out.")); |
skyostil | 0259835 | 2015-06-12 12:37:25 | [diff] [blame] | 628 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
[email protected] | 4173deb | 2013-06-07 15:21:04 | [diff] [blame] | 629 | FROM_HERE, timeout.callback(), TestTimeouts::action_timeout()); |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 630 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 631 | extensions::ProcessManager* manager = |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 632 | extensions::ProcessManager::Get(browser()->profile()); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 633 | extensions::ProcessManager::FrameSet all_frames = manager->GetAllFrames(); |
| 634 | for (extensions::ProcessManager::FrameSet::const_iterator iter = |
| 635 | all_frames.begin(); |
| 636 | iter != all_frames.end();) { |
| 637 | if (!content::WebContents::FromRenderFrameHost(*iter)->IsLoading()) |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 638 | ++iter; |
| 639 | else |
[email protected] | 729eb63 | 2012-07-26 04:45:26 | [diff] [blame] | 640 | content::RunMessageLoop(); |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 641 | } |
| 642 | |
[email protected] | 4207d2b | 2011-11-28 18:09:21 | [diff] [blame] | 643 | timeout.Cancel(); |
[email protected] | 680bc22 | 2009-10-27 10:46:22 | [diff] [blame] | 644 | return true; |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 645 | } |
| 646 | |
dcheng | 03748a4 | 2014-10-21 10:19:13 | [diff] [blame] | 647 | void Observe(int type, |
| 648 | const content::NotificationSource& source, |
| 649 | const content::NotificationDetails& details) override { |
limasdf | f3a0c5ef | 2017-02-28 01:30:38 | [diff] [blame] | 650 | DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, |
| 651 | type); |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 652 | base::RunLoop::QuitCurrentWhenIdleDeprecated(); |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 653 | } |
| 654 | |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 655 | std::vector<std::unique_ptr<extensions::TestExtensionDir>> |
| 656 | test_extension_dirs_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 657 | base::FilePath test_extensions_dir_; |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 658 | }; |
| 659 | |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 660 | class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest { |
| 661 | public: |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 662 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 663 | command_line->AppendSwitch( |
| 664 | extensions::switches::kEnableExperimentalExtensionApis); |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 665 | } |
| 666 | }; |
| 667 | |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 668 | class WorkerDevToolsSanityTest : public InProcessBrowserTest { |
| 669 | public: |
[email protected] | 90ca4427 | 2012-07-18 18:15:48 | [diff] [blame] | 670 | WorkerDevToolsSanityTest() : window_(NULL) {} |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 671 | |
| 672 | protected: |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 673 | class WorkerCreationObserver : public DevToolsAgentHostObserver { |
[email protected] | 649d1c0 | 2012-04-27 02:56:21 | [diff] [blame] | 674 | public: |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 675 | WorkerCreationObserver(const std::string& path, |
| 676 | scoped_refptr<DevToolsAgentHost>* out_host, |
| 677 | base::Closure quit) |
| 678 | : path_(path), out_host_(out_host), quit_(quit) { |
| 679 | DevToolsAgentHost::AddObserver(this); |
[email protected] | d9ddc0d | 2011-10-12 08:40:12 | [diff] [blame] | 680 | } |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 681 | |
| 682 | private: |
| 683 | ~WorkerCreationObserver() override { |
| 684 | DevToolsAgentHost::RemoveObserver(this); |
| 685 | } |
| 686 | |
| 687 | void DevToolsAgentHostCreated(DevToolsAgentHost* host) override { |
| 688 | if (host->GetType() == DevToolsAgentHost::kTypeSharedWorker && |
| 689 | host->GetURL().path().rfind(path_) != std::string::npos) { |
| 690 | *out_host_ = host; |
| 691 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_); |
| 692 | delete this; |
| 693 | } |
| 694 | } |
| 695 | |
yurys | 48be075f | 2014-10-16 09:04:21 | [diff] [blame] | 696 | std::string path_; |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 697 | scoped_refptr<DevToolsAgentHost>* out_host_; |
| 698 | base::Closure quit_; |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 699 | }; |
| 700 | |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 701 | static scoped_refptr<DevToolsAgentHost> WaitForFirstSharedWorker( |
| 702 | const char* path) { |
| 703 | for (auto& host : DevToolsAgentHost::GetOrCreateAll()) { |
| 704 | if (host->GetType() == DevToolsAgentHost::kTypeSharedWorker && |
| 705 | host->GetURL().path().rfind(path) != std::string::npos) { |
| 706 | return host; |
| 707 | } |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 708 | } |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 709 | scoped_refptr<DevToolsAgentHost> host; |
| 710 | base::RunLoop run_loop; |
| 711 | new WorkerCreationObserver(path, &host, run_loop.QuitWhenIdleClosure()); |
| 712 | content::RunThisRunLoop(&run_loop); |
| 713 | return host; |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 714 | } |
| 715 | |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 716 | void OpenDevToolsWindow(scoped_refptr<DevToolsAgentHost> agent_host) { |
[email protected] | cf3b40e3 | 2011-08-02 06:45:03 | [diff] [blame] | 717 | Profile* profile = browser()->profile(); |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 718 | window_ = |
| 719 | DevToolsWindowTesting::OpenDevToolsWindowSync(profile, agent_host); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | void CloseDevToolsWindow() { |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 723 | DevToolsWindowTesting::CloseDevToolsWindowSync(window_); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | DevToolsWindow* window_; |
| 727 | }; |
| 728 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 729 | // Tests that BeforeUnload event gets called on docked devtools if |
| 730 | // we try to close them. |
| 731 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 732 | RunBeforeUnloadSanityTest(true, base::Bind( |
tzik | e04a147 | 2016-08-02 21:00:33 | [diff] [blame] | 733 | &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, |
| 734 | base::Unretained(this)), false); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | // Tests that BeforeUnload event gets called on docked devtools if |
| 738 | // we try to close the inspected page. |
| 739 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
avi | 64b8b65b | 2017-03-29 18:50:34 | [diff] [blame] | 740 | TestDockedDevToolsInspectedTabClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 741 | RunBeforeUnloadSanityTest(true, base::Bind( |
tzik | e04a147 | 2016-08-02 21:00:33 | [diff] [blame] | 742 | &DevToolsBeforeUnloadTest::CloseInspectedTab, |
| 743 | base::Unretained(this))); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | // Tests that BeforeUnload event gets called on docked devtools if |
| 747 | // we try to close the inspected browser. |
| 748 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
avi | 64b8b65b | 2017-03-29 18:50:34 | [diff] [blame] | 749 | TestDockedDevToolsInspectedBrowserClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 750 | RunBeforeUnloadSanityTest(true, base::Bind( |
tzik | e04a147 | 2016-08-02 21:00:33 | [diff] [blame] | 751 | &DevToolsBeforeUnloadTest::CloseInspectedBrowser, |
| 752 | base::Unretained(this))); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | // Tests that BeforeUnload event gets called on undocked devtools if |
| 756 | // we try to close them. |
avi | 64b8b65b | 2017-03-29 18:50:34 | [diff] [blame] | 757 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 758 | RunBeforeUnloadSanityTest(false, base::Bind( |
tzik | e04a147 | 2016-08-02 21:00:33 | [diff] [blame] | 759 | &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, |
| 760 | base::Unretained(this)), false); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | // Tests that BeforeUnload event gets called on undocked devtools if |
| 764 | // we try to close the inspected page. |
| 765 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
avi | 64b8b65b | 2017-03-29 18:50:34 | [diff] [blame] | 766 | TestUndockedDevToolsInspectedTabClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 767 | RunBeforeUnloadSanityTest(false, base::Bind( |
tzik | e04a147 | 2016-08-02 21:00:33 | [diff] [blame] | 768 | &DevToolsBeforeUnloadTest::CloseInspectedTab, |
| 769 | base::Unretained(this))); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | // Tests that BeforeUnload event gets called on undocked devtools if |
| 773 | // we try to close the inspected browser. |
| 774 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
avi | 64b8b65b | 2017-03-29 18:50:34 | [diff] [blame] | 775 | TestUndockedDevToolsInspectedBrowserClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 776 | RunBeforeUnloadSanityTest(false, base::Bind( |
tzik | e04a147 | 2016-08-02 21:00:33 | [diff] [blame] | 777 | &DevToolsBeforeUnloadTest::CloseInspectedBrowser, |
| 778 | base::Unretained(this))); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | // Tests that BeforeUnload event gets called on undocked devtools if |
| 782 | // we try to exit application. |
| 783 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
avi | 64b8b65b | 2017-03-29 18:50:34 | [diff] [blame] | 784 | TestUndockedDevToolsApplicationClose) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 785 | RunBeforeUnloadSanityTest(false, base::Bind( |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 786 | &chrome::CloseAllBrowsers)); |
| 787 | } |
| 788 | |
[email protected] | c0da7c1 | 2013-11-27 19:07:00 | [diff] [blame] | 789 | // Tests that inspected tab gets closed if devtools renderer |
| 790 | // becomes unresponsive during beforeunload event interception. |
| 791 | // @see http://crbug.com/322380 |
lushnikov | cf05b64 | 2015-11-04 00:10:13 | [diff] [blame] | 792 | // Disabled because of http://crbug.com/410327 |
avi | 64b8b65b | 2017-03-29 18:50:34 | [diff] [blame] | 793 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
lushnikov | cf05b64 | 2015-11-04 00:10:13 | [diff] [blame] | 794 | DISABLED_TestUndockedDevToolsUnresponsive) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 795 | ASSERT_TRUE(spawned_test_server()->Start()); |
[email protected] | c0da7c1 | 2013-11-27 19:07:00 | [diff] [blame] | 796 | LoadTestPage(kDebuggerTestPage); |
| 797 | DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 798 | GetInspectedTab(), false); |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 799 | |
| 800 | scoped_refptr<content::MessageLoopRunner> runner = |
| 801 | new content::MessageLoopRunner; |
| 802 | DevToolsWindowTesting::Get(devtools_window)->SetCloseCallback( |
| 803 | runner->QuitClosure()); |
[email protected] | c0da7c1 | 2013-11-27 19:07:00 | [diff] [blame] | 804 | |
| 805 | ASSERT_TRUE(content::ExecuteScript( |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 806 | DevToolsWindowTesting::Get(devtools_window)->main_web_contents()-> |
| 807 | GetRenderViewHost(), |
[email protected] | c0da7c1 | 2013-11-27 19:07:00 | [diff] [blame] | 808 | "window.addEventListener('beforeunload'," |
| 809 | "function(event) { while (true); });")); |
| 810 | CloseInspectedTab(); |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 811 | runner->Run(); |
[email protected] | c0da7c1 | 2013-11-27 19:07:00 | [diff] [blame] | 812 | } |
| 813 | |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 814 | // Tests that closing worker inspector window does not cause browser crash |
| 815 | // @see http://crbug.com/323031 |
| 816 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
| 817 | TestWorkerWindowClosing) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 818 | ASSERT_TRUE(spawned_test_server()->Start()); |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 819 | LoadTestPage(kDebuggerTestPage); |
| 820 | DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 821 | GetInspectedTab(), false); |
[email protected] | 1692b80f7 | 2013-11-28 20:08:58 | [diff] [blame] | 822 | |
| 823 | OpenDevToolsPopupWindow(devtools_window); |
| 824 | CloseDevToolsPopupWindow(devtools_window); |
| 825 | } |
| 826 | |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 827 | // Tests that BeforeUnload event gets called on devtools that are opened |
| 828 | // on another devtools. |
[email protected] | 68b36ac | 2013-11-19 23:56:03 | [diff] [blame] | 829 | IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, |
kozyatinskiy | 6e28163 | 2016-06-09 18:08:56 | [diff] [blame] | 830 | TestDevToolsOnDevTools) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 831 | ASSERT_TRUE(spawned_test_server()->Start()); |
[email protected] | 5da96a4 | 2013-11-21 06:49:21 | [diff] [blame] | 832 | LoadTestPage(kDebuggerTestPage); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 833 | |
| 834 | std::vector<DevToolsWindow*> windows; |
| 835 | std::vector<content::WindowedNotificationObserver*> close_observers; |
| 836 | content::WebContents* inspected_web_contents = GetInspectedTab(); |
| 837 | for (int i = 0; i < 3; ++i) { |
| 838 | DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents( |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 839 | inspected_web_contents, i == 0); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 840 | windows.push_back(devtools_window); |
| 841 | content::WindowedNotificationObserver* close_observer = |
| 842 | new content::WindowedNotificationObserver( |
| 843 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 844 | content::Source<content::WebContents>( |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 845 | DevToolsWindowTesting::Get(devtools_window)-> |
| 846 | main_web_contents())); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 847 | close_observers.push_back(close_observer); |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 848 | inspected_web_contents = |
| 849 | DevToolsWindowTesting::Get(devtools_window)->main_web_contents(); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 850 | } |
| 851 | |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 852 | InjectBeforeUnloadListener( |
| 853 | DevToolsWindowTesting::Get(windows[0])->main_web_contents()); |
| 854 | InjectBeforeUnloadListener( |
| 855 | DevToolsWindowTesting::Get(windows[2])->main_web_contents()); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 856 | // Try to close second devtools. |
| 857 | { |
| 858 | content::WindowedNotificationObserver cancel_browser( |
| 859 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 860 | content::NotificationService::AllSources()); |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 861 | chrome::CloseWindow(DevToolsWindowTesting::Get(windows[1])->browser()); |
[email protected] | 9035471 | 2013-11-16 00:06:30 | [diff] [blame] | 862 | CancelModalDialog(); |
| 863 | cancel_browser.Wait(); |
| 864 | } |
| 865 | // Try to close browser window. |
| 866 | { |
| 867 | content::WindowedNotificationObserver cancel_browser( |
| 868 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 869 | content::NotificationService::AllSources()); |
| 870 | chrome::CloseWindow(browser()); |
| 871 | AcceptModalDialog(); |
| 872 | CancelModalDialog(); |
| 873 | cancel_browser.Wait(); |
| 874 | } |
| 875 | // Try to exit application. |
| 876 | { |
| 877 | content::WindowedNotificationObserver close_observer( |
| 878 | chrome::NOTIFICATION_BROWSER_CLOSED, |
| 879 | content::Source<Browser>(browser())); |
| 880 | chrome::CloseAllBrowsers(); |
| 881 | AcceptModalDialog(); |
| 882 | AcceptModalDialog(); |
| 883 | close_observer.Wait(); |
| 884 | } |
| 885 | for (size_t i = 0; i < close_observers.size(); ++i) { |
| 886 | close_observers[i]->Wait(); |
| 887 | delete close_observers[i]; |
| 888 | } |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 889 | } |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 890 | |
[email protected] | 3f5866e | 2009-07-01 07:25:16 | [diff] [blame] | 891 | // Tests scripts panel showing. |
[email protected] | 2565b87 | 2014-08-01 11:57:52 | [diff] [blame] | 892 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestShowScriptsTab) { |
[email protected] | 3f5866e | 2009-07-01 07:25:16 | [diff] [blame] | 893 | RunTest("testShowScriptsTab", kDebuggerTestPage); |
[email protected] | a2f2023 | 2009-06-30 15:06:57 | [diff] [blame] | 894 | } |
| 895 | |
[email protected] | 13a6abf8 | 2009-10-31 08:42:21 | [diff] [blame] | 896 | // Tests that scripts tab is populated with inspected scripts even if it |
| 897 | // hadn't been shown by the moment inspected paged refreshed. |
| 898 | // @see http://crbug.com/26312 |
[email protected] | a9b82d3 | 2012-01-25 19:55:38 | [diff] [blame] | 899 | IN_PROC_BROWSER_TEST_F( |
| 900 | DevToolsSanityTest, |
oshima | 98205bc | 2015-06-19 19:52:42 | [diff] [blame] | 901 | TestScriptsTabIsPopulatedOnInspectedPageRefresh) { |
[email protected] | 13a6abf8 | 2009-10-31 08:42:21 | [diff] [blame] | 902 | RunTest("testScriptsTabIsPopulatedOnInspectedPageRefresh", |
| 903 | kDebuggerTestPage); |
| 904 | } |
| 905 | |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 906 | // Tests that chrome.devtools extension is correctly exposed. |
[email protected] | fb996d3 | 2011-12-21 12:55:30 | [diff] [blame] | 907 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 908 | TestDevToolsExtensionAPI) { |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 909 | LoadExtension("devtools_extension"); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 910 | RunTest("waitForTestResultsInConsole", std::string()); |
[email protected] | ec6d535 | 2011-12-19 14:48:34 | [diff] [blame] | 911 | } |
| 912 | |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 913 | // Tests that http Iframes within the visible devtools panel for the devtools |
| 914 | // extension are rendered in their own processes and not in the devtools process |
| 915 | // or the extension's process. This is tested because this is one of the |
| 916 | // extension pages with devtools access |
| 917 | // (https://developer.chrome.com/extensions/devtools). Also tests that frames |
| 918 | // with data URLs and about:blank URLs are rendered in the devtools process, |
| 919 | // unless a web OOPIF navigates itself to about:blank, in which case it does not |
| 920 | // end up back in the devtools process. Also tests that when a web IFrame is |
| 921 | // navigated back to a devtools extension page, it gets put back in the devtools |
| 922 | // process. |
| 923 | // http://crbug.com/570483 |
| 924 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 925 | HttpIframeInDevToolsExtensionPanel) { |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 926 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 927 | |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 928 | // Install the dynamically-generated extension. |
| 929 | const Extension* extension = |
| 930 | LoadExtensionForTest("Devtools Extension", "panel_devtools_page.html", |
| 931 | "/multi_frame_page.html"); |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 932 | ASSERT_TRUE(extension); |
| 933 | |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 934 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 935 | |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 936 | // Wait for the extension's panel to finish loading -- it'll output 'PASS' |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 937 | // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. |
| 938 | RunTestFunction(window_, "waitForTestResultsInConsole"); |
| 939 | |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 940 | // Now that we know the panel is loaded, switch to it. |
| 941 | SwitchToExtensionPanel(window_, extension, "iframe_panel"); |
| 942 | content::WaitForLoadStop(main_web_contents()); |
| 943 | |
| 944 | std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); |
| 945 | EXPECT_EQ(7U, rfhs.size()); |
| 946 | |
| 947 | // This test creates a page with the following frame tree: |
| 948 | // - DevTools |
| 949 | // - devtools_page from DevTools extension |
| 950 | // - Panel (DevTools extension) |
| 951 | // - iframe (DevTools extension) |
| 952 | // - about:blank |
| 953 | // - data: |
| 954 | // - web URL |
| 955 | |
| 956 | RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); |
| 957 | RenderFrameHost* devtools_extension_devtools_page_rfh = |
| 958 | ChildFrameAt(main_devtools_rfh, 0); |
| 959 | RenderFrameHost* devtools_extension_panel_rfh = |
| 960 | ChildFrameAt(main_devtools_rfh, 1); |
| 961 | RenderFrameHost* panel_frame_rfh = |
| 962 | ChildFrameAt(devtools_extension_panel_rfh, 0); |
| 963 | RenderFrameHost* about_blank_frame_rfh = ChildFrameAt(panel_frame_rfh, 0); |
| 964 | RenderFrameHost* data_frame_rfh = ChildFrameAt(panel_frame_rfh, 1); |
| 965 | RenderFrameHost* web_frame_rfh = ChildFrameAt(panel_frame_rfh, 2); |
| 966 | |
| 967 | GURL web_url = embedded_test_server()->GetURL("a.com", "/title3.html"); |
| 968 | GURL about_blank_url = GURL(url::kAboutBlankURL); |
| 969 | GURL data_url = GURL("data:text/html,foo"); |
| 970 | |
| 971 | EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( |
| 972 | content::kChromeDevToolsScheme)); |
| 973 | EXPECT_EQ(extension->GetResourceURL("/panel_devtools_page.html"), |
| 974 | devtools_extension_devtools_page_rfh->GetLastCommittedURL()); |
| 975 | EXPECT_EQ(extension->GetResourceURL("/panel.html"), |
| 976 | devtools_extension_panel_rfh->GetLastCommittedURL()); |
| 977 | EXPECT_EQ(extension->GetResourceURL("/multi_frame_page.html"), |
| 978 | panel_frame_rfh->GetLastCommittedURL()); |
| 979 | EXPECT_EQ(about_blank_url, about_blank_frame_rfh->GetLastCommittedURL()); |
| 980 | EXPECT_EQ(data_url, data_frame_rfh->GetLastCommittedURL()); |
| 981 | EXPECT_EQ(web_url, web_frame_rfh->GetLastCommittedURL()); |
| 982 | |
| 983 | content::SiteInstance* devtools_instance = |
| 984 | main_devtools_rfh->GetSiteInstance(); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 985 | content::SiteInstance* extensions_instance = |
| 986 | devtools_extension_devtools_page_rfh->GetSiteInstance(); |
| 987 | |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 988 | EXPECT_TRUE( |
| 989 | devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 990 | EXPECT_TRUE( |
| 991 | extensions_instance->GetSiteURL().SchemeIs(extensions::kExtensionScheme)); |
| 992 | |
| 993 | EXPECT_NE(devtools_instance, extensions_instance); |
| 994 | EXPECT_EQ(extensions_instance, |
| 995 | devtools_extension_panel_rfh->GetSiteInstance()); |
| 996 | EXPECT_EQ(extensions_instance, panel_frame_rfh->GetSiteInstance()); |
| 997 | EXPECT_EQ(extensions_instance, about_blank_frame_rfh->GetSiteInstance()); |
| 998 | EXPECT_EQ(extensions_instance, data_frame_rfh->GetSiteInstance()); |
| 999 | |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1000 | EXPECT_EQ(web_url.host(), |
| 1001 | web_frame_rfh->GetSiteInstance()->GetSiteURL().host()); |
| 1002 | EXPECT_NE(devtools_instance, web_frame_rfh->GetSiteInstance()); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1003 | EXPECT_NE(extensions_instance, web_frame_rfh->GetSiteInstance()); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1004 | |
| 1005 | // Check that if the web iframe navigates itself to about:blank, it stays in |
| 1006 | // the web SiteInstance. |
| 1007 | std::string about_blank_javascript = "location.href='about:blank';"; |
| 1008 | |
| 1009 | content::TestNavigationManager web_about_blank_manager(main_web_contents(), |
| 1010 | about_blank_url); |
| 1011 | |
| 1012 | ASSERT_TRUE(content::ExecuteScript(web_frame_rfh, about_blank_javascript)); |
| 1013 | |
| 1014 | web_about_blank_manager.WaitForNavigationFinished(); |
| 1015 | |
| 1016 | EXPECT_EQ(about_blank_url, web_frame_rfh->GetLastCommittedURL()); |
| 1017 | EXPECT_EQ(web_url.host(), |
| 1018 | web_frame_rfh->GetSiteInstance()->GetSiteURL().host()); |
| 1019 | EXPECT_NE(devtools_instance, web_frame_rfh->GetSiteInstance()); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1020 | EXPECT_NE(extensions_instance, web_frame_rfh->GetSiteInstance()); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1021 | |
| 1022 | // Check that if the web IFrame is navigated back to a devtools extension |
| 1023 | // page, it gets put back in the devtools process. |
| 1024 | GURL extension_simple_url = |
| 1025 | extension->GetResourceURL("/simple_test_page.html"); |
| 1026 | std::string renavigation_javascript = |
| 1027 | "location.href='" + extension_simple_url.spec() + "';"; |
| 1028 | |
| 1029 | content::TestNavigationManager renavigation_manager(main_web_contents(), |
| 1030 | extension_simple_url); |
| 1031 | |
| 1032 | ASSERT_TRUE(content::ExecuteScript(web_frame_rfh, renavigation_javascript)); |
| 1033 | |
| 1034 | renavigation_manager.WaitForNavigationFinished(); |
| 1035 | |
| 1036 | // The old RFH is no longer valid after the renavigation, so we must get the |
| 1037 | // new one. |
| 1038 | RenderFrameHost* extension_simple_frame_rfh = |
| 1039 | ChildFrameAt(panel_frame_rfh, 2); |
| 1040 | |
| 1041 | EXPECT_EQ(extension_simple_url, |
| 1042 | extension_simple_frame_rfh->GetLastCommittedURL()); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1043 | EXPECT_EQ(extensions_instance, extension_simple_frame_rfh->GetSiteInstance()); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | // Tests that http Iframes within the sidebar pane page for the devtools |
| 1047 | // extension that is visible in the elements panel are rendered in their own |
| 1048 | // processes and not in the devtools process or the extension's process. This |
| 1049 | // is tested because this is one of the extension pages with devtools access |
| 1050 | // (https://developer.chrome.com/extensions/devtools). http://crbug.com/570483 |
| 1051 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 1052 | HttpIframeInDevToolsExtensionSideBarPane) { |
| 1053 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1054 | |
| 1055 | GURL web_url = embedded_test_server()->GetURL("a.com", "/title3.html"); |
| 1056 | |
| 1057 | // Install the dynamically-generated extension. |
| 1058 | const Extension* extension = LoadExtensionForTest( |
| 1059 | "Devtools Extension", "sidebarpane_devtools_page.html", web_url.spec()); |
| 1060 | ASSERT_TRUE(extension); |
| 1061 | |
| 1062 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 1063 | |
| 1064 | // Wait for the extension's sidebarpane to finish loading -- it'll output |
| 1065 | // 'PASS' when it's installed. waitForTestResultsInConsole waits until that |
| 1066 | // 'PASS'. |
| 1067 | RunTestFunction(window_, "waitForTestResultsInConsole"); |
| 1068 | |
| 1069 | // Now that we know the sidebarpane is loaded, switch to it. |
| 1070 | content::TestNavigationManager web_manager(main_web_contents(), web_url); |
| 1071 | SwitchToPanel(window_, "elements"); |
| 1072 | // This is a bit of a hack to switch to the sidebar pane in the elements panel |
| 1073 | // that the Iframe has been added to. |
| 1074 | SwitchToPanel(window_, "iframe_pane"); |
| 1075 | web_manager.WaitForNavigationFinished(); |
| 1076 | |
| 1077 | std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); |
| 1078 | EXPECT_EQ(4U, rfhs.size()); |
| 1079 | |
| 1080 | RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); |
| 1081 | RenderFrameHost* devtools_extension_devtools_page_rfh = |
| 1082 | ChildFrameAt(main_devtools_rfh, 0); |
| 1083 | RenderFrameHost* devtools_sidebar_pane_extension_rfh = |
| 1084 | ChildFrameAt(main_devtools_rfh, 1); |
| 1085 | RenderFrameHost* http_iframe_rfh = |
| 1086 | ChildFrameAt(devtools_sidebar_pane_extension_rfh, 0); |
| 1087 | |
| 1088 | EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( |
| 1089 | content::kChromeDevToolsScheme)); |
| 1090 | EXPECT_EQ(extension->GetResourceURL("/sidebarpane_devtools_page.html"), |
| 1091 | devtools_extension_devtools_page_rfh->GetLastCommittedURL()); |
| 1092 | EXPECT_EQ(extension->GetResourceURL("/panel.html"), |
| 1093 | devtools_sidebar_pane_extension_rfh->GetLastCommittedURL()); |
| 1094 | EXPECT_EQ(web_url, http_iframe_rfh->GetLastCommittedURL()); |
| 1095 | |
| 1096 | content::SiteInstance* devtools_instance = |
| 1097 | main_devtools_rfh->GetSiteInstance(); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1098 | content::SiteInstance* extensions_instance = |
| 1099 | devtools_extension_devtools_page_rfh->GetSiteInstance(); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1100 | EXPECT_TRUE( |
| 1101 | devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1102 | EXPECT_NE(devtools_instance, extensions_instance); |
| 1103 | EXPECT_EQ(extensions_instance, |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1104 | devtools_extension_devtools_page_rfh->GetSiteInstance()); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1105 | EXPECT_EQ(extensions_instance, |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1106 | devtools_sidebar_pane_extension_rfh->GetSiteInstance()); |
| 1107 | EXPECT_EQ(web_url.host(), |
| 1108 | http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); |
| 1109 | EXPECT_NE(devtools_instance, http_iframe_rfh->GetSiteInstance()); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1110 | EXPECT_NE(extensions_instance, http_iframe_rfh->GetSiteInstance()); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | // Tests that http Iframes within the devtools background page, which is |
| 1114 | // different from the extension's background page, are rendered in their own |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1115 | // processes and not in the devtools process or the extension's process. |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1116 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 1117 | HttpIframeInDevToolsExtensionDevtools) { |
| 1118 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1119 | |
| 1120 | // Install the dynamically-generated extension. |
| 1121 | const Extension* extension = |
| 1122 | LoadExtensionForTest("Devtools Extension", "web_devtools_page.html", |
| 1123 | "" /* panel_iframe_src */); |
| 1124 | ASSERT_TRUE(extension); |
| 1125 | |
| 1126 | // Wait for a 'DONE' message sent from popup_iframe.html, indicating that it |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 1127 | // loaded successfully. |
| 1128 | content::DOMMessageQueue message_queue; |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 1129 | std::string message; |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1130 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 1131 | |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 1132 | while (true) { |
| 1133 | ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 1134 | if (message == "\"DONE\"") |
| 1135 | break; |
| 1136 | } |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1137 | |
| 1138 | std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); |
| 1139 | EXPECT_EQ(3U, rfhs.size()); |
| 1140 | |
| 1141 | RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); |
| 1142 | RenderFrameHost* devtools_extension_devtools_page_rfh = |
| 1143 | ChildFrameAt(main_devtools_rfh, 0); |
| 1144 | RenderFrameHost* http_iframe_rfh = |
| 1145 | ChildFrameAt(devtools_extension_devtools_page_rfh, 0); |
| 1146 | |
| 1147 | GURL web_url = embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); |
| 1148 | |
| 1149 | EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( |
| 1150 | content::kChromeDevToolsScheme)); |
| 1151 | EXPECT_EQ(extension->GetResourceURL("/web_devtools_page.html"), |
| 1152 | devtools_extension_devtools_page_rfh->GetLastCommittedURL()); |
| 1153 | EXPECT_EQ(web_url, http_iframe_rfh->GetLastCommittedURL()); |
| 1154 | |
| 1155 | content::SiteInstance* devtools_instance = |
| 1156 | main_devtools_rfh->GetSiteInstance(); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1157 | content::SiteInstance* extensions_instance = |
| 1158 | devtools_extension_devtools_page_rfh->GetSiteInstance(); |
| 1159 | |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1160 | EXPECT_TRUE( |
| 1161 | devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1162 | EXPECT_NE(devtools_instance, extensions_instance); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1163 | EXPECT_EQ(web_url.host(), |
| 1164 | http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); |
| 1165 | EXPECT_NE(devtools_instance, http_iframe_rfh->GetSiteInstance()); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1166 | EXPECT_NE(extensions_instance, http_iframe_rfh->GetSiteInstance()); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | // Tests that iframes to a non-devtools extension embedded in a devtools |
| 1170 | // extension will be isolated from devtools and the devtools extension. |
| 1171 | // http://crbug.com/570483 |
| 1172 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 1173 | NonDevToolsExtensionInDevToolsExtension) { |
| 1174 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1175 | |
| 1176 | // Install the dynamically-generated non-devtools extension. |
| 1177 | const Extension* non_devtools_extension = |
| 1178 | LoadExtensionForTest("Non-DevTools Extension", "" /* devtools_page */, |
| 1179 | "" /* panel_iframe_src */); |
| 1180 | ASSERT_TRUE(non_devtools_extension); |
| 1181 | |
| 1182 | GURL non_dt_extension_test_url = |
| 1183 | non_devtools_extension->GetResourceURL("/simple_test_page.html"); |
| 1184 | |
| 1185 | // Install the dynamically-generated devtools extension. |
| 1186 | const Extension* devtools_extension = |
| 1187 | LoadExtensionForTest("Devtools Extension", "panel_devtools_page.html", |
| 1188 | non_dt_extension_test_url.spec()); |
| 1189 | ASSERT_TRUE(devtools_extension); |
| 1190 | |
| 1191 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 1192 | |
| 1193 | // Wait for the extension's panel to finish loading -- it'll output 'PASS' |
| 1194 | // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. |
| 1195 | RunTestFunction(window_, "waitForTestResultsInConsole"); |
| 1196 | |
| 1197 | // Now that we know the panel is loaded, switch to it. |
| 1198 | content::TestNavigationManager non_devtools_manager( |
| 1199 | main_web_contents(), non_dt_extension_test_url); |
| 1200 | SwitchToExtensionPanel(window_, devtools_extension, "iframe_panel"); |
| 1201 | non_devtools_manager.WaitForNavigationFinished(); |
| 1202 | |
| 1203 | std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); |
| 1204 | EXPECT_EQ(4U, rfhs.size()); |
| 1205 | |
| 1206 | RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); |
| 1207 | RenderFrameHost* devtools_extension_devtools_page_rfh = |
| 1208 | ChildFrameAt(main_devtools_rfh, 0); |
| 1209 | RenderFrameHost* devtools_extension_panel_rfh = |
| 1210 | ChildFrameAt(main_devtools_rfh, 1); |
| 1211 | RenderFrameHost* non_devtools_extension_rfh = |
| 1212 | ChildFrameAt(devtools_extension_panel_rfh, 0); |
| 1213 | |
| 1214 | EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( |
| 1215 | content::kChromeDevToolsScheme)); |
| 1216 | EXPECT_EQ(devtools_extension->GetResourceURL("/panel_devtools_page.html"), |
| 1217 | devtools_extension_devtools_page_rfh->GetLastCommittedURL()); |
| 1218 | EXPECT_EQ(devtools_extension->GetResourceURL("/panel.html"), |
| 1219 | devtools_extension_panel_rfh->GetLastCommittedURL()); |
| 1220 | EXPECT_EQ(non_dt_extension_test_url, |
| 1221 | non_devtools_extension_rfh->GetLastCommittedURL()); |
| 1222 | |
| 1223 | // simple_test_page.html's frame should be in |non_devtools_extension|'s |
| 1224 | // process, not in devtools or |devtools_extension|'s process. |
| 1225 | content::SiteInstance* devtools_instance = |
| 1226 | main_devtools_rfh->GetSiteInstance(); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1227 | content::SiteInstance* extensions_instance = |
| 1228 | devtools_extension_devtools_page_rfh->GetSiteInstance(); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1229 | EXPECT_TRUE( |
| 1230 | devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1231 | EXPECT_NE(devtools_instance, extensions_instance); |
| 1232 | EXPECT_EQ(extensions_instance, |
| 1233 | devtools_extension_panel_rfh->GetSiteInstance()); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1234 | EXPECT_EQ(non_dt_extension_test_url.GetOrigin(), |
| 1235 | non_devtools_extension_rfh->GetSiteInstance()->GetSiteURL()); |
| 1236 | EXPECT_NE(devtools_instance, non_devtools_extension_rfh->GetSiteInstance()); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1237 | EXPECT_NE(extensions_instance, non_devtools_extension_rfh->GetSiteInstance()); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | // Tests that if a devtools extension's devtools panel page has a subframe to a |
| 1241 | // page for another devtools extension, the subframe is rendered in the devtools |
| 1242 | // process as well. http://crbug.com/570483 |
| 1243 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 1244 | DevToolsExtensionInDevToolsExtension) { |
| 1245 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1246 | |
| 1247 | // Install the dynamically-generated extension. |
| 1248 | const Extension* devtools_b_extension = |
| 1249 | LoadExtensionForTest("Devtools Extension B", "simple_devtools_page.html", |
| 1250 | "" /* panel_iframe_src */); |
| 1251 | ASSERT_TRUE(devtools_b_extension); |
| 1252 | |
| 1253 | GURL extension_b_page_url = |
| 1254 | devtools_b_extension->GetResourceURL("/simple_test_page.html"); |
| 1255 | |
| 1256 | // Install another dynamically-generated extension. This extension's |
| 1257 | // panel.html's iframe will point to an extension b URL. |
| 1258 | const Extension* devtools_a_extension = |
| 1259 | LoadExtensionForTest("Devtools Extension A", "panel_devtools_page.html", |
| 1260 | extension_b_page_url.spec()); |
| 1261 | ASSERT_TRUE(devtools_a_extension); |
| 1262 | |
| 1263 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 1264 | |
| 1265 | // Wait for the extension's panel to finish loading -- it'll output 'PASS' |
| 1266 | // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. |
| 1267 | RunTestFunction(window_, "waitForTestResultsInConsole"); |
| 1268 | |
| 1269 | // Now that we know the panel is loaded, switch to it. |
| 1270 | content::TestNavigationManager extension_b_manager(main_web_contents(), |
| 1271 | extension_b_page_url); |
| 1272 | SwitchToExtensionPanel(window_, devtools_a_extension, "iframe_panel"); |
| 1273 | extension_b_manager.WaitForNavigationFinished(); |
| 1274 | |
| 1275 | std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); |
| 1276 | EXPECT_EQ(5U, rfhs.size()); |
| 1277 | |
| 1278 | RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); |
| 1279 | |
| 1280 | RenderFrameHost* devtools_extension_a_devtools_rfh = |
| 1281 | content::FrameMatchingPredicate( |
| 1282 | main_web_contents(), base::Bind(&content::FrameHasSourceUrl, |
| 1283 | devtools_a_extension->GetResourceURL( |
| 1284 | "/panel_devtools_page.html"))); |
| 1285 | EXPECT_TRUE(devtools_extension_a_devtools_rfh); |
| 1286 | RenderFrameHost* devtools_extension_b_devtools_rfh = |
| 1287 | content::FrameMatchingPredicate( |
| 1288 | main_web_contents(), base::Bind(&content::FrameHasSourceUrl, |
| 1289 | devtools_b_extension->GetResourceURL( |
| 1290 | "/simple_devtools_page.html"))); |
| 1291 | EXPECT_TRUE(devtools_extension_b_devtools_rfh); |
| 1292 | |
| 1293 | RenderFrameHost* devtools_extension_a_panel_rfh = |
| 1294 | ChildFrameAt(main_devtools_rfh, 2); |
| 1295 | RenderFrameHost* devtools_extension_b_frame_rfh = |
| 1296 | ChildFrameAt(devtools_extension_a_panel_rfh, 0); |
| 1297 | |
| 1298 | EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( |
| 1299 | content::kChromeDevToolsScheme)); |
| 1300 | EXPECT_EQ(devtools_a_extension->GetResourceURL("/panel_devtools_page.html"), |
| 1301 | devtools_extension_a_devtools_rfh->GetLastCommittedURL()); |
| 1302 | EXPECT_EQ(devtools_b_extension->GetResourceURL("/simple_devtools_page.html"), |
| 1303 | devtools_extension_b_devtools_rfh->GetLastCommittedURL()); |
| 1304 | EXPECT_EQ(devtools_a_extension->GetResourceURL("/panel.html"), |
| 1305 | devtools_extension_a_panel_rfh->GetLastCommittedURL()); |
| 1306 | EXPECT_EQ(extension_b_page_url, |
| 1307 | devtools_extension_b_frame_rfh->GetLastCommittedURL()); |
| 1308 | |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1309 | // Main extension frame should be loaded in the extensions process. Nested |
| 1310 | // iframes should be loaded consistently with any other extensions iframes |
| 1311 | // (in or out of process). |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1312 | content::SiteInstance* devtools_instance = |
| 1313 | main_devtools_rfh->GetSiteInstance(); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1314 | content::SiteInstance* extension_a_instance = |
| 1315 | devtools_extension_a_devtools_rfh->GetSiteInstance(); |
| 1316 | content::SiteInstance* extension_b_instance = |
| 1317 | devtools_extension_b_devtools_rfh->GetSiteInstance(); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1318 | EXPECT_TRUE( |
| 1319 | devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1320 | EXPECT_NE(devtools_instance, extension_a_instance); |
| 1321 | EXPECT_NE(devtools_instance, extension_b_instance); |
| 1322 | EXPECT_NE(extension_a_instance, extension_b_instance); |
| 1323 | EXPECT_EQ(extension_a_instance, |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1324 | devtools_extension_a_panel_rfh->GetSiteInstance()); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1325 | EXPECT_EQ(extension_b_instance, |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1326 | devtools_extension_b_frame_rfh->GetSiteInstance()); |
| 1327 | } |
| 1328 | |
| 1329 | // Tests that a devtools extension can still have subframes to itself in a |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1330 | // "devtools page" and that they will be rendered within the extension process |
| 1331 | // as well, not in some other process. |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1332 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionInItself) { |
| 1333 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1334 | |
| 1335 | // Install the dynamically-generated extension. |
| 1336 | const Extension* extension = |
| 1337 | LoadExtensionForTest("Devtools Extension", "panel_devtools_page.html", |
| 1338 | "/simple_test_page.html"); |
| 1339 | ASSERT_TRUE(extension); |
| 1340 | |
| 1341 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 1342 | |
| 1343 | // Wait for the extension's panel to finish loading -- it'll output 'PASS' |
| 1344 | // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. |
| 1345 | RunTestFunction(window_, "waitForTestResultsInConsole"); |
| 1346 | |
| 1347 | // Now that we know the panel is loaded, switch to it. |
| 1348 | GURL extension_test_url = extension->GetResourceURL("/simple_test_page.html"); |
| 1349 | content::TestNavigationManager test_page_manager(main_web_contents(), |
| 1350 | extension_test_url); |
| 1351 | SwitchToExtensionPanel(window_, extension, "iframe_panel"); |
| 1352 | test_page_manager.WaitForNavigationFinished(); |
| 1353 | |
| 1354 | std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); |
| 1355 | EXPECT_EQ(4U, rfhs.size()); |
| 1356 | |
| 1357 | RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); |
| 1358 | RenderFrameHost* devtools_extension_devtools_page_rfh = |
| 1359 | ChildFrameAt(main_devtools_rfh, 0); |
| 1360 | RenderFrameHost* devtools_extension_panel_rfh = |
| 1361 | ChildFrameAt(main_devtools_rfh, 1); |
| 1362 | RenderFrameHost* devtools_extension_panel_frame_rfh = |
| 1363 | ChildFrameAt(devtools_extension_panel_rfh, 0); |
| 1364 | |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1365 | // Extension frames should be in the extensions process, including |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1366 | // simple_test_page.html |
| 1367 | EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( |
| 1368 | content::kChromeDevToolsScheme)); |
| 1369 | EXPECT_EQ(extension->GetResourceURL("/panel_devtools_page.html"), |
| 1370 | devtools_extension_devtools_page_rfh->GetLastCommittedURL()); |
| 1371 | EXPECT_EQ(extension->GetResourceURL("/panel.html"), |
| 1372 | devtools_extension_panel_rfh->GetLastCommittedURL()); |
| 1373 | EXPECT_EQ(extension_test_url, |
| 1374 | devtools_extension_panel_frame_rfh->GetLastCommittedURL()); |
| 1375 | |
| 1376 | content::SiteInstance* devtools_instance = |
| 1377 | main_devtools_rfh->GetSiteInstance(); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1378 | content::SiteInstance* extensions_instance = |
| 1379 | devtools_extension_devtools_page_rfh->GetSiteInstance(); |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1380 | EXPECT_TRUE( |
| 1381 | devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); |
Pavel Feldman | 28010fcf | 2017-06-15 19:21:17 | [diff] [blame] | 1382 | EXPECT_EQ(extensions_instance, |
| 1383 | devtools_extension_panel_rfh->GetSiteInstance()); |
| 1384 | EXPECT_EQ(extensions_instance, |
davidsac | 88a1aa7 | 2017-03-30 21:10:41 | [diff] [blame] | 1385 | devtools_extension_panel_frame_rfh->GetSiteInstance()); |
| 1386 | } |
| 1387 | |
| 1388 | // Tests that a devtools (not a devtools extension) Iframe can be injected into |
| 1389 | // devtools. http://crbug.com/570483 |
| 1390 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DevtoolsInDevTools) { |
| 1391 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1392 | |
| 1393 | GURL devtools_url = GURL(chrome::kChromeUIDevToolsURL); |
| 1394 | |
| 1395 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 1396 | |
| 1397 | std::string javascript = |
| 1398 | "var devtoolsFrame = document.createElement('iframe');" |
| 1399 | "document.body.appendChild(devtoolsFrame);" |
| 1400 | "devtoolsFrame.src = '" + |
| 1401 | devtools_url.spec() + "';"; |
| 1402 | |
| 1403 | RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); |
| 1404 | |
| 1405 | content::TestNavigationManager manager(main_web_contents(), devtools_url); |
| 1406 | ASSERT_TRUE(content::ExecuteScript(main_devtools_rfh, javascript)); |
| 1407 | manager.WaitForNavigationFinished(); |
| 1408 | |
| 1409 | std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); |
| 1410 | EXPECT_EQ(2U, rfhs.size()); |
| 1411 | RenderFrameHost* devtools_iframe_rfh = ChildFrameAt(main_devtools_rfh, 0); |
| 1412 | EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( |
| 1413 | content::kChromeDevToolsScheme)); |
| 1414 | EXPECT_EQ(devtools_url, devtools_iframe_rfh->GetLastCommittedURL()); |
| 1415 | content::SiteInstance* devtools_instance = |
| 1416 | main_devtools_rfh->GetSiteInstance(); |
| 1417 | EXPECT_TRUE( |
| 1418 | devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); |
| 1419 | EXPECT_EQ(devtools_instance, devtools_iframe_rfh->GetSiteInstance()); |
| 1420 | |
| 1421 | std::string message; |
| 1422 | EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1423 | devtools_iframe_rfh, "domAutomationController.send(document.origin)", |
| 1424 | &message)); |
| 1425 | EXPECT_EQ(devtools_url.GetOrigin().spec(), message + "/"); |
nick | 32e53c15 | 2015-12-17 19:48:54 | [diff] [blame] | 1426 | } |
| 1427 | |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 1428 | // Some web features, when used from an extension, are subject to browser-side |
| 1429 | // security policy enforcement. Make sure they work properly from inside a |
| 1430 | // devtools extension. |
| 1431 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 1432 | DevToolsExtensionSecurityPolicyGrants) { |
| 1433 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1434 | |
| 1435 | std::unique_ptr<extensions::TestExtensionDir> dir( |
| 1436 | new extensions::TestExtensionDir()); |
| 1437 | |
| 1438 | extensions::DictionaryBuilder manifest; |
| 1439 | dir->WriteManifest(extensions::DictionaryBuilder() |
| 1440 | .Set("name", "Devtools Panel") |
| 1441 | .Set("version", "1") |
mkwst | e82aced1 | 2016-11-30 08:25:01 | [diff] [blame] | 1442 | // Whitelist the script we stuff into the 'blob:' URL: |
| 1443 | .Set("content_security_policy", |
| 1444 | "script-src 'self' " |
Lukasz Anforowicz | 0419fb8 | 2017-08-24 19:19:34 | [diff] [blame] | 1445 | "'sha256-uv9gxBEOFchPzak3TK6O39RdKxJeZvfha9zOHGam" |
| 1446 | "TB4='; " |
mkwst | e82aced1 | 2016-11-30 08:25:01 | [diff] [blame] | 1447 | "object-src 'none'") |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 1448 | .Set("manifest_version", 2) |
| 1449 | .Set("devtools_page", "devtools.html") |
| 1450 | .ToJSON()); |
| 1451 | |
| 1452 | dir->WriteFile( |
| 1453 | FILE_PATH_LITERAL("devtools.html"), |
| 1454 | "<html><head><script src='devtools.js'></script></head></html>"); |
| 1455 | |
| 1456 | dir->WriteFile( |
| 1457 | FILE_PATH_LITERAL("devtools.js"), |
| 1458 | "chrome.devtools.panels.create('the_panel_name',\n" |
| 1459 | " null,\n" |
| 1460 | " 'panel.html',\n" |
| 1461 | " function(panel) {\n" |
| 1462 | " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n" |
| 1463 | " }\n" |
| 1464 | ");\n"); |
| 1465 | |
| 1466 | dir->WriteFile(FILE_PATH_LITERAL("panel.html"), |
| 1467 | "<html><body>A panel." |
| 1468 | "<script src='blob_xhr.js'></script>" |
nick | 01a85bdd | 2016-10-27 20:17:12 | [diff] [blame] | 1469 | "<script src='blob_iframe.js'></script>" |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 1470 | "</body></html>"); |
| 1471 | // Creating blobs from chrome-extension:// origins is only permitted if the |
| 1472 | // process has been granted permission to commit 'chrome-extension' schemes. |
| 1473 | dir->WriteFile( |
| 1474 | FILE_PATH_LITERAL("blob_xhr.js"), |
nick | 01a85bdd | 2016-10-27 20:17:12 | [diff] [blame] | 1475 | "var blob_url = URL.createObjectURL(new Blob(['xhr blob contents']));\n" |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 1476 | "var xhr = new XMLHttpRequest();\n" |
| 1477 | "xhr.open('GET', blob_url, true);\n" |
| 1478 | "xhr.onload = function (e) {\n" |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 1479 | " domAutomationController.send(xhr.response);\n" |
| 1480 | "};\n" |
| 1481 | "xhr.send(null);\n"); |
nick | 01a85bdd | 2016-10-27 20:17:12 | [diff] [blame] | 1482 | dir->WriteFile( |
| 1483 | FILE_PATH_LITERAL("blob_iframe.js"), |
| 1484 | "var payload = `" |
| 1485 | "<html><body>iframe blob contents" |
| 1486 | "<script>" |
nick | 01a85bdd | 2016-10-27 20:17:12 | [diff] [blame] | 1487 | " domAutomationController.send(document.body.innerText);\n" |
| 1488 | "</script></body></html>" |
| 1489 | "`;" |
| 1490 | "document.body.appendChild(document.createElement('iframe')).src =" |
| 1491 | " URL.createObjectURL(new Blob([payload], {type: 'text/html'}));"); |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 1492 | // Install the extension. |
| 1493 | const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); |
| 1494 | ASSERT_TRUE(extension); |
| 1495 | |
| 1496 | // Open a devtools window. |
| 1497 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 1498 | |
| 1499 | // Wait for the panel extension to finish loading -- it'll output 'PASS' |
| 1500 | // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. |
| 1501 | RunTestFunction(window_, "waitForTestResultsInConsole"); |
| 1502 | |
| 1503 | // Now that we know the panel is loaded, switch to it. We'll wait until we |
| 1504 | // see a 'DONE' message sent from popup_iframe.html, indicating that it |
| 1505 | // loaded successfully. |
| 1506 | content::DOMMessageQueue message_queue; |
| 1507 | SwitchToExtensionPanel(window_, extension, "the_panel_name"); |
| 1508 | std::string message; |
| 1509 | while (true) { |
| 1510 | ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
nick | 01a85bdd | 2016-10-27 20:17:12 | [diff] [blame] | 1511 | if (message == "\"xhr blob contents\"") |
| 1512 | break; |
| 1513 | } |
| 1514 | while (true) { |
| 1515 | ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 1516 | if (message == "\"iframe blob contents\"") |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 1517 | break; |
| 1518 | } |
| 1519 | } |
| 1520 | |
[email protected] | 43466b9 | 2013-12-27 22:00:11 | [diff] [blame] | 1521 | // Disabled on Windows due to flakiness. http://crbug.com/183649 |
| 1522 | #if defined(OS_WIN) |
[email protected] | 4319aa30 | 2013-06-12 19:59:45 | [diff] [blame] | 1523 | #define MAYBE_TestDevToolsExtensionMessaging DISABLED_TestDevToolsExtensionMessaging |
| 1524 | #else |
| 1525 | #define MAYBE_TestDevToolsExtensionMessaging TestDevToolsExtensionMessaging |
| 1526 | #endif |
| 1527 | |
[email protected] | 6dcc943 | 2012-02-28 12:59:37 | [diff] [blame] | 1528 | // Tests that chrome.devtools extension can communicate with background page |
| 1529 | // using extension messaging. |
| 1530 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
[email protected] | 4319aa30 | 2013-06-12 19:59:45 | [diff] [blame] | 1531 | MAYBE_TestDevToolsExtensionMessaging) { |
[email protected] | 6dcc943 | 2012-02-28 12:59:37 | [diff] [blame] | 1532 | LoadExtension("devtools_messaging"); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1533 | RunTest("waitForTestResultsInConsole", std::string()); |
[email protected] | 6dcc943 | 2012-02-28 12:59:37 | [diff] [blame] | 1534 | } |
| 1535 | |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 1536 | // Tests that chrome.experimental.devtools extension is correctly exposed |
| 1537 | // when the extension has experimental permission. |
| 1538 | IN_PROC_BROWSER_TEST_F(DevToolsExperimentalExtensionTest, |
| 1539 | TestDevToolsExperimentalExtensionAPI) { |
| 1540 | LoadExtension("devtools_experimental"); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1541 | RunTest("waitForTestResultsInConsole", std::string()); |
[email protected] | e89c05a | 2011-12-26 08:51:57 | [diff] [blame] | 1542 | } |
| 1543 | |
[email protected] | 92094f31 | 2013-11-12 18:09:26 | [diff] [blame] | 1544 | // Tests that a content script is in the scripts list. |
[email protected] | 92094f31 | 2013-11-12 18:09:26 | [diff] [blame] | 1545 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
[email protected] | 2565b87 | 2014-08-01 11:57:52 | [diff] [blame] | 1546 | TestContentScriptIsPresent) { |
[email protected] | 2c7b4d7 | 2009-10-21 07:17:17 | [diff] [blame] | 1547 | LoadExtension("simple_content_script"); |
| 1548 | RunTest("testContentScriptIsPresent", kPageWithContentScript); |
| 1549 | } |
| 1550 | |
lushnikov | 6d00792 | 2016-08-31 02:59:44 | [diff] [blame] | 1551 | // Tests that console selector shows correct context names. |
| 1552 | IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 1553 | TestConsoleContextNames) { |
| 1554 | LoadExtension("simple_content_script"); |
| 1555 | RunTest("testConsoleContextNames", kPageWithContentScript); |
| 1556 | } |
| 1557 | |
[email protected] | f099ba3 | 2009-09-18 13:43:17 | [diff] [blame] | 1558 | // Tests that scripts are not duplicated after Scripts Panel switch. |
| 1559 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, |
[email protected] | 2565b87 | 2014-08-01 11:57:52 | [diff] [blame] | 1560 | TestNoScriptDuplicatesOnPanelSwitch) { |
[email protected] | f099ba3 | 2009-09-18 13:43:17 | [diff] [blame] | 1561 | RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage); |
| 1562 | } |
| 1563 | |
[email protected] | 53976e8 | 2009-11-11 17:08:31 | [diff] [blame] | 1564 | // Tests that debugger works correctly if pause event occurs when DevTools |
| 1565 | // frontend is being loaded. |
[email protected] | e043c2a | 2011-12-02 00:08:17 | [diff] [blame] | 1566 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, |
mukai | 9f72da92 | 2015-03-14 01:54:54 | [diff] [blame] | 1567 | TestPauseWhenLoadingDevTools) { |
[email protected] | 53976e8 | 2009-11-11 17:08:31 | [diff] [blame] | 1568 | RunTest("testPauseWhenLoadingDevTools", kPauseWhenLoadingDevTools); |
| 1569 | } |
| 1570 | |
[email protected] | 28ce8eb | 2009-11-30 09:20:45 | [diff] [blame] | 1571 | // Tests that pressing 'Pause' will pause script execution if the script |
| 1572 | // is already running. |
sergeyv | b4eb247 | 2015-03-17 10:51:13 | [diff] [blame] | 1573 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) |
[email protected] | 5808fe1 | 2013-05-10 02:42:45 | [diff] [blame] | 1574 | // Timing out on linux ARM bot: https://crbug/238453 |
| 1575 | #define MAYBE_TestPauseWhenScriptIsRunning DISABLED_TestPauseWhenScriptIsRunning |
sergeyv | b4eb247 | 2015-03-17 10:51:13 | [diff] [blame] | 1576 | #else |
| 1577 | #define MAYBE_TestPauseWhenScriptIsRunning TestPauseWhenScriptIsRunning |
| 1578 | #endif |
[email protected] | 8128438 | 2013-10-21 23:08:54 | [diff] [blame] | 1579 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, |
sergeyv | b4eb247 | 2015-03-17 10:51:13 | [diff] [blame] | 1580 | MAYBE_TestPauseWhenScriptIsRunning) { |
[email protected] | 6303b28 | 2012-02-14 00:55:37 | [diff] [blame] | 1581 | RunTest("testPauseWhenScriptIsRunning", kPauseWhenScriptIsRunning); |
[email protected] | 28ce8eb | 2009-11-30 09:20:45 | [diff] [blame] | 1582 | } |
| 1583 | |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 1584 | // Tests network timing. |
[email protected] | 5c80747a1 | 2011-08-26 01:35:57 | [diff] [blame] | 1585 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkTiming) { |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 1586 | RunTest("testNetworkTiming", kSlowTestPage); |
| 1587 | } |
| 1588 | |
| 1589 | // Tests network size. |
oshima | 98205bc | 2015-06-19 19:52:42 | [diff] [blame] | 1590 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSize) { |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 1591 | RunTest("testNetworkSize", kChunkedTestPage); |
| 1592 | } |
| 1593 | |
| 1594 | // Tests raw headers text. |
[email protected] | 689a480 | 2012-10-12 15:12:22 | [diff] [blame] | 1595 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSyncSize) { |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 1596 | RunTest("testNetworkSyncSize", kChunkedTestPage); |
| 1597 | } |
| 1598 | |
| 1599 | // Tests raw headers text. |
oshima | 98205bc | 2015-06-19 19:52:42 | [diff] [blame] | 1600 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkRawHeadersText) { |
[email protected] | 74568b05 | 2011-05-20 09:36:14 | [diff] [blame] | 1601 | RunTest("testNetworkRawHeadersText", kChunkedTestPage); |
| 1602 | } |
| 1603 | |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 1604 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkPushTime) { |
| 1605 | OpenDevToolsWindow(kPushTestPage, false); |
| 1606 | GURL push_url = spawned_test_server()->GetURL(kPushTestResource); |
| 1607 | base::FilePath file_path = |
| 1608 | spawned_test_server()->document_root().AppendASCII(kPushTestResource); |
| 1609 | |
| 1610 | BrowserThread::PostTask( |
| 1611 | BrowserThread::IO, FROM_HERE, |
tzik | 93bf8a7 | 2017-04-24 18:53:30 | [diff] [blame] | 1612 | base::BindOnce(&TestInterceptor::Register, push_url, file_path)); |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 1613 | |
| 1614 | DispatchOnTestSuite(window_, "testPushTimes", push_url.spec().c_str()); |
| 1615 | |
tzik | 93bf8a7 | 2017-04-24 18:53:30 | [diff] [blame] | 1616 | BrowserThread::PostTask( |
| 1617 | BrowserThread::IO, FROM_HERE, |
| 1618 | base::BindOnce(&TestInterceptor::Unregister, push_url)); |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 1619 | |
| 1620 | CloseDevToolsWindow(); |
| 1621 | } |
| 1622 | |
Nathanael Alcock | 90cb98d | 2017-09-29 21:55:20 | [diff] [blame] | 1623 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDOMWarnings) { |
| 1624 | RunTest("testDOMWarnings", kDOMWarningsTestPage); |
| 1625 | } |
| 1626 | |
[email protected] | e344c39 | 2011-09-28 06:36:03 | [diff] [blame] | 1627 | // Tests that console messages are not duplicated on navigation back. |
oshima | 98205bc | 2015-06-19 19:52:42 | [diff] [blame] | 1628 | #if defined(OS_WIN) |
tim | 3c2889b | 2014-08-30 01:49:57 | [diff] [blame] | 1629 | // Flaking on windows swarm try runs: crbug.com/409285. |
| 1630 | #define MAYBE_TestConsoleOnNavigateBack DISABLED_TestConsoleOnNavigateBack |
| 1631 | #else |
| 1632 | #define MAYBE_TestConsoleOnNavigateBack TestConsoleOnNavigateBack |
| 1633 | #endif |
| 1634 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, MAYBE_TestConsoleOnNavigateBack) { |
[email protected] | e344c39 | 2011-09-28 06:36:03 | [diff] [blame] | 1635 | RunTest("testConsoleOnNavigateBack", kNavigateBackTestPage); |
| 1636 | } |
| 1637 | |
dgozman | 8388f06 | 2015-09-04 19:03:51 | [diff] [blame] | 1638 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDeviceEmulation) { |
[email protected] | 05401dc | 2014-05-13 20:08:42 | [diff] [blame] | 1639 | RunTest("testDeviceMetricsOverrides", "about:blank"); |
| 1640 | } |
| 1641 | |
dgozman | 204daf3 | 2016-07-13 03:51:01 | [diff] [blame] | 1642 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDispatchKeyEventDoesNotCrash) { |
| 1643 | RunTest("testDispatchKeyEventDoesNotCrash", "about:blank"); |
| 1644 | } |
| 1645 | |
Blaise | bcad00c | 2017-07-25 00:19:49 | [diff] [blame] | 1646 | class AutofillManagerTestDelegateDevtoolsImpl |
| 1647 | : public autofill::AutofillManagerTestDelegate { |
| 1648 | public: |
| 1649 | explicit AutofillManagerTestDelegateDevtoolsImpl( |
| 1650 | WebContents* inspectedContents) |
| 1651 | : inspected_contents_(inspectedContents) {} |
| 1652 | ~AutofillManagerTestDelegateDevtoolsImpl() override {} |
| 1653 | |
| 1654 | void DidPreviewFormData() override {} |
| 1655 | |
| 1656 | void DidFillFormData() override {} |
| 1657 | |
| 1658 | void DidShowSuggestions() override { |
| 1659 | ASSERT_TRUE(content::ExecuteScript(inspected_contents_, |
| 1660 | "console.log('didShowSuggestions');")); |
| 1661 | } |
| 1662 | |
| 1663 | void OnTextFieldChanged() override {} |
| 1664 | |
| 1665 | private: |
| 1666 | WebContents* inspected_contents_; |
| 1667 | |
| 1668 | DISALLOW_COPY_AND_ASSIGN(AutofillManagerTestDelegateDevtoolsImpl); |
| 1669 | }; |
| 1670 | |
| 1671 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDispatchKeyEventShowsAutoFill) { |
| 1672 | OpenDevToolsWindow(kDispatchKeyEventShowsAutoFill, false); |
| 1673 | |
| 1674 | autofill::ContentAutofillDriver* autofill_driver = |
| 1675 | autofill::ContentAutofillDriverFactory::FromWebContents(GetInspectedTab()) |
| 1676 | ->DriverForFrame(GetInspectedTab()->GetMainFrame()); |
| 1677 | autofill::AutofillManager* autofill_manager = |
| 1678 | autofill_driver->autofill_manager(); |
| 1679 | AutofillManagerTestDelegateDevtoolsImpl autoFillTestDelegate( |
| 1680 | GetInspectedTab()); |
| 1681 | autofill_manager->SetTestDelegate(&autoFillTestDelegate); |
| 1682 | |
| 1683 | RunTestFunction(window_, "testDispatchKeyEventShowsAutoFill"); |
| 1684 | CloseDevToolsWindow(); |
| 1685 | } |
| 1686 | |
dgozman | 0fced85f4 | 2015-06-10 15:06:03 | [diff] [blame] | 1687 | // Tests that settings are stored in profile correctly. |
| 1688 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestSettings) { |
| 1689 | OpenDevToolsWindow("about:blank", true); |
| 1690 | RunTestFunction(window_, "testSettings"); |
| 1691 | CloseDevToolsWindow(); |
| 1692 | } |
| 1693 | |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 1694 | // Tests that external navigation from inspector page is always handled by |
| 1695 | // DevToolsWindow and results in inspected page navigation. |
| 1696 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsExternalNavigation) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 1697 | OpenDevToolsWindow(kDebuggerTestPage, true); |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 1698 | GURL url = spawned_test_server()->GetURL(kNavigateBackTestPage); |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 1699 | ui_test_utils::UrlLoadObserver observer(url, |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 1700 | content::NotificationService::AllSources()); |
| 1701 | ASSERT_TRUE(content::ExecuteScript( |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 1702 | main_web_contents(), |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 1703 | std::string("window.location = \"") + url.spec() + "\"")); |
| 1704 | observer.Wait(); |
| 1705 | |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 1706 | ASSERT_TRUE(main_web_contents()->GetURL(). |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 1707 | SchemeIs(content::kChromeDevToolsScheme)); |
[email protected] | 9fc94c6d | 2014-02-12 14:48:48 | [diff] [blame] | 1708 | ASSERT_EQ(url, GetInspectedTab()->GetURL()); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 1709 | CloseDevToolsWindow(); |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 1710 | } |
| 1711 | |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 1712 | // Tests that toolbox window is loaded when DevTools window is undocked. |
suzyh | b6d0e27 | 2017-04-21 00:40:33 | [diff] [blame] | 1713 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxLoadedUndocked) { |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 1714 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 1715 | ASSERT_TRUE(toolbox_web_contents()); |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 1716 | DevToolsWindow* on_self = |
| 1717 | DevToolsWindowTesting::OpenDevToolsWindowSync(main_web_contents(), false); |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 1718 | ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents()); |
| 1719 | DevToolsWindowTesting::CloseDevToolsWindowSync(on_self); |
| 1720 | CloseDevToolsWindow(); |
| 1721 | } |
| 1722 | |
| 1723 | // Tests that toolbox window is not loaded when DevTools window is docked. |
| 1724 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxNotLoadedDocked) { |
| 1725 | OpenDevToolsWindow(kDebuggerTestPage, true); |
| 1726 | ASSERT_FALSE(toolbox_web_contents()); |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 1727 | DevToolsWindow* on_self = |
| 1728 | DevToolsWindowTesting::OpenDevToolsWindowSync(main_web_contents(), false); |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 1729 | ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents()); |
| 1730 | DevToolsWindowTesting::CloseDevToolsWindowSync(on_self); |
| 1731 | CloseDevToolsWindow(); |
| 1732 | } |
| 1733 | |
[email protected] | a88511b | 2011-11-09 06:53:07 | [diff] [blame] | 1734 | // Tests that inspector will reattach to inspected page when it is reloaded |
| 1735 | // after a crash. See http://crbug.com/101952 |
sergeyv | 27f196c | 2015-02-25 14:25:15 | [diff] [blame] | 1736 | // Disabled. it doesn't check anything right now: http://crbug.com/461790 |
| 1737 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_TestReattachAfterCrash) { |
[email protected] | ebb10bb | 2014-04-16 17:16:01 | [diff] [blame] | 1738 | RunTest("testReattachAfterCrash", std::string()); |
[email protected] | a88511b | 2011-11-09 06:53:07 | [diff] [blame] | 1739 | } |
| 1740 | |
[email protected] | 3766a36 | 2011-06-21 17:56:18 | [diff] [blame] | 1741 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) { |
[email protected] | b9c5d50b | 2014-01-16 20:37:43 | [diff] [blame] | 1742 | OpenDevToolsWindow("about:blank", false); |
[email protected] | 3766a36 | 2011-06-21 17:56:18 | [diff] [blame] | 1743 | std::string result; |
| 1744 | ASSERT_TRUE( |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 1745 | content::ExecuteScriptAndExtractString( |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 1746 | main_web_contents()->GetRenderViewHost(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 1747 | "window.domAutomationController.send(" |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 1748 | " '' + (window.uiTests && (typeof uiTests.dispatchOnTestSuite)));", |
[email protected] | 3766a36 | 2011-06-21 17:56:18 | [diff] [blame] | 1749 | &result)); |
| 1750 | ASSERT_EQ("function", result) << "DevTools front-end is broken."; |
| 1751 | CloseDevToolsWindow(); |
| 1752 | } |
| 1753 | |
dgozman | 54cc54e | 2016-02-23 03:47:30 | [diff] [blame] | 1754 | class DevToolsAutoOpenerTest : public DevToolsSanityTest { |
| 1755 | public: |
| 1756 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1757 | command_line->AppendSwitch(switches::kAutoOpenDevToolsForTabs); |
dgozman | 010f9e0e | 2016-02-24 21:25:53 | [diff] [blame] | 1758 | observer_.reset(new DevToolsWindowCreationObserver()); |
dgozman | 54cc54e | 2016-02-23 03:47:30 | [diff] [blame] | 1759 | } |
dgozman | 010f9e0e | 2016-02-24 21:25:53 | [diff] [blame] | 1760 | protected: |
dcheng | b8eac3a | 2016-04-13 02:03:23 | [diff] [blame] | 1761 | std::unique_ptr<DevToolsWindowCreationObserver> observer_; |
dgozman | 54cc54e | 2016-02-23 03:47:30 | [diff] [blame] | 1762 | }; |
| 1763 | |
| 1764 | IN_PROC_BROWSER_TEST_F(DevToolsAutoOpenerTest, TestAutoOpenForTabs) { |
| 1765 | { |
dgozman | 54cc54e | 2016-02-23 03:47:30 | [diff] [blame] | 1766 | DevToolsWindowCreationObserver observer; |
| 1767 | AddTabAtIndexToBrowser(browser(), 0, GURL("about:blank"), |
| 1768 | ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false); |
| 1769 | observer.WaitForLoad(); |
dgozman | 010f9e0e | 2016-02-24 21:25:53 | [diff] [blame] | 1770 | } |
| 1771 | Browser* new_browser = nullptr; |
| 1772 | { |
| 1773 | DevToolsWindowCreationObserver observer; |
| 1774 | new_browser = CreateBrowser(browser()->profile()); |
| 1775 | observer.WaitForLoad(); |
dgozman | 54cc54e | 2016-02-23 03:47:30 | [diff] [blame] | 1776 | } |
| 1777 | { |
| 1778 | DevToolsWindowCreationObserver observer; |
dgozman | 54cc54e | 2016-02-23 03:47:30 | [diff] [blame] | 1779 | AddTabAtIndexToBrowser(new_browser, 0, GURL("about:blank"), |
| 1780 | ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false); |
| 1781 | observer.WaitForLoad(); |
dgozman | 54cc54e | 2016-02-23 03:47:30 | [diff] [blame] | 1782 | } |
dgozman | 010f9e0e | 2016-02-24 21:25:53 | [diff] [blame] | 1783 | observer_->CloseAllSync(); |
dgozman | 54cc54e | 2016-02-23 03:47:30 | [diff] [blame] | 1784 | } |
| 1785 | |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 1786 | class DevToolsReattachAfterCrashTest : public DevToolsSanityTest { |
| 1787 | protected: |
| 1788 | void RunTestWithPanel(const char* panel_name) { |
| 1789 | OpenDevToolsWindow("about:blank", false); |
| 1790 | SwitchToPanel(window_, panel_name); |
| 1791 | ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
| 1792 | |
| 1793 | content::RenderProcessHostWatcher crash_observer( |
| 1794 | GetInspectedTab(), |
| 1795 | content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 1796 | ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL)); |
| 1797 | crash_observer.Wait(); |
| 1798 | content::TestNavigationObserver navigation_observer(GetInspectedTab(), 1); |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 1799 | chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
caseq | c1edde1a | 2015-09-29 00:17:07 | [diff] [blame] | 1800 | navigation_observer.Wait(); |
| 1801 | } |
| 1802 | }; |
| 1803 | |
| 1804 | IN_PROC_BROWSER_TEST_F(DevToolsReattachAfterCrashTest, |
| 1805 | TestReattachAfterCrashOnTimeline) { |
| 1806 | RunTestWithPanel("timeline"); |
| 1807 | } |
| 1808 | |
| 1809 | IN_PROC_BROWSER_TEST_F(DevToolsReattachAfterCrashTest, |
| 1810 | TestReattachAfterCrashOnNetwork) { |
| 1811 | RunTestWithPanel("network"); |
| 1812 | } |
| 1813 | |
dgozman | ab68041 | 2016-02-04 02:21:37 | [diff] [blame] | 1814 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, AutoAttachToWindowOpen) { |
| 1815 | OpenDevToolsWindow(kWindowOpenTestPage, false); |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 1816 | DevToolsWindowTesting::Get(window_)->SetOpenNewWindowForPopups(true); |
dgozman | ab68041 | 2016-02-04 02:21:37 | [diff] [blame] | 1817 | DevToolsWindowCreationObserver observer; |
| 1818 | ASSERT_TRUE(content::ExecuteScript( |
| 1819 | GetInspectedTab(), "window.open('window_open.html', '_blank');")); |
| 1820 | observer.WaitForLoad(); |
| 1821 | DispatchOnTestSuite(observer.devtools_window(), "waitForDebuggerPaused"); |
| 1822 | DevToolsWindowTesting::CloseDevToolsWindowSync(observer.devtools_window()); |
| 1823 | CloseDevToolsWindow(); |
| 1824 | } |
| 1825 | |
dgozman | 16fd697 | 2017-05-02 23:33:50 | [diff] [blame] | 1826 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, SecondTabAfterDevTools) { |
| 1827 | OpenDevToolsWindow(kDebuggerTestPage, true); |
| 1828 | |
| 1829 | ui_test_utils::NavigateToURLWithDisposition( |
| 1830 | browser(), spawned_test_server()->GetURL(kDebuggerTestPage), |
| 1831 | WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 1832 | ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
| 1833 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1834 | WebContents* second = browser()->tab_strip_model()->GetActiveWebContents(); |
| 1835 | |
| 1836 | scoped_refptr<content::DevToolsAgentHost> agent( |
| 1837 | content::DevToolsAgentHost::GetOrCreateFor(second)); |
| 1838 | EXPECT_EQ("page", agent->GetType()); |
| 1839 | |
| 1840 | CloseDevToolsWindow(); |
| 1841 | } |
| 1842 | |
sergeyv | b4eb247 | 2015-03-17 10:51:13 | [diff] [blame] | 1843 | IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, InspectSharedWorker) { |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 1844 | ASSERT_TRUE(spawned_test_server()->Start()); |
| 1845 | GURL url = spawned_test_server()->GetURL(kSharedWorkerTestPage); |
| 1846 | ui_test_utils::NavigateToURL(browser(), url); |
| 1847 | |
| 1848 | scoped_refptr<DevToolsAgentHost> host = |
| 1849 | WaitForFirstSharedWorker(kSharedWorkerTestWorker); |
| 1850 | OpenDevToolsWindow(host); |
| 1851 | RunTestFunction(window_, "testSharedWorker"); |
| 1852 | CloseDevToolsWindow(); |
[email protected] | 1fcef59 | 2011-07-20 07:16:36 | [diff] [blame] | 1853 | } |
| 1854 | |
Aleksey Kozyatinskiy | 3037914 | 2017-12-05 17:45:24 | [diff] [blame] | 1855 | // Flaky on multiple platforms. See http://crbug.com/432444 |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 1856 | IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, |
Alexey Kozyatinskiy | 478a686 | 2018-01-02 19:45:22 | [diff] [blame] | 1857 | PauseInSharedWorkerInitialization) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 1858 | ASSERT_TRUE(spawned_test_server()->Start()); |
| 1859 | GURL url = spawned_test_server()->GetURL(kReloadSharedWorkerTestPage); |
[email protected] | 9e1ee54c | 2012-03-12 17:47:13 | [diff] [blame] | 1860 | ui_test_utils::NavigateToURL(browser(), url); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 1861 | |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 1862 | scoped_refptr<DevToolsAgentHost> host = |
yurys | 48be075f | 2014-10-16 09:04:21 | [diff] [blame] | 1863 | WaitForFirstSharedWorker(kReloadSharedWorkerTestWorker); |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 1864 | OpenDevToolsWindow(host); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 1865 | |
vsevik | a985241 | 2014-10-29 14:20:50 | [diff] [blame] | 1866 | // We should make sure that the worker inspector has loaded before |
| 1867 | // terminating worker. |
| 1868 | RunTestFunction(window_, "testPauseInSharedWorkerInitialization1"); |
| 1869 | |
Dmitry Gozman | dc7f367 | 2017-11-20 15:52:46 | [diff] [blame] | 1870 | host->Close(); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 1871 | |
[email protected] | 9e1ee54c | 2012-03-12 17:47:13 | [diff] [blame] | 1872 | // Reload page to restart the worker. |
| 1873 | ui_test_utils::NavigateToURL(browser(), url); |
[email protected] | 867fd923 | 2011-10-17 06:32:34 | [diff] [blame] | 1874 | |
[email protected] | 9e1ee54c | 2012-03-12 17:47:13 | [diff] [blame] | 1875 | // Wait until worker script is paused on the debugger statement. |
vsevik | a985241 | 2014-10-29 14:20:50 | [diff] [blame] | 1876 | RunTestFunction(window_, "testPauseInSharedWorkerInitialization2"); |
[email protected] | 9e1ee54c | 2012-03-12 17:47:13 | [diff] [blame] | 1877 | CloseDevToolsWindow(); |
| 1878 | } |
| 1879 | |
[email protected] | a2dcc673 | 2013-03-14 13:28:08 | [diff] [blame] | 1880 | class DevToolsAgentHostTest : public InProcessBrowserTest {}; |
| 1881 | |
| 1882 | // Tests DevToolsAgentHost retention by its target. |
| 1883 | IN_PROC_BROWSER_TEST_F(DevToolsAgentHostTest, TestAgentHostReleased) { |
| 1884 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 1885 | WebContents* web_contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 1886 | DevToolsAgentHost* agent_raw = |
| 1887 | DevToolsAgentHost::GetOrCreateFor(web_contents).get(); |
[email protected] | a2dcc673 | 2013-03-14 13:28:08 | [diff] [blame] | 1888 | const std::string agent_id = agent_raw->GetId(); |
dcheng | f4b5657 | 2014-08-27 06:59:37 | [diff] [blame] | 1889 | ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id).get()) |
| 1890 | << "DevToolsAgentHost cannot be found by id"; |
[email protected] | a2dcc673 | 2013-03-14 13:28:08 | [diff] [blame] | 1891 | browser()->tab_strip_model()-> |
| 1892 | CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1893 | ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get()) |
| 1894 | << "DevToolsAgentHost is not released when the tab is closed"; |
[email protected] | a2dcc673 | 2013-03-14 13:28:08 | [diff] [blame] | 1895 | } |
| 1896 | |
vkuzkokov | 00700c3 | 2015-03-17 16:04:07 | [diff] [blame] | 1897 | class RemoteDebuggingTest : public ExtensionApiTest { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 1898 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 1899 | ExtensionApiTest::SetUpCommandLine(command_line); |
| 1900 | command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222"); |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 1901 | |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 1902 | // Override the extension root path. |
| 1903 | PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 1904 | test_data_dir_ = test_data_dir_.AppendASCII("devtools"); |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 1905 | } |
| 1906 | }; |
| 1907 | |
Nicolas Zea | 4c8a23e | 2014-11-07 20:50:16 | [diff] [blame] | 1908 | // Fails on CrOS. crbug.com/431399 |
| 1909 | #if defined(OS_CHROMEOS) |
| 1910 | #define MAYBE_RemoteDebugger DISABLED_RemoteDebugger |
| 1911 | #else |
| 1912 | #define MAYBE_RemoteDebugger RemoteDebugger |
| 1913 | #endif |
| 1914 | IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, MAYBE_RemoteDebugger) { |
[email protected] | 96590138 | 2013-04-03 07:38:39 | [diff] [blame] | 1915 | ASSERT_TRUE(RunExtensionTest("target_list")) << message_; |
[email protected] | ead05635 | 2013-03-12 08:47:54 | [diff] [blame] | 1916 | } |
peletskyi | 5ec60bf | 2015-03-12 09:53:18 | [diff] [blame] | 1917 | |
| 1918 | using DevToolsPolicyTest = InProcessBrowserTest; |
| 1919 | IN_PROC_BROWSER_TEST_F(DevToolsPolicyTest, PolicyTrue) { |
| 1920 | browser()->profile()->GetPrefs()->SetBoolean(prefs::kDevToolsDisabled, true); |
| 1921 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 1922 | content::WebContents* web_contents = |
| 1923 | browser()->tab_strip_model()->GetWebContentsAt(0); |
| 1924 | scoped_refptr<content::DevToolsAgentHost> agent( |
| 1925 | content::DevToolsAgentHost::GetOrCreateFor(web_contents)); |
| 1926 | DevToolsWindow::OpenDevToolsWindow(web_contents); |
| 1927 | DevToolsWindow* window = DevToolsWindow::FindDevToolsWindow(agent.get()); |
| 1928 | ASSERT_FALSE(window); |
| 1929 | } |
caseq | c5e16683 | 2015-07-10 07:40:47 | [diff] [blame] | 1930 | |
| 1931 | class DevToolsPixelOutputTests : public DevToolsSanityTest { |
| 1932 | public: |
| 1933 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1934 | command_line->AppendSwitch(switches::kEnablePixelOutputInTests); |
| 1935 | command_line->AppendSwitch(switches::kUseGpuInTests); |
| 1936 | } |
| 1937 | }; |
| 1938 | |
eugenis | 2580a335 | 2015-07-10 22:04:54 | [diff] [blame] | 1939 | // This test enables switches::kUseGpuInTests which causes false positives |
ccameron | 606eb38 | 2016-09-06 18:57:54 | [diff] [blame] | 1940 | // with MemorySanitizer. This is also flakey on many configurations. |
benwells | 0af03f9 | 2017-06-28 08:35:33 | [diff] [blame] | 1941 | // See https://crbug.com/510291 |
eugenis | 2580a335 | 2015-07-10 22:04:54 | [diff] [blame] | 1942 | IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests, |
benwells | 0af03f9 | 2017-06-28 08:35:33 | [diff] [blame] | 1943 | DISABLED_TestScreenshotRecording) { |
caseq | c5e16683 | 2015-07-10 07:40:47 | [diff] [blame] | 1944 | RunTest("testScreenshotRecording", std::string()); |
| 1945 | } |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 1946 | |
| 1947 | // This test enables switches::kUseGpuInTests which causes false positives |
| 1948 | // with MemorySanitizer. |
timloh | 0b9fe71 | 2017-04-04 05:23:53 | [diff] [blame] | 1949 | // Flaky on multiple platforms https://crbug.com/624215 |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 1950 | IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests, |
timloh | 0b9fe71 | 2017-04-04 05:23:53 | [diff] [blame] | 1951 | DISABLED_TestLatencyInfoInstrumentation) { |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 1952 | WebContents* web_contents = GetInspectedTab(); |
| 1953 | OpenDevToolsWindow(kLatencyInfoTestPage, false); |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 1954 | DispatchAndWait("startTimeline"); |
| 1955 | |
| 1956 | for (int i = 0; i < 3; ++i) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1957 | SimulateMouseEvent(web_contents, blink::WebInputEvent::kMouseMove, |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 1958 | gfx::Point(30, 60)); |
| 1959 | DispatchInPageAndWait("waitForEvent", "mousemove"); |
| 1960 | } |
| 1961 | |
nzolghadr | 656569e | 2016-08-19 16:53:00 | [diff] [blame] | 1962 | SimulateMouseClickAt(web_contents, 0, |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1963 | blink::WebPointerProperties::Button::kLeft, |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 1964 | gfx::Point(30, 60)); |
| 1965 | DispatchInPageAndWait("waitForEvent", "click"); |
| 1966 | |
| 1967 | SimulateMouseWheelEvent(web_contents, gfx::Point(300, 100), |
sahel | e2b952b | 2017-09-13 18:28:49 | [diff] [blame] | 1968 | gfx::Vector2d(0, 120), |
| 1969 | blink::WebMouseWheelEvent::kPhaseBegan); |
caseq | cfbb3faf | 2016-02-18 19:15:06 | [diff] [blame] | 1970 | DispatchInPageAndWait("waitForEvent", "wheel"); |
| 1971 | |
| 1972 | SimulateTapAt(web_contents, gfx::Point(30, 60)); |
| 1973 | DispatchInPageAndWait("waitForEvent", "gesturetap"); |
| 1974 | |
| 1975 | DispatchAndWait("stopTimeline"); |
| 1976 | RunTestMethod("checkInputEventsPresent", "MouseMove", "MouseDown", |
| 1977 | "MouseWheel", "GestureTap"); |
| 1978 | |
| 1979 | CloseDevToolsWindow(); |
| 1980 | } |
dgozman | 6ca18e3 | 2016-06-29 19:30:29 | [diff] [blame] | 1981 | |
| 1982 | class DevToolsNetInfoTest : public DevToolsSanityTest { |
| 1983 | protected: |
| 1984 | void SetUpCommandLine(base::CommandLine* command_line) override { |
Tarun Bansal | 1f332ebe | 2017-07-14 04:18:09 | [diff] [blame] | 1985 | command_line->AppendSwitch(switches::kEnableNetworkInformationDownlinkMax); |
dgozman | 6ca18e3 | 2016-06-29 19:30:29 | [diff] [blame] | 1986 | command_line->AppendSwitch( |
| 1987 | switches::kEnableExperimentalWebPlatformFeatures); |
| 1988 | } |
| 1989 | }; |
| 1990 | |
| 1991 | IN_PROC_BROWSER_TEST_F(DevToolsNetInfoTest, EmulateNetworkConditions) { |
| 1992 | RunTest("testEmulateNetworkConditions", kEmulateNetworkConditionsPage); |
| 1993 | } |
kozyatinskiy | 3ac9439 | 2016-07-14 00:07:47 | [diff] [blame] | 1994 | |
Will Chen | cc578c3 | 2017-08-08 01:58:37 | [diff] [blame] | 1995 | IN_PROC_BROWSER_TEST_F(DevToolsNetInfoTest, OfflineNetworkConditions) { |
| 1996 | RunTest("testOfflineNetworkConditions", kEmulateNetworkConditionsPage); |
| 1997 | } |
| 1998 | |
kozyatinskiy | 3ac9439 | 2016-07-14 00:07:47 | [diff] [blame] | 1999 | class StaticURLDataSource : public content::URLDataSource { |
| 2000 | public: |
| 2001 | StaticURLDataSource(const std::string& source, const std::string& content) |
| 2002 | : source_(source), content_(content) {} |
| 2003 | |
| 2004 | std::string GetSource() const override { return source_; } |
jam | edcd8b01 | 2016-09-20 02:03:58 | [diff] [blame] | 2005 | void StartDataRequest( |
| 2006 | const std::string& path, |
| 2007 | const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 2008 | const GotDataCallback& callback) override { |
kozyatinskiy | 3ac9439 | 2016-07-14 00:07:47 | [diff] [blame] | 2009 | std::string data(content_); |
| 2010 | callback.Run(base::RefCountedString::TakeString(&data)); |
| 2011 | } |
| 2012 | std::string GetMimeType(const std::string& path) const override { |
| 2013 | return "text/html"; |
| 2014 | } |
| 2015 | bool ShouldAddContentSecurityPolicy() const override { return false; } |
| 2016 | |
| 2017 | private: |
| 2018 | std::string source_; |
| 2019 | std::string content_; |
| 2020 | DISALLOW_COPY_AND_ASSIGN(StaticURLDataSource); |
| 2021 | }; |
| 2022 | |
| 2023 | class MockWebUIProvider |
| 2024 | : public TestChromeWebUIControllerFactory::WebUIProvider { |
| 2025 | public: |
| 2026 | MockWebUIProvider(const std::string& source, const std::string& content) |
| 2027 | : source_(source), content_(content) {} |
| 2028 | |
| 2029 | content::WebUIController* NewWebUI(content::WebUI* web_ui, |
| 2030 | const GURL& url) override { |
| 2031 | content::URLDataSource::Add(Profile::FromWebUI(web_ui), |
| 2032 | new StaticURLDataSource(source_, content_)); |
| 2033 | return new content::WebUIController(web_ui); |
| 2034 | } |
| 2035 | |
| 2036 | private: |
| 2037 | std::string source_; |
| 2038 | std::string content_; |
| 2039 | DISALLOW_COPY_AND_ASSIGN(MockWebUIProvider); |
| 2040 | }; |
| 2041 | |
| 2042 | // This tests checks that window is correctly initialized when DevTools is |
| 2043 | // opened while navigation through history with forward and back actions. |
| 2044 | // (crbug.com/627407) |
kozyatinskiy | 3ac9439 | 2016-07-14 00:07:47 | [diff] [blame] | 2045 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, |
Alexey Kozyatinskiy | 9b0d8b1 | 2018-01-03 17:30:04 | [diff] [blame] | 2046 | TestWindowInitializedOnNavigateBack) { |
kozyatinskiy | 3ac9439 | 2016-07-14 00:07:47 | [diff] [blame] | 2047 | TestChromeWebUIControllerFactory test_factory; |
| 2048 | MockWebUIProvider mock_provider("dummyurl", |
| 2049 | "<script>\n" |
| 2050 | " window.abc = 239;\n" |
| 2051 | " console.log(abc);\n" |
| 2052 | "</script>"); |
| 2053 | test_factory.AddFactoryOverride(GURL("chrome://dummyurl").host(), |
| 2054 | &mock_provider); |
| 2055 | content::WebUIControllerFactory::RegisterFactory(&test_factory); |
| 2056 | |
| 2057 | ui_test_utils::NavigateToURL(browser(), GURL("chrome://dummyurl")); |
| 2058 | DevToolsWindow* window = |
| 2059 | DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), true); |
| 2060 | chrome::DuplicateTab(browser()); |
| 2061 | chrome::SelectPreviousTab(browser()); |
| 2062 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 2063 | chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB); |
kozyatinskiy | 3ac9439 | 2016-07-14 00:07:47 | [diff] [blame] | 2064 | RunTestFunction(window, "testWindowInitializedOnNavigateBack"); |
| 2065 | |
| 2066 | DevToolsWindowTesting::CloseDevToolsWindowSync(window); |
| 2067 | content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); |
| 2068 | } |
Andrey Kosyakov | 2e893e6 | 2017-08-31 17:00:52 | [diff] [blame] | 2069 | |
| 2070 | void AddHSTSHost(scoped_refptr<net::URLRequestContextGetter> context, |
| 2071 | std::string host) { |
| 2072 | net::TransportSecurityState* transport_security_state = |
| 2073 | context->GetURLRequestContext()->transport_security_state(); |
| 2074 | base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
| 2075 | bool include_subdomains = false; |
| 2076 | transport_security_state->AddHSTS(host, expiry, include_subdomains); |
| 2077 | } |
| 2078 | |
| 2079 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestRawHeadersWithRedirectAndHSTS) { |
| 2080 | net::EmbeddedTestServer https_test_server( |
| 2081 | net::EmbeddedTestServer::TYPE_HTTPS); |
| 2082 | https_test_server.SetSSLConfig( |
| 2083 | net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 2084 | https_test_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 2085 | ASSERT_TRUE(https_test_server.Start()); |
| 2086 | GURL https_url = https_test_server.GetURL("localhost", "/devtools/image.png"); |
| 2087 | BrowserThread::PostTask( |
| 2088 | BrowserThread::IO, FROM_HERE, |
| 2089 | base::BindOnce( |
| 2090 | AddHSTSHost, |
| 2091 | base::RetainedRef(browser()->profile()->GetRequestContext()), |
| 2092 | https_url.host())); |
| 2093 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 2094 | |
| 2095 | OpenDevToolsWindow(std::string(), false); |
| 2096 | GURL::Replacements replace_scheme; |
| 2097 | replace_scheme.SetSchemeStr("http"); |
| 2098 | GURL http_url = https_url.ReplaceComponents(replace_scheme); |
| 2099 | GURL redirect_url = |
| 2100 | embedded_test_server()->GetURL("/server-redirect?" + http_url.spec()); |
| 2101 | |
| 2102 | DispatchOnTestSuite(window_, "testRawHeadersWithHSTS", |
| 2103 | redirect_url.spec().c_str()); |
| 2104 | CloseDevToolsWindow(); |
| 2105 | } |
Erik Luo | 3fe960d | 2018-01-24 21:39:13 | [diff] [blame] | 2106 | |
| 2107 | // Tests that OpenInNewTab filters URLs. |
| 2108 | IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestOpenInNewTabFilter) { |
| 2109 | OpenDevToolsWindow(kDebuggerTestPage, false); |
| 2110 | DevToolsUIBindings::Delegate* bindings_delegate_ = |
| 2111 | static_cast<DevToolsUIBindings::Delegate*>(window_); |
| 2112 | std::string test_url = |
| 2113 | spawned_test_server()->GetURL(kDebuggerTestPage).spec(); |
| 2114 | const std::string self_blob_url = |
| 2115 | base::StringPrintf("blob:%s", test_url.c_str()); |
| 2116 | const std::string self_filesystem_url = |
| 2117 | base::StringPrintf("filesystem:%s", test_url.c_str()); |
| 2118 | |
| 2119 | // Pairs include a URL string and boolean whether it should be allowed. |
| 2120 | std::vector<std::pair<const std::string, const std::string>> tests = { |
| 2121 | {test_url, test_url}, |
| 2122 | {"data:,foo", "data:,foo"}, |
| 2123 | {"about://inspect", "about:blank"}, |
| 2124 | {"chrome://inspect", "about:blank"}, |
| 2125 | {"chrome://inspect/#devices", "about:blank"}, |
| 2126 | {self_blob_url, self_blob_url}, |
| 2127 | {"blob:chrome://inspect", "about:blank"}, |
| 2128 | {self_filesystem_url, self_filesystem_url}, |
| 2129 | {"filesystem:chrome://inspect", "about:blank"}, |
| 2130 | {"view-source:http://chromium.org", "about:blank"}, |
| 2131 | {"file:///", "about:blank"}, |
| 2132 | {"about://gpu", "about:blank"}, |
| 2133 | {"chrome://gpu", "about:blank"}, |
| 2134 | {"chrome://crash", "about:blank"}, |
| 2135 | {"", "about:blank"}, |
| 2136 | }; |
| 2137 | |
| 2138 | TabStripModel* tabs = browser()->tab_strip_model(); |
| 2139 | int i = 0; |
| 2140 | for (const std::pair<const std::string, const std::string> pair : tests) { |
| 2141 | bindings_delegate_->OpenInNewTab(pair.first); |
| 2142 | i++; |
| 2143 | |
| 2144 | std::string opened_url = tabs->GetWebContentsAt(i)->GetVisibleURL().spec(); |
| 2145 | SCOPED_TRACE( |
| 2146 | base::StringPrintf("while testing URL: %s", pair.first.c_str())); |
| 2147 | EXPECT_EQ(opened_url, pair.second); |
| 2148 | } |
| 2149 | } |
Dmitry Gozman | 902bffab | 2018-01-27 15:20:46 | [diff] [blame] | 2150 | |
| 2151 | IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsSanityTest, InspectElement) { |
| 2152 | GURL url(embedded_test_server()->GetURL("a.com", "/devtools/oopif.html")); |
| 2153 | ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2); |
| 2154 | |
| 2155 | std::vector<RenderFrameHost*> frames = GetInspectedTab()->GetAllFrames(); |
| 2156 | ASSERT_EQ(2u, frames.size()); |
| 2157 | ASSERT_NE(frames[0]->GetProcess(), frames[1]->GetProcess()); |
| 2158 | RenderFrameHost* frame_host = frames[0]->GetParent() ? frames[0] : frames[1]; |
| 2159 | |
| 2160 | DevToolsWindowCreationObserver observer; |
| 2161 | DevToolsWindow::InspectElement(frame_host, 100, 100); |
| 2162 | observer.WaitForLoad(); |
| 2163 | DevToolsWindow* window = observer.devtools_window(); |
| 2164 | |
| 2165 | DispatchOnTestSuite(window, "testInspectedElementIs", "INSPECTED-DIV"); |
| 2166 | DevToolsWindowTesting::CloseDevToolsWindowSync(window); |
| 2167 | } |
Dmitry Gozman | 901b630 | 2018-03-02 02:30:39 | [diff] [blame] | 2168 | |
Trent Apted | fdc9e0f | 2018-03-12 07:16:38 | [diff] [blame] | 2169 | // Flaky on Mus. See https://crbug.com/819285. |
Dmitry Gozman | 901b630 | 2018-03-02 02:30:39 | [diff] [blame] | 2170 | IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsSanityTest, |
Trent Apted | fdc9e0f | 2018-03-12 07:16:38 | [diff] [blame] | 2171 | DISABLED_InputDispatchEventsToOOPIF) { |
Dmitry Gozman | 901b630 | 2018-03-02 02:30:39 | [diff] [blame] | 2172 | GURL url( |
| 2173 | embedded_test_server()->GetURL("a.com", "/devtools/oopif-input.html")); |
| 2174 | ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2); |
| 2175 | for (auto* frame : GetInspectedTab()->GetAllFrames()) |
| 2176 | content::WaitForChildFrameSurfaceReady(frame); |
| 2177 | DevToolsWindow* window = |
| 2178 | DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), false); |
| 2179 | RunTestFunction(window, "testInputDispatchEventsToOOPIF"); |
| 2180 | DevToolsWindowTesting::CloseDevToolsWindowSync(window); |
| 2181 | } |