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

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 CrOS test failures 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
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.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/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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 EXPECT_TRUE(driver()->IsConnected()); 394 EXPECT_TRUE(driver()->IsConnected());
380 } 395 }
381 396
382 TEST_F(GCMDriverTest, Shutdown) { 397 TEST_F(GCMDriverTest, Shutdown) {
383 CreateDriver(FakeGCMClient::NO_DELAY_START); 398 CreateDriver(FakeGCMClient::NO_DELAY_START);
384 EXPECT_FALSE(HasAppHandlers()); 399 EXPECT_FALSE(HasAppHandlers());
385 400
386 AddAppHandlers(); 401 AddAppHandlers();
387 EXPECT_TRUE(HasAppHandlers()); 402 EXPECT_TRUE(HasAppHandlers());
388 403
389 driver()->Shutdown(); 404 ShutdownDriver();
390 EXPECT_FALSE(HasAppHandlers()); 405 EXPECT_FALSE(HasAppHandlers());
391 EXPECT_FALSE(driver()->IsConnected()); 406 EXPECT_FALSE(driver()->IsConnected());
392 EXPECT_FALSE(gcm_connection_observer()->connected()); 407 EXPECT_FALSE(gcm_connection_observer()->connected());
393 } 408 }
394 409
395 TEST_F(GCMDriverTest, SignInAndSignOutOnGCMEnabled) { 410 TEST_F(GCMDriverTest, SignInAndSignOutOnGCMEnabled) {
396 // By default, GCM is enabled. 411 // By default, GCM is enabled.
397 CreateDriver(FakeGCMClient::NO_DELAY_START); 412 CreateDriver(FakeGCMClient::NO_DELAY_START);
398 AddAppHandlers(); 413 AddAppHandlers();
399 414
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 } 949 }
935 950
936 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { 951 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) {
937 GetGCMClient()->DeleteMessages(kTestAppID1); 952 GetGCMClient()->DeleteMessages(kTestAppID1);
938 gcm_app_handler()->WaitForNotification(); 953 gcm_app_handler()->WaitForNotification();
939 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, 954 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT,
940 gcm_app_handler()->received_event()); 955 gcm_app_handler()->received_event());
941 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); 956 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id());
942 } 957 }
943 958
959 // Tests a single instance of GCMDriver.
960 class GCMChannelStatusSyncerTest : public GCMDriverTest {
961 public:
962 GCMChannelStatusSyncerTest();
963 virtual ~GCMChannelStatusSyncerTest();
964
965 // testing::Test:
966 virtual void SetUp() OVERRIDE;
967
968 void CompleteGCMChannelStatusRequest(bool enabled, int poll_interval_seconds);
969 bool CompareDelaySeconds(bool expected_delay_seconds,
970 bool actual_delay_seconds);
971
972 GCMChannelStatusSyncer* syncer() {
973 return driver()->gcm_channel_status_syncer_for_testing();
974 }
975
976 private:
977 net::TestURLFetcherFactory url_fetcher_factory_;
978
979 DISALLOW_COPY_AND_ASSIGN(GCMChannelStatusSyncerTest);
980 };
981
982 GCMChannelStatusSyncerTest::GCMChannelStatusSyncerTest() {
983 }
984
985 GCMChannelStatusSyncerTest::~GCMChannelStatusSyncerTest() {
986 }
987
988 void GCMChannelStatusSyncerTest::SetUp() {
989 GCMDriverTest::SetUp();
990
991 // Turn on all-user support.
992 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled"));
993 }
994
995 void GCMChannelStatusSyncerTest::CompleteGCMChannelStatusRequest(
996 bool enabled, int poll_interval_seconds) {
997 gcm_proto::ExperimentStatusResponse response_proto;
998 response_proto.mutable_gcm_channel()->set_enabled(enabled);
999
1000 if (poll_interval_seconds)
1001 response_proto.set_poll_interval_seconds(poll_interval_seconds);
1002
1003 std::string response_string;
1004 response_proto.SerializeToString(&response_string);
1005
1006 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
1007 ASSERT_TRUE(fetcher);
1008 fetcher->set_response_code(net::HTTP_OK);
1009 fetcher->SetResponseString(response_string);
1010 fetcher->delegate()->OnURLFetchComplete(fetcher);
1011 }
1012
1013 bool GCMChannelStatusSyncerTest::CompareDelaySeconds(
1014 bool expected_delay_seconds, bool actual_delay_seconds) {
1015 // Most of time, the actual delay should not be smaller than the expected
1016 // delay.
1017 if (actual_delay_seconds >= expected_delay_seconds)
1018 return true;
1019 // It is also OK that the actual delay is a bit smaller than the expected
1020 // delay in case that the test runs slowly.
1021 return expected_delay_seconds - actual_delay_seconds < 30;
1022 }
1023
1024 TEST_F(GCMChannelStatusSyncerTest, DisableAndEnable) {
1025 // Create GCMDriver first. GCM is not started.
1026 CreateDriver(FakeGCMClient::NO_DELAY_START);
1027 EXPECT_FALSE(driver()->IsStarted());
1028
1029 // By default, GCM is enabled.
1030 EXPECT_TRUE(driver()->gcm_enabled());
1031 EXPECT_TRUE(syncer()->gcm_enabled());
1032
1033 // Remove delay such that the request could be executed immediately.
1034 syncer()->set_delay_removed_for_testing(true);
1035
1036 // GCM will be started after app handler is added.
1037 AddAppHandlers();
1038 EXPECT_TRUE(driver()->IsStarted());
1039
1040 // GCM is still enabled at this point.
1041 EXPECT_TRUE(driver()->gcm_enabled());
1042 EXPECT_TRUE(syncer()->gcm_enabled());
1043
1044 // Wait until the GCM channel status request gets triggered.
1045 PumpUILoop();
1046
1047 // Complete the request that disables the GCM.
1048 CompleteGCMChannelStatusRequest(false, 0);
1049 EXPECT_FALSE(driver()->gcm_enabled());
1050 EXPECT_FALSE(syncer()->gcm_enabled());
1051 EXPECT_FALSE(driver()->IsStarted());
1052
1053 // Wait until next GCM channel status request gets triggered.
1054 PumpUILoop();
1055
1056 // Complete the request that enables the GCM.
1057 CompleteGCMChannelStatusRequest(true, 0);
1058 EXPECT_TRUE(driver()->gcm_enabled());
1059 EXPECT_TRUE(syncer()->gcm_enabled());
1060 EXPECT_TRUE(driver()->IsStarted());
1061 }
1062
1063 TEST_F(GCMChannelStatusSyncerTest, DisableAndRestart) {
1064 // Create GCMDriver first. GCM is not started.
1065 CreateDriver(FakeGCMClient::NO_DELAY_START);
1066 EXPECT_FALSE(driver()->IsStarted());
1067
1068 // By default, GCM is enabled.
1069 EXPECT_TRUE(driver()->gcm_enabled());
1070 EXPECT_TRUE(syncer()->gcm_enabled());
1071
1072 // Remove delay such that the request could be executed immediately.
1073 syncer()->set_delay_removed_for_testing(true);
1074
1075 // GCM will be started after app handler is added.
1076 AddAppHandlers();
1077 EXPECT_TRUE(driver()->IsStarted());
1078
1079 // GCM is still enabled at this point.
1080 EXPECT_TRUE(driver()->gcm_enabled());
1081 EXPECT_TRUE(syncer()->gcm_enabled());
1082
1083 // Wait until the GCM channel status request gets triggered.
1084 PumpUILoop();
1085
1086 // Complete the request that disables the GCM.
1087 CompleteGCMChannelStatusRequest(false, 0);
1088 EXPECT_FALSE(driver()->gcm_enabled());
1089 EXPECT_FALSE(syncer()->gcm_enabled());
1090 EXPECT_FALSE(driver()->IsStarted());
1091
1092 // Simulate browser start by recreating GCMDriver.
1093 ShutdownDriver();
1094 CreateDriver(FakeGCMClient::NO_DELAY_START);
1095
1096 // GCM is still disabled.
1097 EXPECT_FALSE(driver()->gcm_enabled());
1098 EXPECT_FALSE(syncer()->gcm_enabled());
1099 EXPECT_FALSE(driver()->IsStarted());
1100
1101 AddAppHandlers();
1102 EXPECT_FALSE(driver()->gcm_enabled());
1103 EXPECT_FALSE(syncer()->gcm_enabled());
1104 EXPECT_FALSE(driver()->IsStarted());
1105 }
1106
1107 TEST_F(GCMChannelStatusSyncerTest, FirstTimePolling) {
1108 // Start GCM.
1109 CreateDriver(FakeGCMClient::NO_DELAY_START);
1110 AddAppHandlers();
1111
1112 // The 1st request should be triggered shortly without jittering.
1113 EXPECT_EQ(GCMChannelStatusSyncer::first_time_delay_seconds(),
1114 syncer()->current_request_delay_interval().InSeconds());
1115 }
1116
1117 TEST_F(GCMChannelStatusSyncerTest, SubsequentPollingWithDefaultInterval) {
1118 // Create GCMDriver first. GCM is not started.
1119 CreateDriver(FakeGCMClient::NO_DELAY_START);
1120
1121 // Remove delay such that the request could be executed immediately.
1122 syncer()->set_delay_removed_for_testing(true);
1123
1124 // Now GCM is started.
1125 AddAppHandlers();
1126
1127 // Wait until the GCM channel status request gets triggered.
1128 PumpUILoop();
1129
1130 // Keep delay such that we can find out the computed delay time.
1131 syncer()->set_delay_removed_for_testing(false);
1132
1133 // Complete the request. The default interval is intact.
1134 CompleteGCMChannelStatusRequest(true, 0);
1135
1136 // The next request should be scheduled at the expected default interval.
1137 int64 actual_delay_seconds =
1138 syncer()->current_request_delay_interval().InSeconds();
1139 int64 expected_delay_seconds =
1140 GCMChannelStatusRequest::default_poll_interval_seconds();
1141 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1142 << "expected delay: " << expected_delay_seconds
1143 << " actual delay: " << actual_delay_seconds;
1144
1145 // Simulate browser start by recreating GCMDriver.
1146 ShutdownDriver();
1147 CreateDriver(FakeGCMClient::NO_DELAY_START);
1148 AddAppHandlers();
1149
1150 // After start-up, the request should still be scheduled at the expected
1151 // default interval.
1152 actual_delay_seconds =
1153 syncer()->current_request_delay_interval().InSeconds();
1154 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1155 << "expected delay: " << expected_delay_seconds
1156 << " actual delay: " << actual_delay_seconds;
1157 }
1158
1159 TEST_F(GCMChannelStatusSyncerTest, SubsequentPollingWithUpdatedInterval) {
1160 // Create GCMDriver first. GCM is not started.
1161 CreateDriver(FakeGCMClient::NO_DELAY_START);
1162
1163 // Remove delay such that the request could be executed immediately.
1164 syncer()->set_delay_removed_for_testing(true);
1165
1166 // Now GCM is started.
1167 AddAppHandlers();
1168
1169 // Wait until the GCM channel status request gets triggered.
1170 PumpUILoop();
1171
1172 // Keep delay such that we can find out the computed delay time.
1173 syncer()->set_delay_removed_for_testing(false);
1174
1175 // Complete the request. The interval is being changed.
1176 int new_poll_interval_seconds =
1177 GCMChannelStatusRequest::default_poll_interval_seconds() * 2;
1178 CompleteGCMChannelStatusRequest(true, new_poll_interval_seconds);
1179
1180 // The next request should be scheduled at the expected updated interval.
1181 int64 actual_delay_seconds =
1182 syncer()->current_request_delay_interval().InSeconds();
1183 int64 expected_delay_seconds = new_poll_interval_seconds;
1184 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1185 << "expected delay: " << expected_delay_seconds
1186 << " actual delay: " << actual_delay_seconds;
1187
1188 // Simulate browser start by recreating GCMDriver.
1189 ShutdownDriver();
1190 CreateDriver(FakeGCMClient::NO_DELAY_START);
1191 AddAppHandlers();
1192
1193 // After start-up, the request should still be scheduled at the expected
1194 // updated interval.
1195 actual_delay_seconds =
1196 syncer()->current_request_delay_interval().InSeconds();
1197 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1198 << "expected delay: " << expected_delay_seconds
1199 << " actual delay: " << actual_delay_seconds;
1200 }
1201
944 } // namespace gcm 1202 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698