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

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

Issue 4960003: Don't register gmail users at the device management server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " 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/mock_notification_observer.h" 16 #include "chrome/test/mock_notification_observer.h"
17 #include "chrome/test/testing_device_token_fetcher.h"
18 #include "chrome/test/testing_profile.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
19 const char kTestToken[] = "device_policy_provider_test_auth_token"; 21 const char kTestToken[] = "device_policy_provider_test_auth_token";
20 22
21 namespace policy { 23 namespace policy {
22 24
23 using ::testing::_; 25 using ::testing::_;
24 using ::testing::Mock; 26 using ::testing::Mock;
25 27
26 class DeviceManagementPolicyProviderTest : public testing::Test { 28 class DeviceManagementPolicyProviderTest : public testing::Test {
27 public: 29 public:
28 DeviceManagementPolicyProviderTest() 30 DeviceManagementPolicyProviderTest()
29 : ui_thread_(BrowserThread::UI, &loop_), 31 : ui_thread_(BrowserThread::UI, &loop_),
30 file_thread_(BrowserThread::FILE, &loop_) {} 32 file_thread_(BrowserThread::FILE, &loop_) {}
31 33
32 virtual ~DeviceManagementPolicyProviderTest() {} 34 virtual ~DeviceManagementPolicyProviderTest() {}
33 35
34 virtual void SetUp() { 36 virtual void SetUp() {
35 EXPECT_TRUE(storage_dir_.CreateUniqueTempDir()); 37 EXPECT_TRUE(storage_dir_.CreateUniqueTempDir());
38 profile_.reset(new TestingProfile);
36 CreateNewBackend(); 39 CreateNewBackend();
37 CreateNewProvider(); 40 CreateNewProvider();
38 } 41 }
39 42
40 void CreateNewBackend() { 43 void CreateNewBackend() {
41 backend_ = new MockDeviceManagementBackend; 44 backend_ = new MockDeviceManagementBackend;
42 backend_->AddBooleanPolicy(key::kDisableSpdy, true); 45 backend_->AddBooleanPolicy(key::kDisableSpdy, true);
43 } 46 }
44 47
45 void CreateNewProvider() { 48 void CreateNewProvider() {
46 token_service_.reset(new TokenService);
47 provider_.reset(new DeviceManagementPolicyProvider( 49 provider_.reset(new DeviceManagementPolicyProvider(
48 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), 50 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
49 backend_, 51 backend_,
50 token_service_.get(), 52 profile_.get(),
51 storage_dir_.path())); 53 new TestingDeviceTokenFetcher(backend_,
54 profile_.get(),
55 storage_dir_.path())));
52 loop_.RunAllPending(); 56 loop_.RunAllPending();
53 } 57 }
54 58
55 void SimulateSuccessfulLoginAndRunPending() { 59 void SimulateSuccessfulLoginAndRunPending() {
56 loop_.RunAllPending(); 60 loop_.RunAllPending();
57 token_service_->IssueAuthTokenForTest( 61 profile_->GetTokenService()->IssueAuthTokenForTest(
58 GaiaConstants::kDeviceManagementService, kTestToken); 62 GaiaConstants::kDeviceManagementService, kTestToken);
63 TestingDeviceTokenFetcher* fetcher =
64 static_cast<TestingDeviceTokenFetcher*> (
Mattias Nissler (ping if slow) 2010/11/22 20:36:08 No space before (
gfeher 2010/11/23 13:47:51 Done.
65 provider_->token_fetcher_.get());
66 fetcher->SimulateLogin(kTestDasherDomainUsername);
59 loop_.RunAllPending(); 67 loop_.RunAllPending();
60 } 68 }
61 69
62 void SimulateSuccessfulInitialPolicyFetch() { 70 void SimulateSuccessfulInitialPolicyFetch() {
63 MockConfigurationPolicyStore store; 71 MockConfigurationPolicyStore store;
64 backend_->AllShouldSucceed(); 72 backend_->AllShouldSucceed();
65 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); 73 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1);
66 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(1); 74 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(1);
67 SimulateSuccessfulLoginAndRunPending(); 75 SimulateSuccessfulLoginAndRunPending();
68 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); 76 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1);
69 provider_->Provide(&store); 77 provider_->Provide(&store);
70 ASSERT_EQ(1U, store.policy_map().size()); 78 ASSERT_EQ(1U, store.policy_map().size());
71 Mock::VerifyAndClearExpectations(backend_); 79 Mock::VerifyAndClearExpectations(backend_);
72 Mock::VerifyAndClearExpectations(&store); 80 Mock::VerifyAndClearExpectations(&store);
73 } 81 }
74 82
75 virtual void TearDown() { 83 virtual void TearDown() {
76 loop_.RunAllPending(); 84 loop_.RunAllPending();
77 } 85 }
78 86
79 protected: 87 protected:
80 MockDeviceManagementBackend* backend_; // weak 88 MockDeviceManagementBackend* backend_; // weak
81 scoped_ptr<DeviceManagementPolicyProvider> provider_; 89 scoped_ptr<DeviceManagementPolicyProvider> provider_;
82 90
83 private: 91 private:
84 MessageLoop loop_; 92 MessageLoop loop_;
85 BrowserThread ui_thread_; 93 BrowserThread ui_thread_;
86 BrowserThread file_thread_; 94 BrowserThread file_thread_;
87 ScopedTempDir storage_dir_; 95 ScopedTempDir storage_dir_;
88 scoped_ptr<TokenService> token_service_; 96 scoped_ptr<Profile> profile_;
89 97
90 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest); 98 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest);
91 }; 99 };
92 100
93 // If there's no login and no previously-fetched policy, the provider should 101 // If there's no login and no previously-fetched policy, the provider should
94 // provide an empty policy. 102 // provide an empty policy.
95 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) { 103 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) {
96 MockConfigurationPolicyStore store; 104 MockConfigurationPolicyStore store;
97 backend_->AllShouldSucceed(); 105 backend_->AllShouldSucceed();
98 EXPECT_CALL(store, Apply(_, _)).Times(0); 106 EXPECT_CALL(store, Apply(_, _)).Times(0);
(...skipping 21 matching lines...) Expand all
120 EXPECT_TRUE(store.policy_map().empty()); 128 EXPECT_TRUE(store.policy_map().empty());
121 } 129 }
122 130
123 // If a policy has been fetched previously, if should be available even before 131 // If a policy has been fetched previously, if should be available even before
124 // the login succeeds or the device management backend is available. 132 // the login succeeds or the device management backend is available.
125 TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) { 133 TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) {
126 // Pre-fetch and persist a policy 134 // Pre-fetch and persist a policy
127 SimulateSuccessfulInitialPolicyFetch(); 135 SimulateSuccessfulInitialPolicyFetch();
128 136
129 // Simulate a app relaunch by constructing a new provider. Policy should be 137 // Simulate a app relaunch by constructing a new provider. Policy should be
130 // immediately provided and no refresh should be triggered. 138 // immediately provided and no refresh should be triggered.
gfeher 2010/11/22 16:05:51 There is a logic change here, because the TestingP
Mattias Nissler (ping if slow) 2010/11/22 20:36:08 Can we just reinitialize everything, i.e. the prof
gfeher 2010/11/23 13:47:51 No changes made, as discussed.
131 CreateNewBackend(); 139 CreateNewBackend();
132 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(0); 140 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(0);
133 CreateNewProvider(); 141 CreateNewProvider();
134 MockConfigurationPolicyStore store; 142 MockConfigurationPolicyStore store;
135 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); 143 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1);
136 provider_->Provide(&store); 144 provider_->Provide(&store);
137 } 145 }
138 146
139 // When policy is successfully fetched from the device management server, it 147 // When policy is successfully fetched from the device management server, it
140 // should force a policy refresh. 148 // should force a policy refresh.
141 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) { 149 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) {
142 MockNotificationObserver observer; 150 MockNotificationObserver observer;
143 NotificationRegistrar registrar; 151 NotificationRegistrar registrar;
144 registrar.Add(&observer, 152 registrar.Add(&observer,
145 NotificationType::POLICY_CHANGED, 153 NotificationType::POLICY_CHANGED,
146 NotificationService::AllSources()); 154 NotificationService::AllSources());
147 EXPECT_CALL(observer, 155 EXPECT_CALL(observer,
148 Observe(_, _, _)).Times(1); 156 Observe(_, _, _)).Times(1);
149 SimulateSuccessfulInitialPolicyFetch(); 157 SimulateSuccessfulInitialPolicyFetch();
150 } 158 }
151 159
152 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698