OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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. | |
4 | |
5 #include "content/browser/frame_host/frame_tree.h" | |
6 #include "content/browser/frame_host/frame_tree_node.h" | |
7 #include "content/browser/renderer_host/render_view_host_impl.h" | |
8 #include "content/browser/web_contents/web_contents_impl.h" | |
9 #include "content/public/browser/notification_types.h" | |
10 #include "content/public/test/test_navigation_observer.h" | |
11 #include "content/public/test/test_utils.h" | |
12 #include "content/shell/browser/shell.h" | |
13 #include "content/test/content_browser_test.h" | |
14 #include "content/test/content_browser_test_utils.h" | |
15 #include "net/dns/mock_host_resolver.h" | |
16 | |
17 namespace content { | |
18 | |
19 class FrameTreeBrowserTest : public ContentBrowserTest { | |
20 public: | |
21 FrameTreeBrowserTest() {} | |
awong
2013/11/22 03:19:29
nit: Unless there's precedent, I'd generally just
Charlie Reis
2013/11/23 01:04:16
Oops, forgot this one. There's a precedent in Web
| |
22 | |
23 private: | |
24 DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest); | |
25 }; | |
26 | |
27 // Ensures FrameTree correctly reflects page structure during navigations. | |
28 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape) { | |
29 host_resolver()->AddRule("*", "127.0.0.1"); | |
30 ASSERT_TRUE(test_server()->Start()); | |
31 | |
32 GURL base_url = test_server()->GetURL("files/site_isolation/"); | |
33 GURL::Replacements replace_host; | |
34 std::string host_str("A.com"); // Must stay in scope with replace_host. | |
35 replace_host.SetHostStr(host_str); | |
36 base_url = base_url.ReplaceComponents(replace_host); | |
37 | |
38 // Load doc without iframes. Verify FrameTree just has root. | |
39 // Frame tree: | |
40 // Site-A Root | |
41 NavigateToURL(shell(), base_url.Resolve("blank.html")); | |
42 FrameTreeNode* root = | |
43 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
44 GetFrameTree()->root(); | |
45 EXPECT_EQ(0U, root->child_count()); | |
46 | |
47 // Add 2 same-site frames. Verify 3 nodes in tree with proper names. | |
48 // Frame tree: | |
49 // Site-A Root -- Site-A frame1 | |
50 // \-- Site-A frame2 | |
51 WindowedNotificationObserver observer1( | |
52 content::NOTIFICATION_LOAD_STOP, | |
53 content::Source<NavigationController>( | |
54 &shell()->web_contents()->GetController())); | |
55 NavigateToURL(shell(), base_url.Resolve("frames-X-X.html")); | |
56 observer1.Wait(); | |
57 ASSERT_EQ(2U, root->child_count()); | |
58 EXPECT_EQ(0U, root->child_at(0)->child_count()); | |
59 EXPECT_EQ(0U, root->child_at(1)->child_count()); | |
60 } | |
61 | |
62 // TODO(ajwong): Talk with nasko and merge this functionality with | |
63 // FrameTreeShape. | |
64 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape2) { | |
65 host_resolver()->AddRule("*", "127.0.0.1"); | |
66 ASSERT_TRUE(test_server()->Start()); | |
67 | |
68 NavigateToURL(shell(), | |
69 test_server()->GetURL("files/frame_tree/top.html")); | |
70 | |
71 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
72 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
73 wc->GetRenderViewHost()); | |
74 FrameTreeNode* root = wc->GetFrameTree()->root(); | |
75 | |
76 // Check that the root node is properly created with the frame id of the | |
77 // initial navigation. | |
78 ASSERT_EQ(3UL, root->child_count()); | |
79 EXPECT_EQ(std::string(), root->frame_name()); | |
80 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
81 | |
82 ASSERT_EQ(2UL, root->child_at(0)->child_count()); | |
83 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str()); | |
84 | |
85 // Verify the deepest node exists and has the right name. | |
86 ASSERT_EQ(2UL, root->child_at(2)->child_count()); | |
87 EXPECT_EQ(1UL, root->child_at(2)->child_at(1)->child_count()); | |
88 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_at(0)->child_count()); | |
89 EXPECT_STREQ("3-1-id", | |
90 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str()); | |
91 | |
92 // Navigate to about:blank, which should leave only the root node of the frame | |
93 // tree in the browser process. | |
94 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | |
95 | |
96 root = wc->GetFrameTree()->root(); | |
97 EXPECT_EQ(0UL, root->child_count()); | |
98 EXPECT_EQ(std::string(), root->frame_name()); | |
99 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
100 } | |
101 | |
102 } // namespace content | |
OLD | NEW |