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

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api_unittest.cc

Issue 2264903003: Adjust callers and networking delegates in chrome/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: fix while loop Created 4 years, 2 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 <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 11 matching lines...) Expand all
22 #include "base/run_loop.h" 22 #include "base/run_loop.h"
23 #include "base/stl_util.h" 23 #include "base/stl_util.h"
24 #include "base/strings/string_piece.h" 24 #include "base/strings/string_piece.h"
25 #include "base/strings/string_split.h" 25 #include "base/strings/string_split.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
28 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/thread_task_runner_handle.h"
29 #include "base/time/time.h" 29 #include "base/time/time.h"
30 #include "chrome/browser/content_settings/cookie_settings_factory.h" 30 #include "chrome/browser/content_settings/cookie_settings_factory.h"
31 #include "chrome/browser/extensions/event_router_forwarder.h" 31 #include "chrome/browser/extensions/event_router_forwarder.h"
32 #include "chrome/browser/net/chrome_extensions_network_delegate.h"
32 #include "chrome/browser/net/chrome_network_delegate.h" 33 #include "chrome/browser/net/chrome_network_delegate.h"
33 #include "chrome/test/base/testing_browser_process.h" 34 #include "chrome/test/base/testing_browser_process.h"
34 #include "chrome/test/base/testing_profile.h" 35 #include "chrome/test/base/testing_profile.h"
35 #include "chrome/test/base/testing_profile_manager.h" 36 #include "chrome/test/base/testing_profile_manager.h"
36 #include "components/about_handler/about_protocol_handler.h" 37 #include "components/about_handler/about_protocol_handler.h"
37 #include "components/content_settings/core/browser/cookie_settings.h" 38 #include "components/content_settings/core/browser/cookie_settings.h"
38 #include "components/prefs/pref_member.h" 39 #include "components/prefs/pref_member.h"
39 #include "components/syncable_prefs/testing_pref_service_syncable.h" 40 #include "components/syncable_prefs/testing_pref_service_syncable.h"
40 #include "content/public/common/url_constants.h" 41 #include "content/public/common/url_constants.h"
41 #include "content/public/test/test_browser_thread_bundle.h" 42 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 extension1_id, base::Time::FromDoubleT(1)); 293 extension1_id, base::Time::FromDoubleT(1));
293 ipc_sender_.PushTask( 294 ipc_sender_.PushTask(
294 base::Bind(&EventHandledOnIOThread, 295 base::Bind(&EventHandledOnIOThread,
295 &profile_, extension1_id, kEventName, kEventName + "/1", 296 &profile_, extension1_id, kEventName, kEventName + "/1",
296 request->identifier(), response)); 297 request->identifier(), response));
297 298
298 request->Start(); 299 request->Start();
299 base::RunLoop().Run(); 300 base::RunLoop().Run();
300 301
301 EXPECT_TRUE(!request->is_pending()); 302 EXPECT_TRUE(!request->is_pending());
302 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); 303 EXPECT_EQ(net::OK, delegate_.request_status());
303 EXPECT_EQ(0, request->status().error());
304 EXPECT_EQ(redirect_url, request->url()); 304 EXPECT_EQ(redirect_url, request->url());
305 EXPECT_EQ(2U, request->url_chain().size()); 305 EXPECT_EQ(2U, request->url_chain().size());
306 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); 306 EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
307 } 307 }
308 308
309 // Now test the same thing but the extensions answer in reverse order. 309 // Now test the same thing but the extensions answer in reverse order.
310 std::unique_ptr<net::URLRequest> request2(context_->CreateRequest( 310 std::unique_ptr<net::URLRequest> request2(context_->CreateRequest(
311 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_)); 311 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_));
312 { 312 {
313 ExtensionWebRequestEventRouter::EventResponse* response = NULL; 313 ExtensionWebRequestEventRouter::EventResponse* response = NULL;
(...skipping 29 matching lines...) Expand all
343 extension1_id, base::Time::FromDoubleT(1)); 343 extension1_id, base::Time::FromDoubleT(1));
344 ipc_sender_.PushTask( 344 ipc_sender_.PushTask(
345 base::Bind(&EventHandledOnIOThread, 345 base::Bind(&EventHandledOnIOThread,
346 &profile_, extension1_id, kEventName, kEventName + "/1", 346 &profile_, extension1_id, kEventName, kEventName + "/1",
347 request2->identifier(), response)); 347 request2->identifier(), response));
348 348
349 request2->Start(); 349 request2->Start();
350 base::RunLoop().Run(); 350 base::RunLoop().Run();
351 351
352 EXPECT_TRUE(!request2->is_pending()); 352 EXPECT_TRUE(!request2->is_pending());
353 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request2->status().status()); 353 EXPECT_EQ(net::OK, delegate_.request_status());
354 EXPECT_EQ(0, request2->status().error());
355 EXPECT_EQ(redirect_url, request2->url()); 354 EXPECT_EQ(redirect_url, request2->url());
356 EXPECT_EQ(2U, request2->url_chain().size()); 355 EXPECT_EQ(2U, request2->url_chain().size());
357 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); 356 EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
358 } 357 }
359 358
360 ExtensionWebRequestEventRouter::EventListener::ID id1( 359 ExtensionWebRequestEventRouter::EventListener::ID id1(
361 &profile_, extension1_id, kEventName + "/1", 0, 0); 360 &profile_, extension1_id, kEventName + "/1", 0, 0);
362 ExtensionWebRequestEventRouter::EventListener::ID id2( 361 ExtensionWebRequestEventRouter::EventListener::ID id2(
363 &profile_, extension2_id, kEventName + "/2", 0, 0); 362 &profile_, extension2_id, kEventName + "/2", 0, 0);
364 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, 363 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 ipc_sender_.PushTask( 411 ipc_sender_.PushTask(
413 base::Bind(&EventHandledOnIOThread, 412 base::Bind(&EventHandledOnIOThread,
414 &profile_, extension2_id, kEventName, kEventName + "/2", 413 &profile_, extension2_id, kEventName, kEventName + "/2",
415 request->identifier(), response)); 414 request->identifier(), response));
416 415
417 request->Start(); 416 request->Start();
418 417
419 base::RunLoop().Run(); 418 base::RunLoop().Run();
420 419
421 EXPECT_TRUE(!request->is_pending()); 420 EXPECT_TRUE(!request->is_pending());
422 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); 421 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, delegate_.request_status());
423 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, request->status().error());
424 EXPECT_EQ(request_url, request->url()); 422 EXPECT_EQ(request_url, request->url());
425 EXPECT_EQ(1U, request->url_chain().size()); 423 EXPECT_EQ(1U, request->url_chain().size());
426 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); 424 EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
427 425
428 ExtensionWebRequestEventRouter::EventListener::ID id1( 426 ExtensionWebRequestEventRouter::EventListener::ID id1(
429 &profile_, extension1_id, kEventName + "/1", 0, 0); 427 &profile_, extension1_id, kEventName + "/1", 0, 0);
430 ExtensionWebRequestEventRouter::EventListener::ID id2( 428 ExtensionWebRequestEventRouter::EventListener::ID id2(
431 &profile_, extension2_id, kEventName + "/2", 0, 0); 429 &profile_, extension2_id, kEventName + "/2", 0, 0);
432 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, 430 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1,
433 false); 431 false);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 base::RunLoop run_loop; 474 base::RunLoop run_loop;
477 475
478 // Extension response for OnErrorOccurred: Terminate the message loop. 476 // Extension response for OnErrorOccurred: Terminate the message loop.
479 ipc_sender_.PushTask( 477 ipc_sender_.PushTask(
480 base::Bind(base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask), 478 base::Bind(base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask),
481 base::ThreadTaskRunnerHandle::Get(), FROM_HERE, 479 base::ThreadTaskRunnerHandle::Get(), FROM_HERE,
482 run_loop.QuitWhenIdleClosure())); 480 run_loop.QuitWhenIdleClosure()));
483 481
484 request->Start(); 482 request->Start();
485 // request->Start() will have submitted OnBeforeRequest by the time we cancel. 483 // request->Start() will have submitted OnBeforeRequest by the time we cancel.
486 request->Cancel(); 484 int net_error = request->Cancel();
487 run_loop.Run(); 485 run_loop.Run();
488 486
487 EXPECT_EQ(net::ERR_ABORTED, net_error);
489 EXPECT_TRUE(!request->is_pending()); 488 EXPECT_TRUE(!request->is_pending());
490 EXPECT_EQ(net::URLRequestStatus::CANCELED, request->status().status());
491 EXPECT_EQ(net::ERR_ABORTED, request->status().error());
492 EXPECT_EQ(request_url, request->url()); 489 EXPECT_EQ(request_url, request->url());
493 EXPECT_EQ(1U, request->url_chain().size()); 490 EXPECT_EQ(1U, request->url_chain().size());
494 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); 491 EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
495 492
496 ExtensionWebRequestEventRouter::EventListener::ID id1( 493 ExtensionWebRequestEventRouter::EventListener::ID id1(
497 &profile_, extension_id, kEventName + "/1", 0, 0); 494 &profile_, extension_id, kEventName + "/1", 0, 0);
498 ExtensionWebRequestEventRouter::EventListener::ID id2( 495 ExtensionWebRequestEventRouter::EventListener::ID id2(
499 &profile_, extension_id, kEventName2 + "/1", 0, 0); 496 &profile_, extension_id, kEventName2 + "/1", 0, 0);
500 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, 497 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1,
501 false); 498 false);
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 // request->Start() will first add additional headers (e.g. the User-Agent) 1111 // request->Start() will first add additional headers (e.g. the User-Agent)
1115 // and then send an event to the extension. When we have prepared our 1112 // and then send an event to the extension. When we have prepared our
1116 // answers to the onBeforeSendHeaders events above, these headers did not 1113 // answers to the onBeforeSendHeaders events above, these headers did not
1117 // exists and are therefore not listed in the responses. This makes 1114 // exists and are therefore not listed in the responses. This makes
1118 // them seem deleted. 1115 // them seem deleted.
1119 request->Start(); 1116 request->Start();
1120 base::RunLoop().Run(); 1117 base::RunLoop().Run();
1121 1118
1122 EXPECT_TRUE(!request->is_pending()); 1119 EXPECT_TRUE(!request->is_pending());
1123 // This cannot succeed as we send the request to a server that does not exist. 1120 // This cannot succeed as we send the request to a server that does not exist.
1124 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); 1121 EXPECT_EQ(net::ERR_NAME_NOT_RESOLVED, delegate_.request_status());
1125 EXPECT_EQ(request_url, request->url()); 1122 EXPECT_EQ(request_url, request->url());
1126 EXPECT_EQ(1U, request->url_chain().size()); 1123 EXPECT_EQ(1U, request->url_chain().size());
1127 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); 1124 EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
1128 1125
1129 // Calculate the expected headers. 1126 // Calculate the expected headers.
1130 net::HttpRequestHeaders expected_headers; 1127 net::HttpRequestHeaders expected_headers;
1131 for (int i = 0; i < test.after_size; ++i) { 1128 for (int i = 0; i < test.after_size; ++i) {
1132 expected_headers.SetHeader(test.after[i].name, 1129 expected_headers.SetHeader(test.after[i].name,
1133 test.after[i].value); 1130 test.after[i].value);
1134 } 1131 }
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 EXPECT_TRUE(credentials_set); 2450 EXPECT_TRUE(credentials_set);
2454 EXPECT_FALSE(auth3.Empty()); 2451 EXPECT_FALSE(auth3.Empty());
2455 EXPECT_EQ(username, auth1.username()); 2452 EXPECT_EQ(username, auth1.username());
2456 EXPECT_EQ(password, auth1.password()); 2453 EXPECT_EQ(password, auth1.password());
2457 EXPECT_EQ(1u, warning_set.size()); 2454 EXPECT_EQ(1u, warning_set.size());
2458 EXPECT_TRUE(HasWarning(warning_set, "extid2")); 2455 EXPECT_TRUE(HasWarning(warning_set, "extid2"));
2459 EXPECT_EQ(3u, capturing_net_log.GetSize()); 2456 EXPECT_EQ(3u, capturing_net_log.GetSize());
2460 } 2457 }
2461 2458
2462 } // namespace extensions 2459 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698