Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / net / chrome_network_delegate_unittest.cc
index 75144be..0dc2baa 100644 (file)
@@ -9,7 +9,6 @@
 #include "base/message_loop/message_loop.h"
 #include "base/prefs/pref_member.h"
 #include "chrome/browser/content_settings/cookie_settings.h"
-#include "chrome/browser/extensions/event_router_forwarder.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/common/url_constants.h"
 #include "chrome/test/base/testing_pref_service_syncable.h"
 #include "net/url_request/url_request_test_util.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+#if defined(ENABLE_EXTENSIONS)
+#include "chrome/browser/extensions/event_router_forwarder.h"
+#endif
+
+#if defined(ENABLE_EXTENSIONS)
 class ChromeNetworkDelegateTest : public testing::Test {
  protected:
   ChromeNetworkDelegateTest()
       : forwarder_(new extensions::EventRouterForwarder()) {
   }
 
-  virtual void SetUp() OVERRIDE {
+  void SetUp() override {
     never_throttle_requests_original_value_ =
         ChromeNetworkDelegate::g_never_throttle_requests_;
     ChromeNetworkDelegate::g_never_throttle_requests_ = false;
   }
 
-  virtual void TearDown() OVERRIDE {
+  void TearDown() override {
     ChromeNetworkDelegate::g_never_throttle_requests_ =
         never_throttle_requests_original_value_;
   }
@@ -48,22 +52,22 @@ class ChromeNetworkDelegateTest : public testing::Test {
     scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate());
 
     net::TestURLRequestContext context;
-    net::TestURLRequest extension_request(
-        GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, &context);
-    extension_request.set_first_party_for_cookies(
+    scoped_ptr<net::URLRequest> extension_request(context.CreateRequest(
+        GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, NULL));
+    extension_request->set_first_party_for_cookies(
         GURL("chrome-extension://abcdef/bingo.html"));
-    net::TestURLRequest web_page_request(
-        GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, &context);
-    web_page_request.set_first_party_for_cookies(
+    scoped_ptr<net::URLRequest> web_page_request(context.CreateRequest(
+        GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, NULL));
+    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));
+    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));
+    ASSERT_FALSE(delegate->OnCanThrottleRequest(*extension_request));
+    ASSERT_FALSE(delegate->OnCanThrottleRequest(*web_page_request));
 
     // Verify that the flag applies to later instances of the
     // ChromeNetworkDelegate.
@@ -73,8 +77,8 @@ class ChromeNetworkDelegateTest : public testing::Test {
     // 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));
+    ASSERT_FALSE(delegate->OnCanThrottleRequest(*extension_request));
+    ASSERT_FALSE(delegate->OnCanThrottleRequest(*web_page_request));
   }
 
  private:
@@ -88,15 +92,18 @@ class ChromeNetworkDelegateTest : public testing::Test {
 TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) {
   NeverThrottleLogicImpl();
 }
+#endif  // defined(ENABLE_EXTENSIONS)
 
 class ChromeNetworkDelegateSafeSearchTest : public testing::Test {
  public:
   ChromeNetworkDelegateSafeSearchTest()
-      : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
-        forwarder_(new extensions::EventRouterForwarder()) {
+      : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
+#if defined(ENABLE_EXTENSIONS)
+    forwarder_ = new extensions::EventRouterForwarder();
+#endif
   }
 
-  virtual void SetUp() OVERRIDE {
+  void SetUp() override {
     ChromeNetworkDelegate::InitializePrefsOnUIThread(
         &enable_referrers_, NULL, &force_google_safe_search_,
         profile_.GetTestingPrefService());
@@ -105,9 +112,9 @@ class ChromeNetworkDelegateSafeSearchTest : public testing::Test {
  protected:
   scoped_ptr<net::NetworkDelegate> CreateNetworkDelegate() {
     scoped_ptr<ChromeNetworkDelegate> network_delegate(
-        new ChromeNetworkDelegate(forwarder_.get(), &enable_referrers_));
+        new ChromeNetworkDelegate(forwarder(), &enable_referrers_));
     network_delegate->set_force_google_safe_search(&force_google_safe_search_);
-    return network_delegate.PassAs<net::NetworkDelegate>();
+    return network_delegate.Pass();
   }
 
   void SetSafeSearch(bool value) {
@@ -127,18 +134,28 @@ class ChromeNetworkDelegateSafeSearchTest : public testing::Test {
     // Show the URL in the trace so we know where we failed.
     SCOPED_TRACE(url_string);
 
-    net::TestURLRequest request(
-        GURL(url_string), net::DEFAULT_PRIORITY, &delegate_, &context_);
+    scoped_ptr<net::URLRequest> request(context_.CreateRequest(
+        GURL(url_string), net::DEFAULT_PRIORITY, &delegate_, NULL));
 
-    request.Start();
+    request->Start();
     base::MessageLoop::current()->RunUntilIdle();
 
-    EXPECT_EQ(expected_query_parameters, request.url().query());
+    EXPECT_EQ(expected_query_parameters, request->url().query());
   }
 
  private:
+  extensions::EventRouterForwarder* forwarder() {
+#if defined(ENABLE_EXTENSIONS)
+    return forwarder_.get();
+#else
+    return NULL;
+#endif
+  }
+
   content::TestBrowserThreadBundle thread_bundle_;
+#if defined(ENABLE_EXTENSIONS)
   scoped_refptr<extensions::EventRouterForwarder> forwarder_;
+#endif
   TestingProfile profile_;
   BooleanPrefMember enable_referrers_;
   BooleanPrefMember force_google_safe_search_;
@@ -285,7 +302,9 @@ class ChromeNetworkDelegatePrivacyModeTest : public testing::Test {
  public:
   ChromeNetworkDelegatePrivacyModeTest()
       : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
+#if defined(ENABLE_EXTENSIONS)
         forwarder_(new extensions::EventRouterForwarder()),
+#endif
         cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_)
                              .get()),
         kBlockedSite("http://ads.thirdparty.com"),
@@ -293,7 +312,7 @@ class ChromeNetworkDelegatePrivacyModeTest : public testing::Test {
         kFirstPartySite("http://cool.things.com"),
         kBlockedFirstPartySite("http://no.thirdparties.com") {}
 
-  virtual void SetUp() OVERRIDE {
+  void SetUp() override {
     ChromeNetworkDelegate::InitializePrefsOnUIThread(
         &enable_referrers_, NULL, NULL,
         profile_.GetTestingPrefService());
@@ -302,7 +321,7 @@ class ChromeNetworkDelegatePrivacyModeTest : public testing::Test {
  protected:
   scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() {
     scoped_ptr<ChromeNetworkDelegate> network_delegate(
-        new ChromeNetworkDelegate(forwarder_.get(), &enable_referrers_));
+        new ChromeNetworkDelegate(forwarder(), &enable_referrers_));
     network_delegate->set_cookie_settings(cookie_settings_);
     return network_delegate.Pass();
   }
@@ -313,8 +332,18 @@ class ChromeNetworkDelegatePrivacyModeTest : public testing::Test {
   }
 
  protected:
+  extensions::EventRouterForwarder* forwarder() {
+#if defined(ENABLE_EXTENSIONS)
+    return forwarder_.get();
+#else
+    return NULL;
+#endif
+  }
+
   content::TestBrowserThreadBundle thread_bundle_;
+#if defined(ENABLE_EXTENSIONS)
   scoped_refptr<extensions::EventRouterForwarder> forwarder_;
+#endif
   TestingProfile profile_;
   CookieSettings* cookie_settings_;
   BooleanPrefMember enable_referrers_;