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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/net/chrome_network_delegate.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/chrome_network_delegate_unittest.cc
diff --git a/chrome/browser/net/chrome_network_delegate_unittest.cc b/chrome/browser/net/chrome_network_delegate_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..554c6fab6846eca92d833d81e6b9ccbb5fb79f65
--- /dev/null
+++ b/chrome/browser/net/chrome_network_delegate_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/net/chrome_network_delegate.h"
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "chrome/browser/extensions/event_router_forwarder.h"
+#include "chrome/browser/prefs/pref_member.h"
+#include "net/url_request/url_request_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class ChromeNetworkDelegateTest : public testing::Test {
+ protected:
+ ChromeNetworkDelegateTest()
+ : forwarder_(new extensions::EventRouterForwarder()) {
+ }
+
+ virtual void SetUp() OVERRIDE {
+ never_throttle_requests_original_value_ =
+ ChromeNetworkDelegate::g_never_throttle_requests_;
+ ChromeNetworkDelegate::g_never_throttle_requests_ = false;
+ }
+
+ virtual void TearDown() OVERRIDE {
+ ChromeNetworkDelegate::g_never_throttle_requests_ =
+ never_throttle_requests_original_value_;
+ }
+
+ scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() {
+ return scoped_ptr<ChromeNetworkDelegate>(new ChromeNetworkDelegate(
+ forwarder_.get(), NULL, NULL, NULL, NULL, &pref_member_, NULL));
+ }
+
+ // Implementation moved here for access to private bits.
+ void NeverThrottleLogicImpl() {
+ scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate());
+
+ TestURLRequestContext context;
+ TestURLRequest extension_request(
+ GURL("http://example.com/"), NULL, &context);
+ extension_request.set_first_party_for_cookies(
+ GURL("chrome-extension://abcdef/bingo.html"));
+ TestURLRequest web_page_request(
+ GURL("http://example.com/"), NULL, &context);
+ web_page_request.set_first_party_for_cookies(
+ GURL("http://example.com/helloworld.html"));
+
+ ASSERT_TRUE(delegate->OnCanThrottleRequest(extension_request));
+ ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request));
+
+ delegate->NeverThrottleRequests();
+ ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_);
+ ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request));
+ ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request));
+
+ // Verify that the flag applies to later instances of the
+ // ChromeNetworkDelegate.
+ //
+ // We test the side effects of the flag rather than just the flag
+ // itself (which we did above) to help ensure that a changed
+ // implementation would show the same behavior, i.e. all instances
+ // of ChromeNetworkDelegate after the flag is set obey the flag.
+ scoped_ptr<ChromeNetworkDelegate> second_delegate(CreateNetworkDelegate());
+ ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request));
+ ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request));
+ }
+
+ private:
+ bool never_throttle_requests_original_value_;
+ MessageLoopForIO message_loop_;
+
+ scoped_refptr<extensions::EventRouterForwarder> forwarder_;
+ BooleanPrefMember pref_member_;
+};
+
+TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) {
+ NeverThrottleLogicImpl();
+}
« 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