| 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" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 loop_.RunAllPending(); | 56 loop_.RunAllPending(); |
| 57 token_service_->IssueAuthTokenForTest( | 57 token_service_->IssueAuthTokenForTest( |
| 58 GaiaConstants::kDeviceManagementService, kTestToken); | 58 GaiaConstants::kDeviceManagementService, kTestToken); |
| 59 loop_.RunAllPending(); | 59 loop_.RunAllPending(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void SimulateSuccessfulInitialPolicyFetch() { | 62 void SimulateSuccessfulInitialPolicyFetch() { |
| 63 MockConfigurationPolicyStore store; | 63 MockConfigurationPolicyStore store; |
| 64 backend_->AllShouldSucceed(); | 64 backend_->AllShouldSucceed(); |
| 65 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); | 65 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
| 66 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(1); | 66 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).Times(1); |
| 67 SimulateSuccessfulLoginAndRunPending(); | 67 SimulateSuccessfulLoginAndRunPending(); |
| 68 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); | 68 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); |
| 69 provider_->Provide(&store); | 69 provider_->Provide(&store); |
| 70 ASSERT_EQ(1U, store.policy_map().size()); | 70 ASSERT_EQ(1U, store.policy_map().size()); |
| 71 Mock::VerifyAndClearExpectations(backend_); | 71 Mock::VerifyAndClearExpectations(backend_); |
| 72 Mock::VerifyAndClearExpectations(&store); | 72 Mock::VerifyAndClearExpectations(&store); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual void TearDown() { | 75 virtual void TearDown() { |
| 76 loop_.RunAllPending(); | 76 loop_.RunAllPending(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 106 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideWithLogin) { | 106 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideWithLogin) { |
| 107 SimulateSuccessfulInitialPolicyFetch(); | 107 SimulateSuccessfulInitialPolicyFetch(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // If the login succeeds but the device management backend is unreachable, | 110 // If the login succeeds but the device management backend is unreachable, |
| 111 // there should be no policy provided if there's no previously-fetched policy, | 111 // there should be no policy provided if there's no previously-fetched policy, |
| 112 TEST_F(DeviceManagementPolicyProviderTest, EmptyProvideWithFailedBackend) { | 112 TEST_F(DeviceManagementPolicyProviderTest, EmptyProvideWithFailedBackend) { |
| 113 MockConfigurationPolicyStore store; | 113 MockConfigurationPolicyStore store; |
| 114 backend_->AllShouldFail(); | 114 backend_->AllShouldFail(); |
| 115 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); | 115 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
| 116 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(0); | 116 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).Times(0); |
| 117 SimulateSuccessfulLoginAndRunPending(); | 117 SimulateSuccessfulLoginAndRunPending(); |
| 118 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(0); | 118 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(0); |
| 119 provider_->Provide(&store); | 119 provider_->Provide(&store); |
| 120 EXPECT_TRUE(store.policy_map().empty()); | 120 EXPECT_TRUE(store.policy_map().empty()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // If a policy has been fetched previously, if should be available even before | 123 // If a policy has been fetched previously, if should be available even before |
| 124 // the login succeeds or the device management backend is available. | 124 // the login succeeds or the device management backend is available. |
| 125 TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) { | 125 TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) { |
| 126 // Pre-fetch and persist a policy | 126 // Pre-fetch and persist a policy |
| 127 SimulateSuccessfulInitialPolicyFetch(); | 127 SimulateSuccessfulInitialPolicyFetch(); |
| 128 | 128 |
| 129 // Simulate a app relaunch by constructing a new provider. Policy should be | 129 // Simulate a app relaunch by constructing a new provider. Policy should be |
| 130 // immediately provided and no refresh should be triggered. | 130 // immediately provided and no refresh should be triggered. |
| 131 CreateNewBackend(); | 131 CreateNewBackend(); |
| 132 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(0); | 132 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).Times(0); |
| 133 CreateNewProvider(); | 133 CreateNewProvider(); |
| 134 MockConfigurationPolicyStore store; | 134 MockConfigurationPolicyStore store; |
| 135 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); | 135 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); |
| 136 provider_->Provide(&store); | 136 provider_->Provide(&store); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // When policy is successfully fetched from the device management server, it | 139 // When policy is successfully fetched from the device management server, it |
| 140 // should force a policy refresh. | 140 // should force a policy refresh. |
| 141 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) { | 141 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) { |
| 142 MockNotificationObserver observer; | 142 MockNotificationObserver observer; |
| 143 NotificationRegistrar registrar; | 143 NotificationRegistrar registrar; |
| 144 registrar.Add(&observer, | 144 registrar.Add(&observer, |
| 145 NotificationType::POLICY_CHANGED, | 145 NotificationType::POLICY_CHANGED, |
| 146 NotificationService::AllSources()); | 146 NotificationService::AllSources()); |
| 147 EXPECT_CALL(observer, | 147 EXPECT_CALL(observer, |
| 148 Observe(_, _, _)).Times(1); | 148 Observe(_, _, _)).Times(1); |
| 149 SimulateSuccessfulInitialPolicyFetch(); | 149 SimulateSuccessfulInitialPolicyFetch(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 } | 152 } |
| OLD | NEW |