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

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: remove a file that has already been uploaded with another CL 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 extension1_id, base::Time::FromDoubleT(1)); 292 extension1_id, base::Time::FromDoubleT(1));
292 ipc_sender_.PushTask( 293 ipc_sender_.PushTask(
293 base::Bind(&EventHandledOnIOThread, 294 base::Bind(&EventHandledOnIOThread,
294 &profile_, extension1_id, kEventName, kEventName + "/1", 295 &profile_, extension1_id, kEventName, kEventName + "/1",
295 request->identifier(), response)); 296 request->identifier(), response));
296 297
297 request->Start(); 298 request->Start();
298 base::RunLoop().Run(); 299 base::RunLoop().Run();
299 300
300 EXPECT_TRUE(!request->is_pending()); 301 EXPECT_TRUE(!request->is_pending());
301 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); 302 EXPECT_EQ(net::OK, delegate_.request_status());
302 EXPECT_EQ(0, request->status().error());
303 EXPECT_EQ(redirect_url, request->url()); 303 EXPECT_EQ(redirect_url, request->url());
304 EXPECT_EQ(2U, request->url_chain().size()); 304 EXPECT_EQ(2U, request->url_chain().size());
305 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); 305 EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
306 } 306 }
307 307
308 // Now test the same thing but the extensions answer in reverse order. 308 // Now test the same thing but the extensions answer in reverse order.
309 std::unique_ptr<net::URLRequest> request2(context_->CreateRequest( 309 std::unique_ptr<net::URLRequest> request2(context_->CreateRequest(
310 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_)); 310 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_));
311 { 311 {
312 ExtensionWebRequestEventRouter::EventResponse* response = NULL; 312 ExtensionWebRequestEventRouter::EventResponse* response = NULL;
(...skipping 29 matching lines...) Expand all
342 extension1_id, base::Time::FromDoubleT(1)); 342 extension1_id, base::Time::FromDoubleT(1));
343 ipc_sender_.PushTask( 343 ipc_sender_.PushTask(
344 base::Bind(&EventHandledOnIOThread, 344 base::Bind(&EventHandledOnIOThread,
345 &profile_, extension1_id, kEventName, kEventName + "/1", 345 &profile_, extension1_id, kEventName, kEventName + "/1",
346 request2->identifier(), response)); 346 request2->identifier(), response));
347 347
348 request2->Start(); 348 request2->Start();
349 base::RunLoop().Run(); 349 base::RunLoop().Run();
350 350
351 EXPECT_TRUE(!request2->is_pending()); 351 EXPECT_TRUE(!request2->is_pending());
352 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request2->status().status()); 352 EXPECT_EQ(net::OK, delegate_.request_status());
353 EXPECT_EQ(0, request2->status().error());
354 EXPECT_EQ(redirect_url, request2->url()); 353 EXPECT_EQ(redirect_url, request2->url());
355 EXPECT_EQ(2U, request2->url_chain().size()); 354 EXPECT_EQ(2U, request2->url_chain().size());
356 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); 355 EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
357 } 356 }
358 357
359 ExtensionWebRequestEventRouter::EventListener::ID id1( 358 ExtensionWebRequestEventRouter::EventListener::ID id1(
360 &profile_, extension1_id, kEventName + "/1", 0, 0); 359 &profile_, extension1_id, kEventName + "/1", 0, 0);
361 ExtensionWebRequestEventRouter::EventListener::ID id2( 360 ExtensionWebRequestEventRouter::EventListener::ID id2(
362 &profile_, extension2_id, kEventName + "/2", 0, 0); 361 &profile_, extension2_id, kEventName + "/2", 0, 0);
363 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, 362 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 ipc_sender_.PushTask( 410 ipc_sender_.PushTask(
412 base::Bind(&EventHandledOnIOThread, 411 base::Bind(&EventHandledOnIOThread,
413 &profile_, extension2_id, kEventName, kEventName + "/2", 412 &profile_, extension2_id, kEventName, kEventName + "/2",
414 request->identifier(), response)); 413 request->identifier(), response));
415 414
416 request->Start(); 415 request->Start();
417 416
418 base::RunLoop().Run(); 417 base::RunLoop().Run();
419 418
420 EXPECT_TRUE(!request->is_pending()); 419 EXPECT_TRUE(!request->is_pending());
421 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); 420 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()); 421 EXPECT_EQ(request_url, request->url());
424 EXPECT_EQ(1U, request->url_chain().size()); 422 EXPECT_EQ(1U, request->url_chain().size());
425 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); 423 EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
426 424
427 ExtensionWebRequestEventRouter::EventListener::ID id1( 425 ExtensionWebRequestEventRouter::EventListener::ID id1(
428 &profile_, extension1_id, kEventName + "/1", 0, 0); 426 &profile_, extension1_id, kEventName + "/1", 0, 0);
429 ExtensionWebRequestEventRouter::EventListener::ID id2( 427 ExtensionWebRequestEventRouter::EventListener::ID id2(
430 &profile_, extension2_id, kEventName + "/2", 0, 0); 428 &profile_, extension2_id, kEventName + "/2", 0, 0);
431 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1, 429 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(id1,
432 false); 430 false);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 base::Bind(base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask), 477 base::Bind(base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask),
480 base::ThreadTaskRunnerHandle::Get(), FROM_HERE, 478 base::ThreadTaskRunnerHandle::Get(), FROM_HERE,
481 run_loop.QuitWhenIdleClosure())); 479 run_loop.QuitWhenIdleClosure()));
482 480
483 request->Start(); 481 request->Start();
484 // request->Start() will have submitted OnBeforeRequest by the time we cancel. 482 // request->Start() will have submitted OnBeforeRequest by the time we cancel.
485 request->Cancel(); 483 request->Cancel();
486 run_loop.Run(); 484 run_loop.Run();
487 485
488 EXPECT_TRUE(!request->is_pending()); 486 EXPECT_TRUE(!request->is_pending());
489 EXPECT_EQ(net::URLRequestStatus::CANCELED, request->status().status());
490 EXPECT_EQ(net::ERR_ABORTED, request->status().error());
battre 2016/09/29 13:24:29 Doesn't a canceled request have some status?
maksims (do not use this acc) 2016/09/30 06:06:07 Yes, indeed, it has. But the status is returned th
battre 2016/09/30 06:53:24 ok, I see. I think the important line of this test
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
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_NAME_NOT_RESOLVED, 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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698