OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_MANAGER_UNITTEST_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_MANAGER_UNITTEST_H_ |
| 7 |
| 8 #include "chrome/browser/chromeos/login/owner_manager.h" |
| 9 |
| 10 #include <string> |
| 11 |
| 12 #include "base/file_path.h" |
| 13 #include "base/file_util.h" |
| 14 #include "base/logging.h" |
| 15 #include "chrome/browser/chrome_thread.h" |
| 16 #include "chrome/common/notification_observer.h" |
| 17 #include "chrome/common/notification_registrar.h" |
| 18 #include "chrome/common/notification_service.h" |
| 19 #include "chrome/common/notification_type.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 |
| 23 |
| 24 namespace chromeos { |
| 25 class MockKeyLoadObserver : public NotificationObserver { |
| 26 public: |
| 27 MockKeyLoadObserver() |
| 28 : success_expected_(false), |
| 29 quit_on_observe_(true), |
| 30 observed_(false) { |
| 31 registrar_.Add( |
| 32 this, |
| 33 NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, |
| 34 NotificationService::AllSources()); |
| 35 registrar_.Add( |
| 36 this, |
| 37 NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, |
| 38 NotificationService::AllSources()); |
| 39 } |
| 40 |
| 41 virtual ~MockKeyLoadObserver() { |
| 42 EXPECT_TRUE(observed_); |
| 43 } |
| 44 |
| 45 // NotificationObserver implementation. |
| 46 virtual void Observe(NotificationType type, |
| 47 const NotificationSource& source, |
| 48 const NotificationDetails& details) { |
| 49 LOG(INFO) << "Observed key fetch event"; |
| 50 if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { |
| 51 EXPECT_TRUE(success_expected_); |
| 52 observed_ = true; |
| 53 if (quit_on_observe_) |
| 54 MessageLoop::current()->Quit(); |
| 55 } else if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED) { |
| 56 EXPECT_FALSE(success_expected_); |
| 57 observed_ = true; |
| 58 if (quit_on_observe_) |
| 59 MessageLoop::current()->Quit(); |
| 60 } |
| 61 } |
| 62 |
| 63 void ExpectKeyFetchSuccess(bool should_succeed) { |
| 64 success_expected_ = should_succeed; |
| 65 } |
| 66 |
| 67 void SetQuitOnKeyFetch(bool should_quit) { quit_on_observe_ = should_quit; } |
| 68 |
| 69 private: |
| 70 NotificationRegistrar registrar_; |
| 71 bool success_expected_; |
| 72 bool quit_on_observe_; |
| 73 bool observed_; |
| 74 DISALLOW_COPY_AND_ASSIGN(MockKeyLoadObserver); |
| 75 }; |
| 76 |
| 77 class MockKeyUser : public OwnerManager::Delegate { |
| 78 public: |
| 79 explicit MockKeyUser(const OwnerManager::KeyOpCode expected) |
| 80 : expected_(expected) { |
| 81 } |
| 82 |
| 83 virtual ~MockKeyUser() {} |
| 84 |
| 85 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
| 86 const std::string& payload) { |
| 87 MessageLoop::current()->Quit(); |
| 88 EXPECT_EQ(expected_, return_code); |
| 89 } |
| 90 |
| 91 const OwnerManager::KeyOpCode expected_; |
| 92 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(MockKeyUser); |
| 94 }; |
| 95 |
| 96 } // namespace chromeos |
| 97 |
| 98 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_MANAGER_UNITTEST_H_ |
OLD | NEW |