| 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_->Purge(); | 261 driver_->OnSignedOut(); |
| 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. |
| 353 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled")); | 354 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled")); |
| 354 | 355 |
| 355 // Create GCMDriver first. GCM is not started. | 356 // Create GCMDriver first. GCM is not started. |
| 356 CreateDriver(FakeGCMClient::NO_DELAY_START); | 357 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 357 EXPECT_FALSE(driver()->IsStarted()); | 358 EXPECT_FALSE(driver()->IsStarted()); |
| 358 EXPECT_FALSE(driver()->IsConnected()); | 359 EXPECT_FALSE(driver()->IsConnected()); |
| 359 EXPECT_FALSE(gcm_connection_observer()->connected()); | 360 EXPECT_FALSE(gcm_connection_observer()->connected()); |
| 360 | 361 |
| 361 // GCM will be started after app handler is added. | 362 // GCM will be started after app handler is added. |
| 362 AddAppHandlers(); | 363 AddAppHandlers(); |
| 363 EXPECT_TRUE(driver()->IsStarted()); | 364 EXPECT_TRUE(driver()->IsStarted()); |
| 364 PumpIOLoop(); | 365 PumpIOLoop(); |
| 365 EXPECT_TRUE(driver()->IsConnected()); | 366 EXPECT_TRUE(driver()->IsConnected()); |
| 366 EXPECT_TRUE(gcm_connection_observer()->connected()); | 367 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()); |
| 367 } | 380 } |
| 368 | 381 |
| 369 TEST_F(GCMDriverTest, Shutdown) { | 382 TEST_F(GCMDriverTest, Shutdown) { |
| 370 CreateDriver(FakeGCMClient::NO_DELAY_START); | 383 CreateDriver(FakeGCMClient::NO_DELAY_START); |
| 371 EXPECT_FALSE(HasAppHandlers()); | 384 EXPECT_FALSE(HasAppHandlers()); |
| 372 | 385 |
| 373 AddAppHandlers(); | 386 AddAppHandlers(); |
| 374 EXPECT_TRUE(HasAppHandlers()); | 387 EXPECT_TRUE(HasAppHandlers()); |
| 375 | 388 |
| 376 driver()->Shutdown(); | 389 driver()->Shutdown(); |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 | 935 |
| 923 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { | 936 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { |
| 924 GetGCMClient()->DeleteMessages(kTestAppID1); | 937 GetGCMClient()->DeleteMessages(kTestAppID1); |
| 925 gcm_app_handler()->WaitForNotification(); | 938 gcm_app_handler()->WaitForNotification(); |
| 926 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, | 939 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, |
| 927 gcm_app_handler()->received_event()); | 940 gcm_app_handler()->received_event()); |
| 928 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); | 941 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); |
| 929 } | 942 } |
| 930 | 943 |
| 931 } // namespace gcm | 944 } // namespace gcm |
| OLD | NEW |