OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/navigation_handle_impl.h" | 5 #include "content/browser/frame_host/navigation_handle_impl.h" |
6 #include "content/browser/web_contents/web_contents_impl.h" | 6 #include "content/browser/web_contents/web_contents_impl.h" |
7 #include "content/public/browser/web_contents.h" | 7 #include "content/public/browser/web_contents.h" |
8 #include "content/public/browser/web_contents_observer.h" | 8 #include "content/public/browser/web_contents_observer.h" |
9 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
10 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
11 #include "content/public/test/content_browser_test_utils.h" | 11 #include "content/public/test/content_browser_test_utils.h" |
12 #include "content/public/test/test_navigation_observer.h" | 12 #include "content/public/test/test_navigation_observer.h" |
13 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
14 #include "content/shell/browser/shell.h" | 14 #include "content/shell/browser/shell.h" |
15 #include "content/test/content_browser_test_utils_internal.h" | 15 #include "content/test/content_browser_test_utils_internal.h" |
16 #include "net/dns/mock_host_resolver.h" | 16 #include "net/dns/mock_host_resolver.h" |
17 #include "ui/base/page_transition_types.h" | 17 #include "ui/base/page_transition_types.h" |
18 #include "url/url_constants.h" | 18 #include "url/url_constants.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Gathers data from the NavigationHandle assigned to the next navigation that | |
25 // happens to the expected URL. All subsequent navigations are ignored; create | |
26 // new instances as needed. | |
24 class NavigationHandleObserver : public WebContentsObserver { | 27 class NavigationHandleObserver : public WebContentsObserver { |
25 public: | 28 public: |
26 NavigationHandleObserver(WebContents* web_contents, const GURL& expected_url) | 29 NavigationHandleObserver(WebContents* web_contents, const GURL& expected_url) |
27 : WebContentsObserver(web_contents), | 30 : WebContentsObserver(web_contents), |
28 handle_(nullptr), | 31 handle_(nullptr), |
29 has_committed_(false), | 32 has_committed_(false), |
30 is_error_(false), | 33 is_error_(false), |
31 is_main_frame_(false), | 34 is_main_frame_(false), |
32 is_parent_main_frame_(false), | 35 is_parent_main_frame_(false), |
33 is_renderer_initiated_(true), | 36 is_renderer_initiated_(true), |
34 is_synchronous_(false), | 37 is_synchronous_(false), |
35 is_srcdoc_(false), | 38 is_srcdoc_(false), |
36 was_redirected_(false), | 39 was_redirected_(false), |
37 frame_tree_node_id_(-1), | 40 frame_tree_node_id_(-1), |
38 page_transition_(ui::PAGE_TRANSITION_LINK), | 41 page_transition_(ui::PAGE_TRANSITION_LINK), |
39 expected_url_(expected_url) {} | 42 expected_url_(expected_url) {} |
40 | 43 |
41 void DidStartNavigation(NavigationHandle* navigation_handle) override { | 44 void DidStartNavigation(NavigationHandle* navigation_handle) override { |
42 if (handle_ || navigation_handle->GetURL() != expected_url_) | 45 if (handle_ || navigation_handle->GetURL() != expected_url_) { |
46 last_unmatched_url_ = navigation_handle->GetURL(); | |
carlosk
2016/06/28 14:44:32
I added this new member to allow for more meaningf
| |
43 return; | 47 return; |
48 } | |
44 | 49 |
45 handle_ = navigation_handle; | 50 handle_ = navigation_handle; |
46 has_committed_ = false; | |
47 is_error_ = false; | |
48 page_transition_ = ui::PAGE_TRANSITION_LINK; | |
49 last_committed_url_ = GURL(); | |
carlosk
2016/06/28 14:44:32
These were in fact never updated given the if-chec
nasko
2016/06/28 22:38:20
I'm not sure I follow. DidStartNavigation will be
carlosk
2016/07/01 20:22:51
Yes, you are right, I missed that. Reverted and ma
| |
50 | 51 |
51 is_main_frame_ = navigation_handle->IsInMainFrame(); | 52 is_main_frame_ = navigation_handle->IsInMainFrame(); |
52 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); | 53 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); |
53 is_renderer_initiated_ = navigation_handle->IsRendererInitiated(); | 54 is_renderer_initiated_ = navigation_handle->IsRendererInitiated(); |
54 is_synchronous_ = navigation_handle->IsSynchronousNavigation(); | 55 is_synchronous_ = navigation_handle->IsSynchronousNavigation(); |
55 is_srcdoc_ = navigation_handle->IsSrcdoc(); | 56 is_srcdoc_ = navigation_handle->IsSrcdoc(); |
56 was_redirected_ = navigation_handle->WasServerRedirect(); | 57 was_redirected_ = navigation_handle->WasServerRedirect(); |
57 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); | 58 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); |
58 } | 59 } |
59 | 60 |
60 void DidFinishNavigation(NavigationHandle* navigation_handle) override { | 61 void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
61 if (navigation_handle != handle_) | 62 if (navigation_handle != handle_) |
62 return; | 63 return; |
63 | 64 |
64 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame()); | 65 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame()); |
65 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame()); | 66 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame()); |
66 DCHECK_EQ(is_synchronous_, navigation_handle->IsSynchronousNavigation()); | 67 DCHECK_EQ(is_synchronous_, navigation_handle->IsSynchronousNavigation()); |
67 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated()); | 68 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated()); |
68 DCHECK_EQ(is_srcdoc_, navigation_handle->IsSrcdoc()); | 69 DCHECK_EQ(is_srcdoc_, navigation_handle->IsSrcdoc()); |
69 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId()); | 70 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId()); |
70 | 71 |
71 was_redirected_ = navigation_handle->WasServerRedirect(); | 72 was_redirected_ = navigation_handle->WasServerRedirect(); |
72 | 73 |
73 if (navigation_handle->HasCommitted()) { | 74 if (navigation_handle->HasCommitted()) { |
74 has_committed_ = true; | 75 has_committed_ = true; |
75 if (!navigation_handle->IsErrorPage()) { | 76 if (!navigation_handle->IsErrorPage()) { |
76 page_transition_ = navigation_handle->GetPageTransition(); | 77 page_transition_ = navigation_handle->GetPageTransition(); |
77 last_committed_url_ = navigation_handle->GetURL(); | 78 committed_url_ = navigation_handle->GetURL(); |
78 } else { | 79 } else { |
79 is_error_ = true; | 80 is_error_ = true; |
80 } | 81 } |
81 } else { | 82 } else { |
82 has_committed_ = false; | 83 has_committed_ = false; |
83 is_error_ = true; | 84 is_error_ = true; |
84 } | 85 } |
85 | 86 |
86 handle_ = nullptr; | 87 handle_ = nullptr; |
87 } | 88 } |
88 | 89 |
89 bool has_committed() { return has_committed_; } | 90 bool has_committed() { return has_committed_; } |
90 bool is_error() { return is_error_; } | 91 bool is_error() { return is_error_; } |
91 bool is_main_frame() { return is_main_frame_; } | 92 bool is_main_frame() { return is_main_frame_; } |
92 bool is_parent_main_frame() { return is_parent_main_frame_; } | 93 bool is_parent_main_frame() { return is_parent_main_frame_; } |
93 bool is_renderer_initiated() { return is_renderer_initiated_; } | 94 bool is_renderer_initiated() { return is_renderer_initiated_; } |
94 bool is_synchronous() { return is_synchronous_; } | 95 bool is_synchronous() { return is_synchronous_; } |
95 bool is_srcdoc() { return is_srcdoc_; } | 96 bool is_srcdoc() { return is_srcdoc_; } |
96 bool was_redirected() { return was_redirected_; } | 97 bool was_redirected() { return was_redirected_; } |
97 int frame_tree_node_id() { return frame_tree_node_id_; } | 98 int frame_tree_node_id() { return frame_tree_node_id_; } |
98 | 99 |
99 const GURL& last_committed_url() { return last_committed_url_; } | 100 const GURL& last_unmatched_url() { return last_unmatched_url_; } |
101 const GURL& committed_url() { return committed_url_; } | |
carlosk
2016/06/28 14:44:32
Renamed this because it was confusing: last_... ga
nasko
2016/06/28 22:38:20
It actually can be updated multiple times : ).
carlosk
2016/07/01 20:22:52
Reverted.
| |
100 | 102 |
101 ui::PageTransition page_transition() { return page_transition_; } | 103 ui::PageTransition page_transition() { return page_transition_; } |
102 | 104 |
103 private: | 105 private: |
104 // A reference to the NavigationHandle so this class will track only | 106 // A reference to the NavigationHandle so this class will track only |
105 // one navigation at a time. It is set at DidStartNavigation and cleared | 107 // one navigation at a time. It is set at DidStartNavigation and cleared |
106 // at DidFinishNavigation before the NavigationHandle is destroyed. | 108 // at DidFinishNavigation before the NavigationHandle is destroyed. |
107 NavigationHandle* handle_; | 109 NavigationHandle* handle_; |
108 bool has_committed_; | 110 bool has_committed_; |
109 bool is_error_; | 111 bool is_error_; |
110 bool is_main_frame_; | 112 bool is_main_frame_; |
111 bool is_parent_main_frame_; | 113 bool is_parent_main_frame_; |
112 bool is_renderer_initiated_; | 114 bool is_renderer_initiated_; |
113 bool is_synchronous_; | 115 bool is_synchronous_; |
114 bool is_srcdoc_; | 116 bool is_srcdoc_; |
115 bool was_redirected_; | 117 bool was_redirected_; |
116 int frame_tree_node_id_; | 118 int frame_tree_node_id_; |
117 ui::PageTransition page_transition_; | 119 ui::PageTransition page_transition_; |
118 GURL expected_url_; | 120 GURL expected_url_; |
119 GURL last_committed_url_; | 121 GURL last_unmatched_url_; |
122 GURL committed_url_; | |
120 }; | 123 }; |
121 | 124 |
122 // A test NavigationThrottle that will return pre-determined checks and run | 125 // A test NavigationThrottle that will return pre-determined checks and run |
123 // callbacks when the various NavigationThrottle methods are called. | 126 // callbacks when the various NavigationThrottle methods are called. This is |
127 // generally not instantiated directly but through a | |
128 // TestNavigationThrottleInstaller. | |
124 class TestNavigationThrottle : public NavigationThrottle { | 129 class TestNavigationThrottle : public NavigationThrottle { |
125 public: | 130 public: |
126 TestNavigationThrottle( | 131 TestNavigationThrottle( |
127 NavigationHandle* handle, | 132 NavigationHandle* handle, |
128 NavigationThrottle::ThrottleCheckResult will_start_result, | 133 NavigationThrottle::ThrottleCheckResult will_start_result, |
129 NavigationThrottle::ThrottleCheckResult will_redirect_result, | 134 NavigationThrottle::ThrottleCheckResult will_redirect_result, |
130 NavigationThrottle::ThrottleCheckResult will_process_result, | 135 NavigationThrottle::ThrottleCheckResult will_process_result, |
131 base::Closure did_call_will_start, | 136 base::Closure did_call_will_start, |
132 base::Closure did_call_will_redirect, | 137 base::Closure did_call_will_redirect, |
133 base::Closure did_call_will_process) | 138 base::Closure did_call_will_process) |
(...skipping 29 matching lines...) Expand all Loading... | |
163 | 168 |
164 NavigationThrottle::ThrottleCheckResult will_start_result_; | 169 NavigationThrottle::ThrottleCheckResult will_start_result_; |
165 NavigationThrottle::ThrottleCheckResult will_redirect_result_; | 170 NavigationThrottle::ThrottleCheckResult will_redirect_result_; |
166 NavigationThrottle::ThrottleCheckResult will_process_result_; | 171 NavigationThrottle::ThrottleCheckResult will_process_result_; |
167 base::Closure did_call_will_start_; | 172 base::Closure did_call_will_start_; |
168 base::Closure did_call_will_redirect_; | 173 base::Closure did_call_will_redirect_; |
169 base::Closure did_call_will_process_; | 174 base::Closure did_call_will_process_; |
170 }; | 175 }; |
171 | 176 |
172 // Install a TestNavigationThrottle on all requests and allows waiting for | 177 // Install a TestNavigationThrottle on all requests and allows waiting for |
173 // various NavigationThrottle related events. | 178 // various NavigationThrottle related events. Waiting is only allows for the |
179 // immediately next navigation; create new instances as needed. | |
174 class TestNavigationThrottleInstaller : public WebContentsObserver { | 180 class TestNavigationThrottleInstaller : public WebContentsObserver { |
175 public: | 181 public: |
176 TestNavigationThrottleInstaller( | 182 TestNavigationThrottleInstaller( |
177 WebContents* web_contents, | 183 WebContents* web_contents, |
178 NavigationThrottle::ThrottleCheckResult will_start_result, | 184 NavigationThrottle::ThrottleCheckResult will_start_result, |
179 NavigationThrottle::ThrottleCheckResult will_redirect_result, | 185 NavigationThrottle::ThrottleCheckResult will_redirect_result, |
180 NavigationThrottle::ThrottleCheckResult will_process_result) | 186 NavigationThrottle::ThrottleCheckResult will_process_result) |
181 : WebContentsObserver(web_contents), | 187 : WebContentsObserver(web_contents), |
182 will_start_result_(will_start_result), | 188 will_start_result_(will_start_result), |
183 will_redirect_result_(will_redirect_result), | 189 will_redirect_result_(will_redirect_result), |
184 will_process_result_(will_process_result), | 190 will_process_result_(will_process_result), |
185 will_start_called_(0), | 191 will_start_called_(0), |
186 will_redirect_called_(0), | 192 will_redirect_called_(0), |
187 will_process_called_(0), | 193 will_process_called_(0), |
188 navigation_throttle_(nullptr) {} | 194 navigation_throttle_(nullptr) {} |
189 ~TestNavigationThrottleInstaller() override{}; | 195 ~TestNavigationThrottleInstaller() override{}; |
190 | 196 |
191 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } | 197 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } |
192 | 198 |
193 void WaitForThrottleWillStart() { | 199 void WaitForThrottleWillStart() { |
194 if (will_start_called_) | 200 CHECK(!will_start_called_); |
carlosk
2016/06/28 14:44:32
Switched this to a CHECK because calls are useless
| |
195 return; | |
196 will_start_loop_runner_ = new MessageLoopRunner(); | 201 will_start_loop_runner_ = new MessageLoopRunner(); |
197 will_start_loop_runner_->Run(); | 202 will_start_loop_runner_->Run(); |
198 will_start_loop_runner_ = nullptr; | 203 will_start_loop_runner_ = nullptr; |
199 } | 204 } |
200 | 205 |
201 void WaitForThrottleWillRedirect() { | 206 void WaitForThrottleWillRedirect() { |
202 if (will_redirect_called_) | 207 CHECK(!will_redirect_called_); |
203 return; | |
204 will_redirect_loop_runner_ = new MessageLoopRunner(); | 208 will_redirect_loop_runner_ = new MessageLoopRunner(); |
205 will_redirect_loop_runner_->Run(); | 209 will_redirect_loop_runner_->Run(); |
206 will_redirect_loop_runner_ = nullptr; | 210 will_redirect_loop_runner_ = nullptr; |
207 } | 211 } |
208 | 212 |
209 void WaitForThrottleWillProcess() { | 213 void WaitForThrottleWillProcess() { |
210 if (will_process_called_) | 214 CHECK(!will_process_called_); |
211 return; | |
212 will_process_loop_runner_ = new MessageLoopRunner(); | 215 will_process_loop_runner_ = new MessageLoopRunner(); |
213 will_process_loop_runner_->Run(); | 216 will_process_loop_runner_->Run(); |
214 will_process_loop_runner_ = nullptr; | 217 will_process_loop_runner_ = nullptr; |
215 } | 218 } |
216 | 219 |
217 int will_start_called() { return will_start_called_; } | 220 int will_start_called() { return will_start_called_; } |
218 int will_redirect_called() { return will_redirect_called_; } | 221 int will_redirect_called() { return will_redirect_called_; } |
219 int will_process_called() { return will_process_called_; } | 222 int will_process_called() { return will_process_called_; } |
220 | 223 |
221 private: | 224 private: |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // if it came from the omnibox. | 291 // if it came from the omnibox. |
289 GURL url(embedded_test_server()->GetURL("/title1.html")); | 292 GURL url(embedded_test_server()->GetURL("/title1.html")); |
290 NavigationHandleObserver observer(shell()->web_contents(), url); | 293 NavigationHandleObserver observer(shell()->web_contents(), url); |
291 ui::PageTransition expected_transition = ui::PageTransitionFromInt( | 294 ui::PageTransition expected_transition = ui::PageTransitionFromInt( |
292 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | 295 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
293 | 296 |
294 EXPECT_TRUE(NavigateToURL(shell(), url)); | 297 EXPECT_TRUE(NavigateToURL(shell(), url)); |
295 | 298 |
296 EXPECT_TRUE(observer.has_committed()); | 299 EXPECT_TRUE(observer.has_committed()); |
297 EXPECT_FALSE(observer.is_error()); | 300 EXPECT_FALSE(observer.is_error()); |
298 EXPECT_EQ(url, observer.last_committed_url()); | 301 EXPECT_EQ(url, observer.committed_url()); |
299 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 302 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
300 observer.page_transition(), expected_transition)); | 303 observer.page_transition(), expected_transition)); |
301 } | 304 } |
302 | 305 |
303 { | 306 { |
304 // Test navigating to a page with subframe. The subframe will have | 307 // Test navigating to a page with subframe. The subframe will have |
305 // PageTransition of type AUTO_SUBFRAME. | 308 // PageTransition of type AUTO_SUBFRAME. |
306 GURL url( | 309 GURL url( |
307 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); | 310 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); |
308 NavigationHandleObserver observer( | 311 NavigationHandleObserver observer( |
309 shell()->web_contents(), | 312 shell()->web_contents(), |
310 embedded_test_server()->GetURL("/cross-site/baz.com/title1.html")); | 313 embedded_test_server()->GetURL("/cross-site/baz.com/title1.html")); |
311 ui::PageTransition expected_transition = | 314 ui::PageTransition expected_transition = |
312 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_AUTO_SUBFRAME); | 315 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_AUTO_SUBFRAME); |
313 | 316 |
314 EXPECT_TRUE(NavigateToURL(shell(), url)); | 317 EXPECT_TRUE(NavigateToURL(shell(), url)); |
315 | 318 |
316 EXPECT_TRUE(observer.has_committed()); | 319 EXPECT_TRUE(observer.has_committed()); |
317 EXPECT_FALSE(observer.is_error()); | 320 EXPECT_FALSE(observer.is_error()); |
318 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title1.html"), | 321 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title1.html"), |
319 observer.last_committed_url()); | 322 observer.committed_url()); |
320 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 323 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
321 observer.page_transition(), expected_transition)); | 324 observer.page_transition(), expected_transition)); |
322 EXPECT_FALSE(observer.is_main_frame()); | 325 EXPECT_FALSE(observer.is_main_frame()); |
323 } | 326 } |
324 } | 327 } |
325 | 328 |
326 // Ensure that the following methods on NavigationHandle behave correctly: | 329 // Ensure that the following methods on NavigationHandle behave correctly: |
327 // * IsInMainFrame | 330 // * IsInMainFrame |
328 // * IsParentMainFrame | 331 // * IsParentMainFrame |
329 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifyFrameTree) { | 332 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifyFrameTree) { |
(...skipping 10 matching lines...) Expand all Loading... | |
340 | 343 |
341 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 344 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
342 | 345 |
343 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 346 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
344 ->GetFrameTree() | 347 ->GetFrameTree() |
345 ->root(); | 348 ->root(); |
346 | 349 |
347 // Verify the main frame. | 350 // Verify the main frame. |
348 EXPECT_TRUE(main_observer.has_committed()); | 351 EXPECT_TRUE(main_observer.has_committed()); |
349 EXPECT_FALSE(main_observer.is_error()); | 352 EXPECT_FALSE(main_observer.is_error()); |
350 EXPECT_EQ(main_url, main_observer.last_committed_url()); | 353 EXPECT_EQ(main_url, main_observer.committed_url()); |
351 EXPECT_TRUE(main_observer.is_main_frame()); | 354 EXPECT_TRUE(main_observer.is_main_frame()); |
352 EXPECT_EQ(root->frame_tree_node_id(), main_observer.frame_tree_node_id()); | 355 EXPECT_EQ(root->frame_tree_node_id(), main_observer.frame_tree_node_id()); |
353 | 356 |
354 // Verify the b.com frame. | 357 // Verify the b.com frame. |
355 EXPECT_TRUE(b_observer.has_committed()); | 358 EXPECT_TRUE(b_observer.has_committed()); |
356 EXPECT_FALSE(b_observer.is_error()); | 359 EXPECT_FALSE(b_observer.is_error()); |
357 EXPECT_EQ(b_url, b_observer.last_committed_url()); | 360 EXPECT_EQ(b_url, b_observer.committed_url()); |
358 EXPECT_FALSE(b_observer.is_main_frame()); | 361 EXPECT_FALSE(b_observer.is_main_frame()); |
359 EXPECT_TRUE(b_observer.is_parent_main_frame()); | 362 EXPECT_TRUE(b_observer.is_parent_main_frame()); |
360 EXPECT_EQ(root->child_at(0)->frame_tree_node_id(), | 363 EXPECT_EQ(root->child_at(0)->frame_tree_node_id(), |
361 b_observer.frame_tree_node_id()); | 364 b_observer.frame_tree_node_id()); |
362 | 365 |
363 // Verify the c.com frame. | 366 // Verify the c.com frame. |
364 EXPECT_TRUE(c_observer.has_committed()); | 367 EXPECT_TRUE(c_observer.has_committed()); |
365 EXPECT_FALSE(c_observer.is_error()); | 368 EXPECT_FALSE(c_observer.is_error()); |
366 EXPECT_EQ(c_url, c_observer.last_committed_url()); | 369 EXPECT_EQ(c_url, c_observer.committed_url()); |
367 EXPECT_FALSE(c_observer.is_main_frame()); | 370 EXPECT_FALSE(c_observer.is_main_frame()); |
368 EXPECT_FALSE(c_observer.is_parent_main_frame()); | 371 EXPECT_FALSE(c_observer.is_parent_main_frame()); |
369 EXPECT_EQ(root->child_at(0)->child_at(0)->frame_tree_node_id(), | 372 EXPECT_EQ(root->child_at(0)->child_at(0)->frame_tree_node_id(), |
370 c_observer.frame_tree_node_id()); | 373 c_observer.frame_tree_node_id()); |
371 } | 374 } |
372 | 375 |
373 // Ensure that the WasRedirected() method on NavigationHandle behaves correctly. | 376 // Ensure that the WasRedirected() method on NavigationHandle behaves correctly. |
374 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifyRedirect) { | 377 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifyRedirect) { |
375 { | 378 { |
376 GURL url(embedded_test_server()->GetURL("/title1.html")); | 379 GURL url(embedded_test_server()->GetURL("/title1.html")); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 // Wait for the end of the navigation. | 628 // Wait for the end of the navigation. |
626 navigation_observer.Wait(); | 629 navigation_observer.Wait(); |
627 | 630 |
628 EXPECT_TRUE(observer.has_committed()); | 631 EXPECT_TRUE(observer.has_committed()); |
629 EXPECT_TRUE(observer.was_redirected()); | 632 EXPECT_TRUE(observer.was_redirected()); |
630 EXPECT_FALSE(observer.is_error()); | 633 EXPECT_FALSE(observer.is_error()); |
631 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), | 634 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), |
632 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); | 635 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); |
633 } | 636 } |
634 | 637 |
638 // Ensure that the URL received with the provisional load start notification is | |
639 // already upgraded to HTTPS. | |
640 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, | |
641 ProvisionalLoadStartUrlIsHttpsUpgraded) { | |
642 GURL start_url(embedded_test_server()->GetURL( | |
643 "/navigation_handle_https_upgrade_test.html")); | |
644 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme)); | |
645 | |
646 // Builds the expected upgraded URL. | |
647 GURL::Replacements replace_scheme; | |
648 replace_scheme.SetSchemeStr("https"); | |
649 replace_scheme.SetPortStr(""); | |
650 GURL iframe_secure_url = embedded_test_server() | |
651 ->GetURL("other.com", "/title1.html") | |
652 .ReplaceComponents(replace_scheme); | |
653 ASSERT_TRUE(iframe_secure_url.SchemeIs(url::kHttpsScheme)); | |
654 ASSERT_FALSE(iframe_secure_url.has_port()); | |
655 | |
656 NavigationHandleObserver observer_main(shell()->web_contents(), start_url); | |
657 NavigationHandleObserver observer_iframe(shell()->web_contents(), | |
658 iframe_secure_url); | |
659 TestNavigationThrottleInstaller installer_main( | |
660 shell()->web_contents(), NavigationThrottle::PROCEED, | |
661 NavigationThrottle::PROCEED, NavigationThrottle::DEFER); | |
662 | |
663 // Start loading the main frame and stop at WillProcess. | |
664 shell()->LoadURL(start_url); | |
665 installer_main.WaitForThrottleWillProcess(); | |
666 EXPECT_EQ(1, installer_main.will_start_called()); | |
667 EXPECT_EQ(0, installer_main.will_redirect_called()); | |
668 EXPECT_EQ(1, installer_main.will_process_called()); | |
669 | |
670 // Create a new throttle installer and start the iframe navigation until | |
671 // WillStart. | |
672 TestNavigationThrottleInstaller installer_iframe( | |
673 shell()->web_contents(), NavigationThrottle::DEFER, | |
674 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | |
675 installer_main.navigation_throttle()->Resume(); | |
676 installer_iframe.WaitForThrottleWillStart(); | |
677 EXPECT_EQ(1, installer_iframe.will_start_called()); | |
678 EXPECT_EQ(0, installer_iframe.will_redirect_called()); | |
679 EXPECT_EQ(0, installer_iframe.will_process_called()); | |
680 | |
681 // Confirm the navigation of the main frame succeeded. | |
682 EXPECT_NE(-1, observer_main.frame_tree_node_id()); | |
683 EXPECT_EQ(start_url, observer_main.committed_url()); | |
684 EXPECT_TRUE(observer_main.has_committed()); | |
685 EXPECT_TRUE(observer_main.is_main_frame()); | |
686 EXPECT_FALSE(observer_main.is_renderer_initiated()); | |
687 | |
688 // Check that the handle observer did receive the start call with the correct | |
689 // URL. | |
690 ASSERT_NE(-1, observer_iframe.frame_tree_node_id()) | |
691 << "The start URL \"" << observer_iframe.last_unmatched_url() | |
692 << "\" didn't match the expected \"" << iframe_secure_url << "\""; | |
693 EXPECT_FALSE(observer_iframe.has_committed()); | |
694 EXPECT_FALSE(observer_iframe.is_main_frame()); | |
695 EXPECT_TRUE(observer_iframe.is_parent_main_frame()); | |
696 EXPECT_TRUE(observer_iframe.is_renderer_initiated()); | |
697 } | |
698 | |
635 } // namespace content | 699 } // namespace content |
OLD | NEW |