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

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

Issue 693493003: Revert "Move network_connect code to ui/chromeos/network" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
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/run_loop.h"
8 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/shill_device_client.h"
10 #include "chromeos/dbus/shill_service_client.h"
11 #include "chromeos/login/login_state.h"
12 #include "chromeos/network/network_handler.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 #include "ui/chromeos/network/network_connect.h"
17 #include "ui/message_center/message_center.h"
18
19 using chromeos::DBusThreadManager;
20 using chromeos::ShillDeviceClient;
21 using chromeos::ShillServiceClient;
22
23 namespace ui {
24 namespace test {
25
26 class NetworkConnectTestDelegate : public NetworkConnect::Delegate {
27 public:
28 NetworkConnectTestDelegate() {}
29 ~NetworkConnectTestDelegate() override {}
30
31 // NetworkConnect::Delegate
32 void ShowNetworkConfigure(const std::string& network_id) override {}
33 void ShowNetworkSettings(const std::string& network_id) override {}
34 bool ShowEnrollNetwork(const std::string& network_id) override {
35 return false;
36 }
37 void ShowMobileSimDialog() override {}
38 void ShowMobileSetupDialog(const std::string& service_path) override {}
39
40 private:
41 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate);
42 };
43
44 class NetworkStateNotifierTest : public testing::Test {
45 public:
46 NetworkStateNotifierTest() {}
47 ~NetworkStateNotifierTest() override {}
48
49 void SetUp() override {
50 testing::Test::SetUp();
51 DBusThreadManager::Initialize();
52 chromeos::LoginState::Initialize();
53 SetupDefaultShillState();
54 chromeos::NetworkHandler::Initialize();
55 message_center::MessageCenter::Initialize();
56 base::RunLoop().RunUntilIdle();
57 network_connect_delegate_.reset(new NetworkConnectTestDelegate);
58 NetworkConnect::Initialize(network_connect_delegate_.get());
59 }
60
61 void TearDown() override {
62 NetworkConnect::Shutdown();
63 network_connect_delegate_.reset();
64 message_center::MessageCenter::Shutdown();
65 chromeos::LoginState::Shutdown();
66 chromeos::NetworkHandler::Shutdown();
67 DBusThreadManager::Shutdown();
68 testing::Test::TearDown();
69 }
70
71 protected:
72 void SetupDefaultShillState() {
73 base::RunLoop().RunUntilIdle();
74 ShillDeviceClient::TestInterface* device_test =
75 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
76 device_test->ClearDevices();
77 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi,
78 "stub_wifi_device1");
79 device_test->AddDevice("/device/stub_cellular_device1",
80 shill::kTypeCellular, "stub_cellular_device1");
81
82 ShillServiceClient::TestInterface* service_test =
83 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
84 service_test->ClearServices();
85 const bool add_to_visible = true;
86 // Create a wifi network and set to online.
87 service_test->AddService("/service/wifi1", "wifi1_guid", "wifi1",
88 shill::kTypeWifi, shill::kStateIdle,
89 add_to_visible);
90 service_test->SetServiceProperty("wifi1", shill::kSecurityProperty,
91 base::StringValue(shill::kSecurityWep));
92 service_test->SetServiceProperty("wifi1", shill::kConnectableProperty,
93 base::FundamentalValue(true));
94 service_test->SetServiceProperty("wifi1", shill::kPassphraseProperty,
95 base::StringValue("failure"));
96 base::RunLoop().RunUntilIdle();
97 }
98
99 scoped_ptr<NetworkConnectTestDelegate> network_connect_delegate_;
100 base::MessageLoop message_loop_;
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest);
104 };
105
106 TEST_F(NetworkStateNotifierTest, ConnectionFailure) {
107 NetworkConnect::Get()->ConnectToNetwork("wifi1");
108 base::RunLoop().RunUntilIdle();
109 // Failure should spawn a notification.
110 message_center::MessageCenter* message_center =
111 message_center::MessageCenter::Get();
112 EXPECT_TRUE(message_center->FindVisibleNotificationById(
113 NetworkStateNotifier::kNetworkConnectNotificationId));
114 }
115
116 } // namespace test
117 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/network/network_state_notifier.cc ('k') | ui/chromeos/resources/default_100_percent/network/notification_3g.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698