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/common/content_switches.h"
18 #include "content/public/test/browser_test_utils.h"
19 #include "content/public/test/content_browser_test_utils.h"
20 #include "content/public/test/test_utils.h"
21 #include "net/dns/mock_host_resolver.h"
22 #include "net/test/embedded_test_server/embedded_test_server.h"
25 class ChromeSitePerProcessTest
: public InProcessBrowserTest
{
27 ChromeSitePerProcessTest() {}
28 ~ChromeSitePerProcessTest() override
{}
30 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
31 command_line
->AppendSwitch(switches::kSitePerProcess
);
34 void SetUpOnMainThread() override
{
35 host_resolver()->AddRule("*", "127.0.0.1");
36 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
37 content::SetupCrossSiteRedirector(embedded_test_server());
41 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessTest
);
44 // Verify that browser shutdown path works correctly when there's a
45 // RenderFrameProxyHost for a child frame.
46 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest
, RenderFrameProxyHostShutdown
) {
47 GURL
main_url(embedded_test_server()->GetURL(
49 "/frame_tree/page_with_two_frames_remote_and_local.html"));
50 ui_test_utils::NavigateToURL(browser(), main_url
);
53 // Verify that origin replication allows JS access to localStorage, database,
54 // and FileSystem APIs. These features involve a check on the
55 // WebSecurityOrigin of the topmost WebFrame in ContentSettingsObserver, and
56 // this test ensures this check works when the top frame is remote.
57 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest
,
58 OriginReplicationAllowsAccessToStorage
) {
59 // Navigate to a page with a same-site iframe.
60 GURL
main_url(embedded_test_server()->GetURL("a.com", "/iframe.html"));
61 ui_test_utils::NavigateToURL(browser(), main_url
);
63 // Navigate subframe cross-site.
64 content::WebContents
* active_web_contents
=
65 browser()->tab_strip_model()->GetActiveWebContents();
66 GURL
cross_site_url(embedded_test_server()->GetURL("b.com", "/title2.html"));
67 EXPECT_TRUE(NavigateIframeToURL(active_web_contents
, "test", cross_site_url
));
69 // Find the subframe's RenderFrameHost.
70 content::RenderFrameHost
* frame_host
= FrameMatchingPredicate(
72 base::Bind(&content::FrameHasSourceUrl
, cross_site_url
));
73 ASSERT_TRUE(frame_host
);
74 EXPECT_TRUE(frame_host
->IsCrossProcessSubframe());
76 // Check that JS storage APIs can be accessed successfully.
78 content::ExecuteScript(frame_host
, "localStorage['foo'] = 'bar'"));
80 EXPECT_TRUE(ExecuteScriptAndExtractString(
81 frame_host
, "window.domAutomationController.send(localStorage['foo']);",
83 EXPECT_EQ(result
, "bar");
84 bool is_object_created
= false;
85 EXPECT_TRUE(ExecuteScriptAndExtractBool(
87 "window.domAutomationController.send(!!indexedDB.open('testdb', 2));",
89 EXPECT_TRUE(is_object_created
);
90 is_object_created
= false;
91 EXPECT_TRUE(ExecuteScriptAndExtractBool(
93 "window.domAutomationController.send(!!openDatabase("
94 "'foodb', '1.0', 'Test DB', 1024));",
96 EXPECT_TRUE(is_object_created
);
97 EXPECT_TRUE(ExecuteScript(frame_host
,
98 "window.webkitRequestFileSystem("
99 "window.TEMPORARY, 1024, function() {});"));