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

Side by Side Diff: chrome/browser/extensions/extension_webrequest_api_unittest.cc

Issue 9114020: Remove task.h and finish base::Bind() migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <queue> 5 #include <queue>
6 #include <map> 6 #include <map>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/json/json_value_serializer.h" 11 #include "base/json/json_value_serializer.h"
12 #include "base/memory/weak_ptr.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/extensions/extension_event_router_forwarder.h" 16 #include "chrome/browser/extensions/extension_event_router_forwarder.h"
16 #include "chrome/browser/extensions/extension_webrequest_api.h" 17 #include "chrome/browser/extensions/extension_webrequest_api.h"
17 #include "chrome/browser/extensions/extension_webrequest_api_constants.h" 18 #include "chrome/browser/extensions/extension_webrequest_api_constants.h"
18 #include "chrome/browser/extensions/extension_webrequest_api_helpers.h" 19 #include "chrome/browser/extensions/extension_webrequest_api_helpers.h"
19 #include "chrome/browser/net/chrome_network_delegate.h" 20 #include "chrome/browser/net/chrome_network_delegate.h"
20 #include "chrome/browser/prefs/pref_member.h" 21 #include "chrome/browser/prefs/pref_member.h"
21 #include "chrome/common/extensions/extension_messages.h" 22 #include "chrome/common/extensions/extension_messages.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } // namespace 56 } // namespace
56 57
57 // A mock event router that responds to events with a pre-arranged queue of 58 // A mock event router that responds to events with a pre-arranged queue of
58 // Tasks. 59 // Tasks.
59 class TestIPCSender : public IPC::Message::Sender { 60 class TestIPCSender : public IPC::Message::Sender {
60 public: 61 public:
61 typedef std::list<linked_ptr<IPC::Message> > SentMessages; 62 typedef std::list<linked_ptr<IPC::Message> > SentMessages;
62 63
63 // Adds a Task to the queue. We will fire these in order as events are 64 // Adds a Task to the queue. We will fire these in order as events are
64 // dispatched. 65 // dispatched.
65 void PushTask(base::Closure task) { 66 void PushTask(const base::Closure& task) {
66 task_queue_.push(task); 67 task_queue_.push(task);
67 } 68 }
68 69
69 size_t GetNumTasks() { return task_queue_.size(); } 70 size_t GetNumTasks() { return task_queue_.size(); }
70 71
71 SentMessages::const_iterator sent_begin() const { 72 SentMessages::const_iterator sent_begin() const {
72 return sent_messages_.begin(); 73 return sent_messages_.begin();
73 } 74 }
74 75
75 SentMessages::const_iterator sent_end() const { 76 SentMessages::const_iterator sent_end() const {
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 TestingProfile profile_; 355 TestingProfile profile_;
355 TestDelegate delegate_; 356 TestDelegate delegate_;
356 BooleanPrefMember enable_referrers_; 357 BooleanPrefMember enable_referrers_;
357 TestIPCSender ipc_sender_; 358 TestIPCSender ipc_sender_;
358 scoped_refptr<ExtensionEventRouterForwarder> event_router_; 359 scoped_refptr<ExtensionEventRouterForwarder> event_router_;
359 scoped_refptr<ExtensionInfoMap> extension_info_map_; 360 scoped_refptr<ExtensionInfoMap> extension_info_map_;
360 scoped_ptr<ChromeNetworkDelegate> network_delegate_; 361 scoped_ptr<ChromeNetworkDelegate> network_delegate_;
361 scoped_refptr<TestURLRequestContext> context_; 362 scoped_refptr<TestURLRequestContext> context_;
362 }; 363 };
363 364
364 static void DoNothing() {
365 }
366
367 TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) { 365 TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) {
368 std::string extension1_id("1"); 366 std::string extension1_id("1");
369 std::string extension2_id("2"); 367 std::string extension2_id("2");
370 std::string extension3_id("3"); 368 std::string extension3_id("3");
371 ExtensionWebRequestEventRouter::RequestFilter filter; 369 ExtensionWebRequestEventRouter::RequestFilter filter;
372 const std::string kEventName(keys::kOnBeforeSendHeaders); 370 const std::string kEventName(keys::kOnBeforeSendHeaders);
373 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); 371 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_);
374 372
375 // Install two extensions that can modify headers. Extension 2 has 373 // Install two extensions that can modify headers. Extension 2 has
376 // higher precedence than extension 1. 374 // higher precedence than extension 1.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 ipc_sender_.PushTask( 430 ipc_sender_.PushTask(
433 base::Bind(&EventHandledOnIOThread, 431 base::Bind(&EventHandledOnIOThread,
434 &profile_, mod.extension_id == 1 ? extension1_id : extension2_id, 432 &profile_, mod.extension_id == 1 ? extension1_id : extension2_id,
435 kEventName, kEventName + (mod.extension_id == 1 ? "/1" : "/2"), 433 kEventName, kEventName + (mod.extension_id == 1 ? "/1" : "/2"),
436 request.identifier(), response)); 434 request.identifier(), response));
437 response = NULL; 435 response = NULL;
438 } 436 }
439 } 437 }
440 438
441 // Don't do anything for the onSendHeaders message. 439 // Don't do anything for the onSendHeaders message.
442 ipc_sender_.PushTask(base::Bind(&DoNothing)); 440 ipc_sender_.PushTask(base::Bind(&base::DoNothing));
443 441
444 // Note that we mess up the headers slightly: 442 // Note that we mess up the headers slightly:
445 // request.Start() will first add additional headers (e.g. the User-Agent) 443 // request.Start() will first add additional headers (e.g. the User-Agent)
446 // and then send an event to the extension. When we have prepared our 444 // and then send an event to the extension. When we have prepared our
447 // answers to the onBeforeSendHeaders events above, these headers did not 445 // answers to the onBeforeSendHeaders events above, these headers did not
448 // exists and are therefore not listed in the responses. This makes 446 // exists and are therefore not listed in the responses. This makes
449 // them seem deleted. 447 // them seem deleted.
450 request.Start(); 448 request.Start();
451 MessageLoop::current()->Run(); 449 MessageLoop::current()->Run();
452 450
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 credentials_set = MergeOnAuthRequiredResponses( 1349 credentials_set = MergeOnAuthRequiredResponses(
1352 deltas, &auth3, &conflicting_extensions, &event_log); 1350 deltas, &auth3, &conflicting_extensions, &event_log);
1353 EXPECT_TRUE(credentials_set); 1351 EXPECT_TRUE(credentials_set);
1354 EXPECT_FALSE(auth3.Empty()); 1352 EXPECT_FALSE(auth3.Empty());
1355 EXPECT_EQ(username, auth1.username()); 1353 EXPECT_EQ(username, auth1.username());
1356 EXPECT_EQ(password, auth1.password()); 1354 EXPECT_EQ(password, auth1.password());
1357 EXPECT_EQ(1u, conflicting_extensions.size()); 1355 EXPECT_EQ(1u, conflicting_extensions.size());
1358 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); 1356 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2"));
1359 EXPECT_EQ(3u, event_log.size()); 1357 EXPECT_EQ(3u, event_log.size());
1360 } 1358 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_processes_api.cc ('k') | chrome/browser/extensions/settings/settings_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698