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

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

Issue 10386176: Revert "Refactored NetworkConfigurationUpdater to read policy from the PolicyService." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months 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
« no previous file with comments | « chrome/browser/policy/network_configuration_updater.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/network_configuration_updater.h" 5 #include "chrome/browser/policy/network_configuration_updater.h"
6 6
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/chromeos/cros/mock_network_library.h" 7 #include "chrome/browser/chromeos/cros/mock_network_library.h"
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 8 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
10 #include "chrome/browser/policy/policy_map.h" 9 #include "chrome/browser/policy/policy_map.h"
11 #include "chrome/browser/policy/policy_service_impl.h"
12 #include "policy/policy_constants.h" 10 #include "policy/policy_constants.h"
13 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
15 13
16 using testing::Mock; 14 using testing::Mock;
17 using testing::Return; 15 using testing::Return;
18 using testing::_; 16 using testing::_;
19 17
20 namespace policy { 18 namespace policy {
21 19
22 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; 20 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }";
23 21
24 class NetworkConfigurationUpdaterTest 22 class NetworkConfigurationUpdaterTest
25 : public testing::TestWithParam<const char*> { 23 : public testing::TestWithParam<const char*> {
26 protected: 24 protected:
27 virtual void SetUp() OVERRIDE { 25 virtual void SetUp() OVERRIDE {
28 EXPECT_CALL(network_library_, LoadOncNetworks(_, "", _, _)) 26 EXPECT_CALL(network_library_, LoadOncNetworks(_, "", _, _))
29 .WillRepeatedly(Return(true)); 27 .WillRepeatedly(Return(true));
30 PolicyServiceImpl::Providers providers;
31 providers.push_back(&provider_);
32 policy_service_.reset(new PolicyServiceImpl(providers));
33 } 28 }
34 29
35 // Maps configuration policy name to corresponding ONC source. 30 // Maps configuration policy name to corresponding ONC source.
36 static chromeos::NetworkUIData::ONCSource NameToONCSource( 31 static chromeos::NetworkUIData::ONCSource NameToONCSource(
37 const std::string& name) { 32 const std::string& name) {
38 if (name == key::kDeviceOpenNetworkConfiguration) 33 if (name == key::kDeviceOpenNetworkConfiguration)
39 return chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY; 34 return chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY;
40 if (name == key::kOpenNetworkConfiguration) 35 if (name == key::kOpenNetworkConfiguration)
41 return chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY; 36 return chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY;
42 return chromeos::NetworkUIData::ONC_SOURCE_NONE; 37 return chromeos::NetworkUIData::ONC_SOURCE_NONE;
43 } 38 }
44 39
45 chromeos::MockNetworkLibrary network_library_; 40 chromeos::MockNetworkLibrary network_library_;
46 MockConfigurationPolicyProvider provider_; 41 MockConfigurationPolicyProvider provider_;
47 scoped_ptr<PolicyServiceImpl> policy_service_;
48 }; 42 };
49 43
50 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) { 44 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) {
51 PolicyMap policy; 45 PolicyMap policy;
52 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 46 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
53 Value::CreateStringValue(kFakeONC)); 47 Value::CreateStringValue(kFakeONC));
54 provider_.UpdateChromePolicy(policy); 48 provider_.UpdateChromePolicy(policy);
55 49
56 EXPECT_CALL(network_library_, 50 EXPECT_CALL(network_library_,
57 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 51 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _))
58 .WillOnce(Return(true)); 52 .WillOnce(Return(true));
59 53
60 NetworkConfigurationUpdater updater(policy_service_.get(), &network_library_); 54 NetworkConfigurationUpdater updater(&provider_, &network_library_);
61 Mock::VerifyAndClearExpectations(&network_library_); 55 Mock::VerifyAndClearExpectations(&network_library_);
62 } 56 }
63 57
64 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { 58 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) {
65 NetworkConfigurationUpdater updater(policy_service_.get(), &network_library_); 59 NetworkConfigurationUpdater updater(&provider_, &network_library_);
66 60
67 // We should update if policy changes. 61 // We should update if policy changes.
68 EXPECT_CALL(network_library_, 62 EXPECT_CALL(network_library_,
69 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 63 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _))
70 .WillOnce(Return(true)); 64 .WillOnce(Return(true));
71 PolicyMap policy; 65 PolicyMap policy;
72 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 66 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
73 Value::CreateStringValue(kFakeONC)); 67 Value::CreateStringValue(kFakeONC));
74 provider_.UpdateChromePolicy(policy); 68 provider_.UpdateChromePolicy(policy);
75 Mock::VerifyAndClearExpectations(&network_library_); 69 Mock::VerifyAndClearExpectations(&network_library_);
(...skipping 15 matching lines...) Expand all
91 Mock::VerifyAndClearExpectations(&network_library_); 85 Mock::VerifyAndClearExpectations(&network_library_);
92 } 86 }
93 87
94 INSTANTIATE_TEST_CASE_P( 88 INSTANTIATE_TEST_CASE_P(
95 NetworkConfigurationUpdaterTestInstance, 89 NetworkConfigurationUpdaterTestInstance,
96 NetworkConfigurationUpdaterTest, 90 NetworkConfigurationUpdaterTest,
97 testing::Values(key::kDeviceOpenNetworkConfiguration, 91 testing::Values(key::kDeviceOpenNetworkConfiguration,
98 key::kOpenNetworkConfiguration)); 92 key::kOpenNetworkConfiguration));
99 93
100 } // namespace policy 94 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/network_configuration_updater.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698