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: | |
16 // testing::Test implementation: | |
17 virtual void SetUp() OVERRIDE { | |
18 settings_.reset(new DataReductionProxySettingsAndroid(NULL, NULL)); | |
19 PrefRegistrySimple* registry = pref_service_.registry(); | |
20 registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); | |
21 registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); | |
22 registry->RegisterInt64Pref( | |
23 prefs::kDailyHttpContentLengthLastUpdateDate, 0L); | |
24 settings_->set_local_state_prefs_for_testing(&pref_service_); | |
25 ListPrefUpdate original_update(&pref_service_, | |
26 prefs::kDailyHttpOriginalContentLength); | |
27 ListPrefUpdate received_update(&pref_service_, | |
28 prefs::kDailyHttpReceivedContentLength); | |
29 for (int64 i = 0; i < spdyproxy::kNumDaysInHistory; i++) { | |
30 original_update->Insert(0, new StringValue(base::Int64ToString(2 * i))); | |
31 received_update->Insert(0, new StringValue(base::Int64ToString(i))); | |
32 } | |
33 last_update_time_ = | |
34 base::Time::Now().LocalMidnight() - base::TimeDelta::FromDays( | |
35 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.
| |
36 pref_service_.SetInt64( | |
37 prefs::kDailyHttpContentLengthLastUpdateDate, | |
38 last_update_time_.ToInternalValue()); | |
39 } | |
40 | |
41 TestingPrefServiceSimple pref_service_; | |
42 scoped_ptr<DataReductionProxySettingsAndroid> settings_; | |
43 base::Time last_update_time_; | |
44 }; | |
45 | |
46 TEST_F(DataReductionProxySettingsAndroidTest, TestBypassRules) { | |
47 // Confirm that the bypass rule functions generate the intended JavaScript | |
48 // code for the Proxy PAC. | |
49 settings_->AddURLPatternToBypass("http://foo.com/*"); | |
50 settings_->AddHostPatternToBypass("bar.com"); | |
51 settings_->AddHostToBypass("127.0.0.1"); | |
52 | |
53 std::string expected[] = { | |
54 "shExpMatch(url, \"http://foo.com/*\")", | |
55 "shExpMatch(host, \"bar.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); | |
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.
| |
63 } | |
64 | |
65 TEST_F(DataReductionProxySettingsAndroidTest, TestStatistics) { | |
66 int64 original_content_length; | |
67 int64 received_content_length; | |
68 int64 last_update_time; | |
69 settings_->GetContentLengths(spdyproxy::kNumDaysInHistory, | |
70 &original_content_length, | |
71 &received_content_length, | |
72 &last_update_time); | |
73 DCHECK_EQ(3540L, original_content_length); | |
74 DCHECK_EQ(1770L, received_content_length); | |
75 DCHECK_EQ(last_update_time_.ToInternalValue(), last_update_time); | |
76 } | |
OLD | NEW |