| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 driver_->RemoveAppHandler(kTestAppID2); | 251 driver_->RemoveAppHandler(kTestAppID2); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void GCMDriverTest::SignIn(const std::string& account_id) { | 254 void GCMDriverTest::SignIn(const std::string& account_id) { |
| 255 driver_->OnSignedIn(); | 255 driver_->OnSignedIn(); |
| 256 PumpIOLoop(); | 256 PumpIOLoop(); |
| 257 PumpUILoop(); | 257 PumpUILoop(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void GCMDriverTest::SignOut() { | 260 void GCMDriverTest::SignOut() { |
| 261 driver_->OnSignedOut(); | 261 driver_->Purge(); |
| 262 PumpIOLoop(); | 262 PumpIOLoop(); |
| 263 PumpUILoop(); | 263 PumpUILoop(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void GCMDriverTest::Register(const std::string& app_id, | 266 void GCMDriverTest::Register(const std::string& app_id, |
| 267 const std::vector<std::string>& sender_ids, | 267 const std::vector<std::string>& sender_ids, |
| 268 WaitToFinish wait_to_finish) { | 268 WaitToFinish wait_to_finish) { |
| 269 base::RunLoop run_loop; | 269 base::RunLoop run_loop; |
| 270 async_operation_completed_callback_ = run_loop.QuitClosure(); | 270 async_operation_completed_callback_ = run_loop.QuitClosure(); |
| 271 driver_->Register(app_id, | 271 driver_->Register(app_id, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 343 |
| 344 // GCM will be started only after both sign-in and app handler being added. | 344 // GCM will be started only after both sign-in and app handler being added. |
| 345 AddAppHandlers(); | 345 AddAppHandlers(); |
| 346 EXPECT_TRUE(driver()->IsStarted()); | 346 EXPECT_TRUE(driver()->IsStarted()); |
| 347 PumpIOLoop(); | 347 PumpIOLoop(); |
| 348 EXPECT_TRUE(driver()->IsConnected()); | 348 EXPECT_TRUE(driver()->IsConnected()); |
| 349 EXPECT_TRUE(gcm_connection_observer()->connected()); | 349 EXPECT_TRUE(gcm_connection_observer()->connected()); |
| 350 } | 350 } |
| 351 | 351 |
| 352 TEST_F(GCMDriverTest, CreateByFieldTrial) { | 352 TEST_F(GCMDriverTest, CreateByFieldTrial) { |
| 353 // Turn on the signal to drop sign-in enforcement. | |
| 354 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled")); | 353 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled")); |
| 355 | 354 |
| 356 // Create GCMDriver first. GCM is not started. | 355 // Create GCMDriver first. GCM is not started. |
| 357 CreateDriver(FakeGCMClient::NO_DELAY_START); | 356 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 358 EXPECT_FALSE(driver()->IsStarted()); | 357 EXPECT_FALSE(driver()->IsStarted()); |
| 359 EXPECT_FALSE(driver()->IsConnected()); | 358 EXPECT_FALSE(driver()->IsConnected()); |
| 360 EXPECT_FALSE(gcm_connection_observer()->connected()); | 359 EXPECT_FALSE(gcm_connection_observer()->connected()); |
| 361 | 360 |
| 362 // GCM will be started after app handler is added. | 361 // GCM will be started after app handler is added. |
| 363 AddAppHandlers(); | 362 AddAppHandlers(); |
| 364 EXPECT_TRUE(driver()->IsStarted()); | 363 EXPECT_TRUE(driver()->IsStarted()); |
| 365 PumpIOLoop(); | 364 PumpIOLoop(); |
| 366 EXPECT_TRUE(driver()->IsConnected()); | 365 EXPECT_TRUE(driver()->IsConnected()); |
| 367 EXPECT_TRUE(gcm_connection_observer()->connected()); | 366 EXPECT_TRUE(gcm_connection_observer()->connected()); |
| 368 | |
| 369 // Sign-in will not affect GCM state. | |
| 370 SignIn(kTestAccountID1); | |
| 371 PumpIOLoop(); | |
| 372 EXPECT_TRUE(driver()->IsStarted()); | |
| 373 EXPECT_TRUE(driver()->IsConnected()); | |
| 374 | |
| 375 // Sign-out will not affect GCM state. | |
| 376 SignOut(); | |
| 377 PumpIOLoop(); | |
| 378 EXPECT_TRUE(driver()->IsStarted()); | |
| 379 EXPECT_TRUE(driver()->IsConnected()); | |
| 380 } | 367 } |
| 381 | 368 |
| 382 TEST_F(GCMDriverTest, Shutdown) { | 369 TEST_F(GCMDriverTest, Shutdown) { |
| 383 CreateDriver(FakeGCMClient::NO_DELAY_START); | 370 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 384 EXPECT_FALSE(HasAppHandlers()); | 371 EXPECT_FALSE(HasAppHandlers()); |
| 385 | 372 |
| 386 AddAppHandlers(); | 373 AddAppHandlers(); |
| 387 EXPECT_TRUE(HasAppHandlers()); | 374 EXPECT_TRUE(HasAppHandlers()); |
| 388 | 375 |
| 389 driver()->Shutdown(); | 376 driver()->Shutdown(); |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 | 922 |
| 936 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { | 923 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { |
| 937 GetGCMClient()->DeleteMessages(kTestAppID1); | 924 GetGCMClient()->DeleteMessages(kTestAppID1); |
| 938 gcm_app_handler()->WaitForNotification(); | 925 gcm_app_handler()->WaitForNotification(); |
| 939 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, | 926 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, |
| 940 gcm_app_handler()->received_event()); | 927 gcm_app_handler()->received_event()); |
| 941 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); | 928 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); |
| 942 } | 929 } |
| 943 | 930 |
| 944 } // namespace gcm | 931 } // namespace gcm |
| OLD | NEW |