[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 5 | #include <stddef.h> |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 6 | |
| 7 | #include <memory> |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 8 | #include <utility> |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 9 | |
Sebastien Marchand | f1349f5 | 2019-01-25 03:16:41 | [diff] [blame] | 10 | #include "base/bind.h" |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 11 | #include "base/callback.h" |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 12 | #include "base/path_service.h" |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 13 | #include "base/run_loop.h" |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 14 | #include "base/stl_util.h" |
Daniel Cheng | 4ebba55 | 2018-07-06 21:43:16 | [diff] [blame] | 15 | #include "base/strings/strcat.h" |
Lei Zhang | fe5b8693 | 2019-02-01 17:26:59 | [diff] [blame] | 16 | #include "base/strings/stringprintf.h" |
Devlin Cronin | 7a282e3 | 2017-08-10 01:54:10 | [diff] [blame] | 17 | #include "base/strings/utf_string_conversions.h" |
Devlin Cronin | 626d80c | 2018-06-01 01:08:36 | [diff] [blame] | 18 | #include "base/test/metrics/histogram_tester.h" |
vitaliii | 20d3e4e | 2018-01-29 12:45:14 | [diff] [blame] | 19 | #include "build/build_config.h" |
steel | f65a72a | 2016-10-19 22:16:45 | [diff] [blame] | 20 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_browsertest.h" |
| 22 | #include "chrome/browser/extensions/extension_service.h" |
Jochen Eisinger | 68fb064 | 2018-01-17 21:56:45 | [diff] [blame] | 23 | #include "chrome/browser/permissions/permission_request_manager.h" |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 24 | #include "chrome/browser/ui/browser_commands.h" |
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 25 | #include "chrome/browser/ui/extensions/extension_action_test_helper.h" |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 26 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 27 | #include "chrome/common/chrome_paths.h" |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 28 | #include "chrome/common/pref_names.h" |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 29 | #include "chrome/test/base/in_process_browser_test.h" |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 30 | #include "chrome/test/base/ui_test_utils.h" |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 31 | #include "components/guest_view/browser/test_guest_view_manager.h" |
Evan Stade | 7220e47 | 2020-01-31 17:06:57 | [diff] [blame^] | 32 | #include "components/javascript_dialogs/app_modal_dialog_manager.h" |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 33 | #include "content/public/browser/child_process_security_policy.h" |
nasko | 68e5e6d | 2017-05-24 23:19:34 | [diff] [blame] | 34 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 35 | #include "content/public/browser/notification_service.h" |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 36 | #include "content/public/browser/render_frame_host.h" |
nick | 92b0458 | 2016-04-08 02:54:04 | [diff] [blame] | 37 | #include "content/public/browser/render_process_host.h" |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 38 | #include "content/public/browser/web_contents.h" |
Arthur Sonzogni | f21fb51 | 2018-11-06 09:31:58 | [diff] [blame] | 39 | #include "content/public/common/navigation_policy.h" |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 40 | #include "content/public/test/browser_test_utils.h" |
Jochen Eisinger | 68fb064 | 2018-01-17 21:56:45 | [diff] [blame] | 41 | #include "content/public/test/download_test_observer.h" |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 42 | #include "content/public/test/test_navigation_observer.h" |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 43 | #include "content/public/test/test_utils.h" |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 44 | #include "extensions/browser/app_window/app_window.h" |
| 45 | #include "extensions/browser/app_window/app_window_registry.h" |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 46 | #include "extensions/browser/process_manager.h" |
wez | 714dde1 | 2017-02-14 22:26:03 | [diff] [blame] | 47 | #include "extensions/common/manifest_handlers/background_info.h" |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 48 | #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 49 | #include "extensions/common/permissions/permissions_data.h" |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 50 | #include "extensions/common/value_builder.h" |
| 51 | #include "extensions/test/background_page_watcher.h" |
Devlin Cronin | 4f455a2 | 2018-01-25 01:36:45 | [diff] [blame] | 52 | #include "extensions/test/test_extension_dir.h" |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 53 | #include "net/dns/mock_host_resolver.h" |
| 54 | #include "net/test/embedded_test_server/embedded_test_server.h" |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 55 | |
Hiroki Sato | be244d9 | 2020-01-28 00:12:48 | [diff] [blame] | 56 | #if defined(OS_CHROMEOS) |
achuith | cb6fe98c | 2017-03-22 08:57:51 | [diff] [blame] | 57 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 58 | #include "chromeos/constants/chromeos_switches.h" |
achuith | cb6fe98c | 2017-03-22 08:57:51 | [diff] [blame] | 59 | #endif |
| 60 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 61 | namespace extensions { |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 62 | |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 63 | namespace { |
| 64 | |
Nick Carter | bf6264a5 | 2018-04-06 02:39:33 | [diff] [blame] | 65 | bool IsExtensionProcessSharingAllowed() { |
| 66 | // TODO(nick): Currently, process sharing is allowed even in |
| 67 | // --site-per-process. Lock this down. https://crbug.com/766267 |
| 68 | return true; |
| 69 | } |
| 70 | |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 71 | void AddFrameToSet(std::set<content::RenderFrameHost*>* frames, |
| 72 | content::RenderFrameHost* rfh) { |
| 73 | if (rfh->IsRenderFrameLive()) |
| 74 | frames->insert(rfh); |
| 75 | } |
| 76 | |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 77 | GURL CreateBlobURL(content::RenderFrameHost* frame, |
| 78 | const std::string& content) { |
| 79 | std::string blob_url_string; |
| 80 | EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 81 | frame, |
| 82 | "var blob = new Blob(['<html><body>" + content + "</body></html>'],\n" |
| 83 | " {type: 'text/html'});\n" |
| 84 | "domAutomationController.send(URL.createObjectURL(blob));\n", |
| 85 | &blob_url_string)); |
| 86 | GURL blob_url(blob_url_string); |
| 87 | EXPECT_TRUE(blob_url.is_valid()); |
| 88 | EXPECT_TRUE(blob_url.SchemeIsBlob()); |
| 89 | return blob_url; |
| 90 | } |
| 91 | |
| 92 | GURL CreateFileSystemURL(content::RenderFrameHost* frame, |
| 93 | const std::string& content) { |
| 94 | std::string filesystem_url_string; |
| 95 | EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 96 | frame, |
| 97 | "var blob = new Blob(['<html><body>" + content + "</body></html>'],\n" |
| 98 | " {type: 'text/html'});\n" |
| 99 | "window.webkitRequestFileSystem(TEMPORARY, blob.size, fs => {\n" |
| 100 | " fs.root.getFile('foo.html', {create: true}, file => {\n" |
| 101 | " file.createWriter(writer => {\n" |
| 102 | " writer.write(blob);\n" |
| 103 | " writer.onwriteend = () => {\n" |
| 104 | " domAutomationController.send(file.toURL());\n" |
| 105 | " }\n" |
| 106 | " });\n" |
| 107 | " });\n" |
| 108 | "});\n", |
| 109 | &filesystem_url_string)); |
| 110 | GURL filesystem_url(filesystem_url_string); |
| 111 | EXPECT_TRUE(filesystem_url.is_valid()); |
| 112 | EXPECT_TRUE(filesystem_url.SchemeIsFileSystem()); |
| 113 | return filesystem_url; |
| 114 | } |
| 115 | |
| 116 | std::string GetTextContent(content::RenderFrameHost* frame) { |
| 117 | std::string result; |
| 118 | EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 119 | frame, "domAutomationController.send(document.body.innerText)", &result)); |
| 120 | return result; |
| 121 | } |
| 122 | |
alexmos | 1f48ef6 | 2016-10-06 00:51:50 | [diff] [blame] | 123 | // Helper to send a postMessage from |sender| to |opener| via window.opener, |
| 124 | // wait for a reply, and verify the response. Defines its own message event |
| 125 | // handlers. |
| 126 | void VerifyPostMessageToOpener(content::RenderFrameHost* sender, |
| 127 | content::RenderFrameHost* opener) { |
| 128 | EXPECT_TRUE( |
| 129 | ExecuteScript(opener, |
| 130 | "window.addEventListener('message', function(event) {\n" |
| 131 | " event.source.postMessage(event.data, '*');\n" |
| 132 | "});")); |
| 133 | |
| 134 | EXPECT_TRUE( |
| 135 | ExecuteScript(sender, |
| 136 | "window.addEventListener('message', function(event) {\n" |
| 137 | " window.domAutomationController.send(event.data);\n" |
| 138 | "});")); |
| 139 | |
| 140 | std::string result; |
| 141 | EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 142 | sender, "opener.postMessage('foo', '*');", &result)); |
| 143 | EXPECT_EQ("foo", result); |
| 144 | } |
| 145 | |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 146 | // Takes a snapshot of all frames upon construction. When Wait() is called, a |
| 147 | // MessageLoop is created and Quit when all previously recorded frames are |
| 148 | // either present in the tab, or deleted. If a navigation happens between the |
| 149 | // construction and the Wait() call, then this logic ensures that all obsolete |
| 150 | // RenderFrameHosts have been destructed when Wait() returns. |
| 151 | // See also the comment at ProcessManagerBrowserTest::NavigateToURL. |
| 152 | class NavigationCompletedObserver : public content::WebContentsObserver { |
| 153 | public: |
| 154 | explicit NavigationCompletedObserver(content::WebContents* web_contents) |
| 155 | : content::WebContentsObserver(web_contents), |
| 156 | message_loop_runner_(new content::MessageLoopRunner) { |
| 157 | web_contents->ForEachFrame( |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 158 | base::BindRepeating(&AddFrameToSet, base::Unretained(&frames_))); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void Wait() { |
| 162 | if (!AreAllFramesInTab()) |
| 163 | message_loop_runner_->Run(); |
| 164 | } |
| 165 | |
| 166 | void RenderFrameDeleted(content::RenderFrameHost* rfh) override { |
| 167 | if (frames_.erase(rfh) != 0 && message_loop_runner_->loop_running() && |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 168 | AreAllFramesInTab()) { |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 169 | message_loop_runner_->Quit(); |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 170 | } |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | private: |
| 174 | // Check whether all frames that were recorded at the construction of this |
| 175 | // class are still part of the tab. |
| 176 | bool AreAllFramesInTab() { |
| 177 | std::set<content::RenderFrameHost*> current_frames; |
| 178 | web_contents()->ForEachFrame( |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 179 | base::BindRepeating(&AddFrameToSet, base::Unretained(¤t_frames))); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 180 | for (content::RenderFrameHost* frame : frames_) { |
Jan Wilken Dörrie | ade7922 | 2019-06-06 19:01:12 | [diff] [blame] | 181 | if (!base::Contains(current_frames, frame)) |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 182 | return false; |
| 183 | } |
| 184 | return true; |
| 185 | } |
| 186 | |
| 187 | std::set<content::RenderFrameHost*> frames_; |
| 188 | scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 189 | |
| 190 | DISALLOW_COPY_AND_ASSIGN(NavigationCompletedObserver); |
| 191 | }; |
| 192 | |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 193 | // Exists as a browser test because ExtensionHosts are hard to create without |
| 194 | // a real browser. |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 195 | class ProcessManagerBrowserTest : public ExtensionBrowserTest { |
| 196 | public: |
krasin | af85e4c4 | 2016-10-25 17:54:26 | [diff] [blame] | 197 | ProcessManagerBrowserTest() { |
| 198 | guest_view::GuestViewManager::set_factory_for_testing(&factory_); |
| 199 | } |
jam | a9cfcb5 | 2017-05-01 21:49:13 | [diff] [blame] | 200 | |
| 201 | void SetUpOnMainThread() override { |
| 202 | ExtensionBrowserTest::SetUpOnMainThread(); |
| 203 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 204 | } |
| 205 | |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 206 | // Create an extension with web-accessible frames and an optional background |
| 207 | // page. |
| 208 | const Extension* CreateExtension(const std::string& name, |
| 209 | bool has_background_process) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 210 | std::unique_ptr<TestExtensionDir> dir(new TestExtensionDir()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 211 | |
| 212 | DictionaryBuilder manifest; |
| 213 | manifest.Set("name", name) |
| 214 | .Set("version", "1") |
| 215 | .Set("manifest_version", 2) |
| 216 | // To allow ExecuteScript* to work. |
| 217 | .Set("content_security_policy", |
| 218 | "script-src 'self' 'unsafe-eval'; object-src 'self'") |
limasdf | 3d10254 | 2015-12-09 03:58:45 | [diff] [blame] | 219 | .Set("sandbox", |
dcheng | 794d2bd | 2016-02-27 03:51:32 | [diff] [blame] | 220 | DictionaryBuilder() |
| 221 | .Set("pages", ListBuilder().Append("sandboxed.html").Build()) |
| 222 | .Build()) |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 223 | .Set("web_accessible_resources", |
| 224 | ListBuilder().Append("*.html").Build()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 225 | |
| 226 | if (has_background_process) { |
limasdf | 21d67e6 | 2015-12-19 12:04:49 | [diff] [blame] | 227 | manifest.Set("background", |
dcheng | 794d2bd | 2016-02-27 03:51:32 | [diff] [blame] | 228 | DictionaryBuilder().Set("page", "bg.html").Build()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 229 | dir->WriteFile(FILE_PATH_LITERAL("bg.html"), |
| 230 | "<iframe id='bgframe' src='empty.html'></iframe>"); |
| 231 | } |
| 232 | |
| 233 | dir->WriteFile(FILE_PATH_LITERAL("blank_iframe.html"), |
| 234 | "<iframe id='frame0' src='about:blank'></iframe>"); |
| 235 | |
| 236 | dir->WriteFile(FILE_PATH_LITERAL("srcdoc_iframe.html"), |
| 237 | "<iframe id='frame0' srcdoc='Hello world'></iframe>"); |
| 238 | |
| 239 | dir->WriteFile(FILE_PATH_LITERAL("two_iframes.html"), |
| 240 | "<iframe id='frame1' src='empty.html'></iframe>" |
| 241 | "<iframe id='frame2' src='empty.html'></iframe>"); |
| 242 | |
| 243 | dir->WriteFile(FILE_PATH_LITERAL("sandboxed.html"), "Some sandboxed page"); |
| 244 | |
| 245 | dir->WriteFile(FILE_PATH_LITERAL("empty.html"), ""); |
| 246 | |
| 247 | dir->WriteManifest(manifest.ToJSON()); |
| 248 | |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 249 | const Extension* extension = LoadExtension(dir->UnpackedPath()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 250 | EXPECT_TRUE(extension); |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 251 | temp_dirs_.push_back(std::move(dir)); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 252 | return extension; |
| 253 | } |
| 254 | |
| 255 | // ui_test_utils::NavigateToURL sometimes returns too early: It returns as |
| 256 | // soon as the StopLoading notification has been triggered. This does not |
| 257 | // imply that RenderFrameDeleted was called, so the test may continue too |
| 258 | // early and fail when ProcessManager::GetAllFrames() returns too many frames |
| 259 | // (namely frames that are in the process of being deleted). To work around |
| 260 | // this problem, we also wait until all previous frames have been deleted. |
| 261 | void NavigateToURL(const GURL& url) { |
| 262 | NavigationCompletedObserver observer( |
| 263 | browser()->tab_strip_model()->GetActiveWebContents()); |
| 264 | |
| 265 | ui_test_utils::NavigateToURL(browser(), url); |
| 266 | |
| 267 | // Wait until the last RenderFrameHosts are deleted. This wait doesn't take |
| 268 | // long. |
| 269 | observer.Wait(); |
| 270 | } |
| 271 | |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 272 | content::WebContents* OpenPopup(content::RenderFrameHost* opener, |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 273 | const GURL& url, |
| 274 | bool expect_success = true) { |
Evan Stade | acbfc3de | 2019-07-18 19:44:17 | [diff] [blame] | 275 | ui_test_utils::TabAddedWaiter waiter(browser()); |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 276 | EXPECT_TRUE(ExecuteScript( |
| 277 | opener, "window.popup = window.open('" + url.spec() + "')")); |
Evan Stade | acbfc3de | 2019-07-18 19:44:17 | [diff] [blame] | 278 | waiter.Wait(); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 279 | content::WebContents* popup = |
| 280 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 281 | WaitForLoadStop(popup); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 282 | if (expect_success) |
| 283 | EXPECT_EQ(url, popup->GetMainFrame()->GetLastCommittedURL()); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 284 | return popup; |
| 285 | } |
| 286 | |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 287 | content::WebContents* OpenPopupNoOpener(content::RenderFrameHost* opener, |
| 288 | const GURL& url) { |
| 289 | content::WebContentsAddedObserver popup_observer; |
| 290 | EXPECT_TRUE(ExecuteScript( |
| 291 | opener, "window.open('" + url.spec() + "', '', 'noopener')")); |
| 292 | content::WebContents* popup = popup_observer.GetWebContents(); |
| 293 | WaitForLoadStop(popup); |
| 294 | return popup; |
| 295 | } |
| 296 | |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 297 | private: |
krasin | af85e4c4 | 2016-10-25 17:54:26 | [diff] [blame] | 298 | guest_view::TestGuestViewManagerFactory factory_; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 299 | std::vector<std::unique_ptr<TestExtensionDir>> temp_dirs_; |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 300 | }; |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 301 | |
achuith | cb6fe98c | 2017-03-22 08:57:51 | [diff] [blame] | 302 | class DefaultProfileExtensionBrowserTest : public ExtensionBrowserTest { |
| 303 | protected: |
| 304 | DefaultProfileExtensionBrowserTest() { |
| 305 | #if defined(OS_CHROMEOS) |
| 306 | // We want signin profile on ChromeOS, not logged in user profile. |
| 307 | set_chromeos_user_ = false; |
| 308 | #endif |
| 309 | } |
| 310 | |
| 311 | private: |
| 312 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 313 | ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 314 | #if defined(OS_CHROMEOS) |
| 315 | command_line->AppendSwitch(chromeos::switches::kLoginManager); |
| 316 | command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); |
| 317 | #endif |
| 318 | } |
| 319 | }; |
| 320 | |
| 321 | } // namespace |
| 322 | |
| 323 | // By default, no extension hosts should be present in the profile; |
| 324 | // they should only be present if non-component extensions are loaded |
| 325 | // or if the user takes some action to trigger a component extension. |
| 326 | // TODO(achuith): Expand this testing to include more in-depth |
| 327 | // testing for the signin profile, where we explicitly disallow all |
| 328 | // extension hosts unless it's the off-the-record profile. |
| 329 | IN_PROC_BROWSER_TEST_F(DefaultProfileExtensionBrowserTest, NoExtensionHosts) { |
| 330 | // Explicitly get the original and off-the-record-profiles, since on CrOS, |
| 331 | // the signin profile (profile()) is the off-the-record version. |
| 332 | Profile* original = profile()->GetOriginalProfile(); |
| 333 | Profile* otr = original->GetOffTheRecordProfile(); |
| 334 | #if defined(OS_CHROMEOS) |
| 335 | EXPECT_EQ(profile(), otr); |
| 336 | EXPECT_TRUE(chromeos::ProfileHelper::IsSigninProfile(original)); |
| 337 | #endif |
| 338 | |
| 339 | ProcessManager* pm = ProcessManager::Get(original); |
| 340 | EXPECT_EQ(0u, pm->background_hosts().size()); |
| 341 | |
| 342 | pm = ProcessManager::Get(otr); |
| 343 | EXPECT_EQ(0u, pm->background_hosts().size()); |
| 344 | } |
| 345 | |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 346 | // Test that basic extension loading creates the appropriate ExtensionHosts |
| 347 | // and background pages. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 348 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 349 | ExtensionHostCreation) { |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 350 | ProcessManager* pm = ProcessManager::Get(profile()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 351 | |
| 352 | // We start with no background hosts. |
| 353 | ASSERT_EQ(0u, pm->background_hosts().size()); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 354 | ASSERT_EQ(0u, pm->GetAllFrames().size()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 355 | |
| 356 | // Load an extension with a background page. |
| 357 | scoped_refptr<const Extension> extension = |
| 358 | LoadExtension(test_data_dir_.AppendASCII("api_test") |
| 359 | .AppendASCII("browser_action") |
| 360 | .AppendASCII("none")); |
wez | 714dde1 | 2017-02-14 22:26:03 | [diff] [blame] | 361 | ASSERT_TRUE(extension); |
| 362 | |
| 363 | EXPECT_TRUE(BackgroundInfo::HasPersistentBackgroundPage(extension.get())); |
| 364 | EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(extension.get())); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 365 | EXPECT_TRUE(pm->GetLazyKeepaliveActivities(extension.get()).empty()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 366 | |
| 367 | // Process manager gains a background host. |
| 368 | EXPECT_EQ(1u, pm->background_hosts().size()); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 369 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 370 | EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); |
| 371 | EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 372 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 373 | EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 374 | |
| 375 | // Unload the extension. |
| 376 | UnloadExtension(extension->id()); |
| 377 | |
| 378 | // Background host disappears. |
| 379 | EXPECT_EQ(0u, pm->background_hosts().size()); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 380 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 381 | EXPECT_FALSE(pm->GetBackgroundHostForExtension(extension->id())); |
| 382 | EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 383 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 384 | EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); |
wez | 714dde1 | 2017-02-14 22:26:03 | [diff] [blame] | 385 | EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(extension.get())); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 386 | EXPECT_TRUE(pm->GetLazyKeepaliveActivities(extension.get()).empty()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 387 | } |
| 388 | |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 389 | // Test that loading an extension with a browser action does not create a |
| 390 | // background page and that clicking on the action creates the appropriate |
| 391 | // ExtensionHost. |
[email protected] | 1df312d | 2013-11-05 21:20:39 | [diff] [blame] | 392 | // Disabled due to flake, see http://crbug.com/315242 |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 393 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
[email protected] | 1df312d | 2013-11-05 21:20:39 | [diff] [blame] | 394 | DISABLED_PopupHostCreation) { |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 395 | ProcessManager* pm = ProcessManager::Get(profile()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 396 | |
| 397 | // Load an extension with the ability to open a popup but no background |
| 398 | // page. |
| 399 | scoped_refptr<const Extension> popup = |
| 400 | LoadExtension(test_data_dir_.AppendASCII("api_test") |
| 401 | .AppendASCII("browser_action") |
| 402 | .AppendASCII("popup")); |
wez | 714dde1 | 2017-02-14 22:26:03 | [diff] [blame] | 403 | ASSERT_TRUE(popup); |
| 404 | |
| 405 | EXPECT_FALSE(BackgroundInfo::HasBackgroundPage(popup.get())); |
| 406 | EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(popup.get())); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 407 | EXPECT_TRUE(pm->GetLazyKeepaliveActivities(popup.get()).empty()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 408 | |
| 409 | // No background host was added. |
| 410 | EXPECT_EQ(0u, pm->background_hosts().size()); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 411 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 412 | EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 413 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 414 | EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); |
| 415 | EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 416 | |
| 417 | // Simulate clicking on the action to open a popup. |
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 418 | auto test_util = ExtensionActionTestHelper::Create(browser()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 419 | content::WindowedNotificationObserver frame_observer( |
| 420 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 421 | content::NotificationService::AllSources()); |
| 422 | // Open popup in the first extension. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 423 | test_util->Press(0); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 424 | frame_observer.Wait(); |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 425 | ASSERT_TRUE(test_util->HasPopup()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 426 | |
| 427 | // We now have a view, but still no background hosts. |
| 428 | EXPECT_EQ(0u, pm->background_hosts().size()); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 429 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 430 | EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 431 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 432 | EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); |
| 433 | EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); |
wez | 714dde1 | 2017-02-14 22:26:03 | [diff] [blame] | 434 | EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(popup.get())); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 435 | EXPECT_TRUE(pm->GetLazyKeepaliveActivities(popup.get()).empty()); |
| 436 | EXPECT_TRUE(pm->GetLazyKeepaliveActivities(popup.get()).empty()); |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 437 | } |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 438 | |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 439 | // Content loaded from http://hlogonemlfkgpejgnedahbkiabcdhnnn should not |
| 440 | // interact with an installed extension with that ID. Regression test |
| 441 | // for bug 357382. |
| 442 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HttpHostMatchingExtensionId) { |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 443 | ProcessManager* pm = ProcessManager::Get(profile()); |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 444 | |
| 445 | // We start with no background hosts. |
| 446 | ASSERT_EQ(0u, pm->background_hosts().size()); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 447 | ASSERT_EQ(0u, pm->GetAllFrames().size()); |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 448 | |
| 449 | // Load an extension with a background page. |
| 450 | scoped_refptr<const Extension> extension = |
| 451 | LoadExtension(test_data_dir_.AppendASCII("api_test") |
| 452 | .AppendASCII("browser_action") |
| 453 | .AppendASCII("none")); |
| 454 | |
| 455 | // Set up a test server running at http://[extension-id] |
| 456 | ASSERT_TRUE(extension.get()); |
mgiuca | 77752c3 | 2015-02-05 07:31:18 | [diff] [blame] | 457 | const std::string& aliased_host = extension->id(); |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 458 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 459 | GURL url = |
| 460 | embedded_test_server()->GetURL("/extensions/test_file_with_body.html"); |
| 461 | GURL::Replacements replace_host; |
| 462 | replace_host.SetHostStr(aliased_host); |
| 463 | url = url.ReplaceComponents(replace_host); |
| 464 | |
| 465 | // Load a page from the test host in a new tab. |
| 466 | ui_test_utils::NavigateToURLWithDisposition( |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 467 | browser(), url, WindowOpenDisposition::NEW_FOREGROUND_TAB, |
Fergal Daly | ffa9bba | 2020-01-27 23:45:02 | [diff] [blame] | 468 | ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP); |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 469 | |
| 470 | // Sanity check that there's no bleeding between the extension and the tab. |
| 471 | content::WebContents* tab_web_contents = |
| 472 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 473 | EXPECT_EQ(url, tab_web_contents->GetVisibleURL()); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 474 | EXPECT_FALSE(pm->GetExtensionForWebContents(tab_web_contents)) |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 475 | << "Non-extension content must not have an associated extension"; |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 476 | ASSERT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 477 | content::WebContents* extension_web_contents = |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 478 | content::WebContents::FromRenderFrameHost( |
| 479 | *pm->GetRenderFrameHostsForExtension(extension->id()).begin()); |
[email protected] | 6703c15d | 2014-04-03 19:03:45 | [diff] [blame] | 480 | EXPECT_TRUE(extension_web_contents->GetSiteInstance() != |
| 481 | tab_web_contents->GetSiteInstance()); |
| 482 | EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url()) != |
| 483 | tab_web_contents->GetSiteInstance()); |
| 484 | EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); |
| 485 | } |
| 486 | |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 487 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, NoBackgroundPage) { |
| 488 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 489 | |
| 490 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 491 | const Extension* extension = |
| 492 | LoadExtension(test_data_dir_.AppendASCII("api_test") |
| 493 | .AppendASCII("messaging") |
| 494 | .AppendASCII("connect_nobackground")); |
| 495 | ASSERT_TRUE(extension); |
| 496 | |
| 497 | // The extension has no background page. |
| 498 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 499 | |
| 500 | // Start in a non-extension process, then navigate to an extension process. |
| 501 | NavigateToURL(embedded_test_server()->GetURL("/empty.html")); |
| 502 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 503 | |
| 504 | const GURL extension_url = extension->url().Resolve("manifest.json"); |
| 505 | NavigateToURL(extension_url); |
| 506 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 507 | |
| 508 | NavigateToURL(GURL("about:blank")); |
| 509 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 510 | |
| 511 | ui_test_utils::NavigateToURLWithDisposition( |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 512 | browser(), extension_url, WindowOpenDisposition::NEW_FOREGROUND_TAB, |
Fergal Daly | ffa9bba | 2020-01-27 23:45:02 | [diff] [blame] | 513 | ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 514 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 515 | } |
| 516 | |
| 517 | // Tests whether frames are correctly classified. Non-extension frames should |
| 518 | // never appear in the list. Top-level extension frames should always appear. |
| 519 | // Child extension frames should only appear if it is hosted in an extension |
| 520 | // process (i.e. if the top-level frame is an extension page, or if OOP frames |
| 521 | // are enabled for extensions). |
mgiuca | f5c1ca2 | 2017-02-20 02:16:21 | [diff] [blame] | 522 | // Disabled due to flake: https://crbug.com/693287. |
| 523 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 524 | DISABLED_FrameClassification) { |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 525 | const Extension* extension1 = CreateExtension("Extension 1", false); |
| 526 | const Extension* extension2 = CreateExtension("Extension 2", true); |
| 527 | embedded_test_server()->ServeFilesFromDirectory(extension1->path()); |
| 528 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 529 | |
| 530 | const GURL kExt1TwoFramesUrl(extension1->url().Resolve("two_iframes.html")); |
| 531 | const GURL kExt1EmptyUrl(extension1->url().Resolve("empty.html")); |
| 532 | const GURL kExt2TwoFramesUrl(extension2->url().Resolve("two_iframes.html")); |
| 533 | const GURL kExt2EmptyUrl(extension2->url().Resolve("empty.html")); |
| 534 | |
| 535 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 536 | |
| 537 | // 1 background page + 1 frame in background page from Extension 2. |
| 538 | BackgroundPageWatcher(pm, extension2).WaitForOpen(); |
| 539 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
| 540 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
| 541 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 542 | |
| 543 | ExecuteScriptInBackgroundPageNoWait(extension2->id(), |
| 544 | "setTimeout(window.close, 0)"); |
| 545 | BackgroundPageWatcher(pm, extension2).WaitForClose(); |
| 546 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 547 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 548 | |
| 549 | NavigateToURL(embedded_test_server()->GetURL("/two_iframes.html")); |
| 550 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 551 | |
| 552 | content::WebContents* tab = |
| 553 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 554 | |
| 555 | // Tests extension frames in non-extension page. |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 556 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame1", kExt1EmptyUrl)); |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 557 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
| 558 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 559 | |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 560 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame2", kExt2EmptyUrl)); |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 561 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 562 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 563 | |
| 564 | // Tests non-extension page in extension frame. |
| 565 | NavigateToURL(kExt1TwoFramesUrl); |
| 566 | // 1 top-level + 2 child frames from Extension 1. |
| 567 | EXPECT_EQ(3u, pm->GetAllFrames().size()); |
| 568 | EXPECT_EQ(3u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
| 569 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 570 | |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 571 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame1", |
| 572 | embedded_test_server() |
| 573 | ->GetURL("/empty.html"))); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 574 | // 1 top-level + 1 child frame from Extension 1. |
| 575 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
| 576 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
| 577 | |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 578 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame1", kExt1EmptyUrl)); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 579 | // 1 top-level + 2 child frames from Extension 1. |
| 580 | EXPECT_EQ(3u, pm->GetAllFrames().size()); |
| 581 | EXPECT_EQ(3u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
| 582 | |
| 583 | // Load a frame from another extension. |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 584 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame1", kExt2EmptyUrl)); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 585 | // 1 top-level + 1 child frame from Extension 1, |
| 586 | // 1 child frame from Extension 2. |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 587 | EXPECT_EQ(3u, pm->GetAllFrames().size()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 588 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 589 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 590 | |
| 591 | // Destroy all existing frames by navigating to another extension. |
| 592 | NavigateToURL(extension2->url().Resolve("empty.html")); |
| 593 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 594 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
| 595 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 596 | |
| 597 | // Test about:blank and about:srcdoc child frames. |
| 598 | NavigateToURL(extension2->url().Resolve("srcdoc_iframe.html")); |
| 599 | // 1 top-level frame + 1 child frame from Extension 2. |
| 600 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
| 601 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 602 | |
| 603 | NavigateToURL(extension2->url().Resolve("blank_iframe.html")); |
| 604 | // 1 top-level frame + 1 child frame from Extension 2. |
| 605 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
| 606 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 607 | |
| 608 | // Sandboxed frames are not viewed as extension frames. |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 609 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame0", |
| 610 | extension2->url() |
| 611 | .Resolve("sandboxed.html"))); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 612 | // 1 top-level frame from Extension 2. |
| 613 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 614 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 615 | |
| 616 | NavigateToURL(extension2->url().Resolve("sandboxed.html")); |
| 617 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 618 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 619 | |
| 620 | // Test nested frames (same extension). |
| 621 | NavigateToURL(kExt2TwoFramesUrl); |
| 622 | // 1 top-level + 2 child frames from Extension 2. |
| 623 | EXPECT_EQ(3u, pm->GetAllFrames().size()); |
| 624 | EXPECT_EQ(3u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 625 | |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 626 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame1", kExt2TwoFramesUrl)); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 627 | // 1 top-level + 2 child frames from Extension 1, |
| 628 | // 2 child frames in frame1 from Extension 2. |
| 629 | EXPECT_EQ(5u, pm->GetAllFrames().size()); |
| 630 | EXPECT_EQ(5u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 631 | |
| 632 | // The extension frame from the other extension should not be classified as an |
| 633 | // extension (unless out-of-process frames are enabled). |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 634 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame1", kExt1EmptyUrl)); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 635 | // 1 top-level + 1 child frames from Extension 2, |
| 636 | // 1 child frame from Extension 1. |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 637 | EXPECT_EQ(3u, pm->GetAllFrames().size()); |
| 638 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 639 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 640 | |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 641 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame2", kExt1TwoFramesUrl)); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 642 | // 1 top-level + 1 child frames from Extension 2, |
| 643 | // 1 child frame + 2 child frames in frame2 from Extension 1. |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 644 | EXPECT_EQ(5u, pm->GetAllFrames().size()); |
| 645 | EXPECT_EQ(4u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 646 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 647 | |
| 648 | // Crash tab where the top-level frame is an extension frame. |
| 649 | content::CrashTab(tab); |
| 650 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 651 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
| 652 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 653 | |
| 654 | // Now load an extension page and a non-extension page... |
| 655 | ui_test_utils::NavigateToURLWithDisposition( |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 656 | browser(), kExt1EmptyUrl, WindowOpenDisposition::NEW_BACKGROUND_TAB, |
Fergal Daly | ffa9bba | 2020-01-27 23:45:02 | [diff] [blame] | 657 | ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 658 | NavigateToURL(embedded_test_server()->GetURL("/two_iframes.html")); |
| 659 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 660 | |
| 661 | // ... load an extension frame in the non-extension process |
rob | 57afbca | 2015-12-21 17:52:11 | [diff] [blame] | 662 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame1", kExt1EmptyUrl)); |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 663 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
rob | cdcc4b8 | 2015-12-06 12:39:45 | [diff] [blame] | 664 | |
| 665 | // ... and take down the tab. The extension process is not part of the tab, |
| 666 | // so it should be kept alive (minus the frames that died). |
| 667 | content::CrashTab(tab); |
| 668 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 669 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
| 670 | } |
| 671 | |
rockot | e570329 | 2015-09-28 23:23:09 | [diff] [blame] | 672 | // Verify correct keepalive count behavior on network request events. |
| 673 | // Regression test for http://crbug.com/535716. |
Takumi Fujimoto | 574147e0 | 2019-12-03 23:26:05 | [diff] [blame] | 674 | // Disabled on Linux for flakiness: http://crbug.com/1030435. |
| 675 | #if defined(OS_LINUX) |
| 676 | #define MAYBE_KeepaliveOnNetworkRequest DISABLED_KeepaliveOnNetworkRequest |
| 677 | #else |
| 678 | #define MAYBE_KeepaliveOnNetworkRequest KeepaliveOnNetworkRequest |
| 679 | #endif |
| 680 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 681 | MAYBE_KeepaliveOnNetworkRequest) { |
rockot | e570329 | 2015-09-28 23:23:09 | [diff] [blame] | 682 | // Load an extension with a lazy background page. |
| 683 | scoped_refptr<const Extension> extension = |
| 684 | LoadExtension(test_data_dir_.AppendASCII("api_test") |
| 685 | .AppendASCII("lazy_background_page") |
| 686 | .AppendASCII("broadcast_event")); |
| 687 | ASSERT_TRUE(extension.get()); |
| 688 | |
| 689 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 690 | ProcessManager::FrameSet frames = |
| 691 | pm->GetRenderFrameHostsForExtension(extension->id()); |
| 692 | ASSERT_EQ(1u, frames.size()); |
| 693 | |
| 694 | // Keepalive count at this point is unpredictable as there may be an |
| 695 | // outstanding event dispatch. We use the current keepalive count as a |
| 696 | // reliable baseline for future expectations. |
wez | 714dde1 | 2017-02-14 22:26:03 | [diff] [blame] | 697 | EXPECT_TRUE(BackgroundInfo::HasLazyBackgroundPage(extension.get())); |
rockot | e570329 | 2015-09-28 23:23:09 | [diff] [blame] | 698 | int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get()); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 699 | size_t baseline_activities_count = |
| 700 | pm->GetLazyKeepaliveActivities(extension.get()).size(); |
wez | 714dde1 | 2017-02-14 22:26:03 | [diff] [blame] | 701 | EXPECT_LE(0, baseline_keepalive); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 702 | EXPECT_LE(0u, baseline_activities_count); |
rockot | e570329 | 2015-09-28 23:23:09 | [diff] [blame] | 703 | |
| 704 | // Simulate some network events. This test assumes no other network requests |
| 705 | // are pending, i.e., that there are no conflicts with the fake request IDs |
| 706 | // we're using. This should be a safe assumption because LoadExtension should |
| 707 | // wait for loads to complete, and we don't run the message loop otherwise. |
| 708 | content::RenderFrameHost* frame_host = *frames.begin(); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 709 | constexpr int kRequestId = 1; |
| 710 | const auto activity = |
| 711 | std::make_pair(Activity::NETWORK, base::NumberToString(kRequestId)); |
| 712 | |
| 713 | pm->OnNetworkRequestStarted(frame_host, kRequestId); |
rockot | e570329 | 2015-09-28 23:23:09 | [diff] [blame] | 714 | EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 715 | EXPECT_EQ(1u, |
| 716 | pm->GetLazyKeepaliveActivities(extension.get()).count(activity)); |
| 717 | pm->OnNetworkRequestDone(frame_host, kRequestId); |
rockot | e570329 | 2015-09-28 23:23:09 | [diff] [blame] | 718 | EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 719 | EXPECT_EQ(0u, |
| 720 | pm->GetLazyKeepaliveActivities(extension.get()).count(activity)); |
rockot | e570329 | 2015-09-28 23:23:09 | [diff] [blame] | 721 | |
| 722 | // Simulate only a request completion for this ID and ensure it doesn't result |
| 723 | // in keepalive decrement. |
| 724 | pm->OnNetworkRequestDone(frame_host, 2); |
| 725 | EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); |
David Bertoni | 3e1e9fa | 2018-08-29 20:39:30 | [diff] [blame] | 726 | EXPECT_EQ(baseline_activities_count, |
| 727 | pm->GetLazyKeepaliveActivities(extension.get()).size()); |
rockot | e570329 | 2015-09-28 23:23:09 | [diff] [blame] | 728 | } |
| 729 | |
nick | 92b0458 | 2016-04-08 02:54:04 | [diff] [blame] | 730 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, ExtensionProcessReuse) { |
| 731 | const size_t kNumExtensions = 3; |
| 732 | content::RenderProcessHost::SetMaxRendererProcessCount(kNumExtensions - 1); |
| 733 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 734 | |
| 735 | std::set<int> processes; |
| 736 | std::set<const Extension*> installed_extensions; |
| 737 | |
| 738 | // Create 3 extensions, which is more than the process limit. |
| 739 | for (int i = 1; i <= static_cast<int>(kNumExtensions); ++i) { |
| 740 | const Extension* extension = |
| 741 | CreateExtension(base::StringPrintf("Extension %d", i), true); |
| 742 | installed_extensions.insert(extension); |
| 743 | ExtensionHost* extension_host = |
| 744 | pm->GetBackgroundHostForExtension(extension->id()); |
| 745 | |
| 746 | EXPECT_EQ(extension->url(), |
| 747 | extension_host->host_contents()->GetSiteInstance()->GetSiteURL()); |
| 748 | |
| 749 | processes.insert(extension_host->render_process_host()->GetID()); |
| 750 | } |
| 751 | |
| 752 | EXPECT_EQ(kNumExtensions, installed_extensions.size()); |
| 753 | |
Nick Carter | bf6264a5 | 2018-04-06 02:39:33 | [diff] [blame] | 754 | if (!IsExtensionProcessSharingAllowed()) { |
nick | 92b0458 | 2016-04-08 02:54:04 | [diff] [blame] | 755 | EXPECT_EQ(kNumExtensions, processes.size()) << "Extension process reuse is " |
Nick Carter | bf6264a5 | 2018-04-06 02:39:33 | [diff] [blame] | 756 | "expected to be disabled."; |
nick | 92b0458 | 2016-04-08 02:54:04 | [diff] [blame] | 757 | } else { |
| 758 | EXPECT_LT(processes.size(), kNumExtensions) |
| 759 | << "Expected extension process reuse, but none happened."; |
| 760 | } |
| 761 | |
| 762 | // Interact with each extension background page by setting and reading back |
| 763 | // the cookie. This would fail for one of the two extensions in a shared |
| 764 | // process, if that process is locked to a single origin. This is a regression |
| 765 | // test for http://crbug.com/600441. |
| 766 | for (const Extension* extension : installed_extensions) { |
| 767 | content::DOMMessageQueue queue; |
| 768 | ExecuteScriptInBackgroundPageNoWait( |
| 769 | extension->id(), |
| 770 | "document.cookie = 'extension_cookie';" |
| 771 | "window.domAutomationController.send(document.cookie);"); |
| 772 | std::string message; |
| 773 | ASSERT_TRUE(queue.WaitForMessage(&message)); |
| 774 | EXPECT_EQ(message, "\"extension_cookie\""); |
| 775 | } |
| 776 | } |
| 777 | |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 778 | // Test that navigations to blob: and filesystem: URLs with extension origins |
| 779 | // are disallowed when initiated from non-extension processes. See |
| 780 | // https://crbug.com/645028 and https://crbug.com/644426. |
| 781 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
Alex Moshchuk | d2a81fe2 | 2018-05-07 17:35:44 | [diff] [blame] | 782 | NestedURLNavigationsToExtensionBlocked) { |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 783 | // Disabling web security is necessary to test the browser enforcement; |
| 784 | // without it, the loads in this test would be blocked by |
| 785 | // SecurityOrigin::canDisplay() as invalid local resource loads. |
| 786 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 787 | prefs->SetBoolean(prefs::kWebKitWebSecurityEnabled, false); |
| 788 | |
| 789 | // Create a simple extension without a background page. |
| 790 | const Extension* extension = CreateExtension("Extension", false); |
| 791 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 792 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 793 | |
| 794 | // Navigate main tab to a web page with two web iframes. There should be no |
| 795 | // extension frames yet. |
| 796 | NavigateToURL(embedded_test_server()->GetURL("/two_iframes.html")); |
| 797 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 798 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 799 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 800 | |
| 801 | content::WebContents* tab = |
| 802 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 803 | |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 804 | // Navigate first subframe to an extension URL. This will go into a new |
| 805 | // extension process. |
Daniel Cheng | 4ebba55 | 2018-07-06 21:43:16 | [diff] [blame] | 806 | const GURL extension_empty_resource(extension->url().Resolve("empty.html")); |
| 807 | EXPECT_TRUE( |
| 808 | content::NavigateIframeToURL(tab, "frame1", extension_empty_resource)); |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 809 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 810 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 811 | |
| 812 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 813 | content::RenderFrameHost* extension_frame = ChildFrameAt(main_frame, 0); |
| 814 | |
Daniel Cheng | 4ebba55 | 2018-07-06 21:43:16 | [diff] [blame] | 815 | // Ideally, this would be a GURL, but it's easier to compose the rest of the |
| 816 | // URLs if this is a std::string. Meh. |
| 817 | const std::string extension_base_url = |
| 818 | base::StrCat({"chrome-extension://", extension->id()}); |
| 819 | const GURL extension_blob_url = |
| 820 | GURL(base::StrCat({"blob:", extension_base_url, "/some-guid"})); |
| 821 | const GURL extension_file_system_url = |
| 822 | GURL(base::StrCat({"filesystem:", extension_base_url, "/some-path"})); |
| 823 | const GURL extension_url = |
| 824 | GURL(base::StrCat({extension_base_url, "/some-path"})); |
| 825 | |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 826 | // Validate that permissions have been granted for the extension scheme |
| 827 | // to the process of the extension iframe. |
| 828 | content::ChildProcessSecurityPolicy* policy = |
| 829 | content::ChildProcessSecurityPolicy::GetInstance(); |
Daniel Cheng | 4ebba55 | 2018-07-06 21:43:16 | [diff] [blame] | 830 | EXPECT_TRUE(policy->CanRequestURL(extension_frame->GetProcess()->GetID(), |
| 831 | extension_blob_url)); |
| 832 | EXPECT_TRUE(policy->CanRequestURL(main_frame->GetProcess()->GetID(), |
| 833 | extension_blob_url)); |
| 834 | EXPECT_TRUE(policy->CanRequestURL(extension_frame->GetProcess()->GetID(), |
| 835 | extension_file_system_url)); |
| 836 | EXPECT_TRUE(policy->CanRequestURL(main_frame->GetProcess()->GetID(), |
| 837 | extension_file_system_url)); |
| 838 | EXPECT_TRUE(policy->CanRequestURL(extension_frame->GetProcess()->GetID(), |
| 839 | extension_url)); |
| 840 | EXPECT_TRUE( |
| 841 | policy->CanRequestURL(main_frame->GetProcess()->GetID(), extension_url)); |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 842 | |
Daniel Cheng | 4ebba55 | 2018-07-06 21:43:16 | [diff] [blame] | 843 | EXPECT_TRUE(policy->CanCommitURL(extension_frame->GetProcess()->GetID(), |
| 844 | extension_blob_url)); |
| 845 | EXPECT_FALSE(policy->CanCommitURL(main_frame->GetProcess()->GetID(), |
| 846 | extension_blob_url)); |
| 847 | EXPECT_TRUE(policy->CanCommitURL(extension_frame->GetProcess()->GetID(), |
| 848 | extension_file_system_url)); |
| 849 | EXPECT_FALSE(policy->CanCommitURL(main_frame->GetProcess()->GetID(), |
| 850 | extension_file_system_url)); |
| 851 | EXPECT_TRUE(policy->CanCommitURL(extension_frame->GetProcess()->GetID(), |
| 852 | extension_url)); |
| 853 | EXPECT_FALSE( |
| 854 | policy->CanCommitURL(main_frame->GetProcess()->GetID(), extension_url)); |
nick | 2a8ba8c | 2016-10-03 18:51:39 | [diff] [blame] | 855 | |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 856 | // Open a new about:blank popup from main frame. This should stay in the web |
| 857 | // process. |
| 858 | content::WebContents* popup = |
| 859 | OpenPopup(main_frame, GURL(url::kAboutBlankURL)); |
| 860 | EXPECT_NE(popup, tab); |
| 861 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 862 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 863 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 864 | |
| 865 | // Create valid blob and filesystem URLs in the extension's origin. |
| 866 | url::Origin extension_origin(extension_frame->GetLastCommittedOrigin()); |
| 867 | GURL blob_url(CreateBlobURL(extension_frame, "foo")); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 868 | EXPECT_EQ(extension_origin, url::Origin::Create(blob_url)); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 869 | GURL filesystem_url(CreateFileSystemURL(extension_frame, "foo")); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 870 | EXPECT_EQ(extension_origin, url::Origin::Create(filesystem_url)); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 871 | |
| 872 | // Navigate the popup to each nested URL with extension origin. |
| 873 | GURL nested_urls[] = {blob_url, filesystem_url}; |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 874 | for (size_t i = 0; i < base::size(nested_urls); i++) { |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 875 | EXPECT_TRUE(ExecuteScript( |
| 876 | popup, "location.href = '" + nested_urls[i].spec() + "';")); |
Alex Moshchuk | d2a81fe2 | 2018-05-07 17:35:44 | [diff] [blame] | 877 | |
| 878 | // If a navigation was started, wait for it to finish. This can't just use |
| 879 | // a TestNavigationObserver, since after https://crbug.com/811558 blob: and |
| 880 | // filesystem: navigations have different failure modes: blob URLs will be |
| 881 | // blocked on the browser side, and filesystem URLs on the renderer side, |
| 882 | // without notifying the browser. Since these navigations are scheduled in |
| 883 | // Blink, run a dummy script on the renderer to ensure that the navigation, |
| 884 | // if started, has made it to the browser process before we call |
| 885 | // WaitForLoadStop(). |
| 886 | EXPECT_TRUE(ExecuteScript(popup, "true")); |
| 887 | EXPECT_TRUE(content::WaitForLoadStop(popup)); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 888 | |
| 889 | // This is a top-level navigation that should be blocked since it |
| 890 | // originates from a non-extension process. Ensure that the error page |
| 891 | // doesn't commit an extension URL or origin. |
| 892 | EXPECT_NE(nested_urls[i], popup->GetLastCommittedURL()); |
| 893 | EXPECT_FALSE(extension_origin.IsSameOriginWith( |
| 894 | popup->GetMainFrame()->GetLastCommittedOrigin())); |
| 895 | EXPECT_NE("foo", GetTextContent(popup->GetMainFrame())); |
| 896 | |
nasko | abed2a5 | 2017-05-03 05:10:17 | [diff] [blame] | 897 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 898 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 899 | } |
| 900 | |
Alex Moshchuk | d2a81fe2 | 2018-05-07 17:35:44 | [diff] [blame] | 901 | // Close the popup. It won't be needed anymore, and bringing the original |
| 902 | // page back into foreground makes the remainder of this test a bit faster. |
| 903 | popup->Close(); |
| 904 | |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 905 | // Navigate second subframe to each nested URL from the main frame (i.e., |
nick | 6cfe5c7 | 2017-05-22 22:00:42 | [diff] [blame] | 906 | // from non-extension process). These should be canceled. |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 907 | for (size_t i = 0; i < base::size(nested_urls); i++) { |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 908 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame2", nested_urls[i])); |
| 909 | content::RenderFrameHost* second_frame = ChildFrameAt(main_frame, 1); |
nick | 6cfe5c7 | 2017-05-22 22:00:42 | [diff] [blame] | 910 | |
| 911 | EXPECT_NE(nested_urls[i], second_frame->GetLastCommittedURL()); |
| 912 | EXPECT_FALSE(extension_origin.IsSameOriginWith( |
| 913 | second_frame->GetLastCommittedOrigin())); |
| 914 | EXPECT_NE("foo", GetTextContent(second_frame)); |
| 915 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 916 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 917 | |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 918 | EXPECT_TRUE( |
| 919 | content::NavigateIframeToURL(tab, "frame2", GURL(url::kAboutBlankURL))); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 920 | } |
Alex Moshchuk | d2a81fe2 | 2018-05-07 17:35:44 | [diff] [blame] | 921 | } |
Jochen Eisinger | 68fb064 | 2018-01-17 21:56:45 | [diff] [blame] | 922 | |
Alex Moshchuk | d8fb84f | 2019-06-07 22:53:55 | [diff] [blame] | 923 | // Check that browser-side restrictions on extension blob URLs allow |
Alex Moshchuk | d2a81fe2 | 2018-05-07 17:35:44 | [diff] [blame] | 924 | // navigations that will result in downloads. See https://crbug.com/714373. |
| 925 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
Alex Moshchuk | d8fb84f | 2019-06-07 22:53:55 | [diff] [blame] | 926 | BlobURLDownloadsToExtensionAllowed) { |
Alex Moshchuk | d2a81fe2 | 2018-05-07 17:35:44 | [diff] [blame] | 927 | // Disabling web security is necessary to test the browser enforcement; |
| 928 | // without it, the loads in this test would be blocked by |
| 929 | // SecurityOrigin::CanDisplay() as invalid local resource loads. |
| 930 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 931 | prefs->SetBoolean(prefs::kWebKitWebSecurityEnabled, false); |
| 932 | |
| 933 | // Create a simple extension without a background page. |
| 934 | const Extension* extension = CreateExtension("Extension", false); |
| 935 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 936 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 937 | |
| 938 | // Navigate main tab to a web page an iframe. There should be no extension |
| 939 | // frames yet. |
| 940 | NavigateToURL(embedded_test_server()->GetURL("/blank_iframe.html")); |
| 941 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 942 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 943 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 944 | |
| 945 | content::WebContents* tab = |
| 946 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 947 | |
| 948 | // Navigate iframe to an extension URL. |
| 949 | const GURL extension_url(extension->url().Resolve("empty.html")); |
| 950 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame0", extension_url)); |
| 951 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 952 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 953 | |
| 954 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 955 | content::RenderFrameHost* extension_frame = ChildFrameAt(main_frame, 0); |
| 956 | |
Alex Moshchuk | d8fb84f | 2019-06-07 22:53:55 | [diff] [blame] | 957 | // Create a valid blob URL in the extension's origin. |
Alex Moshchuk | d2a81fe2 | 2018-05-07 17:35:44 | [diff] [blame] | 958 | url::Origin extension_origin(extension_frame->GetLastCommittedOrigin()); |
| 959 | GURL blob_url(CreateBlobURL(extension_frame, "foo")); |
| 960 | EXPECT_EQ(extension_origin, url::Origin::Create(blob_url)); |
Alex Moshchuk | d2a81fe2 | 2018-05-07 17:35:44 | [diff] [blame] | 961 | |
Alex Moshchuk | d8fb84f | 2019-06-07 22:53:55 | [diff] [blame] | 962 | // Check that extension blob URLs still can be downloaded via an HTML anchor |
| 963 | // tag with the download attribute (i.e., <a download>) (which starts out as |
| 964 | // a top-level navigation). |
Jochen Eisinger | 68fb064 | 2018-01-17 21:56:45 | [diff] [blame] | 965 | PermissionRequestManager* permission_request_manager = |
Alex Moshchuk | d2a81fe2 | 2018-05-07 17:35:44 | [diff] [blame] | 966 | PermissionRequestManager::FromWebContents(tab); |
Jochen Eisinger | 68fb064 | 2018-01-17 21:56:45 | [diff] [blame] | 967 | permission_request_manager->set_auto_response_for_test( |
| 968 | PermissionRequestManager::ACCEPT_ALL); |
Jochen Eisinger | 68fb064 | 2018-01-17 21:56:45 | [diff] [blame] | 969 | |
Alex Moshchuk | d8fb84f | 2019-06-07 22:53:55 | [diff] [blame] | 970 | content::DownloadTestObserverTerminal observer( |
| 971 | content::BrowserContext::GetDownloadManager(profile()), 1, |
| 972 | content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 973 | std::string script = base::StringPrintf( |
| 974 | R"(var anchor = document.createElement('a'); |
| 975 | anchor.href = '%s'; |
| 976 | anchor.download = ''; |
| 977 | anchor.click();)", |
| 978 | blob_url.spec().c_str()); |
| 979 | EXPECT_TRUE(ExecuteScript(tab, script)); |
| 980 | observer.WaitForFinished(); |
| 981 | EXPECT_EQ(1u, |
| 982 | observer.NumDownloadsSeenInState(download::DownloadItem::COMPLETE)); |
Jochen Eisinger | 68fb064 | 2018-01-17 21:56:45 | [diff] [blame] | 983 | |
Alex Moshchuk | d8fb84f | 2019-06-07 22:53:55 | [diff] [blame] | 984 | // This is a top-level navigation that should have resulted in a download. |
| 985 | // Ensure that the tab stayed at its original location. |
| 986 | EXPECT_NE(blob_url, tab->GetLastCommittedURL()); |
| 987 | EXPECT_FALSE( |
| 988 | extension_origin.IsSameOriginWith(main_frame->GetLastCommittedOrigin())); |
| 989 | EXPECT_NE("foo", GetTextContent(main_frame)); |
| 990 | |
| 991 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 992 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | // Test that navigations to blob: and filesystem: URLs with extension origins |
Charlie Reis | 7614790 | 2018-04-26 01:21:07 | [diff] [blame] | 996 | // are disallowed in subframes when initiated from non-extension processes, even |
| 997 | // when the main frame lies about its origin. See https://crbug.com/836858. |
| 998 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 999 | NestedURLNavigationsToExtensionBlockedInSubframe) { |
| 1000 | // Disabling web security is necessary to test the browser enforcement; |
| 1001 | // without it, the loads in this test would be blocked by |
| 1002 | // SecurityOrigin::canDisplay() as invalid local resource loads. |
| 1003 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 1004 | prefs->SetBoolean(prefs::kWebKitWebSecurityEnabled, false); |
| 1005 | |
| 1006 | // Create a simple extension without a background page. |
| 1007 | const Extension* extension = CreateExtension("Extension", false); |
| 1008 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 1009 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1010 | |
| 1011 | // Navigate main tab to a web page with two web iframes. There should be no |
| 1012 | // extension frames yet. |
| 1013 | NavigateToURL(embedded_test_server()->GetURL("/two_iframes.html")); |
| 1014 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1015 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1016 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1017 | |
| 1018 | content::WebContents* tab = |
| 1019 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1020 | |
| 1021 | // Navigate first subframe to an extension URL. This will go into a new |
| 1022 | // extension process. |
| 1023 | const GURL extension_url(extension->url().Resolve("empty.html")); |
| 1024 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame1", extension_url)); |
| 1025 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1026 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 1027 | |
| 1028 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 1029 | content::RenderFrameHost* extension_frame = ChildFrameAt(main_frame, 0); |
| 1030 | |
| 1031 | // Create valid blob and filesystem URLs in the extension's origin. |
| 1032 | url::Origin extension_origin(extension_frame->GetLastCommittedOrigin()); |
| 1033 | GURL blob_url(CreateBlobURL(extension_frame, "foo")); |
| 1034 | EXPECT_EQ(extension_origin, url::Origin::Create(blob_url)); |
| 1035 | GURL filesystem_url(CreateFileSystemURL(extension_frame, "foo")); |
| 1036 | EXPECT_EQ(extension_origin, url::Origin::Create(filesystem_url)); |
| 1037 | |
| 1038 | // Suppose that the main frame's origin incorrectly claims it is an extension, |
| 1039 | // even though it is not in an extension process. This used to bypass the |
| 1040 | // checks in ExtensionNavigationThrottle. |
| 1041 | OverrideLastCommittedOrigin(main_frame, extension_origin); |
| 1042 | |
| 1043 | // Navigate second subframe to each nested URL from the main frame (i.e., |
| 1044 | // from non-extension process). These should be canceled. |
| 1045 | GURL nested_urls[] = {blob_url, filesystem_url}; |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 1046 | for (size_t i = 0; i < base::size(nested_urls); i++) { |
Charlie Reis | 7614790 | 2018-04-26 01:21:07 | [diff] [blame] | 1047 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame2", nested_urls[i])); |
| 1048 | content::RenderFrameHost* second_frame = ChildFrameAt(main_frame, 1); |
| 1049 | |
| 1050 | EXPECT_NE(nested_urls[i], second_frame->GetLastCommittedURL()); |
| 1051 | EXPECT_FALSE(extension_origin.IsSameOriginWith( |
| 1052 | second_frame->GetLastCommittedOrigin())); |
| 1053 | EXPECT_NE("foo", GetTextContent(second_frame)); |
| 1054 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1055 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 1056 | |
| 1057 | EXPECT_TRUE( |
| 1058 | content::NavigateIframeToURL(tab, "frame2", GURL(url::kAboutBlankURL))); |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | // Test that navigations to blob: and filesystem: URLs with extension origins |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 1063 | // are allowed when initiated from extension processes. See |
| 1064 | // https://crbug.com/645028 and https://crbug.com/644426. |
| 1065 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 1066 | NestedURLNavigationsToExtensionAllowed) { |
| 1067 | // Create a simple extension without a background page. |
| 1068 | const Extension* extension = CreateExtension("Extension", false); |
| 1069 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 1070 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1071 | |
| 1072 | // Navigate main tab to an extension URL with a blank subframe. |
| 1073 | const GURL extension_url(extension->url().Resolve("blank_iframe.html")); |
| 1074 | NavigateToURL(extension_url); |
| 1075 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1076 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
| 1077 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1078 | |
| 1079 | content::WebContents* tab = |
| 1080 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1081 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 1082 | |
| 1083 | // Create blob and filesystem URLs in the extension's origin. |
| 1084 | url::Origin extension_origin(main_frame->GetLastCommittedOrigin()); |
| 1085 | GURL blob_url(CreateBlobURL(main_frame, "foo")); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 1086 | EXPECT_EQ(extension_origin, url::Origin::Create(blob_url)); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 1087 | GURL filesystem_url(CreateFileSystemURL(main_frame, "foo")); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 1088 | EXPECT_EQ(extension_origin, url::Origin::Create(filesystem_url)); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 1089 | |
| 1090 | // From the main frame, navigate its subframe to each nested URL. This |
| 1091 | // should be allowed and should stay in the extension process. |
| 1092 | GURL nested_urls[] = {blob_url, filesystem_url}; |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 1093 | for (size_t i = 0; i < base::size(nested_urls); i++) { |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 1094 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame0", nested_urls[i])); |
| 1095 | content::RenderFrameHost* child = ChildFrameAt(main_frame, 0); |
| 1096 | EXPECT_EQ(nested_urls[i], child->GetLastCommittedURL()); |
| 1097 | EXPECT_EQ(extension_origin, child->GetLastCommittedOrigin()); |
| 1098 | EXPECT_EQ("foo", GetTextContent(child)); |
| 1099 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1100 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
| 1101 | } |
| 1102 | |
Mustafa Emre Acer | 5440020 | 2018-04-30 19:38:11 | [diff] [blame] | 1103 | // From the main frame, create a blank popup and navigate it to the nested |
| 1104 | // blob URL. This should also be allowed, since the navigation originated from |
| 1105 | // an extension process. |
| 1106 | { |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 1107 | content::WebContents* popup = |
| 1108 | OpenPopup(main_frame, GURL(url::kAboutBlankURL)); |
| 1109 | EXPECT_NE(popup, tab); |
| 1110 | |
| 1111 | content::TestNavigationObserver observer(popup); |
| 1112 | EXPECT_TRUE(ExecuteScript( |
Mustafa Emre Acer | 5440020 | 2018-04-30 19:38:11 | [diff] [blame] | 1113 | popup, "location.href = '" + nested_urls[0].spec() + "';")); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 1114 | observer.Wait(); |
| 1115 | |
Mustafa Emre Acer | 5440020 | 2018-04-30 19:38:11 | [diff] [blame] | 1116 | EXPECT_EQ(nested_urls[0], popup->GetLastCommittedURL()); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 1117 | EXPECT_EQ(extension_origin, |
| 1118 | popup->GetMainFrame()->GetLastCommittedOrigin()); |
| 1119 | EXPECT_EQ("foo", GetTextContent(popup->GetMainFrame())); |
| 1120 | |
Mustafa Emre Acer | 5440020 | 2018-04-30 19:38:11 | [diff] [blame] | 1121 | EXPECT_EQ(3u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1122 | EXPECT_EQ(3u, pm->GetAllFrames().size()); |
| 1123 | } |
| 1124 | |
| 1125 | // Same as above, but renderers cannot navigate top frame to filesystem URLs. |
| 1126 | // So this will result in a console message. |
| 1127 | { |
| 1128 | content::WebContents* popup = |
| 1129 | OpenPopup(main_frame, GURL(url::kAboutBlankURL)); |
| 1130 | EXPECT_NE(popup, tab); |
| 1131 | |
| 1132 | content::ConsoleObserverDelegate console_observer( |
| 1133 | popup, "Not allowed to navigate top frame to*"); |
| 1134 | popup->SetDelegate(&console_observer); |
| 1135 | EXPECT_TRUE(ExecuteScript( |
| 1136 | popup, "location.href = '" + nested_urls[1].spec() + "';")); |
| 1137 | console_observer.Wait(); |
| 1138 | |
| 1139 | // about:blank URLs can be modified by their opener. In that case their |
| 1140 | // effective origin changes to that of the opener, but the page URL remains |
| 1141 | // about:blank. Here the popup is being modified by the extension page, |
| 1142 | // so it's origin will change to the extension URL. |
| 1143 | EXPECT_EQ(GURL(url::kAboutBlankURL), popup->GetLastCommittedURL()); |
| 1144 | EXPECT_EQ(extension_origin, |
| 1145 | popup->GetMainFrame()->GetLastCommittedOrigin()); |
| 1146 | EXPECT_EQ(std::string(), GetTextContent(popup->GetMainFrame())); |
| 1147 | |
| 1148 | EXPECT_EQ(4u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1149 | EXPECT_EQ(4u, pm->GetAllFrames().size()); |
alexmos | 4bfdc92 | 2016-09-15 22:40:54 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1153 | // Test that navigations to blob: and filesystem: URLs with extension origins |
| 1154 | // are disallowed in an unprivileged, non-guest web process when the extension |
| 1155 | // origin corresponds to a Chrome app with the "webview" permission. See |
| 1156 | // https://crbug.com/656752. These requests should still be allowed inside |
| 1157 | // actual <webview> guest processes created by a Chrome app; this is checked in |
| 1158 | // WebViewTest.Shim_TestBlobURL. |
Nasko Oskov | 83bb45e | 2019-01-04 22:46:08 | [diff] [blame] | 1159 | // TODO(alexmos): Enable this test once checks are implemented in the |
| 1160 | // extensions NavigationThrottle. See https://crbug.com/919194. |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1161 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
Nasko Oskov | 83bb45e | 2019-01-04 22:46:08 | [diff] [blame] | 1162 | DISABLED_NestedURLNavigationsToAppBlocked) { |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1163 | // Disabling web security is necessary to test the browser enforcement; |
| 1164 | // without it, the loads in this test would be blocked by |
| 1165 | // SecurityOrigin::canDisplay() as invalid local resource loads. |
| 1166 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 1167 | prefs->SetBoolean(prefs::kWebKitWebSecurityEnabled, false); |
| 1168 | |
| 1169 | // Load a simple app that has the "webview" permission. The app will also |
| 1170 | // open a <webview> when it's loaded. |
| 1171 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1172 | base::FilePath dir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 1173 | base::PathService::Get(chrome::DIR_TEST_DATA, &dir); |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1174 | dir = dir.AppendASCII("extensions") |
| 1175 | .AppendASCII("platform_apps") |
| 1176 | .AppendASCII("web_view") |
| 1177 | .AppendASCII("simple"); |
| 1178 | const Extension* app = LoadAndLaunchApp(dir); |
| 1179 | EXPECT_TRUE(app->permissions_data()->HasAPIPermission( |
| 1180 | extensions::APIPermission::kWebView)); |
| 1181 | |
| 1182 | auto app_windows = AppWindowRegistry::Get(browser()->profile()) |
| 1183 | ->GetAppWindowsForApp(app->id()); |
| 1184 | EXPECT_EQ(1u, app_windows.size()); |
| 1185 | content::WebContents* app_tab = (*app_windows.begin())->web_contents(); |
| 1186 | content::RenderFrameHost* app_rfh = app_tab->GetMainFrame(); |
| 1187 | url::Origin app_origin(app_rfh->GetLastCommittedOrigin()); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 1188 | EXPECT_EQ(url::Origin::Create(app->url()), app_rfh->GetLastCommittedOrigin()); |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1189 | |
| 1190 | // Wait for the app's guest WebContents to load. |
| 1191 | guest_view::TestGuestViewManager* guest_manager = |
| 1192 | static_cast<guest_view::TestGuestViewManager*>( |
| 1193 | guest_view::TestGuestViewManager::FromBrowserContext( |
| 1194 | browser()->profile())); |
| 1195 | content::WebContents* guest = guest_manager->WaitForSingleGuestCreated(); |
Lucas Furukawa Gadani | 565f657 | 2017-06-07 22:17:40 | [diff] [blame] | 1196 | guest_manager->WaitUntilAttached(guest); |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1197 | |
| 1198 | // There should be two extension frames in ProcessManager: the app's main |
| 1199 | // page and the background page. |
| 1200 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1201 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
| 1202 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(app->id()).size()); |
| 1203 | |
| 1204 | // Create valid blob and filesystem URLs in the app's origin. |
| 1205 | GURL blob_url(CreateBlobURL(app_rfh, "foo")); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 1206 | EXPECT_EQ(app_origin, url::Origin::Create(blob_url)); |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1207 | GURL filesystem_url(CreateFileSystemURL(app_rfh, "foo")); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 1208 | EXPECT_EQ(app_origin, url::Origin::Create(filesystem_url)); |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1209 | |
| 1210 | // Create a new tab, unrelated to the app, and navigate it to a web URL. |
| 1211 | chrome::NewTab(browser()); |
| 1212 | content::WebContents* web_tab = |
| 1213 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1214 | GURL web_url(embedded_test_server()->GetURL("/title1.html")); |
| 1215 | ui_test_utils::NavigateToURL(browser(), web_url); |
| 1216 | EXPECT_NE(web_tab, app_tab); |
| 1217 | EXPECT_NE(web_tab->GetMainFrame()->GetProcess(), app_rfh->GetProcess()); |
| 1218 | |
| 1219 | // The web process shouldn't have permission to request URLs in the app's |
| 1220 | // origin, but the guest process should. |
| 1221 | content::ChildProcessSecurityPolicy* policy = |
| 1222 | content::ChildProcessSecurityPolicy::GetInstance(); |
Daniel Cheng | 4ebba55 | 2018-07-06 21:43:16 | [diff] [blame] | 1223 | EXPECT_FALSE(policy->CanRequestURL( |
| 1224 | web_tab->GetMainFrame()->GetProcess()->GetID(), app_origin.GetURL())); |
| 1225 | EXPECT_TRUE(policy->CanRequestURL( |
| 1226 | guest->GetMainFrame()->GetProcess()->GetID(), app_origin.GetURL())); |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1227 | |
| 1228 | // Try navigating the web tab to each nested URL with the app's origin. This |
| 1229 | // should be blocked. |
| 1230 | GURL nested_urls[] = {blob_url, filesystem_url}; |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 1231 | for (size_t i = 0; i < base::size(nested_urls); i++) { |
alexmos | f7af135 | 2016-10-21 20:00:41 | [diff] [blame] | 1232 | content::TestNavigationObserver observer(web_tab); |
| 1233 | EXPECT_TRUE(ExecuteScript( |
| 1234 | web_tab, "location.href = '" + nested_urls[i].spec() + "';")); |
| 1235 | observer.Wait(); |
| 1236 | EXPECT_NE(nested_urls[i], web_tab->GetLastCommittedURL()); |
| 1237 | EXPECT_FALSE(app_origin.IsSameOriginWith( |
| 1238 | web_tab->GetMainFrame()->GetLastCommittedOrigin())); |
| 1239 | EXPECT_NE("foo", GetTextContent(web_tab->GetMainFrame())); |
| 1240 | EXPECT_NE(web_tab->GetMainFrame()->GetProcess(), app_rfh->GetProcess()); |
| 1241 | |
| 1242 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
| 1243 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(app->id()).size()); |
| 1244 | } |
| 1245 | } |
| 1246 | |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1247 | // Test that a web frame can't navigate a proxy for an extension frame to a |
| 1248 | // blob/filesystem extension URL. See https://crbug.com/656752. |
| 1249 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
Nick Carter | ac31d43 | 2018-03-16 23:38:35 | [diff] [blame] | 1250 | NestedURLNavigationsViaProxyBlocked) { |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 1251 | // Create a simple extension without a background page. |
| 1252 | const Extension* extension = CreateExtension("Extension", false); |
| 1253 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 1254 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1255 | |
| 1256 | // Navigate main tab to an empty web page. There should be no extension |
| 1257 | // frames yet. |
| 1258 | NavigateToURL(embedded_test_server()->GetURL("/empty.html")); |
| 1259 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1260 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1261 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1262 | |
| 1263 | content::WebContents* tab = |
| 1264 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1265 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 1266 | |
| 1267 | // Have the web page navigate the popup to each nested URL with extension |
| 1268 | // origin via the window reference it obtained earlier from window.open. |
| 1269 | const GURL extension_url(extension->url().Resolve("empty.html")); |
| 1270 | for (auto create_function : {&CreateBlobURL, &CreateFileSystemURL}) { |
| 1271 | // Setup the test by navigating popup to an extension page. This is allowed |
| 1272 | // because it's web accessible. |
| 1273 | content::WebContents* popup = OpenPopup(main_frame, extension_url); |
| 1274 | |
| 1275 | // This frame should now be in an extension process. |
| 1276 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 1277 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1278 | |
| 1279 | // Create a valid blob or filesystem URL in the extension's origin. |
| 1280 | GURL nested_url = (*create_function)(popup->GetMainFrame(), "foo"); |
| 1281 | |
| 1282 | // Navigate via the proxy to |nested_url|. This should be blocked by |
| 1283 | // FilterURL. |
| 1284 | EXPECT_TRUE(ExecuteScript( |
| 1285 | tab, "window.popup.location.href = '" + nested_url.spec() + "';")); |
| 1286 | WaitForLoadStop(popup); |
| 1287 | |
Nick Carter | d2e4acf | 2018-03-30 22:13:29 | [diff] [blame] | 1288 | // Because the navigation was blocked, the URL doesn't change. |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 1289 | EXPECT_NE(nested_url, popup->GetLastCommittedURL()); |
Nick Carter | d2e4acf | 2018-03-30 22:13:29 | [diff] [blame] | 1290 | EXPECT_EQ(extension_url, popup->GetLastCommittedURL().spec()); |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 1291 | EXPECT_NE("foo", GetTextContent(popup->GetMainFrame())); |
Nick Carter | d2e4acf | 2018-03-30 22:13:29 | [diff] [blame] | 1292 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1293 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 1294 | popup->Close(); |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 1295 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1296 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1297 | } |
| 1298 | } |
| 1299 | |
Elly Fong-Jones | d47cd17a | 2019-12-03 16:18:51 | [diff] [blame] | 1300 | // TODO(crbug.com/909570): This test is flaky everywhere. |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 1301 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
Elly Fong-Jones | d47cd17a | 2019-12-03 16:18:51 | [diff] [blame] | 1302 | DISABLED_NestedURLNavigationsViaNoOpenerPopupBlocked) { |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1303 | // Create a simple extension without a background page. |
| 1304 | const Extension* extension = CreateExtension("Extension", false); |
| 1305 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 1306 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1307 | |
| 1308 | // Navigate main tab to an empty web page. There should be no extension |
| 1309 | // frames yet. |
| 1310 | NavigateToURL(embedded_test_server()->GetURL("/empty.html")); |
| 1311 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1312 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1313 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1314 | |
| 1315 | content::WebContents* tab = |
| 1316 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1317 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 1318 | |
| 1319 | // Open a new about:blank popup from main frame. This should stay in the web |
| 1320 | // process. |
| 1321 | content::WebContents* popup = |
| 1322 | OpenPopup(main_frame, GURL(url::kAboutBlankURL)); |
| 1323 | EXPECT_NE(popup, tab); |
| 1324 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 1325 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1326 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1327 | |
| 1328 | // Navigate popup to an extension page. |
| 1329 | const GURL extension_url(extension->url().Resolve("empty.html")); |
| 1330 | content::TestNavigationObserver observer(popup); |
| 1331 | EXPECT_TRUE( |
| 1332 | ExecuteScript(popup, "location.href = '" + extension_url.spec() + "';")); |
| 1333 | observer.Wait(); |
| 1334 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 1335 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1336 | content::RenderFrameHost* extension_frame = popup->GetMainFrame(); |
| 1337 | |
| 1338 | // Create valid blob and filesystem URLs in the extension's origin. |
| 1339 | url::Origin extension_origin(extension_frame->GetLastCommittedOrigin()); |
| 1340 | GURL blob_url(CreateBlobURL(extension_frame, "foo")); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 1341 | EXPECT_EQ(extension_origin, url::Origin::Create(blob_url)); |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1342 | GURL filesystem_url(CreateFileSystemURL(extension_frame, "foo")); |
Daniel Cheng | 88186bd5 | 2017-10-20 08:14:46 | [diff] [blame] | 1343 | EXPECT_EQ(extension_origin, url::Origin::Create(filesystem_url)); |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1344 | |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 1345 | // Attempt opening the nested urls using window.open(url, '', 'noopener'). |
| 1346 | // This should not be allowed. |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1347 | GURL nested_urls[] = {blob_url, filesystem_url}; |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 1348 | for (size_t i = 0; i < base::size(nested_urls); i++) { |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 1349 | content::WebContents* new_popup = |
| 1350 | OpenPopupNoOpener(tab->GetMainFrame(), nested_urls[i]); |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1351 | |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 1352 | // This is a top-level navigation to a local resource, that should be |
| 1353 | // blocked by FilterURL, since it originates from a non-extension process. |
| 1354 | EXPECT_NE(nested_urls[i], new_popup->GetLastCommittedURL()); |
| 1355 | EXPECT_EQ("about:blank", new_popup->GetLastCommittedURL().spec()); |
| 1356 | EXPECT_NE("foo", GetTextContent(new_popup->GetMainFrame())); |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1357 | |
| 1358 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1359 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1360 | |
Nick Carter | a6102ee | 2018-03-14 18:49:13 | [diff] [blame] | 1361 | new_popup->Close(); |
| 1362 | } |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1363 | } |
| 1364 | |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1365 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 1366 | ServerRedirectToNonWebAccessibleResource) { |
| 1367 | // Create a simple extension without a background page. |
| 1368 | const Extension* extension = CreateExtension("Extension", false); |
| 1369 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 1370 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1371 | |
| 1372 | // Navigate main tab to an empty web page. There should be no extension |
| 1373 | // frames yet. |
| 1374 | NavigateToURL(embedded_test_server()->GetURL("/empty.html")); |
| 1375 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1376 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1377 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1378 | |
| 1379 | content::WebContents* tab = |
| 1380 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1381 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 1382 | |
| 1383 | // For this extension, only "*.html" resources are listed as web accessible; |
| 1384 | // "manifest.json" doesn't match that pattern, so it shouldn't be possible for |
| 1385 | // a webpage to initiate such a navigation. |
| 1386 | const GURL inaccessible_extension_resource( |
| 1387 | extension->url().Resolve("manifest.json")); |
| 1388 | // This is an HTTP request that redirects to a non-webaccessible resource. |
| 1389 | const GURL redirect_to_inaccessible(embedded_test_server()->GetURL( |
| 1390 | "/server-redirect?" + inaccessible_extension_resource.spec())); |
| 1391 | content::WebContents* sneaky_popup = |
| 1392 | OpenPopup(main_frame, redirect_to_inaccessible, false); |
Lukasz Anforowicz | c805806 | 2019-10-01 20:13:02 | [diff] [blame] | 1393 | EXPECT_EQ(inaccessible_extension_resource, |
| 1394 | sneaky_popup->GetLastCommittedURL()); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1395 | EXPECT_EQ( |
| 1396 | content::PAGE_TYPE_ERROR, |
| 1397 | sneaky_popup->GetController().GetLastCommittedEntry()->GetPageType()); |
| 1398 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1399 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1400 | |
| 1401 | // Adding "noopener" to the navigation shouldn't make it work either. |
| 1402 | content::WebContents* sneaky_noopener_popup = |
| 1403 | OpenPopupNoOpener(main_frame, redirect_to_inaccessible); |
Lukasz Anforowicz | c805806 | 2019-10-01 20:13:02 | [diff] [blame] | 1404 | EXPECT_EQ(inaccessible_extension_resource, |
| 1405 | sneaky_noopener_popup->GetLastCommittedURL()); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1406 | EXPECT_EQ(content::PAGE_TYPE_ERROR, sneaky_noopener_popup->GetController() |
| 1407 | .GetLastCommittedEntry() |
| 1408 | ->GetPageType()); |
| 1409 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1410 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1411 | } |
| 1412 | |
| 1413 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 1414 | CrossExtensionEmbeddingOfWebAccessibleResources) { |
| 1415 | // Create a simple extension without a background page. |
| 1416 | const Extension* extension1 = CreateExtension("Extension 1", false); |
| 1417 | const Extension* extension2 = CreateExtension("Extension 2", false); |
| 1418 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1419 | |
| 1420 | // Navigate to the "extension 1" page with two iframes. |
| 1421 | NavigateToURL(extension1->url().Resolve("two_iframes.html")); |
| 1422 | |
| 1423 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1424 | content::WebContents* tab = |
| 1425 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1426 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 1427 | |
| 1428 | // Navigate the first iframe to a webaccessible resource of extension 2. This |
| 1429 | // should work. |
| 1430 | GURL extension2_empty = extension2->url().Resolve("/empty.html"); |
| 1431 | EXPECT_TRUE(WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 1432 | extension2, extension2_empty.path())); |
| 1433 | { |
| 1434 | content::RenderFrameDeletedObserver frame_deleted_observer( |
| 1435 | ChildFrameAt(main_frame, 0)); |
| 1436 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame1", extension2_empty)); |
| 1437 | EXPECT_EQ(extension2_empty, |
| 1438 | ChildFrameAt(main_frame, 0)->GetLastCommittedURL()); |
| 1439 | frame_deleted_observer.WaitUntilDeleted(); |
| 1440 | EXPECT_EQ(3u, pm->GetAllFrames().size()); |
| 1441 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
| 1442 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
| 1443 | } |
| 1444 | |
| 1445 | // Manifest.json is not a webaccessible resource. extension1 should not be |
| 1446 | // able to navigate to extension2's manifest.json. |
| 1447 | GURL extension2_manifest = extension2->url().Resolve("/manifest.json"); |
| 1448 | EXPECT_FALSE(WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 1449 | extension2, extension2_manifest.path())); |
| 1450 | { |
Lukasz Anforowicz | fc41749 | 2019-09-25 19:53:28 | [diff] [blame] | 1451 | content::TestNavigationObserver nav_observer(tab, 1); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1452 | EXPECT_TRUE(ExecuteScript( |
| 1453 | tab, base::StringPrintf("frames[0].location.href = '%s';", |
| 1454 | extension2_manifest.spec().c_str()))); |
Lukasz Anforowicz | fc41749 | 2019-09-25 19:53:28 | [diff] [blame] | 1455 | nav_observer.Wait(); |
| 1456 | EXPECT_FALSE(nav_observer.last_navigation_succeeded()); |
| 1457 | EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, nav_observer.last_net_error_code()); |
| 1458 | EXPECT_EQ(extension2_manifest, |
| 1459 | ChildFrameAt(main_frame, 0)->GetLastCommittedURL()); |
| 1460 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1461 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
Lukasz Anforowicz | fc41749 | 2019-09-25 19:53:28 | [diff] [blame] | 1462 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | // extension1 should not be able to navigate its second iframe to |
| 1466 | // extension2's manifest by bouncing off an HTTP redirect. |
| 1467 | const GURL sneaky_extension2_manifest(embedded_test_server()->GetURL( |
| 1468 | "/server-redirect?" + extension2_manifest.spec())); |
| 1469 | { |
Lukasz Anforowicz | c805806 | 2019-10-01 20:13:02 | [diff] [blame] | 1470 | content::TestNavigationObserver nav_observer(tab, 1); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1471 | EXPECT_TRUE(ExecuteScript( |
| 1472 | tab, base::StringPrintf("frames[1].location.href = '%s';", |
| 1473 | sneaky_extension2_manifest.spec().c_str()))); |
Lukasz Anforowicz | c805806 | 2019-10-01 20:13:02 | [diff] [blame] | 1474 | nav_observer.Wait(); |
| 1475 | EXPECT_FALSE(nav_observer.last_navigation_succeeded()) |
Nate Chapin | e6fd9fb | 2019-04-22 18:06:02 | [diff] [blame] | 1476 | << "The initial navigation should be allowed, but not the server " |
| 1477 | "redirect to extension2's manifest"; |
Lukasz Anforowicz | c805806 | 2019-10-01 20:13:02 | [diff] [blame] | 1478 | EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, nav_observer.last_net_error_code()); |
| 1479 | EXPECT_EQ(extension2_manifest, nav_observer.last_navigation_url()); |
| 1480 | EXPECT_EQ(extension2_manifest, |
| 1481 | ChildFrameAt(main_frame, 1)->GetLastCommittedURL()); |
Lukasz Anforowicz | fc41749 | 2019-09-25 19:53:28 | [diff] [blame] | 1482 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
Nate Chapin | e6fd9fb | 2019-04-22 18:06:02 | [diff] [blame] | 1483 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
Lukasz Anforowicz | fc41749 | 2019-09-25 19:53:28 | [diff] [blame] | 1484 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | // extension1 can embed a webaccessible resource of extension2 by means of |
| 1488 | // an HTTP redirect. |
| 1489 | { |
| 1490 | content::RenderFrameDeletedObserver frame_deleted_observer( |
| 1491 | ChildFrameAt(main_frame, 1)); |
| 1492 | const GURL extension2_accessible_redirect(embedded_test_server()->GetURL( |
| 1493 | "/server-redirect?" + extension2_empty.spec())); |
| 1494 | EXPECT_TRUE(ExecuteScript( |
| 1495 | tab, |
| 1496 | base::StringPrintf("frames[1].location.href = '%s';", |
| 1497 | extension2_accessible_redirect.spec().c_str()))); |
| 1498 | WaitForLoadStop(tab); |
| 1499 | frame_deleted_observer.WaitUntilDeleted(); |
| 1500 | EXPECT_EQ(extension2_empty, |
| 1501 | ChildFrameAt(main_frame, 1)->GetLastCommittedURL()) |
| 1502 | << "The URL of frames[1] should have changed"; |
Lukasz Anforowicz | fc41749 | 2019-09-25 19:53:28 | [diff] [blame] | 1503 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1504 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); |
Lukasz Anforowicz | fc41749 | 2019-09-25 19:53:28 | [diff] [blame] | 1505 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); |
Nick Carter | 1cb9c33c | 2018-03-30 18:40:07 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | |
alexmos | 1f48ef6 | 2016-10-06 00:51:50 | [diff] [blame] | 1509 | // Verify that a web popup created via window.open from an extension page can |
| 1510 | // communicate with the extension page via window.opener. See |
| 1511 | // https://crbug.com/590068. |
| 1512 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 1513 | WebPopupFromExtensionMainFrameHasValidOpener) { |
| 1514 | // Create a simple extension without a background page. |
| 1515 | const Extension* extension = CreateExtension("Extension", false); |
| 1516 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 1517 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1518 | |
| 1519 | // Navigate main tab to an extension page. |
| 1520 | NavigateToURL(extension->GetResourceURL("empty.html")); |
| 1521 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1522 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 1523 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1524 | |
| 1525 | content::WebContents* tab = |
| 1526 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1527 | |
| 1528 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 1529 | |
| 1530 | // Open a new web popup from the extension tab. The popup should go into a |
| 1531 | // new process. |
| 1532 | GURL popup_url(embedded_test_server()->GetURL("/empty.html")); |
| 1533 | content::WebContents* popup = OpenPopup(main_frame, popup_url); |
| 1534 | EXPECT_NE(popup, tab); |
| 1535 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
Lukasz Anforowicz | 3f0b84ca | 2017-09-28 13:02:37 | [diff] [blame] | 1536 | EXPECT_NE(popup->GetMainFrame()->GetProcess(), main_frame->GetProcess()); |
alexmos | 1f48ef6 | 2016-10-06 00:51:50 | [diff] [blame] | 1537 | |
| 1538 | // Ensure the popup's window.opener is defined. |
| 1539 | bool is_opener_defined = false; |
| 1540 | EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 1541 | popup, "window.domAutomationController.send(!!window.opener)", |
| 1542 | &is_opener_defined)); |
| 1543 | EXPECT_TRUE(is_opener_defined); |
| 1544 | |
| 1545 | // Verify that postMessage to window.opener works. |
| 1546 | VerifyPostMessageToOpener(popup->GetMainFrame(), main_frame); |
| 1547 | } |
| 1548 | |
| 1549 | // Verify that a web popup created via window.open from an extension subframe |
| 1550 | // can communicate with the extension page via window.opener. Similar to the |
| 1551 | // test above, but for subframes. See https://crbug.com/590068. |
| 1552 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 1553 | WebPopupFromExtensionSubframeHasValidOpener) { |
alexmos | 1f48ef6 | 2016-10-06 00:51:50 | [diff] [blame] | 1554 | // Create a simple extension without a background page. |
| 1555 | const Extension* extension = CreateExtension("Extension", false); |
| 1556 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 1557 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1558 | |
| 1559 | // Navigate main tab to a web page with a blank iframe. There should be no |
| 1560 | // extension frames yet. |
| 1561 | NavigateToURL(embedded_test_server()->GetURL("/blank_iframe.html")); |
| 1562 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1563 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1564 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1565 | |
| 1566 | content::WebContents* tab = |
| 1567 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1568 | |
| 1569 | // Navigate first subframe to an extension URL. |
| 1570 | const GURL extension_url(extension->GetResourceURL("empty.html")); |
| 1571 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame0", extension_url)); |
| 1572 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1573 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 1574 | |
| 1575 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 1576 | content::RenderFrameHost* extension_frame = ChildFrameAt(main_frame, 0); |
| 1577 | |
| 1578 | // Open a new web popup from extension frame. The popup should go into main |
| 1579 | // frame's web process. |
| 1580 | GURL popup_url(embedded_test_server()->GetURL("/empty.html")); |
| 1581 | content::WebContents* popup = OpenPopup(extension_frame, popup_url); |
| 1582 | EXPECT_NE(popup, tab); |
| 1583 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
Lukasz Anforowicz | 3f0b84ca | 2017-09-28 13:02:37 | [diff] [blame] | 1584 | EXPECT_NE(popup->GetMainFrame()->GetProcess(), extension_frame->GetProcess()); |
| 1585 | EXPECT_EQ(popup->GetMainFrame()->GetProcess(), main_frame->GetProcess()); |
alexmos | 1f48ef6 | 2016-10-06 00:51:50 | [diff] [blame] | 1586 | |
| 1587 | // Ensure the popup's window.opener is defined. |
| 1588 | bool is_opener_defined = false; |
| 1589 | EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 1590 | popup, "window.domAutomationController.send(!!window.opener)", |
| 1591 | &is_opener_defined)); |
| 1592 | EXPECT_TRUE(is_opener_defined); |
| 1593 | |
| 1594 | // Verify that postMessage to window.opener works. |
| 1595 | VerifyPostMessageToOpener(popup->GetMainFrame(), extension_frame); |
| 1596 | } |
| 1597 | |
alexmos | 24409702 | 2017-04-17 23:13:31 | [diff] [blame] | 1598 | // Test that when a web site has an extension iframe, navigating that iframe to |
| 1599 | // a different web site without --site-per-process will place it in the parent |
| 1600 | // frame's process. See https://crbug.com/711006. |
| 1601 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 1602 | ExtensionFrameNavigatesToParentSiteInstance) { |
| 1603 | // This test matters only *without* --site-per-process. |
| 1604 | if (content::AreAllSitesIsolatedForTesting()) |
| 1605 | return; |
| 1606 | |
alexmos | 24409702 | 2017-04-17 23:13:31 | [diff] [blame] | 1607 | // Create a simple extension without a background page. |
| 1608 | const Extension* extension = CreateExtension("Extension", false); |
| 1609 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 1610 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1611 | |
| 1612 | // Navigate main tab to a web page with a blank iframe. There should be no |
| 1613 | // extension frames yet. |
| 1614 | NavigateToURL(embedded_test_server()->GetURL("a.com", "/blank_iframe.html")); |
| 1615 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1616 | EXPECT_EQ(0u, pm->GetAllFrames().size()); |
| 1617 | EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1618 | |
| 1619 | content::WebContents* tab = |
| 1620 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1621 | |
| 1622 | // Navigate subframe to an extension URL. This should go into a new |
| 1623 | // extension process. |
| 1624 | const GURL extension_url(extension->url().Resolve("empty.html")); |
| 1625 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame0", extension_url)); |
| 1626 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1627 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 1628 | |
| 1629 | content::RenderFrameHost* main_frame = tab->GetMainFrame(); |
| 1630 | { |
| 1631 | content::RenderFrameHost* subframe = ChildFrameAt(main_frame, 0); |
| 1632 | EXPECT_NE(subframe->GetProcess(), main_frame->GetProcess()); |
| 1633 | EXPECT_NE(subframe->GetSiteInstance(), main_frame->GetSiteInstance()); |
| 1634 | } |
| 1635 | |
| 1636 | // Navigate subframe to b.com. This should be brought back to the parent |
| 1637 | // frame's (a.com) process. |
| 1638 | GURL b_url(embedded_test_server()->GetURL("b.com", "/empty.html")); |
| 1639 | EXPECT_TRUE(content::NavigateIframeToURL(tab, "frame0", b_url)); |
| 1640 | { |
| 1641 | content::RenderFrameHost* subframe = ChildFrameAt(main_frame, 0); |
| 1642 | EXPECT_EQ(subframe->GetProcess(), main_frame->GetProcess()); |
| 1643 | EXPECT_EQ(subframe->GetSiteInstance(), main_frame->GetSiteInstance()); |
| 1644 | } |
| 1645 | } |
| 1646 | |
Alex Moshchuk | 9c9e388 | 2018-11-02 19:57:03 | [diff] [blame] | 1647 | // Verify that web iframes on extension frames do not attempt to aggressively |
| 1648 | // reuse existing processes for the same site. This helps prevent a |
| 1649 | // misbehaving web iframe on an extension from slowing down other processes. |
| 1650 | // See https://crbug.com/899418. |
| 1651 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
| 1652 | WebSubframeOnExtensionDoesNotReuseExistingProcess) { |
| 1653 | // This test matters only *with* --site-per-process. It depends on process |
| 1654 | // reuse logic that subframes use to look for existing processes, but that |
| 1655 | // logic is only turned on for sites that require a dedicated process. |
| 1656 | if (!content::AreAllSitesIsolatedForTesting()) |
| 1657 | return; |
| 1658 | |
| 1659 | // Create a simple extension with a background page that has an empty iframe. |
| 1660 | const Extension* extension = CreateExtension("Extension", true); |
| 1661 | embedded_test_server()->ServeFilesFromDirectory(extension->path()); |
| 1662 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1663 | |
| 1664 | // Navigate main tab to a web page on foo.com. |
| 1665 | GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 1666 | NavigateToURL(foo_url); |
| 1667 | content::WebContents* tab = |
| 1668 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1669 | EXPECT_EQ(foo_url, tab->GetLastCommittedURL()); |
| 1670 | |
| 1671 | // So far, there should be two extension frames: one for the background page, |
| 1672 | // one for the empty subframe on it. |
| 1673 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1674 | EXPECT_EQ(2u, pm->GetAllFrames().size()); |
| 1675 | EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1676 | |
| 1677 | // Navigate the subframe on the extension background page to foo.com, and |
| 1678 | // wait for the old subframe to go away. |
| 1679 | ExtensionHost* background_host = |
| 1680 | pm->GetBackgroundHostForExtension(extension->id()); |
| 1681 | content::RenderFrameHost* background_rfh = |
| 1682 | background_host->host_contents()->GetMainFrame(); |
| 1683 | content::RenderFrameHost* extension_subframe = |
| 1684 | ChildFrameAt(background_rfh, 0); |
| 1685 | content::RenderFrameDeletedObserver deleted_observer(extension_subframe); |
| 1686 | EXPECT_TRUE( |
| 1687 | content::ExecJs(extension_subframe, |
| 1688 | content::JsReplace("window.location = $1;", foo_url))); |
| 1689 | deleted_observer.WaitUntilDeleted(); |
| 1690 | |
| 1691 | // There should now only be one extension frame for the background page. The |
| 1692 | // subframe should've swapped processes and should now be a web frame. |
| 1693 | EXPECT_EQ(1u, pm->GetAllFrames().size()); |
| 1694 | EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
| 1695 | content::RenderFrameHost* subframe = ChildFrameAt(background_rfh, 0); |
| 1696 | EXPECT_EQ(foo_url, subframe->GetLastCommittedURL()); |
| 1697 | |
| 1698 | // Verify that the subframe did *not* reuse the existing foo.com process. |
| 1699 | EXPECT_NE(tab->GetMainFrame()->GetProcess(), subframe->GetProcess()); |
| 1700 | } |
| 1701 | |
nasko | 68e5e6d | 2017-05-24 23:19:34 | [diff] [blame] | 1702 | // Test to verify that loading a resource other than an icon file is |
| 1703 | // disallowed for hosted apps, while icons are allowed. |
| 1704 | // See https://crbug.com/717626. |
| 1705 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HostedAppFilesAccess) { |
| 1706 | // Load an extension with a background page. |
| 1707 | scoped_refptr<const Extension> extension = |
| 1708 | LoadExtension(test_data_dir_.AppendASCII("hosted_app")); |
| 1709 | ASSERT_TRUE(extension); |
| 1710 | |
| 1711 | content::WebContents* tab = |
| 1712 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1713 | |
| 1714 | // Navigating to the manifest should be blocked with an error page. |
| 1715 | { |
| 1716 | content::TestNavigationObserver observer(tab); |
| 1717 | NavigateToURL(extension->GetResourceURL("/manifest.json")); |
| 1718 | EXPECT_FALSE(observer.last_navigation_succeeded()); |
| 1719 | EXPECT_EQ(tab->GetController().GetLastCommittedEntry()->GetPageType(), |
| 1720 | content::PAGE_TYPE_ERROR); |
| 1721 | } |
| 1722 | |
| 1723 | // Navigation to the icon file should succeed. |
| 1724 | { |
| 1725 | content::TestNavigationObserver observer(tab); |
| 1726 | NavigateToURL(extension->GetResourceURL("/icon.png")); |
| 1727 | EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1728 | EXPECT_EQ(tab->GetController().GetLastCommittedEntry()->GetPageType(), |
| 1729 | content::PAGE_TYPE_NORMAL); |
| 1730 | } |
| 1731 | } |
| 1732 | |
Devlin Cronin | 7a282e3 | 2017-08-10 01:54:10 | [diff] [blame] | 1733 | // Tests that we correctly account for vanilla web URLs that may be in the |
| 1734 | // same SiteInstance as a hosted app, and display alerts correctly. |
| 1735 | // https://crbug.com/746517. |
| 1736 | IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HostedAppAlerts) { |
| 1737 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1738 | scoped_refptr<const Extension> extension = |
| 1739 | LoadExtension(test_data_dir_.AppendASCII("hosted_app")); |
| 1740 | ASSERT_TRUE(extension); |
| 1741 | |
| 1742 | content::WebContents* tab = |
| 1743 | browser()->tab_strip_model()->GetActiveWebContents(); |
Nasko Oskov | 31c0204d | 2018-04-30 17:32:48 | [diff] [blame] | 1744 | GURL hosted_app_url(embedded_test_server()->GetURL( |
| 1745 | "localhost", "/extensions/hosted_app/main.html")); |
| 1746 | { |
| 1747 | content::TestNavigationObserver observer(tab); |
| 1748 | NavigateToURL(hosted_app_url); |
| 1749 | EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1750 | } |
Devlin Cronin | 7a282e3 | 2017-08-10 01:54:10 | [diff] [blame] | 1751 | EXPECT_EQ(hosted_app_url, tab->GetLastCommittedURL()); |
| 1752 | ProcessManager* pm = ProcessManager::Get(profile()); |
| 1753 | EXPECT_EQ(extension, pm->GetExtensionForWebContents(tab)); |
Evan Stade | 7220e47 | 2020-01-31 17:06:57 | [diff] [blame^] | 1754 | javascript_dialogs::AppModalDialogManager* js_dialog_manager = |
| 1755 | javascript_dialogs::AppModalDialogManager::GetInstance(); |
Devlin Cronin | 7a282e3 | 2017-08-10 01:54:10 | [diff] [blame] | 1756 | base::string16 hosted_app_title = base::ASCIIToUTF16("hosted_app"); |
| 1757 | EXPECT_EQ(hosted_app_title, js_dialog_manager->GetTitle( |
| 1758 | tab, tab->GetLastCommittedURL().GetOrigin())); |
| 1759 | |
| 1760 | GURL web_url = embedded_test_server()->GetURL("/title1.html"); |
| 1761 | ASSERT_TRUE(content::ExecuteScript( |
| 1762 | tab, base::StringPrintf("window.open('%s');", web_url.spec().c_str()))); |
| 1763 | content::WebContents* new_tab = |
| 1764 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1765 | EXPECT_NE(new_tab, tab); |
| 1766 | EXPECT_TRUE(content::WaitForLoadStop(new_tab)); |
| 1767 | EXPECT_EQ(web_url, new_tab->GetLastCommittedURL()); |
| 1768 | EXPECT_EQ(nullptr, pm->GetExtensionForWebContents(new_tab)); |
| 1769 | EXPECT_NE(hosted_app_title, |
| 1770 | js_dialog_manager->GetTitle( |
| 1771 | new_tab, new_tab->GetLastCommittedURL().GetOrigin())); |
| 1772 | } |
| 1773 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 1774 | } // namespace extensions |