OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/instance_id/instance_id_driver.h" | 5 #include "components/gcm_driver/instance_id/instance_id_driver.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/message_loop/message_loop.h" | |
14 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
15 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/test/scoped_task_environment.h" |
16 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" | 16 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" |
17 #include "components/gcm_driver/instance_id/instance_id.h" | 17 #include "components/gcm_driver/instance_id/instance_id.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
21 #include "components/gcm_driver/instance_id/instance_id_android.h" | 21 #include "components/gcm_driver/instance_id/instance_id_android.h" |
22 #include "components/gcm_driver/instance_id/scoped_use_fake_instance_id_android.
h" | 22 #include "components/gcm_driver/instance_id/scoped_use_fake_instance_id_android.
h" |
23 #endif // OS_ANDROID | 23 #endif // OS_ANDROID |
24 | 24 |
25 namespace instance_id { | 25 namespace instance_id { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 InstanceIDDriver* driver() const { return driver_.get(); } | 81 InstanceIDDriver* driver() const { return driver_.get(); } |
82 | 82 |
83 private: | 83 private: |
84 void GetIDCompleted(const std::string& id); | 84 void GetIDCompleted(const std::string& id); |
85 void GetCreationTimeCompleted(const base::Time& creation_time); | 85 void GetCreationTimeCompleted(const base::Time& creation_time); |
86 void DeleteIDCompleted(InstanceID::Result result); | 86 void DeleteIDCompleted(InstanceID::Result result); |
87 void GetTokenCompleted(const std::string& token, InstanceID::Result result); | 87 void GetTokenCompleted(const std::string& token, InstanceID::Result result); |
88 void DeleteTokenCompleted(InstanceID::Result result); | 88 void DeleteTokenCompleted(InstanceID::Result result); |
89 | 89 |
90 base::MessageLoopForUI message_loop_; | 90 base::test::ScopedTaskEnvironment scoped_task_environment_; |
91 std::unique_ptr<FakeGCMDriverForInstanceID> gcm_driver_; | 91 std::unique_ptr<FakeGCMDriverForInstanceID> gcm_driver_; |
92 std::unique_ptr<InstanceIDDriver> driver_; | 92 std::unique_ptr<InstanceIDDriver> driver_; |
93 | 93 |
94 #if defined(OS_ANDROID) | 94 #if defined(OS_ANDROID) |
95 InstanceIDAndroid::ScopedBlockOnAsyncTasksForTesting block_async_; | 95 InstanceIDAndroid::ScopedBlockOnAsyncTasksForTesting block_async_; |
96 ScopedUseFakeInstanceIDAndroid use_fake_; | 96 ScopedUseFakeInstanceIDAndroid use_fake_; |
97 #endif // OS_ANDROID | 97 #endif // OS_ANDROID |
98 | 98 |
99 std::string id_; | 99 std::string id_; |
100 base::Time creation_time_; | 100 base::Time creation_time_; |
101 std::string token_; | 101 std::string token_; |
102 InstanceID::Result result_; | 102 InstanceID::Result result_; |
103 | 103 |
104 bool async_operation_completed_; | 104 bool async_operation_completed_; |
105 base::Closure async_operation_completed_callback_; | 105 base::Closure async_operation_completed_callback_; |
106 | 106 |
107 DISALLOW_COPY_AND_ASSIGN(InstanceIDDriverTest); | 107 DISALLOW_COPY_AND_ASSIGN(InstanceIDDriverTest); |
108 }; | 108 }; |
109 | 109 |
110 InstanceIDDriverTest::InstanceIDDriverTest() | 110 InstanceIDDriverTest::InstanceIDDriverTest() |
111 : result_(InstanceID::UNKNOWN_ERROR), | 111 : scoped_task_environment_( |
112 async_operation_completed_(false) { | 112 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
113 } | 113 result_(InstanceID::UNKNOWN_ERROR), |
| 114 async_operation_completed_(false) {} |
114 | 115 |
115 InstanceIDDriverTest::~InstanceIDDriverTest() { | 116 InstanceIDDriverTest::~InstanceIDDriverTest() { |
116 } | 117 } |
117 | 118 |
118 void InstanceIDDriverTest::SetUp() { | 119 void InstanceIDDriverTest::SetUp() { |
119 gcm_driver_.reset(new FakeGCMDriverForInstanceID); | 120 gcm_driver_.reset(new FakeGCMDriverForInstanceID); |
120 RecreateInstanceIDDriver(); | 121 RecreateInstanceIDDriver(); |
121 } | 122 } |
122 | 123 |
123 void InstanceIDDriverTest::TearDown() { | 124 void InstanceIDDriverTest::TearDown() { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 GetToken(instance_id, kAuthorizedEntity1, kScope2, options); | 371 GetToken(instance_id, kAuthorizedEntity1, kScope2, options); |
371 EXPECT_FALSE(new_token1.empty()); | 372 EXPECT_FALSE(new_token1.empty()); |
372 EXPECT_NE(token1, new_token1); | 373 EXPECT_NE(token1, new_token1); |
373 | 374 |
374 // The other token is not affected by the deletion. | 375 // The other token is not affected by the deletion. |
375 EXPECT_EQ(token2, | 376 EXPECT_EQ(token2, |
376 GetToken(instance_id, kAuthorizedEntity2, kScope1, options)); | 377 GetToken(instance_id, kAuthorizedEntity2, kScope1, options)); |
377 } | 378 } |
378 | 379 |
379 } // namespace instance_id | 380 } // namespace instance_id |
OLD | NEW |