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

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: rebaesd 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(), &network_library_);
63 Mock::VerifyAndClearExpectations(&network_library_); 64 Mock::VerifyAndClearExpectations(&network_library_);
64 } 65 }
65 66
67 TEST_P(NetworkConfigurationUpdaterTest, AllowWebTrust) {
68 NetworkConfigurationUpdater updater(policy_service_.get(), &network_library_);
69 updater.set_allow_web_trust(true);
70
71 EXPECT_CALL(network_library_,
72 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()),
73 true, _))
74 .WillOnce(Return(true));
75
76 PolicyMap policy;
77 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
78 Value::CreateStringValue(kFakeONC));
79 provider_.UpdateChromePolicy(policy);
80 Mock::VerifyAndClearExpectations(&network_library_);
81 }
82
66 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { 83 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) {
67 NetworkConfigurationUpdater updater(policy_service_.get(), &network_library_); 84 NetworkConfigurationUpdater updater(policy_service_.get(), &network_library_);
68 85
69 // We should update if policy changes. 86 // We should update if policy changes.
70 EXPECT_CALL(network_library_, 87 EXPECT_CALL(network_library_,
71 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 88 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()),
89 false, _))
72 .WillOnce(Return(true)); 90 .WillOnce(Return(true));
73 PolicyMap policy; 91 PolicyMap policy;
74 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 92 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
75 Value::CreateStringValue(kFakeONC)); 93 Value::CreateStringValue(kFakeONC));
76 provider_.UpdateChromePolicy(policy); 94 provider_.UpdateChromePolicy(policy);
77 Mock::VerifyAndClearExpectations(&network_library_); 95 Mock::VerifyAndClearExpectations(&network_library_);
78 96
79 // No update if the set the same value again. 97 // No update if the set the same value again.
80 EXPECT_CALL(network_library_, 98 EXPECT_CALL(network_library_,
81 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 99 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()),
100 false, _))
82 .Times(0); 101 .Times(0);
83 provider_.UpdateChromePolicy(policy); 102 provider_.UpdateChromePolicy(policy);
84 Mock::VerifyAndClearExpectations(&network_library_); 103 Mock::VerifyAndClearExpectations(&network_library_);
85 104
86 // Another update is expected if the policy goes away. 105 // Another update is expected if the policy goes away.
87 EXPECT_CALL(network_library_, 106 EXPECT_CALL(network_library_,
88 LoadOncNetworks(NetworkConfigurationUpdater::kEmptyConfiguration, 107 LoadOncNetworks(NetworkConfigurationUpdater::kEmptyConfiguration,
89 "", NameToONCSource(GetParam()), _)) 108 "", NameToONCSource(GetParam()), false, _))
90 .WillOnce(Return(true)); 109 .WillOnce(Return(true));
91 policy.Erase(GetParam()); 110 policy.Erase(GetParam());
92 provider_.UpdateChromePolicy(policy); 111 provider_.UpdateChromePolicy(policy);
93 Mock::VerifyAndClearExpectations(&network_library_); 112 Mock::VerifyAndClearExpectations(&network_library_);
94 } 113 }
95 114
96 INSTANTIATE_TEST_CASE_P( 115 INSTANTIATE_TEST_CASE_P(
97 NetworkConfigurationUpdaterTestInstance, 116 NetworkConfigurationUpdaterTestInstance,
98 NetworkConfigurationUpdaterTest, 117 NetworkConfigurationUpdaterTest,
99 testing::Values(key::kDeviceOpenNetworkConfiguration, 118 testing::Values(key::kDeviceOpenNetworkConfiguration,
100 key::kOpenNetworkConfiguration)); 119 key::kOpenNetworkConfiguration));
101 120
102 } // namespace policy 121 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/network_configuration_updater.cc ('k') | chrome/browser/ui/webui/net_internals/net_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698