OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
7 #include "chrome/browser/browser_thread.h" | 7 #include "chrome/browser/browser_thread.h" |
8 #include "chrome/browser/net/gaia/token_service.h" | 8 #include "chrome/browser/net/gaia/token_service.h" |
9 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 9 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
10 #include "chrome/browser/policy/device_management_policy_provider.h" | 10 #include "chrome/browser/policy/device_management_policy_provider.h" |
11 #include "chrome/browser/policy/mock_configuration_policy_store.h" | 11 #include "chrome/browser/policy/mock_configuration_policy_store.h" |
12 #include "chrome/browser/policy/mock_device_management_backend.h" | 12 #include "chrome/browser/policy/mock_device_management_backend.h" |
13 #include "chrome/common/net/gaia/gaia_constants.h" | 13 #include "chrome/common/net/gaia/gaia_constants.h" |
14 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.h" |
15 #include "chrome/common/policy_constants.h" | 15 #include "chrome/common/policy_constants.h" |
16 #include "chrome/test/device_management_test_util.h" | |
17 #include "chrome/test/mock_notification_observer.h" | 16 #include "chrome/test/mock_notification_observer.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
19 | 18 |
19 namespace { | |
20 const char kTestToken[] = "device_policy_provider_test_auth_token"; | |
Nico
2010/11/18 13:53:40
const things implicitly have internal linkage, no
Mattias Nissler (ping if slow)
2010/11/18 14:20:15
Done.
| |
21 } | |
22 | |
20 namespace policy { | 23 namespace policy { |
21 | 24 |
22 using ::testing::_; | 25 using ::testing::_; |
23 using ::testing::Mock; | 26 using ::testing::Mock; |
24 | 27 |
25 class DeviceManagementPolicyProviderTest : public testing::Test { | 28 class DeviceManagementPolicyProviderTest : public testing::Test { |
26 public: | 29 public: |
27 DeviceManagementPolicyProviderTest() | 30 DeviceManagementPolicyProviderTest() |
28 : ui_thread_(BrowserThread::UI, &loop_), | 31 : ui_thread_(BrowserThread::UI, &loop_), |
29 file_thread_(BrowserThread::FILE, &loop_) {} | 32 file_thread_(BrowserThread::FILE, &loop_) {} |
30 | 33 |
31 virtual ~DeviceManagementPolicyProviderTest() {} | 34 virtual ~DeviceManagementPolicyProviderTest() {} |
32 | 35 |
33 virtual void SetUp() { | 36 virtual void SetUp() { |
34 EXPECT_TRUE(storage_dir_.CreateUniqueTempDir()); | 37 EXPECT_TRUE(storage_dir_.CreateUniqueTempDir()); |
35 CreateNewBackend(); | 38 CreateNewBackend(); |
36 CreateNewProvider(); | 39 CreateNewProvider(); |
37 } | 40 } |
38 | 41 |
39 void CreateNewBackend() { | 42 void CreateNewBackend() { |
40 backend_ = new MockDeviceManagementBackend; | 43 backend_ = new MockDeviceManagementBackend; |
41 backend_->AddBooleanPolicy(key::kDisableSpdy, true); | 44 backend_->AddBooleanPolicy(key::kDisableSpdy, true); |
42 } | 45 } |
43 | 46 |
44 void CreateNewProvider() { | 47 void CreateNewProvider() { |
48 token_service_.reset(new TokenService); | |
45 provider_.reset(new DeviceManagementPolicyProvider( | 49 provider_.reset(new DeviceManagementPolicyProvider( |
46 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), | 50 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), |
47 backend_, | 51 backend_, |
52 token_service_.get(), | |
48 storage_dir_.path())); | 53 storage_dir_.path())); |
49 loop_.RunAllPending(); | 54 loop_.RunAllPending(); |
50 } | 55 } |
51 | 56 |
52 void SimulateSuccessfulLoginAndRunPending() { | 57 void SimulateSuccessfulLoginAndRunPending() { |
53 loop_.RunAllPending(); | 58 loop_.RunAllPending(); |
54 SimulateSuccessfulLogin(); | 59 token_service_->IssueAuthTokenForTest( |
60 GaiaConstants::kDeviceManagementService, kTestToken); | |
55 loop_.RunAllPending(); | 61 loop_.RunAllPending(); |
56 } | 62 } |
57 | 63 |
58 void SimulateSuccessfulInitialPolicyFetch() { | 64 void SimulateSuccessfulInitialPolicyFetch() { |
59 MockConfigurationPolicyStore store; | 65 MockConfigurationPolicyStore store; |
60 backend_->AllShouldSucceed(); | 66 backend_->AllShouldSucceed(); |
61 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); | 67 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
62 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(1); | 68 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(1); |
63 SimulateSuccessfulLoginAndRunPending(); | 69 SimulateSuccessfulLoginAndRunPending(); |
64 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); | 70 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); |
65 provider_->Provide(&store); | 71 provider_->Provide(&store); |
66 ASSERT_EQ(1U, store.policy_map().size()); | 72 ASSERT_EQ(1U, store.policy_map().size()); |
67 Mock::VerifyAndClearExpectations(backend_); | 73 Mock::VerifyAndClearExpectations(backend_); |
68 Mock::VerifyAndClearExpectations(&store); | 74 Mock::VerifyAndClearExpectations(&store); |
69 } | 75 } |
70 | 76 |
71 virtual void TearDown() { | 77 virtual void TearDown() { |
72 loop_.RunAllPending(); | 78 loop_.RunAllPending(); |
73 } | 79 } |
74 | 80 |
75 protected: | 81 protected: |
76 MockDeviceManagementBackend* backend_; // weak | 82 MockDeviceManagementBackend* backend_; // weak |
77 scoped_ptr<DeviceManagementPolicyProvider> provider_; | 83 scoped_ptr<DeviceManagementPolicyProvider> provider_; |
78 | 84 |
79 private: | 85 private: |
80 MessageLoop loop_; | 86 MessageLoop loop_; |
81 BrowserThread ui_thread_; | 87 BrowserThread ui_thread_; |
82 BrowserThread file_thread_; | 88 BrowserThread file_thread_; |
83 ScopedTempDir storage_dir_; | 89 ScopedTempDir storage_dir_; |
90 scoped_ptr<TokenService> token_service_; | |
84 | 91 |
85 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest); | 92 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest); |
86 }; | 93 }; |
87 | 94 |
88 // If there's no login and no previously-fetched policy, the provider should | 95 // If there's no login and no previously-fetched policy, the provider should |
89 // provide an empty policy. | 96 // provide an empty policy. |
90 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) { | 97 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) { |
91 MockConfigurationPolicyStore store; | 98 MockConfigurationPolicyStore store; |
92 backend_->AllShouldSucceed(); | 99 backend_->AllShouldSucceed(); |
93 EXPECT_CALL(store, Apply(_, _)).Times(0); | 100 EXPECT_CALL(store, Apply(_, _)).Times(0); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 NotificationRegistrar registrar; | 145 NotificationRegistrar registrar; |
139 registrar.Add(&observer, | 146 registrar.Add(&observer, |
140 NotificationType::POLICY_CHANGED, | 147 NotificationType::POLICY_CHANGED, |
141 NotificationService::AllSources()); | 148 NotificationService::AllSources()); |
142 EXPECT_CALL(observer, | 149 EXPECT_CALL(observer, |
143 Observe(_, _, _)).Times(1); | 150 Observe(_, _, _)).Times(1); |
144 SimulateSuccessfulInitialPolicyFetch(); | 151 SimulateSuccessfulInitialPolicyFetch(); |
145 } | 152 } |
146 | 153 |
147 } | 154 } |
OLD | NEW |