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

Side by Side Diff: components/gcm_driver/gcm_channel_status_request_unittest.cc

Issue 657703002: Revert of [GCM] Start GCMChannelStatusSyncer when GCM is disabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "components/gcm_driver/gcm_channel_status_request.h" 6 #include "components/gcm_driver/gcm_channel_status_request.h"
7 #include "net/url_request/test_url_fetcher_factory.h" 7 #include "net/url_request/test_url_fetcher_factory.h"
8 #include "net/url_request/url_request_test_util.h" 8 #include "net/url_request/url_request_test_util.h"
9 #include "sync/protocol/experiment_status.pb.h" 9 #include "sync/protocol/experiment_status.pb.h"
10 #include "sync/protocol/experiments_specifics.pb.h" 10 #include "sync/protocol/experiments_specifics.pb.h"
(...skipping 11 matching lines...) Expand all
22 NOT_SPECIFIED, 22 NOT_SPECIFIED,
23 GCM_ENABLED, 23 GCM_ENABLED,
24 GCM_DISABLED, 24 GCM_DISABLED,
25 }; 25 };
26 26
27 void StartRequest(); 27 void StartRequest();
28 void SetResponseStatusAndString(net::HttpStatusCode status_code, 28 void SetResponseStatusAndString(net::HttpStatusCode status_code,
29 const std::string& response_body); 29 const std::string& response_body);
30 void SetResponseProtoData(GCMStatus status, int poll_interval_seconds); 30 void SetResponseProtoData(GCMStatus status, int poll_interval_seconds);
31 void CompleteFetch(); 31 void CompleteFetch();
32 void OnRequestCompleted(bool update_received, 32 void OnRequestCompleted(bool enabled, int poll_interval_seconds);
33 bool enabled,
34 int poll_interval_seconds);
35 33
36 scoped_ptr<GCMChannelStatusRequest> request_; 34 scoped_ptr<GCMChannelStatusRequest> request_;
37 base::MessageLoop message_loop_; 35 base::MessageLoop message_loop_;
38 net::TestURLFetcherFactory url_fetcher_factory_; 36 net::TestURLFetcherFactory url_fetcher_factory_;
39 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; 37 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_;
40 bool request_callback_invoked_; 38 bool request_callback_invoked_;
41 bool update_received_;
42 bool enabled_; 39 bool enabled_;
43 int poll_interval_seconds_; 40 int poll_interval_seconds_;
44 }; 41 };
45 42
46 GCMChannelStatusRequestTest::GCMChannelStatusRequestTest() 43 GCMChannelStatusRequestTest::GCMChannelStatusRequestTest()
47 : url_request_context_getter_(new net::TestURLRequestContextGetter( 44 : url_request_context_getter_(new net::TestURLRequestContextGetter(
48 message_loop_.message_loop_proxy())), 45 message_loop_.message_loop_proxy())),
49 request_callback_invoked_(false), 46 request_callback_invoked_(false),
50 update_received_(false),
51 enabled_(true), 47 enabled_(true),
52 poll_interval_seconds_(0) { 48 poll_interval_seconds_(0) {
53 } 49 }
54 50
55 GCMChannelStatusRequestTest::~GCMChannelStatusRequestTest() { 51 GCMChannelStatusRequestTest::~GCMChannelStatusRequestTest() {
56 } 52 }
57 53
58 void GCMChannelStatusRequestTest::StartRequest() { 54 void GCMChannelStatusRequestTest::StartRequest() {
59 request_.reset(new GCMChannelStatusRequest( 55 request_.reset(new GCMChannelStatusRequest(
60 url_request_context_getter_.get(), 56 url_request_context_getter_.get(),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 90 }
95 91
96 void GCMChannelStatusRequestTest::CompleteFetch() { 92 void GCMChannelStatusRequestTest::CompleteFetch() {
97 request_callback_invoked_ = false; 93 request_callback_invoked_ = false;
98 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 94 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
99 ASSERT_TRUE(fetcher); 95 ASSERT_TRUE(fetcher);
100 fetcher->delegate()->OnURLFetchComplete(fetcher); 96 fetcher->delegate()->OnURLFetchComplete(fetcher);
101 } 97 }
102 98
103 void GCMChannelStatusRequestTest::OnRequestCompleted( 99 void GCMChannelStatusRequestTest::OnRequestCompleted(
104 bool update_received, bool enabled, int poll_interval_seconds) { 100 bool enabled, int poll_interval_seconds) {
105 request_callback_invoked_ = true; 101 request_callback_invoked_ = true;
106 update_received_ = update_received;
107 enabled_ = enabled; 102 enabled_ = enabled;
108 poll_interval_seconds_ = poll_interval_seconds; 103 poll_interval_seconds_ = poll_interval_seconds;
109 } 104 }
110 105
111 TEST_F(GCMChannelStatusRequestTest, ResponseHttpStatusNotOK) { 106 TEST_F(GCMChannelStatusRequestTest, ResponseHttpStatusNotOK) {
112 StartRequest(); 107 StartRequest();
113 SetResponseStatusAndString(net::HTTP_UNAUTHORIZED, ""); 108 SetResponseStatusAndString(net::HTTP_UNAUTHORIZED, "");
114 CompleteFetch(); 109 CompleteFetch();
115 110
116 EXPECT_FALSE(request_callback_invoked_); 111 EXPECT_FALSE(request_callback_invoked_);
117 } 112 }
118 113
119 TEST_F(GCMChannelStatusRequestTest, ResponseEmpty) { 114 TEST_F(GCMChannelStatusRequestTest, ResponseEmpty) {
120 StartRequest(); 115 StartRequest();
121 SetResponseStatusAndString(net::HTTP_OK, ""); 116 SetResponseStatusAndString(net::HTTP_OK, "");
122 CompleteFetch(); 117 CompleteFetch();
123 118
124 EXPECT_TRUE(request_callback_invoked_); 119 EXPECT_FALSE(request_callback_invoked_);
125 EXPECT_FALSE(update_received_);
126 } 120 }
127 121
128 TEST_F(GCMChannelStatusRequestTest, ResponseNotInProtoFormat) { 122 TEST_F(GCMChannelStatusRequestTest, ResponseNotInProtoFormat) {
129 StartRequest(); 123 StartRequest();
130 SetResponseStatusAndString(net::HTTP_OK, "foo"); 124 SetResponseStatusAndString(net::HTTP_OK, "foo");
131 CompleteFetch(); 125 CompleteFetch();
132 126
133 EXPECT_FALSE(request_callback_invoked_); 127 EXPECT_FALSE(request_callback_invoked_);
134 } 128 }
135 129
136 TEST_F(GCMChannelStatusRequestTest, ResponseEmptyProtoData) { 130 TEST_F(GCMChannelStatusRequestTest, ResponseEmptyProtoData) {
137 StartRequest(); 131 StartRequest();
138 SetResponseProtoData(NOT_SPECIFIED, 0); 132 SetResponseProtoData(NOT_SPECIFIED, 0);
139 CompleteFetch(); 133 CompleteFetch();
140 134
141 EXPECT_TRUE(request_callback_invoked_); 135 EXPECT_FALSE(request_callback_invoked_);
142 EXPECT_FALSE(update_received_);
143 } 136 }
144 137
145 TEST_F(GCMChannelStatusRequestTest, ResponseWithDisabledStatus) { 138 TEST_F(GCMChannelStatusRequestTest, ResponseWithDisabledStatus) {
146 StartRequest(); 139 StartRequest();
147 SetResponseProtoData(GCM_DISABLED, 0); 140 SetResponseProtoData(GCM_DISABLED, 0);
148 CompleteFetch(); 141 CompleteFetch();
149 142
150 EXPECT_TRUE(request_callback_invoked_); 143 EXPECT_TRUE(request_callback_invoked_);
151 EXPECT_TRUE(update_received_);
152 EXPECT_FALSE(enabled_); 144 EXPECT_FALSE(enabled_);
153 EXPECT_EQ( 145 EXPECT_EQ(
154 GCMChannelStatusRequest::default_poll_interval_seconds(), 146 GCMChannelStatusRequest::default_poll_interval_seconds(),
155 poll_interval_seconds_); 147 poll_interval_seconds_);
156 } 148 }
157 149
158 TEST_F(GCMChannelStatusRequestTest, ResponseWithEnabledStatus) { 150 TEST_F(GCMChannelStatusRequestTest, ResponseWithEnabledStatus) {
159 StartRequest(); 151 StartRequest();
160 SetResponseProtoData(GCM_ENABLED, 0); 152 SetResponseProtoData(GCM_ENABLED, 0);
161 CompleteFetch(); 153 CompleteFetch();
162 154
163 EXPECT_TRUE(request_callback_invoked_); 155 EXPECT_TRUE(request_callback_invoked_);
164 EXPECT_TRUE(update_received_);
165 EXPECT_TRUE(enabled_); 156 EXPECT_TRUE(enabled_);
166 EXPECT_EQ( 157 EXPECT_EQ(
167 GCMChannelStatusRequest::default_poll_interval_seconds(), 158 GCMChannelStatusRequest::default_poll_interval_seconds(),
168 poll_interval_seconds_); 159 poll_interval_seconds_);
169 } 160 }
170 161
171 TEST_F(GCMChannelStatusRequestTest, ResponseWithPollInterval) { 162 TEST_F(GCMChannelStatusRequestTest, ResponseWithPollInterval) {
172 // Setting a poll interval 15 minutes longer than the minimum interval we 163 // Setting a poll interval 15 minutes longer than the minimum interval we
173 // enforce. 164 // enforce.
174 int poll_interval_seconds = 165 int poll_interval_seconds =
175 GCMChannelStatusRequest::min_poll_interval_seconds() + 15 * 60; 166 GCMChannelStatusRequest::min_poll_interval_seconds() + 15 * 60;
176 StartRequest(); 167 StartRequest();
177 SetResponseProtoData(NOT_SPECIFIED, poll_interval_seconds); 168 SetResponseProtoData(NOT_SPECIFIED, poll_interval_seconds);
178 CompleteFetch(); 169 CompleteFetch();
179 170
180 EXPECT_TRUE(request_callback_invoked_); 171 EXPECT_TRUE(request_callback_invoked_);
181 EXPECT_TRUE(update_received_);
182 EXPECT_TRUE(enabled_); 172 EXPECT_TRUE(enabled_);
183 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_); 173 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_);
184 } 174 }
185 175
186 TEST_F(GCMChannelStatusRequestTest, ResponseWithShortPollInterval) { 176 TEST_F(GCMChannelStatusRequestTest, ResponseWithShortPollInterval) {
187 // Setting a poll interval 15 minutes shorter than the minimum interval we 177 // Setting a poll interval 15 minutes shorter than the minimum interval we
188 // enforce. 178 // enforce.
189 int poll_interval_seconds = 179 int poll_interval_seconds =
190 GCMChannelStatusRequest::min_poll_interval_seconds() - 15 * 60; 180 GCMChannelStatusRequest::min_poll_interval_seconds() - 15 * 60;
191 StartRequest(); 181 StartRequest();
192 SetResponseProtoData(NOT_SPECIFIED, poll_interval_seconds); 182 SetResponseProtoData(NOT_SPECIFIED, poll_interval_seconds);
193 CompleteFetch(); 183 CompleteFetch();
194 184
195 EXPECT_TRUE(request_callback_invoked_); 185 EXPECT_TRUE(request_callback_invoked_);
196 EXPECT_TRUE(update_received_);
197 EXPECT_TRUE(enabled_); 186 EXPECT_TRUE(enabled_);
198 EXPECT_EQ(GCMChannelStatusRequest::min_poll_interval_seconds(), 187 EXPECT_EQ(GCMChannelStatusRequest::min_poll_interval_seconds(),
199 poll_interval_seconds_); 188 poll_interval_seconds_);
200 } 189 }
201 190
202 TEST_F(GCMChannelStatusRequestTest, ResponseWithDisabledStatusAndPollInterval) { 191 TEST_F(GCMChannelStatusRequestTest, ResponseWithDisabledStatusAndPollInterval) {
203 int poll_interval_seconds = 192 int poll_interval_seconds =
204 GCMChannelStatusRequest::min_poll_interval_seconds() + 15 * 60; 193 GCMChannelStatusRequest::min_poll_interval_seconds() + 15 * 60;
205 StartRequest(); 194 StartRequest();
206 SetResponseProtoData(GCM_DISABLED, poll_interval_seconds); 195 SetResponseProtoData(GCM_DISABLED, poll_interval_seconds);
207 CompleteFetch(); 196 CompleteFetch();
208 197
209 EXPECT_TRUE(request_callback_invoked_); 198 EXPECT_TRUE(request_callback_invoked_);
210 EXPECT_TRUE(update_received_);
211 EXPECT_FALSE(enabled_); 199 EXPECT_FALSE(enabled_);
212 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_); 200 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_);
213 } 201 }
214 202
215 } // namespace gcm 203 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_channel_status_request.cc ('k') | components/gcm_driver/gcm_channel_status_syncer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698