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 { | |
22 public: | |
23 NetworkIconTest() {} | |
24 ~NetworkIconTest() override {} | |
25 | |
26 void SetUp() override { | |
27 test::AshTestBase::SetUp(); | |
28 chromeos::NetworkHandler::Initialize(); | |
29 | |
30 tether_network = | |
Kyle Horimoto
2017/05/03 01:53:33
nit:
tether_network = ...
tether_network->set_typ
lesliewatkins
2017/05/03 22:00:24
Done.
| |
31 base::MakeUnique<chromeos::NetworkState>("tetherNetworkPath"); | |
32 wifi_network = base::MakeUnique<chromeos::NetworkState>("wifiServicePath"); | |
33 cellular_network = | |
34 base::MakeUnique<chromeos::NetworkState>("cellularServicePath"); | |
35 wifi_tether_network = | |
36 base::MakeUnique<chromeos::NetworkState>("wifiTetherServicePath"); | |
37 | |
38 tether_network->set_type(chromeos::kTypeTether); | |
39 wifi_network->set_type(shill::kTypeWifi); | |
40 cellular_network->set_type(shill::kTypeCellular); | |
41 wifi_tether_network->set_type(shill::kTypeWifi); | |
42 | |
43 wifi_tether_network.get()->set_tether_guid("tetherNetworkGuid"); | |
44 } | |
45 | |
46 void TearDown() override { | |
47 PurgeNetworkIconCache(); | |
48 chromeos::NetworkHandler::Shutdown(); | |
49 test::AshTestBase::TearDown(); | |
50 } | |
51 | |
52 gfx::Image ImageForNetwork(chromeos::NetworkState* network) { | |
53 gfx::ImageSkia image_skia = GetImageForNetwork(network, icon_type); | |
54 return gfx::Image(image_skia); | |
55 } | |
56 | |
57 // The icon for a Tether network should be the same as one for a cellular | |
58 // network. The icon for a Tether network should be different from one for a | |
59 // Wi-Fi network. The icon for a cellular network should be different from one | |
60 // for a Wi-Fi network. The icon for a Tether network should be the same as | |
61 // one for a Wi-Fi network with an associated Tether guid. | |
62 void GetAndCompareImagesByNetworkType() { | |
63 gfx::Image tether_image = ImageForNetwork(tether_network.get()); | |
64 gfx::Image wifi_image = ImageForNetwork(wifi_network.get()); | |
65 gfx::Image cellular_image = ImageForNetwork(cellular_network.get()); | |
66 gfx::Image wifi_tether_image = ImageForNetwork(wifi_tether_network.get()); | |
67 | |
68 EXPECT_FALSE(gfx::test::AreImagesEqual(tether_image, wifi_image)); | |
69 EXPECT_FALSE(gfx::test::AreImagesEqual(cellular_image, wifi_image)); | |
70 EXPECT_TRUE(gfx::test::AreImagesEqual(tether_image, cellular_image)); | |
71 | |
72 EXPECT_TRUE(gfx::test::AreImagesEqual(tether_image, wifi_tether_image)); | |
73 } | |
74 | |
75 IconType icon_type = ICON_TYPE_TRAY; | |
76 | |
77 std::unique_ptr<chromeos::NetworkState> tether_network, wifi_network, | |
Kyle Horimoto
2017/05/03 01:53:33
Declare one per line.
lesliewatkins
2017/05/03 22:00:24
Done.
| |
78 cellular_network, wifi_tether_network; | |
Kyle Horimoto
2017/05/03 01:53:33
nit: For people unfamiliar with how Tether network
lesliewatkins
2017/05/03 22:00:24
Done.
| |
79 | |
80 private: | |
81 DISALLOW_COPY_AND_ASSIGN(NetworkIconTest); | |
82 }; | |
83 | |
84 // This tests that the correct icons are being generated for the correct | |
85 // networks by pairwise comparison of three different network types, verifying | |
86 // that the Tether and cellular icon are the same, Tether and Wi-Fi icons are | |
87 // different, and cellular and Wi-Fi icons are different. Additionaly, it | |
88 // verifies that the Tether network and Wi-Fi network with associated Tether | |
89 // guid are treated the same for purposes of icon display | |
90 TEST_F(NetworkIconTest, CompareImagesByNetworkType_NotVisible) { | |
91 GetAndCompareImagesByNetworkType(); | |
92 } | |
93 | |
94 TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connecting) { | |
95 tether_network->set_visible(true); | |
96 tether_network->set_connection_state(shill::kStateAssociation); | |
97 | |
98 wifi_network->set_visible(true); | |
99 wifi_network->set_connection_state(shill::kStateAssociation); | |
100 | |
101 cellular_network->set_visible(true); | |
102 cellular_network->set_connection_state(shill::kStateAssociation); | |
103 | |
104 wifi_tether_network->set_visible(true); | |
105 wifi_tether_network->set_connection_state(shill::kStateAssociation); | |
106 | |
107 GetAndCompareImagesByNetworkType(); | |
108 } | |
109 | |
110 TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connected) { | |
111 tether_network->set_visible(true); | |
112 tether_network->set_connection_state(shill::kStateOnline); | |
113 | |
114 wifi_network->set_visible(true); | |
115 wifi_network->set_connection_state(shill::kStateOnline); | |
116 | |
117 cellular_network->set_visible(true); | |
118 cellular_network->set_connection_state(shill::kStateOnline); | |
119 | |
120 wifi_tether_network->set_visible(true); | |
121 wifi_tether_network->set_connection_state(shill::kStateOnline); | |
122 | |
123 GetAndCompareImagesByNetworkType(); | |
124 } | |
125 | |
126 } // namespace network_icon | |
127 | |
128 } // namespace ash | |
OLD | NEW |