| 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 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 creation_time_ = base::Time(); | 136 creation_time_ = base::Time(); |
| 137 instance_id->GetCreationTime( | 137 instance_id->GetCreationTime( |
| 138 base::Bind(&InstanceIDDriverTest::GetCreationTimeCompleted, | 138 base::Bind(&InstanceIDDriverTest::GetCreationTimeCompleted, |
| 139 base::Unretained(this))); | 139 base::Unretained(this))); |
| 140 WaitForAsyncOperation(); | 140 WaitForAsyncOperation(); |
| 141 return creation_time_; | 141 return creation_time_; |
| 142 } | 142 } |
| 143 | 143 |
| 144 InstanceID::Result InstanceIDDriverTest::DeleteID(InstanceID* instance_id) { | 144 InstanceID::Result InstanceIDDriverTest::DeleteID(InstanceID* instance_id) { |
| 145 async_operation_completed_ = false; | 145 async_operation_completed_ = false; |
| 146 result_ = InstanceID::UNKNOWN_ERROR;; | 146 result_ = InstanceID::UNKNOWN_ERROR; |
| 147 instance_id->DeleteID(base::Bind(&InstanceIDDriverTest::DeleteIDCompleted, | 147 instance_id->DeleteID(base::Bind(&InstanceIDDriverTest::DeleteIDCompleted, |
| 148 base::Unretained(this))); | 148 base::Unretained(this))); |
| 149 WaitForAsyncOperation(); | 149 WaitForAsyncOperation(); |
| 150 return result_; | 150 return result_; |
| 151 } | 151 } |
| 152 | 152 |
| 153 std::string InstanceIDDriverTest::GetToken( | 153 std::string InstanceIDDriverTest::GetToken( |
| 154 InstanceID* instance_id, | 154 InstanceID* instance_id, |
| 155 const std::string& authorized_entity, | 155 const std::string& authorized_entity, |
| 156 const std::string& scope, | 156 const std::string& scope, |
| 157 const std::map<std::string, std::string>& options) { | 157 const std::map<std::string, std::string>& options) { |
| 158 async_operation_completed_ = false; | 158 async_operation_completed_ = false; |
| 159 token_.clear(); | 159 token_.clear(); |
| 160 result_ = InstanceID::UNKNOWN_ERROR;; | 160 result_ = InstanceID::UNKNOWN_ERROR; |
| 161 instance_id->GetToken( | 161 instance_id->GetToken( |
| 162 authorized_entity, | 162 authorized_entity, |
| 163 scope, | 163 scope, |
| 164 options, | 164 options, |
| 165 base::Bind(&InstanceIDDriverTest::GetTokenCompleted, | 165 base::Bind(&InstanceIDDriverTest::GetTokenCompleted, |
| 166 base::Unretained(this))); | 166 base::Unretained(this))); |
| 167 WaitForAsyncOperation(); | 167 WaitForAsyncOperation(); |
| 168 return token_; | 168 return token_; |
| 169 } | 169 } |
| 170 | 170 |
| 171 InstanceID::Result InstanceIDDriverTest::DeleteToken( | 171 InstanceID::Result InstanceIDDriverTest::DeleteToken( |
| 172 InstanceID* instance_id, | 172 InstanceID* instance_id, |
| 173 const std::string& authorized_entity, | 173 const std::string& authorized_entity, |
| 174 const std::string& scope) { | 174 const std::string& scope) { |
| 175 async_operation_completed_ = false; | 175 async_operation_completed_ = false; |
| 176 result_ = InstanceID::UNKNOWN_ERROR;; | 176 result_ = InstanceID::UNKNOWN_ERROR; |
| 177 instance_id->DeleteToken( | 177 instance_id->DeleteToken( |
| 178 authorized_entity, | 178 authorized_entity, |
| 179 scope, | 179 scope, |
| 180 base::Bind(&InstanceIDDriverTest::DeleteTokenCompleted, | 180 base::Bind(&InstanceIDDriverTest::DeleteTokenCompleted, |
| 181 base::Unretained(this))); | 181 base::Unretained(this))); |
| 182 WaitForAsyncOperation(); | 182 WaitForAsyncOperation(); |
| 183 return result_; | 183 return result_; |
| 184 } | 184 } |
| 185 | 185 |
| 186 void InstanceIDDriverTest::GetIDCompleted(const std::string& id) { | 186 void InstanceIDDriverTest::GetIDCompleted(const std::string& id) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 202 | 202 |
| 203 void InstanceIDDriverTest::DeleteIDCompleted(InstanceID::Result result) { | 203 void InstanceIDDriverTest::DeleteIDCompleted(InstanceID::Result result) { |
| 204 DCHECK(!async_operation_completed_); | 204 DCHECK(!async_operation_completed_); |
| 205 async_operation_completed_ = true; | 205 async_operation_completed_ = true; |
| 206 result_ = result; | 206 result_ = result; |
| 207 if (!async_operation_completed_callback_.is_null()) | 207 if (!async_operation_completed_callback_.is_null()) |
| 208 async_operation_completed_callback_.Run(); | 208 async_operation_completed_callback_.Run(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void InstanceIDDriverTest::GetTokenCompleted( | 211 void InstanceIDDriverTest::GetTokenCompleted( |
| 212 const std::string& token, InstanceID::Result result){ | 212 const std::string& token, InstanceID::Result result) { |
| 213 DCHECK(!async_operation_completed_); | 213 DCHECK(!async_operation_completed_); |
| 214 async_operation_completed_ = true; | 214 async_operation_completed_ = true; |
| 215 token_ = token; | 215 token_ = token; |
| 216 result_ = result; | 216 result_ = result; |
| 217 if (!async_operation_completed_callback_.is_null()) | 217 if (!async_operation_completed_callback_.is_null()) |
| 218 async_operation_completed_callback_.Run(); | 218 async_operation_completed_callback_.Run(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void InstanceIDDriverTest::DeleteTokenCompleted(InstanceID::Result result) { | 221 void InstanceIDDriverTest::DeleteTokenCompleted(InstanceID::Result result) { |
| 222 DCHECK(!async_operation_completed_); | 222 DCHECK(!async_operation_completed_); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 std::string new_token1 = | 350 std::string new_token1 = |
| 351 GetToken(instance_id, kAuthorizedEntity1, kScope2, options); | 351 GetToken(instance_id, kAuthorizedEntity1, kScope2, options); |
| 352 EXPECT_FALSE(new_token1.empty()); | 352 EXPECT_FALSE(new_token1.empty()); |
| 353 EXPECT_NE(token1, new_token1); | 353 EXPECT_NE(token1, new_token1); |
| 354 | 354 |
| 355 // The other token is not affected by the deletion. | 355 // The other token is not affected by the deletion. |
| 356 EXPECT_EQ(token2, | 356 EXPECT_EQ(token2, |
| 357 GetToken(instance_id, kAuthorizedEntity2, kScope1, options)); | 357 GetToken(instance_id, kAuthorizedEntity2, kScope1, options)); |
| 358 } | 358 } |
| 359 | 359 |
| 360 } // instance_id | 360 } // namespace instance_id |
| OLD | NEW |