MD Downloads: UI review feedback
[chromium-blink-merge.git] / chrome / browser / chrome_site_per_process_browsertest.cc
blobb632c5b84c77446c7b82e1c7454b6bfd0ea92991
1 // Copyright 2014 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.
5 #include "base/command_line.h"
6 #include "base/strings/stringprintf.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_observer.h"
17 #include "content/public/test/browser_test_utils.h"
18 #include "content/public/test/content_browser_test_utils.h"
19 #include "content/public/test/test_utils.h"
20 #include "net/dns/mock_host_resolver.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h"
22 #include "url/gurl.h"
24 class ChromeSitePerProcessTest : public InProcessBrowserTest {
25 public:
26 ChromeSitePerProcessTest() {}
27 ~ChromeSitePerProcessTest() override {}
29 void SetUpCommandLine(base::CommandLine* command_line) override {
30 content::IsolateAllSitesForTesting(command_line);
33 void SetUpOnMainThread() override {
34 host_resolver()->AddRule("*", "127.0.0.1");
35 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
36 content::SetupCrossSiteRedirector(embedded_test_server());
39 private:
40 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessTest);
43 // Verify that browser shutdown path works correctly when there's a
44 // RenderFrameProxyHost for a child frame.
45 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, RenderFrameProxyHostShutdown) {
46 GURL main_url(embedded_test_server()->GetURL(
47 "a.com",
48 "/frame_tree/page_with_two_frames_remote_and_local.html"));
49 ui_test_utils::NavigateToURL(browser(), main_url);
52 // Verify that origin replication allows JS access to localStorage, database,
53 // and FileSystem APIs. These features involve a check on the
54 // WebSecurityOrigin of the topmost WebFrame in ContentSettingsObserver, and
55 // this test ensures this check works when the top frame is remote.
56 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest,
57 OriginReplicationAllowsAccessToStorage) {
58 // Navigate to a page with a same-site iframe.
59 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html"));
60 ui_test_utils::NavigateToURL(browser(), main_url);
62 // Navigate subframe cross-site.
63 content::WebContents* active_web_contents =
64 browser()->tab_strip_model()->GetActiveWebContents();
65 GURL cross_site_url(embedded_test_server()->GetURL("b.com", "/title2.html"));
66 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", cross_site_url));
68 // Find the subframe's RenderFrameHost.
69 content::RenderFrameHost* frame_host = FrameMatchingPredicate(
70 active_web_contents,
71 base::Bind(&content::FrameHasSourceUrl, cross_site_url));
72 ASSERT_TRUE(frame_host);
73 EXPECT_TRUE(frame_host->IsCrossProcessSubframe());
75 // Check that JS storage APIs can be accessed successfully.
76 EXPECT_TRUE(
77 content::ExecuteScript(frame_host, "localStorage['foo'] = 'bar'"));
78 std::string result;
79 EXPECT_TRUE(ExecuteScriptAndExtractString(
80 frame_host, "window.domAutomationController.send(localStorage['foo']);",
81 &result));
82 EXPECT_EQ(result, "bar");
83 bool is_object_created = false;
84 EXPECT_TRUE(ExecuteScriptAndExtractBool(
85 frame_host,
86 "window.domAutomationController.send(!!indexedDB.open('testdb', 2));",
87 &is_object_created));
88 EXPECT_TRUE(is_object_created);
89 is_object_created = false;
90 EXPECT_TRUE(ExecuteScriptAndExtractBool(
91 frame_host,
92 "window.domAutomationController.send(!!openDatabase("
93 "'foodb', '1.0', 'Test DB', 1024));",
94 &is_object_created));
95 EXPECT_TRUE(is_object_created);
96 EXPECT_TRUE(ExecuteScript(frame_host,
97 "window.webkitRequestFileSystem("
98 "window.TEMPORARY, 1024, function() {});"));
101 // Ensure that creating a plugin in a cross-site subframe doesn't crash. This
102 // involves querying content settings from the renderer process and using the
103 // top frame's origin as one of the parameters. See https://crbug.com/426658.
104 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, PluginWithRemoteTopFrame) {
105 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html"));
106 ui_test_utils::NavigateToURL(browser(), main_url);
108 // Navigate subframe to a page with a Flash object.
109 content::WebContents* active_web_contents =
110 browser()->tab_strip_model()->GetActiveWebContents();
111 GURL frame_url =
112 embedded_test_server()->GetURL("b.com", "/flash_object.html");
113 content::DOMMessageQueue msg_queue;
114 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url));
116 // Ensure the page finishes loading without crashing.
117 std::string status;
118 while (msg_queue.WaitForMessage(&status)) {
119 if (status == "\"DONE\"")
120 break;