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