| 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/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
| 11 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_device_client.h" | 14 #include "chromeos/dbus/shill_device_client.h" |
| 15 #include "chromeos/dbus/shill_service_client.h" | 15 #include "chromeos/dbus/shill_service_client.h" |
| 16 #include "chromeos/network/network_state_handler.h" | 16 #include "chromeos/network/network_state_handler.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 ash::SystemTray* GetSystemTray() { | 21 ash::SystemTray* GetSystemTray() { |
| 22 return ash::Shell::GetPrimaryRootWindowController()->shelf()-> | 22 return ash::Shell::GetPrimaryRootWindowController()->shelf()-> |
| 23 status_area_widget()->system_tray(); | 23 status_area_widget()->system_tray(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 using chromeos::DBusThreadManager; |
| 29 using chromeos::NetworkHandler; |
| 28 using chromeos::NetworkStateHandler; | 30 using chromeos::NetworkStateHandler; |
| 29 using chromeos::DBusThreadManager; | |
| 30 using chromeos::ShillDeviceClient; | 31 using chromeos::ShillDeviceClient; |
| 31 using chromeos::ShillServiceClient; | 32 using chromeos::ShillServiceClient; |
| 32 | 33 |
| 33 namespace ash { | 34 namespace ash { |
| 34 namespace test { | 35 namespace test { |
| 35 | 36 |
| 36 using internal::NetworkStateNotifier; | 37 using internal::NetworkStateNotifier; |
| 37 | 38 |
| 38 class NetworkStateNotifierTest : public AshTestBase { | 39 class NetworkStateNotifierTest : public AshTestBase { |
| 39 public: | 40 public: |
| 40 NetworkStateNotifierTest() {} | 41 NetworkStateNotifierTest() {} |
| 41 virtual ~NetworkStateNotifierTest() {} | 42 virtual ~NetworkStateNotifierTest() {} |
| 42 | 43 |
| 43 virtual void SetUp() OVERRIDE { | 44 virtual void SetUp() OVERRIDE { |
| 44 DBusThreadManager::InitializeWithStub(); | 45 DBusThreadManager::InitializeWithStub(); |
| 45 SetupDefaultShillState(); | 46 SetupDefaultShillState(); |
| 46 NetworkStateHandler::Initialize(); | 47 NetworkHandler::Initialize(); |
| 47 RunAllPendingInMessageLoop(); | 48 RunAllPendingInMessageLoop(); |
| 48 AshTestBase::SetUp(); | 49 AshTestBase::SetUp(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 virtual void TearDown() OVERRIDE { | 52 virtual void TearDown() OVERRIDE { |
| 52 AshTestBase::TearDown(); | 53 AshTestBase::TearDown(); |
| 53 NetworkStateHandler::Shutdown(); | 54 NetworkHandler::Shutdown(); |
| 54 DBusThreadManager::Shutdown(); | 55 DBusThreadManager::Shutdown(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 protected: | 58 protected: |
| 58 void SetupDefaultShillState() { | 59 void SetupDefaultShillState() { |
| 59 RunAllPendingInMessageLoop(); | 60 RunAllPendingInMessageLoop(); |
| 60 ShillDeviceClient::TestInterface* device_test = | 61 ShillDeviceClient::TestInterface* device_test = |
| 61 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | 62 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
| 62 device_test->ClearDevices(); | 63 device_test->ClearDevices(); |
| 63 device_test->AddDevice("/device/stub_wifi_device1", | 64 device_test->AddDevice("/device/stub_wifi_device1", |
| (...skipping 25 matching lines...) Expand all Loading... |
| 89 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); | 90 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 TEST_F(NetworkStateNotifierTest, ConnectionFailure) { | 93 TEST_F(NetworkStateNotifierTest, ConnectionFailure) { |
| 93 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); | 94 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); |
| 94 // State -> Failure for non connecting network should not spawn a notification | 95 // State -> Failure for non connecting network should not spawn a notification |
| 95 SetServiceState("wifi1", flimflam::kStateFailure); | 96 SetServiceState("wifi1", flimflam::kStateFailure); |
| 96 EXPECT_FALSE(GetSystemTray()->CloseNotificationBubbleForTest()); | 97 EXPECT_FALSE(GetSystemTray()->CloseNotificationBubbleForTest()); |
| 97 // State -> Failure for connecting network should spawn a notification | 98 // State -> Failure for connecting network should spawn a notification |
| 98 SetServiceState("wifi1", flimflam::kStateAssociation); | 99 SetServiceState("wifi1", flimflam::kStateAssociation); |
| 99 NetworkStateHandler::Get()->SetConnectingNetwork("wifi1"); | 100 NetworkHandler::Get()->network_state_handler()->SetConnectingNetwork("wifi1"); |
| 100 SetServiceState("wifi1", flimflam::kStateFailure); | 101 SetServiceState("wifi1", flimflam::kStateFailure); |
| 101 EXPECT_TRUE(GetSystemTray()->CloseNotificationBubbleForTest()); | 102 EXPECT_TRUE(GetSystemTray()->CloseNotificationBubbleForTest()); |
| 102 // Failure -> Idle should not spawn a notification | 103 // Failure -> Idle should not spawn a notification |
| 103 SetServiceState("wifi1", flimflam::kStateIdle); | 104 SetServiceState("wifi1", flimflam::kStateIdle); |
| 104 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); | 105 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); |
| 105 // Idle -> Failure should also not spawn a notification | 106 // Idle -> Failure should also not spawn a notification |
| 106 SetServiceState("wifi1", flimflam::kStateFailure); | 107 SetServiceState("wifi1", flimflam::kStateFailure); |
| 107 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); | 108 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); |
| 108 } | 109 } |
| 109 | 110 |
| 110 } // namespace test | 111 } // namespace test |
| 111 } // namespace ash | 112 } // namespace ash |
| OLD | NEW |