Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/policy/device_token_fetcher.h" | 5 #include "chrome/browser/policy/device_token_fetcher.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "chrome/browser/policy/cloud_policy_data_store.h" | 9 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 10 #include "chrome/browser/policy/logging_work_scheduler.h" | 10 #include "chrome/browser/policy/logging_work_scheduler.h" |
| 11 #include "chrome/browser/policy/mock_cloud_policy_data_store.h" | |
| 11 #include "chrome/browser/policy/mock_device_management_backend.h" | 12 #include "chrome/browser/policy/mock_device_management_backend.h" |
| 12 #include "chrome/browser/policy/mock_device_management_service.h" | 13 #include "chrome/browser/policy/mock_device_management_service.h" |
| 13 #include "chrome/browser/policy/policy_notifier.h" | 14 #include "chrome/browser/policy/policy_notifier.h" |
| 14 #include "chrome/browser/policy/user_policy_cache.h" | 15 #include "chrome/browser/policy/user_policy_cache.h" |
| 15 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace policy { | 20 namespace policy { |
| 20 | 21 |
| 21 const char kTestToken[] = "device_token_fetcher_test_auth_token"; | 22 const char kTestToken[] = "device_token_fetcher_test_auth_token"; |
| 22 | 23 |
| 24 using testing::_; | |
| 25 using testing::AnyNumber; | |
| 23 using testing::Mock; | 26 using testing::Mock; |
| 24 using testing::_; | |
| 25 | |
| 26 class MockTokenAvailableObserver : public CloudPolicyDataStore::Observer { | |
| 27 public: | |
| 28 MockTokenAvailableObserver() {} | |
| 29 virtual ~MockTokenAvailableObserver() {} | |
| 30 | |
| 31 MOCK_METHOD0(OnDeviceTokenChanged, void()); | |
| 32 MOCK_METHOD0(OnCredentialsChanged, void()); | |
| 33 | |
| 34 private: | |
| 35 DISALLOW_COPY_AND_ASSIGN(MockTokenAvailableObserver); | |
| 36 }; | |
| 37 | 27 |
| 38 class DeviceTokenFetcherTest : public testing::Test { | 28 class DeviceTokenFetcherTest : public testing::Test { |
| 39 protected: | 29 protected: |
| 40 DeviceTokenFetcherTest() | 30 DeviceTokenFetcherTest() |
| 41 : ui_thread_(BrowserThread::UI, &loop_), | 31 : ui_thread_(BrowserThread::UI, &loop_), |
| 42 file_thread_(BrowserThread::FILE, &loop_) { | 32 file_thread_(BrowserThread::FILE, &loop_) { |
| 43 EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); | 33 EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); |
| 44 } | 34 } |
| 45 | 35 |
| 46 virtual void SetUp() { | 36 virtual void SetUp() { |
| 47 cache_.reset(new UserPolicyCache( | 37 cache_.reset(new UserPolicyCache( |
| 48 temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"))); | 38 temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"))); |
| 49 service_.set_backend(&backend_); | 39 EXPECT_CALL(service_, CreateBackend()) |
|
gfeher
2011/07/19 13:45:33
I think this may be simplified using ON_CALL inste
Joao da Silva
2011/07/19 15:19:39
Same as above.
| |
| 40 .Times(AnyNumber()) | |
| 41 .WillRepeatedly(MockDeviceManagementServiceProxyBackend(&backend_)); | |
| 50 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 42 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
| 51 data_store_->AddObserver(&observer_); | 43 data_store_->AddObserver(&observer_); |
| 52 } | 44 } |
| 53 | 45 |
| 54 virtual void TearDown() { | 46 virtual void TearDown() { |
| 55 loop_.RunAllPending(); | 47 loop_.RunAllPending(); |
| 56 data_store_->RemoveObserver(&observer_); | 48 data_store_->RemoveObserver(&observer_); |
| 57 } | 49 } |
| 58 | 50 |
| 59 void FetchToken(DeviceTokenFetcher* fetcher) { | 51 void FetchToken(DeviceTokenFetcher* fetcher) { |
| 60 data_store_->SetupForTesting("", "fake_device_id", "fake_user_name", | 52 data_store_->SetupForTesting("", "fake_device_id", "fake_user_name", |
| 61 "fake_auth_token", true); | 53 "fake_auth_token", true); |
| 62 fetcher->FetchToken(); | 54 fetcher->FetchToken(); |
| 63 } | 55 } |
| 64 | 56 |
| 65 MessageLoop loop_; | 57 MessageLoop loop_; |
| 66 MockDeviceManagementBackend backend_; | 58 MockDeviceManagementBackend backend_; |
| 67 MockDeviceManagementService service_; | 59 MockDeviceManagementService service_; |
| 68 scoped_ptr<CloudPolicyCacheBase> cache_; | 60 scoped_ptr<CloudPolicyCacheBase> cache_; |
| 69 scoped_ptr<CloudPolicyDataStore> data_store_; | 61 scoped_ptr<CloudPolicyDataStore> data_store_; |
| 70 MockTokenAvailableObserver observer_; | 62 MockCloudPolicyDataStoreObserver observer_; |
| 71 PolicyNotifier notifier_; | 63 PolicyNotifier notifier_; |
| 72 ScopedTempDir temp_user_data_dir_; | 64 ScopedTempDir temp_user_data_dir_; |
| 73 | 65 |
| 74 private: | 66 private: |
| 75 BrowserThread ui_thread_; | 67 BrowserThread ui_thread_; |
| 76 BrowserThread file_thread_; | 68 BrowserThread file_thread_; |
| 77 }; | 69 }; |
| 78 | 70 |
| 79 TEST_F(DeviceTokenFetcherTest, FetchToken) { | 71 TEST_F(DeviceTokenFetcherTest, FetchToken) { |
| 80 testing::InSequence s; | 72 testing::InSequence s; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 ¬ifier_); | 118 ¬ifier_); |
| 127 EXPECT_CALL(observer_, OnDeviceTokenChanged()).Times(0); | 119 EXPECT_CALL(observer_, OnDeviceTokenChanged()).Times(0); |
| 128 FetchToken(&fetcher); | 120 FetchToken(&fetcher); |
| 129 loop_.RunAllPending(); | 121 loop_.RunAllPending(); |
| 130 Mock::VerifyAndClearExpectations(&observer_); | 122 Mock::VerifyAndClearExpectations(&observer_); |
| 131 EXPECT_EQ("", data_store_->device_token()); | 123 EXPECT_EQ("", data_store_->device_token()); |
| 132 EXPECT_TRUE(cache_->is_unmanaged()); | 124 EXPECT_TRUE(cache_->is_unmanaged()); |
| 133 } | 125 } |
| 134 | 126 |
| 135 } // namespace policy | 127 } // namespace policy |
| OLD | NEW |