Chromium Code Reviews| 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); |
| +} |