Chris Masone | 7156c92 | 2011-08-23 20:36:21 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/default_profile.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame^] | 9 | #include <vector> |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 10 | |
| 11 | #include <chromeos/dbus/service_constants.h> |
| 12 | #include <gtest/gtest.h> |
| 13 | #include <gmock/gmock.h> |
| 14 | |
| 15 | #include "shill/manager.h" |
| 16 | #include "shill/mock_control.h" |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame^] | 17 | #include "shill/mock_device.h" |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 18 | #include "shill/mock_store.h" |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 19 | #include "shill/property_store_unittest.h" |
| 20 | |
| 21 | using std::map; |
| 22 | using std::string; |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame^] | 23 | using std::vector; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 24 | using ::testing::_; |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 25 | using ::testing::Return; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 26 | |
| 27 | namespace shill { |
| 28 | |
| 29 | class DefaultProfileTest : public PropertyStoreTest { |
| 30 | public: |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 31 | DefaultProfileTest() |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 32 | : profile_(new DefaultProfile(control_interface(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 33 | manager(), |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 34 | FilePath(kTestStoragePath), |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame^] | 35 | properties_)), |
| 36 | device_(new MockDevice(control_interface(), |
| 37 | dispatcher(), |
| 38 | manager(), |
| 39 | "null0", |
| 40 | "addr0", |
| 41 | 0)) { |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 42 | } |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 43 | |
| 44 | virtual ~DefaultProfileTest() {} |
| 45 | |
| 46 | protected: |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 47 | static const char kTestStoragePath[]; |
| 48 | |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 49 | ProfileRefPtr profile_; |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame^] | 50 | scoped_refptr<MockDevice> device_; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 51 | Manager::Properties properties_; |
| 52 | }; |
| 53 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 54 | const char DefaultProfileTest::kTestStoragePath[] = "/no/where"; |
| 55 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 56 | TEST_F(DefaultProfileTest, GetProperties) { |
| 57 | Error error(Error::kInvalidProperty, ""); |
| 58 | { |
| 59 | map<string, ::DBus::Variant> props; |
| 60 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 61 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 62 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 63 | EXPECT_FALSE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 64 | } |
| 65 | properties_.offline_mode = true; |
| 66 | { |
| 67 | map<string, ::DBus::Variant> props; |
| 68 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 69 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 70 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 71 | EXPECT_TRUE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 72 | } |
| 73 | { |
| 74 | Error error(Error::kInvalidProperty, ""); |
| 75 | EXPECT_FALSE( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 76 | profile_->mutable_store()->SetBoolProperty( |
| 77 | flimflam::kOfflineModeProperty, |
| 78 | true, |
| 79 | &error)); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 83 | TEST_F(DefaultProfileTest, Save) { |
| 84 | MockStore storage; |
| 85 | EXPECT_CALL(storage, SetString(DefaultProfile::kStorageId, |
| 86 | DefaultProfile::kStorageName, |
| 87 | DefaultProfile::kDefaultId)) |
| 88 | .WillOnce(Return(true)); |
| 89 | EXPECT_CALL(storage, SetString(DefaultProfile::kStorageId, |
| 90 | DefaultProfile::kStorageCheckPortalList, |
| 91 | "")) |
| 92 | .WillOnce(Return(true)); |
| 93 | EXPECT_CALL(storage, SetBool(DefaultProfile::kStorageId, |
| 94 | DefaultProfile::kStorageOfflineMode, |
| 95 | false)) |
| 96 | .WillOnce(Return(true)); |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame^] | 97 | |
| 98 | EXPECT_CALL(*device_.get(), Save(&storage)).WillOnce(Return(true)); |
| 99 | |
| 100 | manager()->RegisterDevice(device_); |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 101 | ASSERT_TRUE(profile_->Save(&storage)); |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame^] | 102 | manager()->DeregisterDevice(device_); |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 105 | TEST_F(DefaultProfileTest, GetStoragePath) { |
| 106 | FilePath path; |
| 107 | EXPECT_TRUE(profile_->GetStoragePath(&path)); |
| 108 | EXPECT_EQ(string(kTestStoragePath) + "/default.profile", path.value()); |
| 109 | } |
| 110 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 111 | } // namespace shill |