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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <queue> | 10 #include <queue> |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 extension1_id, base::Time::FromDoubleT(1)); | 291 extension1_id, base::Time::FromDoubleT(1)); |
292 ipc_sender_.PushTask( | 292 ipc_sender_.PushTask( |
293 base::Bind(&EventHandledOnIOThread, | 293 base::Bind(&EventHandledOnIOThread, |
294 &profile_, extension1_id, kEventName, kEventName + "/1", | 294 &profile_, extension1_id, kEventName, kEventName + "/1", |
295 request->identifier(), response)); | 295 request->identifier(), response)); |
296 | 296 |
297 request->Start(); | 297 request->Start(); |
298 base::RunLoop().Run(); | 298 base::RunLoop().Run(); |
299 | 299 |
300 EXPECT_TRUE(!request->is_pending()); | 300 EXPECT_TRUE(!request->is_pending()); |
301 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); | 301 EXPECT_EQ(net::OK, delegate_.request_status()); |
302 EXPECT_EQ(0, request->status().error()); | |
303 EXPECT_EQ(redirect_url, request->url()); | 302 EXPECT_EQ(redirect_url, request->url()); |
304 EXPECT_EQ(2U, request->url_chain().size()); | 303 EXPECT_EQ(2U, request->url_chain().size()); |
305 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); | 304 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); |
306 } | 305 } |
307 | 306 |
308 // Now test the same thing but the extensions answer in reverse order. | 307 // Now test the same thing but the extensions answer in reverse order. |
309 std::unique_ptr<net::URLRequest> request2(context_->CreateRequest( | 308 std::unique_ptr<net::URLRequest> request2(context_->CreateRequest( |
310 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_)); | 309 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_)); |
311 { | 310 { |
312 ExtensionWebRequestEventRouter::EventResponse* response = NULL; | 311 ExtensionWebRequestEventRouter::EventResponse* response = NULL; |
(...skipping 29 matching lines...) Expand all Loading... |
342 extension1_id, base::Time::FromDoubleT(1)); | 341 extension1_id, base::Time::FromDoubleT(1)); |
343 ipc_sender_.PushTask( | 342 ipc_sender_.PushTask( |
344 base::Bind(&EventHandledOnIOThread, | 343 base::Bind(&EventHandledOnIOThread, |
345 &profile_, extension1_id, kEventName, kEventName + "/1", | 344 &profile_, extension1_id, kEventName, kEventName + "/1", |
346 request2->identifier(), response)); | 345 request2->identifier(), response)); |
347 | 346 |
348 request2->Start(); | 347 request2->Start(); |
349 base::RunLoop().Run(); | 348 base::RunLoop().Run(); |
350 | 349 |
351 EXPECT_TRUE(!request2->is_pending()); | 350 EXPECT_TRUE(!request2->is_pending()); |
352 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request2->status().status()); | 351 EXPECT_EQ(net::OK, delegate_.request_status()); |
353 EXPECT_EQ(0, request2->status().error()); | |
354 EXPECT_EQ(redirect_url, request2->url()); | 352 EXPECT_EQ(redirect_url, request2->url()); |
355 EXPECT_EQ(2U, request2->url_chain().size()); | 353 EXPECT_EQ(2U, request2->url_chain().size()); |
356 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); | 354 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); |
357 } | 355 } |
358 | 356 |
359 ExtensionWebRequestEventRouter::EventListener::ID id1( | 357 ExtensionWebRequestEventRouter::EventListener::ID id1( |
360 &profile_, extension1_id, kEventName + "/1", 0, 0); | 358 &profile_, extension1_id, kEventName + "/1", 0, 0); |
361 ExtensionWebRequestEventRouter::EventListener::ID id2( | 359 ExtensionWebRequestEventRouter::EventListener::ID id2( |
362 &profile_, extension2_id, kEventName + "/2", 0, 0); | 360 &profile_, extension2_id, kEventName + "/2", 0, 0); |
363 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, | 361 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 ipc_sender_.PushTask( | 409 ipc_sender_.PushTask( |
412 base::Bind(&EventHandledOnIOThread, | 410 base::Bind(&EventHandledOnIOThread, |
413 &profile_, extension2_id, kEventName, kEventName + "/2", | 411 &profile_, extension2_id, kEventName, kEventName + "/2", |
414 request->identifier(), response)); | 412 request->identifier(), response)); |
415 | 413 |
416 request->Start(); | 414 request->Start(); |
417 | 415 |
418 base::RunLoop().Run(); | 416 base::RunLoop().Run(); |
419 | 417 |
420 EXPECT_TRUE(!request->is_pending()); | 418 EXPECT_TRUE(!request->is_pending()); |
421 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 419 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, delegate_.request_status()); |
422 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, request->status().error()); | |
423 EXPECT_EQ(request_url, request->url()); | 420 EXPECT_EQ(request_url, request->url()); |
424 EXPECT_EQ(1U, request->url_chain().size()); | 421 EXPECT_EQ(1U, request->url_chain().size()); |
425 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); | 422 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); |
426 | 423 |
427 ExtensionWebRequestEventRouter::EventListener::ID id1( | 424 ExtensionWebRequestEventRouter::EventListener::ID id1( |
428 &profile_, extension1_id, kEventName + "/1", 0, 0); | 425 &profile_, extension1_id, kEventName + "/1", 0, 0); |
429 ExtensionWebRequestEventRouter::EventListener::ID id2( | 426 ExtensionWebRequestEventRouter::EventListener::ID id2( |
430 &profile_, extension2_id, kEventName + "/2", 0, 0); | 427 &profile_, extension2_id, kEventName + "/2", 0, 0); |
431 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, | 428 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, |
432 false); | 429 false); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 base::Bind(base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask), | 476 base::Bind(base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask), |
480 base::ThreadTaskRunnerHandle::Get(), FROM_HERE, | 477 base::ThreadTaskRunnerHandle::Get(), FROM_HERE, |
481 run_loop.QuitWhenIdleClosure())); | 478 run_loop.QuitWhenIdleClosure())); |
482 | 479 |
483 request->Start(); | 480 request->Start(); |
484 // request->Start() will have submitted OnBeforeRequest by the time we cancel. | 481 // request->Start() will have submitted OnBeforeRequest by the time we cancel. |
485 request->Cancel(); | 482 request->Cancel(); |
486 run_loop.Run(); | 483 run_loop.Run(); |
487 | 484 |
488 EXPECT_TRUE(!request->is_pending()); | 485 EXPECT_TRUE(!request->is_pending()); |
489 EXPECT_EQ(net::URLRequestStatus::CANCELED, request->status().status()); | 486 EXPECT_EQ(net::ERR_ABORTED, delegate_.request_status()); |
490 EXPECT_EQ(net::ERR_ABORTED, request->status().error()); | |
491 EXPECT_EQ(request_url, request->url()); | 487 EXPECT_EQ(request_url, request->url()); |
492 EXPECT_EQ(1U, request->url_chain().size()); | 488 EXPECT_EQ(1U, request->url_chain().size()); |
493 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); | 489 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); |
494 | 490 |
495 ExtensionWebRequestEventRouter::EventListener::ID id1( | 491 ExtensionWebRequestEventRouter::EventListener::ID id1( |
496 &profile_, extension_id, kEventName + "/1", 0, 0); | 492 &profile_, extension_id, kEventName + "/1", 0, 0); |
497 ExtensionWebRequestEventRouter::EventListener::ID id2( | 493 ExtensionWebRequestEventRouter::EventListener::ID id2( |
498 &profile_, extension_id, kEventName2 + "/1", 0, 0); | 494 &profile_, extension_id, kEventName2 + "/1", 0, 0); |
499 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, | 495 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, |
500 false); | 496 false); |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 // request->Start() will first add additional headers (e.g. the User-Agent) | 1109 // request->Start() will first add additional headers (e.g. the User-Agent) |
1114 // and then send an event to the extension. When we have prepared our | 1110 // and then send an event to the extension. When we have prepared our |
1115 // answers to the onBeforeSendHeaders events above, these headers did not | 1111 // answers to the onBeforeSendHeaders events above, these headers did not |
1116 // exists and are therefore not listed in the responses. This makes | 1112 // exists and are therefore not listed in the responses. This makes |
1117 // them seem deleted. | 1113 // them seem deleted. |
1118 request->Start(); | 1114 request->Start(); |
1119 base::RunLoop().Run(); | 1115 base::RunLoop().Run(); |
1120 | 1116 |
1121 EXPECT_TRUE(!request->is_pending()); | 1117 EXPECT_TRUE(!request->is_pending()); |
1122 // This cannot succeed as we send the request to a server that does not exist. | 1118 // This cannot succeed as we send the request to a server that does not exist. |
1123 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 1119 EXPECT_EQ(net::ERR_FAILED, delegate_.request_status()); |
1124 EXPECT_EQ(request_url, request->url()); | 1120 EXPECT_EQ(request_url, request->url()); |
1125 EXPECT_EQ(1U, request->url_chain().size()); | 1121 EXPECT_EQ(1U, request->url_chain().size()); |
1126 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); | 1122 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); |
1127 | 1123 |
1128 // Calculate the expected headers. | 1124 // Calculate the expected headers. |
1129 net::HttpRequestHeaders expected_headers; | 1125 net::HttpRequestHeaders expected_headers; |
1130 for (int i = 0; i < test.after_size; ++i) { | 1126 for (int i = 0; i < test.after_size; ++i) { |
1131 expected_headers.SetHeader(test.after[i].name, | 1127 expected_headers.SetHeader(test.after[i].name, |
1132 test.after[i].value); | 1128 test.after[i].value); |
1133 } | 1129 } |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2452 EXPECT_TRUE(credentials_set); | 2448 EXPECT_TRUE(credentials_set); |
2453 EXPECT_FALSE(auth3.Empty()); | 2449 EXPECT_FALSE(auth3.Empty()); |
2454 EXPECT_EQ(username, auth1.username()); | 2450 EXPECT_EQ(username, auth1.username()); |
2455 EXPECT_EQ(password, auth1.password()); | 2451 EXPECT_EQ(password, auth1.password()); |
2456 EXPECT_EQ(1u, warning_set.size()); | 2452 EXPECT_EQ(1u, warning_set.size()); |
2457 EXPECT_TRUE(HasWarning(warning_set, "extid2")); | 2453 EXPECT_TRUE(HasWarning(warning_set, "extid2")); |
2458 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 2454 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
2459 } | 2455 } |
2460 | 2456 |
2461 } // namespace extensions | 2457 } // namespace extensions |
OLD | NEW |