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

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: 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
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..fd717eed87244c0b0c1db78c6ec26e0184e5b326
--- /dev/null
+++ b/chrome/browser/net/chrome_network_delegate_unittest.cc
@@ -0,0 +1,82 @@
+// 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"
+
+namespace {
+
+// Returns a raw pointer that the caller takes ownership of.
+ChromeNetworkDelegate* CreateNetworkDelegate() {
eroman 2012/08/14 16:41:07 [optional]: return a scoped_ptr<ChromeNetworkDeleg
Jói 2012/08/14 22:17:10 Done.
+ scoped_refptr<extensions::EventRouterForwarder> forwarder(
+ new extensions::EventRouterForwarder());
+ BooleanPrefMember pref_member;
+ return new ChromeNetworkDelegate(
+ forwarder.get(), NULL, NULL, NULL, NULL, &pref_member, NULL);
eroman 2012/08/14 16:41:07 Is passing &pref_member safe? That variable will b
Jói 2012/08/14 22:17:10 It's safe for now but the approach you suggested i
+}
+
+} // namespace
+
+class ChromeNetworkDelegateTest : public testing::Test {
+ protected:
+ 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_;
+ }
+
+ // 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_;
+};
+
+TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) {
+ NeverThrottleLogicImpl();
+}

Powered by Google App Engine
This is Rietveld 408576698