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

Side by Side Diff: chrome/browser/chromeos/net/network_state_notifier_unittest.cc

Issue 2434683003: Move NetworkStateNotifier and NetworkConnect from src/ui (Closed)
Patch Set: Fix virtuals Created 4 years, 2 months 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
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 "chrome/browser/chromeos/net/network_state_notifier.h"
6
7 #include <memory>
6 8
7 #include "base/macros.h" 9 #include "base/macros.h"
8 #include "base/run_loop.h" 10 #include "base/run_loop.h"
9 #include "chromeos/dbus/dbus_thread_manager.h" 11 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/shill_device_client.h" 12 #include "chromeos/dbus/shill_device_client.h"
11 #include "chromeos/dbus/shill_service_client.h" 13 #include "chromeos/dbus/shill_service_client.h"
12 #include "chromeos/login/login_state.h" 14 #include "chromeos/login/login_state.h"
15 #include "chromeos/network/network_connect.h"
13 #include "chromeos/network/network_handler.h" 16 #include "chromeos/network/network_handler.h"
14 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h" 18 #include "testing/platform_test.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h" 19 #include "third_party/cros_system_api/dbus/service_constants.h"
17 #include "ui/chromeos/network/network_connect.h"
18 #include "ui/message_center/message_center.h" 20 #include "ui/message_center/message_center.h"
19 21
20 using chromeos::DBusThreadManager; 22 namespace chromeos {
21 using chromeos::ShillDeviceClient;
22 using chromeos::ShillServiceClient;
23
24 namespace ui {
25 namespace test { 23 namespace test {
26 24
27 class NetworkConnectTestDelegate : public NetworkConnect::Delegate { 25 class NetworkConnectTestDelegate : public NetworkConnect::Delegate {
28 public: 26 public:
29 NetworkConnectTestDelegate() {} 27 NetworkConnectTestDelegate()
28 : network_state_notifier_(new NetworkStateNotifier()) {}
30 ~NetworkConnectTestDelegate() override {} 29 ~NetworkConnectTestDelegate() override {}
31 30
32 // NetworkConnect::Delegate 31 // NetworkConnect::Delegate
33 void ShowNetworkConfigure(const std::string& network_id) override {} 32 void ShowNetworkConfigure(const std::string& network_id) override {}
34 void ShowNetworkSettings(const std::string& network_id) override {} 33 void ShowNetworkSettings(const std::string& network_id) override {}
35 bool ShowEnrollNetwork(const std::string& network_id) override { 34 bool ShowEnrollNetwork(const std::string& network_id) override {
36 return false; 35 return false;
37 } 36 }
38 void ShowMobileSimDialog() override {} 37 void ShowMobileSimDialog() override {}
39 void ShowMobileSetupDialog(const std::string& service_path) override {} 38 void ShowMobileSetupDialog(const std::string& service_path) override {}
39 void ShowNetworkConnectError(const std::string& error_name,
40 const std::string& network_id) override {
41 network_state_notifier_->ShowNetworkConnectError(error_name, network_id);
42 }
43 void ShowMobileActivationError(const std::string& network_id) override {}
40 44
41 private: 45 private:
46 std::unique_ptr<NetworkStateNotifier> network_state_notifier_;
47
42 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); 48 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate);
43 }; 49 };
44 50
45 class NetworkStateNotifierTest : public testing::Test { 51 class NetworkStateNotifierTest : public testing::Test {
46 public: 52 public:
47 NetworkStateNotifierTest() {} 53 NetworkStateNotifierTest() {}
48 ~NetworkStateNotifierTest() override {} 54 ~NetworkStateNotifierTest() override {}
49 55
50 void SetUp() override { 56 void SetUp() override {
51 testing::Test::SetUp(); 57 testing::Test::SetUp();
52 DBusThreadManager::Initialize(); 58 DBusThreadManager::Initialize();
53 chromeos::LoginState::Initialize(); 59 LoginState::Initialize();
54 SetupDefaultShillState(); 60 SetupDefaultShillState();
55 chromeos::NetworkHandler::Initialize(); 61 NetworkHandler::Initialize();
56 message_center::MessageCenter::Initialize(); 62 message_center::MessageCenter::Initialize();
57 base::RunLoop().RunUntilIdle(); 63 base::RunLoop().RunUntilIdle();
58 network_connect_delegate_.reset(new NetworkConnectTestDelegate); 64 network_connect_delegate_.reset(new NetworkConnectTestDelegate);
59 NetworkConnect::Initialize(network_connect_delegate_.get()); 65 NetworkConnect::Initialize(network_connect_delegate_.get());
60 } 66 }
61 67
62 void TearDown() override { 68 void TearDown() override {
63 NetworkConnect::Shutdown(); 69 NetworkConnect::Shutdown();
64 network_connect_delegate_.reset(); 70 network_connect_delegate_.reset();
65 message_center::MessageCenter::Shutdown(); 71 message_center::MessageCenter::Shutdown();
66 chromeos::LoginState::Shutdown(); 72 LoginState::Shutdown();
67 chromeos::NetworkHandler::Shutdown(); 73 NetworkHandler::Shutdown();
68 DBusThreadManager::Shutdown(); 74 DBusThreadManager::Shutdown();
69 testing::Test::TearDown(); 75 testing::Test::TearDown();
70 } 76 }
71 77
72 protected: 78 protected:
73 void SetupDefaultShillState() { 79 void SetupDefaultShillState() {
74 base::RunLoop().RunUntilIdle(); 80 base::RunLoop().RunUntilIdle();
75 ShillDeviceClient::TestInterface* device_test = 81 ShillDeviceClient::TestInterface* device_test =
76 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); 82 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
77 device_test->ClearDevices(); 83 device_test->ClearDevices();
(...skipping 21 matching lines...) Expand all
99 105
100 std::unique_ptr<NetworkConnectTestDelegate> network_connect_delegate_; 106 std::unique_ptr<NetworkConnectTestDelegate> network_connect_delegate_;
101 base::MessageLoop message_loop_; 107 base::MessageLoop message_loop_;
102 108
103 private: 109 private:
104 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); 110 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest);
105 }; 111 };
106 112
107 TEST_F(NetworkStateNotifierTest, ConnectionFailure) { 113 TEST_F(NetworkStateNotifierTest, ConnectionFailure) {
108 NetworkConnect::Get()->ConnectToNetwork("wifi1"); 114 NetworkConnect::Get()->ConnectToNetwork("wifi1");
109 base::RunLoop().RunUntilIdle(); 115 base::RunLoop().RunUntilIdle();
110 // Failure should spawn a notification. 116 // Failure should spawn a notification.
111 message_center::MessageCenter* message_center = 117 message_center::MessageCenter* message_center =
112 message_center::MessageCenter::Get(); 118 message_center::MessageCenter::Get();
113 EXPECT_TRUE(message_center->FindVisibleNotificationById( 119 EXPECT_TRUE(message_center->FindVisibleNotificationById(
114 NetworkStateNotifier::kNetworkConnectNotificationId)); 120 NetworkStateNotifier::kNetworkConnectNotificationId));
115 } 121 }
116 122
117 } // namespace test 123 } // namespace test
118 } // namespace ui 124 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/net/network_state_notifier.cc ('k') | chrome/browser/chromeos/net/shill_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698