| 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 <stdint.h> |
| 6 |
| 5 #include <string> | 7 #include <string> |
| 6 #include <vector> | 8 #include <vector> |
| 7 | 9 |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/location.h" | 11 #include "base/location.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 14 #include "base/task_runner.h" | 16 #include "base/task_runner.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 48 |
| 47 // Task runner for handling delayed tasks posted by TPMTokenInfoGetter when | 49 // Task runner for handling delayed tasks posted by TPMTokenInfoGetter when |
| 48 // retrying failed cryptohome method calls. It just records the requested | 50 // retrying failed cryptohome method calls. It just records the requested |
| 49 // delay and immediately runs the task. The task is run asynchronously to be | 51 // delay and immediately runs the task. The task is run asynchronously to be |
| 50 // closer to what's actually happening in production. | 52 // closer to what's actually happening in production. |
| 51 // The delays used by TPMTokenGetter should be monotonically increasing, so | 53 // The delays used by TPMTokenGetter should be monotonically increasing, so |
| 52 // the fake task runner does not handle task reordering based on the delays. | 54 // the fake task runner does not handle task reordering based on the delays. |
| 53 class FakeTaskRunner : public base::TaskRunner { | 55 class FakeTaskRunner : public base::TaskRunner { |
| 54 public: | 56 public: |
| 55 // |delays|: Vector to which the dalays seen by the task runner are saved. | 57 // |delays|: Vector to which the dalays seen by the task runner are saved. |
| 56 explicit FakeTaskRunner(std::vector<int64>* delays) : delays_(delays) {} | 58 explicit FakeTaskRunner(std::vector<int64_t>* delays) : delays_(delays) {} |
| 57 | 59 |
| 58 // base::TaskRunner overrides: | 60 // base::TaskRunner overrides: |
| 59 bool PostDelayedTask(const tracked_objects::Location& from_here, | 61 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 60 const base::Closure& task, | 62 const base::Closure& task, |
| 61 base::TimeDelta delay) override { | 63 base::TimeDelta delay) override { |
| 62 delays_->push_back(delay.InMilliseconds()); | 64 delays_->push_back(delay.InMilliseconds()); |
| 63 base::ThreadTaskRunnerHandle::Get()->PostTask(from_here, task); | 65 base::ThreadTaskRunnerHandle::Get()->PostTask(from_here, task); |
| 64 return true; | 66 return true; |
| 65 } | 67 } |
| 66 bool RunsTasksOnCurrentThread() const override { return true; } | 68 bool RunsTasksOnCurrentThread() const override { return true; } |
| 67 | 69 |
| 68 protected: | 70 protected: |
| 69 ~FakeTaskRunner() override {} | 71 ~FakeTaskRunner() override {} |
| 70 | 72 |
| 71 private: | 73 private: |
| 72 // The vector of delays. | 74 // The vector of delays. |
| 73 std::vector<int64>* delays_; | 75 std::vector<int64_t>* delays_; |
| 74 | 76 |
| 75 DISALLOW_COPY_AND_ASSIGN(FakeTaskRunner); | 77 DISALLOW_COPY_AND_ASSIGN(FakeTaskRunner); |
| 76 }; | 78 }; |
| 77 | 79 |
| 78 // Implementation of CryptohomeClient used in these tests. Note that | 80 // Implementation of CryptohomeClient used in these tests. Note that |
| 79 // TestCryptohomeClient implements FakeCryptohomeClient purely for convenience | 81 // TestCryptohomeClient implements FakeCryptohomeClient purely for convenience |
| 80 // of not having to implement whole CryptohomeClient interface. | 82 // of not having to implement whole CryptohomeClient interface. |
| 81 // TestCryptohomeClient overrides all CryptohomeClient methods used in | 83 // TestCryptohomeClient overrides all CryptohomeClient methods used in |
| 82 // TPMTokenInfoGetter tests. | 84 // TPMTokenInfoGetter tests. |
| 83 class TestCryptohomeClient : public chromeos::FakeCryptohomeClient { | 85 class TestCryptohomeClient : public chromeos::FakeCryptohomeClient { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 tpm_token_info_getter_ = | 241 tpm_token_info_getter_ = |
| 240 chromeos::TPMTokenInfoGetter::CreateForSystemToken( | 242 chromeos::TPMTokenInfoGetter::CreateForSystemToken( |
| 241 cryptohome_client_.get(), | 243 cryptohome_client_.get(), |
| 242 scoped_refptr<base::TaskRunner>(new FakeTaskRunner(&delays_))); | 244 scoped_refptr<base::TaskRunner>(new FakeTaskRunner(&delays_))); |
| 243 } | 245 } |
| 244 | 246 |
| 245 protected: | 247 protected: |
| 246 scoped_ptr<TestCryptohomeClient> cryptohome_client_; | 248 scoped_ptr<TestCryptohomeClient> cryptohome_client_; |
| 247 scoped_ptr<chromeos::TPMTokenInfoGetter> tpm_token_info_getter_; | 249 scoped_ptr<chromeos::TPMTokenInfoGetter> tpm_token_info_getter_; |
| 248 | 250 |
| 249 std::vector<int64> delays_; | 251 std::vector<int64_t> delays_; |
| 250 | 252 |
| 251 private: | 253 private: |
| 252 base::MessageLoop message_loop_; | 254 base::MessageLoop message_loop_; |
| 253 | 255 |
| 254 DISALLOW_COPY_AND_ASSIGN(SystemTPMTokenInfoGetterTest); | 256 DISALLOW_COPY_AND_ASSIGN(SystemTPMTokenInfoGetterTest); |
| 255 }; | 257 }; |
| 256 | 258 |
| 257 class UserTPMTokenInfoGetterTest : public testing::Test { | 259 class UserTPMTokenInfoGetterTest : public testing::Test { |
| 258 public: | 260 public: |
| 259 UserTPMTokenInfoGetterTest() : user_id_("user") {} | 261 UserTPMTokenInfoGetterTest() : user_id_("user") {} |
| 260 ~UserTPMTokenInfoGetterTest() override {} | 262 ~UserTPMTokenInfoGetterTest() override {} |
| 261 | 263 |
| 262 void SetUp() override { | 264 void SetUp() override { |
| 263 cryptohome_client_.reset(new TestCryptohomeClient(user_id_)); | 265 cryptohome_client_.reset(new TestCryptohomeClient(user_id_)); |
| 264 tpm_token_info_getter_ = | 266 tpm_token_info_getter_ = |
| 265 chromeos::TPMTokenInfoGetter::CreateForUserToken( | 267 chromeos::TPMTokenInfoGetter::CreateForUserToken( |
| 266 user_id_, | 268 user_id_, |
| 267 cryptohome_client_.get(), | 269 cryptohome_client_.get(), |
| 268 scoped_refptr<base::TaskRunner>(new FakeTaskRunner(&delays_))); | 270 scoped_refptr<base::TaskRunner>(new FakeTaskRunner(&delays_))); |
| 269 } | 271 } |
| 270 | 272 |
| 271 protected: | 273 protected: |
| 272 scoped_ptr<TestCryptohomeClient> cryptohome_client_; | 274 scoped_ptr<TestCryptohomeClient> cryptohome_client_; |
| 273 scoped_ptr<chromeos::TPMTokenInfoGetter> tpm_token_info_getter_; | 275 scoped_ptr<chromeos::TPMTokenInfoGetter> tpm_token_info_getter_; |
| 274 | 276 |
| 275 std::string user_id_; | 277 std::string user_id_; |
| 276 std::vector<int64> delays_; | 278 std::vector<int64_t> delays_; |
| 277 | 279 |
| 278 private: | 280 private: |
| 279 base::MessageLoop message_loop_; | 281 base::MessageLoop message_loop_; |
| 280 | 282 |
| 281 DISALLOW_COPY_AND_ASSIGN(UserTPMTokenInfoGetterTest); | 283 DISALLOW_COPY_AND_ASSIGN(UserTPMTokenInfoGetterTest); |
| 282 }; | 284 }; |
| 283 | 285 |
| 284 TEST_F(SystemTPMTokenInfoGetterTest, BasicFlow) { | 286 TEST_F(SystemTPMTokenInfoGetterTest, BasicFlow) { |
| 285 TestTPMTokenInfo reported_info; | 287 TestTPMTokenInfo reported_info; |
| 286 tpm_token_info_getter_->Start( | 288 tpm_token_info_getter_->Start( |
| 287 base::Bind(&RecordGetterResult, &reported_info)); | 289 base::Bind(&RecordGetterResult, &reported_info)); |
| 288 base::RunLoop().RunUntilIdle(); | 290 base::RunLoop().RunUntilIdle(); |
| 289 | 291 |
| 290 EXPECT_FALSE(reported_info.IsReady()); | 292 EXPECT_FALSE(reported_info.IsReady()); |
| 291 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); | 293 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); |
| 292 | 294 |
| 293 EXPECT_TRUE(reported_info.IsReady()); | 295 EXPECT_TRUE(reported_info.IsReady()); |
| 294 EXPECT_TRUE(reported_info.enabled); | 296 EXPECT_TRUE(reported_info.enabled); |
| 295 EXPECT_EQ("TOKEN_1", reported_info.name); | 297 EXPECT_EQ("TOKEN_1", reported_info.name); |
| 296 EXPECT_EQ("2222", reported_info.pin); | 298 EXPECT_EQ("2222", reported_info.pin); |
| 297 EXPECT_EQ(1, reported_info.slot_id); | 299 EXPECT_EQ(1, reported_info.slot_id); |
| 298 | 300 |
| 299 EXPECT_EQ(std::vector<int64>(), delays_); | 301 EXPECT_EQ(std::vector<int64_t>(), delays_); |
| 300 } | 302 } |
| 301 | 303 |
| 302 TEST_F(SystemTPMTokenInfoGetterTest, TokenSlotIdEqualsZero) { | 304 TEST_F(SystemTPMTokenInfoGetterTest, TokenSlotIdEqualsZero) { |
| 303 TestTPMTokenInfo reported_info; | 305 TestTPMTokenInfo reported_info; |
| 304 tpm_token_info_getter_->Start( | 306 tpm_token_info_getter_->Start( |
| 305 base::Bind(&RecordGetterResult, &reported_info)); | 307 base::Bind(&RecordGetterResult, &reported_info)); |
| 306 base::RunLoop().RunUntilIdle(); | 308 base::RunLoop().RunUntilIdle(); |
| 307 | 309 |
| 308 EXPECT_FALSE(reported_info.IsReady()); | 310 EXPECT_FALSE(reported_info.IsReady()); |
| 309 cryptohome_client_->SetTPMTokenInfo("TOKEN_0", "2222", 0); | 311 cryptohome_client_->SetTPMTokenInfo("TOKEN_0", "2222", 0); |
| 310 | 312 |
| 311 EXPECT_TRUE(reported_info.IsReady()); | 313 EXPECT_TRUE(reported_info.IsReady()); |
| 312 base::RunLoop().RunUntilIdle(); | 314 base::RunLoop().RunUntilIdle(); |
| 313 | 315 |
| 314 EXPECT_TRUE(reported_info.enabled); | 316 EXPECT_TRUE(reported_info.enabled); |
| 315 EXPECT_EQ("TOKEN_0", reported_info.name); | 317 EXPECT_EQ("TOKEN_0", reported_info.name); |
| 316 EXPECT_EQ("2222", reported_info.pin); | 318 EXPECT_EQ("2222", reported_info.pin); |
| 317 EXPECT_EQ(0, reported_info.slot_id); | 319 EXPECT_EQ(0, reported_info.slot_id); |
| 318 | 320 |
| 319 EXPECT_EQ(std::vector<int64>(), delays_); | 321 EXPECT_EQ(std::vector<int64_t>(), delays_); |
| 320 } | 322 } |
| 321 | 323 |
| 322 TEST_F(SystemTPMTokenInfoGetterTest, TPMNotEnabled) { | 324 TEST_F(SystemTPMTokenInfoGetterTest, TPMNotEnabled) { |
| 323 cryptohome_client_->set_tpm_is_enabled(false); | 325 cryptohome_client_->set_tpm_is_enabled(false); |
| 324 | 326 |
| 325 TestTPMTokenInfo reported_info; | 327 TestTPMTokenInfo reported_info; |
| 326 tpm_token_info_getter_->Start( | 328 tpm_token_info_getter_->Start( |
| 327 base::Bind(&RecordGetterResult, &reported_info)); | 329 base::Bind(&RecordGetterResult, &reported_info)); |
| 328 base::RunLoop().RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
| 329 | 331 |
| 330 EXPECT_FALSE(reported_info.IsReady()); | 332 EXPECT_FALSE(reported_info.IsReady()); |
| 331 EXPECT_FALSE(reported_info.enabled); | 333 EXPECT_FALSE(reported_info.enabled); |
| 332 | 334 |
| 333 EXPECT_EQ(std::vector<int64>(), delays_); | 335 EXPECT_EQ(std::vector<int64_t>(), delays_); |
| 334 } | 336 } |
| 335 | 337 |
| 336 TEST_F(SystemTPMTokenInfoGetterTest, TpmEnabledCallFails) { | 338 TEST_F(SystemTPMTokenInfoGetterTest, TpmEnabledCallFails) { |
| 337 cryptohome_client_->set_tpm_is_enabled_failure_count(1); | 339 cryptohome_client_->set_tpm_is_enabled_failure_count(1); |
| 338 | 340 |
| 339 TestTPMTokenInfo reported_info; | 341 TestTPMTokenInfo reported_info; |
| 340 tpm_token_info_getter_->Start( | 342 tpm_token_info_getter_->Start( |
| 341 base::Bind(&RecordGetterResult, &reported_info)); | 343 base::Bind(&RecordGetterResult, &reported_info)); |
| 342 base::RunLoop().RunUntilIdle(); | 344 base::RunLoop().RunUntilIdle(); |
| 343 | 345 |
| 344 EXPECT_FALSE(reported_info.IsReady()); | 346 EXPECT_FALSE(reported_info.IsReady()); |
| 345 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); | 347 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); |
| 346 | 348 |
| 347 EXPECT_TRUE(reported_info.IsReady()); | 349 EXPECT_TRUE(reported_info.IsReady()); |
| 348 EXPECT_TRUE(reported_info.enabled); | 350 EXPECT_TRUE(reported_info.enabled); |
| 349 EXPECT_EQ("TOKEN_1", reported_info.name); | 351 EXPECT_EQ("TOKEN_1", reported_info.name); |
| 350 EXPECT_EQ("2222", reported_info.pin); | 352 EXPECT_EQ("2222", reported_info.pin); |
| 351 EXPECT_EQ(1, reported_info.slot_id); | 353 EXPECT_EQ(1, reported_info.slot_id); |
| 352 | 354 |
| 353 const int64 kExpectedDelays[] = {100}; | 355 const int64_t kExpectedDelays[] = {100}; |
| 354 EXPECT_EQ(std::vector<int64>(kExpectedDelays, | 356 EXPECT_EQ(std::vector<int64_t>(kExpectedDelays, |
| 355 kExpectedDelays + arraysize(kExpectedDelays)), | 357 kExpectedDelays + arraysize(kExpectedDelays)), |
| 356 delays_); | 358 delays_); |
| 357 } | 359 } |
| 358 | 360 |
| 359 TEST_F(SystemTPMTokenInfoGetterTest, GetTpmTokenInfoInitiallyNotReady) { | 361 TEST_F(SystemTPMTokenInfoGetterTest, GetTpmTokenInfoInitiallyNotReady) { |
| 360 cryptohome_client_->set_get_tpm_token_info_not_set_count(1); | 362 cryptohome_client_->set_get_tpm_token_info_not_set_count(1); |
| 361 | 363 |
| 362 TestTPMTokenInfo reported_info; | 364 TestTPMTokenInfo reported_info; |
| 363 tpm_token_info_getter_->Start( | 365 tpm_token_info_getter_->Start( |
| 364 base::Bind(&RecordGetterResult, &reported_info)); | 366 base::Bind(&RecordGetterResult, &reported_info)); |
| 365 base::RunLoop().RunUntilIdle(); | 367 base::RunLoop().RunUntilIdle(); |
| 366 | 368 |
| 367 EXPECT_FALSE(reported_info.IsReady()); | 369 EXPECT_FALSE(reported_info.IsReady()); |
| 368 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); | 370 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); |
| 369 | 371 |
| 370 EXPECT_TRUE(reported_info.IsReady()); | 372 EXPECT_TRUE(reported_info.IsReady()); |
| 371 EXPECT_TRUE(reported_info.enabled); | 373 EXPECT_TRUE(reported_info.enabled); |
| 372 EXPECT_EQ("TOKEN_1", reported_info.name); | 374 EXPECT_EQ("TOKEN_1", reported_info.name); |
| 373 EXPECT_EQ("2222", reported_info.pin); | 375 EXPECT_EQ("2222", reported_info.pin); |
| 374 EXPECT_EQ(1, reported_info.slot_id); | 376 EXPECT_EQ(1, reported_info.slot_id); |
| 375 | 377 |
| 376 const int64 kExpectedDelays[] = {100}; | 378 const int64_t kExpectedDelays[] = {100}; |
| 377 EXPECT_EQ(std::vector<int64>(kExpectedDelays, | 379 EXPECT_EQ(std::vector<int64_t>(kExpectedDelays, |
| 378 kExpectedDelays + arraysize(kExpectedDelays)), | 380 kExpectedDelays + arraysize(kExpectedDelays)), |
| 379 delays_); | 381 delays_); |
| 380 } | 382 } |
| 381 | 383 |
| 382 TEST_F(SystemTPMTokenInfoGetterTest, GetTpmTokenInfoInitiallyFails) { | 384 TEST_F(SystemTPMTokenInfoGetterTest, GetTpmTokenInfoInitiallyFails) { |
| 383 cryptohome_client_->set_get_tpm_token_info_failure_count(1); | 385 cryptohome_client_->set_get_tpm_token_info_failure_count(1); |
| 384 | 386 |
| 385 TestTPMTokenInfo reported_info; | 387 TestTPMTokenInfo reported_info; |
| 386 tpm_token_info_getter_->Start( | 388 tpm_token_info_getter_->Start( |
| 387 base::Bind(&RecordGetterResult, &reported_info)); | 389 base::Bind(&RecordGetterResult, &reported_info)); |
| 388 base::RunLoop().RunUntilIdle(); | 390 base::RunLoop().RunUntilIdle(); |
| 389 | 391 |
| 390 EXPECT_FALSE(reported_info.IsReady()); | 392 EXPECT_FALSE(reported_info.IsReady()); |
| 391 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); | 393 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); |
| 392 | 394 |
| 393 EXPECT_TRUE(reported_info.IsReady()); | 395 EXPECT_TRUE(reported_info.IsReady()); |
| 394 EXPECT_TRUE(reported_info.enabled); | 396 EXPECT_TRUE(reported_info.enabled); |
| 395 EXPECT_EQ("TOKEN_1", reported_info.name); | 397 EXPECT_EQ("TOKEN_1", reported_info.name); |
| 396 EXPECT_EQ("2222", reported_info.pin); | 398 EXPECT_EQ("2222", reported_info.pin); |
| 397 EXPECT_EQ(1, reported_info.slot_id); | 399 EXPECT_EQ(1, reported_info.slot_id); |
| 398 | 400 |
| 399 const int64 kExpectedDelays[] = {100}; | 401 const int64_t kExpectedDelays[] = {100}; |
| 400 EXPECT_EQ(std::vector<int64>(kExpectedDelays, | 402 EXPECT_EQ(std::vector<int64_t>(kExpectedDelays, |
| 401 kExpectedDelays + arraysize(kExpectedDelays)), | 403 kExpectedDelays + arraysize(kExpectedDelays)), |
| 402 delays_); | 404 delays_); |
| 403 } | 405 } |
| 404 | 406 |
| 405 TEST_F(SystemTPMTokenInfoGetterTest, RetryDelaysIncreaseExponentially) { | 407 TEST_F(SystemTPMTokenInfoGetterTest, RetryDelaysIncreaseExponentially) { |
| 406 cryptohome_client_->set_tpm_is_enabled_failure_count(2); | 408 cryptohome_client_->set_tpm_is_enabled_failure_count(2); |
| 407 cryptohome_client_->set_get_tpm_token_info_failure_count(1); | 409 cryptohome_client_->set_get_tpm_token_info_failure_count(1); |
| 408 cryptohome_client_->set_get_tpm_token_info_not_set_count(3); | 410 cryptohome_client_->set_get_tpm_token_info_not_set_count(3); |
| 409 | 411 |
| 410 TestTPMTokenInfo reported_info; | 412 TestTPMTokenInfo reported_info; |
| 411 tpm_token_info_getter_->Start( | 413 tpm_token_info_getter_->Start( |
| 412 base::Bind(&RecordGetterResult, &reported_info)); | 414 base::Bind(&RecordGetterResult, &reported_info)); |
| 413 base::RunLoop().RunUntilIdle(); | 415 base::RunLoop().RunUntilIdle(); |
| 414 | 416 |
| 415 EXPECT_FALSE(reported_info.IsReady()); | 417 EXPECT_FALSE(reported_info.IsReady()); |
| 416 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 2); | 418 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 2); |
| 417 | 419 |
| 418 EXPECT_TRUE(reported_info.IsReady()); | 420 EXPECT_TRUE(reported_info.IsReady()); |
| 419 EXPECT_TRUE(reported_info.enabled); | 421 EXPECT_TRUE(reported_info.enabled); |
| 420 EXPECT_EQ("TOKEN_1", reported_info.name); | 422 EXPECT_EQ("TOKEN_1", reported_info.name); |
| 421 EXPECT_EQ("2222", reported_info.pin); | 423 EXPECT_EQ("2222", reported_info.pin); |
| 422 EXPECT_EQ(2, reported_info.slot_id); | 424 EXPECT_EQ(2, reported_info.slot_id); |
| 423 | 425 |
| 424 int64 kExpectedDelays[] = { 100, 200, 400, 800, 1600, 3200 }; | 426 int64_t kExpectedDelays[] = {100, 200, 400, 800, 1600, 3200}; |
| 425 ASSERT_EQ( | 427 ASSERT_EQ(std::vector<int64_t>(kExpectedDelays, |
| 426 std::vector<int64>(kExpectedDelays, | 428 kExpectedDelays + arraysize(kExpectedDelays)), |
| 427 kExpectedDelays + arraysize(kExpectedDelays)), | 429 delays_); |
| 428 delays_); | |
| 429 } | 430 } |
| 430 | 431 |
| 431 TEST_F(SystemTPMTokenInfoGetterTest, RetryDelayBounded) { | 432 TEST_F(SystemTPMTokenInfoGetterTest, RetryDelayBounded) { |
| 432 cryptohome_client_->set_tpm_is_enabled_failure_count(4); | 433 cryptohome_client_->set_tpm_is_enabled_failure_count(4); |
| 433 cryptohome_client_->set_get_tpm_token_info_failure_count(5); | 434 cryptohome_client_->set_get_tpm_token_info_failure_count(5); |
| 434 cryptohome_client_->set_get_tpm_token_info_not_set_count(6); | 435 cryptohome_client_->set_get_tpm_token_info_not_set_count(6); |
| 435 | 436 |
| 436 TestTPMTokenInfo reported_info; | 437 TestTPMTokenInfo reported_info; |
| 437 tpm_token_info_getter_->Start( | 438 tpm_token_info_getter_->Start( |
| 438 base::Bind(&RecordGetterResult, &reported_info)); | 439 base::Bind(&RecordGetterResult, &reported_info)); |
| 439 base::RunLoop().RunUntilIdle(); | 440 base::RunLoop().RunUntilIdle(); |
| 440 | 441 |
| 441 EXPECT_FALSE(reported_info.IsReady()); | 442 EXPECT_FALSE(reported_info.IsReady()); |
| 442 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); | 443 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); |
| 443 | 444 |
| 444 EXPECT_TRUE(reported_info.IsReady()); | 445 EXPECT_TRUE(reported_info.IsReady()); |
| 445 EXPECT_TRUE(reported_info.enabled); | 446 EXPECT_TRUE(reported_info.enabled); |
| 446 EXPECT_EQ("TOKEN_1", reported_info.name); | 447 EXPECT_EQ("TOKEN_1", reported_info.name); |
| 447 EXPECT_EQ("2222", reported_info.pin); | 448 EXPECT_EQ("2222", reported_info.pin); |
| 448 EXPECT_EQ(1, reported_info.slot_id); | 449 EXPECT_EQ(1, reported_info.slot_id); |
| 449 | 450 |
| 450 int64 kExpectedDelays[] = { | 451 int64_t kExpectedDelays[] = {100, 200, 400, 800, 1600, |
| 451 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, | 452 3200, 6400, 12800, 25600, 51200, |
| 452 300000, 300000, 300000 | 453 102400, 204800, 300000, 300000, 300000}; |
| 453 }; | 454 ASSERT_EQ(std::vector<int64_t>(kExpectedDelays, |
| 454 ASSERT_EQ( | 455 kExpectedDelays + arraysize(kExpectedDelays)), |
| 455 std::vector<int64>(kExpectedDelays, | 456 delays_); |
| 456 kExpectedDelays + arraysize(kExpectedDelays)), | |
| 457 delays_); | |
| 458 } | 457 } |
| 459 | 458 |
| 460 TEST_F(UserTPMTokenInfoGetterTest, BasicFlow) { | 459 TEST_F(UserTPMTokenInfoGetterTest, BasicFlow) { |
| 461 TestTPMTokenInfo reported_info; | 460 TestTPMTokenInfo reported_info; |
| 462 tpm_token_info_getter_->Start( | 461 tpm_token_info_getter_->Start( |
| 463 base::Bind(&RecordGetterResult, &reported_info)); | 462 base::Bind(&RecordGetterResult, &reported_info)); |
| 464 base::RunLoop().RunUntilIdle(); | 463 base::RunLoop().RunUntilIdle(); |
| 465 | 464 |
| 466 EXPECT_FALSE(reported_info.IsReady()); | 465 EXPECT_FALSE(reported_info.IsReady()); |
| 467 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); | 466 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); |
| 468 | 467 |
| 469 EXPECT_TRUE(reported_info.IsReady()); | 468 EXPECT_TRUE(reported_info.IsReady()); |
| 470 EXPECT_TRUE(reported_info.enabled); | 469 EXPECT_TRUE(reported_info.enabled); |
| 471 EXPECT_EQ("TOKEN_1", reported_info.name); | 470 EXPECT_EQ("TOKEN_1", reported_info.name); |
| 472 EXPECT_EQ("2222", reported_info.pin); | 471 EXPECT_EQ("2222", reported_info.pin); |
| 473 EXPECT_EQ(1, reported_info.slot_id); | 472 EXPECT_EQ(1, reported_info.slot_id); |
| 474 | 473 |
| 475 EXPECT_EQ(std::vector<int64>(), delays_); | 474 EXPECT_EQ(std::vector<int64_t>(), delays_); |
| 476 } | 475 } |
| 477 | 476 |
| 478 TEST_F(UserTPMTokenInfoGetterTest, GetTpmTokenInfoInitiallyFails) { | 477 TEST_F(UserTPMTokenInfoGetterTest, GetTpmTokenInfoInitiallyFails) { |
| 479 cryptohome_client_->set_get_tpm_token_info_failure_count(1); | 478 cryptohome_client_->set_get_tpm_token_info_failure_count(1); |
| 480 | 479 |
| 481 TestTPMTokenInfo reported_info; | 480 TestTPMTokenInfo reported_info; |
| 482 tpm_token_info_getter_->Start( | 481 tpm_token_info_getter_->Start( |
| 483 base::Bind(&RecordGetterResult, &reported_info)); | 482 base::Bind(&RecordGetterResult, &reported_info)); |
| 484 base::RunLoop().RunUntilIdle(); | 483 base::RunLoop().RunUntilIdle(); |
| 485 | 484 |
| 486 EXPECT_FALSE(reported_info.IsReady()); | 485 EXPECT_FALSE(reported_info.IsReady()); |
| 487 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); | 486 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); |
| 488 | 487 |
| 489 EXPECT_TRUE(reported_info.IsReady()); | 488 EXPECT_TRUE(reported_info.IsReady()); |
| 490 EXPECT_TRUE(reported_info.enabled); | 489 EXPECT_TRUE(reported_info.enabled); |
| 491 EXPECT_EQ("TOKEN_1", reported_info.name); | 490 EXPECT_EQ("TOKEN_1", reported_info.name); |
| 492 EXPECT_EQ("2222", reported_info.pin); | 491 EXPECT_EQ("2222", reported_info.pin); |
| 493 EXPECT_EQ(1, reported_info.slot_id); | 492 EXPECT_EQ(1, reported_info.slot_id); |
| 494 | 493 |
| 495 const int64 kExpectedDelays[] = {100}; | 494 const int64_t kExpectedDelays[] = {100}; |
| 496 EXPECT_EQ(std::vector<int64>(kExpectedDelays, | 495 EXPECT_EQ(std::vector<int64_t>(kExpectedDelays, |
| 497 kExpectedDelays + arraysize(kExpectedDelays)), | 496 kExpectedDelays + arraysize(kExpectedDelays)), |
| 498 delays_); | 497 delays_); |
| 499 } | 498 } |
| 500 | 499 |
| 501 TEST_F(UserTPMTokenInfoGetterTest, GetTpmTokenInfoInitiallyNotReady) { | 500 TEST_F(UserTPMTokenInfoGetterTest, GetTpmTokenInfoInitiallyNotReady) { |
| 502 cryptohome_client_->set_get_tpm_token_info_not_set_count(1); | 501 cryptohome_client_->set_get_tpm_token_info_not_set_count(1); |
| 503 | 502 |
| 504 TestTPMTokenInfo reported_info; | 503 TestTPMTokenInfo reported_info; |
| 505 tpm_token_info_getter_->Start( | 504 tpm_token_info_getter_->Start( |
| 506 base::Bind(&RecordGetterResult, &reported_info)); | 505 base::Bind(&RecordGetterResult, &reported_info)); |
| 507 base::RunLoop().RunUntilIdle(); | 506 base::RunLoop().RunUntilIdle(); |
| 508 | 507 |
| 509 EXPECT_FALSE(reported_info.IsReady()); | 508 EXPECT_FALSE(reported_info.IsReady()); |
| 510 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); | 509 cryptohome_client_->SetTPMTokenInfo("TOKEN_1", "2222", 1); |
| 511 | 510 |
| 512 EXPECT_TRUE(reported_info.IsReady()); | 511 EXPECT_TRUE(reported_info.IsReady()); |
| 513 EXPECT_TRUE(reported_info.enabled); | 512 EXPECT_TRUE(reported_info.enabled); |
| 514 EXPECT_EQ("TOKEN_1", reported_info.name); | 513 EXPECT_EQ("TOKEN_1", reported_info.name); |
| 515 EXPECT_EQ("2222", reported_info.pin); | 514 EXPECT_EQ("2222", reported_info.pin); |
| 516 EXPECT_EQ(1, reported_info.slot_id); | 515 EXPECT_EQ(1, reported_info.slot_id); |
| 517 | 516 |
| 518 const int64 kExpectedDelays[] = {100}; | 517 const int64_t kExpectedDelays[] = {100}; |
| 519 EXPECT_EQ(std::vector<int64>(kExpectedDelays, | 518 EXPECT_EQ(std::vector<int64_t>(kExpectedDelays, |
| 520 kExpectedDelays + arraysize(kExpectedDelays)), | 519 kExpectedDelays + arraysize(kExpectedDelays)), |
| 521 delays_); | 520 delays_); |
| 522 } | 521 } |
| 523 | 522 |
| 524 } // namespace | 523 } // namespace |
| OLD | NEW |