OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
8 #include "content/public/browser/navigation_entry.h" | 8 #include "content/public/browser/navigation_entry.h" |
9 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 9 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
10 #include "content/public/browser/resource_throttle.h" | 10 #include "content/public/browser/resource_throttle.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 // Create a RunLoop that will be stopped once the request for the tracked | 58 // Create a RunLoop that will be stopped once the request for the tracked |
59 // URL has been destroyed, to allow tracking the URL while also waiting for | 59 // URL has been destroyed, to allow tracking the URL while also waiting for |
60 // other events. | 60 // other events. |
61 run_loop_.reset(new base::RunLoop()); | 61 run_loop_.reset(new base::RunLoop()); |
62 | 62 |
63 BrowserThread::PostTask( | 63 BrowserThread::PostTask( |
64 BrowserThread::IO, FROM_HERE, | 64 BrowserThread::IO, FROM_HERE, |
65 base::Bind( | 65 base::Bind( |
66 &TrackingResourceDispatcherHostDelegate::SetTrackedURLOnIOThread, | 66 &TrackingResourceDispatcherHostDelegate::SetTrackedURLOnIOThread, |
67 base::Unretained(this), | 67 base::Unretained(this), tracked_url, run_loop_->QuitClosure())); |
68 tracked_url)); | |
69 } | 68 } |
70 | 69 |
71 // Waits until the tracked URL has been requests, and the request for it has | 70 // Waits until the tracked URL has been requested, and the request for it has |
72 // been destroyed. | 71 // been destroyed. |
73 bool WaitForTrackedURLAndGetCompleted() { | 72 bool WaitForTrackedURLAndGetCompleted() { |
74 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 73 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
75 run_loop_->Run(); | 74 run_loop_->Run(); |
76 run_loop_.reset(); | 75 run_loop_.reset(); |
77 return tracked_request_completed_; | 76 return tracked_request_completed_; |
78 } | 77 } |
79 | 78 |
80 private: | 79 private: |
81 // ResourceThrottle attached to request for the tracked URL. On destruction, | 80 // ResourceThrottle attached to request for the tracked URL. On destruction, |
(...skipping 18 matching lines...) Expand all Loading... |
100 return "TrackingThrottle"; | 99 return "TrackingThrottle"; |
101 } | 100 } |
102 | 101 |
103 private: | 102 private: |
104 net::URLRequest* request_; | 103 net::URLRequest* request_; |
105 TrackingResourceDispatcherHostDelegate* tracker_; | 104 TrackingResourceDispatcherHostDelegate* tracker_; |
106 | 105 |
107 DISALLOW_COPY_AND_ASSIGN(TrackingThrottle); | 106 DISALLOW_COPY_AND_ASSIGN(TrackingThrottle); |
108 }; | 107 }; |
109 | 108 |
110 void SetTrackedURLOnIOThread(const GURL& tracked_url) { | 109 void SetTrackedURLOnIOThread(const GURL& tracked_url, |
| 110 const base::Closure& run_loop_quit_closure) { |
111 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 111 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
112 throttle_created_ = false; | 112 throttle_created_ = false; |
113 tracked_url_ = tracked_url; | 113 tracked_url_ = tracked_url; |
| 114 run_loop_quit_closure_ = run_loop_quit_closure; |
114 } | 115 } |
115 | 116 |
116 void OnTrackedRequestDestroyed(bool completed) { | 117 void OnTrackedRequestDestroyed(bool completed) { |
117 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 118 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
118 tracked_request_completed_ = completed; | 119 tracked_request_completed_ = completed; |
119 tracked_url_ = GURL(); | 120 tracked_url_ = GURL(); |
120 | 121 |
121 BrowserThread::PostTask( | 122 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
122 BrowserThread::UI, FROM_HERE, run_loop_->QuitClosure()); | 123 run_loop_quit_closure_); |
123 } | 124 } |
124 | 125 |
125 // These live on the IO thread. | 126 // These live on the IO thread. |
126 GURL tracked_url_; | 127 GURL tracked_url_; |
127 bool throttle_created_; | 128 bool throttle_created_; |
| 129 base::Closure run_loop_quit_closure_; |
128 | 130 |
129 // This is created and destroyed on the UI thread, but stopped on the IO | 131 // This lives on the UI thread. |
130 // thread. | |
131 scoped_ptr<base::RunLoop> run_loop_; | 132 scoped_ptr<base::RunLoop> run_loop_; |
132 | 133 |
133 // Set on the IO thread while |run_loop_| is non-NULL, read on the UI thread | 134 // Set on the IO thread while |run_loop_| is non-nullptr, read on the UI |
134 // after deleting run_loop_. | 135 // thread after deleting run_loop_. |
135 bool tracked_request_completed_; | 136 bool tracked_request_completed_; |
136 | 137 |
137 DISALLOW_COPY_AND_ASSIGN(TrackingResourceDispatcherHostDelegate); | 138 DISALLOW_COPY_AND_ASSIGN(TrackingResourceDispatcherHostDelegate); |
138 }; | 139 }; |
139 | 140 |
140 // WebContentsDelegate that fails to open a URL when there's a request that | 141 // WebContentsDelegate that fails to open a URL when there's a request that |
141 // needs to be transferred between renderers. | 142 // needs to be transferred between renderers. |
142 class NoTransferRequestDelegate : public WebContentsDelegate { | 143 class NoTransferRequestDelegate : public WebContentsDelegate { |
143 public: | 144 public: |
144 NoTransferRequestDelegate() {} | 145 NoTransferRequestDelegate() {} |
145 | 146 |
146 WebContents* OpenURLFromTab(WebContents* source, | 147 WebContents* OpenURLFromTab(WebContents* source, |
147 const OpenURLParams& params) override { | 148 const OpenURLParams& params) override { |
148 bool is_transfer = | 149 bool is_transfer = |
149 (params.transferred_global_request_id != GlobalRequestID()); | 150 (params.transferred_global_request_id != GlobalRequestID()); |
150 if (is_transfer) | 151 if (is_transfer) |
151 return NULL; | 152 return nullptr; |
152 NavigationController::LoadURLParams load_url_params(params.url); | 153 NavigationController::LoadURLParams load_url_params(params.url); |
153 load_url_params.referrer = params.referrer; | 154 load_url_params.referrer = params.referrer; |
154 load_url_params.frame_tree_node_id = params.frame_tree_node_id; | 155 load_url_params.frame_tree_node_id = params.frame_tree_node_id; |
155 load_url_params.transition_type = params.transition; | 156 load_url_params.transition_type = params.transition; |
156 load_url_params.extra_headers = params.extra_headers; | 157 load_url_params.extra_headers = params.extra_headers; |
157 load_url_params.should_replace_current_entry = | 158 load_url_params.should_replace_current_entry = |
158 params.should_replace_current_entry; | 159 params.should_replace_current_entry; |
159 load_url_params.is_renderer_initiated = true; | 160 load_url_params.is_renderer_initiated = true; |
160 source->GetController().LoadURLWithParams(load_url_params); | 161 source->GetController().LoadURLWithParams(load_url_params); |
161 return source; | 162 return source; |
162 } | 163 } |
163 | 164 |
164 private: | 165 private: |
165 DISALLOW_COPY_AND_ASSIGN(NoTransferRequestDelegate); | 166 DISALLOW_COPY_AND_ASSIGN(NoTransferRequestDelegate); |
166 }; | 167 }; |
167 | 168 |
168 class CrossSiteTransferTest : public ContentBrowserTest { | 169 class CrossSiteTransferTest : public ContentBrowserTest { |
169 public: | 170 public: |
170 CrossSiteTransferTest() : old_delegate_(NULL) { | 171 CrossSiteTransferTest() : old_delegate_(nullptr) {} |
171 } | |
172 | 172 |
173 // ContentBrowserTest implementation: | 173 // ContentBrowserTest implementation: |
174 void SetUpOnMainThread() override { | 174 void SetUpOnMainThread() override { |
175 BrowserThread::PostTask( | 175 BrowserThread::PostTask( |
176 BrowserThread::IO, FROM_HERE, | 176 BrowserThread::IO, FROM_HERE, |
177 base::Bind( | 177 base::Bind(&CrossSiteTransferTest::InjectResourceDispatcherHostDelegate, |
178 &CrossSiteTransferTest::InjectResourceDisptcherHostDelegate, | 178 base::Unretained(this))); |
179 base::Unretained(this))); | |
180 host_resolver()->AddRule("*", "127.0.0.1"); | 179 host_resolver()->AddRule("*", "127.0.0.1"); |
181 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 180 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
182 content::SetupCrossSiteRedirector(embedded_test_server()); | 181 content::SetupCrossSiteRedirector(embedded_test_server()); |
183 } | 182 } |
184 | 183 |
185 void TearDownOnMainThread() override { | 184 void TearDownOnMainThread() override { |
186 BrowserThread::PostTask( | 185 BrowserThread::PostTask( |
187 BrowserThread::IO, FROM_HERE, | 186 BrowserThread::IO, FROM_HERE, |
188 base::Bind( | 187 base::Bind( |
189 &CrossSiteTransferTest::RestoreResourceDisptcherHostDelegate, | 188 &CrossSiteTransferTest::RestoreResourceDisptcherHostDelegate, |
(...skipping 14 matching lines...) Expand all Loading... |
204 bool result = ExecuteScript(window->web_contents(), script); | 203 bool result = ExecuteScript(window->web_contents(), script); |
205 EXPECT_TRUE(result); | 204 EXPECT_TRUE(result); |
206 if (should_wait_for_navigation) | 205 if (should_wait_for_navigation) |
207 load_observer.Wait(); | 206 load_observer.Wait(); |
208 } | 207 } |
209 | 208 |
210 void SetUpCommandLine(base::CommandLine* command_line) override { | 209 void SetUpCommandLine(base::CommandLine* command_line) override { |
211 IsolateAllSitesForTesting(command_line); | 210 IsolateAllSitesForTesting(command_line); |
212 } | 211 } |
213 | 212 |
214 void InjectResourceDisptcherHostDelegate() { | 213 void InjectResourceDispatcherHostDelegate() { |
215 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 214 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
216 old_delegate_ = ResourceDispatcherHostImpl::Get()->delegate(); | 215 old_delegate_ = ResourceDispatcherHostImpl::Get()->delegate(); |
217 ResourceDispatcherHostImpl::Get()->SetDelegate(&tracking_delegate_); | 216 ResourceDispatcherHostImpl::Get()->SetDelegate(&tracking_delegate_); |
218 } | 217 } |
219 | 218 |
220 void RestoreResourceDisptcherHostDelegate() { | 219 void RestoreResourceDisptcherHostDelegate() { |
221 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 220 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
222 ResourceDispatcherHostImpl::Get()->SetDelegate(old_delegate_); | 221 ResourceDispatcherHostImpl::Get()->SetDelegate(old_delegate_); |
223 old_delegate_ = NULL; | 222 old_delegate_ = nullptr; |
224 } | 223 } |
225 | 224 |
226 TrackingResourceDispatcherHostDelegate& tracking_delegate() { | 225 TrackingResourceDispatcherHostDelegate& tracking_delegate() { |
227 return tracking_delegate_; | 226 return tracking_delegate_; |
228 } | 227 } |
229 | 228 |
230 private: | 229 private: |
231 TrackingResourceDispatcherHostDelegate tracking_delegate_; | 230 TrackingResourceDispatcherHostDelegate tracking_delegate_; |
232 ResourceDispatcherHostDelegate* old_delegate_; | 231 ResourceDispatcherHostDelegate* old_delegate_; |
233 }; | 232 }; |
(...skipping 12 matching lines...) Expand all Loading... |
246 #endif | 245 #endif |
247 // Tests that the |should_replace_current_entry| flag persists correctly across | 246 // Tests that the |should_replace_current_entry| flag persists correctly across |
248 // request transfers that began with a cross-process navigation. | 247 // request transfers that began with a cross-process navigation. |
249 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, | 248 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, |
250 MAYBE_ReplaceEntryCrossProcessThenTransfer) { | 249 MAYBE_ReplaceEntryCrossProcessThenTransfer) { |
251 const NavigationController& controller = | 250 const NavigationController& controller = |
252 shell()->web_contents()->GetController(); | 251 shell()->web_contents()->GetController(); |
253 | 252 |
254 // Navigate to a starting URL, so there is a history entry to replace. | 253 // Navigate to a starting URL, so there is a history entry to replace. |
255 GURL url1 = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); | 254 GURL url1 = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); |
256 NavigateToURL(shell(), url1); | 255 EXPECT_TRUE(NavigateToURL(shell(), url1)); |
257 | 256 |
258 // Force all future navigations to transfer. Note that this includes same-site | 257 // Force all future navigations to transfer. Note that this includes same-site |
259 // navigiations which may cause double process swaps (via OpenURL and then via | 258 // navigiations which may cause double process swaps (via OpenURL and then via |
260 // transfer). This test intentionally exercises that case. | 259 // transfer). This test intentionally exercises that case. |
261 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); | 260 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); |
262 | 261 |
263 // Navigate to a page on A.com with entry replacement. This navigation is | 262 // Navigate to a page on A.com with entry replacement. This navigation is |
264 // cross-site, so the renderer will send it to the browser via OpenURL to give | 263 // cross-site, so the renderer will send it to the browser via OpenURL to give |
265 // to a new process. It will then be transferred into yet another process due | 264 // to a new process. It will then be transferred into yet another process due |
266 // to the call above. | 265 // to the call above. |
267 GURL url2 = | 266 GURL url2 = |
268 embedded_test_server()->GetURL("A.com", "/site_isolation/blank.html?2"); | 267 embedded_test_server()->GetURL("A.com", "/site_isolation/blank.html?2"); |
269 // Used to make sure the request for url2 succeeds, and there was only one of | 268 // Used to make sure the request for url2 succeeds, and there was only one of |
270 // them. | 269 // them. |
271 tracking_delegate().SetTrackedURL(url2); | 270 tracking_delegate().SetTrackedURL(url2); |
272 NavigateToURLContentInitiated(shell(), url2, true, true); | 271 NavigateToURLContentInitiated(shell(), url2, true, true); |
273 | 272 |
274 // There should be one history entry. url2 should have replaced url1. | 273 // There should be one history entry. url2 should have replaced url1. |
275 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 274 EXPECT_TRUE(controller.GetPendingEntry() == nullptr); |
276 EXPECT_EQ(1, controller.GetEntryCount()); | 275 EXPECT_EQ(1, controller.GetEntryCount()); |
277 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 276 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
278 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 277 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
279 // Make sure the request succeeded. | 278 // Make sure the request succeeded. |
280 EXPECT_TRUE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); | 279 EXPECT_TRUE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); |
281 | 280 |
282 // Now navigate as before to a page on B.com, but normally (without | 281 // Now navigate as before to a page on B.com, but normally (without |
283 // replacement). This will still perform a double process-swap as above, via | 282 // replacement). This will still perform a double process-swap as above, via |
284 // OpenURL and then transfer. | 283 // OpenURL and then transfer. |
285 GURL url3 = | 284 GURL url3 = |
286 embedded_test_server()->GetURL("B.com", "/site_isolation/blank.html?3"); | 285 embedded_test_server()->GetURL("B.com", "/site_isolation/blank.html?3"); |
287 // Used to make sure the request for url3 succeeds, and there was only one of | 286 // Used to make sure the request for url3 succeeds, and there was only one of |
288 // them. | 287 // them. |
289 tracking_delegate().SetTrackedURL(url3); | 288 tracking_delegate().SetTrackedURL(url3); |
290 NavigateToURLContentInitiated(shell(), url3, false, true); | 289 NavigateToURLContentInitiated(shell(), url3, false, true); |
291 | 290 |
292 // There should be two history entries. url2 should have replaced url1. url2 | 291 // There should be two history entries. url2 should have replaced url1. url2 |
293 // should not have replaced url3. | 292 // should not have replaced url3. |
294 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 293 EXPECT_TRUE(controller.GetPendingEntry() == nullptr); |
295 EXPECT_EQ(2, controller.GetEntryCount()); | 294 EXPECT_EQ(2, controller.GetEntryCount()); |
296 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 295 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
297 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 296 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
298 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); | 297 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); |
299 | 298 |
300 // Make sure the request succeeded. | 299 // Make sure the request succeeded. |
301 EXPECT_TRUE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); | 300 EXPECT_TRUE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); |
302 } | 301 } |
303 | 302 |
304 // Tests that the |should_replace_current_entry| flag persists correctly across | 303 // Tests that the |should_replace_current_entry| flag persists correctly across |
305 // request transfers that began with a content-initiated in-process | 304 // request transfers that began with a content-initiated in-process |
306 // navigation. This test is the same as the test above, except transfering from | 305 // navigation. This test is the same as the test above, except transfering from |
307 // in-process. | 306 // in-process. |
308 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, | 307 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, |
309 ReplaceEntryInProcessThenTranfers) { | 308 ReplaceEntryInProcessThenTranfers) { |
310 const NavigationController& controller = | 309 const NavigationController& controller = |
311 shell()->web_contents()->GetController(); | 310 shell()->web_contents()->GetController(); |
312 | 311 |
313 // Navigate to a starting URL, so there is a history entry to replace. | 312 // Navigate to a starting URL, so there is a history entry to replace. |
314 GURL url = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); | 313 GURL url = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); |
315 NavigateToURL(shell(), url); | 314 EXPECT_TRUE(NavigateToURL(shell(), url)); |
316 | 315 |
317 // Force all future navigations to transfer. Note that this includes same-site | 316 // Force all future navigations to transfer. Note that this includes same-site |
318 // navigiations which may cause double process swaps (via OpenURL and then via | 317 // navigiations which may cause double process swaps (via OpenURL and then via |
319 // transfer). All navigations in this test are same-site, so it only swaps | 318 // transfer). All navigations in this test are same-site, so it only swaps |
320 // processes via request transfer. | 319 // processes via request transfer. |
321 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); | 320 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); |
322 | 321 |
323 // Navigate in-process with entry replacement. It will then be transferred | 322 // Navigate in-process with entry replacement. It will then be transferred |
324 // into a new one due to the call above. | 323 // into a new one due to the call above. |
325 GURL url2 = embedded_test_server()->GetURL("/site_isolation/blank.html?2"); | 324 GURL url2 = embedded_test_server()->GetURL("/site_isolation/blank.html?2"); |
326 NavigateToURLContentInitiated(shell(), url2, true, true); | 325 NavigateToURLContentInitiated(shell(), url2, true, true); |
327 | 326 |
328 // There should be one history entry. url2 should have replaced url1. | 327 // There should be one history entry. url2 should have replaced url1. |
329 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 328 EXPECT_TRUE(controller.GetPendingEntry() == nullptr); |
330 EXPECT_EQ(1, controller.GetEntryCount()); | 329 EXPECT_EQ(1, controller.GetEntryCount()); |
331 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 330 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
332 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 331 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
333 | 332 |
334 // Now navigate as before, but without replacement. | 333 // Now navigate as before, but without replacement. |
335 GURL url3 = embedded_test_server()->GetURL("/site_isolation/blank.html?3"); | 334 GURL url3 = embedded_test_server()->GetURL("/site_isolation/blank.html?3"); |
336 NavigateToURLContentInitiated(shell(), url3, false, true); | 335 NavigateToURLContentInitiated(shell(), url3, false, true); |
337 | 336 |
338 // There should be two history entries. url2 should have replaced url1. url2 | 337 // There should be two history entries. url2 should have replaced url1. url2 |
339 // should not have replaced url3. | 338 // should not have replaced url3. |
340 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 339 EXPECT_TRUE(controller.GetPendingEntry() == nullptr); |
341 EXPECT_EQ(2, controller.GetEntryCount()); | 340 EXPECT_EQ(2, controller.GetEntryCount()); |
342 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 341 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
343 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 342 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
344 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); | 343 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); |
345 } | 344 } |
346 | 345 |
347 // Tests that the |should_replace_current_entry| flag persists correctly across | 346 // Tests that the |should_replace_current_entry| flag persists correctly across |
348 // request transfers that cross processes twice from renderer policy. | 347 // request transfers that cross processes twice from renderer policy. |
349 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, | 348 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, |
350 MAYBE_ReplaceEntryCrossProcessTwice) { | 349 MAYBE_ReplaceEntryCrossProcessTwice) { |
351 const NavigationController& controller = | 350 const NavigationController& controller = |
352 shell()->web_contents()->GetController(); | 351 shell()->web_contents()->GetController(); |
353 | 352 |
354 // Navigate to a starting URL, so there is a history entry to replace. | 353 // Navigate to a starting URL, so there is a history entry to replace. |
355 GURL url1 = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); | 354 GURL url1 = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); |
356 NavigateToURL(shell(), url1); | 355 EXPECT_TRUE(NavigateToURL(shell(), url1)); |
357 | 356 |
358 // Navigate to a page on A.com which redirects to B.com with entry | 357 // Navigate to a page on A.com which redirects to B.com with entry |
359 // replacement. This will switch processes via OpenURL twice. First to A.com, | 358 // replacement. This will switch processes via OpenURL twice. First to A.com, |
360 // and second in response to the server redirect to B.com. The second swap is | 359 // and second in response to the server redirect to B.com. The second swap is |
361 // also renderer-initiated via OpenURL because decidePolicyForNavigation is | 360 // also renderer-initiated via OpenURL because decidePolicyForNavigation is |
362 // currently applied on redirects. | 361 // currently applied on redirects. |
363 GURL::Replacements replace_host; | 362 GURL::Replacements replace_host; |
364 GURL url2b = | 363 GURL url2b = |
365 embedded_test_server()->GetURL("B.com", "/site_isolation/blank.html?2"); | 364 embedded_test_server()->GetURL("B.com", "/site_isolation/blank.html?2"); |
366 GURL url2a = embedded_test_server()->GetURL( | 365 GURL url2a = embedded_test_server()->GetURL( |
367 "A.com", "/cross-site/" + url2b.host() + url2b.PathForRequest()); | 366 "A.com", "/cross-site/" + url2b.host() + url2b.PathForRequest()); |
368 NavigateToURLContentInitiated(shell(), url2a, true, true); | 367 NavigateToURLContentInitiated(shell(), url2a, true, true); |
369 | 368 |
370 // There should be one history entry. url2b should have replaced url1. | 369 // There should be one history entry. url2b should have replaced url1. |
371 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 370 EXPECT_TRUE(controller.GetPendingEntry() == nullptr); |
372 EXPECT_EQ(1, controller.GetEntryCount()); | 371 EXPECT_EQ(1, controller.GetEntryCount()); |
373 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 372 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
374 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); | 373 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); |
375 | 374 |
376 // Now repeat without replacement. | 375 // Now repeat without replacement. |
377 GURL url3b = | 376 GURL url3b = |
378 embedded_test_server()->GetURL("B.com", "/site_isolation/blank.html?3"); | 377 embedded_test_server()->GetURL("B.com", "/site_isolation/blank.html?3"); |
379 GURL url3a = embedded_test_server()->GetURL( | 378 GURL url3a = embedded_test_server()->GetURL( |
380 "A.com", "/cross-site/" + url3b.host() + url3b.PathForRequest()); | 379 "A.com", "/cross-site/" + url3b.host() + url3b.PathForRequest()); |
381 NavigateToURLContentInitiated(shell(), url3a, false, true); | 380 NavigateToURLContentInitiated(shell(), url3a, false, true); |
382 | 381 |
383 // There should be two history entries. url2b should have replaced url1. url2b | 382 // There should be two history entries. url2b should have replaced url1. url2b |
384 // should not have replaced url3b. | 383 // should not have replaced url3b. |
385 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 384 EXPECT_TRUE(controller.GetPendingEntry() == nullptr); |
386 EXPECT_EQ(2, controller.GetEntryCount()); | 385 EXPECT_EQ(2, controller.GetEntryCount()); |
387 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 386 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
388 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); | 387 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); |
389 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); | 388 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); |
390 } | 389 } |
391 | 390 |
392 // Tests that the request is destroyed when a cross process navigation is | 391 // Tests that the request is destroyed when a cross process navigation is |
393 // cancelled. | 392 // cancelled. |
394 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, NoLeakOnCrossSiteCancel) { | 393 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, NoLeakOnCrossSiteCancel) { |
395 const NavigationController& controller = | 394 const NavigationController& controller = |
396 shell()->web_contents()->GetController(); | 395 shell()->web_contents()->GetController(); |
397 | 396 |
398 // Navigate to a starting URL, so there is a history entry to replace. | 397 // Navigate to a starting URL, so there is a history entry to replace. |
399 GURL url1 = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); | 398 GURL url1 = embedded_test_server()->GetURL("/site_isolation/blank.html?1"); |
400 NavigateToURL(shell(), url1); | 399 EXPECT_TRUE(NavigateToURL(shell(), url1)); |
401 | 400 |
402 // Force all future navigations to transfer. | 401 // Force all future navigations to transfer. |
403 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); | 402 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); |
404 | 403 |
405 NoTransferRequestDelegate no_transfer_request_delegate; | 404 NoTransferRequestDelegate no_transfer_request_delegate; |
406 WebContentsDelegate* old_delegate = shell()->web_contents()->GetDelegate(); | 405 WebContentsDelegate* old_delegate = shell()->web_contents()->GetDelegate(); |
407 shell()->web_contents()->SetDelegate(&no_transfer_request_delegate); | 406 shell()->web_contents()->SetDelegate(&no_transfer_request_delegate); |
408 | 407 |
409 // Navigate to a page on A.com with entry replacement. This navigation is | 408 // Navigate to a page on A.com with entry replacement. This navigation is |
410 // cross-site, so the renderer will send it to the browser via OpenURL to give | 409 // cross-site, so the renderer will send it to the browser via OpenURL to give |
(...skipping 14 matching lines...) Expand all Loading... |
425 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 424 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
426 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); | 425 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); |
427 | 426 |
428 // Make sure the request for url2 did not complete. | 427 // Make sure the request for url2 did not complete. |
429 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); | 428 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); |
430 | 429 |
431 shell()->web_contents()->SetDelegate(old_delegate); | 430 shell()->web_contents()->SetDelegate(old_delegate); |
432 } | 431 } |
433 | 432 |
434 } // namespace content | 433 } // namespace content |
OLD | NEW |