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

Side by Side Diff: components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc

Issue 11830043: Move content/components/navigation_interception to src/components (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "content/components/navigation_interception/intercept_navigation_resour ce_throttle.h" 10 #include "components/navigation_interception/intercept_navigation_resource_throt tle.h"
11 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/resource_context.h" 12 #include "content/public/browser/resource_context.h"
13 #include "content/public/browser/resource_controller.h" 13 #include "content/public/browser/resource_controller.h"
14 #include "content/public/browser/resource_dispatcher_host.h" 14 #include "content/public/browser/resource_dispatcher_host.h"
15 #include "content/public/browser/resource_dispatcher_host_delegate.h" 15 #include "content/public/browser/resource_dispatcher_host_delegate.h"
16 #include "content/public/browser/resource_request_info.h" 16 #include "content/public/browser/resource_request_info.h"
17 #include "content/public/browser/resource_throttle.h" 17 #include "content/public/browser/resource_throttle.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_delegate.h" 19 #include "content/public/browser/web_contents_delegate.h"
20 #include "content/public/common/page_transition_types.h" 20 #include "content/public/common/page_transition_types.h"
21 #include "content/public/test/mock_resource_context.h" 21 #include "content/public/test/mock_resource_context.h"
22 #include "content/public/test/test_browser_thread.h" 22 #include "content/public/test/test_browser_thread.h"
23 #include "content/public/test/test_renderer_host.h" 23 #include "content/public/test/test_renderer_host.h"
24 #include "net/url_request/url_request.h" 24 #include "net/url_request/url_request.h"
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 using testing::_; 28 using testing::_;
29 using testing::Eq; 29 using testing::Eq;
30 using testing::Ne; 30 using testing::Ne;
31 using testing::Return; 31 using testing::Return;
32 32
33 namespace content { 33 namespace components {
34 34
35 namespace { 35 namespace {
36 36
37 const char kTestUrl[] = "http://www.test.com/"; 37 const char kTestUrl[] = "http://www.test.com/";
38 const char kUnsafeTestUrl[] = "about:crash"; 38 const char kUnsafeTestUrl[] = "about:crash";
39 39
40 void ContinueTestCase() { 40 void ContinueTestCase() {
41 BrowserThread::PostTask( 41 content::BrowserThread::PostTask(
42 BrowserThread::UI, 42 content::BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure());
43 FROM_HERE,
44 MessageLoop::QuitClosure());
45 } 43 }
46 44
47 } // namespace 45 } // namespace
48 46
49 // MockInterceptCallbackReceiver ---------------------------------------------- 47 // MockInterceptCallbackReceiver ----------------------------------------------
50 48
51 class MockInterceptCallbackReceiver { 49 class MockInterceptCallbackReceiver {
52 public: 50 public:
53 MOCK_METHOD6(ShouldIgnoreNavigation, bool(RenderViewHost* source, 51 MOCK_METHOD6(ShouldIgnoreNavigation,
54 const GURL& url, 52 bool(content::RenderViewHost* source,
55 const Referrer& referrer, 53 const GURL& url,
56 bool is_post, 54 const content::Referrer& referrer,
57 bool has_user_gesture, 55 bool is_post,
58 PageTransition page_transition)); 56 bool has_user_gesture,
57 content::PageTransition page_transition));
59 }; 58 };
60 59
61 // MockResourceController ----------------------------------------------------- 60 // MockResourceController -----------------------------------------------------
62 class MockResourceController : public ResourceController { 61 class MockResourceController : public content::ResourceController {
63 public: 62 public:
64 enum Status { 63 enum Status {
65 UNKNOWN, 64 UNKNOWN,
66 RESUMED, 65 RESUMED,
67 CANCELLED 66 CANCELLED
68 }; 67 };
69 68
70 MockResourceController() 69 MockResourceController()
71 : status_(UNKNOWN) { 70 : status_(UNKNOWN) {
72 } 71 }
(...skipping 23 matching lines...) Expand all
96 95
97 // TestIOThreadState ---------------------------------------------------------- 96 // TestIOThreadState ----------------------------------------------------------
98 97
99 class TestIOThreadState { 98 class TestIOThreadState {
100 public: 99 public:
101 TestIOThreadState(const GURL& url, int render_process_id, int render_view_id, 100 TestIOThreadState(const GURL& url, int render_process_id, int render_view_id,
102 const std::string& request_method, 101 const std::string& request_method,
103 MockInterceptCallbackReceiver* callback_receiver) 102 MockInterceptCallbackReceiver* callback_receiver)
104 : request_(url, NULL, resource_context_.GetRequestContext()), 103 : request_(url, NULL, resource_context_.GetRequestContext()),
105 throttle_(NULL) { 104 throttle_(NULL) {
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 105 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
107 if (render_process_id != MSG_ROUTING_NONE && 106 if (render_process_id != MSG_ROUTING_NONE &&
108 render_view_id != MSG_ROUTING_NONE) { 107 render_view_id != MSG_ROUTING_NONE) {
109 ResourceRequestInfo::AllocateForTesting(&request_, 108 content::ResourceRequestInfo::AllocateForTesting(
110 ResourceType::MAIN_FRAME, 109 &request_,
111 &resource_context_, 110 ResourceType::MAIN_FRAME,
112 render_process_id, 111 &resource_context_,
113 render_view_id); 112 render_process_id,
113 render_view_id);
114 } 114 }
115 throttle_.reset(new InterceptNavigationResourceThrottle( 115 throttle_.reset(new InterceptNavigationResourceThrottle(
116 &request_, 116 &request_,
117 base::Bind(&MockInterceptCallbackReceiver::ShouldIgnoreNavigation, 117 base::Bind(&MockInterceptCallbackReceiver::ShouldIgnoreNavigation,
118 base::Unretained(callback_receiver)))); 118 base::Unretained(callback_receiver))));
119 throttle_->set_controller_for_testing(&throttle_controller_); 119 throttle_->set_controller_for_testing(&throttle_controller_);
120 request_.set_method(request_method); 120 request_.set_method(request_method);
121 } 121 }
122 122
123 void ThrottleWillStartRequest(bool* defer) { 123 void ThrottleWillStartRequest(bool* defer) {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 124 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
125 throttle_->WillStartRequest(defer); 125 throttle_->WillStartRequest(defer);
126 } 126 }
127 127
128 bool request_resumed() const { 128 bool request_resumed() const {
129 return throttle_controller_.status() == 129 return throttle_controller_.status() ==
130 MockResourceController::RESUMED; 130 MockResourceController::RESUMED;
131 } 131 }
132 132
133 bool request_cancelled() const { 133 bool request_cancelled() const {
134 return throttle_controller_.status() == 134 return throttle_controller_.status() ==
135 MockResourceController::CANCELLED; 135 MockResourceController::CANCELLED;
136 } 136 }
137 137
138 private: 138 private:
139 MockResourceContext resource_context_; 139 content::MockResourceContext resource_context_;
140 net::URLRequest request_; 140 net::URLRequest request_;
141 scoped_ptr<InterceptNavigationResourceThrottle> throttle_; 141 scoped_ptr<InterceptNavigationResourceThrottle> throttle_;
142 MockResourceController throttle_controller_; 142 MockResourceController throttle_controller_;
143 }; 143 };
144 144
145 // InterceptNavigationResourceThrottleTest ------------------------------------ 145 // InterceptNavigationResourceThrottleTest ------------------------------------
146 146
147 class InterceptNavigationResourceThrottleTest 147 class InterceptNavigationResourceThrottleTest
148 : public RenderViewHostTestHarness { 148 : public content::RenderViewHostTestHarness {
149 public: 149 public:
150 InterceptNavigationResourceThrottleTest() 150 InterceptNavigationResourceThrottleTest()
151 : mock_callback_receiver_(new MockInterceptCallbackReceiver()), 151 : mock_callback_receiver_(new MockInterceptCallbackReceiver()),
152 ui_thread_(BrowserThread::UI, &message_loop_), 152 ui_thread_(content::BrowserThread::UI, &message_loop_),
153 io_thread_(BrowserThread::IO), 153 io_thread_(content::BrowserThread::IO),
154 io_thread_state_(NULL) { 154 io_thread_state_(NULL) {
155 } 155 }
156 156
157 virtual void SetUp() OVERRIDE { 157 virtual void SetUp() OVERRIDE {
158 RenderViewHostTestHarness::SetUp(); 158 RenderViewHostTestHarness::SetUp();
159 159
160 io_thread_.StartIOThread(); 160 io_thread_.StartIOThread();
161 } 161 }
162 162
163 virtual void TearDown() OVERRIDE { 163 virtual void TearDown() OVERRIDE {
164 if (web_contents()) 164 if (web_contents())
165 web_contents()->SetDelegate(NULL); 165 web_contents()->SetDelegate(NULL);
166 166
167 BrowserThread::PostTask( 167 content::BrowserThread::PostTask(
168 BrowserThread::IO, 168 content::BrowserThread::IO,
169 FROM_HERE, 169 FROM_HERE,
170 base::Bind(&base::DeletePointer<TestIOThreadState>, io_thread_state_)); 170 base::Bind(&base::DeletePointer<TestIOThreadState>, io_thread_state_));
171 171
172 RenderViewHostTestHarness::TearDown(); 172 RenderViewHostTestHarness::TearDown();
173 } 173 }
174 174
175 void SetIOThreadState(TestIOThreadState* io_thread_state) { 175 void SetIOThreadState(TestIOThreadState* io_thread_state) {
176 io_thread_state_ = io_thread_state; 176 io_thread_state_ = io_thread_state;
177 } 177 }
178 178
179 void RunThrottleWillStartRequestOnIOThread( 179 void RunThrottleWillStartRequestOnIOThread(
180 const GURL& url, 180 const GURL& url,
181 const std::string& request_method, 181 const std::string& request_method,
182 int render_process_id, 182 int render_process_id,
183 int render_view_id, 183 int render_view_id,
184 bool* defer) { 184 bool* defer) {
185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 185 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
186 TestIOThreadState* io_thread_state = 186 TestIOThreadState* io_thread_state =
187 new TestIOThreadState(url, render_process_id, render_view_id, 187 new TestIOThreadState(url, render_process_id, render_view_id,
188 request_method, mock_callback_receiver_.get()); 188 request_method, mock_callback_receiver_.get());
189 189
190 SetIOThreadState(io_thread_state); 190 SetIOThreadState(io_thread_state);
191 io_thread_state->ThrottleWillStartRequest(defer); 191 io_thread_state->ThrottleWillStartRequest(defer);
192 192
193 if (!*defer) { 193 if (!*defer) {
194 ContinueTestCase(); 194 ContinueTestCase();
195 } 195 }
196 } 196 }
197 197
198 protected: 198 protected:
199 enum ShouldIgnoreNavigationCallbackAction { 199 enum ShouldIgnoreNavigationCallbackAction {
200 IgnoreNavigation, 200 IgnoreNavigation,
201 DontIgnoreNavigation 201 DontIgnoreNavigation
202 }; 202 };
203 203
204 void SetUpWebContentsDelegateAndRunMessageLoop( 204 void SetUpWebContentsDelegateAndRunMessageLoop(
205 ShouldIgnoreNavigationCallbackAction callback_action, 205 ShouldIgnoreNavigationCallbackAction callback_action,
206 bool* defer) { 206 bool* defer) {
207 207
208 ON_CALL(*mock_callback_receiver_, 208 ON_CALL(*mock_callback_receiver_,
209 ShouldIgnoreNavigation(_, _, _, _, _, _)) 209 ShouldIgnoreNavigation(_, _, _, _, _, _))
210 .WillByDefault(Return(callback_action == IgnoreNavigation)); 210 .WillByDefault(Return(callback_action == IgnoreNavigation));
211 EXPECT_CALL(*mock_callback_receiver_, 211 EXPECT_CALL(*mock_callback_receiver_,
212 ShouldIgnoreNavigation(rvh(), Eq(GURL(kTestUrl)), _, _, _, _)) 212 ShouldIgnoreNavigation(rvh(), Eq(GURL(kTestUrl)), _, _, _, _))
213 .Times(1); 213 .Times(1);
214 214
215 BrowserThread::PostTask( 215 content::BrowserThread::PostTask(
216 BrowserThread::IO, 216 content::BrowserThread::IO,
217 FROM_HERE, 217 FROM_HERE,
218 base::Bind( 218 base::Bind(
219 &InterceptNavigationResourceThrottleTest:: 219 &InterceptNavigationResourceThrottleTest::
220 RunThrottleWillStartRequestOnIOThread, 220 RunThrottleWillStartRequestOnIOThread,
221 base::Unretained(this), 221 base::Unretained(this),
222 GURL(kTestUrl), 222 GURL(kTestUrl),
223 "GET", 223 "GET",
224 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), 224 web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
225 web_contents()->GetRenderViewHost()->GetRoutingID(), 225 web_contents()->GetRenderViewHost()->GetRoutingID(),
226 base::Unretained(defer))); 226 base::Unretained(defer)));
227 227
228 // Wait for the request to finish processing. 228 // Wait for the request to finish processing.
229 message_loop_.Run(); 229 message_loop_.Run();
230 } 230 }
231 231
232 void WaitForPreviouslyScheduledIoThreadWork() { 232 void WaitForPreviouslyScheduledIoThreadWork() {
233 base::WaitableEvent io_thread_work_done(true, false); 233 base::WaitableEvent io_thread_work_done(true, false);
234 BrowserThread::PostTask( 234 content::BrowserThread::PostTask(
235 BrowserThread::IO, 235 content::BrowserThread::IO,
236 FROM_HERE, 236 FROM_HERE,
237 base::Bind( 237 base::Bind(
238 &base::WaitableEvent::Signal, 238 &base::WaitableEvent::Signal,
239 base::Unretained(&io_thread_work_done))); 239 base::Unretained(&io_thread_work_done)));
240 io_thread_work_done.Wait(); 240 io_thread_work_done.Wait();
241 } 241 }
242 242
243 scoped_ptr<MockInterceptCallbackReceiver> mock_callback_receiver_; 243 scoped_ptr<MockInterceptCallbackReceiver> mock_callback_receiver_;
244 TestBrowserThread ui_thread_; 244 content::TestBrowserThread ui_thread_;
245 TestBrowserThread io_thread_; 245 content::TestBrowserThread io_thread_;
246 TestIOThreadState* io_thread_state_; 246 TestIOThreadState* io_thread_state_;
247 }; 247 };
248 248
249 TEST_F(InterceptNavigationResourceThrottleTest, 249 TEST_F(InterceptNavigationResourceThrottleTest,
250 RequestDeferredAndResumedIfNavigationNotIgnored) { 250 RequestDeferredAndResumedIfNavigationNotIgnored) {
251 bool defer = false; 251 bool defer = false;
252 SetUpWebContentsDelegateAndRunMessageLoop(DontIgnoreNavigation, &defer); 252 SetUpWebContentsDelegateAndRunMessageLoop(DontIgnoreNavigation, &defer);
253 253
254 EXPECT_TRUE(defer); 254 EXPECT_TRUE(defer);
255 EXPECT_TRUE(io_thread_state_); 255 EXPECT_TRUE(io_thread_state_);
(...skipping 10 matching lines...) Expand all
266 EXPECT_TRUE(io_thread_state_->request_cancelled()); 266 EXPECT_TRUE(io_thread_state_->request_cancelled());
267 } 267 }
268 268
269 TEST_F(InterceptNavigationResourceThrottleTest, 269 TEST_F(InterceptNavigationResourceThrottleTest,
270 NoCallbackMadeIfContentsDeletedWhileThrottleRunning) { 270 NoCallbackMadeIfContentsDeletedWhileThrottleRunning) {
271 bool defer = false; 271 bool defer = false;
272 272
273 // The tested scenario is when the WebContents is deleted after the 273 // The tested scenario is when the WebContents is deleted after the
274 // ResourceThrottle has finished processing on the IO thread but before the 274 // ResourceThrottle has finished processing on the IO thread but before the
275 // UI thread callback has been processed. 275 // UI thread callback has been processed.
276 BrowserThread::PostTask( 276 content::BrowserThread::PostTask(
277 BrowserThread::UI, 277 content::BrowserThread::UI,
278 FROM_HERE, 278 FROM_HERE,
279 base::Bind( 279 base::Bind(
280 &RenderViewHostTestHarness::DeleteContents, 280 &RenderViewHostTestHarness::DeleteContents,
281 base::Unretained(this))); 281 base::Unretained(this)));
282 282
283 EXPECT_CALL(*mock_callback_receiver_, 283 EXPECT_CALL(*mock_callback_receiver_,
284 ShouldIgnoreNavigation(_, _, _, _, _, _)) 284 ShouldIgnoreNavigation(_, _, _, _, _, _))
285 .Times(0); 285 .Times(0);
286 286
287 BrowserThread::PostTask( 287 content::BrowserThread::PostTask(
288 BrowserThread::IO, 288 content::BrowserThread::IO,
289 FROM_HERE, 289 FROM_HERE,
290 base::Bind( 290 base::Bind(
291 &InterceptNavigationResourceThrottleTest:: 291 &InterceptNavigationResourceThrottleTest::
292 RunThrottleWillStartRequestOnIOThread, 292 RunThrottleWillStartRequestOnIOThread,
293 base::Unretained(this), 293 base::Unretained(this),
294 GURL(kTestUrl), 294 GURL(kTestUrl),
295 "GET", 295 "GET",
296 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), 296 web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
297 web_contents()->GetRenderViewHost()->GetRoutingID(), 297 web_contents()->GetRenderViewHost()->GetRoutingID(),
298 base::Unretained(&defer))); 298 base::Unretained(&defer)));
299 299
300 WaitForPreviouslyScheduledIoThreadWork(); 300 WaitForPreviouslyScheduledIoThreadWork();
301 301
302 // The WebContents will now be deleted and only after that will the UI-thread 302 // The WebContents will now be deleted and only after that will the UI-thread
303 // callback posted by the ResourceThrottle be executed. 303 // callback posted by the ResourceThrottle be executed.
304 message_loop_.Run(); 304 message_loop_.Run();
305 305
306 EXPECT_TRUE(defer); 306 EXPECT_TRUE(defer);
307 EXPECT_TRUE(io_thread_state_); 307 EXPECT_TRUE(io_thread_state_);
308 EXPECT_TRUE(io_thread_state_->request_resumed()); 308 EXPECT_TRUE(io_thread_state_->request_resumed());
309 } 309 }
310 310
311 TEST_F(InterceptNavigationResourceThrottleTest, 311 TEST_F(InterceptNavigationResourceThrottleTest,
312 RequestNotDeferredForRequestNotAssociatedWithARenderView) { 312 RequestNotDeferredForRequestNotAssociatedWithARenderView) {
313 bool defer = false; 313 bool defer = false;
314 314
315 BrowserThread::PostTask( 315 content::BrowserThread::PostTask(
316 BrowserThread::IO, 316 content::BrowserThread::IO,
317 FROM_HERE, 317 FROM_HERE,
318 base::Bind( 318 base::Bind(
319 &InterceptNavigationResourceThrottleTest:: 319 &InterceptNavigationResourceThrottleTest::
320 RunThrottleWillStartRequestOnIOThread, 320 RunThrottleWillStartRequestOnIOThread,
321 base::Unretained(this), 321 base::Unretained(this),
322 GURL(kTestUrl), 322 GURL(kTestUrl),
323 "GET", 323 "GET",
324 MSG_ROUTING_NONE, 324 MSG_ROUTING_NONE,
325 MSG_ROUTING_NONE, 325 MSG_ROUTING_NONE,
326 base::Unretained(&defer))); 326 base::Unretained(&defer)));
327 327
328 // Wait for the request to finish processing. 328 // Wait for the request to finish processing.
329 message_loop_.Run(); 329 message_loop_.Run();
330 330
331 EXPECT_FALSE(defer); 331 EXPECT_FALSE(defer);
332 } 332 }
333 333
334 TEST_F(InterceptNavigationResourceThrottleTest, 334 TEST_F(InterceptNavigationResourceThrottleTest,
335 CallbackCalledWithFilteredUrl) { 335 CallbackCalledWithFilteredUrl) {
336 bool defer = false; 336 bool defer = false;
337 337
338 ON_CALL(*mock_callback_receiver_, 338 ON_CALL(*mock_callback_receiver_,
339 ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, _, _, _)) 339 ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, _, _, _))
340 .WillByDefault(Return(false)); 340 .WillByDefault(Return(false));
341 EXPECT_CALL(*mock_callback_receiver_, 341 EXPECT_CALL(*mock_callback_receiver_,
342 ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, _, _, _)) 342 ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, _, _, _))
343 .Times(1); 343 .Times(1);
344 344
345 BrowserThread::PostTask( 345 content::BrowserThread::PostTask(
346 BrowserThread::IO, 346 content::BrowserThread::IO,
347 FROM_HERE, 347 FROM_HERE,
348 base::Bind( 348 base::Bind(
349 &InterceptNavigationResourceThrottleTest:: 349 &InterceptNavigationResourceThrottleTest::
350 RunThrottleWillStartRequestOnIOThread, 350 RunThrottleWillStartRequestOnIOThread,
351 base::Unretained(this), 351 base::Unretained(this),
352 GURL(kUnsafeTestUrl), 352 GURL(kUnsafeTestUrl),
353 "GET", 353 "GET",
354 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), 354 web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
355 web_contents()->GetRenderViewHost()->GetRoutingID(), 355 web_contents()->GetRenderViewHost()->GetRoutingID(),
356 base::Unretained(&defer))); 356 base::Unretained(&defer)));
357 357
358 // Wait for the request to finish processing. 358 // Wait for the request to finish processing.
359 message_loop_.Run(); 359 message_loop_.Run();
360 } 360 }
361 361
362 TEST_F(InterceptNavigationResourceThrottleTest, 362 TEST_F(InterceptNavigationResourceThrottleTest,
363 CallbackIsPostFalseForGet) { 363 CallbackIsPostFalseForGet) {
364 bool defer = false; 364 bool defer = false;
365 365
366 EXPECT_CALL(*mock_callback_receiver_, 366 EXPECT_CALL(*mock_callback_receiver_,
367 ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, false, _, 367 ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, false, _,
368 _)) 368 _))
369 .WillOnce(Return(false)); 369 .WillOnce(Return(false));
370 370
371 BrowserThread::PostTask( 371 content::BrowserThread::PostTask(
372 BrowserThread::IO, 372 content::BrowserThread::IO,
373 FROM_HERE, 373 FROM_HERE,
374 base::Bind( 374 base::Bind(
375 &InterceptNavigationResourceThrottleTest:: 375 &InterceptNavigationResourceThrottleTest::
376 RunThrottleWillStartRequestOnIOThread, 376 RunThrottleWillStartRequestOnIOThread,
377 base::Unretained(this), 377 base::Unretained(this),
378 GURL(kTestUrl), 378 GURL(kTestUrl),
379 "GET", 379 "GET",
380 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), 380 web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
381 web_contents()->GetRenderViewHost()->GetRoutingID(), 381 web_contents()->GetRenderViewHost()->GetRoutingID(),
382 base::Unretained(&defer))); 382 base::Unretained(&defer)));
383 383
384 // Wait for the request to finish processing. 384 // Wait for the request to finish processing.
385 message_loop_.Run(); 385 message_loop_.Run();
386 } 386 }
387 387
388 TEST_F(InterceptNavigationResourceThrottleTest, 388 TEST_F(InterceptNavigationResourceThrottleTest,
389 CallbackIsPostTrueForPost) { 389 CallbackIsPostTrueForPost) {
390 bool defer = false; 390 bool defer = false;
391 391
392 EXPECT_CALL(*mock_callback_receiver_, 392 EXPECT_CALL(*mock_callback_receiver_,
393 ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, true, _, 393 ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, true, _,
394 _)) 394 _))
395 .WillOnce(Return(false)); 395 .WillOnce(Return(false));
396 396
397 BrowserThread::PostTask( 397 content::BrowserThread::PostTask(
398 BrowserThread::IO, 398 content::BrowserThread::IO,
399 FROM_HERE, 399 FROM_HERE,
400 base::Bind( 400 base::Bind(
401 &InterceptNavigationResourceThrottleTest:: 401 &InterceptNavigationResourceThrottleTest::
402 RunThrottleWillStartRequestOnIOThread, 402 RunThrottleWillStartRequestOnIOThread,
403 base::Unretained(this), 403 base::Unretained(this),
404 GURL(kTestUrl), 404 GURL(kTestUrl),
405 "POST", 405 "POST",
406 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), 406 web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
407 web_contents()->GetRenderViewHost()->GetRoutingID(), 407 web_contents()->GetRenderViewHost()->GetRoutingID(),
408 base::Unretained(&defer))); 408 base::Unretained(&defer)));
409 409
410 // Wait for the request to finish processing. 410 // Wait for the request to finish processing.
411 message_loop_.Run(); 411 message_loop_.Run();
412 } 412 }
413 413
414 } // namespace content 414 } // namespace components
OLDNEW
« no previous file with comments | « components/navigation_interception/intercept_navigation_resource_throttle.cc ('k') | components/test/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698