Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/prefs/pref_registry_simple.h" | |
| 6 #include "base/prefs/pref_service.h" | |
| 7 #include "base/prefs/testing_pref_service.h" | |
| 8 #include "base/strings/string_number_conversions.h" | |
| 9 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h" | |
| 10 #include "chrome/browser/prefs/scoped_user_pref_update.h" | |
| 11 #include "chrome/common/pref_names.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 class DataReductionProxySettingsAndroidTest : public testing::Test { | |
| 15 protected: | |
|
mmenke
2013/09/09 15:40:05
nit: "testing::Test implementation:" (Comment is
bengr
2013/09/10 00:56:09
Done.
| |
| 16 virtual void SetUp() OVERRIDE { | |
| 17 settings_.reset(new DataReductionProxySettingsAndroid(NULL, NULL)); | |
| 18 PrefRegistrySimple* registry = pref_service_.registry(); | |
| 19 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); | |
| 20 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); | |
| 21 registry->RegisterInt64Pref( | |
| 22 prefs::kDailyHttpContentLengthLastUpdateDate, 0L); | |
| 23 settings_->set_local_state(&pref_service_); | |
| 24 ListPrefUpdate original_update(&pref_service_, | |
| 25 prefs::kDailyHttpOriginalContentLength); | |
| 26 ListPrefUpdate received_update(&pref_service_, | |
| 27 prefs::kDailyHttpReceivedContentLength); | |
| 28 for (int64 i = 0; i < 60; i++) { | |
| 29 original_update->Insert(0, new StringValue(base::Int64ToString(2 * i))); | |
| 30 received_update->Insert(0, new StringValue(base::Int64ToString(i))); | |
| 31 } | |
| 32 last_update_time_ = | |
| 33 base::Time::Now().LocalMidnight() - base::TimeDelta::FromDays(60); | |
| 34 pref_service_.SetInt64( | |
| 35 prefs::kDailyHttpContentLengthLastUpdateDate, | |
| 36 last_update_time_.ToInternalValue()); | |
| 37 } | |
| 38 | |
| 39 TestingPrefServiceSimple pref_service_; | |
| 40 scoped_ptr<DataReductionProxySettingsAndroid> settings_; | |
| 41 base::Time last_update_time_; | |
| 42 }; | |
| 43 | |
| 44 TEST_F(DataReductionProxySettingsAndroidTest, TestBypassRules) { | |
| 45 // Confirm that the bypass rule functions generate the intended JavaScript | |
| 46 // code for the Proxy PAC. | |
| 47 settings_->AddURLPatternToBypass("http://foo.com/*"); | |
| 48 settings_->AddHostPatternToBypass("bar.com"); | |
| 49 settings_->AddURLSubstringToBypass("http://www.google.com/", 0, 22); | |
| 50 settings_->AddHostToBypass("127.0.0.1"); | |
| 51 | |
| 52 std::string expected[] = { | |
| 53 "shExpMatch(url, \"http://foo.com/*\")", | |
| 54 "shExpMatch(host, \"bar.com\")", | |
| 55 "url.substring(0, 22) == \"http://www.google.com/\"", | |
| 56 "host == \"127.0.0.1\"" | |
| 57 }; | |
| 58 | |
| 59 int i = 0; | |
| 60 for (std::vector<std::string>::iterator it = settings_->bypass_rules_.begin(); | |
| 61 it != settings_->bypass_rules_.end(); ++it) | |
| 62 DCHECK_EQ(expected[i++], *it); | |
| 63 } | |
| 64 | |
| 65 TEST_F(DataReductionProxySettingsAndroidTest, TestFormatURL) { | |
| 66 std::string url = "https://www.google.com:123/"; | |
| 67 settings_->RemoveSchemeAndTrailingSlash(&url); | |
| 68 DCHECK_EQ("www.google.com:123", url); | |
| 69 } | |
| 70 | |
| 71 TEST_F(DataReductionProxySettingsAndroidTest, TestStatistics) { | |
| 72 int64 original_content_length; | |
| 73 int64 received_content_length; | |
| 74 int64 last_update_time; | |
| 75 settings_->GetContentLengths(60, | |
| 76 &original_content_length, | |
| 77 &received_content_length, | |
| 78 &last_update_time); | |
| 79 DCHECK_EQ(3540L, original_content_length); | |
| 80 DCHECK_EQ(1770L, received_content_length); | |
| 81 DCHECK_EQ(last_update_time_.ToInternalValue(), last_update_time); | |
| 82 } | |
| OLD | NEW |