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

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

Issue 10868076: Only import certificates with Web trust from ONC if the user is managed and matches the enterprise … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased, addressed comments Created 8 years, 3 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
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" 7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/chromeos/cros/mock_network_library.h" 8 #include "chrome/browser/chromeos/cros/mock_network_library.h"
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 9 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
10 #include "chrome/browser/policy/policy_map.h" 10 #include "chrome/browser/policy/policy_map.h"
11 #include "chrome/browser/policy/policy_service_impl.h" 11 #include "chrome/browser/policy/policy_service_impl.h"
12 #include "policy/policy_constants.h" 12 #include "policy/policy_constants.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using testing::Mock; 16 using testing::Mock;
17 using testing::Return; 17 using testing::Return;
18 using testing::_; 18 using testing::_;
19 19
20 namespace policy { 20 namespace policy {
21 21
22 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; 22 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }";
23 23
24 class NetworkConfigurationUpdaterTest 24 class NetworkConfigurationUpdaterTest
25 : public testing::TestWithParam<const char*> { 25 : public testing::TestWithParam<const char*> {
26 protected: 26 protected:
27 virtual void SetUp() OVERRIDE { 27 virtual void SetUp() OVERRIDE {
28 EXPECT_CALL(network_library_, LoadOncNetworks(_, "", _, _)) 28 EXPECT_CALL(network_library_, LoadOncNetworks(_, "", _, _, _))
29 .WillRepeatedly(Return(true)); 29 .WillRepeatedly(Return(true));
30 EXPECT_CALL(provider_, IsInitializationComplete()) 30 EXPECT_CALL(provider_, IsInitializationComplete())
31 .WillRepeatedly(Return(true)); 31 .WillRepeatedly(Return(true));
32 PolicyServiceImpl::Providers providers; 32 PolicyServiceImpl::Providers providers;
33 providers.push_back(&provider_); 33 providers.push_back(&provider_);
34 policy_service_.reset(new PolicyServiceImpl(providers)); 34 policy_service_.reset(new PolicyServiceImpl(providers));
35 } 35 }
36 36
37 // Maps configuration policy name to corresponding ONC source. 37 // Maps configuration policy name to corresponding ONC source.
38 static chromeos::NetworkUIData::ONCSource NameToONCSource( 38 static chromeos::NetworkUIData::ONCSource NameToONCSource(
(...skipping 10 matching lines...) Expand all
49 scoped_ptr<PolicyServiceImpl> policy_service_; 49 scoped_ptr<PolicyServiceImpl> policy_service_;
50 }; 50 };
51 51
52 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) { 52 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) {
53 PolicyMap policy; 53 PolicyMap policy;
54 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 54 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
55 Value::CreateStringValue(kFakeONC)); 55 Value::CreateStringValue(kFakeONC));
56 provider_.UpdateChromePolicy(policy); 56 provider_.UpdateChromePolicy(policy);
57 57
58 EXPECT_CALL(network_library_, 58 EXPECT_CALL(network_library_,
59 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 59 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()),
60 false, _))
60 .WillOnce(Return(true)); 61 .WillOnce(Return(true));
61 62
62 NetworkConfigurationUpdater updater(policy_service_.get(), &network_library_); 63 NetworkConfigurationUpdater updater(policy_service_.get(),
64 &network_library_);
65 Mock::VerifyAndClearExpectations(&network_library_);
66 }
67
68 TEST_P(NetworkConfigurationUpdaterTest, AllowWebTrust) {
69 NetworkConfigurationUpdater updater(policy_service_.get(),
70 &network_library_);
71 updater.set_allow_web_trust(true);
72
73 EXPECT_CALL(network_library_,
74 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()),
75 true, _))
76 .WillOnce(Return(true));
77
78 PolicyMap policy;
79 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
80 Value::CreateStringValue(kFakeONC));
81 provider_.UpdateChromePolicy(policy);
63 Mock::VerifyAndClearExpectations(&network_library_); 82 Mock::VerifyAndClearExpectations(&network_library_);
64 } 83 }
65 84
66 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { 85 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) {
67 NetworkConfigurationUpdater updater(policy_service_.get(), &network_library_); 86 NetworkConfigurationUpdater updater(policy_service_.get(),
87 &network_library_);
68 88
69 // We should update if policy changes. 89 // We should update if policy changes.
70 EXPECT_CALL(network_library_, 90 EXPECT_CALL(network_library_,
71 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 91 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()),
92 false, _))
72 .WillOnce(Return(true)); 93 .WillOnce(Return(true));
73 PolicyMap policy; 94 PolicyMap policy;
74 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 95 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
75 Value::CreateStringValue(kFakeONC)); 96 Value::CreateStringValue(kFakeONC));
76 provider_.UpdateChromePolicy(policy); 97 provider_.UpdateChromePolicy(policy);
77 Mock::VerifyAndClearExpectations(&network_library_); 98 Mock::VerifyAndClearExpectations(&network_library_);
78 99
79 // No update if the set the same value again. 100 // No update if the set the same value again.
80 EXPECT_CALL(network_library_, 101 EXPECT_CALL(network_library_,
81 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 102 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()),
103 false, _))
82 .Times(0); 104 .Times(0);
83 provider_.UpdateChromePolicy(policy); 105 provider_.UpdateChromePolicy(policy);
84 Mock::VerifyAndClearExpectations(&network_library_); 106 Mock::VerifyAndClearExpectations(&network_library_);
85 107
86 // Another update is expected if the policy goes away. 108 // Another update is expected if the policy goes away.
87 EXPECT_CALL(network_library_, 109 EXPECT_CALL(network_library_,
88 LoadOncNetworks(NetworkConfigurationUpdater::kEmptyConfiguration, 110 LoadOncNetworks(NetworkConfigurationUpdater::kEmptyConfiguration,
89 "", NameToONCSource(GetParam()), _)) 111 "", NameToONCSource(GetParam()), false, _))
90 .WillOnce(Return(true)); 112 .WillOnce(Return(true));
91 policy.Erase(GetParam()); 113 policy.Erase(GetParam());
92 provider_.UpdateChromePolicy(policy); 114 provider_.UpdateChromePolicy(policy);
93 Mock::VerifyAndClearExpectations(&network_library_); 115 Mock::VerifyAndClearExpectations(&network_library_);
94 } 116 }
95 117
96 INSTANTIATE_TEST_CASE_P( 118 INSTANTIATE_TEST_CASE_P(
97 NetworkConfigurationUpdaterTestInstance, 119 NetworkConfigurationUpdaterTestInstance,
98 NetworkConfigurationUpdaterTest, 120 NetworkConfigurationUpdaterTest,
99 testing::Values(key::kDeviceOpenNetworkConfiguration, 121 testing::Values(key::kDeviceOpenNetworkConfiguration,
100 key::kOpenNetworkConfiguration)); 122 key::kOpenNetworkConfiguration));
101 123
102 } // namespace policy 124 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698