blob: e819185059c65da9ccc597c91d6d01b64be0737f [file] [log] [blame]
Chris Masone7156c922011-08-23 20:36:21 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Chris Masone88cbd5f2011-07-03 14:30:04 -07002// 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>
9
10#include <chromeos/dbus/service_constants.h>
11#include <gtest/gtest.h>
12#include <gmock/gmock.h>
13
14#include "shill/manager.h"
15#include "shill/mock_control.h"
Chris Masoneaa482372011-09-14 16:40:37 -070016#include "shill/mock_store.h"
Chris Masone88cbd5f2011-07-03 14:30:04 -070017#include "shill/property_store_unittest.h"
18
19using std::map;
20using std::string;
21using ::testing::_;
Chris Masoneaa482372011-09-14 16:40:37 -070022using ::testing::Return;
Chris Masone88cbd5f2011-07-03 14:30:04 -070023
24namespace shill {
25
26class DefaultProfileTest : public PropertyStoreTest {
27 public:
Chris Masone7aa5f902011-07-11 11:13:35 -070028 DefaultProfileTest()
Chris Masone2176a882011-09-14 22:29:15 -070029 : profile_(new DefaultProfile(control_interface(),
Chris Masone9d779932011-08-25 16:33:41 -070030 manager(),
Chris Masone2ae797d2011-08-23 20:41:00 -070031 FilePath(kTestStoragePath),
Chris Masone6791a432011-07-12 13:23:19 -070032 properties_)) {
Chris Masone7aa5f902011-07-11 11:13:35 -070033 }
Chris Masone88cbd5f2011-07-03 14:30:04 -070034
35 virtual ~DefaultProfileTest() {}
36
37 protected:
Chris Masone2ae797d2011-08-23 20:41:00 -070038 static const char kTestStoragePath[];
39
Chris Masone7aa5f902011-07-11 11:13:35 -070040 ProfileRefPtr profile_;
Chris Masone88cbd5f2011-07-03 14:30:04 -070041 Manager::Properties properties_;
42};
43
Chris Masone2ae797d2011-08-23 20:41:00 -070044const char DefaultProfileTest::kTestStoragePath[] = "/no/where";
45
Chris Masone88cbd5f2011-07-03 14:30:04 -070046TEST_F(DefaultProfileTest, GetProperties) {
47 Error error(Error::kInvalidProperty, "");
48 {
49 map<string, ::DBus::Variant> props;
50 ::DBus::Error dbus_error;
Chris Masone7aa5f902011-07-11 11:13:35 -070051 DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error);
Chris Masone88cbd5f2011-07-03 14:30:04 -070052 ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end());
53 EXPECT_FALSE(props[flimflam::kOfflineModeProperty].reader().get_bool());
54 }
55 properties_.offline_mode = true;
56 {
57 map<string, ::DBus::Variant> props;
58 ::DBus::Error dbus_error;
Chris Masone7aa5f902011-07-11 11:13:35 -070059 DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error);
Chris Masone88cbd5f2011-07-03 14:30:04 -070060 ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end());
61 EXPECT_TRUE(props[flimflam::kOfflineModeProperty].reader().get_bool());
62 }
63 {
64 Error error(Error::kInvalidProperty, "");
65 EXPECT_FALSE(
Chris Masone7aa5f902011-07-11 11:13:35 -070066 profile_->store()->SetBoolProperty(flimflam::kOfflineModeProperty,
67 true,
68 &error));
Chris Masone88cbd5f2011-07-03 14:30:04 -070069 }
70}
71
Chris Masoneaa482372011-09-14 16:40:37 -070072TEST_F(DefaultProfileTest, Save) {
73 MockStore storage;
74 EXPECT_CALL(storage, SetString(DefaultProfile::kStorageId,
75 DefaultProfile::kStorageName,
76 DefaultProfile::kDefaultId))
77 .WillOnce(Return(true));
78 EXPECT_CALL(storage, SetString(DefaultProfile::kStorageId,
79 DefaultProfile::kStorageCheckPortalList,
80 ""))
81 .WillOnce(Return(true));
82 EXPECT_CALL(storage, SetBool(DefaultProfile::kStorageId,
83 DefaultProfile::kStorageOfflineMode,
84 false))
85 .WillOnce(Return(true));
86 ASSERT_TRUE(profile_->Save(&storage));
87}
88
Chris Masone2ae797d2011-08-23 20:41:00 -070089TEST_F(DefaultProfileTest, GetStoragePath) {
90 FilePath path;
91 EXPECT_TRUE(profile_->GetStoragePath(&path));
92 EXPECT_EQ(string(kTestStoragePath) + "/default.profile", path.value());
93}
94
Chris Masone88cbd5f2011-07-03 14:30:04 -070095} // namespace shill