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..3de31c80a497bde7e78daed94ee584745abd7a61 |
| --- /dev/null |
| +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc |
| @@ -0,0 +1,76 @@ |
| +// 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_prefs_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); |
|
mmenke
2013/09/10 19:54:06
optional nit: Think this may be clearer (I really
bengr
2013/09/11 22:01:02
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_->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); |
|
mmenke
2013/09/10 19:54:06
With multi-line for statements, should use braces.
mmenke
2013/09/10 19:54:06
This should be EXPECT_EQ, not DCHECK_EQ. Or ASSER
bengr
2013/09/11 22:01:02
Done.
bengr
2013/09/11 22:01:02
Got it. Done.
|
| +} |
| + |
| +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); |
| +} |