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

Side by Side Diff: chrome/browser/net/chrome_network_delegate_unittest.cc

Issue 10828284: Regression test for anti-DDoS bugs in ChromeNetworkDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years, 4 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
« no previous file with comments | « chrome/browser/net/chrome_network_delegate.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/net/chrome_network_delegate.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h"
10 #include "chrome/browser/extensions/event_router_forwarder.h"
11 #include "chrome/browser/prefs/pref_member.h"
12 #include "net/url_request/url_request_test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 class ChromeNetworkDelegateTest : public testing::Test {
16 protected:
17 ChromeNetworkDelegateTest()
18 : forwarder_(new extensions::EventRouterForwarder()) {
19 }
20
21 virtual void SetUp() OVERRIDE {
22 never_throttle_requests_original_value_ =
23 ChromeNetworkDelegate::g_never_throttle_requests_;
24 ChromeNetworkDelegate::g_never_throttle_requests_ = false;
25 }
26
27 virtual void TearDown() OVERRIDE {
28 ChromeNetworkDelegate::g_never_throttle_requests_ =
29 never_throttle_requests_original_value_;
30 }
31
32 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() {
33 return scoped_ptr<ChromeNetworkDelegate>(new ChromeNetworkDelegate(
34 forwarder_.get(), NULL, NULL, NULL, NULL, &pref_member_, NULL));
35 }
36
37 // Implementation moved here for access to private bits.
38 void NeverThrottleLogicImpl() {
39 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate());
40
41 TestURLRequestContext context;
42 TestURLRequest extension_request(
43 GURL("http://example.com/"), NULL, &context);
44 extension_request.set_first_party_for_cookies(
45 GURL("chrome-extension://abcdef/bingo.html"));
46 TestURLRequest web_page_request(
47 GURL("http://example.com/"), NULL, &context);
48 web_page_request.set_first_party_for_cookies(
49 GURL("http://example.com/helloworld.html"));
50
51 ASSERT_TRUE(delegate->OnCanThrottleRequest(extension_request));
52 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request));
53
54 delegate->NeverThrottleRequests();
55 ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_);
56 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request));
57 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request));
58
59 // Verify that the flag applies to later instances of the
60 // ChromeNetworkDelegate.
61 //
62 // We test the side effects of the flag rather than just the flag
63 // itself (which we did above) to help ensure that a changed
64 // implementation would show the same behavior, i.e. all instances
65 // of ChromeNetworkDelegate after the flag is set obey the flag.
66 scoped_ptr<ChromeNetworkDelegate> second_delegate(CreateNetworkDelegate());
67 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request));
68 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request));
69 }
70
71 private:
72 bool never_throttle_requests_original_value_;
73 MessageLoopForIO message_loop_;
74
75 scoped_refptr<extensions::EventRouterForwarder> forwarder_;
76 BooleanPrefMember pref_member_;
77 };
78
79 TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) {
80 NeverThrottleLogicImpl();
81 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_network_delegate.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698