| 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 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 | 1010 |
| 1011 GCMChannelStatusSyncerTest::GCMChannelStatusSyncerTest() { | 1011 GCMChannelStatusSyncerTest::GCMChannelStatusSyncerTest() { |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 GCMChannelStatusSyncerTest::~GCMChannelStatusSyncerTest() { | 1014 GCMChannelStatusSyncerTest::~GCMChannelStatusSyncerTest() { |
| 1015 } | 1015 } |
| 1016 | 1016 |
| 1017 void GCMChannelStatusSyncerTest::SetUp() { | 1017 void GCMChannelStatusSyncerTest::SetUp() { |
| 1018 GCMDriverTest::SetUp(); | 1018 GCMDriverTest::SetUp(); |
| 1019 | 1019 |
| 1020 url_fetcher_factory_.set_remove_fetcher_on_delete(true); |
| 1021 |
| 1020 // Turn on all-user support. | 1022 // Turn on all-user support. |
| 1021 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled")); | 1023 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled")); |
| 1022 } | 1024 } |
| 1023 | 1025 |
| 1024 void GCMChannelStatusSyncerTest::CompleteGCMChannelStatusRequest( | 1026 void GCMChannelStatusSyncerTest::CompleteGCMChannelStatusRequest( |
| 1025 bool enabled, int poll_interval_seconds) { | 1027 bool enabled, int poll_interval_seconds) { |
| 1026 sync_pb::ExperimentStatusResponse response_proto; | 1028 sync_pb::ExperimentStatusResponse response_proto; |
| 1027 sync_pb::ExperimentsSpecifics* experiment_specifics = | 1029 sync_pb::ExperimentsSpecifics* experiment_specifics = |
| 1028 response_proto.add_experiment(); | 1030 response_proto.add_experiment(); |
| 1029 experiment_specifics->mutable_gcm_channel()->set_enabled(enabled); | 1031 experiment_specifics->mutable_gcm_channel()->set_enabled(enabled); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 // Wait until next GCM channel status request gets triggered. | 1086 // Wait until next GCM channel status request gets triggered. |
| 1085 PumpUILoop(); | 1087 PumpUILoop(); |
| 1086 | 1088 |
| 1087 // Complete the request that enables the GCM. | 1089 // Complete the request that enables the GCM. |
| 1088 CompleteGCMChannelStatusRequest(true, 0); | 1090 CompleteGCMChannelStatusRequest(true, 0); |
| 1089 EXPECT_TRUE(driver()->gcm_enabled()); | 1091 EXPECT_TRUE(driver()->gcm_enabled()); |
| 1090 EXPECT_TRUE(syncer()->gcm_enabled()); | 1092 EXPECT_TRUE(syncer()->gcm_enabled()); |
| 1091 EXPECT_TRUE(driver()->IsStarted()); | 1093 EXPECT_TRUE(driver()->IsStarted()); |
| 1092 } | 1094 } |
| 1093 | 1095 |
| 1094 TEST_F(GCMChannelStatusSyncerTest, DisableAndRestart) { | 1096 TEST_F(GCMChannelStatusSyncerTest, DisableRestartAndEnable) { |
| 1095 // Create GCMDriver first. GCM is not started. | 1097 // Create GCMDriver first. GCM is not started. |
| 1096 CreateDriver(FakeGCMClient::NO_DELAY_START); | 1098 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 1097 EXPECT_FALSE(driver()->IsStarted()); | 1099 EXPECT_FALSE(driver()->IsStarted()); |
| 1098 | 1100 |
| 1099 // By default, GCM is enabled. | 1101 // By default, GCM is enabled. |
| 1100 EXPECT_TRUE(driver()->gcm_enabled()); | 1102 EXPECT_TRUE(driver()->gcm_enabled()); |
| 1101 EXPECT_TRUE(syncer()->gcm_enabled()); | 1103 EXPECT_TRUE(syncer()->gcm_enabled()); |
| 1102 | 1104 |
| 1103 // Remove delay such that the request could be executed immediately. | 1105 // Remove delay such that the request could be executed immediately. |
| 1104 syncer()->set_delay_removed_for_testing(true); | 1106 syncer()->set_delay_removed_for_testing(true); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1117 // Complete the request that disables the GCM. | 1119 // Complete the request that disables the GCM. |
| 1118 CompleteGCMChannelStatusRequest(false, 0); | 1120 CompleteGCMChannelStatusRequest(false, 0); |
| 1119 EXPECT_FALSE(driver()->gcm_enabled()); | 1121 EXPECT_FALSE(driver()->gcm_enabled()); |
| 1120 EXPECT_FALSE(syncer()->gcm_enabled()); | 1122 EXPECT_FALSE(syncer()->gcm_enabled()); |
| 1121 EXPECT_FALSE(driver()->IsStarted()); | 1123 EXPECT_FALSE(driver()->IsStarted()); |
| 1122 | 1124 |
| 1123 // Simulate browser start by recreating GCMDriver. | 1125 // Simulate browser start by recreating GCMDriver. |
| 1124 ShutdownDriver(); | 1126 ShutdownDriver(); |
| 1125 CreateDriver(FakeGCMClient::NO_DELAY_START); | 1127 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 1126 | 1128 |
| 1129 // Remove delay such that the request could be executed immediately. |
| 1130 syncer()->set_delay_removed_for_testing(true); |
| 1131 |
| 1127 // GCM is still disabled. | 1132 // GCM is still disabled. |
| 1128 EXPECT_FALSE(driver()->gcm_enabled()); | 1133 EXPECT_FALSE(driver()->gcm_enabled()); |
| 1129 EXPECT_FALSE(syncer()->gcm_enabled()); | 1134 EXPECT_FALSE(syncer()->gcm_enabled()); |
| 1130 EXPECT_FALSE(driver()->IsStarted()); | 1135 EXPECT_FALSE(driver()->IsStarted()); |
| 1131 | 1136 |
| 1132 AddAppHandlers(); | 1137 AddAppHandlers(); |
| 1133 EXPECT_FALSE(driver()->gcm_enabled()); | 1138 EXPECT_FALSE(driver()->gcm_enabled()); |
| 1134 EXPECT_FALSE(syncer()->gcm_enabled()); | 1139 EXPECT_FALSE(syncer()->gcm_enabled()); |
| 1135 EXPECT_FALSE(driver()->IsStarted()); | 1140 EXPECT_FALSE(driver()->IsStarted()); |
| 1141 |
| 1142 // Wait until the GCM channel status request gets triggered. |
| 1143 PumpUILoop(); |
| 1144 |
| 1145 // Complete the request that re-enables the GCM. |
| 1146 CompleteGCMChannelStatusRequest(true, 0); |
| 1147 EXPECT_TRUE(driver()->gcm_enabled()); |
| 1148 EXPECT_TRUE(syncer()->gcm_enabled()); |
| 1149 EXPECT_TRUE(driver()->IsStarted()); |
| 1136 } | 1150 } |
| 1137 | 1151 |
| 1138 TEST_F(GCMChannelStatusSyncerTest, FirstTimePolling) { | 1152 TEST_F(GCMChannelStatusSyncerTest, FirstTimePolling) { |
| 1139 // Start GCM. | 1153 // Start GCM. |
| 1140 CreateDriver(FakeGCMClient::NO_DELAY_START); | 1154 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 1141 AddAppHandlers(); | 1155 AddAppHandlers(); |
| 1142 | 1156 |
| 1143 // The 1st request should be triggered shortly without jittering. | 1157 // The 1st request should be triggered shortly without jittering. |
| 1144 EXPECT_EQ(GCMChannelStatusSyncer::first_time_delay_seconds(), | 1158 EXPECT_EQ(GCMChannelStatusSyncer::first_time_delay_seconds(), |
| 1145 syncer()->current_request_delay_interval().InSeconds()); | 1159 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 | 1238 // After start-up, the request should still be scheduled at the expected |
| 1225 // updated interval. | 1239 // updated interval. |
| 1226 actual_delay_seconds = | 1240 actual_delay_seconds = |
| 1227 syncer()->current_request_delay_interval().InSeconds(); | 1241 syncer()->current_request_delay_interval().InSeconds(); |
| 1228 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) | 1242 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) |
| 1229 << "expected delay: " << expected_delay_seconds | 1243 << "expected delay: " << expected_delay_seconds |
| 1230 << " actual delay: " << actual_delay_seconds; | 1244 << " actual delay: " << actual_delay_seconds; |
| 1231 } | 1245 } |
| 1232 | 1246 |
| 1233 } // namespace gcm | 1247 } // namespace gcm |
| OLD | NEW |