Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: ui/chromeos/network/network_state_notifier_unittest.cc

Issue 2434683003: Move NetworkStateNotifier and NetworkConnect from src/ui (Closed)
Patch Set: Fix virtuals Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/chromeos/network/network_state_notifier.cc ('k') | ui/chromeos/ui_chromeos_strings.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include "ui/chromeos/network/network_state_notifier.h"
6
7 #include "base/macros.h"
8 #include "base/run_loop.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/shill_device_client.h"
11 #include "chromeos/dbus/shill_service_client.h"
12 #include "chromeos/login/login_state.h"
13 #include "chromeos/network/network_handler.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
17 #include "ui/chromeos/network/network_connect.h"
18 #include "ui/message_center/message_center.h"
19
20 using chromeos::DBusThreadManager;
21 using chromeos::ShillDeviceClient;
22 using chromeos::ShillServiceClient;
23
24 namespace ui {
25 namespace test {
26
27 class NetworkConnectTestDelegate : public NetworkConnect::Delegate {
28 public:
29 NetworkConnectTestDelegate() {}
30 ~NetworkConnectTestDelegate() override {}
31
32 // NetworkConnect::Delegate
33 void ShowNetworkConfigure(const std::string& network_id) override {}
34 void ShowNetworkSettings(const std::string& network_id) override {}
35 bool ShowEnrollNetwork(const std::string& network_id) override {
36 return false;
37 }
38 void ShowMobileSimDialog() override {}
39 void ShowMobileSetupDialog(const std::string& service_path) override {}
40
41 private:
42 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate);
43 };
44
45 class NetworkStateNotifierTest : public testing::Test {
46 public:
47 NetworkStateNotifierTest() {}
48 ~NetworkStateNotifierTest() override {}
49
50 void SetUp() override {
51 testing::Test::SetUp();
52 DBusThreadManager::Initialize();
53 chromeos::LoginState::Initialize();
54 SetupDefaultShillState();
55 chromeos::NetworkHandler::Initialize();
56 message_center::MessageCenter::Initialize();
57 base::RunLoop().RunUntilIdle();
58 network_connect_delegate_.reset(new NetworkConnectTestDelegate);
59 NetworkConnect::Initialize(network_connect_delegate_.get());
60 }
61
62 void TearDown() override {
63 NetworkConnect::Shutdown();
64 network_connect_delegate_.reset();
65 message_center::MessageCenter::Shutdown();
66 chromeos::LoginState::Shutdown();
67 chromeos::NetworkHandler::Shutdown();
68 DBusThreadManager::Shutdown();
69 testing::Test::TearDown();
70 }
71
72 protected:
73 void SetupDefaultShillState() {
74 base::RunLoop().RunUntilIdle();
75 ShillDeviceClient::TestInterface* device_test =
76 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
77 device_test->ClearDevices();
78 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi,
79 "stub_wifi_device1");
80 device_test->AddDevice("/device/stub_cellular_device1",
81 shill::kTypeCellular, "stub_cellular_device1");
82
83 ShillServiceClient::TestInterface* service_test =
84 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
85 service_test->ClearServices();
86 const bool add_to_visible = true;
87 // Create a wifi network and set to online.
88 service_test->AddService("/service/wifi1", "wifi1_guid", "wifi1",
89 shill::kTypeWifi, shill::kStateIdle,
90 add_to_visible);
91 service_test->SetServiceProperty("wifi1", shill::kSecurityClassProperty,
92 base::StringValue(shill::kSecurityWep));
93 service_test->SetServiceProperty("wifi1", shill::kConnectableProperty,
94 base::FundamentalValue(true));
95 service_test->SetServiceProperty("wifi1", shill::kPassphraseProperty,
96 base::StringValue("failure"));
97 base::RunLoop().RunUntilIdle();
98 }
99
100 std::unique_ptr<NetworkConnectTestDelegate> network_connect_delegate_;
101 base::MessageLoop message_loop_;
102
103 private:
104 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest);
105 };
106
107 TEST_F(NetworkStateNotifierTest, ConnectionFailure) {
108 NetworkConnect::Get()->ConnectToNetwork("wifi1");
109 base::RunLoop().RunUntilIdle();
110 // Failure should spawn a notification.
111 message_center::MessageCenter* message_center =
112 message_center::MessageCenter::Get();
113 EXPECT_TRUE(message_center->FindVisibleNotificationById(
114 NetworkStateNotifier::kNetworkConnectNotificationId));
115 }
116
117 } // namespace test
118 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/network/network_state_notifier.cc ('k') | ui/chromeos/ui_chromeos_strings.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698