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" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.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) | |
21 #include "components/gcm_driver/instance_id/instance_id_android.h" | |
22 #include "components/gcm_driver/instance_id/instance_id_test_utils_android.h" | |
23 #endif // OS_ANDROID | |
24 | |
20 namespace instance_id { | 25 namespace instance_id { |
21 | 26 |
22 namespace { | 27 namespace { |
23 | 28 |
24 const char kTestAppID1[] = "TestApp1"; | 29 const char kTestAppID1[] = "TestApp1"; |
25 const char kTestAppID2[] = "TestApp2"; | 30 const char kTestAppID2[] = "TestApp2"; |
26 const char kAuthorizedEntity1[] = "Sender 1"; | 31 const char kAuthorizedEntity1[] = "Sender 1"; |
27 const char kAuthorizedEntity2[] = "Sender 2"; | 32 const char kAuthorizedEntity2[] = "Sender 2"; |
28 const char kScope1[] = "GCM1"; | 33 const char kScope1[] = "GCM1"; |
29 const char kScope2[] = "FooBar"; | 34 const char kScope2[] = "FooBar"; |
(...skipping 15 matching lines...) Expand all Loading... | |
45 | 50 |
46 } // namespace | 51 } // namespace |
47 | 52 |
48 class InstanceIDDriverTest : public testing::Test { | 53 class InstanceIDDriverTest : public testing::Test { |
49 public: | 54 public: |
50 InstanceIDDriverTest(); | 55 InstanceIDDriverTest(); |
51 ~InstanceIDDriverTest() override; | 56 ~InstanceIDDriverTest() override; |
52 | 57 |
53 // testing::Test: | 58 // testing::Test: |
54 void SetUp() override; | 59 void SetUp() override; |
60 void TearDown() override; | |
55 | 61 |
56 void WaitForAsyncOperation(); | 62 void WaitForAsyncOperation(); |
57 | 63 |
58 // Recreates InstanceIDDriver to simulate restart. | 64 // Recreates InstanceIDDriver to simulate restart. |
59 void RecreateInstanceIDDriver(); | 65 void RecreateInstanceIDDriver(); |
60 | 66 |
61 // Sync wrappers for async version. | 67 // Sync wrappers for async version. |
62 std::string GetID(InstanceID* instance_id); | 68 std::string GetID(InstanceID* instance_id); |
63 base::Time GetCreationTime(InstanceID* instance_id); | 69 base::Time GetCreationTime(InstanceID* instance_id); |
64 InstanceID::Result DeleteID(InstanceID* instance_id); | 70 InstanceID::Result DeleteID(InstanceID* instance_id); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 | 104 |
99 InstanceIDDriverTest::InstanceIDDriverTest() | 105 InstanceIDDriverTest::InstanceIDDriverTest() |
100 : result_(InstanceID::UNKNOWN_ERROR), | 106 : result_(InstanceID::UNKNOWN_ERROR), |
101 async_operation_completed_(false) { | 107 async_operation_completed_(false) { |
102 } | 108 } |
103 | 109 |
104 InstanceIDDriverTest::~InstanceIDDriverTest() { | 110 InstanceIDDriverTest::~InstanceIDDriverTest() { |
105 } | 111 } |
106 | 112 |
107 void InstanceIDDriverTest::SetUp() { | 113 void InstanceIDDriverTest::SetUp() { |
114 #if defined(OS_ANDROID) | |
115 InstanceIDAndroid::SetBlockOnAsyncTasksForTesting(true); | |
116 InstanceIDTestUtilsAndroid::ClearDataAndSetUseFakeForTesting(true); | |
Peter Beverloo
2016/04/18 15:46:36
Would we ever used them separately? Could trigger
johnme
2016/04/19 11:15:43
I made them scoped objects. I left them separate f
| |
117 #endif // OS_ANDROID | |
108 gcm_driver_.reset(new FakeGCMDriverForInstanceID); | 118 gcm_driver_.reset(new FakeGCMDriverForInstanceID); |
109 RecreateInstanceIDDriver(); | 119 RecreateInstanceIDDriver(); |
110 } | 120 } |
111 | 121 |
122 void InstanceIDDriverTest::TearDown() { | |
123 #if defined(OS_ANDROID) | |
124 InstanceIDTestUtilsAndroid::ClearDataAndSetUseFakeForTesting(false); | |
125 InstanceIDAndroid::SetBlockOnAsyncTasksForTesting(false); | |
126 #endif // OS_ANDROID | |
127 } | |
128 | |
112 void InstanceIDDriverTest::RecreateInstanceIDDriver() { | 129 void InstanceIDDriverTest::RecreateInstanceIDDriver() { |
113 driver_.reset(new InstanceIDDriver(gcm_driver_.get())); | 130 driver_.reset(new InstanceIDDriver(gcm_driver_.get())); |
114 } | 131 } |
115 | 132 |
116 void InstanceIDDriverTest::WaitForAsyncOperation() { | 133 void InstanceIDDriverTest::WaitForAsyncOperation() { |
117 // No need to wait if async operation is not needed. | 134 // No need to wait if async operation is not needed. |
118 if (async_operation_completed_) | 135 if (async_operation_completed_) |
119 return; | 136 return; |
120 base::RunLoop run_loop; | 137 base::RunLoop run_loop; |
121 async_operation_completed_callback_ = run_loop.QuitClosure(); | 138 async_operation_completed_callback_ = run_loop.QuitClosure(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 GetToken(instance_id, kAuthorizedEntity1, kScope2, options); | 368 GetToken(instance_id, kAuthorizedEntity1, kScope2, options); |
352 EXPECT_FALSE(new_token1.empty()); | 369 EXPECT_FALSE(new_token1.empty()); |
353 EXPECT_NE(token1, new_token1); | 370 EXPECT_NE(token1, new_token1); |
354 | 371 |
355 // The other token is not affected by the deletion. | 372 // The other token is not affected by the deletion. |
356 EXPECT_EQ(token2, | 373 EXPECT_EQ(token2, |
357 GetToken(instance_id, kAuthorizedEntity2, kScope1, options)); | 374 GetToken(instance_id, kAuthorizedEntity2, kScope1, options)); |
358 } | 375 } |
359 | 376 |
360 } // namespace instance_id | 377 } // namespace instance_id |
OLD | NEW |