Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 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" | |
| 23 #include "url/gurl.h" | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 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
| |
| 28 content::RenderFrameHost** out, | |
| 29 content::RenderFrameHost* frame) { | |
| 30 if (frame->GetLastCommittedURL() == url) { | |
| 31 if (*out != NULL) { | |
| 32 ADD_FAILURE() << "Found multiple frames at " << url; | |
| 33 } | |
| 34 *out = frame; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 class ChromeSitePerProcessTest : public InProcessBrowserTest { | |
| 41 public: | |
| 42 ChromeSitePerProcessTest() {} | |
| 43 | |
| 44 void SetUpCommandLine(CommandLine* command_line) override { | |
| 45 command_line->AppendSwitch(switches::kSitePerProcess); | |
| 46 } | |
| 47 | |
| 48 void SetUpOnMainThread() override { | |
| 49 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 50 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 51 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessTest); | |
| 56 }; | |
| 57 | |
| 58 // Verify that origin replication allows JS access to localStorage, database, | |
| 59 // and FileSystem APIs. These features involve a check on the | |
| 60 // WebSecurityOrigin of the topmost WebFrame in ContentSettingsObserver, and | |
| 61 // this test ensures this check works when the top frame is remote. | |
| 62 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, | |
| 63 OriginReplicationAllowsAccessToStorage) { | |
| 64 // Navigate to a page with a same-site iframe. | |
| 65 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); | |
| 66 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 67 | |
| 68 // Navigate subframe cross-site. | |
| 69 content::WebContents* active_web_contents = | |
| 70 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 71 GURL cross_site_url(embedded_test_server()->GetURL("b.com", "/title2.html")); | |
| 72 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, cross_site_url, "test")); | |
| 73 | |
| 74 // Find the subframe's RenderFrameHost. | |
| 75 content::RenderFrameHost* frame_host = NULL; | |
| 76 active_web_contents->ForEachFrame( | |
| 77 base::Bind(&FindFrame, cross_site_url, &frame_host)); | |
| 78 ASSERT_TRUE(frame_host); | |
| 79 EXPECT_TRUE(frame_host->IsCrossProcessSubframe()); | |
| 80 | |
| 81 // Check that JS storage APIs can be accessed successfully. | |
| 82 EXPECT_TRUE( | |
| 83 content::ExecuteScript(frame_host, "localStorage['foo'] = 'bar'")); | |
| 84 std::string result; | |
| 85 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 86 frame_host, "window.domAutomationController.send(localStorage['foo']);", | |
| 87 &result)); | |
| 88 EXPECT_EQ(result, "bar"); | |
| 89 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.
| |
| 90 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 91 frame_host, | |
| 92 "window.domAutomationController.send(!!indexedDB.open('testdb', 2));", | |
| 93 &is_object_created)); | |
| 94 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.
| |
| 95 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 96 frame_host, | |
| 97 "window.domAutomationController.send(!!openDatabase(" | |
| 98 "'foodb', '1.0', 'Test DB', 1024));", | |
| 99 &is_object_created)); | |
| 100 EXPECT_TRUE(is_object_created); | |
| 101 EXPECT_TRUE(ExecuteScript(frame_host, | |
| 102 "window.webkitRequestFileSystem(" | |
| 103 "window.TEMPORARY, 1024, function() {});")); | |
| 104 } | |
| OLD | NEW |