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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
7 #include "content/browser/frame_host/navigation_handle_impl.h" | 7 #include "content/browser/frame_host/navigation_handle_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/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 will_redirect_result_(will_redirect_result), | 47 will_redirect_result_(will_redirect_result), |
48 will_process_result_(will_process_result), | 48 will_process_result_(will_process_result), |
49 did_call_will_start_(did_call_will_start), | 49 did_call_will_start_(did_call_will_start), |
50 did_call_will_redirect_(did_call_will_redirect), | 50 did_call_will_redirect_(did_call_will_redirect), |
51 did_call_will_process_(did_call_will_process) {} | 51 did_call_will_process_(did_call_will_process) {} |
52 ~TestNavigationThrottle() override {} | 52 ~TestNavigationThrottle() override {} |
53 | 53 |
54 const char* GetNameForLogging() override { return "TestNavigationThrottle"; } | 54 const char* GetNameForLogging() override { return "TestNavigationThrottle"; } |
55 | 55 |
56 void Resume() { navigation_handle()->Resume(); } | 56 void Resume() { navigation_handle()->Resume(); } |
| 57 void Cancel(NavigationThrottle::ThrottleCheckResult result) { |
| 58 navigation_handle()->CancelDeferredNavigation(result); |
| 59 } |
57 | 60 |
58 RequestContextType request_context_type() { return request_context_type_; } | 61 RequestContextType request_context_type() { return request_context_type_; } |
59 | 62 |
60 private: | 63 private: |
61 // NavigationThrottle implementation. | 64 // NavigationThrottle implementation. |
62 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { | 65 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { |
63 NavigationHandleImpl* navigation_handle_impl = | 66 NavigationHandleImpl* navigation_handle_impl = |
64 static_cast<NavigationHandleImpl*>(navigation_handle()); | 67 static_cast<NavigationHandleImpl*>(navigation_handle()); |
65 CHECK_NE(REQUEST_CONTEXT_TYPE_UNSPECIFIED, | 68 CHECK_NE(REQUEST_CONTEXT_TYPE_UNSPECIFIED, |
66 navigation_handle_impl->request_context_type()); | 69 navigation_handle_impl->request_context_type()); |
(...skipping 27 matching lines...) Expand all Loading... |
94 | 97 |
95 NavigationThrottle::ThrottleCheckResult will_start_result_; | 98 NavigationThrottle::ThrottleCheckResult will_start_result_; |
96 NavigationThrottle::ThrottleCheckResult will_redirect_result_; | 99 NavigationThrottle::ThrottleCheckResult will_redirect_result_; |
97 NavigationThrottle::ThrottleCheckResult will_process_result_; | 100 NavigationThrottle::ThrottleCheckResult will_process_result_; |
98 base::Closure did_call_will_start_; | 101 base::Closure did_call_will_start_; |
99 base::Closure did_call_will_redirect_; | 102 base::Closure did_call_will_redirect_; |
100 base::Closure did_call_will_process_; | 103 base::Closure did_call_will_process_; |
101 RequestContextType request_context_type_ = REQUEST_CONTEXT_TYPE_UNSPECIFIED; | 104 RequestContextType request_context_type_ = REQUEST_CONTEXT_TYPE_UNSPECIFIED; |
102 }; | 105 }; |
103 | 106 |
104 // Install a TestNavigationThrottle on all following requests and allows waiting | 107 // Installs a TestNavigationThrottle either on all following requests or on |
105 // for various NavigationThrottle related events. Waiting works only for the | 108 // requests with an expected starting URL, and allows waiting for various |
106 // immediately next navigation. New instances are needed to wait for further | 109 // NavigationThrottle related events. Waiting works only for the immediately |
107 // navigations. | 110 // next navigation. New instances are needed to wait for further navigations. |
108 class TestNavigationThrottleInstaller : public WebContentsObserver { | 111 class TestNavigationThrottleInstaller : public WebContentsObserver { |
109 public: | 112 public: |
110 TestNavigationThrottleInstaller( | 113 TestNavigationThrottleInstaller( |
111 WebContents* web_contents, | 114 WebContents* web_contents, |
112 NavigationThrottle::ThrottleCheckResult will_start_result, | 115 NavigationThrottle::ThrottleCheckResult will_start_result, |
113 NavigationThrottle::ThrottleCheckResult will_redirect_result, | 116 NavigationThrottle::ThrottleCheckResult will_redirect_result, |
114 NavigationThrottle::ThrottleCheckResult will_process_result) | 117 NavigationThrottle::ThrottleCheckResult will_process_result, |
| 118 const GURL& expected_start_url = GURL()) |
115 : WebContentsObserver(web_contents), | 119 : WebContentsObserver(web_contents), |
116 will_start_result_(will_start_result), | 120 will_start_result_(will_start_result), |
117 will_redirect_result_(will_redirect_result), | 121 will_redirect_result_(will_redirect_result), |
118 will_process_result_(will_process_result), | 122 will_process_result_(will_process_result), |
| 123 expected_start_url_(expected_start_url), |
119 weak_factory_(this) {} | 124 weak_factory_(this) {} |
120 ~TestNavigationThrottleInstaller() override {} | 125 ~TestNavigationThrottleInstaller() override {} |
121 | 126 |
122 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } | 127 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } |
123 | 128 |
124 void WaitForThrottleWillStart() { | 129 void WaitForThrottleWillStart() { |
125 if (will_start_called_) | 130 if (will_start_called_) |
126 return; | 131 return; |
127 will_start_loop_runner_ = new MessageLoopRunner(); | 132 will_start_loop_runner_ = new MessageLoopRunner(); |
128 will_start_loop_runner_->Run(); | 133 will_start_loop_runner_->Run(); |
129 will_start_loop_runner_ = nullptr; | 134 will_start_loop_runner_ = nullptr; |
130 } | 135 } |
131 | 136 |
132 void WaitForThrottleWillRedirect() { | 137 void WaitForThrottleWillRedirect() { |
133 if (will_redirect_called_) | 138 if (will_redirect_called_) |
134 return; | 139 return; |
135 will_redirect_loop_runner_ = new MessageLoopRunner(); | 140 will_redirect_loop_runner_ = new MessageLoopRunner(); |
136 will_redirect_loop_runner_->Run(); | 141 will_redirect_loop_runner_->Run(); |
137 will_redirect_loop_runner_ = nullptr; | 142 will_redirect_loop_runner_ = nullptr; |
138 } | 143 } |
139 | 144 |
140 void WaitForThrottleWillProcess() { | 145 void WaitForThrottleWillProcess() { |
141 if (will_process_called_) | 146 if (will_process_called_) |
142 return; | 147 return; |
143 will_process_loop_runner_ = new MessageLoopRunner(); | 148 will_process_loop_runner_ = new MessageLoopRunner(); |
144 will_process_loop_runner_->Run(); | 149 will_process_loop_runner_->Run(); |
145 will_process_loop_runner_ = nullptr; | 150 will_process_loop_runner_ = nullptr; |
146 } | 151 } |
147 | 152 |
| 153 void Continue(NavigationThrottle::ThrottleCheckResult result) { |
| 154 ASSERT_NE(NavigationThrottle::DEFER, result); |
| 155 if (result == NavigationThrottle::PROCEED) |
| 156 navigation_throttle()->Resume(); |
| 157 else |
| 158 navigation_throttle()->Cancel(result); |
| 159 } |
| 160 |
148 int will_start_called() { return will_start_called_; } | 161 int will_start_called() { return will_start_called_; } |
149 int will_redirect_called() { return will_redirect_called_; } | 162 int will_redirect_called() { return will_redirect_called_; } |
150 int will_process_called() { return will_process_called_; } | 163 int will_process_called() { return will_process_called_; } |
151 | 164 |
152 int install_count() { return install_count_; } | 165 int install_count() { return install_count_; } |
153 | 166 |
| 167 protected: |
| 168 virtual void DidCallWillStartRequest() { |
| 169 will_start_called_++; |
| 170 if (will_start_loop_runner_) |
| 171 will_start_loop_runner_->Quit(); |
| 172 } |
| 173 |
| 174 virtual void DidCallWillRedirectRequest() { |
| 175 will_redirect_called_++; |
| 176 if (will_redirect_loop_runner_) |
| 177 will_redirect_loop_runner_->Quit(); |
| 178 } |
| 179 |
| 180 virtual void DidCallWillProcessResponse() { |
| 181 will_process_called_++; |
| 182 if (will_process_loop_runner_) |
| 183 will_process_loop_runner_->Quit(); |
| 184 } |
| 185 |
154 private: | 186 private: |
155 void DidStartNavigation(NavigationHandle* handle) override { | 187 void DidStartNavigation(NavigationHandle* handle) override { |
| 188 if (!expected_start_url_.is_empty() && |
| 189 handle->GetURL() != expected_start_url_) |
| 190 return; |
| 191 |
156 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle( | 192 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle( |
157 handle, will_start_result_, will_redirect_result_, will_process_result_, | 193 handle, will_start_result_, will_redirect_result_, will_process_result_, |
158 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest, | 194 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest, |
159 weak_factory_.GetWeakPtr()), | 195 weak_factory_.GetWeakPtr()), |
160 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest, | 196 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest, |
161 weak_factory_.GetWeakPtr()), | 197 weak_factory_.GetWeakPtr()), |
162 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse, | 198 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse, |
163 weak_factory_.GetWeakPtr()))); | 199 weak_factory_.GetWeakPtr()))); |
164 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get()); | 200 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get()); |
165 handle->RegisterThrottleForTesting(std::move(throttle)); | 201 handle->RegisterThrottleForTesting(std::move(throttle)); |
166 ++install_count_; | 202 ++install_count_; |
167 } | 203 } |
168 | 204 |
169 void DidFinishNavigation(NavigationHandle* handle) override { | 205 void DidFinishNavigation(NavigationHandle* handle) override { |
170 if (!navigation_throttle_) | 206 if (!navigation_throttle_) |
171 return; | 207 return; |
172 | 208 |
173 if (handle == navigation_throttle_->navigation_handle()) | 209 if (handle == navigation_throttle_->navigation_handle()) |
174 navigation_throttle_ = nullptr; | 210 navigation_throttle_ = nullptr; |
175 } | 211 } |
176 | 212 |
177 void DidCallWillStartRequest() { | |
178 will_start_called_++; | |
179 if (will_start_loop_runner_) | |
180 will_start_loop_runner_->Quit(); | |
181 } | |
182 | |
183 void DidCallWillRedirectRequest() { | |
184 will_redirect_called_++; | |
185 if (will_redirect_loop_runner_) | |
186 will_redirect_loop_runner_->Quit(); | |
187 } | |
188 | |
189 void DidCallWillProcessResponse() { | |
190 will_process_called_++; | |
191 if (will_process_loop_runner_) | |
192 will_process_loop_runner_->Quit(); | |
193 } | |
194 | |
195 NavigationThrottle::ThrottleCheckResult will_start_result_; | 213 NavigationThrottle::ThrottleCheckResult will_start_result_; |
196 NavigationThrottle::ThrottleCheckResult will_redirect_result_; | 214 NavigationThrottle::ThrottleCheckResult will_redirect_result_; |
197 NavigationThrottle::ThrottleCheckResult will_process_result_; | 215 NavigationThrottle::ThrottleCheckResult will_process_result_; |
198 int will_start_called_ = 0; | 216 int will_start_called_ = 0; |
199 int will_redirect_called_ = 0; | 217 int will_redirect_called_ = 0; |
200 int will_process_called_ = 0; | 218 int will_process_called_ = 0; |
201 TestNavigationThrottle* navigation_throttle_ = nullptr; | 219 TestNavigationThrottle* navigation_throttle_ = nullptr; |
202 int install_count_ = 0; | 220 int install_count_ = 0; |
203 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; | 221 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; |
204 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_; | 222 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_; |
205 scoped_refptr<MessageLoopRunner> will_process_loop_runner_; | 223 scoped_refptr<MessageLoopRunner> will_process_loop_runner_; |
| 224 GURL expected_start_url_; |
206 | 225 |
207 // The throttle installer can be deleted before all tasks posted by its | 226 // The throttle installer can be deleted before all tasks posted by its |
208 // throttles are run, so it must be referenced via weak pointers. | 227 // throttles are run, so it must be referenced via weak pointers. |
209 base::WeakPtrFactory<TestNavigationThrottleInstaller> weak_factory_; | 228 base::WeakPtrFactory<TestNavigationThrottleInstaller> weak_factory_; |
210 }; | 229 }; |
211 | 230 |
| 231 // Same as above, but installs NavigationThrottles that do not directly return |
| 232 // the pre-programmed check results, but first DEFER the navigation at each |
| 233 // stage and then resume/cancel asynchronously. |
| 234 class TestDeferringNavigationThrottleInstaller |
| 235 : public TestNavigationThrottleInstaller { |
| 236 public: |
| 237 TestDeferringNavigationThrottleInstaller( |
| 238 WebContents* web_contents, |
| 239 NavigationThrottle::ThrottleCheckResult will_start_result, |
| 240 NavigationThrottle::ThrottleCheckResult will_redirect_result, |
| 241 NavigationThrottle::ThrottleCheckResult will_process_result, |
| 242 GURL expected_start_url = GURL()) |
| 243 : TestNavigationThrottleInstaller(web_contents, |
| 244 NavigationThrottle::DEFER, |
| 245 NavigationThrottle::DEFER, |
| 246 NavigationThrottle::DEFER, |
| 247 expected_start_url), |
| 248 will_start_deferred_result_(will_start_result), |
| 249 will_redirect_deferred_result_(will_redirect_result), |
| 250 will_process_deferred_result_(will_process_result) {} |
| 251 |
| 252 protected: |
| 253 void DidCallWillStartRequest() override { |
| 254 TestNavigationThrottleInstaller::DidCallWillStartRequest(); |
| 255 Continue(will_start_deferred_result_); |
| 256 } |
| 257 |
| 258 void DidCallWillRedirectRequest() override { |
| 259 TestNavigationThrottleInstaller::DidCallWillStartRequest(); |
| 260 Continue(will_redirect_deferred_result_); |
| 261 } |
| 262 |
| 263 void DidCallWillProcessResponse() override { |
| 264 TestNavigationThrottleInstaller::DidCallWillStartRequest(); |
| 265 Continue(will_process_deferred_result_); |
| 266 } |
| 267 |
| 268 private: |
| 269 NavigationThrottle::ThrottleCheckResult will_start_deferred_result_; |
| 270 NavigationThrottle::ThrottleCheckResult will_redirect_deferred_result_; |
| 271 NavigationThrottle::ThrottleCheckResult will_process_deferred_result_; |
| 272 }; |
| 273 |
212 // Records all navigation start URLs from the WebContents. | 274 // Records all navigation start URLs from the WebContents. |
213 class NavigationStartUrlRecorder : public WebContentsObserver { | 275 class NavigationStartUrlRecorder : public WebContentsObserver { |
214 public: | 276 public: |
215 NavigationStartUrlRecorder(WebContents* web_contents) | 277 NavigationStartUrlRecorder(WebContents* web_contents) |
216 : WebContentsObserver(web_contents) {} | 278 : WebContentsObserver(web_contents) {} |
217 | 279 |
218 void DidStartNavigation(NavigationHandle* navigation_handle) override { | 280 void DidStartNavigation(NavigationHandle* navigation_handle) override { |
219 urls_.push_back(navigation_handle->GetURL()); | 281 urls_.push_back(navigation_handle->GetURL()); |
220 } | 282 } |
221 | 283 |
222 const std::vector<GURL>& urls() const { return urls_; } | 284 const std::vector<GURL>& urls() const { return urls_; } |
223 | 285 |
224 private: | 286 private: |
225 std::vector<GURL> urls_; | 287 std::vector<GURL> urls_; |
226 }; | 288 }; |
227 | 289 |
| 290 void ExpectChildFrameSetAsCollapsedInFTN(Shell* shell, bool expect_collapsed) { |
| 291 // Check if the frame should be collapsed in theory as per FTN. |
| 292 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell->web_contents()) |
| 293 ->GetFrameTree() |
| 294 ->root(); |
| 295 ASSERT_EQ(1u, root->child_count()); |
| 296 FrameTreeNode* child = root->child_at(0u); |
| 297 EXPECT_EQ(expect_collapsed, child->is_collapsed()); |
| 298 } |
| 299 |
| 300 void ExpectChildFrameCollapsedInLayout(Shell* shell, |
| 301 const std::string& frame_id, |
| 302 bool expect_collapsed) { |
| 303 // Check if the frame is collapsed in practice. |
| 304 const char kScript[] = |
| 305 "window.domAutomationController.send(" |
| 306 " document.getElementById(\"%s\").clientWidth" |
| 307 ");"; |
| 308 int client_width = 0; |
| 309 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 310 shell, base::StringPrintf(kScript, frame_id.c_str()), &client_width)); |
| 311 EXPECT_EQ(expect_collapsed, !client_width) << client_width; |
| 312 } |
| 313 |
| 314 void ExpectChildFrameCollapsed(Shell* shell, |
| 315 const std::string& frame_id, |
| 316 bool expect_collapsed) { |
| 317 ExpectChildFrameSetAsCollapsedInFTN(shell, expect_collapsed); |
| 318 ExpectChildFrameCollapsedInLayout(shell, frame_id, expect_collapsed); |
| 319 } |
| 320 |
228 } // namespace | 321 } // namespace |
229 | 322 |
230 class NavigationHandleImplBrowserTest : public ContentBrowserTest { | 323 class NavigationHandleImplBrowserTest : public ContentBrowserTest { |
231 protected: | 324 protected: |
232 void SetUpOnMainThread() override { | 325 void SetUpOnMainThread() override { |
233 host_resolver()->AddRule("*", "127.0.0.1"); | 326 host_resolver()->AddRule("*", "127.0.0.1"); |
234 SetupCrossSiteRedirector(embedded_test_server()); | 327 SetupCrossSiteRedirector(embedded_test_server()); |
235 ASSERT_TRUE(embedded_test_server()->Start()); | 328 ASSERT_TRUE(embedded_test_server()->Start()); |
236 } | 329 } |
237 }; | 330 }; |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 // Wait for the end of the navigation. | 719 // Wait for the end of the navigation. |
627 navigation_observer.Wait(); | 720 navigation_observer.Wait(); |
628 | 721 |
629 EXPECT_TRUE(observer.has_committed()); | 722 EXPECT_TRUE(observer.has_committed()); |
630 EXPECT_TRUE(observer.was_redirected()); | 723 EXPECT_TRUE(observer.was_redirected()); |
631 EXPECT_FALSE(observer.is_error()); | 724 EXPECT_FALSE(observer.is_error()); |
632 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), | 725 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), |
633 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); | 726 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); |
634 } | 727 } |
635 | 728 |
| 729 // Ensure that a NavigationThrottle can block the navigation and collapse the |
| 730 // frame owner both on request start as well as after a redirect. Plus, ensure |
| 731 // that the frame is restored on the subsequent non-error-page navigation. |
| 732 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, |
| 733 ThrottleBlockAndCollapse) { |
| 734 const char kChildFrameId[] = "child0"; |
| 735 GURL main_url(embedded_test_server()->GetURL( |
| 736 "a.com", "/frame_tree/page_with_one_frame.html")); |
| 737 GURL blocked_subframe_url(embedded_test_server()->GetURL( |
| 738 "a.com", "/cross-site/baz.com/title1.html")); |
| 739 GURL allowed_subframe_url(embedded_test_server()->GetURL( |
| 740 "a.com", "/cross-site/baz.com/title2.html")); |
| 741 GURL allowed_subframe_final_url( |
| 742 embedded_test_server()->GetURL("baz.com", "/title2.html")); |
| 743 |
| 744 // Exercise both synchronous and deferred throttle check results, and both on |
| 745 // WillStartRequest and on WillRedirectRequest. |
| 746 const struct { |
| 747 NavigationThrottle::ThrottleCheckResult will_start_result; |
| 748 NavigationThrottle::ThrottleCheckResult will_redirect_result; |
| 749 bool deferred_block; |
| 750 } kTestCases[] = { |
| 751 {NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE, |
| 752 NavigationThrottle::PROCEED, false}, |
| 753 {NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE, |
| 754 NavigationThrottle::PROCEED, true}, |
| 755 {NavigationThrottle::PROCEED, |
| 756 NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE, false}, |
| 757 {NavigationThrottle::PROCEED, |
| 758 NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE, true}, |
| 759 }; |
| 760 |
| 761 for (const auto& test_case : kTestCases) { |
| 762 SCOPED_TRACE(::testing::Message() << test_case.will_start_result << ", " |
| 763 << test_case.will_redirect_result << ", " |
| 764 << test_case.deferred_block); |
| 765 |
| 766 if (!IsBrowserSideNavigationEnabled() && |
| 767 test_case.will_redirect_result == |
| 768 NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE) { |
| 769 continue; |
| 770 } |
| 771 |
| 772 std::unique_ptr<TestNavigationThrottleInstaller> |
| 773 subframe_throttle_installer; |
| 774 if (test_case.deferred_block) { |
| 775 subframe_throttle_installer.reset( |
| 776 new TestDeferringNavigationThrottleInstaller( |
| 777 shell()->web_contents(), test_case.will_start_result, |
| 778 test_case.will_redirect_result, NavigationThrottle::PROCEED, |
| 779 blocked_subframe_url)); |
| 780 } else { |
| 781 subframe_throttle_installer.reset(new TestNavigationThrottleInstaller( |
| 782 shell()->web_contents(), test_case.will_start_result, |
| 783 test_case.will_redirect_result, NavigationThrottle::PROCEED, |
| 784 blocked_subframe_url)); |
| 785 } |
| 786 |
| 787 { |
| 788 SCOPED_TRACE("Initial navigation blocked on main frame load."); |
| 789 NavigationHandleObserver subframe_observer(shell()->web_contents(), |
| 790 blocked_subframe_url); |
| 791 |
| 792 ASSERT_TRUE(NavigateToURL(shell(), main_url)); |
| 793 EXPECT_TRUE(subframe_observer.is_error()); |
| 794 EXPECT_TRUE(subframe_observer.has_committed()); |
| 795 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, subframe_observer.net_error_code()); |
| 796 ExpectChildFrameCollapsed(shell(), kChildFrameId, |
| 797 true /* expect_collapsed */); |
| 798 } |
| 799 |
| 800 { |
| 801 SCOPED_TRACE("Subsequent subframe navigation is allowed."); |
| 802 NavigationHandleObserver subframe_observer(shell()->web_contents(), |
| 803 allowed_subframe_url); |
| 804 |
| 805 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), kChildFrameId, |
| 806 allowed_subframe_url)); |
| 807 EXPECT_TRUE(subframe_observer.has_committed()); |
| 808 EXPECT_FALSE(subframe_observer.is_error()); |
| 809 EXPECT_EQ(allowed_subframe_final_url, |
| 810 subframe_observer.last_committed_url()); |
| 811 ExpectChildFrameCollapsed(shell(), kChildFrameId, |
| 812 false /* expect_collapsed */); |
| 813 } |
| 814 |
| 815 { |
| 816 SCOPED_TRACE("Subsequent subframe navigation is blocked."); |
| 817 NavigationHandleObserver subframe_observer(shell()->web_contents(), |
| 818 blocked_subframe_url); |
| 819 |
| 820 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), kChildFrameId, |
| 821 blocked_subframe_url)); |
| 822 |
| 823 EXPECT_TRUE(subframe_observer.has_committed()); |
| 824 EXPECT_TRUE(subframe_observer.is_error()); |
| 825 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, subframe_observer.net_error_code()); |
| 826 ExpectChildFrameCollapsed(shell(), kChildFrameId, |
| 827 true /* expect_collapsed */); |
| 828 } |
| 829 } |
| 830 } |
| 831 |
| 832 // BLOCK_REQUEST_AND_COLLAPSE should block the navigation in legacy <frame>'s, |
| 833 // but should not collapse the <frame> element itself for legacy reasons. |
| 834 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, |
| 835 ThrottleBlockAndCollapse_LegacyFrameNotCollapsed) { |
| 836 const char kChildFrameId[] = "child0"; |
| 837 GURL main_url(embedded_test_server()->GetURL( |
| 838 "a.com", "/frame_tree/legacy_frameset.html")); |
| 839 GURL blocked_subframe_url( |
| 840 embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 841 GURL allowed_subframe_url( |
| 842 embedded_test_server()->GetURL("a.com", "/title2.html")); |
| 843 |
| 844 TestNavigationThrottleInstaller subframe_throttle_installer( |
| 845 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE, |
| 846 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED, |
| 847 blocked_subframe_url); |
| 848 |
| 849 { |
| 850 SCOPED_TRACE("Initial navigation blocked on main frame load."); |
| 851 NavigationHandleObserver subframe_observer(shell()->web_contents(), |
| 852 blocked_subframe_url); |
| 853 |
| 854 ASSERT_TRUE(NavigateToURL(shell(), main_url)); |
| 855 EXPECT_TRUE(subframe_observer.is_error()); |
| 856 EXPECT_TRUE(subframe_observer.has_committed()); |
| 857 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, subframe_observer.net_error_code()); |
| 858 ExpectChildFrameSetAsCollapsedInFTN(shell(), true /* expect_collapsed */); |
| 859 ExpectChildFrameCollapsedInLayout(shell(), kChildFrameId, |
| 860 false /* expect_collapsed */); |
| 861 } |
| 862 |
| 863 { |
| 864 SCOPED_TRACE("Subsequent subframe navigation is allowed."); |
| 865 NavigationHandleObserver subframe_observer(shell()->web_contents(), |
| 866 allowed_subframe_url); |
| 867 |
| 868 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), kChildFrameId, |
| 869 allowed_subframe_url)); |
| 870 EXPECT_TRUE(subframe_observer.has_committed()); |
| 871 EXPECT_FALSE(subframe_observer.is_error()); |
| 872 EXPECT_EQ(allowed_subframe_url, subframe_observer.last_committed_url()); |
| 873 ExpectChildFrameCollapsed(shell(), kChildFrameId, |
| 874 false /* expect_collapsed */); |
| 875 } |
| 876 } |
| 877 |
636 // Checks that the RequestContextType value is properly set. | 878 // Checks that the RequestContextType value is properly set. |
637 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, | 879 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, |
638 VerifyRequestContextTypeForFrameTree) { | 880 VerifyRequestContextTypeForFrameTree) { |
639 GURL main_url(embedded_test_server()->GetURL( | 881 GURL main_url(embedded_test_server()->GetURL( |
640 "a.com", "/cross_site_iframe_factory.html?a(b(c))")); | 882 "a.com", "/cross_site_iframe_factory.html?a(b(c))")); |
641 GURL b_url(embedded_test_server()->GetURL( | 883 GURL b_url(embedded_test_server()->GetURL( |
642 "b.com", "/cross_site_iframe_factory.html?b(c())")); | 884 "b.com", "/cross_site_iframe_factory.html?b(c())")); |
643 GURL c_url(embedded_test_server()->GetURL( | 885 GURL c_url(embedded_test_server()->GetURL( |
644 "c.com", "/cross_site_iframe_factory.html?c()")); | 886 "c.com", "/cross_site_iframe_factory.html?c()")); |
645 | 887 |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 NavigationHandleObserver observer(shell()->web_contents(), error_url); | 1467 NavigationHandleObserver observer(shell()->web_contents(), error_url); |
1226 EXPECT_FALSE(NavigateToURL(shell(), error_url)); | 1468 EXPECT_FALSE(NavigateToURL(shell(), error_url)); |
1227 EXPECT_TRUE(observer.has_committed()); | 1469 EXPECT_TRUE(observer.has_committed()); |
1228 EXPECT_TRUE(observer.is_error()); | 1470 EXPECT_TRUE(observer.is_error()); |
1229 EXPECT_NE(site_instance, | 1471 EXPECT_NE(site_instance, |
1230 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); | 1472 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); |
1231 } | 1473 } |
1232 } | 1474 } |
1233 | 1475 |
1234 } // namespace content | 1476 } // namespace content |
OLD | NEW |