Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: content/browser/frame_host/frame_tree_browsertest.cc

Issue 797813006: Replicate sandbox flags for OOPIF (Chromium part 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iframe-sandbox-flags-part1
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "content/browser/frame_host/frame_tree.h" 6 #include "content/browser/frame_host/frame_tree.h"
7 #include "content/browser/frame_host/frame_tree_node.h" 7 #include "content/browser/frame_host/frame_tree_node.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/notification_service.h" 10 #include "content/public/browser/notification_service.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // Navigating to a data URL should set a unique origin. This is represented 216 // Navigating to a data URL should set a unique origin. This is represented
217 // as "null" per RFC 6454. 217 // as "null" per RFC 6454.
218 EXPECT_EQ(root->current_replication_state().origin.string(), "null"); 218 EXPECT_EQ(root->current_replication_state().origin.string(), "null");
219 219
220 // Re-navigating to a normal URL should update the origin. 220 // Re-navigating to a normal URL should update the origin.
221 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 221 EXPECT_TRUE(NavigateToURL(shell(), main_url));
222 EXPECT_EQ(root->current_replication_state().origin.string() + '/', 222 EXPECT_EQ(root->current_replication_state().origin.string() + '/',
223 main_url.GetOrigin().spec()); 223 main_url.GetOrigin().spec());
224 } 224 }
225 225
226 // Ensure that sandbox flags are correctly set when child frames are created.
227 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) {
228 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html"));
229 EXPECT_TRUE(NavigateToURL(shell(), main_url));
230
231 // It is safe to obtain the root frame tree node here, as it doesn't change.
232 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
233 ->GetFrameTree()->root();
234
235 // Verify that sandbox flags are set properly for all FrameTreeNodes.
236 // First frame is completely sandboxed; second frame uses "allow-scripts",
237 // which resets both SandboxFlags::Scripts and
238 // SandboxFlags::AutomaticFeatures bits per blink::parseSandboxPolicy(), and
239 // third frame has "allow-scripts allow-same-origin".
240 EXPECT_EQ(root->current_replication_state().sandbox_flags,
241 SandboxFlags::NONE);
242 EXPECT_EQ(root->child_at(0)->current_replication_state().sandbox_flags,
243 SandboxFlags::ALL);
244 EXPECT_EQ(root->child_at(1)->current_replication_state().sandbox_flags,
245 SandboxFlags::ALL & ~SandboxFlags::SCRIPTS &
246 ~SandboxFlags::AUTOMATIC_FEATURES);
247 EXPECT_EQ(root->child_at(2)->current_replication_state().sandbox_flags,
248 SandboxFlags::ALL & ~SandboxFlags::SCRIPTS &
249 ~SandboxFlags::AUTOMATIC_FEATURES & ~SandboxFlags::ORIGIN);
250
251 // Sandboxed frames should set a unique origin unless they have the
252 // "allow-same-origin" directive.
253 EXPECT_EQ(root->child_at(0)->current_replication_state().origin.string(),
254 "null");
255 EXPECT_EQ(root->child_at(1)->current_replication_state().origin.string(),
256 "null");
257 EXPECT_EQ(
258 root->child_at(2)->current_replication_state().origin.string() + "/",
259 main_url.GetOrigin().spec());
260
261 // Navigating to a different URL should not clear sandbox flags.
262 GURL frame_url(embedded_test_server()->GetURL("/title1.html"));
263 NavigateFrameToURL(root->child_at(0), frame_url);
264 EXPECT_EQ(root->child_at(0)->current_replication_state().sandbox_flags,
265 SandboxFlags::ALL);
266 }
267
226 class CrossProcessFrameTreeBrowserTest : public ContentBrowserTest { 268 class CrossProcessFrameTreeBrowserTest : public ContentBrowserTest {
227 public: 269 public:
228 CrossProcessFrameTreeBrowserTest() {} 270 CrossProcessFrameTreeBrowserTest() {}
229 271
230 void SetUpCommandLine(base::CommandLine* command_line) override { 272 void SetUpCommandLine(base::CommandLine* command_line) override {
231 command_line->AppendSwitch(switches::kSitePerProcess); 273 command_line->AppendSwitch(switches::kSitePerProcess);
232 } 274 }
233 275
234 void SetUpOnMainThread() override { 276 void SetUpOnMainThread() override {
235 host_resolver()->AddRule("*", "127.0.0.1"); 277 host_resolver()->AddRule("*", "127.0.0.1");
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 GURL data_url("data:text/html,foo"); 382 GURL data_url("data:text/html,foo");
341 NavigateFrameToURL(root->child_at(1), data_url); 383 NavigateFrameToURL(root->child_at(1), data_url);
342 384
343 // Navigating to a data URL should set a unique origin. This is represented 385 // Navigating to a data URL should set a unique origin. This is represented
344 // as "null" per RFC 6454. 386 // as "null" per RFC 6454.
345 EXPECT_EQ(root->child_at(1)->current_replication_state().origin.string(), 387 EXPECT_EQ(root->child_at(1)->current_replication_state().origin.string(),
346 "null"); 388 "null");
347 } 389 }
348 390
349 } // namespace content 391 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698