Home | History | Annotate | Download | only in ethernet
      1 //
      2 // Copyright (C) 2013 The Android Open Source Project
      3 //
      4 // Licensed under the Apache License, Version 2.0 (the "License");
      5 // you may not use this file except in compliance with the License.
      6 // You may obtain a copy of the License at
      7 //
      8 //      http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unless required by applicable law or agreed to in writing, software
     11 // distributed under the License is distributed on an "AS IS" BASIS,
     12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 // See the License for the specific language governing permissions and
     14 // limitations under the License.
     15 //
     16 
     17 #include "shill/ethernet/ethernet_eap_service.h"
     18 
     19 #include <base/bind.h>
     20 #if defined(__ANDROID__)
     21 #include <dbus/service_constants.h>
     22 #else
     23 #include <chromeos/dbus/service_constants.h>
     24 #endif  // __ANDROID__
     25 #include <gtest/gtest.h>
     26 
     27 #include "shill/ethernet/mock_ethernet_eap_provider.h"
     28 #include "shill/mock_adaptors.h"
     29 #include "shill/mock_control.h"
     30 #include "shill/mock_event_dispatcher.h"
     31 #include "shill/mock_manager.h"
     32 #include "shill/mock_metrics.h"
     33 #include "shill/service_property_change_test.h"
     34 #include "shill/technology.h"
     35 
     36 using testing::Return;
     37 
     38 namespace shill {
     39 
     40 class EthernetEapServiceTest : public testing::Test {
     41  public:
     42   EthernetEapServiceTest()
     43       : metrics_(&dispatcher_),
     44         manager_(&control_, &dispatcher_, &metrics_),
     45         service_(new EthernetEapService(&control_,
     46                                         &dispatcher_,
     47                                         &metrics_,
     48                                         &manager_)) {}
     49   virtual ~EthernetEapServiceTest() {}
     50 
     51  protected:
     52   ServiceMockAdaptor* GetAdaptor() {
     53     return static_cast<ServiceMockAdaptor*>(service_->adaptor());
     54   }
     55 
     56   MockControl control_;
     57   MockEventDispatcher dispatcher_;
     58   MockMetrics metrics_;
     59   MockManager manager_;
     60   MockEthernetEapProvider provider_;
     61   scoped_refptr<EthernetEapService> service_;
     62 };
     63 
     64 TEST_F(EthernetEapServiceTest, MethodOverrides) {
     65   EXPECT_EQ("/", service_->GetDeviceRpcId(nullptr));
     66   EXPECT_EQ("etherneteap_all", service_->GetStorageIdentifier());
     67   EXPECT_EQ(Technology::kEthernetEap, service_->technology());
     68   EXPECT_TRUE(service_->Is8021x());
     69   EXPECT_FALSE(service_->IsVisible());
     70 }
     71 
     72 TEST_F(EthernetEapServiceTest, OnEapCredentialsChanged) {
     73   service_->has_ever_connected_ = true;
     74   EXPECT_TRUE(service_->has_ever_connected());
     75   EXPECT_CALL(manager_, ethernet_eap_provider()).WillOnce(Return(&provider_));
     76   EXPECT_CALL(provider_, OnCredentialsChanged());
     77   service_->OnEapCredentialsChanged(Service::kReasonPropertyUpdate);
     78   EXPECT_FALSE(service_->has_ever_connected());
     79 }
     80 
     81 TEST_F(EthernetEapServiceTest, OnEapCredentialPropertyChanged) {
     82   EXPECT_CALL(manager_, ethernet_eap_provider()).WillOnce(Return(&provider_));
     83   EXPECT_CALL(provider_, OnCredentialsChanged());
     84   service_->OnPropertyChanged(kEapPasswordProperty);
     85 }
     86 
     87 TEST_F(EthernetEapServiceTest, Unload) {
     88   EXPECT_CALL(manager_, ethernet_eap_provider()).WillOnce(Return(&provider_));
     89   EXPECT_CALL(provider_, OnCredentialsChanged());
     90   EXPECT_FALSE(service_->Unload());
     91 }
     92 
     93 TEST_F(EthernetEapServiceTest, PropertyChanges) {
     94   TestCommonPropertyChanges(service_, GetAdaptor());
     95 }
     96 
     97 // Custom property setters should return false, and make no changes, if
     98 // the new value is the same as the old value.
     99 TEST_F(EthernetEapServiceTest, CustomSetterNoopChange) {
    100   TestCustomSetterNoopChange(service_, &manager_);
    101 }
    102 
    103 }  // namespace shill
    104