Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <map> | 6 #include <map> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 Event received_event_; | 207 Event received_event_; |
| 208 std::string app_id_; | 208 std::string app_id_; |
| 209 GCMClient::IncomingMessage message_; | 209 GCMClient::IncomingMessage message_; |
| 210 std::string send_error_message_id_; | 210 std::string send_error_message_id_; |
| 211 GCMClient::Result send_error_result_; | 211 GCMClient::Result send_error_result_; |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 class FakeGCMClientFactory : public GCMClientFactory { | 214 class FakeGCMClientFactory : public GCMClientFactory { |
| 215 public: | 215 public: |
| 216 FakeGCMClientFactory( | 216 FakeGCMClientFactory( |
| 217 GCMClientMock::Status gcm_client_initial_status, | 217 GCMClientMock::CheckinDelay gcm_client_checkin_delay, |
| 218 GCMClientMock::ErrorSimulation gcm_client_error_simulation) | 218 GCMClientMock::ErrorSimulation gcm_client_error_simulation) |
| 219 : gcm_client_initial_status_(gcm_client_initial_status), | 219 : gcm_client_checkin_delay_(gcm_client_checkin_delay), |
| 220 gcm_client_error_simulation_(gcm_client_error_simulation), | 220 gcm_client_error_simulation_(gcm_client_error_simulation), |
| 221 gcm_client_(NULL) { | 221 gcm_client_(NULL) { |
| 222 } | 222 } |
| 223 | 223 |
| 224 virtual ~FakeGCMClientFactory() { | 224 virtual ~FakeGCMClientFactory() { |
| 225 } | 225 } |
| 226 | 226 |
| 227 virtual scoped_ptr<GCMClient> BuildInstance() OVERRIDE { | 227 virtual scoped_ptr<GCMClient> BuildInstance() OVERRIDE { |
| 228 gcm_client_ = new GCMClientMock(gcm_client_initial_status_, | 228 gcm_client_ = new GCMClientMock(gcm_client_checkin_delay_, |
| 229 gcm_client_error_simulation_); | 229 gcm_client_error_simulation_); |
| 230 return scoped_ptr<GCMClient>(gcm_client_); | 230 return scoped_ptr<GCMClient>(gcm_client_); |
| 231 } | 231 } |
| 232 | 232 |
| 233 GCMClientMock* gcm_client() const { return gcm_client_; } | 233 GCMClientMock* gcm_client() const { return gcm_client_; } |
| 234 | 234 |
| 235 private: | 235 private: |
| 236 GCMClientMock::Status gcm_client_initial_status_; | 236 GCMClientMock::CheckinDelay gcm_client_checkin_delay_; |
| 237 GCMClientMock::ErrorSimulation gcm_client_error_simulation_; | 237 GCMClientMock::ErrorSimulation gcm_client_error_simulation_; |
| 238 GCMClientMock* gcm_client_; | 238 GCMClientMock* gcm_client_; |
| 239 | 239 |
| 240 DISALLOW_COPY_AND_ASSIGN(FakeGCMClientFactory); | 240 DISALLOW_COPY_AND_ASSIGN(FakeGCMClientFactory); |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 class GCMProfileServiceTestConsumer : public GCMProfileService::TestingDelegate{ | 243 class GCMProfileServiceTestConsumer : public GCMProfileService::TestingDelegate{ |
| 244 public: | 244 public: |
| 245 static BrowserContextKeyedService* BuildFakeSigninManager( | 245 static BrowserContextKeyedService* BuildFakeSigninManager( |
| 246 content::BrowserContext* context) { | 246 content::BrowserContext* context) { |
| 247 return new FakeSigninManager(static_cast<Profile*>(context)); | 247 return new FakeSigninManager(static_cast<Profile*>(context)); |
| 248 } | 248 } |
| 249 | 249 |
| 250 static BrowserContextKeyedService* BuildGCMProfileService( | 250 static BrowserContextKeyedService* BuildGCMProfileService( |
| 251 content::BrowserContext* context) { | 251 content::BrowserContext* context) { |
| 252 return new GCMProfileService(static_cast<Profile*>(context)); | 252 return new GCMProfileService(static_cast<Profile*>(context)); |
| 253 } | 253 } |
| 254 | 254 |
| 255 explicit GCMProfileServiceTestConsumer(Waiter* waiter) | 255 explicit GCMProfileServiceTestConsumer(Waiter* waiter) |
| 256 : waiter_(waiter), | 256 : waiter_(waiter), |
| 257 extension_service_(NULL), | 257 extension_service_(NULL), |
| 258 signin_manager_(NULL), | 258 signin_manager_(NULL), |
| 259 gcm_client_initial_status_(GCMClientMock::READY), | 259 gcm_client_checkin_delay_(GCMClientMock::NO_CHECKIN_DELAY), |
| 260 gcm_client_error_simulation_(GCMClientMock::ALWAYS_SUCCEED), | 260 gcm_client_error_simulation_(GCMClientMock::ALWAYS_SUCCEED), |
| 261 registration_result_(GCMClient::SUCCESS), | 261 registration_result_(GCMClient::SUCCESS), |
| 262 has_persisted_registration_info_(false), | 262 has_persisted_registration_info_(false), |
| 263 send_result_(GCMClient::SUCCESS) { | 263 send_result_(GCMClient::SUCCESS) { |
| 264 // Create a new profile. | 264 // Create a new profile. |
| 265 profile_.reset(new TestingProfile); | 265 profile_.reset(new TestingProfile); |
| 266 | 266 |
| 267 // Use a fake version of SigninManager. | 267 // Use a fake version of SigninManager. |
| 268 signin_manager_ = static_cast<FakeSigninManager*>( | 268 signin_manager_ = static_cast<FakeSigninManager*>( |
| 269 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 269 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 270 profile(), &GCMProfileServiceTestConsumer::BuildFakeSigninManager)); | 270 profile(), &GCMProfileServiceTestConsumer::BuildFakeSigninManager)); |
| 271 | 271 |
| 272 // Create extension service in order to uninstall the extension. | 272 // Create extension service in order to uninstall the extension. |
| 273 extensions::TestExtensionSystem* extension_system( | 273 extensions::TestExtensionSystem* extension_system( |
| 274 static_cast<extensions::TestExtensionSystem*>( | 274 static_cast<extensions::TestExtensionSystem*>( |
| 275 extensions::ExtensionSystem::Get(profile()))); | 275 extensions::ExtensionSystem::Get(profile()))); |
| 276 extension_system->CreateExtensionService( | 276 extension_system->CreateExtensionService( |
| 277 CommandLine::ForCurrentProcess(), base::FilePath(), false); | 277 CommandLine::ForCurrentProcess(), base::FilePath(), false); |
| 278 extension_service_ = extension_system->Get(profile())->extension_service(); | 278 extension_service_ = extension_system->Get(profile())->extension_service(); |
| 279 | 279 |
| 280 // Enable GCM such that tests could be run on all channels. | 280 // Enable GCM such that tests could be run on all channels. |
| 281 GCMProfileService::enable_gcm_for_testing_ = true; | 281 GCMProfileService::enable_gcm_for_testing_ = true; |
| 282 profile()->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); | |
| 282 | 283 |
| 283 // Mock a GCMEventRouter. | 284 // Mock a GCMEventRouter. |
| 284 gcm_event_router_.reset(new FakeGCMEventRouter(waiter_)); | 285 gcm_event_router_.reset(new FakeGCMEventRouter(waiter_)); |
| 285 } | 286 } |
| 286 | 287 |
| 287 virtual ~GCMProfileServiceTestConsumer() { | 288 virtual ~GCMProfileServiceTestConsumer() { |
| 288 } | 289 } |
| 289 | 290 |
| 290 // Returns a barebones test extension. | 291 // Returns a barebones test extension. |
| 291 scoped_refptr<Extension> CreateExtension() { | 292 scoped_refptr<Extension> CreateExtension() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 extension->id(), UnloadedExtensionInfo::REASON_TERMINATE); | 328 extension->id(), UnloadedExtensionInfo::REASON_TERMINATE); |
| 328 extension_service_->AddExtension(extension); | 329 extension_service_->AddExtension(extension); |
| 329 } | 330 } |
| 330 | 331 |
| 331 void CreateGCMProfileServiceInstance() { | 332 void CreateGCMProfileServiceInstance() { |
| 332 GCMProfileService* gcm_profile_service = static_cast<GCMProfileService*>( | 333 GCMProfileService* gcm_profile_service = static_cast<GCMProfileService*>( |
| 333 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 334 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 334 profile(), &GCMProfileServiceTestConsumer::BuildGCMProfileService)); | 335 profile(), &GCMProfileServiceTestConsumer::BuildGCMProfileService)); |
| 335 gcm_profile_service->set_testing_delegate(this); | 336 gcm_profile_service->set_testing_delegate(this); |
| 336 scoped_ptr<GCMClientFactory> gcm_client_factory( | 337 scoped_ptr<GCMClientFactory> gcm_client_factory( |
| 337 new FakeGCMClientFactory(gcm_client_initial_status_, | 338 new FakeGCMClientFactory(gcm_client_checkin_delay_, |
| 338 gcm_client_error_simulation_)); | 339 gcm_client_error_simulation_)); |
| 339 gcm_profile_service->Initialize(gcm_client_factory.Pass()); | 340 gcm_profile_service->Initialize(gcm_client_factory.Pass()); |
| 340 waiter_->PumpIOLoop(); | 341 waiter_->PumpIOLoop(); |
| 341 } | 342 } |
| 342 | 343 |
| 343 void SignIn(const std::string& username) { | 344 void SignIn(const std::string& username) { |
| 344 signin_manager_->SignIn(username); | 345 signin_manager_->SignIn(username); |
| 345 waiter_->PumpIOLoop(); | 346 waiter_->PumpIOLoop(); |
| 346 waiter_->PumpUILoop(); | 347 waiter_->PumpUILoop(); |
| 347 } | 348 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 | 426 |
| 426 bool ExistsCachedRegistrationInfo() const { | 427 bool ExistsCachedRegistrationInfo() const { |
| 427 return !GetGCMProfileService()->registration_info_map_.empty(); | 428 return !GetGCMProfileService()->registration_info_map_.empty(); |
| 428 } | 429 } |
| 429 | 430 |
| 430 Profile* profile() const { return profile_.get(); } | 431 Profile* profile() const { return profile_.get(); } |
| 431 FakeGCMEventRouter* gcm_event_router() const { | 432 FakeGCMEventRouter* gcm_event_router() const { |
| 432 return gcm_event_router_.get(); | 433 return gcm_event_router_.get(); |
| 433 } | 434 } |
| 434 | 435 |
| 435 void set_gcm_client_initial_status(GCMClientMock::Status status) { | 436 void set_gcm_client_checkin_delay(GCMClientMock::CheckinDelay delay) { |
| 436 gcm_client_initial_status_ = status; | 437 gcm_client_checkin_delay_ = delay; |
| 437 } | 438 } |
| 438 void set_gcm_client_error_simulation(GCMClientMock::ErrorSimulation error) { | 439 void set_gcm_client_error_simulation(GCMClientMock::ErrorSimulation error) { |
| 439 gcm_client_error_simulation_ = error; | 440 gcm_client_error_simulation_ = error; |
| 440 } | 441 } |
| 441 | 442 |
| 442 const std::string& registration_id() const { return registration_id_; } | 443 const std::string& registration_id() const { return registration_id_; } |
| 443 GCMClient::Result registration_result() const { return registration_result_; } | 444 GCMClient::Result registration_result() const { return registration_result_; } |
| 444 const std::string& send_message_id() const { return send_message_id_; } | 445 const std::string& send_message_id() const { return send_message_id_; } |
| 445 GCMClient::Result send_result() const { return send_result_; } | 446 GCMClient::Result send_result() const { return send_result_; } |
| 446 | 447 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 458 virtual GCMEventRouter* GetEventRouter() const OVERRIDE { | 459 virtual GCMEventRouter* GetEventRouter() const OVERRIDE { |
| 459 return gcm_event_router_.get(); | 460 return gcm_event_router_.get(); |
| 460 } | 461 } |
| 461 | 462 |
| 462 Waiter* waiter_; // Not owned. | 463 Waiter* waiter_; // Not owned. |
| 463 scoped_ptr<TestingProfile> profile_; | 464 scoped_ptr<TestingProfile> profile_; |
| 464 ExtensionService* extension_service_; // Not owned. | 465 ExtensionService* extension_service_; // Not owned. |
| 465 FakeSigninManager* signin_manager_; // Not owned. | 466 FakeSigninManager* signin_manager_; // Not owned. |
| 466 scoped_ptr<FakeGCMEventRouter> gcm_event_router_; | 467 scoped_ptr<FakeGCMEventRouter> gcm_event_router_; |
| 467 | 468 |
| 468 GCMClientMock::Status gcm_client_initial_status_; | 469 GCMClientMock::CheckinDelay gcm_client_checkin_delay_; |
| 469 GCMClientMock::ErrorSimulation gcm_client_error_simulation_; | 470 GCMClientMock::ErrorSimulation gcm_client_error_simulation_; |
| 470 | 471 |
| 471 std::string registration_id_; | 472 std::string registration_id_; |
| 472 GCMClient::Result registration_result_; | 473 GCMClient::Result registration_result_; |
| 473 bool has_persisted_registration_info_; | 474 bool has_persisted_registration_info_; |
| 474 | 475 |
| 475 std::string send_message_id_; | 476 std::string send_message_id_; |
| 476 GCMClient::Result send_result_; | 477 GCMClient::Result send_result_; |
| 477 | 478 |
| 478 DISALLOW_COPY_AND_ASSIGN(GCMProfileServiceTestConsumer); | 479 DISALLOW_COPY_AND_ASSIGN(GCMProfileServiceTestConsumer); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 | 578 |
| 578 TEST_F(GCMProfileServiceTest, CreateGCMProfileServiceAfterProfileSignIn) { | 579 TEST_F(GCMProfileServiceTest, CreateGCMProfileServiceAfterProfileSignIn) { |
| 579 // Sign in to a profile. This will not initiate the check-in. | 580 // Sign in to a profile. This will not initiate the check-in. |
| 580 consumer()->SignIn(kTestingUsername); | 581 consumer()->SignIn(kTestingUsername); |
| 581 | 582 |
| 582 // Create GCMProfileService after sign-in. | 583 // Create GCMProfileService after sign-in. |
| 583 consumer()->CreateGCMProfileServiceInstance(); | 584 consumer()->CreateGCMProfileServiceInstance(); |
| 584 EXPECT_FALSE(consumer()->GetUsername().empty()); | 585 EXPECT_FALSE(consumer()->GetUsername().empty()); |
| 585 } | 586 } |
| 586 | 587 |
| 587 TEST_F(GCMProfileServiceTest, RegsiterWhenNotSignedIn) { | 588 TEST_F(GCMProfileServiceTest, SignInAndSignOutUnderPositiveChannelSignal) { |
| 589 // Positive channel signal is provided in SetUp. | |
| 590 consumer()->CreateGCMProfileServiceInstance(); | |
| 591 consumer()->SignIn(kTestingUsername); | |
| 592 | |
| 593 // GCMClient should be checked in. | |
| 594 EXPECT_TRUE(consumer()->IsGCMClientReady()); | |
| 595 EXPECT_EQ(GCMClientMock::CHECKED_IN, consumer()->GetGCMClient()->status()); | |
| 596 | |
| 597 consumer()->SignOut(); | |
| 598 | |
| 599 // GCMClient should be checked out. | |
| 600 EXPECT_FALSE(consumer()->IsGCMClientReady()); | |
| 601 EXPECT_EQ(GCMClientMock::CHECKED_OUT, consumer()->GetGCMClient()->status()); | |
| 602 } | |
| 603 | |
| 604 TEST_F(GCMProfileServiceTest, SignInAndSignOutUnderNegativeChannelSignal) { | |
|
fgorski
2014/02/20 22:18:40
Make sure to add a test where you invoke send or r
jianli
2014/02/21 18:25:11
Done.
| |
| 605 // Negative channel signal will cause GCMClient not checked in when the | |
|
fgorski
2014/02/20 22:18:40
will prevent GCMClient from checking in when
jianli
2014/02/21 18:25:11
Done.
| |
| 606 // profile is signed in. | |
| 607 profile()->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, false); | |
| 608 | |
| 609 consumer()->CreateGCMProfileServiceInstance(); | |
| 610 consumer()->SignIn(kTestingUsername); | |
| 611 | |
| 612 // GCMClient should not be checked in. | |
| 613 EXPECT_FALSE(consumer()->IsGCMClientReady()); | |
| 614 EXPECT_EQ(GCMClientMock::UNINITIALIZED, consumer()->GetGCMClient()->status()); | |
| 615 | |
| 616 consumer()->SignOut(); | |
| 617 | |
| 618 // Check-out should still be performed. | |
| 619 EXPECT_FALSE(consumer()->IsGCMClientReady()); | |
| 620 EXPECT_EQ(GCMClientMock::CHECKED_OUT, consumer()->GetGCMClient()->status()); | |
| 621 } | |
| 622 | |
| 623 TEST_F(GCMProfileServiceTest, SignOutAndThenSignIn) { | |
| 624 // Positive channel signal is provided in SetUp. | |
| 625 consumer()->CreateGCMProfileServiceInstance(); | |
| 626 consumer()->SignIn(kTestingUsername); | |
| 627 | |
| 628 // GCMClient should not be checked in. | |
| 629 EXPECT_TRUE(consumer()->IsGCMClientReady()); | |
| 630 EXPECT_EQ(GCMClientMock::CHECKED_IN, consumer()->GetGCMClient()->status()); | |
| 631 | |
| 632 consumer()->SignOut(); | |
| 633 | |
| 634 // GCMClient should be checked out. | |
| 635 EXPECT_FALSE(consumer()->IsGCMClientReady()); | |
| 636 EXPECT_EQ(GCMClientMock::CHECKED_OUT, consumer()->GetGCMClient()->status()); | |
| 637 | |
| 638 // Sign-in with a different username. | |
| 639 consumer()->SignIn(kTestingUsername2); | |
| 640 | |
| 641 // GCMClient should not be checked in again. | |
| 642 EXPECT_TRUE(consumer()->IsGCMClientReady()); | |
| 643 EXPECT_EQ(GCMClientMock::CHECKED_IN, consumer()->GetGCMClient()->status()); | |
| 644 } | |
| 645 | |
| 646 TEST_F(GCMProfileServiceTest, RegisterWhenNotSignedIn) { | |
| 647 consumer()->CreateGCMProfileServiceInstance(); | |
| 648 | |
| 588 std::vector<std::string> sender_ids; | 649 std::vector<std::string> sender_ids; |
| 589 sender_ids.push_back("sender1"); | 650 sender_ids.push_back("sender1"); |
| 590 consumer()->Register(kTestingAppId, sender_ids); | 651 consumer()->Register(kTestingAppId, sender_ids); |
| 591 | 652 |
| 592 EXPECT_TRUE(consumer()->registration_id().empty()); | 653 EXPECT_TRUE(consumer()->registration_id().empty()); |
| 593 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); | 654 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); |
| 594 } | 655 } |
| 595 | 656 |
| 596 TEST_F(GCMProfileServiceTest, SendWhenNotSignedIn) { | 657 TEST_F(GCMProfileServiceTest, SendWhenNotSignedIn) { |
| 658 consumer()->CreateGCMProfileServiceInstance(); | |
| 659 | |
| 597 GCMClient::OutgoingMessage message; | 660 GCMClient::OutgoingMessage message; |
| 598 message.id = "1"; | 661 message.id = "1"; |
| 599 message.data["key1"] = "value1"; | 662 message.data["key1"] = "value1"; |
| 600 consumer()->Send(kTestingAppId, kUserId, message); | 663 consumer()->Send(kTestingAppId, kUserId, message); |
| 601 | 664 |
| 602 EXPECT_TRUE(consumer()->send_message_id().empty()); | 665 EXPECT_TRUE(consumer()->send_message_id().empty()); |
| 603 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->send_result()); | 666 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->send_result()); |
| 604 } | 667 } |
| 605 | 668 |
| 606 // Tests single-profile. | 669 // Tests single-profile. |
| 607 class GCMProfileServiceSingleProfileTest : public GCMProfileServiceTest { | 670 class GCMProfileServiceSingleProfileTest : public GCMProfileServiceTest { |
| 608 public: | 671 public: |
| 609 GCMProfileServiceSingleProfileTest() { | 672 GCMProfileServiceSingleProfileTest() { |
| 610 } | 673 } |
| 611 | 674 |
| 612 virtual ~GCMProfileServiceSingleProfileTest() { | 675 virtual ~GCMProfileServiceSingleProfileTest() { |
| 613 } | 676 } |
| 614 | 677 |
| 615 virtual void SetUp() OVERRIDE { | 678 virtual void SetUp() OVERRIDE { |
| 616 GCMProfileServiceTest::SetUp(); | 679 GCMProfileServiceTest::SetUp(); |
| 617 | 680 |
| 618 consumer()->CreateGCMProfileServiceInstance(); | 681 consumer()->CreateGCMProfileServiceInstance(); |
| 619 consumer()->SignIn(kTestingUsername); | 682 consumer()->SignIn(kTestingUsername); |
| 620 } | 683 } |
| 621 }; | 684 }; |
| 622 | 685 |
| 623 TEST_F(GCMProfileServiceSingleProfileTest, SignOut) { | |
| 624 EXPECT_TRUE(consumer()->IsGCMClientReady()); | |
| 625 | |
| 626 // This will trigger check-out. | |
| 627 consumer()->SignOut(); | |
| 628 | |
| 629 EXPECT_FALSE(consumer()->IsGCMClientReady()); | |
| 630 } | |
| 631 | |
| 632 TEST_F(GCMProfileServiceSingleProfileTest, SignOutAndThenSignIn) { | |
| 633 EXPECT_TRUE(consumer()->IsGCMClientReady()); | |
| 634 | |
| 635 // This will trigger check-out. | |
| 636 consumer()->SignOut(); | |
| 637 | |
| 638 EXPECT_FALSE(consumer()->IsGCMClientReady()); | |
| 639 | |
| 640 // Sign-in with a different username. | |
| 641 consumer()->SignIn(kTestingUsername2); | |
| 642 | |
| 643 EXPECT_TRUE(consumer()->IsGCMClientReady()); | |
| 644 } | |
| 645 | |
| 646 TEST_F(GCMProfileServiceSingleProfileTest, Register) { | 686 TEST_F(GCMProfileServiceSingleProfileTest, Register) { |
| 647 std::vector<std::string> sender_ids; | 687 std::vector<std::string> sender_ids; |
| 648 sender_ids.push_back("sender1"); | 688 sender_ids.push_back("sender1"); |
| 649 consumer()->Register(kTestingAppId, sender_ids); | 689 consumer()->Register(kTestingAppId, sender_ids); |
| 650 std::string expected_registration_id = | 690 std::string expected_registration_id = |
| 651 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 691 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); |
| 652 | 692 |
| 653 WaitUntilCompleted(); | 693 WaitUntilCompleted(); |
| 654 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); | 694 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); |
| 655 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 695 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 | 821 |
| 782 WaitUntilCompleted(); | 822 WaitUntilCompleted(); |
| 783 EXPECT_FALSE(consumer()->registration_id().empty()); | 823 EXPECT_FALSE(consumer()->registration_id().empty()); |
| 784 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 824 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 785 std::string old_registration_id = consumer()->registration_id(); | 825 std::string old_registration_id = consumer()->registration_id(); |
| 786 | 826 |
| 787 // Clears the results that would be set by the Register callback in | 827 // Clears the results that would be set by the Register callback in |
| 788 // preparation to call register 2nd time. | 828 // preparation to call register 2nd time. |
| 789 consumer()->clear_registration_result(); | 829 consumer()->clear_registration_result(); |
| 790 | 830 |
| 791 // Needs to create a GCMClient instance that is not ready initiallly. | |
| 792 consumer()->set_gcm_client_initial_status(GCMClientMock::NOT_READY); | |
| 793 | |
| 794 // Simulate start-up by recreating GCMProfileService. | 831 // Simulate start-up by recreating GCMProfileService. |
| 832 consumer()->set_gcm_client_checkin_delay(GCMClientMock::CHECKIN_DELAY); | |
| 795 consumer()->CreateGCMProfileServiceInstance(); | 833 consumer()->CreateGCMProfileServiceInstance(); |
| 796 | 834 |
| 797 // Simulate start-up by reloading extension. | 835 // Simulate start-up by reloading extension. |
| 798 consumer()->ReloadExtension(extension); | 836 consumer()->ReloadExtension(extension); |
| 799 | 837 |
| 800 // Read the registration info from the extension's state store. | 838 // Read the registration info from the extension's state store. |
| 801 // This would hold up because GCMClient is in loading state. | 839 // This would hold up because GCMClient is in loading state. |
| 802 consumer()->Register(extension->id(), sender_ids); | 840 consumer()->Register(extension->id(), sender_ids); |
| 803 base::RunLoop().RunUntilIdle(); | 841 base::RunLoop().RunUntilIdle(); |
| 804 EXPECT_TRUE(consumer()->registration_id().empty()); | 842 EXPECT_TRUE(consumer()->registration_id().empty()); |
| 805 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, consumer()->registration_result()); | 843 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, consumer()->registration_result()); |
| 806 | 844 |
| 807 // Register operation will be invoked after GCMClient becomes ready. | 845 // Register operation will be invoked after GCMClient becomes ready. |
| 808 consumer()->GetGCMClient()->SetReady(); | 846 consumer()->GetGCMClient()->PerformDelayedCheckIn(); |
| 809 WaitUntilCompleted(); | 847 WaitUntilCompleted(); |
| 810 EXPECT_EQ(old_registration_id, consumer()->registration_id()); | 848 EXPECT_EQ(old_registration_id, consumer()->registration_id()); |
| 811 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 849 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 812 } | 850 } |
| 813 | 851 |
| 814 TEST_F(GCMProfileServiceSingleProfileTest, | 852 TEST_F(GCMProfileServiceSingleProfileTest, |
| 815 PersistedRegistrationInfoRemoveAfterSignOut) { | 853 PersistedRegistrationInfoRemoveAfterSignOut) { |
| 816 std::vector<std::string> sender_ids; | 854 std::vector<std::string> sender_ids; |
| 817 sender_ids.push_back("sender1"); | 855 sender_ids.push_back("sender1"); |
| 818 consumer()->Register(kTestingAppId, sender_ids); | 856 consumer()->Register(kTestingAppId, sender_ids); |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1262 consumer()->gcm_event_router()->clear_results(); | 1300 consumer()->gcm_event_router()->clear_results(); |
| 1263 WaitUntilCompleted(); | 1301 WaitUntilCompleted(); |
| 1264 | 1302 |
| 1265 EXPECT_EQ(FakeGCMEventRouter::MESSAGE_EVENT, | 1303 EXPECT_EQ(FakeGCMEventRouter::MESSAGE_EVENT, |
| 1266 consumer()->gcm_event_router()->received_event()); | 1304 consumer()->gcm_event_router()->received_event()); |
| 1267 EXPECT_TRUE( | 1305 EXPECT_TRUE( |
| 1268 in_message5.data == consumer()->gcm_event_router()->message().data); | 1306 in_message5.data == consumer()->gcm_event_router()->message().data); |
| 1269 } | 1307 } |
| 1270 | 1308 |
| 1271 } // namespace gcm | 1309 } // namespace gcm |
| OLD | NEW |