| OLD | NEW |
| (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 "ash/system/chromeos/network/network_state_notifier.h" | |
| 6 | |
| 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" | |
| 14 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 15 #include "chromeos/dbus/shill_device_client.h" | |
| 16 #include "chromeos/dbus/shill_service_client.h" | |
| 17 #include "chromeos/login/login_state.h" | |
| 18 #include "chromeos/network/network_handler.h" | |
| 19 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 20 #include "ui/message_center/message_center.h" | |
| 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 | |
| 33 using chromeos::DBusThreadManager; | |
| 34 using chromeos::ShillDeviceClient; | |
| 35 using chromeos::ShillServiceClient; | |
| 36 | |
| 37 namespace ash { | |
| 38 namespace test { | |
| 39 | |
| 40 class NetworkConnectTestDelegate : public NetworkConnect::Delegate { | |
| 41 public: | |
| 42 NetworkConnectTestDelegate() {} | |
| 43 ~NetworkConnectTestDelegate() override {} | |
| 44 | |
| 45 // NetworkConnect::Delegate | |
| 46 void ShowNetworkConfigure(const std::string& network_id) override {} | |
| 47 void ShowNetworkSettings(const std::string& network_id) override {} | |
| 48 bool ShowEnrollNetwork(const std::string& network_id) override { | |
| 49 return false; | |
| 50 } | |
| 51 void ShowMobileSimDialog() override {} | |
| 52 void ShowMobileSetupDialog(const std::string& service_path) override {} | |
| 53 | |
| 54 private: | |
| 55 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); | |
| 56 }; | |
| 57 | |
| 58 class NetworkStateNotifierTest : public AshTestBase { | |
| 59 public: | |
| 60 NetworkStateNotifierTest() {} | |
| 61 ~NetworkStateNotifierTest() override {} | |
| 62 | |
| 63 void SetUp() override { | |
| 64 DBusThreadManager::Initialize(); | |
| 65 chromeos::LoginState::Initialize(); | |
| 66 SetupDefaultShillState(); | |
| 67 chromeos::NetworkHandler::Initialize(); | |
| 68 RunAllPendingInMessageLoop(); | |
| 69 AshTestBase::SetUp(); | |
| 70 network_connect_delegate_.reset(new NetworkConnectTestDelegate); | |
| 71 NetworkConnect::Initialize(network_connect_delegate_.get()); | |
| 72 } | |
| 73 | |
| 74 void TearDown() override { | |
| 75 NetworkConnect::Shutdown(); | |
| 76 network_connect_delegate_.reset(); | |
| 77 AshTestBase::TearDown(); | |
| 78 chromeos::LoginState::Shutdown(); | |
| 79 chromeos::NetworkHandler::Shutdown(); | |
| 80 DBusThreadManager::Shutdown(); | |
| 81 } | |
| 82 | |
| 83 protected: | |
| 84 void SetupDefaultShillState() { | |
| 85 RunAllPendingInMessageLoop(); | |
| 86 ShillDeviceClient::TestInterface* device_test = | |
| 87 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | |
| 88 device_test->ClearDevices(); | |
| 89 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi, | |
| 90 "stub_wifi_device1"); | |
| 91 device_test->AddDevice("/device/stub_cellular_device1", | |
| 92 shill::kTypeCellular, "stub_cellular_device1"); | |
| 93 | |
| 94 ShillServiceClient::TestInterface* service_test = | |
| 95 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | |
| 96 service_test->ClearServices(); | |
| 97 const bool add_to_visible = true; | |
| 98 // Create a wifi network and set to online. | |
| 99 service_test->AddService("/service/wifi1", "wifi1_guid", "wifi1", | |
| 100 shill::kTypeWifi, shill::kStateIdle, | |
| 101 add_to_visible); | |
| 102 service_test->SetServiceProperty("wifi1", shill::kSecurityProperty, | |
| 103 base::StringValue(shill::kSecurityWep)); | |
| 104 service_test->SetServiceProperty("wifi1", shill::kConnectableProperty, | |
| 105 base::FundamentalValue(true)); | |
| 106 service_test->SetServiceProperty("wifi1", shill::kPassphraseProperty, | |
| 107 base::StringValue("failure")); | |
| 108 RunAllPendingInMessageLoop(); | |
| 109 } | |
| 110 | |
| 111 scoped_ptr<NetworkConnectTestDelegate> network_connect_delegate_; | |
| 112 | |
| 113 private: | |
| 114 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); | |
| 115 }; | |
| 116 | |
| 117 TEST_F(NetworkStateNotifierTest, ConnectionFailure) { | |
| 118 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); | |
| 119 NetworkConnect::Get()->ConnectToNetwork("wifi1"); | |
| 120 RunAllPendingInMessageLoop(); | |
| 121 // Failure should spawn a notification. | |
| 122 message_center::MessageCenter* message_center = | |
| 123 message_center::MessageCenter::Get(); | |
| 124 EXPECT_TRUE(message_center->FindVisibleNotificationById( | |
| 125 NetworkStateNotifier::kNetworkConnectNotificationId)); | |
| 126 } | |
| 127 | |
| 128 } // namespace test | |
| 129 } // namespace ash | |
| OLD | NEW |