Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: chrome/browser/policy/device_management_policy_provider_unittest.cc

Issue 5174006: Move DeviceManagementPolicyProvider into the profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 const char kTestToken[] = "device_policy_provider_test_auth_token";
20
20 namespace policy { 21 namespace policy {
21 22
22 using ::testing::_; 23 using ::testing::_;
23 using ::testing::Mock; 24 using ::testing::Mock;
24 25
25 class DeviceManagementPolicyProviderTest : public testing::Test { 26 class DeviceManagementPolicyProviderTest : public testing::Test {
26 public: 27 public:
27 DeviceManagementPolicyProviderTest() 28 DeviceManagementPolicyProviderTest()
28 : ui_thread_(BrowserThread::UI, &loop_), 29 : ui_thread_(BrowserThread::UI, &loop_),
29 file_thread_(BrowserThread::FILE, &loop_) {} 30 file_thread_(BrowserThread::FILE, &loop_) {}
30 31
31 virtual ~DeviceManagementPolicyProviderTest() {} 32 virtual ~DeviceManagementPolicyProviderTest() {}
32 33
33 virtual void SetUp() { 34 virtual void SetUp() {
34 EXPECT_TRUE(storage_dir_.CreateUniqueTempDir()); 35 EXPECT_TRUE(storage_dir_.CreateUniqueTempDir());
35 CreateNewBackend(); 36 CreateNewBackend();
36 CreateNewProvider(); 37 CreateNewProvider();
37 } 38 }
38 39
39 void CreateNewBackend() { 40 void CreateNewBackend() {
40 backend_ = new MockDeviceManagementBackend; 41 backend_ = new MockDeviceManagementBackend;
41 backend_->AddBooleanPolicy(key::kDisableSpdy, true); 42 backend_->AddBooleanPolicy(key::kDisableSpdy, true);
42 } 43 }
43 44
44 void CreateNewProvider() { 45 void CreateNewProvider() {
46 token_service_.reset(new TokenService);
45 provider_.reset(new DeviceManagementPolicyProvider( 47 provider_.reset(new DeviceManagementPolicyProvider(
46 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), 48 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
47 backend_, 49 backend_,
50 token_service_.get(),
48 storage_dir_.path())); 51 storage_dir_.path()));
49 loop_.RunAllPending(); 52 loop_.RunAllPending();
50 } 53 }
51 54
52 void SimulateSuccessfulLoginAndRunPending() { 55 void SimulateSuccessfulLoginAndRunPending() {
53 loop_.RunAllPending(); 56 loop_.RunAllPending();
54 SimulateSuccessfulLogin(); 57 token_service_->IssueAuthTokenForTest(
58 GaiaConstants::kDeviceManagementService, kTestToken);
55 loop_.RunAllPending(); 59 loop_.RunAllPending();
56 } 60 }
57 61
58 void SimulateSuccessfulInitialPolicyFetch() { 62 void SimulateSuccessfulInitialPolicyFetch() {
59 MockConfigurationPolicyStore store; 63 MockConfigurationPolicyStore store;
60 backend_->AllShouldSucceed(); 64 backend_->AllShouldSucceed();
61 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); 65 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1);
62 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(1); 66 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(1);
63 SimulateSuccessfulLoginAndRunPending(); 67 SimulateSuccessfulLoginAndRunPending();
64 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); 68 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1);
65 provider_->Provide(&store); 69 provider_->Provide(&store);
66 ASSERT_EQ(1U, store.policy_map().size()); 70 ASSERT_EQ(1U, store.policy_map().size());
67 Mock::VerifyAndClearExpectations(backend_); 71 Mock::VerifyAndClearExpectations(backend_);
68 Mock::VerifyAndClearExpectations(&store); 72 Mock::VerifyAndClearExpectations(&store);
69 } 73 }
70 74
71 virtual void TearDown() { 75 virtual void TearDown() {
72 loop_.RunAllPending(); 76 loop_.RunAllPending();
73 } 77 }
74 78
75 protected: 79 protected:
76 MockDeviceManagementBackend* backend_; // weak 80 MockDeviceManagementBackend* backend_; // weak
77 scoped_ptr<DeviceManagementPolicyProvider> provider_; 81 scoped_ptr<DeviceManagementPolicyProvider> provider_;
78 82
79 private: 83 private:
80 MessageLoop loop_; 84 MessageLoop loop_;
81 BrowserThread ui_thread_; 85 BrowserThread ui_thread_;
82 BrowserThread file_thread_; 86 BrowserThread file_thread_;
83 ScopedTempDir storage_dir_; 87 ScopedTempDir storage_dir_;
88 scoped_ptr<TokenService> token_service_;
84 89
85 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest); 90 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest);
86 }; 91 };
87 92
88 // If there's no login and no previously-fetched policy, the provider should 93 // If there's no login and no previously-fetched policy, the provider should
89 // provide an empty policy. 94 // provide an empty policy.
90 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) { 95 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) {
91 MockConfigurationPolicyStore store; 96 MockConfigurationPolicyStore store;
92 backend_->AllShouldSucceed(); 97 backend_->AllShouldSucceed();
93 EXPECT_CALL(store, Apply(_, _)).Times(0); 98 EXPECT_CALL(store, Apply(_, _)).Times(0);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 NotificationRegistrar registrar; 143 NotificationRegistrar registrar;
139 registrar.Add(&observer, 144 registrar.Add(&observer,
140 NotificationType::POLICY_CHANGED, 145 NotificationType::POLICY_CHANGED,
141 NotificationService::AllSources()); 146 NotificationService::AllSources());
142 EXPECT_CALL(observer, 147 EXPECT_CALL(observer,
143 Observe(_, _, _)).Times(1); 148 Observe(_, _, _)).Times(1);
144 SimulateSuccessfulInitialPolicyFetch(); 149 SimulateSuccessfulInitialPolicyFetch();
145 } 150 }
146 151
147 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698