Chromium Code Reviews| Index: chrome/browser/chrome_site_per_process_browsertest.cc |
| diff --git a/chrome/browser/chrome_site_per_process_browsertest.cc b/chrome/browser/chrome_site_per_process_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a969d8677df185bee236a3ba442f5c385adbfbc0 |
| --- /dev/null |
| +++ b/chrome/browser/chrome_site_per_process_browsertest.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
Charlie Reis
2014/12/12 18:02:45
Copyright 2014
alexmos
2014/12/13 00:58:12
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/command_line.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/notification_types.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| +#include "content/public/common/content_switches.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "content/public/test/content_browser_test_utils.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "net/dns/mock_host_resolver.h" |
| +#include "net/test/embedded_test_server/embedded_test_server.h" |
| +#include "url/gurl.h" |
| + |
| +namespace { |
| + |
| +void FindFrame(const GURL& url, |
|
alexmos
2014/12/11 18:45:18
I borrowed this from extension_webui_apitest.cc.
Charlie Reis
2014/12/12 18:02:45
It does seem like we'd benefit from a public utili
alexmos
2014/12/13 00:58:12
Actually, I somehow missed that there's already a
Charlie Reis
2014/12/15 20:25:35
Even better.
I didn't see any change to extension
|
| + content::RenderFrameHost** out, |
| + content::RenderFrameHost* frame) { |
| + if (frame->GetLastCommittedURL() == url) { |
| + if (*out != NULL) { |
| + ADD_FAILURE() << "Found multiple frames at " << url; |
| + } |
| + *out = frame; |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +class ChromeSitePerProcessTest : public InProcessBrowserTest { |
| + public: |
| + ChromeSitePerProcessTest() {} |
| + |
| + void SetUpCommandLine(CommandLine* command_line) override { |
| + command_line->AppendSwitch(switches::kSitePerProcess); |
| + } |
| + |
| + void SetUpOnMainThread() override { |
| + host_resolver()->AddRule("*", "127.0.0.1"); |
| + ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| + content::SetupCrossSiteRedirector(embedded_test_server()); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessTest); |
| +}; |
| + |
| +// Verify that origin replication allows JS access to localStorage, database, |
| +// and FileSystem APIs. These features involve a check on the |
| +// WebSecurityOrigin of the topmost WebFrame in ContentSettingsObserver, and |
| +// this test ensures this check works when the top frame is remote. |
| +IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, |
| + OriginReplicationAllowsAccessToStorage) { |
| + // Navigate to a page with a same-site iframe. |
| + GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); |
| + ui_test_utils::NavigateToURL(browser(), main_url); |
| + |
| + // Navigate subframe cross-site. |
| + content::WebContents* active_web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + GURL cross_site_url(embedded_test_server()->GetURL("b.com", "/title2.html")); |
| + EXPECT_TRUE(NavigateIframeToURL(active_web_contents, cross_site_url, "test")); |
| + |
| + // Find the subframe's RenderFrameHost. |
| + content::RenderFrameHost* frame_host = NULL; |
| + active_web_contents->ForEachFrame( |
| + base::Bind(&FindFrame, cross_site_url, &frame_host)); |
| + ASSERT_TRUE(frame_host); |
| + EXPECT_TRUE(frame_host->IsCrossProcessSubframe()); |
| + |
| + // Check that JS storage APIs can be accessed successfully. |
| + EXPECT_TRUE( |
| + content::ExecuteScript(frame_host, "localStorage['foo'] = 'bar'")); |
| + std::string result; |
| + EXPECT_TRUE(ExecuteScriptAndExtractString( |
| + frame_host, "window.domAutomationController.send(localStorage['foo']);", |
| + &result)); |
| + EXPECT_EQ(result, "bar"); |
| + bool is_object_created; |
|
Charlie Reis
2014/12/12 18:02:45
nit: Let's initialize this to false.
alexmos
2014/12/13 00:58:12
Done.
|
| + EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| + frame_host, |
| + "window.domAutomationController.send(!!indexedDB.open('testdb', 2));", |
| + &is_object_created)); |
| + EXPECT_TRUE(is_object_created); |
|
Charlie Reis
2014/12/12 18:02:45
Let's set it back to false after this line.
alexmos
2014/12/13 00:58:12
Done.
|
| + EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| + frame_host, |
| + "window.domAutomationController.send(!!openDatabase(" |
| + "'foodb', '1.0', 'Test DB', 1024));", |
| + &is_object_created)); |
| + EXPECT_TRUE(is_object_created); |
| + EXPECT_TRUE(ExecuteScript(frame_host, |
| + "window.webkitRequestFileSystem(" |
| + "window.TEMPORARY, 1024, function() {});")); |
| +} |