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

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

Issue 874743003: Revert of Remove the use of page id from building the commit params. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | content/renderer/render_frame_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind.h" 5 #include "base/bind.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "content/browser/frame_host/frame_tree.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h" 7 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 8 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/test/browser_test_utils.h" 10 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/content_browser_test.h" 11 #include "content/public/test/content_browser_test.h"
15 #include "content/public/test/content_browser_test_utils.h" 12 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/public/test/test_utils.h"
17 #include "content/shell/browser/shell.h" 13 #include "content/shell/browser/shell.h"
18 #include "content/test/content_browser_test_utils_internal.h"
19 #include "net/dns/mock_host_resolver.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h"
21 14
22 namespace content { 15 namespace content {
23 16
24 class NavigationControllerBrowserTest : public ContentBrowserTest { 17 class NavigationControllerBrowserTest : public ContentBrowserTest {
25 protected:
26 void SetUpOnMainThread() override {
27 host_resolver()->AddRule("*", "127.0.0.1");
28 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
29 }
30 }; 18 };
31 19
32 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadDataWithBaseURL) { 20 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadDataWithBaseURL) {
33 const GURL base_url("http://baseurl"); 21 const GURL base_url("http://baseurl");
34 const GURL history_url("http://historyurl"); 22 const GURL history_url("http://historyurl");
35 const std::string data = "<html><body>foo</body></html>"; 23 const std::string data = "<html><body>foo</body></html>";
36 24
37 const NavigationController& controller = 25 const NavigationController& controller =
38 shell()->web_contents()->GetController(); 26 shell()->web_contents()->GetController();
39 // Load data. Blocks until it is done. 27 // Load data. Blocks until it is done.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // Now try to go back. This should not hang. 69 // Now try to go back. This should not hang.
82 ASSERT_TRUE(controller.CanGoBack()); 70 ASSERT_TRUE(controller.CanGoBack());
83 controller.GoBack(); 71 controller.GoBack();
84 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 72 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
85 73
86 // This should have successfully gone back. 74 // This should have successfully gone back.
87 EXPECT_EQ(GURL(base::StringPrintf("data:text/html,page%d", kMaxEntryCount)), 75 EXPECT_EQ(GURL(base::StringPrintf("data:text/html,page%d", kMaxEntryCount)),
88 controller.GetLastCommittedEntry()->GetURL()); 76 controller.GetLastCommittedEntry()->GetURL());
89 } 77 }
90 78
91 struct FrameNavigateParamsCapturer : public WebContentsObserver { 79 } // namespace content
92 public:
93 explicit FrameNavigateParamsCapturer(FrameTreeNode* node)
94 : WebContentsObserver(
95 node->current_frame_host()->delegate()->GetAsWebContents()),
96 frame_tree_node_id_(node->frame_tree_node_id()),
97 message_loop_runner_(new MessageLoopRunner) {}
98 80
99 void Wait() {
100 message_loop_runner_->Run();
101 }
102
103 const FrameNavigateParams& params() const {
104 return params_;
105 }
106
107 private:
108 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
109 const LoadCommittedDetails& details,
110 const FrameNavigateParams& params) override {
111 RenderFrameHostImpl* rfh =
112 static_cast<RenderFrameHostImpl*>(render_frame_host);
113 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_)
114 return;
115
116 params_ = params;
117 message_loop_runner_->Quit();
118 }
119
120 // The id of the FrameTreeNode in which navigations are peformed.
121 int frame_tree_node_id_;
122
123 // The params of the last navigation.
124 FrameNavigateParams params_;
125
126 // The MessageLoopRunner used to spin the message loop.
127 scoped_refptr<MessageLoopRunner> message_loop_runner_;
128 };
129
130 // Verify that PAGE_TRANSITION_AUTO_SUBFRAME and PAGE_TRANSITION_MANUAL_SUBFRAME
131 // are properly set for subframe navigations.
132 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
133 ManualAndAutoSubframeNavigationTransitions) {
134 GURL main_url(
135 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html"));
136 NavigateToURL(shell(), main_url);
137
138 // It is safe to obtain the root frame tree node here, as it doesn't change.
139 FrameTreeNode* root =
140 static_cast<WebContentsImpl*>(shell()->web_contents())->
141 GetFrameTree()->root();
142
143 ASSERT_EQ(1U, root->child_count());
144 ASSERT_NE(nullptr, root->child_at(0));
145
146 {
147 // Navigate the iframe to a new URL; expect a manual subframe transition.
148 FrameNavigateParamsCapturer capturer(root->child_at(0));
149 GURL frame_url(
150 embedded_test_server()->GetURL("/frame_tree/2-1.html"));
151 NavigateFrameToURL(root->child_at(0), frame_url);
152 capturer.Wait();
153 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
154 capturer.params().transition);
155 }
156
157 {
158 // History navigations should result in an auto subframe transition.
159 FrameNavigateParamsCapturer capturer(root->child_at(0));
160 shell()->web_contents()->GetController().GoBack();
161 capturer.Wait();
162 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition);
163 }
164
165 {
166 // History navigations should result in an auto subframe transition.
167 FrameNavigateParamsCapturer capturer(root->child_at(0));
168 shell()->web_contents()->GetController().GoForward();
169 capturer.Wait();
170 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition);
171 }
172
173 {
174 // Navigate the iframe to a new URL; expect a manual subframe transition.
175 FrameNavigateParamsCapturer capturer(root->child_at(0));
176 GURL frame_url(
177 embedded_test_server()->GetURL("/frame_tree/2-3.html"));
178 NavigateFrameToURL(root->child_at(0), frame_url);
179 capturer.Wait();
180 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
181 capturer.params().transition);
182 }
183 }
184
185 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_frame_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698