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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
6 #include "chrome/browser/invalidation/gcm_invalidation_bridge.h" | 6 #include "chrome/browser/invalidation/gcm_invalidation_bridge.h" |
7 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 7 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
8 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 8 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| 11 #include "components/gcm_driver/fake_gcm_driver.h" |
11 #include "components/gcm_driver/gcm_driver.h" | 12 #include "components/gcm_driver/gcm_driver.h" |
12 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
13 #include "google_apis/gaia/fake_identity_provider.h" | 14 #include "google_apis/gaia/fake_identity_provider.h" |
14 #include "google_apis/gaia/google_service_auth_error.h" | 15 #include "google_apis/gaia/google_service_auth_error.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace invalidation { | 18 namespace invalidation { |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Implementation of GCMDriver::Register that always succeeds with the same | 21 // Implementation of GCMDriver::Register that always succeeds with the same |
21 // registrationId. | 22 // registrationId. |
22 class FakeGCMDriver : public gcm::GCMDriver { | 23 class CustomFakeGCMDriver : public gcm::FakeGCMDriver { |
23 public: | 24 public: |
24 FakeGCMDriver() {} | 25 CustomFakeGCMDriver() {} |
25 virtual ~FakeGCMDriver() {} | 26 virtual ~CustomFakeGCMDriver() {} |
26 | 27 |
| 28 // GCMDriver overrides: |
27 virtual void Register(const std::string& app_id, | 29 virtual void Register(const std::string& app_id, |
28 const std::vector<std::string>& sender_ids, | 30 const std::vector<std::string>& sender_ids, |
29 const RegisterCallback& callback) OVERRIDE { | 31 const RegisterCallback& callback) OVERRIDE { |
30 base::MessageLoop::current()->PostTask( | 32 base::MessageLoop::current()->PostTask( |
31 FROM_HERE, | 33 FROM_HERE, |
32 base::Bind( | 34 base::Bind( |
33 callback, std::string("registration.id"), gcm::GCMClient::SUCCESS)); | 35 callback, std::string("registration.id"), gcm::GCMClient::SUCCESS)); |
34 } | 36 } |
35 | 37 |
36 private: | 38 private: |
37 DISALLOW_COPY_AND_ASSIGN(FakeGCMDriver); | 39 DISALLOW_COPY_AND_ASSIGN(CustomFakeGCMDriver); |
38 }; | 40 }; |
39 | 41 |
40 class GCMInvalidationBridgeTest : public ::testing::Test { | 42 class GCMInvalidationBridgeTest : public ::testing::Test { |
41 protected: | 43 protected: |
42 GCMInvalidationBridgeTest() {} | 44 GCMInvalidationBridgeTest() {} |
43 | 45 |
44 virtual ~GCMInvalidationBridgeTest() {} | 46 virtual ~GCMInvalidationBridgeTest() {} |
45 | 47 |
46 virtual void SetUp() OVERRIDE { | 48 virtual void SetUp() OVERRIDE { |
47 TestingProfile::Builder builder; | 49 TestingProfile::Builder builder; |
48 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | 50 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), |
49 &BuildAutoIssuingFakeProfileOAuth2TokenService); | 51 &BuildAutoIssuingFakeProfileOAuth2TokenService); |
50 profile_ = builder.Build(); | 52 profile_ = builder.Build(); |
51 | 53 |
52 FakeProfileOAuth2TokenService* token_service = | 54 FakeProfileOAuth2TokenService* token_service = |
53 (FakeProfileOAuth2TokenService*) | 55 (FakeProfileOAuth2TokenService*) |
54 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 56 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
55 token_service->IssueRefreshTokenForUser("", "fake_refresh_token"); | 57 token_service->IssueRefreshTokenForUser("", "fake_refresh_token"); |
56 gcm_driver_.reset(new FakeGCMDriver()); | 58 gcm_driver_.reset(new CustomFakeGCMDriver()); |
57 | 59 |
58 identity_provider_.reset(new FakeIdentityProvider(token_service)); | 60 identity_provider_.reset(new FakeIdentityProvider(token_service)); |
59 bridge_.reset(new GCMInvalidationBridge(gcm_driver_.get(), | 61 bridge_.reset(new GCMInvalidationBridge(gcm_driver_.get(), |
60 identity_provider_.get())); | 62 identity_provider_.get())); |
61 | 63 |
62 delegate_ = bridge_->CreateDelegate(); | 64 delegate_ = bridge_->CreateDelegate(); |
63 delegate_->Initialize(); | 65 delegate_->Initialize(); |
64 base::RunLoop run_loop; | 66 base::RunLoop run_loop; |
65 run_loop.RunUntilIdle(); | 67 run_loop.RunUntilIdle(); |
66 } | 68 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 delegate_->Register(base::Bind(&GCMInvalidationBridgeTest::RegisterFinished, | 132 delegate_->Register(base::Bind(&GCMInvalidationBridgeTest::RegisterFinished, |
131 base::Unretained(this))); | 133 base::Unretained(this))); |
132 base::RunLoop run_loop; | 134 base::RunLoop run_loop; |
133 run_loop.RunUntilIdle(); | 135 run_loop.RunUntilIdle(); |
134 | 136 |
135 EXPECT_FALSE(registration_id_.empty()); | 137 EXPECT_FALSE(registration_id_.empty()); |
136 } | 138 } |
137 | 139 |
138 } // namespace | 140 } // namespace |
139 } // namespace invalidation | 141 } // namespace invalidation |
OLD | NEW |