| 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/status_area_widget.h" | 11 #include "ash/system/status_area_widget.h" |
| 11 #include "ash/system/tray/system_tray.h" | 12 #include "ash/system/tray/system_tray.h" |
| 12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_device_client.h" | 15 #include "chromeos/dbus/shill_device_client.h" |
| 15 #include "chromeos/dbus/shill_service_client.h" | 16 #include "chromeos/dbus/shill_service_client.h" |
| 16 #include "chromeos/network/network_state_handler.h" | 17 #include "chromeos/network/network_connection_handler.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 ash::SystemTray* GetSystemTray() { | 22 ash::SystemTray* GetSystemTray() { |
| 22 return ash::Shell::GetPrimaryRootWindowController()->shelf()-> | 23 return ash::Shell::GetPrimaryRootWindowController()->shelf()-> |
| 23 status_area_widget()->system_tray(); | 24 status_area_widget()->system_tray(); |
| 24 } | 25 } |
| 25 | 26 |
| 26 } // namespace | 27 } // namespace |
| 27 | 28 |
| 28 using chromeos::DBusThreadManager; | 29 using chromeos::DBusThreadManager; |
| 29 using chromeos::NetworkHandler; | 30 using chromeos::NetworkHandler; |
| 30 using chromeos::NetworkStateHandler; | 31 using chromeos::NetworkConnectionHandler; |
| 31 using chromeos::ShillDeviceClient; | 32 using chromeos::ShillDeviceClient; |
| 32 using chromeos::ShillServiceClient; | 33 using chromeos::ShillServiceClient; |
| 33 | 34 |
| 34 namespace ash { | 35 namespace ash { |
| 35 namespace test { | 36 namespace test { |
| 36 | 37 |
| 37 class NetworkStateNotifierTest : public AshTestBase { | 38 class NetworkStateNotifierTest : public AshTestBase { |
| 38 public: | 39 public: |
| 39 NetworkStateNotifierTest() {} | 40 NetworkStateNotifierTest() {} |
| 40 virtual ~NetworkStateNotifierTest() {} | 41 virtual ~NetworkStateNotifierTest() {} |
| (...skipping 23 matching lines...) Expand all Loading... |
| 64 device_test->AddDevice("/device/stub_cellular_device1", | 65 device_test->AddDevice("/device/stub_cellular_device1", |
| 65 flimflam::kTypeCellular, "stub_cellular_device1"); | 66 flimflam::kTypeCellular, "stub_cellular_device1"); |
| 66 | 67 |
| 67 ShillServiceClient::TestInterface* service_test = | 68 ShillServiceClient::TestInterface* service_test = |
| 68 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 69 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 69 service_test->ClearServices(); | 70 service_test->ClearServices(); |
| 70 const bool add_to_watchlist = true; | 71 const bool add_to_watchlist = true; |
| 71 const bool add_to_visible = true; | 72 const bool add_to_visible = true; |
| 72 // Create wifi and cellular networks and set to online. | 73 // Create wifi and cellular networks and set to online. |
| 73 service_test->AddService("wifi1", "wifi1", | 74 service_test->AddService("wifi1", "wifi1", |
| 74 flimflam::kTypeWifi, flimflam::kStateOnline, | 75 flimflam::kTypeWifi, flimflam::kStateIdle, |
| 75 add_to_visible, add_to_watchlist); | 76 add_to_visible, add_to_watchlist); |
| 77 service_test->SetServiceProperty("wifi1", |
| 78 flimflam::kSecurityProperty, |
| 79 base::StringValue(flimflam::kSecurityWep)); |
| 80 service_test->SetServiceProperty("wifi1", |
| 81 flimflam::kConnectableProperty, |
| 82 base::FundamentalValue(true)); |
| 83 service_test->SetServiceProperty("wifi1", |
| 84 flimflam::kPassphraseProperty, |
| 85 base::StringValue("failure")); |
| 76 RunAllPendingInMessageLoop(); | 86 RunAllPendingInMessageLoop(); |
| 77 } | 87 } |
| 78 | 88 |
| 79 void SetServiceState(const std::string& service_path, | |
| 80 const std::string& state) { | |
| 81 ShillServiceClient::TestInterface* service_test = | |
| 82 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | |
| 83 service_test->SetServiceProperty(service_path, flimflam::kStateProperty, | |
| 84 base::StringValue(state)); | |
| 85 RunAllPendingInMessageLoop(); | |
| 86 } | |
| 87 | |
| 88 private: | 89 private: |
| 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 ash::network_connect::ConnectToNetwork("wifi1", NULL /* owning_window */); |
| 95 SetServiceState("wifi1", flimflam::kStateFailure); | 96 RunAllPendingInMessageLoop(); |
| 96 EXPECT_FALSE(GetSystemTray()->CloseNotificationBubbleForTest()); | 97 // Failure should spawn a notification. |
| 97 // State -> Failure for connecting network should spawn a notification | |
| 98 SetServiceState("wifi1", flimflam::kStateAssociation); | |
| 99 NetworkHandler::Get()->network_state_handler()->SetConnectingNetwork("wifi1"); | |
| 100 SetServiceState("wifi1", flimflam::kStateFailure); | |
| 101 EXPECT_TRUE(GetSystemTray()->CloseNotificationBubbleForTest()); | 98 EXPECT_TRUE(GetSystemTray()->CloseNotificationBubbleForTest()); |
| 102 // Failure -> Idle should not spawn a notification | |
| 103 SetServiceState("wifi1", flimflam::kStateIdle); | |
| 104 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); | |
| 105 // Idle -> Failure should also not spawn a notification | |
| 106 SetServiceState("wifi1", flimflam::kStateFailure); | |
| 107 EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); | |
| 108 } | 99 } |
| 109 | 100 |
| 110 } // namespace test | 101 } // namespace test |
| 111 } // namespace ash | 102 } // namespace ash |
| OLD | NEW |