| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 EXPECT_FALSE(gcm_connection_observer()->connected()); | 357 EXPECT_FALSE(gcm_connection_observer()->connected()); |
| 358 } | 358 } |
| 359 | 359 |
| 360 TEST_F(GCMDriverTest, DisableAndReenableGCM) { | 360 TEST_F(GCMDriverTest, DisableAndReenableGCM) { |
| 361 CreateDriver(FakeGCMClient::NO_DELAY_START); | 361 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 362 AddAppHandlers(); | 362 AddAppHandlers(); |
| 363 PumpIOLoop(); | 363 PumpIOLoop(); |
| 364 PumpUILoop(); | 364 PumpUILoop(); |
| 365 | 365 |
| 366 // GCMClient should be started. | 366 // GCMClient should be started. |
| 367 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); | 367 EXPECT_TRUE(driver()->IsStarted()); |
| 368 | 368 |
| 369 // Disables the GCM. | 369 // Disables the GCM. |
| 370 driver()->Disable(); | 370 driver()->Disable(); |
| 371 PumpIOLoop(); | 371 PumpIOLoop(); |
| 372 PumpUILoop(); | 372 PumpUILoop(); |
| 373 | 373 |
| 374 // GCMClient should be stopped. | 374 // GCMClient should be stopped. |
| 375 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status()); | 375 EXPECT_FALSE(driver()->IsStarted()); |
| 376 | 376 |
| 377 // Enables the GCM. | 377 // Enables the GCM. |
| 378 driver()->Enable(); | 378 driver()->Enable(); |
| 379 PumpIOLoop(); | 379 PumpIOLoop(); |
| 380 PumpUILoop(); | 380 PumpUILoop(); |
| 381 | 381 |
| 382 // GCMClient should be started. | 382 // GCMClient should be started. |
| 383 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); | 383 EXPECT_TRUE(driver()->IsStarted()); |
| 384 | |
| 385 // Disables the GCM. | |
| 386 driver()->Disable(); | |
| 387 PumpIOLoop(); | |
| 388 PumpUILoop(); | |
| 389 | |
| 390 // GCMClient should be stopped. | |
| 391 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status()); | |
| 392 | |
| 393 // GCMClient should be stopped. | |
| 394 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status()); | |
| 395 } | 384 } |
| 396 | 385 |
| 397 TEST_F(GCMDriverTest, StartOrStopGCMOnDemand) { | 386 TEST_F(GCMDriverTest, StartOrStopGCMOnDemand) { |
| 398 CreateDriver(FakeGCMClient::NO_DELAY_START); | 387 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 399 PumpIOLoop(); | 388 PumpIOLoop(); |
| 400 PumpUILoop(); | 389 PumpUILoop(); |
| 401 | 390 |
| 402 // GCMClient is not started. | |
| 403 EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status()); | |
| 404 | |
| 405 // GCMClient is started after an app handler has been added. | 391 // GCMClient is started after an app handler has been added. |
| 406 driver()->AddAppHandler(kTestAppID1, gcm_app_handler()); | 392 driver()->AddAppHandler(kTestAppID1, gcm_app_handler()); |
| 407 PumpIOLoop(); | 393 PumpIOLoop(); |
| 408 PumpUILoop(); | 394 PumpUILoop(); |
| 409 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); | 395 EXPECT_TRUE(driver()->IsStarted()); |
| 410 | 396 |
| 411 // Add another app handler. | 397 // Add another app handler. |
| 412 driver()->AddAppHandler(kTestAppID2, gcm_app_handler()); | 398 driver()->AddAppHandler(kTestAppID2, gcm_app_handler()); |
| 413 PumpIOLoop(); | 399 PumpIOLoop(); |
| 414 PumpUILoop(); | 400 PumpUILoop(); |
| 415 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); | 401 EXPECT_TRUE(driver()->IsStarted()); |
| 416 | 402 |
| 417 // GCMClient remains active after one app handler is gone. | 403 // GCMClient remains active after one app handler is gone. |
| 418 driver()->RemoveAppHandler(kTestAppID1); | 404 driver()->RemoveAppHandler(kTestAppID1); |
| 419 PumpIOLoop(); | 405 PumpIOLoop(); |
| 420 PumpUILoop(); | 406 PumpUILoop(); |
| 421 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); | 407 EXPECT_TRUE(driver()->IsStarted()); |
| 422 | 408 |
| 423 // GCMClient should be stopped after the last app handler is gone. | 409 // GCMClient should be stopped after the last app handler is gone. |
| 424 driver()->RemoveAppHandler(kTestAppID2); | 410 driver()->RemoveAppHandler(kTestAppID2); |
| 425 PumpIOLoop(); | 411 PumpIOLoop(); |
| 426 PumpUILoop(); | 412 PumpUILoop(); |
| 427 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status()); | 413 EXPECT_FALSE(driver()->IsStarted()); |
| 428 | 414 |
| 429 // GCMClient is restarted after an app handler has been added. | 415 // GCMClient is restarted after an app handler has been added. |
| 430 driver()->AddAppHandler(kTestAppID2, gcm_app_handler()); | 416 driver()->AddAppHandler(kTestAppID2, gcm_app_handler()); |
| 431 PumpIOLoop(); | 417 PumpIOLoop(); |
| 432 PumpUILoop(); | 418 PumpUILoop(); |
| 433 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); | 419 EXPECT_TRUE(driver()->IsStarted()); |
| 434 } | 420 } |
| 435 | 421 |
| 436 TEST_F(GCMDriverTest, RegisterFailed) { | 422 TEST_F(GCMDriverTest, RegisterFailed) { |
| 437 std::vector<std::string> sender_ids; | 423 std::vector<std::string> sender_ids; |
| 438 sender_ids.push_back("sender1"); | 424 sender_ids.push_back("sender1"); |
| 439 | 425 |
| 440 CreateDriver(FakeGCMClient::NO_DELAY_START); | 426 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 441 | 427 |
| 442 // Registration fails when GCM is disabled. | 428 // Registration fails when GCM is disabled. |
| 443 driver()->Disable(); | 429 driver()->Disable(); |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 // After start-up, the request should still be scheduled at the expected | 1054 // After start-up, the request should still be scheduled at the expected |
| 1069 // updated interval. | 1055 // updated interval. |
| 1070 actual_delay_seconds = | 1056 actual_delay_seconds = |
| 1071 syncer()->current_request_delay_interval().InSeconds(); | 1057 syncer()->current_request_delay_interval().InSeconds(); |
| 1072 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) | 1058 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) |
| 1073 << "expected delay: " << expected_delay_seconds | 1059 << "expected delay: " << expected_delay_seconds |
| 1074 << " actual delay: " << actual_delay_seconds; | 1060 << " actual delay: " << actual_delay_seconds; |
| 1075 } | 1061 } |
| 1076 | 1062 |
| 1077 } // namespace gcm | 1063 } // namespace gcm |
| OLD | NEW |