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 "chrome/browser/services/gcm/gcm_driver.h" | 5 #include "chrome/browser/services/gcm/gcm_driver.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" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "chrome/browser/services/gcm/fake_gcm_client.h" |
14 #include "chrome/browser/services/gcm/fake_gcm_client_factory.h" | 15 #include "chrome/browser/services/gcm/fake_gcm_client_factory.h" |
15 #include "chrome/browser/services/gcm/gcm_app_handler.h" | 16 #include "chrome/browser/services/gcm/gcm_app_handler.h" |
16 #include "chrome/browser/services/gcm/gcm_client_mock.h" | |
17 #include "components/gcm_driver/gcm_client_factory.h" | 17 #include "components/gcm_driver/gcm_client_factory.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "google_apis/gaia/fake_identity_provider.h" | 20 #include "google_apis/gaia/fake_identity_provider.h" |
21 #include "google_apis/gaia/fake_oauth2_token_service.h" | 21 #include "google_apis/gaia/fake_oauth2_token_service.h" |
22 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
23 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 namespace gcm { | 26 namespace gcm { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 const std::string& send_message_id() const { return send_message_id_; } | 225 const std::string& send_message_id() const { return send_message_id_; } |
226 GCMClient::Result send_result() const { return send_result_; } | 226 GCMClient::Result send_result() const { return send_result_; } |
227 GCMClient::Result unregistration_result() const { | 227 GCMClient::Result unregistration_result() const { |
228 return unregistration_result_; | 228 return unregistration_result_; |
229 } | 229 } |
230 | 230 |
231 void ClearRegistrationResult(); | 231 void ClearRegistrationResult(); |
232 void ClearUnregistrationResult(); | 232 void ClearUnregistrationResult(); |
233 | 233 |
234 bool HasAppHandlers() const; | 234 bool HasAppHandlers() const; |
235 GCMClientMock* GetGCMClient(); | 235 FakeGCMClient* GetGCMClient(); |
236 | 236 |
237 void CreateDriver(bool start_automatically, | 237 void CreateDriver(bool start_automatically, |
238 GCMClientMock::StartMode gcm_client_start_mode); | 238 FakeGCMClient::StartMode gcm_client_start_mode); |
239 | 239 |
240 void SignIn(const std::string& account_id); | 240 void SignIn(const std::string& account_id); |
241 void SignOut(); | 241 void SignOut(); |
242 | 242 |
243 void Register(const std::string& app_id, | 243 void Register(const std::string& app_id, |
244 const std::vector<std::string>& sender_ids, | 244 const std::vector<std::string>& sender_ids, |
245 WaitToFinish wait_to_finish); | 245 WaitToFinish wait_to_finish); |
246 void Send(const std::string& app_id, | 246 void Send(const std::string& app_id, |
247 const std::string& receiver_id, | 247 const std::string& receiver_id, |
248 const GCMClient::OutgoingMessage& message, | 248 const GCMClient::OutgoingMessage& message, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 | 308 |
309 void GCMDriverTest::ClearUnregistrationResult() { | 309 void GCMDriverTest::ClearUnregistrationResult() { |
310 unregistration_result_ = GCMClient::UNKNOWN_ERROR; | 310 unregistration_result_ = GCMClient::UNKNOWN_ERROR; |
311 } | 311 } |
312 | 312 |
313 bool GCMDriverTest::HasAppHandlers() const { | 313 bool GCMDriverTest::HasAppHandlers() const { |
314 return !driver_->app_handlers().empty(); | 314 return !driver_->app_handlers().empty(); |
315 } | 315 } |
316 | 316 |
317 GCMClientMock* GCMDriverTest::GetGCMClient() { | 317 FakeGCMClient* GCMDriverTest::GetGCMClient() { |
318 return static_cast<GCMClientMock*>(driver_->GetGCMClientForTesting()); | 318 return static_cast<FakeGCMClient*>(driver_->GetGCMClientForTesting()); |
319 } | 319 } |
320 | 320 |
321 void GCMDriverTest::CreateDriver( | 321 void GCMDriverTest::CreateDriver( |
322 bool start_automatically, | 322 bool start_automatically, |
323 GCMClientMock::StartMode gcm_client_start_mode) { | 323 FakeGCMClient::StartMode gcm_client_start_mode) { |
324 scoped_refptr<net::URLRequestContextGetter> request_context = | 324 scoped_refptr<net::URLRequestContextGetter> request_context = |
325 new net::TestURLRequestContextGetter( | 325 new net::TestURLRequestContextGetter( |
326 content::BrowserThread::GetMessageLoopProxyForThread( | 326 content::BrowserThread::GetMessageLoopProxyForThread( |
327 content::BrowserThread::IO)); | 327 content::BrowserThread::IO)); |
328 driver_.reset(new TestGCMDriver( | 328 driver_.reset(new TestGCMDriver( |
329 start_automatically, | 329 start_automatically, |
330 identity_provider_owner_.PassAs<IdentityProvider>(), | 330 identity_provider_owner_.PassAs<IdentityProvider>(), |
331 request_context)); | 331 request_context)); |
332 driver_->Initialize(scoped_ptr<GCMClientFactory>( | 332 driver_->Initialize(scoped_ptr<GCMClientFactory>( |
333 new FakeGCMClientFactory(gcm_client_start_mode))); | 333 new FakeGCMClientFactory(gcm_client_start_mode))); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 } | 412 } |
413 | 413 |
414 void GCMDriverTest::UnregisterCompleted(GCMClient::Result result) { | 414 void GCMDriverTest::UnregisterCompleted(GCMClient::Result result) { |
415 unregistration_result_ = result; | 415 unregistration_result_ = result; |
416 if (!async_operation_completed_callback_.is_null()) | 416 if (!async_operation_completed_callback_.is_null()) |
417 async_operation_completed_callback_.Run(); | 417 async_operation_completed_callback_.Run(); |
418 } | 418 } |
419 | 419 |
420 TEST_F(GCMDriverTest, CreateGCMDriverBeforeSignIn) { | 420 TEST_F(GCMDriverTest, CreateGCMDriverBeforeSignIn) { |
421 // Create CreateGMCService first. | 421 // Create CreateGMCService first. |
422 CreateDriver(true, GCMClientMock::NO_DELAY_START); | 422 CreateDriver(true, FakeGCMClient::NO_DELAY_START); |
423 EXPECT_FALSE(driver()->IsStarted()); | 423 EXPECT_FALSE(driver()->IsStarted()); |
424 | 424 |
425 // Sign in. This will kick off the check-in. | 425 // Sign in. This will kick off the check-in. |
426 SignIn(kTestAccountID1); | 426 SignIn(kTestAccountID1); |
427 EXPECT_TRUE(driver()->IsStarted()); | 427 EXPECT_TRUE(driver()->IsStarted()); |
428 } | 428 } |
429 | 429 |
430 TEST_F(GCMDriverTest, CreateGCMDriverAfterSignIn) { | 430 TEST_F(GCMDriverTest, CreateGCMDriverAfterSignIn) { |
431 // Sign in. This will not initiate the check-in. | 431 // Sign in. This will not initiate the check-in. |
432 SignIn(kTestAccountID1); | 432 SignIn(kTestAccountID1); |
433 | 433 |
434 // Create GCMeService after sign-in. | 434 // Create GCMeService after sign-in. |
435 CreateDriver(true, GCMClientMock::NO_DELAY_START); | 435 CreateDriver(true, FakeGCMClient::NO_DELAY_START); |
436 EXPECT_TRUE(driver()->IsStarted()); | 436 EXPECT_TRUE(driver()->IsStarted()); |
437 } | 437 } |
438 | 438 |
439 TEST_F(GCMDriverTest, Shutdown) { | 439 TEST_F(GCMDriverTest, Shutdown) { |
440 CreateDriver(true, GCMClientMock::NO_DELAY_START); | 440 CreateDriver(true, FakeGCMClient::NO_DELAY_START); |
441 EXPECT_TRUE(HasAppHandlers()); | 441 EXPECT_TRUE(HasAppHandlers()); |
442 | 442 |
443 driver()->ShutdownService(); | 443 driver()->ShutdownService(); |
444 EXPECT_FALSE(HasAppHandlers()); | 444 EXPECT_FALSE(HasAppHandlers()); |
445 } | 445 } |
446 | 446 |
447 TEST_F(GCMDriverTest, SignInAndSignOutUnderPositiveChannelSignal) { | 447 TEST_F(GCMDriverTest, SignInAndSignOutUnderPositiveChannelSignal) { |
448 CreateDriver(true, GCMClientMock::NO_DELAY_START); | 448 CreateDriver(true, FakeGCMClient::NO_DELAY_START); |
449 SignIn(kTestAccountID1); | 449 SignIn(kTestAccountID1); |
450 | 450 |
451 // GCMClient should be loaded. | 451 // GCMClient should be loaded. |
452 EXPECT_TRUE(driver()->IsGCMClientReady()); | 452 EXPECT_TRUE(driver()->IsGCMClientReady()); |
453 EXPECT_EQ(GCMClientMock::STARTED, GetGCMClient()->status()); | 453 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); |
454 | 454 |
455 SignOut(); | 455 SignOut(); |
456 | 456 |
457 // GCMClient should be checked out. | 457 // GCMClient should be checked out. |
458 EXPECT_FALSE(driver()->IsGCMClientReady()); | 458 EXPECT_FALSE(driver()->IsGCMClientReady()); |
459 EXPECT_EQ(GCMClientMock::CHECKED_OUT, GetGCMClient()->status()); | 459 EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status()); |
460 } | 460 } |
461 | 461 |
462 TEST_F(GCMDriverTest, SignInAndSignOutUnderNonPositiveChannelSignal) { | 462 TEST_F(GCMDriverTest, SignInAndSignOutUnderNonPositiveChannelSignal) { |
463 // Non-positive channel signal will prevent GCMClient from checking in during | 463 // Non-positive channel signal will prevent GCMClient from checking in during |
464 // sign-in. | 464 // sign-in. |
465 CreateDriver(false, GCMClientMock::NO_DELAY_START); | 465 CreateDriver(false, FakeGCMClient::NO_DELAY_START); |
466 SignIn(kTestAccountID1); | 466 SignIn(kTestAccountID1); |
467 | 467 |
468 // GCMClient should not be loaded. | 468 // GCMClient should not be loaded. |
469 EXPECT_FALSE(driver()->IsGCMClientReady()); | 469 EXPECT_FALSE(driver()->IsGCMClientReady()); |
470 EXPECT_EQ(GCMClientMock::UNINITIALIZED, GetGCMClient()->status()); | 470 EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status()); |
471 | 471 |
472 SignOut(); | 472 SignOut(); |
473 | 473 |
474 // Check-out should still be performed. | 474 // Check-out should still be performed. |
475 EXPECT_FALSE(driver()->IsGCMClientReady()); | 475 EXPECT_FALSE(driver()->IsGCMClientReady()); |
476 EXPECT_EQ(GCMClientMock::CHECKED_OUT, GetGCMClient()->status()); | 476 EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status()); |
477 } | 477 } |
478 | 478 |
479 TEST_F(GCMDriverTest, SignOutAndThenSignIn) { | 479 TEST_F(GCMDriverTest, SignOutAndThenSignIn) { |
480 CreateDriver(true, GCMClientMock::NO_DELAY_START); | 480 CreateDriver(true, FakeGCMClient::NO_DELAY_START); |
481 SignIn(kTestAccountID1); | 481 SignIn(kTestAccountID1); |
482 | 482 |
483 // GCMClient should be loaded. | 483 // GCMClient should be loaded. |
484 EXPECT_TRUE(driver()->IsGCMClientReady()); | 484 EXPECT_TRUE(driver()->IsGCMClientReady()); |
485 EXPECT_EQ(GCMClientMock::STARTED, GetGCMClient()->status()); | 485 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); |
486 | 486 |
487 SignOut(); | 487 SignOut(); |
488 | 488 |
489 // GCMClient should be checked out. | 489 // GCMClient should be checked out. |
490 EXPECT_FALSE(driver()->IsGCMClientReady()); | 490 EXPECT_FALSE(driver()->IsGCMClientReady()); |
491 EXPECT_EQ(GCMClientMock::CHECKED_OUT, GetGCMClient()->status()); | 491 EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status()); |
492 | 492 |
493 // Sign-in with a different account. | 493 // Sign-in with a different account. |
494 SignIn(kTestAccountID2); | 494 SignIn(kTestAccountID2); |
495 | 495 |
496 // GCMClient should be loaded again. | 496 // GCMClient should be loaded again. |
497 EXPECT_TRUE(driver()->IsGCMClientReady()); | 497 EXPECT_TRUE(driver()->IsGCMClientReady()); |
498 EXPECT_EQ(GCMClientMock::STARTED, GetGCMClient()->status()); | 498 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); |
499 } | 499 } |
500 | 500 |
501 TEST_F(GCMDriverTest, StopAndRestartGCM) { | 501 TEST_F(GCMDriverTest, StopAndRestartGCM) { |
502 CreateDriver(true, GCMClientMock::NO_DELAY_START); | 502 CreateDriver(true, FakeGCMClient::NO_DELAY_START); |
503 SignIn(kTestAccountID1); | 503 SignIn(kTestAccountID1); |
504 | 504 |
505 // GCMClient should be loaded. | 505 // GCMClient should be loaded. |
506 EXPECT_TRUE(driver()->IsGCMClientReady()); | 506 EXPECT_TRUE(driver()->IsGCMClientReady()); |
507 EXPECT_EQ(GCMClientMock::STARTED, GetGCMClient()->status()); | 507 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); |
508 | 508 |
509 // Stops the GCM. | 509 // Stops the GCM. |
510 driver()->Stop(); | 510 driver()->Stop(); |
511 PumpIOLoop(); | 511 PumpIOLoop(); |
512 PumpUILoop(); | 512 PumpUILoop(); |
513 | 513 |
514 // GCMClient should be stopped. | 514 // GCMClient should be stopped. |
515 EXPECT_FALSE(driver()->IsGCMClientReady()); | 515 EXPECT_FALSE(driver()->IsGCMClientReady()); |
516 EXPECT_EQ(GCMClientMock::STOPPED, GetGCMClient()->status()); | 516 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status()); |
517 | 517 |
518 // Restarts the GCM. | 518 // Restarts the GCM. |
519 driver()->Start(); | 519 driver()->Start(); |
520 PumpIOLoop(); | 520 PumpIOLoop(); |
521 PumpUILoop(); | 521 PumpUILoop(); |
522 | 522 |
523 // GCMClient should be loaded. | 523 // GCMClient should be loaded. |
524 EXPECT_TRUE(driver()->IsGCMClientReady()); | 524 EXPECT_TRUE(driver()->IsGCMClientReady()); |
525 EXPECT_EQ(GCMClientMock::STARTED, GetGCMClient()->status()); | 525 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); |
526 | 526 |
527 // Stops the GCM. | 527 // Stops the GCM. |
528 driver()->Stop(); | 528 driver()->Stop(); |
529 PumpIOLoop(); | 529 PumpIOLoop(); |
530 PumpUILoop(); | 530 PumpUILoop(); |
531 | 531 |
532 // GCMClient should be stopped. | 532 // GCMClient should be stopped. |
533 EXPECT_FALSE(driver()->IsGCMClientReady()); | 533 EXPECT_FALSE(driver()->IsGCMClientReady()); |
534 EXPECT_EQ(GCMClientMock::STOPPED, GetGCMClient()->status()); | 534 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status()); |
535 | 535 |
536 // Sign out. | 536 // Sign out. |
537 SignOut(); | 537 SignOut(); |
538 | 538 |
539 // GCMClient should be checked out. | 539 // GCMClient should be checked out. |
540 EXPECT_FALSE(driver()->IsGCMClientReady()); | 540 EXPECT_FALSE(driver()->IsGCMClientReady()); |
541 EXPECT_EQ(GCMClientMock::CHECKED_OUT, GetGCMClient()->status()); | 541 EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status()); |
542 } | 542 } |
543 | 543 |
544 TEST_F(GCMDriverTest, RegisterWhenNotSignedIn) { | 544 TEST_F(GCMDriverTest, RegisterWhenNotSignedIn) { |
545 CreateDriver(true, GCMClientMock::NO_DELAY_START); | 545 CreateDriver(true, FakeGCMClient::NO_DELAY_START); |
546 | 546 |
547 std::vector<std::string> sender_ids; | 547 std::vector<std::string> sender_ids; |
548 sender_ids.push_back("sender1"); | 548 sender_ids.push_back("sender1"); |
549 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); | 549 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); |
550 | 550 |
551 EXPECT_TRUE(registration_id().empty()); | 551 EXPECT_TRUE(registration_id().empty()); |
552 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, registration_result()); | 552 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, registration_result()); |
553 } | 553 } |
554 | 554 |
555 TEST_F(GCMDriverTest, RegisterUnderNonPositiveChannelSignal) { | 555 TEST_F(GCMDriverTest, RegisterUnderNonPositiveChannelSignal) { |
556 // Non-positive channel signal will prevent GCMClient from checking in during | 556 // Non-positive channel signal will prevent GCMClient from checking in during |
557 // sign-in. | 557 // sign-in. |
558 CreateDriver(false, GCMClientMock::NO_DELAY_START); | 558 CreateDriver(false, FakeGCMClient::NO_DELAY_START); |
559 SignIn(kTestAccountID1); | 559 SignIn(kTestAccountID1); |
560 | 560 |
561 // GCMClient should not be checked in. | 561 // GCMClient should not be checked in. |
562 EXPECT_FALSE(driver()->IsGCMClientReady()); | 562 EXPECT_FALSE(driver()->IsGCMClientReady()); |
563 EXPECT_EQ(GCMClientMock::UNINITIALIZED, GetGCMClient()->status()); | 563 EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status()); |
564 | 564 |
565 // Invoking register will make GCMClient checked in. | 565 // Invoking register will make GCMClient checked in. |
566 std::vector<std::string> sender_ids; | 566 std::vector<std::string> sender_ids; |
567 sender_ids.push_back("sender1"); | 567 sender_ids.push_back("sender1"); |
568 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); | 568 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); |
569 | 569 |
570 // GCMClient should be checked in. | 570 // GCMClient should be checked in. |
571 EXPECT_TRUE(driver()->IsGCMClientReady()); | 571 EXPECT_TRUE(driver()->IsGCMClientReady()); |
572 EXPECT_EQ(GCMClientMock::STARTED, GetGCMClient()->status()); | 572 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); |
573 | 573 |
574 // Registration should succeed. | 574 // Registration should succeed. |
575 const std::string expected_registration_id = | 575 const std::string expected_registration_id = |
576 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 576 FakeGCMClient::GetRegistrationIdFromSenderIds(sender_ids); |
577 EXPECT_EQ(expected_registration_id, registration_id()); | 577 EXPECT_EQ(expected_registration_id, registration_id()); |
578 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); | 578 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
579 } | 579 } |
580 | 580 |
581 TEST_F(GCMDriverTest, SendWhenNotSignedIn) { | 581 TEST_F(GCMDriverTest, SendWhenNotSignedIn) { |
582 CreateDriver(true, GCMClientMock::NO_DELAY_START); | 582 CreateDriver(true, FakeGCMClient::NO_DELAY_START); |
583 | 583 |
584 GCMClient::OutgoingMessage message; | 584 GCMClient::OutgoingMessage message; |
585 message.id = "1"; | 585 message.id = "1"; |
586 message.data["key1"] = "value1"; | 586 message.data["key1"] = "value1"; |
587 Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT); | 587 Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT); |
588 | 588 |
589 EXPECT_TRUE(send_message_id().empty()); | 589 EXPECT_TRUE(send_message_id().empty()); |
590 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, send_result()); | 590 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, send_result()); |
591 } | 591 } |
592 | 592 |
593 TEST_F(GCMDriverTest, SendUnderNonPositiveChannelSignal) { | 593 TEST_F(GCMDriverTest, SendUnderNonPositiveChannelSignal) { |
594 // Non-positive channel signal will prevent GCMClient from checking in during | 594 // Non-positive channel signal will prevent GCMClient from checking in during |
595 // sign-in. | 595 // sign-in. |
596 CreateDriver(false, GCMClientMock::NO_DELAY_START); | 596 CreateDriver(false, FakeGCMClient::NO_DELAY_START); |
597 SignIn(kTestAccountID1); | 597 SignIn(kTestAccountID1); |
598 | 598 |
599 // GCMClient should not be checked in. | 599 // GCMClient should not be checked in. |
600 EXPECT_FALSE(driver()->IsGCMClientReady()); | 600 EXPECT_FALSE(driver()->IsGCMClientReady()); |
601 EXPECT_EQ(GCMClientMock::UNINITIALIZED, GetGCMClient()->status()); | 601 EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status()); |
602 | 602 |
603 // Invoking send will make GCMClient checked in. | 603 // Invoking send will make GCMClient checked in. |
604 GCMClient::OutgoingMessage message; | 604 GCMClient::OutgoingMessage message; |
605 message.id = "1"; | 605 message.id = "1"; |
606 message.data["key1"] = "value1"; | 606 message.data["key1"] = "value1"; |
607 Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT); | 607 Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT); |
608 | 608 |
609 // GCMClient should be checked in. | 609 // GCMClient should be checked in. |
610 EXPECT_TRUE(driver()->IsGCMClientReady()); | 610 EXPECT_TRUE(driver()->IsGCMClientReady()); |
611 EXPECT_EQ(GCMClientMock::STARTED, GetGCMClient()->status()); | 611 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); |
612 | 612 |
613 // Sending should succeed. | 613 // Sending should succeed. |
614 EXPECT_EQ(message.id, send_message_id()); | 614 EXPECT_EQ(message.id, send_message_id()); |
615 EXPECT_EQ(GCMClient::SUCCESS, send_result()); | 615 EXPECT_EQ(GCMClient::SUCCESS, send_result()); |
616 } | 616 } |
617 | 617 |
618 TEST_F(GCMDriverTest, GCMClientNotReadyBeforeRegistration) { | 618 TEST_F(GCMDriverTest, GCMClientNotReadyBeforeRegistration) { |
619 // Make GCMClient not ready initially. | 619 // Make GCMClient not ready initially. |
620 CreateDriver(true, GCMClientMock::DELAY_START); | 620 CreateDriver(true, FakeGCMClient::DELAY_START); |
621 SignIn(kTestAccountID1); | 621 SignIn(kTestAccountID1); |
622 | 622 |
623 // The registration is on hold until GCMClient is ready. | 623 // The registration is on hold until GCMClient is ready. |
624 std::vector<std::string> sender_ids; | 624 std::vector<std::string> sender_ids; |
625 sender_ids.push_back("sender1"); | 625 sender_ids.push_back("sender1"); |
626 Register(kTestAppID1, | 626 Register(kTestAppID1, |
627 sender_ids, | 627 sender_ids, |
628 GCMDriverTest::DO_NOT_WAIT); | 628 GCMDriverTest::DO_NOT_WAIT); |
629 PumpIOLoop(); | 629 PumpIOLoop(); |
630 PumpUILoop(); | 630 PumpUILoop(); |
631 EXPECT_TRUE(registration_id().empty()); | 631 EXPECT_TRUE(registration_id().empty()); |
632 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, registration_result()); | 632 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, registration_result()); |
633 | 633 |
634 // Register operation will be invoked after GCMClient becomes ready. | 634 // Register operation will be invoked after GCMClient becomes ready. |
635 GetGCMClient()->PerformDelayedLoading(); | 635 GetGCMClient()->PerformDelayedLoading(); |
636 WaitForAsyncOperation(); | 636 WaitForAsyncOperation(); |
637 EXPECT_FALSE(registration_id().empty()); | 637 EXPECT_FALSE(registration_id().empty()); |
638 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); | 638 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
639 } | 639 } |
640 | 640 |
641 TEST_F(GCMDriverTest, GCMClientNotReadyBeforeSending) { | 641 TEST_F(GCMDriverTest, GCMClientNotReadyBeforeSending) { |
642 // Make GCMClient not ready initially. | 642 // Make GCMClient not ready initially. |
643 CreateDriver(true, GCMClientMock::DELAY_START); | 643 CreateDriver(true, FakeGCMClient::DELAY_START); |
644 SignIn(kTestAccountID1); | 644 SignIn(kTestAccountID1); |
645 | 645 |
646 // The sending is on hold until GCMClient is ready. | 646 // The sending is on hold until GCMClient is ready. |
647 GCMClient::OutgoingMessage message; | 647 GCMClient::OutgoingMessage message; |
648 message.id = "1"; | 648 message.id = "1"; |
649 message.data["key1"] = "value1"; | 649 message.data["key1"] = "value1"; |
650 message.data["key2"] = "value2"; | 650 message.data["key2"] = "value2"; |
651 Send(kTestAppID1, kUserID1, message, GCMDriverTest::DO_NOT_WAIT); | 651 Send(kTestAppID1, kUserID1, message, GCMDriverTest::DO_NOT_WAIT); |
652 PumpIOLoop(); | 652 PumpIOLoop(); |
653 PumpUILoop(); | 653 PumpUILoop(); |
(...skipping 23 matching lines...) Expand all Loading... |
677 | 677 |
678 GCMDriverFunctionalTest::GCMDriverFunctionalTest() { | 678 GCMDriverFunctionalTest::GCMDriverFunctionalTest() { |
679 } | 679 } |
680 | 680 |
681 GCMDriverFunctionalTest::~GCMDriverFunctionalTest() { | 681 GCMDriverFunctionalTest::~GCMDriverFunctionalTest() { |
682 } | 682 } |
683 | 683 |
684 void GCMDriverFunctionalTest::SetUp() { | 684 void GCMDriverFunctionalTest::SetUp() { |
685 GCMDriverTest::SetUp(); | 685 GCMDriverTest::SetUp(); |
686 | 686 |
687 CreateDriver(true, GCMClientMock::NO_DELAY_START); | 687 CreateDriver(true, FakeGCMClient::NO_DELAY_START); |
688 SignIn(kTestAccountID1); | 688 SignIn(kTestAccountID1); |
689 } | 689 } |
690 | 690 |
691 TEST_F(GCMDriverFunctionalTest, Register) { | 691 TEST_F(GCMDriverFunctionalTest, Register) { |
692 std::vector<std::string> sender_ids; | 692 std::vector<std::string> sender_ids; |
693 sender_ids.push_back("sender1"); | 693 sender_ids.push_back("sender1"); |
694 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); | 694 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); |
695 const std::string expected_registration_id = | 695 const std::string expected_registration_id = |
696 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 696 FakeGCMClient::GetRegistrationIdFromSenderIds(sender_ids); |
697 | 697 |
698 EXPECT_EQ(expected_registration_id, registration_id()); | 698 EXPECT_EQ(expected_registration_id, registration_id()); |
699 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); | 699 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
700 } | 700 } |
701 | 701 |
702 TEST_F(GCMDriverFunctionalTest, RegisterError) { | 702 TEST_F(GCMDriverFunctionalTest, RegisterError) { |
703 std::vector<std::string> sender_ids; | 703 std::vector<std::string> sender_ids; |
704 sender_ids.push_back("sender1@error"); | 704 sender_ids.push_back("sender1@error"); |
705 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); | 705 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); |
706 | 706 |
707 EXPECT_TRUE(registration_id().empty()); | 707 EXPECT_TRUE(registration_id().empty()); |
708 EXPECT_NE(GCMClient::SUCCESS, registration_result()); | 708 EXPECT_NE(GCMClient::SUCCESS, registration_result()); |
709 } | 709 } |
710 | 710 |
711 TEST_F(GCMDriverFunctionalTest, RegisterAgainWithSameSenderIDs) { | 711 TEST_F(GCMDriverFunctionalTest, RegisterAgainWithSameSenderIDs) { |
712 std::vector<std::string> sender_ids; | 712 std::vector<std::string> sender_ids; |
713 sender_ids.push_back("sender1"); | 713 sender_ids.push_back("sender1"); |
714 sender_ids.push_back("sender2"); | 714 sender_ids.push_back("sender2"); |
715 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); | 715 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); |
716 const std::string expected_registration_id = | 716 const std::string expected_registration_id = |
717 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 717 FakeGCMClient::GetRegistrationIdFromSenderIds(sender_ids); |
718 | 718 |
719 EXPECT_EQ(expected_registration_id, registration_id()); | 719 EXPECT_EQ(expected_registration_id, registration_id()); |
720 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); | 720 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
721 | 721 |
722 // Clears the results the would be set by the Register callback in preparation | 722 // Clears the results the would be set by the Register callback in preparation |
723 // to call register 2nd time. | 723 // to call register 2nd time. |
724 ClearRegistrationResult(); | 724 ClearRegistrationResult(); |
725 | 725 |
726 // Calling register 2nd time with the same set of sender IDs but different | 726 // Calling register 2nd time with the same set of sender IDs but different |
727 // ordering will get back the same registration ID. | 727 // ordering will get back the same registration ID. |
728 std::vector<std::string> another_sender_ids; | 728 std::vector<std::string> another_sender_ids; |
729 another_sender_ids.push_back("sender2"); | 729 another_sender_ids.push_back("sender2"); |
730 another_sender_ids.push_back("sender1"); | 730 another_sender_ids.push_back("sender1"); |
731 Register(kTestAppID1, another_sender_ids, GCMDriverTest::WAIT); | 731 Register(kTestAppID1, another_sender_ids, GCMDriverTest::WAIT); |
732 | 732 |
733 EXPECT_EQ(expected_registration_id, registration_id()); | 733 EXPECT_EQ(expected_registration_id, registration_id()); |
734 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); | 734 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
735 } | 735 } |
736 | 736 |
737 TEST_F(GCMDriverFunctionalTest, RegisterAgainWithDifferentSenderIDs) { | 737 TEST_F(GCMDriverFunctionalTest, RegisterAgainWithDifferentSenderIDs) { |
738 std::vector<std::string> sender_ids; | 738 std::vector<std::string> sender_ids; |
739 sender_ids.push_back("sender1"); | 739 sender_ids.push_back("sender1"); |
740 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); | 740 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); |
741 const std::string expected_registration_id = | 741 const std::string expected_registration_id = |
742 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 742 FakeGCMClient::GetRegistrationIdFromSenderIds(sender_ids); |
743 | 743 |
744 EXPECT_EQ(expected_registration_id, registration_id()); | 744 EXPECT_EQ(expected_registration_id, registration_id()); |
745 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); | 745 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
746 | 746 |
747 // Make sender IDs different. | 747 // Make sender IDs different. |
748 sender_ids.push_back("sender2"); | 748 sender_ids.push_back("sender2"); |
749 const std::string expected_registration_id2 = | 749 const std::string expected_registration_id2 = |
750 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 750 FakeGCMClient::GetRegistrationIdFromSenderIds(sender_ids); |
751 | 751 |
752 // Calling register 2nd time with the different sender IDs will get back a new | 752 // Calling register 2nd time with the different sender IDs will get back a new |
753 // registration ID. | 753 // registration ID. |
754 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); | 754 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); |
755 EXPECT_EQ(expected_registration_id2, registration_id()); | 755 EXPECT_EQ(expected_registration_id2, registration_id()); |
756 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); | 756 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
757 } | 757 } |
758 | 758 |
759 TEST_F(GCMDriverFunctionalTest, RegisterAfterSignOut) { | 759 TEST_F(GCMDriverFunctionalTest, RegisterAfterSignOut) { |
760 // This will trigger check-out. | 760 // This will trigger check-out. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 | 936 |
937 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { | 937 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { |
938 GetGCMClient()->DeleteMessages(kTestAppID1); | 938 GetGCMClient()->DeleteMessages(kTestAppID1); |
939 gcm_app_handler()->WaitForNotification(); | 939 gcm_app_handler()->WaitForNotification(); |
940 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, | 940 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, |
941 gcm_app_handler()->received_event()); | 941 gcm_app_handler()->received_event()); |
942 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); | 942 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); |
943 } | 943 } |
944 | 944 |
945 } // namespace gcm | 945 } // namespace gcm |
OLD | NEW |