| OLD | NEW |
| 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" |
| (...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 // Wait until next GCM channel status request gets triggered. | 1084 // Wait until next GCM channel status request gets triggered. |
| 1085 PumpUILoop(); | 1085 PumpUILoop(); |
| 1086 | 1086 |
| 1087 // Complete the request that enables the GCM. | 1087 // Complete the request that enables the GCM. |
| 1088 CompleteGCMChannelStatusRequest(true, 0); | 1088 CompleteGCMChannelStatusRequest(true, 0); |
| 1089 EXPECT_TRUE(driver()->gcm_enabled()); | 1089 EXPECT_TRUE(driver()->gcm_enabled()); |
| 1090 EXPECT_TRUE(syncer()->gcm_enabled()); | 1090 EXPECT_TRUE(syncer()->gcm_enabled()); |
| 1091 EXPECT_TRUE(driver()->IsStarted()); | 1091 EXPECT_TRUE(driver()->IsStarted()); |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 TEST_F(GCMChannelStatusSyncerTest, DisableAndRestart) { | 1094 TEST_F(GCMChannelStatusSyncerTest, DisableRestartAndEnable) { |
| 1095 // Create GCMDriver first. GCM is not started. | 1095 // Create GCMDriver first. GCM is not started. |
| 1096 CreateDriver(FakeGCMClient::NO_DELAY_START); | 1096 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 1097 EXPECT_FALSE(driver()->IsStarted()); | 1097 EXPECT_FALSE(driver()->IsStarted()); |
| 1098 | 1098 |
| 1099 // By default, GCM is enabled. | 1099 // By default, GCM is enabled. |
| 1100 EXPECT_TRUE(driver()->gcm_enabled()); | 1100 EXPECT_TRUE(driver()->gcm_enabled()); |
| 1101 EXPECT_TRUE(syncer()->gcm_enabled()); | 1101 EXPECT_TRUE(syncer()->gcm_enabled()); |
| 1102 | 1102 |
| 1103 // Remove delay such that the request could be executed immediately. | 1103 // Remove delay such that the request could be executed immediately. |
| 1104 syncer()->set_delay_removed_for_testing(true); | 1104 syncer()->set_delay_removed_for_testing(true); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1117 // Complete the request that disables the GCM. | 1117 // Complete the request that disables the GCM. |
| 1118 CompleteGCMChannelStatusRequest(false, 0); | 1118 CompleteGCMChannelStatusRequest(false, 0); |
| 1119 EXPECT_FALSE(driver()->gcm_enabled()); | 1119 EXPECT_FALSE(driver()->gcm_enabled()); |
| 1120 EXPECT_FALSE(syncer()->gcm_enabled()); | 1120 EXPECT_FALSE(syncer()->gcm_enabled()); |
| 1121 EXPECT_FALSE(driver()->IsStarted()); | 1121 EXPECT_FALSE(driver()->IsStarted()); |
| 1122 | 1122 |
| 1123 // Simulate browser start by recreating GCMDriver. | 1123 // Simulate browser start by recreating GCMDriver. |
| 1124 ShutdownDriver(); | 1124 ShutdownDriver(); |
| 1125 CreateDriver(FakeGCMClient::NO_DELAY_START); | 1125 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 1126 | 1126 |
| 1127 // Remove delay such that the request could be executed immediately. |
| 1128 syncer()->set_delay_removed_for_testing(true); |
| 1129 |
| 1127 // GCM is still disabled. | 1130 // GCM is still disabled. |
| 1128 EXPECT_FALSE(driver()->gcm_enabled()); | 1131 EXPECT_FALSE(driver()->gcm_enabled()); |
| 1129 EXPECT_FALSE(syncer()->gcm_enabled()); | 1132 EXPECT_FALSE(syncer()->gcm_enabled()); |
| 1130 EXPECT_FALSE(driver()->IsStarted()); | 1133 EXPECT_FALSE(driver()->IsStarted()); |
| 1131 | 1134 |
| 1132 AddAppHandlers(); | 1135 AddAppHandlers(); |
| 1133 EXPECT_FALSE(driver()->gcm_enabled()); | 1136 EXPECT_FALSE(driver()->gcm_enabled()); |
| 1134 EXPECT_FALSE(syncer()->gcm_enabled()); | 1137 EXPECT_FALSE(syncer()->gcm_enabled()); |
| 1135 EXPECT_FALSE(driver()->IsStarted()); | 1138 EXPECT_FALSE(driver()->IsStarted()); |
| 1139 |
| 1140 // Wait until the GCM channel status request gets triggered. |
| 1141 PumpUILoop(); |
| 1142 |
| 1143 // Complete the request that re-enables the GCM. |
| 1144 CompleteGCMChannelStatusRequest(true, 0); |
| 1145 EXPECT_TRUE(driver()->gcm_enabled()); |
| 1146 EXPECT_TRUE(syncer()->gcm_enabled()); |
| 1147 EXPECT_TRUE(driver()->IsStarted()); |
| 1136 } | 1148 } |
| 1137 | 1149 |
| 1138 TEST_F(GCMChannelStatusSyncerTest, FirstTimePolling) { | 1150 TEST_F(GCMChannelStatusSyncerTest, FirstTimePolling) { |
| 1139 // Start GCM. | 1151 // Start GCM. |
| 1140 CreateDriver(FakeGCMClient::NO_DELAY_START); | 1152 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 1141 AddAppHandlers(); | 1153 AddAppHandlers(); |
| 1142 | 1154 |
| 1143 // The 1st request should be triggered shortly without jittering. | 1155 // The 1st request should be triggered shortly without jittering. |
| 1144 EXPECT_EQ(GCMChannelStatusSyncer::first_time_delay_seconds(), | 1156 EXPECT_EQ(GCMChannelStatusSyncer::first_time_delay_seconds(), |
| 1145 syncer()->current_request_delay_interval().InSeconds()); | 1157 syncer()->current_request_delay_interval().InSeconds()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 // After start-up, the request should still be scheduled at the expected | 1236 // After start-up, the request should still be scheduled at the expected |
| 1225 // updated interval. | 1237 // updated interval. |
| 1226 actual_delay_seconds = | 1238 actual_delay_seconds = |
| 1227 syncer()->current_request_delay_interval().InSeconds(); | 1239 syncer()->current_request_delay_interval().InSeconds(); |
| 1228 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) | 1240 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) |
| 1229 << "expected delay: " << expected_delay_seconds | 1241 << "expected delay: " << expected_delay_seconds |
| 1230 << " actual delay: " << actual_delay_seconds; | 1242 << " actual delay: " << actual_delay_seconds; |
| 1231 } | 1243 } |
| 1232 | 1244 |
| 1233 } // namespace gcm | 1245 } // namespace gcm |
| OLD | NEW |