diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 16:37:41 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 16:37:41 +0000 |
commit | 62eeafc6f90d4e9625da2f453913e7861889f0db (patch) | |
tree | 835f1f1a03b2ff9f6ef02e141305fd9ee1248bb1 /chrome | |
parent | 8fa6f7d95ae66cda157f0fa63c616b90315fd398 (diff) | |
download | chromium_src-62eeafc6f90d4e9625da2f453913e7861889f0db.zip chromium_src-62eeafc6f90d4e9625da2f453913e7861889f0db.tar.gz chromium_src-62eeafc6f90d4e9625da2f453913e7861889f0db.tar.bz2 |
Add a helper class to use with SignedSettings.
- Add a SignedSettingsHelper that serializes all SignedSettings ops,
provides a unified callback interface and allows canceling callback of
requested ops;
- Move MockOwnershipService into a header file;
- Add a unit test for SignedSettingsHelper;
BUG=chromium-os:968
TEST=none. This is still plumbing work required users options ui.
Review URL: http://codereview.chromium.org/3373008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59380 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/login/mock_ownership_service.h | 31 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings.h | 1 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings_helper.cc | 409 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings_helper.h | 83 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings_helper_unittest.cc | 152 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings_unittest.cc | 19 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 |
8 files changed, 682 insertions, 16 deletions
diff --git a/chrome/browser/chromeos/login/mock_ownership_service.h b/chrome/browser/chromeos/login/mock_ownership_service.h new file mode 100644 index 0000000..5690cfb --- /dev/null +++ b/chrome/browser/chromeos/login/mock_ownership_service.h @@ -0,0 +1,31 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_OWNERSHIP_SERVICE_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_OWNERSHIP_SERVICE_H_ +#pragma once + +#include <string> + +#include "chrome/browser/chromeos/login/ownership_service.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace chromeos { + +class MockOwnershipService : public OwnershipService { + public: + MOCK_METHOD0(IsAlreadyOwned, bool(void)); + MOCK_METHOD0(StartLoadOwnerKeyAttempt, bool(void)); + MOCK_METHOD0(StartTakeOwnershipAttempt, bool(void)); + MOCK_METHOD2(StartSigningAttempt, void(const std::string&, + OwnerManager::Delegate*)); + MOCK_METHOD3(StartVerifyAttempt, void(const std::string&, + const std::vector<uint8>&, + OwnerManager::Delegate*)); + MOCK_METHOD0(CurrentUserIsOwner, bool(void)); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_OWNERSHIP_SERVICE_H_ diff --git a/chrome/browser/chromeos/login/signed_settings.h b/chrome/browser/chromeos/login/signed_settings.h index d2c1049..8882d7e 100644 --- a/chrome/browser/chromeos/login/signed_settings.h +++ b/chrome/browser/chromeos/login/signed_settings.h @@ -78,6 +78,7 @@ class SignedSettings : public base::RefCountedThreadSafe<SignedSettings>, private: friend class SignedSettingsTest; + friend class SignedSettingsHelperTest; void set_service(OwnershipService* service) { service_ = service; } }; diff --git a/chrome/browser/chromeos/login/signed_settings_helper.cc b/chrome/browser/chromeos/login/signed_settings_helper.cc new file mode 100644 index 0000000..67b3ca5 --- /dev/null +++ b/chrome/browser/chromeos/login/signed_settings_helper.cc @@ -0,0 +1,409 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/login/signed_settings_helper.h" + +#include <string> +#include <vector> + +#include "base/logging.h" +#include "base/ref_counted.h" +#include "base/singleton.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/chromeos/login/signed_settings.h" + +namespace chromeos { + +namespace { + +class OpContext { + public: + class Delegate { + public: + virtual void OnOpCreated(OpContext* context) = 0; + virtual void OnOpStarted(OpContext* context) = 0; + virtual void OnOpCompleted(OpContext* context) = 0; + }; + + virtual ~OpContext() {} + + // Creates and execute op. + void Execute() { + CreateOp(); + CHECK(op_.get()); + if (delegate_) + delegate_->OnOpCreated(this); + + executing_ = true; + op_->Execute(); + + if (delegate_) + delegate_->OnOpStarted(this); + } + + // Cancels callback. + void Cancel() { + callback_ = NULL; + + if (!executing_) + OnOpCompleted(); + } + + // Accessors. + SignedSettings* op() const { + return op_.get(); + } + + SignedSettingsHelper::Callback* callback() const { + return callback_; + } + + void set_delegate(Delegate* delegate) { + delegate_ = delegate; + } + + protected: + OpContext(SignedSettingsHelper::Callback* callback, + Delegate* delegate) + : executing_(false), + delegate_(delegate), + callback_(callback) { + } + + // Creates the op to execute. + virtual void CreateOp() = 0; + + // Callback on op completion. + virtual void OnOpCompleted() { + if (delegate_) + delegate_->OnOpCompleted(this); + + delete this; + } + + bool executing_; + Delegate* delegate_; + + scoped_refptr<SignedSettings> op_; + SignedSettingsHelper::Callback* callback_; +}; + +class WhitelistOpContext : public SignedSettings::Delegate<bool>, + public OpContext { + public: + enum Type { + CHECK, + ADD, + REMOVE, + }; + + WhitelistOpContext(Type type, + const std::string& email, + SignedSettingsHelper::Callback* callback, + Delegate* delegate) + : OpContext(callback, delegate), + type_(type), + email_(email) { + } + + // chromeos::SignedSettings::Delegate implementation + virtual void OnSettingsOpSucceeded(bool value) { + if (callback_) { + switch (type_) { + case CHECK: + callback_->OnCheckWhiteListCompleted(value, email_); + break; + case ADD: + callback_->OnWhitelistCompleted(value, email_); + break; + case REMOVE: + callback_->OnUnwhitelistCompleted(value, email_); + break; + default: + LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; + break; + } + } + + OnOpCompleted(); + } + + virtual void OnSettingsOpFailed() { + if (callback_) { + switch (type_) { + case CHECK: + callback_->OnCheckWhiteListCompleted(false, email_); + break; + case ADD: + callback_->OnWhitelistCompleted(false, email_); + break; + case REMOVE: + callback_->OnUnwhitelistCompleted(false, email_); + break; + default: + LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; + break; + } + } + + OnOpCompleted(); + } + + protected: + // OpContext implemenetation + virtual void CreateOp() { + switch (type_) { + case CHECK: + op_ = SignedSettings::CreateCheckWhitelistOp(email_, this); + break; + case ADD: + op_ = SignedSettings::CreateWhitelistOp(email_, true, this); + break; + case REMOVE: + op_ = SignedSettings::CreateWhitelistOp(email_, false, this); + break; + default: + LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; + break; + } + } + + private: + Type type_; + std::string email_; + + DISALLOW_COPY_AND_ASSIGN(WhitelistOpContext); +}; + +class StorePropertyOpContext : public SignedSettings::Delegate<bool>, + public OpContext { + public: + StorePropertyOpContext(const std::string& name, + const std::string& value, + SignedSettingsHelper::Callback* callback, + Delegate* delegate) + : OpContext(callback, delegate), + name_(name), + value_(value) { + } + + // chromeos::SignedSettings::Delegate implementation + virtual void OnSettingsOpSucceeded(bool value) { + if (callback_) + callback_->OnStorePropertyCompleted(true, name_, value_); + OnOpCompleted(); + } + + virtual void OnSettingsOpFailed() { + if (callback_) + callback_->OnStorePropertyCompleted(false, name_, value_); + OnOpCompleted(); + } + + protected: + // OpContext implemenetation + virtual void CreateOp() { + op_ = SignedSettings::CreateStorePropertyOp(name_, value_, this); + } + + private: + std::string name_; + std::string value_; + + DISALLOW_COPY_AND_ASSIGN(StorePropertyOpContext); +}; + +class RetrievePropertyOpContext + : public SignedSettings::Delegate<std::string>, + public OpContext { + public: + RetrievePropertyOpContext(const std::string& name, + SignedSettingsHelper::Callback* callback, + Delegate* delegate) + : OpContext(callback, delegate), + name_(name) { + } + + // chromeos::SignedSettings::Delegate implementation + virtual void OnSettingsOpSucceeded(std::string value) { + if (callback_) + callback_->OnRetrievePropertyCompleted(true, name_, value); + + OnOpCompleted(); + } + + virtual void OnSettingsOpFailed() { + if (callback_) + callback_->OnRetrievePropertyCompleted(false, name_, std::string()); + OnOpCompleted(); + } + + protected: + // OpContext implemenetation + virtual void CreateOp() { + op_ = SignedSettings::CreateRetrievePropertyOp(name_, this); + } + + private: + std::string name_; + + DISALLOW_COPY_AND_ASSIGN(RetrievePropertyOpContext); +}; + +} // namespace + + +class SignedSettingsHelperImpl : public SignedSettingsHelper, + public OpContext::Delegate { + public: + // SignedSettingsHelper implementation + virtual void StartCheckWhitelistOp(const std::string& email, + Callback* callback); + virtual void StartWhitelistOp(const std::string& email, + bool add_to_whitelist, + Callback* callback); + virtual void StartStorePropertyOp(const std::string& name, + const std::string& value, + Callback* callback); + virtual void StartRetrieveProperty(const std::string& name, + Callback* callback); + virtual void Cancel(Callback* callback); + + // OpContext::Delegate implementation + virtual void OnOpCreated(OpContext* context); + virtual void OnOpStarted(OpContext* context); + virtual void OnOpCompleted(OpContext* context); + + private: + SignedSettingsHelperImpl(); + ~SignedSettingsHelperImpl(); + + void AddOpContext(OpContext* context); + void ClearAll(); + + OpContext* current_context_; + std::vector<OpContext*> pending_contexts_; + + friend struct DefaultSingletonTraits<SignedSettingsHelperImpl>; + DISALLOW_COPY_AND_ASSIGN(SignedSettingsHelperImpl); +}; + +SignedSettingsHelperImpl::SignedSettingsHelperImpl() + : current_context_(NULL) { +} + +SignedSettingsHelperImpl::~SignedSettingsHelperImpl() { + if (!pending_contexts_.empty()) { + LOG(WARNING) << "SignedSettingsHelperImpl shutdown with pending ops, " + << "changes will be lost."; + ClearAll(); + } +} + +void SignedSettingsHelperImpl::StartCheckWhitelistOp( + const std::string&email, + SignedSettingsHelper::Callback* callback) { + AddOpContext(new WhitelistOpContext( + WhitelistOpContext::CHECK, + email, + callback, + this)); +} + +void SignedSettingsHelperImpl::StartWhitelistOp( + const std::string&email, + bool add_to_whitelist, + SignedSettingsHelper::Callback* callback) { + AddOpContext(new WhitelistOpContext( + add_to_whitelist ? WhitelistOpContext::ADD : WhitelistOpContext::REMOVE, + email, + callback, + this)); +} + +void SignedSettingsHelperImpl::StartStorePropertyOp( + const std::string& name, + const std::string& value, + SignedSettingsHelper::SignedSettingsHelper::Callback* callback) { + AddOpContext(new StorePropertyOpContext( + name, + value, + callback, + this)); +} + +void SignedSettingsHelperImpl::StartRetrieveProperty( + const std::string& name, + SignedSettingsHelper::Callback* callback) { + AddOpContext(new RetrievePropertyOpContext( + name, + callback, + this)); +} + +void SignedSettingsHelperImpl::Cancel( + SignedSettingsHelper::Callback* callback) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + + for (size_t i = 0; i < pending_contexts_.size(); ++i) { + if (pending_contexts_[i]->callback() == callback) { + pending_contexts_[i]->Cancel(); + pending_contexts_.erase(pending_contexts_.begin() + i); + } + } +} + +void SignedSettingsHelperImpl::AddOpContext(OpContext* context) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + CHECK(context); + + pending_contexts_.push_back(context); + if (current_context_ == NULL && pending_contexts_.size() == 1) + context->Execute(); +} + +void SignedSettingsHelperImpl::ClearAll() { + for (size_t i = 0; i < pending_contexts_.size(); ++i) { + pending_contexts_[i]->set_delegate(NULL); + pending_contexts_[i]->Cancel(); + } + pending_contexts_.clear(); +} + +void SignedSettingsHelperImpl::OnOpCreated(OpContext* context) { + if (test_delegate_) + test_delegate_->OnOpCreated(context->op()); +} + +void SignedSettingsHelperImpl::OnOpStarted(OpContext* context) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + DCHECK(current_context_ == NULL); + current_context_ = context; + + if (test_delegate_) + test_delegate_->OnOpStarted(context->op()); +} + +void SignedSettingsHelperImpl::OnOpCompleted(OpContext* context) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + + if (current_context_ == context) { + current_context_ = NULL; + + if (pending_contexts_.front() == context) + pending_contexts_.erase(pending_contexts_.begin()); + } + + if (current_context_ == NULL && !pending_contexts_.empty()) + pending_contexts_.front()->Execute(); + + if (test_delegate_) + test_delegate_->OnOpCompleted(context->op()); +} + +SignedSettingsHelper* SignedSettingsHelper::Get() { + return Singleton<SignedSettingsHelperImpl>::get(); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/login/signed_settings_helper.h b/chrome/browser/chromeos/login/signed_settings_helper.h new file mode 100644 index 0000000..75320e0 --- /dev/null +++ b/chrome/browser/chromeos/login/signed_settings_helper.h @@ -0,0 +1,83 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ +#pragma once + +#include <string> + +namespace chromeos { + +class SignedSettings; + +// Helper to serialize signed settings ops, provide unified callback interface, +// and handle callbacks destruction before ops completion. +class SignedSettingsHelper { + public: + class Callback { + public: + // Callback of CheckWhitelistOp. |success| indicates whether the op succeeds + // or not. |email| is the email that is checked against. + virtual void OnCheckWhiteListCompleted( + bool success, const std::string& email) {} + + // Callback of WhitelistOp that adds |email| to the whitelist. + virtual void OnWhitelistCompleted( + bool success, const std::string& email) {} + + // Callback of WhitelistOp that removes |email| to the whitelist. + virtual void OnUnwhitelistCompleted( + bool success, const std::string& email) {} + + // Callback of StorePropertyOp. + virtual void OnStorePropertyCompleted( + bool success, const std::string& name, const std::string& value) {} + + // Callback of RetrievePropertyOp. + virtual void OnRetrievePropertyCompleted( + bool success, const std::string& name, const std::string& value) {} + }; + + // Class factory + static SignedSettingsHelper* Get(); + + // Functions to start signed settings ops. + virtual void StartCheckWhitelistOp(const std::string& email, + Callback* callback) = 0; + virtual void StartWhitelistOp(const std::string& email, + bool add_to_whitelist, + Callback* callback) = 0; + virtual void StartStorePropertyOp(const std::string& name, + const std::string& value, + Callback* callback) = 0; + virtual void StartRetrieveProperty(const std::string& name, + Callback* callback) = 0; + + // Cancels all pending calls associated with given callback. + virtual void Cancel(Callback* callback) = 0; + + class TestDelegate { + public: + virtual void OnOpCreated(SignedSettings* op) = 0; + virtual void OnOpStarted(SignedSettings* op) = 0; + virtual void OnOpCompleted(SignedSettings* op) = 0; + }; + +#if defined(UNIT_TEST) + void set_test_delegate(TestDelegate* test_delegate) { + test_delegate_ = test_delegate; + } +#endif // defined(UNIT_TEST) + + protected: + SignedSettingsHelper() : test_delegate_(NULL) { + } + + TestDelegate* test_delegate_; +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ diff --git a/chrome/browser/chromeos/login/signed_settings_helper_unittest.cc b/chrome/browser/chromeos/login/signed_settings_helper_unittest.cc new file mode 100644 index 0000000..74f7cd0 --- /dev/null +++ b/chrome/browser/chromeos/login/signed_settings_helper_unittest.cc @@ -0,0 +1,152 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/login/signed_settings_helper.h" + +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/chromeos/login/owner_manager.h" +#include "chrome/browser/chromeos/login/mock_ownership_service.h" +#include "chrome/browser/chromeos/login/signed_settings.h" +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using ::testing::_; +using ::testing::InSequence; + +namespace chromeos { + +class MockSignedSettingsHelperCallback : public SignedSettingsHelper::Callback { + public: + MOCK_METHOD2(OnCheckWhiteListCompleted, void( + bool success, const std::string& email)); + MOCK_METHOD2(OnWhitelistCompleted, void( + bool success, const std::string& email)); + MOCK_METHOD2(OnUnwhitelistCompleted, void( + bool success, const std::string& email)); + MOCK_METHOD3(OnStorePropertyCompleted, void( + bool success, const std::string& name, const std::string& value)); + MOCK_METHOD3(OnRetrievePropertyCompleted, void( + bool success, const std::string& name, const std::string& value)); +}; + +class SignedSettingsHelperTest : public ::testing::Test, + public SignedSettingsHelper::TestDelegate { + public: + SignedSettingsHelperTest() + : fake_email_("fakey"), + fake_prop_("prop_name"), + fake_value_("stub"), + message_loop_(MessageLoop::TYPE_UI), + ui_thread_(ChromeThread::UI, &message_loop_), + file_thread_(ChromeThread::FILE), + pending_ops_(0) { + } + + virtual void SetUp() { + chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); + file_thread_.Start(); + SignedSettingsHelper::Get()->set_test_delegate(this); + } + + virtual void TearDown() { + SignedSettingsHelper::Get()->set_test_delegate(NULL); + } + + virtual void OnOpCreated(SignedSettings* op) { + // Use MockOwnershipService for all SignedSettings op. + op->set_service(&m_); + } + + virtual void OnOpStarted(SignedSettings* op) { + op->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); + } + + virtual void OnOpCompleted(SignedSettings* op) { + --pending_ops_; + if (!pending_ops_) + MessageLoop::current()->Quit(); + } + + const std::string fake_email_; + const std::string fake_prop_; + const std::string fake_value_; + MockOwnershipService m_; + + MessageLoop message_loop_; + ChromeThread ui_thread_; + ChromeThread file_thread_; + + int pending_ops_; +}; + +TEST_F(SignedSettingsHelperTest, SerializedOps) { + MockSignedSettingsHelperCallback cb; + + InSequence s; + EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1); + EXPECT_CALL(cb, OnCheckWhiteListCompleted(true, _)) + .Times(1); + EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); + EXPECT_CALL(cb, OnWhitelistCompleted(true, _)) + .Times(1); + EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); + EXPECT_CALL(cb, OnUnwhitelistCompleted(true, _)) + .Times(1); + EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); + EXPECT_CALL(cb, OnStorePropertyCompleted(true, _, _)) + .Times(1); + EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1); + EXPECT_CALL(cb, OnRetrievePropertyCompleted(true, _, _)) + .Times(1); + + pending_ops_ = 5; + SignedSettingsHelper::Get()->StartCheckWhitelistOp(fake_email_, &cb); + SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, true, &cb); + SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, false, &cb); + SignedSettingsHelper::Get()->StartStorePropertyOp(fake_prop_, fake_value_, + &cb); + SignedSettingsHelper::Get()->StartRetrieveProperty(fake_prop_, &cb); + + message_loop_.Run(); +} + +TEST_F(SignedSettingsHelperTest, CanceledOps) { + MockSignedSettingsHelperCallback cb; + + InSequence s; + EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1); + EXPECT_CALL(cb, OnCheckWhiteListCompleted(true, _)) + .Times(1); + EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); + EXPECT_CALL(cb, OnWhitelistCompleted(true, _)) + .Times(1); + EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); + EXPECT_CALL(cb, OnUnwhitelistCompleted(true, _)) + .Times(1); + EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); + EXPECT_CALL(cb, OnStorePropertyCompleted(true, _, _)) + .Times(1); + EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1); + EXPECT_CALL(cb, OnRetrievePropertyCompleted(true, _, _)) + .Times(1); + + pending_ops_ = 5; // 3 below and 2 after cb_to_be_canceled + SignedSettingsHelper::Get()->StartCheckWhitelistOp(fake_email_, &cb); + SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, true, &cb); + SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, false, &cb); + + MockSignedSettingsHelperCallback cb_to_be_canceled; + SignedSettingsHelper::Get()->StartCheckWhitelistOp(fake_email_, + &cb_to_be_canceled); + SignedSettingsHelper::Get()->Cancel(&cb_to_be_canceled); + + SignedSettingsHelper::Get()->StartStorePropertyOp(fake_prop_, fake_value_, + &cb); + SignedSettingsHelper::Get()->StartRetrieveProperty(fake_prop_, &cb); + + message_loop_.Run(); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/login/signed_settings_unittest.cc b/chrome/browser/chromeos/login/signed_settings_unittest.cc index f56a393..14b360c 100644 --- a/chrome/browser/chromeos/login/signed_settings_unittest.cc +++ b/chrome/browser/chromeos/login/signed_settings_unittest.cc @@ -11,7 +11,7 @@ #include "base/stringprintf.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/chromeos/login/mock_owner_key_utils.h" -#include "chrome/browser/chromeos/login/ownership_service.h" +#include "chrome/browser/chromeos/login/mock_ownership_service.h" #include "chrome/browser/chromeos/login/owner_manager_unittest.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "testing/gmock/include/gmock/gmock.h" @@ -62,19 +62,6 @@ class Quitter : public DummyDelegate<bool> { }; } // anonymous namespace -class MockService : public OwnershipService { - public: - MOCK_METHOD0(IsAlreadyOwned, bool(void)); - MOCK_METHOD0(StartLoadOwnerKeyAttempt, bool(void)); - MOCK_METHOD0(StartTakeOwnershipAttempt, bool(void)); - MOCK_METHOD2(StartSigningAttempt, void(const std::string&, - OwnerManager::Delegate*)); - MOCK_METHOD3(StartVerifyAttempt, void(const std::string&, - const std::vector<uint8>&, - OwnerManager::Delegate*)); - MOCK_METHOD0(CurrentUserIsOwner, bool(void)); -}; - class SignedSettingsTest : public ::testing::Test { public: SignedSettingsTest() @@ -99,7 +86,7 @@ class SignedSettingsTest : public ::testing::Test { OwnerKeyUtils::set_factory(NULL); } - void mock_service(SignedSettings* s, MockService* m) { + void mock_service(SignedSettings* s, MockOwnershipService* m) { s->set_service(m); } @@ -162,7 +149,7 @@ class SignedSettingsTest : public ::testing::Test { const std::string fake_email_; const std::string fake_prop_; const std::string fake_value_; - MockService m_; + MockOwnershipService m_; ScopedTempDir tmpdir_; FilePath tmpfile_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 76ddc3a..38bfae5 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -551,6 +551,8 @@ 'browser/chromeos/login/screen_observer.h', 'browser/chromeos/login/signed_settings.cc', 'browser/chromeos/login/signed_settings.h', + 'browser/chromeos/login/signed_settings_helper.cc', + 'browser/chromeos/login/signed_settings_helper.h', 'browser/chromeos/login/update_screen.cc', 'browser/chromeos/login/update_screen.h', 'browser/chromeos/login/update_view.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 6b537e5..a1718f2 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -867,6 +867,7 @@ 'browser/chromeos/login/owner_manager_unittest.cc', 'browser/chromeos/login/ownership_service_unittest.cc', 'browser/chromeos/login/signed_settings_unittest.cc', + 'browser/chromeos/login/signed_settings_helper_unittest.cc', 'browser/chromeos/notifications/desktop_notifications_unittest.cc', 'browser/chromeos/offline/offline_load_page_unittest.cc', 'browser/chromeos/options/language_config_model_unittest.cc', |