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

Unified Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc

Issue 23458016: Added probe to determine if data reduction proxy can be used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added initializations Created 7 years, 3 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/spdyproxy/data_reduction_proxy_settings_android.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..23af7ce5346cfe092ad3232e98d703c438bbd440
--- /dev/null
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc
@@ -0,0 +1,82 @@
+// Copyright 2013 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 "base/prefs/pref_registry_simple.h"
+#include "base/prefs/pref_service.h"
+#include "base/prefs/testing_pref_service.h"
+#include "base/strings/string_number_conversions.h"
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/common/pref_names.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class DataReductionProxySettingsAndroidTest : public testing::Test {
+ protected:
+ virtual void SetUp() OVERRIDE {
+ settings_.reset(new DataReductionProxySettingsAndroid(NULL, NULL));
+ PrefRegistrySimple* registry = pref_service_.registry();
+ registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength);
+ registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength);
+ registry->RegisterInt64Pref(
+ prefs::kDailyHttpContentLengthLastUpdateDate, 0L);
+ settings_->set_local_state(&pref_service_);
+ ListPrefUpdate original_update(&pref_service_,
+ prefs::kDailyHttpOriginalContentLength);
+ ListPrefUpdate received_update(&pref_service_,
+ prefs::kDailyHttpReceivedContentLength);
+ for (int64 i = 0; i < 60; i++) {
+ original_update->Insert(0, new StringValue(base::Int64ToString(2 * i)));
+ received_update->Insert(0, new StringValue(base::Int64ToString(i)));
+ }
+ last_update_time_ =
+ base::Time::Now().LocalMidnight() -base::TimeDelta::FromDays(60);
nyquist 2013/09/05 14:53:44 Nit; space after -
bengr 2013/09/05 18:18:47 Done.
+ pref_service_.SetInt64(
+ prefs::kDailyHttpContentLengthLastUpdateDate,
+ last_update_time_.ToInternalValue());
+ }
+
+ TestingPrefServiceSimple pref_service_;
+ scoped_ptr<DataReductionProxySettingsAndroid> settings_;
+ base::Time last_update_time_;
+};
+
+TEST_F(DataReductionProxySettingsAndroidTest, TestBypassRules) {
+ // Confirm that the bypass rule functions generate the intended JavaScript
+ // code for the Proxy PAC.
+ settings_->AddURLPatternToBypass("http://foo.com/*");
+ settings_->AddHostPatternToBypass("bar.com");
+ settings_->AddURLSubstringToBypass("http://www.google.com/", 0, 22);
+ settings_->AddHostToBypass("127.0.0.1");
+
+ std::string expected[] = {
+ "shExpMatch(url, \"http://foo.com/*\")",
+ "shExpMatch(host, \"bar.com\")",
+ "url.substring(0, 22) == \"http://www.google.com/\"",
+ "host == \"127.0.0.1\""
+ };
+
+ int i = 0;
+ for (std::vector<std::string>::iterator it = settings_->bypass_rules_.begin();
+ it != settings_->bypass_rules_.end(); ++it)
+ DCHECK_EQ(expected[i++], *it);
+}
+
+TEST_F(DataReductionProxySettingsAndroidTest, TestFormatURL) {
+ std::string url = "https://www.google.com:123/";
+ settings_->RemoveSchemeAndTrailingSlash(&url);
+ DCHECK_EQ("www.google.com:123", url);
+}
+
+TEST_F(DataReductionProxySettingsAndroidTest, TestStatistics) {
+ int64 original_content_length;
+ int64 received_content_length;
+ int64 last_update_time;
+ settings_->GetContentLengths(60,
+ &original_content_length,
+ &received_content_length,
+ &last_update_time);
+ DCHECK_EQ(3540L, original_content_length);
+ DCHECK_EQ(1770L, received_content_length);
+ DCHECK_EQ(last_update_time_.ToInternalValue(), last_update_time);
+}
« no previous file with comments | « chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698