OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/network/network_icon.h" | |
6 | |
7 #include "ash/test/ash_test_base.h" | |
8 #include "base/logging.h" | |
9 #include "base/memory/ptr_util.h" | |
10 #include "chromeos/network/network_handler.h" | |
11 #include "chromeos/network/network_state.h" | |
12 #include "chromeos/network/tether_constants.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" | |
15 #include "ui/gfx/image/image_unittest_util.h" | |
16 | |
17 namespace ash { | |
18 | |
19 namespace network_icon { | |
20 | |
21 class NetworkIconTest : public test::AshTestBase { | |
Kyle Horimoto
2017/05/01 17:09:26
You need to add one more type to your test: a Wi-F
lesliewatkins
2017/05/03 01:23:23
Done.
| |
22 public: | |
23 NetworkIconTest() {} | |
24 ~NetworkIconTest() override {} | |
25 | |
26 std::unique_ptr<chromeos::NetworkState> tether_network, wifi_network, | |
27 cellular_network; | |
28 void SetUp() override { | |
29 test::AshTestBase::SetUp(); | |
30 chromeos::NetworkHandler::Initialize(); | |
31 } | |
32 | |
33 void SetNetworkType(chromeos::NetworkState* network, | |
34 const std::string& type) { | |
35 network->set_type(type); | |
36 } | |
37 | |
38 void TearDown() override { | |
39 chromeos::NetworkHandler::Shutdown(); | |
40 test::AshTestBase::TearDown(); | |
41 } | |
42 | |
43 gfx::Image ImageForNetwork(chromeos::NetworkState* network) { | |
44 gfx::ImageSkia image_skia = GetImageForNetwork(network, icon_type); | |
45 return gfx::Image(image_skia); | |
46 } | |
47 | |
48 // The icon for a Tether network should be the same as one for a cellular | |
49 // network. The icon for a Tether network should be different from one for a | |
50 // wifi network. The icon for a cellular network should be different from one | |
51 // for a wifi network. | |
52 void GetAndCompareImagesByNetworkType( | |
53 chromeos::NetworkState* tether_network, | |
54 chromeos::NetworkState* wifi_network, | |
55 chromeos::NetworkState* cellular_network) { | |
56 gfx::Image tether_image = ImageForNetwork(tether_network); | |
57 gfx::Image wifi_image = ImageForNetwork(wifi_network); | |
58 gfx::Image cellular_image = ImageForNetwork(cellular_network); | |
59 | |
60 EXPECT_FALSE(gfx::test::AreImagesEqual(tether_image, wifi_image)); | |
61 EXPECT_FALSE(gfx::test::AreImagesEqual(cellular_image, wifi_image)); | |
62 EXPECT_TRUE(gfx::test::AreImagesEqual(tether_image, cellular_image)); | |
63 } | |
64 | |
65 IconType icon_type = ICON_TYPE_TRAY; | |
66 | |
67 private: | |
68 DISALLOW_COPY_AND_ASSIGN(NetworkIconTest); | |
69 }; | |
70 | |
71 // This tests that the correct icons are being generated for the correct | |
72 // networks by pairwise comparison of three different network types, verifying | |
73 // that the Tether and cellular icon are the same, Tether and wifi icons are | |
74 // different, and cellular and wifi icons are different. | |
75 TEST_F(NetworkIconTest, CompareImagesByNetworkType_NotVisible) { | |
76 std::unique_ptr<chromeos::NetworkState> tether_network = | |
77 base::MakeUnique<chromeos::NetworkState>("tether"); | |
78 SetNetworkType(tether_network.get(), chromeos::kTypeTether); | |
79 | |
80 std::unique_ptr<chromeos::NetworkState> wifi_network = | |
81 base::MakeUnique<chromeos::NetworkState>("wifi"); | |
82 SetNetworkType(wifi_network.get(), shill::kTypeWifi); | |
83 | |
84 std::unique_ptr<chromeos::NetworkState> cellular_network = | |
85 base::MakeUnique<chromeos::NetworkState>("cellular"); | |
86 SetNetworkType(cellular_network.get(), shill::kTypeCellular); | |
87 | |
88 GetAndCompareImagesByNetworkType(tether_network.get(), wifi_network.get(), | |
89 cellular_network.get()); | |
90 } | |
91 | |
92 TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connecting) { | |
93 std::unique_ptr<chromeos::NetworkState> tether_network = | |
94 base::MakeUnique<chromeos::NetworkState>("tether_connecting"); | |
95 tether_network->set_visible(true); | |
96 tether_network->set_connection_state(shill::kStateAssociation); | |
97 SetNetworkType(tether_network.get(), chromeos::kTypeTether); | |
98 | |
99 std::unique_ptr<chromeos::NetworkState> wifi_network = | |
100 base::MakeUnique<chromeos::NetworkState>("wifi_connecting"); | |
101 wifi_network->set_visible(true); | |
102 wifi_network->set_connection_state(shill::kStateAssociation); | |
103 SetNetworkType(wifi_network.get(), shill::kTypeWifi); | |
104 | |
105 std::unique_ptr<chromeos::NetworkState> cellular_network = | |
106 base::MakeUnique<chromeos::NetworkState>("cellular_connecting"); | |
107 cellular_network->set_visible(true); | |
108 cellular_network->set_connection_state(shill::kStateAssociation); | |
109 SetNetworkType(cellular_network.get(), shill::kTypeCellular); | |
110 | |
111 GetAndCompareImagesByNetworkType(tether_network.get(), wifi_network.get(), | |
112 cellular_network.get()); | |
113 } | |
114 | |
115 TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connected) { | |
116 std::unique_ptr<chromeos::NetworkState> tether_network = | |
117 base::MakeUnique<chromeos::NetworkState>("tether_connected"); | |
118 tether_network->set_visible(true); | |
119 tether_network->set_connection_state(shill::kStateOnline); | |
120 SetNetworkType(tether_network.get(), chromeos::kTypeTether); | |
121 | |
122 std::unique_ptr<chromeos::NetworkState> wifi_network = | |
123 base::MakeUnique<chromeos::NetworkState>("wifi_connected"); | |
124 wifi_network->set_visible(true); | |
125 wifi_network->set_connection_state(shill::kStateOnline); | |
126 SetNetworkType(wifi_network.get(), shill::kTypeWifi); | |
127 | |
128 std::unique_ptr<chromeos::NetworkState> cellular_network = | |
129 base::MakeUnique<chromeos::NetworkState>("cellular_connected"); | |
130 cellular_network->set_visible(true); | |
131 cellular_network->set_connection_state(shill::kStateOnline); | |
132 SetNetworkType(cellular_network.get(), shill::kTypeCellular); | |
133 | |
134 GetAndCompareImagesByNetworkType(tether_network.get(), wifi_network.get(), | |
135 cellular_network.get()); | |
136 } | |
137 | |
138 } // namespace network_icon | |
139 | |
140 } // namespace ash | |
OLD | NEW |