| 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..f4de980b6db9fa76e3e17e57fbe5ece61fb3e24b
|
| --- /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:
|
| + // testing::Test implementation:
|
| + 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_for_testing(&pref_service_);
|
| + ListPrefUpdate original_update(&pref_service_,
|
| + prefs::kDailyHttpOriginalContentLength);
|
| + ListPrefUpdate received_update(&pref_service_,
|
| + prefs::kDailyHttpReceivedContentLength);
|
| + for (int64 i = 0; i < spdyproxy::kNumDaysInHistory; 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(
|
| + spdyproxy::kNumDaysInHistory);
|
| + 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_->AddHostToBypass("127.0.0.1");
|
| +
|
| + std::string expected[] = {
|
| + "shExpMatch(url, \"http://foo.com/*\")",
|
| + "shExpMatch(host, \"bar.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(spdyproxy::kNumDaysInHistory,
|
| + &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);
|
| +}
|
|
|