OLD | NEW |
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 "content/browser/frame_host/frame_tree.h" | 5 #include "content/browser/frame_host/frame_tree.h" |
6 #include "content/browser/frame_host/frame_tree_node.h" | 6 #include "content/browser/frame_host/frame_tree_node.h" |
7 #include "content/browser/renderer_host/render_view_host_impl.h" | 7 #include "content/browser/renderer_host/render_view_host_impl.h" |
8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 GURL main_url(embedded_test_server()->GetURL("/frame_tree/top.html")); | 208 GURL main_url(embedded_test_server()->GetURL("/frame_tree/top.html")); |
209 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 209 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
210 | 210 |
211 // It is safe to obtain the root frame tree node here, as it doesn't change. | 211 // It is safe to obtain the root frame tree node here, as it doesn't change. |
212 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 212 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
213 ->GetFrameTree()->root(); | 213 ->GetFrameTree()->root(); |
214 | 214 |
215 // Extra '/' is added because the replicated origin is serialized in RFC 6454 | 215 // Extra '/' is added because the replicated origin is serialized in RFC 6454 |
216 // format, which dictates no trailing '/', whereas GURL::GetOrigin does put a | 216 // format, which dictates no trailing '/', whereas GURL::GetOrigin does put a |
217 // '/' at the end. | 217 // '/' at the end. |
218 EXPECT_EQ(root->current_replication_state().origin.Serialize() + '/', | 218 EXPECT_EQ(root->current_origin().Serialize() + '/', |
219 main_url.GetOrigin().spec()); | 219 main_url.GetOrigin().spec()); |
220 | 220 |
221 GURL frame_url(embedded_test_server()->GetURL("/title1.html")); | 221 GURL frame_url(embedded_test_server()->GetURL("/title1.html")); |
222 NavigateFrameToURL(root->child_at(0), frame_url); | 222 NavigateFrameToURL(root->child_at(0), frame_url); |
223 | 223 |
224 EXPECT_EQ( | 224 EXPECT_EQ(root->child_at(0)->current_origin().Serialize() + '/', |
225 root->child_at(0)->current_replication_state().origin.Serialize() + '/', | 225 frame_url.GetOrigin().spec()); |
226 frame_url.GetOrigin().spec()); | |
227 | 226 |
228 GURL data_url("data:text/html,foo"); | 227 GURL data_url("data:text/html,foo"); |
229 EXPECT_TRUE(NavigateToURL(shell(), data_url)); | 228 EXPECT_TRUE(NavigateToURL(shell(), data_url)); |
230 | 229 |
231 // Navigating to a data URL should set a unique origin. This is represented | 230 // Navigating to a data URL should set a unique origin. This is represented |
232 // as "null" per RFC 6454. | 231 // as "null" per RFC 6454. |
233 EXPECT_EQ(root->current_replication_state().origin.Serialize(), "null"); | 232 EXPECT_EQ(root->current_origin().Serialize(), "null"); |
234 | 233 |
235 // Re-navigating to a normal URL should update the origin. | 234 // Re-navigating to a normal URL should update the origin. |
236 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 235 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
237 EXPECT_EQ(root->current_replication_state().origin.Serialize() + '/', | 236 EXPECT_EQ(root->current_origin().Serialize() + '/', |
238 main_url.GetOrigin().spec()); | 237 main_url.GetOrigin().spec()); |
239 } | 238 } |
240 | 239 |
241 // Ensure that sandbox flags are correctly set when child frames are created. | 240 // Ensure that sandbox flags are correctly set when child frames are created. |
242 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { | 241 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { |
243 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); | 242 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); |
244 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 243 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
245 | 244 |
246 // It is safe to obtain the root frame tree node here, as it doesn't change. | 245 // It is safe to obtain the root frame tree node here, as it doesn't change. |
247 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 246 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
(...skipping 11 matching lines...) Expand all Loading... |
259 EXPECT_EQ(root->child_at(1)->current_replication_state().sandbox_flags, | 258 EXPECT_EQ(root->child_at(1)->current_replication_state().sandbox_flags, |
260 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 259 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
261 ~blink::WebSandboxFlags::AutomaticFeatures); | 260 ~blink::WebSandboxFlags::AutomaticFeatures); |
262 EXPECT_EQ(root->child_at(2)->current_replication_state().sandbox_flags, | 261 EXPECT_EQ(root->child_at(2)->current_replication_state().sandbox_flags, |
263 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 262 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
264 ~blink::WebSandboxFlags::AutomaticFeatures & | 263 ~blink::WebSandboxFlags::AutomaticFeatures & |
265 ~blink::WebSandboxFlags::Origin); | 264 ~blink::WebSandboxFlags::Origin); |
266 | 265 |
267 // Sandboxed frames should set a unique origin unless they have the | 266 // Sandboxed frames should set a unique origin unless they have the |
268 // "allow-same-origin" directive. | 267 // "allow-same-origin" directive. |
269 EXPECT_EQ(root->child_at(0)->current_replication_state().origin.Serialize(), | 268 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), "null"); |
270 "null"); | 269 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null"); |
271 EXPECT_EQ(root->child_at(1)->current_replication_state().origin.Serialize(), | 270 EXPECT_EQ(root->child_at(2)->current_origin().Serialize() + "/", |
272 "null"); | 271 main_url.GetOrigin().spec()); |
273 EXPECT_EQ( | |
274 root->child_at(2)->current_replication_state().origin.Serialize() + "/", | |
275 main_url.GetOrigin().spec()); | |
276 | 272 |
277 // Navigating to a different URL should not clear sandbox flags. | 273 // Navigating to a different URL should not clear sandbox flags. |
278 GURL frame_url(embedded_test_server()->GetURL("/title1.html")); | 274 GURL frame_url(embedded_test_server()->GetURL("/title1.html")); |
279 NavigateFrameToURL(root->child_at(0), frame_url); | 275 NavigateFrameToURL(root->child_at(0), frame_url); |
280 EXPECT_EQ(root->child_at(0)->current_replication_state().sandbox_flags, | 276 EXPECT_EQ(root->child_at(0)->current_replication_state().sandbox_flags, |
281 blink::WebSandboxFlags::All); | 277 blink::WebSandboxFlags::All); |
282 } | 278 } |
283 | 279 |
284 // Ensure that a popup opened from a subframe sets its opener to the subframe's | 280 // Ensure that a popup opened from a subframe sets its opener to the subframe's |
285 // FrameTreeNode, and that the opener is cleared if the subframe is destroyed. | 281 // FrameTreeNode, and that the opener is cleared if the subframe is destroyed. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 382 |
387 IN_PROC_BROWSER_TEST_F(CrossProcessFrameTreeBrowserTest, | 383 IN_PROC_BROWSER_TEST_F(CrossProcessFrameTreeBrowserTest, |
388 OriginSetOnCrossProcessNavigations) { | 384 OriginSetOnCrossProcessNavigations) { |
389 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 385 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
390 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 386 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
391 | 387 |
392 // It is safe to obtain the root frame tree node here, as it doesn't change. | 388 // It is safe to obtain the root frame tree node here, as it doesn't change. |
393 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 389 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
394 ->GetFrameTree()->root(); | 390 ->GetFrameTree()->root(); |
395 | 391 |
396 EXPECT_EQ(root->current_replication_state().origin.Serialize() + '/', | 392 EXPECT_EQ(root->current_origin().Serialize() + '/', |
397 main_url.GetOrigin().spec()); | 393 main_url.GetOrigin().spec()); |
398 | 394 |
399 // First frame is an about:blank frame. Check that its origin is correctly | 395 // First frame is an about:blank frame. Check that its origin is correctly |
400 // inherited from the parent. | 396 // inherited from the parent. |
401 EXPECT_EQ( | 397 EXPECT_EQ(root->child_at(0)->current_origin().Serialize() + '/', |
402 root->child_at(0)->current_replication_state().origin.Serialize() + '/', | 398 main_url.GetOrigin().spec()); |
403 main_url.GetOrigin().spec()); | |
404 | 399 |
405 // Second frame loads a same-site page. Its origin should also be the same | 400 // Second frame loads a same-site page. Its origin should also be the same |
406 // as the parent. | 401 // as the parent. |
407 EXPECT_EQ( | 402 EXPECT_EQ(root->child_at(1)->current_origin().Serialize() + '/', |
408 root->child_at(1)->current_replication_state().origin.Serialize() + '/', | 403 main_url.GetOrigin().spec()); |
409 main_url.GetOrigin().spec()); | |
410 | 404 |
411 // Load cross-site page into the first frame. | 405 // Load cross-site page into the first frame. |
412 GURL cross_site_url( | 406 GURL cross_site_url( |
413 embedded_test_server()->GetURL("foo.com", "/title2.html")); | 407 embedded_test_server()->GetURL("foo.com", "/title2.html")); |
414 NavigateFrameToURL(root->child_at(0), cross_site_url); | 408 NavigateFrameToURL(root->child_at(0), cross_site_url); |
415 | 409 |
416 EXPECT_EQ( | 410 EXPECT_EQ(root->child_at(0)->current_origin().Serialize() + '/', |
417 root->child_at(0)->current_replication_state().origin.Serialize() + '/', | 411 cross_site_url.GetOrigin().spec()); |
418 cross_site_url.GetOrigin().spec()); | |
419 | 412 |
420 // The root's origin shouldn't have changed. | 413 // The root's origin shouldn't have changed. |
421 EXPECT_EQ(root->current_replication_state().origin.Serialize() + '/', | 414 EXPECT_EQ(root->current_origin().Serialize() + '/', |
422 main_url.GetOrigin().spec()); | 415 main_url.GetOrigin().spec()); |
423 | 416 |
424 GURL data_url("data:text/html,foo"); | 417 GURL data_url("data:text/html,foo"); |
425 NavigateFrameToURL(root->child_at(1), data_url); | 418 NavigateFrameToURL(root->child_at(1), data_url); |
426 | 419 |
427 // Navigating to a data URL should set a unique origin. This is represented | 420 // Navigating to a data URL should set a unique origin. This is represented |
428 // as "null" per RFC 6454. | 421 // as "null" per RFC 6454. |
429 EXPECT_EQ(root->child_at(1)->current_replication_state().origin.Serialize(), | 422 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null"); |
430 "null"); | |
431 } | 423 } |
432 | 424 |
433 } // namespace content | 425 } // namespace content |
OLD | NEW |