Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / chrome / browser / local_discovery / wifi / bootstrapping_network_switcher_unittest.cc
blob4c3a6d8381390f92a972f7a9199e18e4925df031
1 // Copyright 2014 The Chromium 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.
5 #include "base/bind.h"
6 #include "chrome/browser/local_discovery/wifi/bootstrapping_network_switcher.h"
7 #include "chrome/browser/local_discovery/wifi/mock_wifi_manager.h"
8 #include "components/onc/onc_constants.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using testing::StrictMock;
14 namespace local_discovery {
16 namespace wifi {
18 namespace {
20 class MockableNetworkSwitchCallback {
21 public:
22 MOCK_METHOD1(OnNetworkSwitch, void(bool success));
24 BootstrappingNetworkSwitcher::SuccessCallback callback() {
25 return base::Bind(&MockableNetworkSwitchCallback::OnNetworkSwitch,
26 base::Unretained(this));
30 class BootstrappingNetworkSwitcherTest : public ::testing::Test {
31 public:
32 BootstrappingNetworkSwitcherTest() {
33 NetworkProperties network1;
34 network1.guid = "SampleGUID1";
35 network1.ssid = "SampleSSID1";
36 network1.connection_state = onc::connection_state::kNotConnected;
38 NetworkProperties network2;
39 network2.guid = "SampleGUID2";
40 network2.ssid = "SampleSSID2";
41 network2.connection_state = onc::connection_state::kConnected;
43 network_properties_.push_back(network1);
44 network_properties_.push_back(network2);
47 ~BootstrappingNetworkSwitcherTest() {}
49 NetworkPropertiesList network_properties_;
50 StrictMock<MockableNetworkSwitchCallback> mockable_callback_;
51 StrictMock<MockWifiManager> mock_wifi_manager_;
52 scoped_ptr<BootstrappingNetworkSwitcher> network_switcher_;
55 TEST_F(BootstrappingNetworkSwitcherTest, EndToEndSuccess) {
56 network_switcher_.reset(new BootstrappingNetworkSwitcher(
57 &mock_wifi_manager_, "SampleConnectSSID", mockable_callback_.callback()));
59 EXPECT_CALL(mock_wifi_manager_, GetSSIDListInternal());
60 network_switcher_->Connect();
62 EXPECT_CALL(mock_wifi_manager_,
63 ConfigureAndConnectNetworkInternal("SampleConnectSSID", ""));
64 mock_wifi_manager_.CallSSIDListCallback(network_properties_);
66 EXPECT_CALL(mockable_callback_, OnNetworkSwitch(true));
67 mock_wifi_manager_.CallConfigureAndConnectNetworkCallback(true);
69 EXPECT_CALL(mock_wifi_manager_, ConnectToNetworkByIDInternal("SampleGUID2"));
70 network_switcher_->Disconnect();
73 TEST_F(BootstrappingNetworkSwitcherTest, MidconnnectCancel) {
74 network_switcher_.reset(new BootstrappingNetworkSwitcher(
75 &mock_wifi_manager_, "SampleConnectSSID", mockable_callback_.callback()));
77 EXPECT_CALL(mock_wifi_manager_, GetSSIDListInternal());
78 network_switcher_->Connect();
80 EXPECT_CALL(mock_wifi_manager_,
81 ConfigureAndConnectNetworkInternal("SampleConnectSSID", ""));
82 mock_wifi_manager_.CallSSIDListCallback(network_properties_);
84 EXPECT_CALL(mock_wifi_manager_, ConnectToNetworkByIDInternal("SampleGUID2"));
85 network_switcher_->Disconnect();
88 TEST_F(BootstrappingNetworkSwitcherTest, Failure) {
89 network_switcher_.reset(new BootstrappingNetworkSwitcher(
90 &mock_wifi_manager_, "SampleConnectSSID", mockable_callback_.callback()));
92 EXPECT_CALL(mock_wifi_manager_, GetSSIDListInternal());
93 network_switcher_->Connect();
95 EXPECT_CALL(mock_wifi_manager_,
96 ConfigureAndConnectNetworkInternal("SampleConnectSSID", ""));
97 mock_wifi_manager_.CallSSIDListCallback(network_properties_);
99 EXPECT_CALL(mockable_callback_, OnNetworkSwitch(false));
100 mock_wifi_manager_.CallConfigureAndConnectNetworkCallback(false);
102 network_switcher_->Disconnect();
105 TEST_F(BootstrappingNetworkSwitcherTest, RAII) {
106 network_switcher_.reset(new BootstrappingNetworkSwitcher(
107 &mock_wifi_manager_, "SampleConnectSSID", mockable_callback_.callback()));
109 EXPECT_CALL(mock_wifi_manager_, GetSSIDListInternal());
110 network_switcher_->Connect();
112 EXPECT_CALL(mock_wifi_manager_,
113 ConfigureAndConnectNetworkInternal("SampleConnectSSID", ""));
114 mock_wifi_manager_.CallSSIDListCallback(network_properties_);
116 EXPECT_CALL(mock_wifi_manager_, ConnectToNetworkByIDInternal("SampleGUID2"));
117 network_switcher_.reset();
120 } // namespace
122 } // namespace wifi
124 } // namespace local_discovery