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

Side by Side Diff: ash/system/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
« no previous file with comments | « ash/system/chromeos/network/network_state_notifier.cc ('k') | ash/system/system_notifier.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/chromeos/network/network_state_notifier.h" 5 #include "ash/system/chromeos/network/network_state_notifier.h"
6 6
7 #include "base/run_loop.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf_widget.h"
9 #include "ash/shell.h"
10 #include "ash/system/chromeos/network/network_connect.h"
11 #include "ash/system/status_area_widget.h"
12 #include "ash/system/tray/system_tray.h"
13 #include "ash/test/ash_test_base.h"
8 #include "chromeos/dbus/dbus_thread_manager.h" 14 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/shill_device_client.h" 15 #include "chromeos/dbus/shill_device_client.h"
10 #include "chromeos/dbus/shill_service_client.h" 16 #include "chromeos/dbus/shill_service_client.h"
11 #include "chromeos/login/login_state.h" 17 #include "chromeos/login/login_state.h"
12 #include "chromeos/network/network_handler.h" 18 #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" 19 #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" 20 #include "ui/message_center/message_center.h"
18 21
22 namespace {
23
24 ash::SystemTray* GetSystemTray() {
25 return ash::Shell::GetPrimaryRootWindowController()
26 ->shelf()
27 ->status_area_widget()
28 ->system_tray();
29 }
30
31 } // namespace
32
19 using chromeos::DBusThreadManager; 33 using chromeos::DBusThreadManager;
20 using chromeos::ShillDeviceClient; 34 using chromeos::ShillDeviceClient;
21 using chromeos::ShillServiceClient; 35 using chromeos::ShillServiceClient;
22 36
23 namespace ui { 37 namespace ash {
24 namespace test { 38 namespace test {
25 39
26 class NetworkConnectTestDelegate : public NetworkConnect::Delegate { 40 class NetworkConnectTestDelegate : public NetworkConnect::Delegate {
27 public: 41 public:
28 NetworkConnectTestDelegate() {} 42 NetworkConnectTestDelegate() {}
29 ~NetworkConnectTestDelegate() override {} 43 ~NetworkConnectTestDelegate() override {}
30 44
31 // NetworkConnect::Delegate 45 // NetworkConnect::Delegate
32 void ShowNetworkConfigure(const std::string& network_id) override {} 46 void ShowNetworkConfigure(const std::string& network_id) override {}
33 void ShowNetworkSettings(const std::string& network_id) override {} 47 void ShowNetworkSettings(const std::string& network_id) override {}
34 bool ShowEnrollNetwork(const std::string& network_id) override { 48 bool ShowEnrollNetwork(const std::string& network_id) override {
35 return false; 49 return false;
36 } 50 }
37 void ShowMobileSimDialog() override {} 51 void ShowMobileSimDialog() override {}
38 void ShowMobileSetupDialog(const std::string& service_path) override {} 52 void ShowMobileSetupDialog(const std::string& service_path) override {}
39 53
40 private: 54 private:
41 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); 55 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate);
42 }; 56 };
43 57
44 class NetworkStateNotifierTest : public testing::Test { 58 class NetworkStateNotifierTest : public AshTestBase {
45 public: 59 public:
46 NetworkStateNotifierTest() {} 60 NetworkStateNotifierTest() {}
47 ~NetworkStateNotifierTest() override {} 61 ~NetworkStateNotifierTest() override {}
48 62
49 void SetUp() override { 63 void SetUp() override {
50 testing::Test::SetUp();
51 DBusThreadManager::Initialize(); 64 DBusThreadManager::Initialize();
52 chromeos::LoginState::Initialize(); 65 chromeos::LoginState::Initialize();
53 SetupDefaultShillState(); 66 SetupDefaultShillState();
54 chromeos::NetworkHandler::Initialize(); 67 chromeos::NetworkHandler::Initialize();
55 message_center::MessageCenter::Initialize(); 68 RunAllPendingInMessageLoop();
56 base::RunLoop().RunUntilIdle(); 69 AshTestBase::SetUp();
57 network_connect_delegate_.reset(new NetworkConnectTestDelegate); 70 network_connect_delegate_.reset(new NetworkConnectTestDelegate);
58 NetworkConnect::Initialize(network_connect_delegate_.get()); 71 NetworkConnect::Initialize(network_connect_delegate_.get());
59 } 72 }
60 73
61 void TearDown() override { 74 void TearDown() override {
62 NetworkConnect::Shutdown(); 75 NetworkConnect::Shutdown();
63 network_connect_delegate_.reset(); 76 network_connect_delegate_.reset();
64 message_center::MessageCenter::Shutdown(); 77 AshTestBase::TearDown();
65 chromeos::LoginState::Shutdown(); 78 chromeos::LoginState::Shutdown();
66 chromeos::NetworkHandler::Shutdown(); 79 chromeos::NetworkHandler::Shutdown();
67 DBusThreadManager::Shutdown(); 80 DBusThreadManager::Shutdown();
68 testing::Test::TearDown();
69 } 81 }
70 82
71 protected: 83 protected:
72 void SetupDefaultShillState() { 84 void SetupDefaultShillState() {
73 base::RunLoop().RunUntilIdle(); 85 RunAllPendingInMessageLoop();
74 ShillDeviceClient::TestInterface* device_test = 86 ShillDeviceClient::TestInterface* device_test =
75 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); 87 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
76 device_test->ClearDevices(); 88 device_test->ClearDevices();
77 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi, 89 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi,
78 "stub_wifi_device1"); 90 "stub_wifi_device1");
79 device_test->AddDevice("/device/stub_cellular_device1", 91 device_test->AddDevice("/device/stub_cellular_device1",
80 shill::kTypeCellular, "stub_cellular_device1"); 92 shill::kTypeCellular, "stub_cellular_device1");
81 93
82 ShillServiceClient::TestInterface* service_test = 94 ShillServiceClient::TestInterface* service_test =
83 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 95 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
84 service_test->ClearServices(); 96 service_test->ClearServices();
85 const bool add_to_visible = true; 97 const bool add_to_visible = true;
86 // Create a wifi network and set to online. 98 // Create a wifi network and set to online.
87 service_test->AddService("/service/wifi1", "wifi1_guid", "wifi1", 99 service_test->AddService("/service/wifi1", "wifi1_guid", "wifi1",
88 shill::kTypeWifi, shill::kStateIdle, 100 shill::kTypeWifi, shill::kStateIdle,
89 add_to_visible); 101 add_to_visible);
90 service_test->SetServiceProperty("wifi1", shill::kSecurityProperty, 102 service_test->SetServiceProperty("wifi1", shill::kSecurityProperty,
91 base::StringValue(shill::kSecurityWep)); 103 base::StringValue(shill::kSecurityWep));
92 service_test->SetServiceProperty("wifi1", shill::kConnectableProperty, 104 service_test->SetServiceProperty("wifi1", shill::kConnectableProperty,
93 base::FundamentalValue(true)); 105 base::FundamentalValue(true));
94 service_test->SetServiceProperty("wifi1", shill::kPassphraseProperty, 106 service_test->SetServiceProperty("wifi1", shill::kPassphraseProperty,
95 base::StringValue("failure")); 107 base::StringValue("failure"));
96 base::RunLoop().RunUntilIdle(); 108 RunAllPendingInMessageLoop();
97 } 109 }
98 110
99 scoped_ptr<NetworkConnectTestDelegate> network_connect_delegate_; 111 scoped_ptr<NetworkConnectTestDelegate> network_connect_delegate_;
100 base::MessageLoop message_loop_;
101 112
102 private: 113 private:
103 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); 114 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest);
104 }; 115 };
105 116
106 TEST_F(NetworkStateNotifierTest, ConnectionFailure) { 117 TEST_F(NetworkStateNotifierTest, ConnectionFailure) {
118 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble());
107 NetworkConnect::Get()->ConnectToNetwork("wifi1"); 119 NetworkConnect::Get()->ConnectToNetwork("wifi1");
108 base::RunLoop().RunUntilIdle(); 120 RunAllPendingInMessageLoop();
109 // Failure should spawn a notification. 121 // Failure should spawn a notification.
110 message_center::MessageCenter* message_center = 122 message_center::MessageCenter* message_center =
111 message_center::MessageCenter::Get(); 123 message_center::MessageCenter::Get();
112 EXPECT_TRUE(message_center->FindVisibleNotificationById( 124 EXPECT_TRUE(message_center->FindVisibleNotificationById(
113 NetworkStateNotifier::kNetworkConnectNotificationId)); 125 NetworkStateNotifier::kNetworkConnectNotificationId));
114 } 126 }
115 127
116 } // namespace test 128 } // namespace test
117 } // namespace ui 129 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/network_state_notifier.cc ('k') | ash/system/system_notifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698