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