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

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

Issue 561943002: Reland: Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix try jobs Created 6 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
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/gcm_driver/gcm_driver_desktop.h" 5 #include "components/gcm_driver/gcm_driver_desktop.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_loop_proxy.h" 12 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/prefs/pref_registry_simple.h"
15 #include "base/prefs/testing_pref_service.h"
14 #include "base/run_loop.h" 16 #include "base/run_loop.h"
15 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
16 #include "base/test/test_simple_task_runner.h" 18 #include "base/test/test_simple_task_runner.h"
17 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
18 #include "components/gcm_driver/fake_gcm_app_handler.h" 20 #include "components/gcm_driver/fake_gcm_app_handler.h"
19 #include "components/gcm_driver/fake_gcm_client.h" 21 #include "components/gcm_driver/fake_gcm_client.h"
20 #include "components/gcm_driver/fake_gcm_client_factory.h" 22 #include "components/gcm_driver/fake_gcm_client_factory.h"
21 #include "components/gcm_driver/gcm_app_handler.h" 23 #include "components/gcm_driver/gcm_app_handler.h"
24 #include "components/gcm_driver/gcm_channel_status_request.h"
25 #include "components/gcm_driver/gcm_channel_status_syncer.h"
22 #include "components/gcm_driver/gcm_client_factory.h" 26 #include "components/gcm_driver/gcm_client_factory.h"
23 #include "components/gcm_driver/gcm_connection_observer.h" 27 #include "components/gcm_driver/gcm_connection_observer.h"
28 #include "components/gcm_driver/proto/gcm_channel_status.pb.h"
29 #include "net/url_request/test_url_fetcher_factory.h"
30 #include "net/url_request/url_fetcher_delegate.h"
24 #include "net/url_request/url_request_context_getter.h" 31 #include "net/url_request/url_request_context_getter.h"
25 #include "net/url_request/url_request_test_util.h" 32 #include "net/url_request/url_request_test_util.h"
26 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
27 34
28 namespace gcm { 35 namespace gcm {
29 36
30 namespace { 37 namespace {
31 38
32 const char kTestAccountID1[] = "user1@example.com"; 39 const char kTestAccountID1[] = "user1@example.com";
33 const char kTestAccountID2[] = "user2@example.com"; 40 const char kTestAccountID2[] = "user2@example.com";
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 WAIT 97 WAIT
91 }; 98 };
92 99
93 GCMDriverTest(); 100 GCMDriverTest();
94 virtual ~GCMDriverTest(); 101 virtual ~GCMDriverTest();
95 102
96 // testing::Test: 103 // testing::Test:
97 virtual void SetUp() OVERRIDE; 104 virtual void SetUp() OVERRIDE;
98 virtual void TearDown() OVERRIDE; 105 virtual void TearDown() OVERRIDE;
99 106
100 GCMDriver* driver() { return driver_.get(); } 107 GCMDriverDesktop* driver() { return driver_.get(); }
101 FakeGCMAppHandler* gcm_app_handler() { return gcm_app_handler_.get(); } 108 FakeGCMAppHandler* gcm_app_handler() { return gcm_app_handler_.get(); }
102 FakeGCMConnectionObserver* gcm_connection_observer() { 109 FakeGCMConnectionObserver* gcm_connection_observer() {
103 return gcm_connection_observer_.get(); 110 return gcm_connection_observer_.get();
104 } 111 }
105 const std::string& registration_id() const { return registration_id_; } 112 const std::string& registration_id() const { return registration_id_; }
106 GCMClient::Result registration_result() const { return registration_result_; } 113 GCMClient::Result registration_result() const { return registration_result_; }
107 const std::string& send_message_id() const { return send_message_id_; } 114 const std::string& send_message_id() const { return send_message_id_; }
108 GCMClient::Result send_result() const { return send_result_; } 115 GCMClient::Result send_result() const { return send_result_; }
109 GCMClient::Result unregistration_result() const { 116 GCMClient::Result unregistration_result() const {
110 return unregistration_result_; 117 return unregistration_result_;
111 } 118 }
112 119
113 void PumpIOLoop(); 120 void PumpIOLoop();
114 121
115 void ClearResults(); 122 void ClearResults();
116 123
117 bool HasAppHandlers() const; 124 bool HasAppHandlers() const;
118 FakeGCMClient* GetGCMClient(); 125 FakeGCMClient* GetGCMClient();
119 126
120 void CreateDriver(FakeGCMClient::StartMode gcm_client_start_mode); 127 void CreateDriver(FakeGCMClient::StartMode gcm_client_start_mode);
128 void ShutdownDriver();
121 void AddAppHandlers(); 129 void AddAppHandlers();
122 void RemoveAppHandlers(); 130 void RemoveAppHandlers();
123 131
124 void SignIn(const std::string& account_id); 132 void SignIn(const std::string& account_id);
125 void SignOut(); 133 void SignOut();
126 134
127 void Register(const std::string& app_id, 135 void Register(const std::string& app_id,
128 const std::vector<std::string>& sender_ids, 136 const std::vector<std::string>& sender_ids,
129 WaitToFinish wait_to_finish); 137 WaitToFinish wait_to_finish);
130 void Send(const std::string& app_id, 138 void Send(const std::string& app_id,
131 const std::string& receiver_id, 139 const std::string& receiver_id,
132 const GCMClient::OutgoingMessage& message, 140 const GCMClient::OutgoingMessage& message,
133 WaitToFinish wait_to_finish); 141 WaitToFinish wait_to_finish);
134 void Unregister(const std::string& app_id, WaitToFinish wait_to_finish); 142 void Unregister(const std::string& app_id, WaitToFinish wait_to_finish);
135 143
136 void WaitForAsyncOperation(); 144 void WaitForAsyncOperation();
137 145
138 private: 146 private:
139 void RegisterCompleted(const std::string& registration_id, 147 void RegisterCompleted(const std::string& registration_id,
140 GCMClient::Result result); 148 GCMClient::Result result);
141 void SendCompleted(const std::string& message_id, GCMClient::Result result); 149 void SendCompleted(const std::string& message_id, GCMClient::Result result);
142 void UnregisterCompleted(GCMClient::Result result); 150 void UnregisterCompleted(GCMClient::Result result);
143 151
144 base::ScopedTempDir temp_dir_; 152 base::ScopedTempDir temp_dir_;
153 TestingPrefServiceSimple prefs_;
145 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 154 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
146 base::MessageLoopForUI message_loop_; 155 base::MessageLoopForUI message_loop_;
147 base::Thread io_thread_; 156 base::Thread io_thread_;
148 base::FieldTrialList field_trial_list_; 157 base::FieldTrialList field_trial_list_;
149 scoped_ptr<GCMDriver> driver_; 158 scoped_ptr<GCMDriverDesktop> driver_;
150 scoped_ptr<FakeGCMAppHandler> gcm_app_handler_; 159 scoped_ptr<FakeGCMAppHandler> gcm_app_handler_;
151 scoped_ptr<FakeGCMConnectionObserver> gcm_connection_observer_; 160 scoped_ptr<FakeGCMConnectionObserver> gcm_connection_observer_;
152 161
153 base::Closure async_operation_completed_callback_; 162 base::Closure async_operation_completed_callback_;
154 163
155 std::string registration_id_; 164 std::string registration_id_;
156 GCMClient::Result registration_result_; 165 GCMClient::Result registration_result_;
157 std::string send_message_id_; 166 std::string send_message_id_;
158 GCMClient::Result send_result_; 167 GCMClient::Result send_result_;
159 GCMClient::Result unregistration_result_; 168 GCMClient::Result unregistration_result_;
160 169
161 DISALLOW_COPY_AND_ASSIGN(GCMDriverTest); 170 DISALLOW_COPY_AND_ASSIGN(GCMDriverTest);
162 }; 171 };
163 172
164 GCMDriverTest::GCMDriverTest() 173 GCMDriverTest::GCMDriverTest()
165 : task_runner_(new base::TestSimpleTaskRunner()), 174 : task_runner_(new base::TestSimpleTaskRunner()),
166 io_thread_("IOThread"), 175 io_thread_("IOThread"),
167 field_trial_list_(NULL), 176 field_trial_list_(NULL),
168 registration_result_(GCMClient::UNKNOWN_ERROR), 177 registration_result_(GCMClient::UNKNOWN_ERROR),
169 send_result_(GCMClient::UNKNOWN_ERROR), 178 send_result_(GCMClient::UNKNOWN_ERROR),
170 unregistration_result_(GCMClient::UNKNOWN_ERROR) { 179 unregistration_result_(GCMClient::UNKNOWN_ERROR) {
171 } 180 }
172 181
173 GCMDriverTest::~GCMDriverTest() { 182 GCMDriverTest::~GCMDriverTest() {
174 } 183 }
175 184
176 void GCMDriverTest::SetUp() { 185 void GCMDriverTest::SetUp() {
186 GCMChannelStatusSyncer::RegisterPrefs(prefs_.registry());
177 io_thread_.Start(); 187 io_thread_.Start();
178 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 188 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
179 } 189 }
180 190
181 void GCMDriverTest::TearDown() { 191 void GCMDriverTest::TearDown() {
182 if (!driver_) 192 if (!driver_)
183 return; 193 return;
184 194
185 if (gcm_connection_observer_.get()) 195 ShutdownDriver();
186 driver_->RemoveConnectionObserver(gcm_connection_observer_.get());
187 driver_->Shutdown();
188 driver_.reset(); 196 driver_.reset();
189 PumpIOLoop(); 197 PumpIOLoop();
190 198
191 io_thread_.Stop(); 199 io_thread_.Stop();
192 } 200 }
193 201
194 void GCMDriverTest::PumpIOLoop() { 202 void GCMDriverTest::PumpIOLoop() {
195 base::RunLoop run_loop; 203 base::RunLoop run_loop;
196 io_thread_.message_loop_proxy()->PostTaskAndReply( 204 io_thread_.message_loop_proxy()->PostTaskAndReply(
197 FROM_HERE, 205 FROM_HERE,
(...skipping 24 matching lines...) Expand all
222 FakeGCMClient::StartMode gcm_client_start_mode) { 230 FakeGCMClient::StartMode gcm_client_start_mode) {
223 scoped_refptr<net::URLRequestContextGetter> request_context = 231 scoped_refptr<net::URLRequestContextGetter> request_context =
224 new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy()); 232 new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy());
225 // TODO(johnme): Need equivalent test coverage of GCMDriverAndroid. 233 // TODO(johnme): Need equivalent test coverage of GCMDriverAndroid.
226 driver_.reset(new GCMDriverDesktop( 234 driver_.reset(new GCMDriverDesktop(
227 scoped_ptr<GCMClientFactory>(new FakeGCMClientFactory( 235 scoped_ptr<GCMClientFactory>(new FakeGCMClientFactory(
228 gcm_client_start_mode, 236 gcm_client_start_mode,
229 base::MessageLoopProxy::current(), 237 base::MessageLoopProxy::current(),
230 io_thread_.message_loop_proxy())).Pass(), 238 io_thread_.message_loop_proxy())).Pass(),
231 GCMClient::ChromeBuildInfo(), 239 GCMClient::ChromeBuildInfo(),
240 &prefs_,
232 temp_dir_.path(), 241 temp_dir_.path(),
233 request_context, 242 request_context,
234 base::MessageLoopProxy::current(), 243 base::MessageLoopProxy::current(),
235 io_thread_.message_loop_proxy(), 244 io_thread_.message_loop_proxy(),
236 task_runner_)); 245 task_runner_));
237 246
238 gcm_app_handler_.reset(new FakeGCMAppHandler); 247 gcm_app_handler_.reset(new FakeGCMAppHandler);
239 gcm_connection_observer_.reset(new FakeGCMConnectionObserver); 248 gcm_connection_observer_.reset(new FakeGCMConnectionObserver);
240 249
241 driver_->AddConnectionObserver(gcm_connection_observer_.get()); 250 driver_->AddConnectionObserver(gcm_connection_observer_.get());
242 } 251 }
243 252
253 void GCMDriverTest::ShutdownDriver() {
254 if (gcm_connection_observer())
255 driver()->RemoveConnectionObserver(gcm_connection_observer());
256 driver()->Shutdown();
257 }
258
244 void GCMDriverTest::AddAppHandlers() { 259 void GCMDriverTest::AddAppHandlers() {
245 driver_->AddAppHandler(kTestAppID1, gcm_app_handler_.get()); 260 driver_->AddAppHandler(kTestAppID1, gcm_app_handler_.get());
246 driver_->AddAppHandler(kTestAppID2, gcm_app_handler_.get()); 261 driver_->AddAppHandler(kTestAppID2, gcm_app_handler_.get());
247 } 262 }
248 263
249 void GCMDriverTest::RemoveAppHandlers() { 264 void GCMDriverTest::RemoveAppHandlers() {
250 driver_->RemoveAppHandler(kTestAppID1); 265 driver_->RemoveAppHandler(kTestAppID1);
251 driver_->RemoveAppHandler(kTestAppID2); 266 driver_->RemoveAppHandler(kTestAppID2);
252 } 267 }
253 268
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 EXPECT_TRUE(gcm_connection_observer()->connected()); 381 EXPECT_TRUE(gcm_connection_observer()->connected());
367 } 382 }
368 383
369 TEST_F(GCMDriverTest, Shutdown) { 384 TEST_F(GCMDriverTest, Shutdown) {
370 CreateDriver(FakeGCMClient::NO_DELAY_START); 385 CreateDriver(FakeGCMClient::NO_DELAY_START);
371 EXPECT_FALSE(HasAppHandlers()); 386 EXPECT_FALSE(HasAppHandlers());
372 387
373 AddAppHandlers(); 388 AddAppHandlers();
374 EXPECT_TRUE(HasAppHandlers()); 389 EXPECT_TRUE(HasAppHandlers());
375 390
376 driver()->Shutdown(); 391 ShutdownDriver();
377 EXPECT_FALSE(HasAppHandlers()); 392 EXPECT_FALSE(HasAppHandlers());
378 EXPECT_FALSE(driver()->IsConnected()); 393 EXPECT_FALSE(driver()->IsConnected());
379 EXPECT_FALSE(gcm_connection_observer()->connected()); 394 EXPECT_FALSE(gcm_connection_observer()->connected());
380 } 395 }
381 396
382 TEST_F(GCMDriverTest, SignInAndSignOutOnGCMEnabled) { 397 TEST_F(GCMDriverTest, SignInAndSignOutOnGCMEnabled) {
383 // By default, GCM is enabled. 398 // By default, GCM is enabled.
384 CreateDriver(FakeGCMClient::NO_DELAY_START); 399 CreateDriver(FakeGCMClient::NO_DELAY_START);
385 AddAppHandlers(); 400 AddAppHandlers();
386 401
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } 936 }
922 937
923 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { 938 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) {
924 GetGCMClient()->DeleteMessages(kTestAppID1); 939 GetGCMClient()->DeleteMessages(kTestAppID1);
925 gcm_app_handler()->WaitForNotification(); 940 gcm_app_handler()->WaitForNotification();
926 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, 941 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT,
927 gcm_app_handler()->received_event()); 942 gcm_app_handler()->received_event());
928 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); 943 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id());
929 } 944 }
930 945
946 // Tests a single instance of GCMDriver.
947 class GCMChannelStatusSyncerTest : public GCMDriverTest {
948 public:
949 GCMChannelStatusSyncerTest();
950 virtual ~GCMChannelStatusSyncerTest();
951
952 // testing::Test:
953 virtual void SetUp() OVERRIDE;
954
955 void CompleteGCMChannelStatusRequest(bool enabled, int poll_interval_seconds);
956 bool CompareDelaySeconds(bool expected_delay_seconds,
957 bool actual_delay_seconds);
958
959 GCMChannelStatusSyncer* syncer() {
960 return driver()->gcm_channel_status_syncer_for_testing();
961 }
962
963 private:
964 net::TestURLFetcherFactory url_fetcher_factory_;
965
966 DISALLOW_COPY_AND_ASSIGN(GCMChannelStatusSyncerTest);
967 };
968
969 GCMChannelStatusSyncerTest::GCMChannelStatusSyncerTest() {
970 }
971
972 GCMChannelStatusSyncerTest::~GCMChannelStatusSyncerTest() {
973 }
974
975 void GCMChannelStatusSyncerTest::SetUp() {
976 GCMDriverTest::SetUp();
977
978 // Turn on all-user support.
979 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled"));
980 }
981
982 void GCMChannelStatusSyncerTest::CompleteGCMChannelStatusRequest(
983 bool enabled, int poll_interval_seconds) {
984 gcm_proto::ExperimentStatusResponse response_proto;
985 response_proto.mutable_gcm_channel()->set_enabled(enabled);
986
987 if (poll_interval_seconds)
988 response_proto.set_poll_interval_seconds(poll_interval_seconds);
989
990 std::string response_string;
991 response_proto.SerializeToString(&response_string);
992
993 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
994 ASSERT_TRUE(fetcher);
995 fetcher->set_response_code(net::HTTP_OK);
996 fetcher->SetResponseString(response_string);
997 fetcher->delegate()->OnURLFetchComplete(fetcher);
998 }
999
1000 bool GCMChannelStatusSyncerTest::CompareDelaySeconds(
1001 bool expected_delay_seconds, bool actual_delay_seconds) {
1002 // Most of time, the actual delay should not be smaller than the expected
1003 // delay.
1004 if (actual_delay_seconds >= expected_delay_seconds)
1005 return true;
1006 // It is also OK that the actual delay is a bit smaller than the expected
1007 // delay in case that the test runs slowly.
1008 return expected_delay_seconds - actual_delay_seconds < 30;
1009 }
1010
1011 TEST_F(GCMChannelStatusSyncerTest, DisableAndEnable) {
1012 // Create GCMDriver first. GCM is not started.
1013 CreateDriver(FakeGCMClient::NO_DELAY_START);
1014 EXPECT_FALSE(driver()->IsStarted());
1015
1016 // By default, GCM is enabled.
1017 EXPECT_TRUE(driver()->gcm_enabled());
1018 EXPECT_TRUE(syncer()->gcm_enabled());
1019
1020 // Remove delay such that the request could be executed immediately.
1021 syncer()->set_delay_removed_for_testing(true);
1022
1023 // GCM will be started after app handler is added.
1024 AddAppHandlers();
1025 EXPECT_TRUE(driver()->IsStarted());
1026
1027 // GCM is still enabled at this point.
1028 EXPECT_TRUE(driver()->gcm_enabled());
1029 EXPECT_TRUE(syncer()->gcm_enabled());
1030
1031 // Wait until the GCM channel status request gets triggered.
1032 PumpUILoop();
1033
1034 // Complete the request that disables the GCM.
1035 CompleteGCMChannelStatusRequest(false, 0);
1036 EXPECT_FALSE(driver()->gcm_enabled());
1037 EXPECT_FALSE(syncer()->gcm_enabled());
1038 EXPECT_FALSE(driver()->IsStarted());
1039
1040 // Wait until next GCM channel status request gets triggered.
1041 PumpUILoop();
1042
1043 // Complete the request that enables the GCM.
1044 CompleteGCMChannelStatusRequest(true, 0);
1045 EXPECT_TRUE(driver()->gcm_enabled());
1046 EXPECT_TRUE(syncer()->gcm_enabled());
1047 EXPECT_TRUE(driver()->IsStarted());
1048 }
1049
1050 TEST_F(GCMChannelStatusSyncerTest, DisableAndRestart) {
1051 // Create GCMDriver first. GCM is not started.
1052 CreateDriver(FakeGCMClient::NO_DELAY_START);
1053 EXPECT_FALSE(driver()->IsStarted());
1054
1055 // By default, GCM is enabled.
1056 EXPECT_TRUE(driver()->gcm_enabled());
1057 EXPECT_TRUE(syncer()->gcm_enabled());
1058
1059 // Remove delay such that the request could be executed immediately.
1060 syncer()->set_delay_removed_for_testing(true);
1061
1062 // GCM will be started after app handler is added.
1063 AddAppHandlers();
1064 EXPECT_TRUE(driver()->IsStarted());
1065
1066 // GCM is still enabled at this point.
1067 EXPECT_TRUE(driver()->gcm_enabled());
1068 EXPECT_TRUE(syncer()->gcm_enabled());
1069
1070 // Wait until the GCM channel status request gets triggered.
1071 PumpUILoop();
1072
1073 // Complete the request that disables the GCM.
1074 CompleteGCMChannelStatusRequest(false, 0);
1075 EXPECT_FALSE(driver()->gcm_enabled());
1076 EXPECT_FALSE(syncer()->gcm_enabled());
1077 EXPECT_FALSE(driver()->IsStarted());
1078
1079 // Simulate browser start by recreating GCMDriver.
1080 ShutdownDriver();
1081 CreateDriver(FakeGCMClient::NO_DELAY_START);
1082
1083 // GCM is still disabled.
1084 EXPECT_FALSE(driver()->gcm_enabled());
1085 EXPECT_FALSE(syncer()->gcm_enabled());
1086 EXPECT_FALSE(driver()->IsStarted());
1087
1088 AddAppHandlers();
1089 EXPECT_FALSE(driver()->gcm_enabled());
1090 EXPECT_FALSE(syncer()->gcm_enabled());
1091 EXPECT_FALSE(driver()->IsStarted());
1092 }
1093
1094 TEST_F(GCMChannelStatusSyncerTest, FirstPolling) {
fgorski 2014/09/11 18:24:35 nit: FirstTimePolling
jianli 2014/09/11 21:04:31 Done.
1095 // Start GCM.
1096 CreateDriver(FakeGCMClient::NO_DELAY_START);
1097 AddAppHandlers();
1098
1099 // The 1st request should be triggered shortly without jittering.
1100 EXPECT_EQ(GCMChannelStatusSyncer::first_time_delay_seconds(),
1101 syncer()->current_request_delay_interval().InSeconds());
1102 }
1103
1104 TEST_F(GCMChannelStatusSyncerTest, SubsequentPollingWithDefaultInterval) {
1105 // Create GCMDriver first. GCM is not started.
1106 CreateDriver(FakeGCMClient::NO_DELAY_START);
1107
1108 // Remove delay such that the request could be executed immediately.
1109 syncer()->set_delay_removed_for_testing(true);
1110
1111 // Now GCM is started.
1112 AddAppHandlers();
1113
1114 // Wait until the GCM channel status request gets triggered.
1115 PumpUILoop();
1116
1117 // Keep delay such that we can find out the computed delay time.
1118 syncer()->set_delay_removed_for_testing(false);
1119
1120 // Complete the request. The default interval is intact.
1121 CompleteGCMChannelStatusRequest(true, 0);
1122
1123 // The next request should be scheduled at the expected default interval.
1124 int64 actual_delay_seconds =
1125 syncer()->current_request_delay_interval().InSeconds();
1126 int64 expected_delay_seconds =
1127 GCMChannelStatusRequest::default_poll_interval_seconds();
1128 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1129 << "expected delay: " << expected_delay_seconds
1130 << " actual delay: " << actual_delay_seconds;
1131
1132 // Simulate browser start by recreating GCMDriver.
1133 ShutdownDriver();
1134 CreateDriver(FakeGCMClient::NO_DELAY_START);
1135 AddAppHandlers();
1136
1137 // After start-up, the request should still be scheduled at the expected
1138 // default interval.
1139 actual_delay_seconds =
1140 syncer()->current_request_delay_interval().InSeconds();
1141 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1142 << "expected delay: " << expected_delay_seconds
1143 << " actual delay: " << actual_delay_seconds;
1144 }
1145
1146 TEST_F(GCMChannelStatusSyncerTest, SubsequentPollingWithUpdatedInterval) {
1147 // Create GCMDriver first. GCM is not started.
1148 CreateDriver(FakeGCMClient::NO_DELAY_START);
1149
1150 // Remove delay such that the request could be executed immediately.
1151 syncer()->set_delay_removed_for_testing(true);
1152
1153 // Now GCM is started.
1154 AddAppHandlers();
1155
1156 // Wait until the GCM channel status request gets triggered.
1157 PumpUILoop();
1158
1159 // Keep delay such that we can find out the computed delay time.
1160 syncer()->set_delay_removed_for_testing(false);
1161
1162 // Complete the request. The interval is being changed.
1163 int new_poll_interval_seconds =
1164 GCMChannelStatusRequest::default_poll_interval_seconds() * 2;
1165 CompleteGCMChannelStatusRequest(true, new_poll_interval_seconds);
1166
1167 // The next request should be scheduled at the expected updated interval.
1168 int64 actual_delay_seconds =
1169 syncer()->current_request_delay_interval().InSeconds();
1170 int64 expected_delay_seconds = new_poll_interval_seconds;
1171 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1172 << "expected delay: " << expected_delay_seconds
1173 << " actual delay: " << actual_delay_seconds;
1174
1175 // Simulate browser start by recreating GCMDriver.
1176 ShutdownDriver();
1177 CreateDriver(FakeGCMClient::NO_DELAY_START);
1178 AddAppHandlers();
1179
1180 // After start-up, the request should still be scheduled at the expected
1181 // updated interval.
1182 actual_delay_seconds =
1183 syncer()->current_request_delay_interval().InSeconds();
1184 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1185 << "expected delay: " << expected_delay_seconds
1186 << " actual delay: " << actual_delay_seconds;
1187 }
1188
931 } // namespace gcm 1189 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698