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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc

Issue 412143009: Moved data reduction proxy initialization logic to ProfileImplIOData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 6 years, 4 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
« no previous file with comments | « components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h" 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta ts.h"
6 6
7 #include "base/bind.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "net/base/request_priority.h" 9 #include "net/base/request_priority.h"
9 #include "net/url_request/url_request.h" 10 #include "net/url_request/url_request.h"
10 #include "net/url_request/url_request_status.h" 11 #include "net/url_request/url_request_status.h"
11 #include "net/url_request/url_request_test_util.h" 12 #include "net/url_request/url_request_test_util.h"
12 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 using base::MessageLoop; 16 using base::MessageLoop;
16 using base::MessageLoopProxy; 17 using base::MessageLoopProxy;
(...skipping 21 matching lines...) Expand all
38 39
39 } // namespace 40 } // namespace
40 41
41 namespace data_reduction_proxy { 42 namespace data_reduction_proxy {
42 43
43 class DataReductionProxyUsageStatsTest : public testing::Test { 44 class DataReductionProxyUsageStatsTest : public testing::Test {
44 public: 45 public:
45 DataReductionProxyUsageStatsTest() 46 DataReductionProxyUsageStatsTest()
46 : loop_proxy_(MessageLoopProxy::current().get()), 47 : loop_proxy_(MessageLoopProxy::current().get()),
47 context_(true), 48 context_(true),
48 mock_url_request_(GURL(), net::IDLE, &delegate_, &context_) { 49 mock_url_request_(GURL(), net::IDLE, &delegate_, &context_),
50 unavailable_(false) {
49 context_.Init(); 51 context_.Init();
50 } 52 }
53
54 void NotifyUnavailable(bool unavailable) {
55 unavailable_ = unavailable;
56 }
57
51 // Required for MessageLoopProxy::current(). 58 // Required for MessageLoopProxy::current().
52 base::MessageLoopForUI loop_; 59 base::MessageLoopForUI loop_;
53 MessageLoopProxy* loop_proxy_; 60 MessageLoopProxy* loop_proxy_;
54 61
55 protected: 62 protected:
56 TestURLRequestContext context_; 63 TestURLRequestContext context_;
57 TestDelegate delegate_; 64 TestDelegate delegate_;
58 DataReductionProxyParamsMock mock_params_; 65 DataReductionProxyParamsMock mock_params_;
59 URLRequest mock_url_request_; 66 URLRequest mock_url_request_;
67 bool unavailable_;
60 }; 68 };
61 69
62 TEST_F(DataReductionProxyUsageStatsTest, isDataReductionProxyUnreachable) { 70 TEST_F(DataReductionProxyUsageStatsTest, IsDataReductionProxyUnreachable) {
63 struct TestCase { 71 struct TestCase {
64 bool is_proxy_eligible; 72 bool is_proxy_eligible;
65 bool was_proxy_used; 73 bool was_proxy_used;
66 bool is_unreachable; 74 bool is_unreachable;
67 }; 75 };
68 const TestCase test_cases[] = { 76 const TestCase test_cases[] = {
69 { 77 {
70 false, 78 false,
71 false, 79 false,
72 false 80 false
(...skipping 13 matching lines...) Expand all
86 TestCase test_case = test_cases[i]; 94 TestCase test_case = test_cases[i];
87 95
88 EXPECT_CALL(mock_params_, IsDataReductionProxyEligible(&mock_url_request_)) 96 EXPECT_CALL(mock_params_, IsDataReductionProxyEligible(&mock_url_request_))
89 .WillRepeatedly(Return(test_case.is_proxy_eligible)); 97 .WillRepeatedly(Return(test_case.is_proxy_eligible));
90 EXPECT_CALL(mock_params_, 98 EXPECT_CALL(mock_params_,
91 WasDataReductionProxyUsed(&mock_url_request_, NULL)) 99 WasDataReductionProxyUsed(&mock_url_request_, NULL))
92 .WillRepeatedly(Return(test_case.was_proxy_used)); 100 .WillRepeatedly(Return(test_case.was_proxy_used));
93 101
94 scoped_ptr<DataReductionProxyUsageStats> usage_stats( 102 scoped_ptr<DataReductionProxyUsageStats> usage_stats(
95 new DataReductionProxyUsageStats( 103 new DataReductionProxyUsageStats(
96 &mock_params_, loop_proxy_, loop_proxy_)); 104 &mock_params_, loop_proxy_));
105 usage_stats->set_unavailable_callback(
106 base::Bind(&DataReductionProxyUsageStatsTest::NotifyUnavailable,
107 base::Unretained(this)));
97 108
98 usage_stats->OnUrlRequestCompleted(&mock_url_request_, false); 109 usage_stats->OnUrlRequestCompleted(&mock_url_request_, false);
99 MessageLoop::current()->RunUntilIdle(); 110 MessageLoop::current()->RunUntilIdle();
100 111
101 EXPECT_EQ(test_case.is_unreachable, 112 EXPECT_EQ(test_case.is_unreachable, unavailable_);
102 usage_stats->isDataReductionProxyUnreachable());
103 } 113 }
104 } 114 }
105 115
106 } // namespace data_reduction_proxy 116 } // namespace data_reduction_proxy
OLDNEW
« no previous file with comments | « components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698