mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 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/service_property_change_test.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <chromeos/dbus/service_constants.h> |
| 10 | #include <gtest/gtest.h> |
| 11 | #include <gmock/gmock.h> |
| 12 | |
| 13 | #include "shill/error.h" |
| 14 | #include "shill/mock_adaptors.h" |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 15 | #include "shill/mock_manager.h" |
| 16 | #include "shill/mock_profile.h" |
| 17 | #include "shill/refptr_types.h" |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 18 | #include "shill/service.h" |
| 19 | |
| 20 | using std::string; |
| 21 | using testing::_; |
| 22 | using testing::AnyNumber; |
| 23 | using testing::Mock; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 24 | using testing::NiceMock; |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 25 | |
| 26 | namespace shill { |
| 27 | |
| 28 | // Some of these tests are duplicative, as we also have broader tests |
| 29 | // for specific setters. However, it's convenient to have all the property |
| 30 | // change notifications documented (and tested) in one place. |
| 31 | |
| 32 | void TestCommonPropertyChanges(ServiceRefPtr service, |
| 33 | ServiceMockAdaptor *adaptor) { |
| 34 | Error error; |
| 35 | |
| 36 | EXPECT_EQ(Service::kStateIdle, service->state()); |
| 37 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _)); |
| 38 | service->SetState(Service::kStateConnected); |
| 39 | Mock::VerifyAndClearExpectations(adaptor); |
| 40 | |
Paul Stewart | ee6b3d7 | 2013-07-12 16:07:51 -0700 | [diff] [blame] | 41 | // TODO(quiche): Once crbug.com/216664 is resolved, add a test |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 42 | // that service->SetConnection emits kIPConfigProperty changed. |
| 43 | |
| 44 | bool connectable = service->connectable(); |
| 45 | EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kConnectableProperty, _)); |
| 46 | service->SetConnectable(!connectable); |
| 47 | Mock::VerifyAndClearExpectations(adaptor); |
| 48 | |
| 49 | EXPECT_EQ(string(), service->guid()); |
| 50 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kGuidProperty, _)); |
| 51 | service->SetGuid("some garbage", &error); |
| 52 | Mock::VerifyAndClearExpectations(adaptor); |
| 53 | |
| 54 | EXPECT_FALSE(service->favorite()); |
| 55 | EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kAutoConnectProperty, _)) |
| 56 | .Times(AnyNumber()); |
| 57 | EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kFavoriteProperty, _)); |
| 58 | service->MakeFavorite(); |
| 59 | Mock::VerifyAndClearExpectations(adaptor); |
| 60 | |
| 61 | EXPECT_EQ(0, service->priority()); |
| 62 | EXPECT_CALL(*adaptor, EmitIntChanged(flimflam::kPriorityProperty, _)); |
| 63 | service->SetPriority(1, &error); |
| 64 | Mock::VerifyAndClearExpectations(adaptor); |
| 65 | |
| 66 | EXPECT_EQ(string(), service->GetProxyConfig(&error)); |
| 67 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kProxyConfigProperty, _)); |
| 68 | service->SetProxyConfig("some garbage", &error); |
| 69 | Mock::VerifyAndClearExpectations(adaptor); |
| 70 | |
| 71 | uint8 strength = service->strength(); |
| 72 | EXPECT_CALL(*adaptor, |
| 73 | EmitUint8Changed(flimflam::kSignalStrengthProperty, _)); |
| 74 | service->SetStrength(strength+1); |
| 75 | Mock::VerifyAndClearExpectations(adaptor); |
| 76 | |
| 77 | EXPECT_EQ(string(), service->error_details()); |
| 78 | EXPECT_CALL(*adaptor, EmitStringChanged(kErrorDetailsProperty, _)); |
| 79 | service->SetErrorDetails("some garbage"); |
| 80 | Mock::VerifyAndClearExpectations(adaptor); |
| 81 | |
| 82 | EXPECT_EQ(Service::kFailureUnknown, service->failure()); |
| 83 | EXPECT_EQ(Service::ConnectFailureToString(Service::kFailureUnknown), |
| 84 | service->error()); |
| 85 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _)); |
| 86 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kErrorProperty, _)); |
| 87 | service->SetFailure(Service::kFailureAAA); |
| 88 | Mock::VerifyAndClearExpectations(adaptor); |
| 89 | |
| 90 | EXPECT_NE(Service::ConnectFailureToString(Service::kFailureUnknown), |
| 91 | service->error()); |
| 92 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _)); |
| 93 | EXPECT_CALL(*adaptor, EmitStringChanged(kErrorDetailsProperty, _)); |
| 94 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kErrorProperty, _)); |
| 95 | service->SetState(Service::kStateConnected); |
| 96 | Mock::VerifyAndClearExpectations(adaptor); |
| 97 | |
| 98 | EXPECT_EQ(Service::ConnectFailureToString(Service::kFailureUnknown), |
| 99 | service->error()); |
| 100 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _)); |
| 101 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kErrorProperty, _)); |
| 102 | service->SetFailureSilent(Service::kFailureAAA); |
| 103 | Mock::VerifyAndClearExpectations(adaptor); |
| 104 | } |
| 105 | |
| 106 | void TestAutoConnectPropertyChange(ServiceRefPtr service, |
| 107 | ServiceMockAdaptor *adaptor) { |
| 108 | bool auto_connect = service->auto_connect(); |
| 109 | EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kAutoConnectProperty, _)); |
| 110 | service->SetAutoConnect(!auto_connect); |
| 111 | Mock::VerifyAndClearExpectations(adaptor); |
| 112 | } |
| 113 | |
| 114 | void TestNamePropertyChange(ServiceRefPtr service, |
| 115 | ServiceMockAdaptor *adaptor) { |
| 116 | Error error; |
| 117 | string name = service->GetNameProperty(&error); |
| 118 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kNameProperty, _)); |
| 119 | service->SetNameProperty(name + " and some new stuff", &error); |
| 120 | Mock::VerifyAndClearExpectations(adaptor); |
| 121 | } |
| 122 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 123 | void TestCustomSetterNoopChange(ServiceRefPtr service, |
| 124 | MockManager *mock_manager) { |
| 125 | // SetAutoConnectFull |
| 126 | { |
| 127 | Error error; |
| 128 | EXPECT_CALL(*mock_manager, UpdateService(_)).Times(0); |
| 129 | EXPECT_FALSE(service->SetAutoConnectFull(service->auto_connect(), &error)); |
| 130 | EXPECT_TRUE(error.IsSuccess()); |
| 131 | Mock::VerifyAndClearExpectations(mock_manager); |
| 132 | } |
| 133 | |
| 134 | // SetCheckPortal |
| 135 | { |
| 136 | Error error; |
| 137 | EXPECT_FALSE(service->SetCheckPortal(service->check_portal_, &error)); |
| 138 | EXPECT_TRUE(error.IsSuccess()); |
| 139 | } |
| 140 | |
| 141 | // SetNameProperty |
| 142 | { |
| 143 | Error error; |
| 144 | EXPECT_FALSE(service->SetNameProperty(service->friendly_name_, &error)); |
| 145 | EXPECT_TRUE(error.IsSuccess()); |
| 146 | } |
| 147 | |
| 148 | // SetProfileRpcId |
| 149 | { |
| 150 | Error error; |
| 151 | scoped_refptr<MockProfile> profile( |
| 152 | new NiceMock<MockProfile>(static_cast<ControlInterface *>(NULL), |
| 153 | static_cast<Metrics *>(NULL), |
| 154 | static_cast<Manager *>(NULL))); |
| 155 | service->set_profile(profile); |
| 156 | EXPECT_FALSE(service->SetProfileRpcId(profile->GetRpcIdentifier(), |
| 157 | &error)); |
| 158 | EXPECT_TRUE(error.IsSuccess()); |
| 159 | } |
| 160 | |
| 161 | // SetProxyConfig |
| 162 | { |
| 163 | Error error; |
| 164 | static const string kProxyConfig = "some opaque blob"; |
| 165 | // Set to known value. |
| 166 | EXPECT_TRUE(service->SetProxyConfig(kProxyConfig, &error)); |
| 167 | EXPECT_TRUE(error.IsSuccess()); |
| 168 | // Set to same value. |
| 169 | EXPECT_FALSE(service->SetProxyConfig(kProxyConfig, &error)); |
| 170 | EXPECT_TRUE(error.IsSuccess()); |
| 171 | } |
| 172 | } |
| 173 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 174 | } // namespace shill |