| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 10 #include "components/navigation_interception/intercept_navigation_resource_throt
tle.h" | 11 #include "components/navigation_interception/intercept_navigation_resource_throt
tle.h" |
| 11 #include "components/navigation_interception/navigation_params.h" | 12 #include "components/navigation_interception/navigation_params.h" |
| 12 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 13 #include "content/public/browser/resource_context.h" | 14 #include "content/public/browser/resource_context.h" |
| 14 #include "content/public/browser/resource_controller.h" | 15 #include "content/public/browser/resource_controller.h" |
| 15 #include "content/public/browser/resource_dispatcher_host.h" | 16 #include "content/public/browser/resource_dispatcher_host.h" |
| 16 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 17 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 17 #include "content/public/browser/resource_request_info.h" | 18 #include "content/public/browser/resource_request_info.h" |
| 18 #include "content/public/browser/resource_throttle.h" | 19 #include "content/public/browser/resource_throttle.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_delegate.h" | 21 #include "content/public/browser/web_contents_delegate.h" |
| 21 #include "content/public/common/page_transition_types.h" | 22 #include "content/public/common/page_transition_types.h" |
| 22 #include "content/public/test/mock_resource_context.h" | 23 #include "content/public/test/mock_resource_context.h" |
| 23 #include "content/public/test/test_browser_thread.h" | |
| 24 #include "content/public/test/test_renderer_host.h" | 24 #include "content/public/test/test_renderer_host.h" |
| 25 #include "net/url_request/url_request.h" | 25 #include "net/url_request/url_request.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 using testing::_; | 29 using testing::_; |
| 30 using testing::Eq; | 30 using testing::Eq; |
| 31 using testing::Property; | 31 using testing::Property; |
| 32 using testing::Ne; | 32 using testing::Ne; |
| 33 using testing::Return; | 33 using testing::Return; |
| 34 | 34 |
| 35 namespace navigation_interception { | 35 namespace navigation_interception { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const char kTestUrl[] = "http://www.test.com/"; | 39 const char kTestUrl[] = "http://www.test.com/"; |
| 40 const char kUnsafeTestUrl[] = "about:crash"; | 40 const char kUnsafeTestUrl[] = "about:crash"; |
| 41 | 41 |
| 42 void ContinueTestCase() { | |
| 43 content::BrowserThread::PostTask( | |
| 44 content::BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); | |
| 45 } | |
| 46 | |
| 47 // The MS C++ compiler complains about not being able to resolve which url() | 42 // The MS C++ compiler complains about not being able to resolve which url() |
| 48 // method (const or non-const) to use if we use the Property matcher to check | 43 // method (const or non-const) to use if we use the Property matcher to check |
| 49 // the return value of the NavigationParams::url() method. | 44 // the return value of the NavigationParams::url() method. |
| 50 // It is possible to suppress the error by specifying the types directly but | 45 // It is possible to suppress the error by specifying the types directly but |
| 51 // that results in very ugly syntax, which is why these custom matchers are | 46 // that results in very ugly syntax, which is why these custom matchers are |
| 52 // used instead. | 47 // used instead. |
| 53 MATCHER(NavigationParamsUrlIsTest, "") { | 48 MATCHER(NavigationParamsUrlIsTest, "") { |
| 54 return arg.url() == GURL(kTestUrl); | 49 return arg.url() == GURL(kTestUrl); |
| 55 } | 50 } |
| 56 | 51 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 } | 79 } |
| 85 | 80 |
| 86 Status status() const { return status_; } | 81 Status status() const { return status_; } |
| 87 | 82 |
| 88 // ResourceController: | 83 // ResourceController: |
| 89 virtual void Cancel() OVERRIDE { | 84 virtual void Cancel() OVERRIDE { |
| 90 NOTREACHED(); | 85 NOTREACHED(); |
| 91 } | 86 } |
| 92 virtual void CancelAndIgnore() OVERRIDE { | 87 virtual void CancelAndIgnore() OVERRIDE { |
| 93 status_ = CANCELLED; | 88 status_ = CANCELLED; |
| 94 ContinueTestCase(); | |
| 95 } | 89 } |
| 96 virtual void CancelWithError(int error_code) OVERRIDE { | 90 virtual void CancelWithError(int error_code) OVERRIDE { |
| 97 NOTREACHED(); | 91 NOTREACHED(); |
| 98 } | 92 } |
| 99 virtual void Resume() OVERRIDE { | 93 virtual void Resume() OVERRIDE { |
| 100 DCHECK(status_ == UNKNOWN); | 94 DCHECK(status_ == UNKNOWN); |
| 101 status_ = RESUMED; | 95 status_ = RESUMED; |
| 102 ContinueTestCase(); | |
| 103 } | 96 } |
| 104 | 97 |
| 105 private: | 98 private: |
| 106 Status status_; | 99 Status status_; |
| 107 }; | 100 }; |
| 108 | 101 |
| 109 // TestIOThreadState ---------------------------------------------------------- | 102 // TestIOThreadState ---------------------------------------------------------- |
| 110 | 103 |
| 111 class TestIOThreadState { | 104 class TestIOThreadState { |
| 112 public: | 105 public: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 MockResourceController throttle_controller_; | 148 MockResourceController throttle_controller_; |
| 156 }; | 149 }; |
| 157 | 150 |
| 158 // InterceptNavigationResourceThrottleTest ------------------------------------ | 151 // InterceptNavigationResourceThrottleTest ------------------------------------ |
| 159 | 152 |
| 160 class InterceptNavigationResourceThrottleTest | 153 class InterceptNavigationResourceThrottleTest |
| 161 : public content::RenderViewHostTestHarness { | 154 : public content::RenderViewHostTestHarness { |
| 162 public: | 155 public: |
| 163 InterceptNavigationResourceThrottleTest() | 156 InterceptNavigationResourceThrottleTest() |
| 164 : mock_callback_receiver_(new MockInterceptCallbackReceiver()), | 157 : mock_callback_receiver_(new MockInterceptCallbackReceiver()), |
| 165 ui_thread_(content::BrowserThread::UI, &message_loop_), | |
| 166 io_thread_(content::BrowserThread::IO), | |
| 167 io_thread_state_(NULL) { | 158 io_thread_state_(NULL) { |
| 168 } | 159 } |
| 169 | 160 |
| 170 virtual void SetUp() OVERRIDE { | 161 virtual void SetUp() OVERRIDE { |
| 171 RenderViewHostTestHarness::SetUp(); | 162 RenderViewHostTestHarness::SetUp(); |
| 172 | |
| 173 io_thread_.StartIOThread(); | |
| 174 } | 163 } |
| 175 | 164 |
| 176 virtual void TearDown() OVERRIDE { | 165 virtual void TearDown() OVERRIDE { |
| 177 if (web_contents()) | 166 if (web_contents()) |
| 178 web_contents()->SetDelegate(NULL); | 167 web_contents()->SetDelegate(NULL); |
| 179 | 168 |
| 180 content::BrowserThread::PostTask( | 169 content::BrowserThread::PostTask( |
| 181 content::BrowserThread::IO, | 170 content::BrowserThread::IO, |
| 182 FROM_HERE, | 171 FROM_HERE, |
| 183 base::Bind(&base::DeletePointer<TestIOThreadState>, io_thread_state_)); | 172 base::Bind(&base::DeletePointer<TestIOThreadState>, io_thread_state_)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 195 int render_process_id, | 184 int render_process_id, |
| 196 int render_view_id, | 185 int render_view_id, |
| 197 bool* defer) { | 186 bool* defer) { |
| 198 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 187 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 199 TestIOThreadState* io_thread_state = | 188 TestIOThreadState* io_thread_state = |
| 200 new TestIOThreadState(url, render_process_id, render_view_id, | 189 new TestIOThreadState(url, render_process_id, render_view_id, |
| 201 request_method, mock_callback_receiver_.get()); | 190 request_method, mock_callback_receiver_.get()); |
| 202 | 191 |
| 203 SetIOThreadState(io_thread_state); | 192 SetIOThreadState(io_thread_state); |
| 204 io_thread_state->ThrottleWillStartRequest(defer); | 193 io_thread_state->ThrottleWillStartRequest(defer); |
| 205 | |
| 206 if (!*defer) { | |
| 207 ContinueTestCase(); | |
| 208 } | |
| 209 } | 194 } |
| 210 | 195 |
| 211 protected: | 196 protected: |
| 212 enum ShouldIgnoreNavigationCallbackAction { | 197 enum ShouldIgnoreNavigationCallbackAction { |
| 213 IgnoreNavigation, | 198 IgnoreNavigation, |
| 214 DontIgnoreNavigation | 199 DontIgnoreNavigation |
| 215 }; | 200 }; |
| 216 | 201 |
| 217 void SetUpWebContentsDelegateAndRunMessageLoop( | 202 void SetUpWebContentsDelegateAndDrainRunLoop( |
| 218 ShouldIgnoreNavigationCallbackAction callback_action, | 203 ShouldIgnoreNavigationCallbackAction callback_action, |
| 219 bool* defer) { | 204 bool* defer) { |
| 220 | 205 |
| 221 ON_CALL(*mock_callback_receiver_, ShouldIgnoreNavigation(_, _)) | 206 ON_CALL(*mock_callback_receiver_, ShouldIgnoreNavigation(_, _)) |
| 222 .WillByDefault(Return(callback_action == IgnoreNavigation)); | 207 .WillByDefault(Return(callback_action == IgnoreNavigation)); |
| 223 EXPECT_CALL(*mock_callback_receiver_, | 208 EXPECT_CALL(*mock_callback_receiver_, |
| 224 ShouldIgnoreNavigation(rvh(), NavigationParamsUrlIsTest())) | 209 ShouldIgnoreNavigation(rvh(), NavigationParamsUrlIsTest())) |
| 225 .Times(1); | 210 .Times(1); |
| 226 | 211 |
| 227 content::BrowserThread::PostTask( | 212 content::BrowserThread::PostTask( |
| 228 content::BrowserThread::IO, | 213 content::BrowserThread::IO, |
| 229 FROM_HERE, | 214 FROM_HERE, |
| 230 base::Bind( | 215 base::Bind( |
| 231 &InterceptNavigationResourceThrottleTest:: | 216 &InterceptNavigationResourceThrottleTest:: |
| 232 RunThrottleWillStartRequestOnIOThread, | 217 RunThrottleWillStartRequestOnIOThread, |
| 233 base::Unretained(this), | 218 base::Unretained(this), |
| 234 GURL(kTestUrl), | 219 GURL(kTestUrl), |
| 235 "GET", | 220 "GET", |
| 236 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | 221 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 237 web_contents()->GetRenderViewHost()->GetRoutingID(), | 222 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 238 base::Unretained(defer))); | 223 base::Unretained(defer))); |
| 239 | 224 |
| 240 // Wait for the request to finish processing. | 225 // Wait for the request to finish processing. |
| 241 message_loop_.Run(); | 226 base::RunLoop().RunUntilIdle(); |
| 242 } | 227 } |
| 243 | 228 |
| 244 void WaitForPreviouslyScheduledIoThreadWork() { | 229 void WaitForPreviouslyScheduledIoThreadWork() { |
| 245 base::WaitableEvent io_thread_work_done(true, false); | 230 base::WaitableEvent io_thread_work_done(true, false); |
| 246 content::BrowserThread::PostTask( | 231 content::BrowserThread::PostTask( |
| 247 content::BrowserThread::IO, | 232 content::BrowserThread::IO, |
| 248 FROM_HERE, | 233 FROM_HERE, |
| 249 base::Bind( | 234 base::Bind( |
| 250 &base::WaitableEvent::Signal, | 235 &base::WaitableEvent::Signal, |
| 251 base::Unretained(&io_thread_work_done))); | 236 base::Unretained(&io_thread_work_done))); |
| 252 io_thread_work_done.Wait(); | 237 io_thread_work_done.Wait(); |
| 253 } | 238 } |
| 254 | 239 |
| 255 scoped_ptr<MockInterceptCallbackReceiver> mock_callback_receiver_; | 240 scoped_ptr<MockInterceptCallbackReceiver> mock_callback_receiver_; |
| 256 content::TestBrowserThread ui_thread_; | |
| 257 content::TestBrowserThread io_thread_; | |
| 258 TestIOThreadState* io_thread_state_; | 241 TestIOThreadState* io_thread_state_; |
| 259 }; | 242 }; |
| 260 | 243 |
| 261 TEST_F(InterceptNavigationResourceThrottleTest, | 244 TEST_F(InterceptNavigationResourceThrottleTest, |
| 262 RequestDeferredAndResumedIfNavigationNotIgnored) { | 245 RequestDeferredAndResumedIfNavigationNotIgnored) { |
| 263 bool defer = false; | 246 bool defer = false; |
| 264 SetUpWebContentsDelegateAndRunMessageLoop(DontIgnoreNavigation, &defer); | 247 SetUpWebContentsDelegateAndDrainRunLoop(DontIgnoreNavigation, &defer); |
| 265 | 248 |
| 266 EXPECT_TRUE(defer); | 249 EXPECT_TRUE(defer); |
| 267 EXPECT_TRUE(io_thread_state_); | 250 EXPECT_TRUE(io_thread_state_); |
| 268 EXPECT_TRUE(io_thread_state_->request_resumed()); | 251 EXPECT_TRUE(io_thread_state_->request_resumed()); |
| 269 } | 252 } |
| 270 | 253 |
| 271 TEST_F(InterceptNavigationResourceThrottleTest, | 254 TEST_F(InterceptNavigationResourceThrottleTest, |
| 272 RequestDeferredAndCancelledIfNavigationIgnored) { | 255 RequestDeferredAndCancelledIfNavigationIgnored) { |
| 273 bool defer = false; | 256 bool defer = false; |
| 274 SetUpWebContentsDelegateAndRunMessageLoop(IgnoreNavigation, &defer); | 257 SetUpWebContentsDelegateAndDrainRunLoop(IgnoreNavigation, &defer); |
| 275 | 258 |
| 276 EXPECT_TRUE(defer); | 259 EXPECT_TRUE(defer); |
| 277 EXPECT_TRUE(io_thread_state_); | 260 EXPECT_TRUE(io_thread_state_); |
| 278 EXPECT_TRUE(io_thread_state_->request_cancelled()); | 261 EXPECT_TRUE(io_thread_state_->request_cancelled()); |
| 279 } | 262 } |
| 280 | 263 |
| 281 TEST_F(InterceptNavigationResourceThrottleTest, | 264 TEST_F(InterceptNavigationResourceThrottleTest, |
| 282 NoCallbackMadeIfContentsDeletedWhileThrottleRunning) { | 265 NoCallbackMadeIfContentsDeletedWhileThrottleRunning) { |
| 283 bool defer = false; | 266 bool defer = false; |
| 284 | 267 |
| 285 // The tested scenario is when the WebContents is deleted after the | 268 // The tested scenario is when the WebContents is deleted after the |
| 286 // ResourceThrottle has finished processing on the IO thread but before the | 269 // ResourceThrottle has finished processing on the IO thread but before the |
| 287 // UI thread callback has been processed. | 270 // UI thread callback has been processed. Since both threads in this test |
| 288 content::BrowserThread::PostTask( | 271 // are serviced by one message loop, the post order is the execution order. |
| 289 content::BrowserThread::UI, | |
| 290 FROM_HERE, | |
| 291 base::Bind( | |
| 292 &RenderViewHostTestHarness::DeleteContents, | |
| 293 base::Unretained(this))); | |
| 294 | |
| 295 EXPECT_CALL(*mock_callback_receiver_, | 272 EXPECT_CALL(*mock_callback_receiver_, |
| 296 ShouldIgnoreNavigation(_, _)) | 273 ShouldIgnoreNavigation(_, _)) |
| 297 .Times(0); | 274 .Times(0); |
| 298 | 275 |
| 299 content::BrowserThread::PostTask( | 276 content::BrowserThread::PostTask( |
| 300 content::BrowserThread::IO, | 277 content::BrowserThread::IO, |
| 301 FROM_HERE, | 278 FROM_HERE, |
| 302 base::Bind( | 279 base::Bind( |
| 303 &InterceptNavigationResourceThrottleTest:: | 280 &InterceptNavigationResourceThrottleTest:: |
| 304 RunThrottleWillStartRequestOnIOThread, | 281 RunThrottleWillStartRequestOnIOThread, |
| 305 base::Unretained(this), | 282 base::Unretained(this), |
| 306 GURL(kTestUrl), | 283 GURL(kTestUrl), |
| 307 "GET", | 284 "GET", |
| 308 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | 285 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 309 web_contents()->GetRenderViewHost()->GetRoutingID(), | 286 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 310 base::Unretained(&defer))); | 287 base::Unretained(&defer))); |
| 311 | 288 |
| 312 WaitForPreviouslyScheduledIoThreadWork(); | 289 content::BrowserThread::PostTask( |
| 290 content::BrowserThread::UI, |
| 291 FROM_HERE, |
| 292 base::Bind( |
| 293 &RenderViewHostTestHarness::DeleteContents, |
| 294 base::Unretained(this))); |
| 313 | 295 |
| 314 // The WebContents will now be deleted and only after that will the UI-thread | 296 // The WebContents will now be deleted and only after that will the UI-thread |
| 315 // callback posted by the ResourceThrottle be executed. | 297 // callback posted by the ResourceThrottle be executed. |
| 316 message_loop_.Run(); | 298 base::RunLoop().RunUntilIdle(); |
| 317 | 299 |
| 318 EXPECT_TRUE(defer); | 300 EXPECT_TRUE(defer); |
| 319 EXPECT_TRUE(io_thread_state_); | 301 EXPECT_TRUE(io_thread_state_); |
| 320 EXPECT_TRUE(io_thread_state_->request_resumed()); | 302 EXPECT_TRUE(io_thread_state_->request_resumed()); |
| 321 } | 303 } |
| 322 | 304 |
| 323 TEST_F(InterceptNavigationResourceThrottleTest, | 305 TEST_F(InterceptNavigationResourceThrottleTest, |
| 324 RequestNotDeferredForRequestNotAssociatedWithARenderView) { | 306 RequestNotDeferredForRequestNotAssociatedWithARenderView) { |
| 325 bool defer = false; | 307 bool defer = false; |
| 326 | 308 |
| 327 content::BrowserThread::PostTask( | 309 content::BrowserThread::PostTask( |
| 328 content::BrowserThread::IO, | 310 content::BrowserThread::IO, |
| 329 FROM_HERE, | 311 FROM_HERE, |
| 330 base::Bind( | 312 base::Bind( |
| 331 &InterceptNavigationResourceThrottleTest:: | 313 &InterceptNavigationResourceThrottleTest:: |
| 332 RunThrottleWillStartRequestOnIOThread, | 314 RunThrottleWillStartRequestOnIOThread, |
| 333 base::Unretained(this), | 315 base::Unretained(this), |
| 334 GURL(kTestUrl), | 316 GURL(kTestUrl), |
| 335 "GET", | 317 "GET", |
| 336 MSG_ROUTING_NONE, | 318 MSG_ROUTING_NONE, |
| 337 MSG_ROUTING_NONE, | 319 MSG_ROUTING_NONE, |
| 338 base::Unretained(&defer))); | 320 base::Unretained(&defer))); |
| 339 | 321 |
| 340 // Wait for the request to finish processing. | 322 // Wait for the request to finish processing. |
| 341 message_loop_.Run(); | 323 base::RunLoop().RunUntilIdle(); |
| 342 | 324 |
| 343 EXPECT_FALSE(defer); | 325 EXPECT_FALSE(defer); |
| 344 } | 326 } |
| 345 | 327 |
| 346 TEST_F(InterceptNavigationResourceThrottleTest, | 328 TEST_F(InterceptNavigationResourceThrottleTest, |
| 347 CallbackCalledWithFilteredUrl) { | 329 CallbackCalledWithFilteredUrl) { |
| 348 bool defer = false; | 330 bool defer = false; |
| 349 | 331 |
| 350 ON_CALL(*mock_callback_receiver_, | 332 ON_CALL(*mock_callback_receiver_, |
| 351 ShouldIgnoreNavigation(_, NavigationParamsUrlIsSafe())) | 333 ShouldIgnoreNavigation(_, NavigationParamsUrlIsSafe())) |
| 352 .WillByDefault(Return(false)); | 334 .WillByDefault(Return(false)); |
| 353 EXPECT_CALL(*mock_callback_receiver_, | 335 EXPECT_CALL(*mock_callback_receiver_, |
| 354 ShouldIgnoreNavigation(_, NavigationParamsUrlIsSafe())) | 336 ShouldIgnoreNavigation(_, NavigationParamsUrlIsSafe())) |
| 355 .Times(1); | 337 .Times(1); |
| 356 | 338 |
| 357 content::BrowserThread::PostTask( | 339 content::BrowserThread::PostTask( |
| 358 content::BrowserThread::IO, | 340 content::BrowserThread::IO, |
| 359 FROM_HERE, | 341 FROM_HERE, |
| 360 base::Bind( | 342 base::Bind( |
| 361 &InterceptNavigationResourceThrottleTest:: | 343 &InterceptNavigationResourceThrottleTest:: |
| 362 RunThrottleWillStartRequestOnIOThread, | 344 RunThrottleWillStartRequestOnIOThread, |
| 363 base::Unretained(this), | 345 base::Unretained(this), |
| 364 GURL(kUnsafeTestUrl), | 346 GURL(kUnsafeTestUrl), |
| 365 "GET", | 347 "GET", |
| 366 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | 348 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 367 web_contents()->GetRenderViewHost()->GetRoutingID(), | 349 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 368 base::Unretained(&defer))); | 350 base::Unretained(&defer))); |
| 369 | 351 |
| 370 // Wait for the request to finish processing. | 352 // Wait for the request to finish processing. |
| 371 message_loop_.Run(); | 353 base::RunLoop().RunUntilIdle(); |
| 372 } | 354 } |
| 373 | 355 |
| 374 TEST_F(InterceptNavigationResourceThrottleTest, | 356 TEST_F(InterceptNavigationResourceThrottleTest, |
| 375 CallbackIsPostFalseForGet) { | 357 CallbackIsPostFalseForGet) { |
| 376 bool defer = false; | 358 bool defer = false; |
| 377 | 359 |
| 378 EXPECT_CALL(*mock_callback_receiver_, | 360 EXPECT_CALL(*mock_callback_receiver_, |
| 379 ShouldIgnoreNavigation(_, AllOf( | 361 ShouldIgnoreNavigation(_, AllOf( |
| 380 NavigationParamsUrlIsSafe(), | 362 NavigationParamsUrlIsSafe(), |
| 381 Property(&NavigationParams::is_post, Eq(false))))) | 363 Property(&NavigationParams::is_post, Eq(false))))) |
| 382 .WillOnce(Return(false)); | 364 .WillOnce(Return(false)); |
| 383 | 365 |
| 384 content::BrowserThread::PostTask( | 366 content::BrowserThread::PostTask( |
| 385 content::BrowserThread::IO, | 367 content::BrowserThread::IO, |
| 386 FROM_HERE, | 368 FROM_HERE, |
| 387 base::Bind( | 369 base::Bind( |
| 388 &InterceptNavigationResourceThrottleTest:: | 370 &InterceptNavigationResourceThrottleTest:: |
| 389 RunThrottleWillStartRequestOnIOThread, | 371 RunThrottleWillStartRequestOnIOThread, |
| 390 base::Unretained(this), | 372 base::Unretained(this), |
| 391 GURL(kTestUrl), | 373 GURL(kTestUrl), |
| 392 "GET", | 374 "GET", |
| 393 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | 375 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 394 web_contents()->GetRenderViewHost()->GetRoutingID(), | 376 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 395 base::Unretained(&defer))); | 377 base::Unretained(&defer))); |
| 396 | 378 |
| 397 // Wait for the request to finish processing. | 379 // Wait for the request to finish processing. |
| 398 message_loop_.Run(); | 380 base::RunLoop().RunUntilIdle(); |
| 399 } | 381 } |
| 400 | 382 |
| 401 TEST_F(InterceptNavigationResourceThrottleTest, | 383 TEST_F(InterceptNavigationResourceThrottleTest, |
| 402 CallbackIsPostTrueForPost) { | 384 CallbackIsPostTrueForPost) { |
| 403 bool defer = false; | 385 bool defer = false; |
| 404 | 386 |
| 405 EXPECT_CALL(*mock_callback_receiver_, | 387 EXPECT_CALL(*mock_callback_receiver_, |
| 406 ShouldIgnoreNavigation(_, AllOf( | 388 ShouldIgnoreNavigation(_, AllOf( |
| 407 NavigationParamsUrlIsSafe(), | 389 NavigationParamsUrlIsSafe(), |
| 408 Property(&NavigationParams::is_post, Eq(true))))) | 390 Property(&NavigationParams::is_post, Eq(true))))) |
| 409 .WillOnce(Return(false)); | 391 .WillOnce(Return(false)); |
| 410 | 392 |
| 411 content::BrowserThread::PostTask( | 393 content::BrowserThread::PostTask( |
| 412 content::BrowserThread::IO, | 394 content::BrowserThread::IO, |
| 413 FROM_HERE, | 395 FROM_HERE, |
| 414 base::Bind( | 396 base::Bind( |
| 415 &InterceptNavigationResourceThrottleTest:: | 397 &InterceptNavigationResourceThrottleTest:: |
| 416 RunThrottleWillStartRequestOnIOThread, | 398 RunThrottleWillStartRequestOnIOThread, |
| 417 base::Unretained(this), | 399 base::Unretained(this), |
| 418 GURL(kTestUrl), | 400 GURL(kTestUrl), |
| 419 "POST", | 401 "POST", |
| 420 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | 402 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 421 web_contents()->GetRenderViewHost()->GetRoutingID(), | 403 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 422 base::Unretained(&defer))); | 404 base::Unretained(&defer))); |
| 423 | 405 |
| 424 // Wait for the request to finish processing. | 406 // Wait for the request to finish processing. |
| 425 message_loop_.Run(); | 407 base::RunLoop().RunUntilIdle(); |
| 426 } | 408 } |
| 427 | 409 |
| 428 } // namespace navigation_interception | 410 } // namespace navigation_interception |
| OLD | NEW |