Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chromeos/network/managed_network_configuration_handler.h" | 5 #include "chromeos/network/managed_network_configuration_handler.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 12 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/mock_shill_manager_client.h" | 13 #include "chromeos/dbus/mock_shill_manager_client.h" |
| 14 #include "chromeos/dbus/mock_shill_profile_client.h" | 14 #include "chromeos/dbus/mock_shill_profile_client.h" |
| 15 #include "chromeos/dbus/mock_shill_service_client.h" | 15 #include "chromeos/dbus/mock_shill_service_client.h" |
| 16 #include "chromeos/dbus/shill_profile_client_stub.h" | 16 #include "chromeos/dbus/shill_profile_client_stub.h" |
| 17 #include "chromeos/network/network_configuration_handler.h" | 17 #include "chromeos/network/network_configuration_handler.h" |
| 18 #include "chromeos/network/network_profile_handler_stub.h" | |
| 18 #include "chromeos/network/onc/onc_test_utils.h" | 19 #include "chromeos/network/onc/onc_test_utils.h" |
| 19 #include "chromeos/network/onc/onc_utils.h" | 20 #include "chromeos/network/onc/onc_utils.h" |
| 20 #include "dbus/object_path.h" | 21 #include "dbus/object_path.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 24 | 25 |
| 25 using ::testing::Invoke; | 26 using ::testing::Invoke; |
| 26 using ::testing::Mock; | 27 using ::testing::Mock; |
| 27 using ::testing::Pointee; | 28 using ::testing::Pointee; |
| 28 using ::testing::Return; | 29 using ::testing::Return; |
| 29 using ::testing::SaveArg; | 30 using ::testing::SaveArg; |
| 30 using ::testing::StrEq; | 31 using ::testing::StrEq; |
| 31 using ::testing::StrictMock; | 32 using ::testing::StrictMock; |
| 32 using ::testing::_; | 33 using ::testing::_; |
| 33 | 34 |
| 34 namespace test_utils = ::chromeos::onc::test_utils; | 35 namespace test_utils = ::chromeos::onc::test_utils; |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 std::string ValueToString(const base::Value* value) { | 39 std::string ValueToString(const base::Value* value) { |
| 39 std::stringstream str; | 40 std::stringstream str; |
| 40 str << *value; | 41 str << *value; |
| 41 return str.str(); | 42 return str.str(); |
| 42 } | 43 } |
| 43 | 44 |
| 45 const char kSharedProfilePath[] = "/profile/default"; | |
| 46 const char kUser1[] = "user1"; | |
| 47 const char kUser1ProfilePath[] = "/profile/user1/shill"; | |
| 48 | |
| 44 // Matcher to match base::Value. | 49 // Matcher to match base::Value. |
| 45 MATCHER_P(IsEqualTo, | 50 MATCHER_P(IsEqualTo, |
| 46 value, | 51 value, |
| 47 std::string(negation ? "isn't" : "is") + " equal to " + | 52 std::string(negation ? "isn't" : "is") + " equal to " + |
| 48 ValueToString(value)) { | 53 ValueToString(value)) { |
| 49 return value->Equals(&arg); | 54 return value->Equals(&arg); |
| 50 } | 55 } |
| 51 | 56 |
| 52 } // namespace | 57 } // namespace |
| 53 | 58 |
| 54 | 59 |
| 55 namespace chromeos { | 60 namespace chromeos { |
| 56 | 61 |
| 57 class ManagedNetworkConfigurationHandlerTest : public testing::Test { | 62 class ManagedNetworkConfigurationHandlerTest : public testing::Test { |
| 58 public: | 63 public: |
| 59 ManagedNetworkConfigurationHandlerTest() { | 64 ManagedNetworkConfigurationHandlerTest() |
| 65 : stub_profile_client_(NULL /* no ShillManagerClient::TestInterface */ ) { | |
| 60 } | 66 } |
| 61 | 67 |
| 62 virtual ~ManagedNetworkConfigurationHandlerTest() { | 68 virtual ~ManagedNetworkConfigurationHandlerTest() { |
| 63 } | 69 } |
| 64 | 70 |
| 65 virtual void SetUp() OVERRIDE { | 71 virtual void SetUp() OVERRIDE { |
| 66 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; | 72 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; |
| 67 EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) | 73 EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) |
| 68 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); | 74 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); |
| 69 DBusThreadManager::InitializeForTesting(dbus_thread_manager); | 75 DBusThreadManager::InitializeForTesting(dbus_thread_manager); |
| 70 | 76 |
| 71 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) | 77 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) |
| 72 .WillRepeatedly(Return(&mock_manager_client_)); | 78 .WillRepeatedly(Return(&mock_manager_client_)); |
| 73 EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient()) | 79 EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient()) |
| 74 .WillRepeatedly(Return(&mock_service_client_)); | 80 .WillRepeatedly(Return(&mock_service_client_)); |
| 75 EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient()) | 81 EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient()) |
| 76 .WillRepeatedly(Return(&mock_profile_client_)); | 82 .WillRepeatedly(Return(&mock_profile_client_)); |
| 77 | 83 |
| 78 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) | 84 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) |
| 79 .WillByDefault(Invoke(&stub_profile_client_, | 85 .WillByDefault(Invoke(&stub_profile_client_, |
| 80 &ShillProfileClientStub::GetProperties)); | 86 &ShillProfileClientStub::GetProperties)); |
| 81 | 87 |
| 82 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) | 88 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) |
| 83 .WillByDefault(Invoke(&stub_profile_client_, | 89 .WillByDefault(Invoke(&stub_profile_client_, |
| 84 &ShillProfileClientStub::GetEntry)); | 90 &ShillProfileClientStub::GetEntry)); |
| 85 | 91 |
| 86 NetworkConfigurationHandler::Initialize(); | 92 NetworkConfigurationHandler::Initialize(); |
| 87 ManagedNetworkConfigurationHandler::Initialize(); | 93 ManagedNetworkConfigurationHandler::Initialize(&stub_profile_handler_); |
|
pneubeck (no reviews)
2013/04/29 18:05:51
I think it would be better, to use the constructor
stevenjb
2013/04/30 17:42:47
If we were using a mock or a locally defined stub,
| |
| 88 message_loop_.RunUntilIdle(); | 94 message_loop_.RunUntilIdle(); |
| 89 } | 95 } |
| 90 | 96 |
| 91 virtual void TearDown() OVERRIDE { | 97 virtual void TearDown() OVERRIDE { |
| 92 ManagedNetworkConfigurationHandler::Shutdown(); | 98 ManagedNetworkConfigurationHandler::Shutdown(); |
| 93 NetworkConfigurationHandler::Shutdown(); | 99 NetworkConfigurationHandler::Shutdown(); |
| 94 DBusThreadManager::Shutdown(); | 100 DBusThreadManager::Shutdown(); |
| 95 } | 101 } |
| 96 | 102 |
| 103 void VerifyAndClearExpectations() { | |
| 104 Mock::VerifyAndClearExpectations(&mock_manager_client_); | |
| 105 Mock::VerifyAndClearExpectations(&mock_service_client_); | |
| 106 Mock::VerifyAndClearExpectations(&mock_profile_client_); | |
| 107 } | |
| 108 | |
| 109 void InitializeStandardProfiles() { | |
| 110 stub_profile_client_.AddProfile(kUser1ProfilePath, kUser1); | |
| 111 stub_profile_handler_.AddProfile(NetworkProfile(kUser1ProfilePath, kUser1)); | |
| 112 stub_profile_handler_.AddProfile( | |
| 113 NetworkProfile(kSharedProfilePath, std::string())); | |
| 114 } | |
| 115 | |
| 97 void SetUpEntry(const std::string& path_to_shill_json, | 116 void SetUpEntry(const std::string& path_to_shill_json, |
| 98 const std::string& profile_path, | 117 const std::string& profile_path, |
| 99 const std::string& entry_path) { | 118 const std::string& entry_path) { |
| 100 stub_profile_client_.AddEntry( | 119 scoped_ptr<base::DictionaryValue> entry = |
| 101 profile_path, | 120 test_utils::ReadTestDictionary(path_to_shill_json); |
| 102 entry_path, | 121 entry->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
| 103 *test_utils::ReadTestDictionary(path_to_shill_json)); | 122 profile_path); |
| 123 stub_profile_client_.AddEntry(profile_path, entry_path, *entry); | |
| 104 } | 124 } |
| 105 | 125 |
| 106 void SetPolicy(onc::ONCSource onc_source, | 126 void SetPolicy(onc::ONCSource onc_source, |
| 127 const std::string& userhash, | |
| 107 const std::string& path_to_onc) { | 128 const std::string& path_to_onc) { |
| 108 scoped_ptr<base::DictionaryValue> policy; | 129 scoped_ptr<base::DictionaryValue> policy; |
| 109 if (path_to_onc.empty()) | 130 if (path_to_onc.empty()) |
| 110 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); | 131 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); |
| 111 else | 132 else |
| 112 policy = test_utils::ReadTestDictionary(path_to_onc); | 133 policy = test_utils::ReadTestDictionary(path_to_onc); |
| 113 | 134 |
| 114 base::ListValue* network_configs = NULL; | 135 base::ListValue* network_configs = NULL; |
| 115 policy->GetListWithoutPathExpansion( | 136 policy->GetListWithoutPathExpansion( |
| 116 onc::toplevel_config::kNetworkConfigurations, &network_configs); | 137 onc::toplevel_config::kNetworkConfigurations, &network_configs); |
| 117 | 138 |
| 118 managed_handler()->SetPolicy(onc::ONC_SOURCE_USER_POLICY, *network_configs); | 139 managed_handler()->SetPolicy( |
| 140 onc::ONC_SOURCE_USER_POLICY, userhash, *network_configs); | |
| 119 } | 141 } |
| 120 | 142 |
| 121 ManagedNetworkConfigurationHandler* managed_handler() { | 143 ManagedNetworkConfigurationHandler* managed_handler() { |
| 122 return ManagedNetworkConfigurationHandler::Get(); | 144 return ManagedNetworkConfigurationHandler::Get(); |
| 123 } | 145 } |
| 124 | 146 |
| 125 protected: | 147 protected: |
| 126 StrictMock<MockShillManagerClient> mock_manager_client_; | 148 StrictMock<MockShillManagerClient> mock_manager_client_; |
| 127 StrictMock<MockShillServiceClient> mock_service_client_; | 149 StrictMock<MockShillServiceClient> mock_service_client_; |
| 128 StrictMock<MockShillProfileClient> mock_profile_client_; | 150 StrictMock<MockShillProfileClient> mock_profile_client_; |
| 129 ShillProfileClientStub stub_profile_client_; | 151 ShillProfileClientStub stub_profile_client_; |
|
stevenjb
2013/04/30 17:42:47
Again, mixing mocks and stubs is going to be very
pneubeck (no reviews)
2013/05/03 17:32:55
Why should there be two stubs? The MockDBusThreadM
| |
| 152 NetworkProfileHandlerStub stub_profile_handler_; | |
| 130 MessageLoop message_loop_; | 153 MessageLoop message_loop_; |
| 131 | 154 |
| 132 private: | 155 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); | 156 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); |
| 134 }; | 157 }; |
| 135 | 158 |
| 159 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) { | |
| 160 InitializeStandardProfiles(); | |
| 161 message_loop_.RunUntilIdle(); | |
| 162 } | |
| 163 | |
| 136 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnconfigured) { | 164 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnconfigured) { |
| 165 InitializeStandardProfiles(); | |
| 137 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 166 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
| 138 test_utils::ReadTestDictionary( | 167 test_utils::ReadTestDictionary( |
| 139 "policy/shill_policy_on_unconfigured_wifi1.json"); | 168 "policy/shill_policy_on_unconfigured_wifi1.json"); |
| 140 | 169 |
| 141 EXPECT_CALL(mock_profile_client_, | 170 EXPECT_CALL(mock_profile_client_, |
| 142 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), | 171 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
| 143 _, _)).Times(1); | |
| 144 | 172 |
| 145 EXPECT_CALL(mock_manager_client_, | 173 EXPECT_CALL(mock_manager_client_, |
| 146 ConfigureServiceForProfile( | 174 ConfigureServiceForProfile( |
| 147 dbus::ObjectPath("/profile/chronos/shill"), | 175 dbus::ObjectPath(kUser1ProfilePath), |
| 148 IsEqualTo(expected_shill_properties.get()), | 176 IsEqualTo(expected_shill_properties.get()), |
| 149 _, _)).Times(1); | 177 _, _)); |
| 150 | 178 |
| 151 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); | 179 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
| 152 message_loop_.RunUntilIdle(); | 180 message_loop_.RunUntilIdle(); |
| 153 } | 181 } |
| 154 | 182 |
| 155 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) { | 183 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) { |
| 156 EXPECT_CALL(mock_profile_client_, | 184 InitializeStandardProfiles(); |
| 157 GetProperties(_, _, _)).Times(1); | 185 EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _)); |
| 158 | 186 |
| 159 EXPECT_CALL(mock_manager_client_, | 187 EXPECT_CALL(mock_manager_client_, ConfigureServiceForProfile(_, _, _, _)); |
| 160 ConfigureServiceForProfile(_, _, _, _)).Times(1); | |
| 161 | 188 |
| 162 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); | 189 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
| 163 message_loop_.RunUntilIdle(); | 190 message_loop_.RunUntilIdle(); |
| 164 Mock::VerifyAndClearExpectations(&mock_profile_client_); | 191 VerifyAndClearExpectations(); |
| 165 Mock::VerifyAndClearExpectations(&mock_manager_client_); | |
| 166 | 192 |
| 167 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json", | 193 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json", |
| 168 "/profile/chronos/shill", | 194 kUser1ProfilePath, |
| 169 "some_entry_path"); | 195 "some_entry_path"); |
| 170 | 196 |
| 171 EXPECT_CALL(mock_profile_client_, | 197 EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _)); |
| 172 GetProperties(_, _, _)).Times(1); | |
| 173 | 198 |
| 174 EXPECT_CALL(mock_profile_client_, | 199 EXPECT_CALL(mock_profile_client_, |
| 175 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), | 200 GetEntry(dbus::ObjectPath(kUser1ProfilePath), |
| 176 "some_entry_path", | 201 "some_entry_path", |
| 177 _, _)).Times(1); | 202 _, _)); |
| 178 | 203 |
| 179 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); | 204 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
| 180 message_loop_.RunUntilIdle(); | 205 message_loop_.RunUntilIdle(); |
| 181 } | 206 } |
| 182 | 207 |
| 183 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnmanaged) { | 208 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnmanaged) { |
| 209 InitializeStandardProfiles(); | |
| 184 SetUpEntry("policy/shill_unmanaged_user_wifi1.json", | 210 SetUpEntry("policy/shill_unmanaged_user_wifi1.json", |
| 185 "/profile/chronos/shill", | 211 kUser1ProfilePath, |
| 186 "old_entry_path"); | 212 "old_entry_path"); |
| 187 | 213 |
| 188 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 214 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
| 189 test_utils::ReadTestDictionary( | 215 test_utils::ReadTestDictionary( |
| 190 "policy/shill_policy_on_unmanaged_user_wifi1.json"); | 216 "policy/shill_policy_on_unmanaged_user_wifi1.json"); |
| 191 | 217 |
| 192 EXPECT_CALL(mock_profile_client_, | 218 EXPECT_CALL(mock_profile_client_, |
| 193 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), | 219 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
| 194 _, _)).Times(1); | |
| 195 | 220 |
| 196 EXPECT_CALL(mock_profile_client_, | 221 EXPECT_CALL(mock_profile_client_, |
| 197 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), | 222 GetEntry(dbus::ObjectPath(kUser1ProfilePath), |
| 198 "old_entry_path", | 223 "old_entry_path", |
| 199 _, _)).Times(1); | 224 _, _)); |
| 200 | 225 |
| 201 EXPECT_CALL(mock_manager_client_, | 226 EXPECT_CALL(mock_manager_client_, |
| 202 ConfigureServiceForProfile( | 227 ConfigureServiceForProfile( |
| 203 dbus::ObjectPath("/profile/chronos/shill"), | 228 dbus::ObjectPath(kUser1ProfilePath), |
| 204 IsEqualTo(expected_shill_properties.get()), | 229 IsEqualTo(expected_shill_properties.get()), |
| 205 _, _)).Times(1); | 230 _, _)); |
| 206 | 231 |
| 207 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); | 232 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
| 208 message_loop_.RunUntilIdle(); | 233 message_loop_.RunUntilIdle(); |
| 209 } | 234 } |
| 210 | 235 |
| 211 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) { | 236 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) { |
| 237 InitializeStandardProfiles(); | |
| 212 SetUpEntry("policy/shill_managed_wifi1.json", | 238 SetUpEntry("policy/shill_managed_wifi1.json", |
| 213 "/profile/chronos/shill", | 239 kUser1ProfilePath, |
| 214 "old_entry_path"); | 240 "old_entry_path"); |
| 215 | 241 |
| 216 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 242 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
| 217 test_utils::ReadTestDictionary( | 243 test_utils::ReadTestDictionary( |
| 218 "policy/shill_policy_on_unmanaged_user_wifi1.json"); | 244 "policy/shill_policy_on_unmanaged_user_wifi1.json"); |
| 219 | 245 |
| 220 // The passphrase isn't sent again, because it's configured by the user and | 246 // The passphrase isn't sent again, because it's configured by the user and |
| 221 // Shill doesn't sent it on GetProperties calls. | 247 // Shill doesn't sent it on GetProperties calls. |
| 222 expected_shill_properties->RemoveWithoutPathExpansion( | 248 expected_shill_properties->RemoveWithoutPathExpansion( |
| 223 flimflam::kPassphraseProperty, NULL); | 249 flimflam::kPassphraseProperty, NULL); |
| 224 | 250 |
| 225 EXPECT_CALL(mock_profile_client_, | 251 EXPECT_CALL(mock_profile_client_, |
| 226 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), | 252 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
| 227 _, _)).Times(1); | |
| 228 | 253 |
| 229 EXPECT_CALL(mock_profile_client_, | 254 EXPECT_CALL(mock_profile_client_, |
| 230 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), | 255 GetEntry(dbus::ObjectPath(kUser1ProfilePath), |
| 231 "old_entry_path", | 256 "old_entry_path", |
| 232 _, _)).Times(1); | 257 _, _)); |
| 233 | 258 |
| 234 EXPECT_CALL(mock_manager_client_, | 259 EXPECT_CALL(mock_manager_client_, |
| 235 ConfigureServiceForProfile( | 260 ConfigureServiceForProfile( |
| 236 dbus::ObjectPath("/profile/chronos/shill"), | 261 dbus::ObjectPath(kUser1ProfilePath), |
| 237 IsEqualTo(expected_shill_properties.get()), | 262 IsEqualTo(expected_shill_properties.get()), |
| 238 _, _)).Times(1); | 263 _, _)); |
| 239 | 264 |
| 240 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); | 265 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
| 241 message_loop_.RunUntilIdle(); | 266 message_loop_.RunUntilIdle(); |
| 242 } | 267 } |
| 243 | 268 |
| 244 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { | 269 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { |
| 270 InitializeStandardProfiles(); | |
| 245 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json", | 271 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json", |
| 246 "/profile/chronos/shill", | 272 kUser1ProfilePath, |
| 247 "old_entry_path"); | 273 "old_entry_path"); |
| 248 | 274 |
| 249 scoped_ptr<base::DictionaryValue> expected_shill_properties = | 275 scoped_ptr<base::DictionaryValue> expected_shill_properties = |
| 250 test_utils::ReadTestDictionary( | 276 test_utils::ReadTestDictionary( |
| 251 "policy/shill_policy_on_unmanaged_user_wifi1.json"); | 277 "policy/shill_policy_on_unmanaged_user_wifi1.json"); |
| 252 | 278 |
| 253 // The passphrase isn't sent again, because it's configured by the user and | 279 // The passphrase isn't sent again, because it's configured by the user and |
| 254 // Shill doesn't sent it on GetProperties calls. | 280 // Shill doesn't sent it on GetProperties calls. |
| 255 expected_shill_properties->RemoveWithoutPathExpansion( | 281 expected_shill_properties->RemoveWithoutPathExpansion( |
| 256 flimflam::kPassphraseProperty, NULL); | 282 flimflam::kPassphraseProperty, NULL); |
| 257 | 283 |
| 258 EXPECT_CALL(mock_profile_client_, | 284 EXPECT_CALL(mock_profile_client_, |
| 259 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), | 285 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
| 260 _, _)).Times(1); | |
| 261 | 286 |
| 262 EXPECT_CALL(mock_profile_client_, | 287 EXPECT_CALL(mock_profile_client_, |
| 263 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), | 288 GetEntry(dbus::ObjectPath(kUser1ProfilePath), |
| 264 "old_entry_path", | 289 "old_entry_path", |
| 265 _, _)).Times(1); | 290 _, _)); |
| 266 | 291 |
| 267 EXPECT_CALL(mock_manager_client_, | 292 EXPECT_CALL(mock_manager_client_, |
| 268 ConfigureServiceForProfile( | 293 ConfigureServiceForProfile( |
| 269 dbus::ObjectPath("/profile/chronos/shill"), | 294 dbus::ObjectPath(kUser1ProfilePath), |
| 270 IsEqualTo(expected_shill_properties.get()), | 295 IsEqualTo(expected_shill_properties.get()), |
| 271 _, _)).Times(1); | 296 _, _)); |
| 272 | 297 |
| 273 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); | 298 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); |
| 274 message_loop_.RunUntilIdle(); | 299 message_loop_.RunUntilIdle(); |
| 275 } | 300 } |
| 276 | 301 |
| 277 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUnmanageManaged) { | 302 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUnmanageManaged) { |
| 303 InitializeStandardProfiles(); | |
| 278 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json", | 304 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json", |
| 279 "/profile/chronos/shill", | 305 kUser1ProfilePath, |
| 280 "old_entry_path"); | 306 "old_entry_path"); |
| 281 | 307 |
| 282 EXPECT_CALL(mock_profile_client_, | 308 EXPECT_CALL(mock_profile_client_, |
| 283 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), | 309 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
| 284 _, _)).Times(1); | |
| 285 | 310 |
| 286 EXPECT_CALL(mock_profile_client_, | 311 EXPECT_CALL(mock_profile_client_, |
| 287 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), | 312 GetEntry(dbus::ObjectPath(kUser1ProfilePath), |
| 288 "old_entry_path", | 313 "old_entry_path", |
| 289 _, _)).Times(1); | 314 _, _)); |
| 290 | 315 |
| 291 EXPECT_CALL(mock_profile_client_, | 316 EXPECT_CALL(mock_profile_client_, |
| 292 DeleteEntry(dbus::ObjectPath("/profile/chronos/shill"), | 317 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath), |
| 293 "old_entry_path", | 318 "old_entry_path", |
| 294 _, _)).Times(1); | 319 _, _)); |
| 295 | 320 |
| 296 SetPolicy(onc::ONC_SOURCE_USER_POLICY, ""); | 321 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, ""); |
| 297 message_loop_.RunUntilIdle(); | 322 message_loop_.RunUntilIdle(); |
| 298 } | 323 } |
| 299 | 324 |
| 300 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmanaged) { | 325 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmanaged) { |
| 326 InitializeStandardProfiles(); | |
| 301 SetUpEntry("policy/shill_unmanaged_user_wifi1.json", | 327 SetUpEntry("policy/shill_unmanaged_user_wifi1.json", |
| 302 "/profile/chronos/shill", | 328 kUser1ProfilePath, |
| 303 "old_entry_path"); | 329 "old_entry_path"); |
| 304 | 330 |
| 305 EXPECT_CALL(mock_profile_client_, | 331 EXPECT_CALL(mock_profile_client_, |
| 306 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), | 332 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); |
| 307 _, _)).Times(1); | |
| 308 | 333 |
| 309 EXPECT_CALL(mock_profile_client_, | 334 EXPECT_CALL(mock_profile_client_, |
| 310 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), | 335 GetEntry(dbus::ObjectPath(kUser1ProfilePath), |
| 311 "old_entry_path", | 336 "old_entry_path", |
| 312 _, _)).Times(1); | 337 _, _)); |
| 313 | 338 |
| 314 SetPolicy(onc::ONC_SOURCE_USER_POLICY, ""); | 339 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, ""); |
| 315 message_loop_.RunUntilIdle(); | 340 message_loop_.RunUntilIdle(); |
| 316 } | 341 } |
| 317 | 342 |
| 343 TEST_F(ManagedNetworkConfigurationHandlerTest, LateProfileLoading) { | |
| 344 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); | |
| 345 | |
| 346 message_loop_.RunUntilIdle(); | |
| 347 VerifyAndClearExpectations(); | |
| 348 | |
| 349 scoped_ptr<base::DictionaryValue> expected_shill_properties = | |
| 350 test_utils::ReadTestDictionary( | |
| 351 "policy/shill_policy_on_unconfigured_wifi1.json"); | |
| 352 | |
| 353 EXPECT_CALL(mock_profile_client_, | |
| 354 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); | |
| 355 | |
| 356 EXPECT_CALL(mock_manager_client_, | |
| 357 ConfigureServiceForProfile( | |
| 358 dbus::ObjectPath(kUser1ProfilePath), | |
| 359 IsEqualTo(expected_shill_properties.get()), | |
| 360 _, _)); | |
| 361 | |
| 362 InitializeStandardProfiles(); | |
| 363 message_loop_.RunUntilIdle(); | |
| 364 } | |
| 365 | |
| 318 } // namespace chromeos | 366 } // namespace chromeos |
| OLD | NEW |