Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc

Issue 23458016: Added probe to determine if data reduction proxy can be used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from mmenke Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_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);
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);
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(spdyproxy::kNumDaysInHistory,
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698