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 // This (somewhat indirectly) tests that the correct icons are being generated | |
Kyle Horimoto
2017/04/27 01:28:07
Move the comments to the individual tests. Someone
lesliewatkins
2017/04/28 21:30:42
Done.
| |
22 // for the correct networks by pairwise comparison of three different network | |
23 // types. | |
24 | |
25 // The icon for a tether network should be the same as one for a cellular | |
Ryan Hansberry
2017/04/27 16:32:27
nit: please refer to Tether networks in comments a
lesliewatkins
2017/04/28 21:30:42
Done.
| |
26 // network. The icon for a tether network should be different from one for a | |
27 // wifi network. The icon for a cellular network should be different from one | |
28 // for a wifi network. | |
29 class NetworkIconTest : public test::AshTestBase { | |
30 public: | |
31 NetworkIconTest() {} | |
32 ~NetworkIconTest() override {} | |
33 | |
34 IconType icon_type = ICON_TYPE_TRAY; | |
Kyle Horimoto
2017/04/27 01:28:07
Move instance field declarations below functions,
lesliewatkins
2017/04/28 21:30:42
Done.
| |
35 | |
36 std::unique_ptr<chromeos::NetworkState> tether_network, wifi_network, | |
37 cellular_network; | |
38 void SetUp() override { | |
39 this->test::AshTestBase::SetUp(); | |
Kyle Horimoto
2017/04/27 01:28:07
You don't need "this->"; same in TearDown().
lesliewatkins
2017/04/28 21:30:42
Done.
| |
40 chromeos::NetworkHandler::Initialize(); | |
41 } | |
42 | |
43 void SetNetworkType(chromeos::NetworkState* network, | |
44 const std::string& type) { | |
45 network->set_type(type); | |
46 } | |
47 | |
48 void PrintImage(gfx::Image image, int i = 0) { | |
Kyle Horimoto
2017/04/27 01:28:07
Remove this function - it's unused.
lesliewatkins
2017/04/28 21:30:42
Done.
| |
49 image.AsImageSkia().EnsureRepsForSupportedScales(); | |
50 SkBitmap bitmap = image.AsImageSkia().image_reps()[i].sk_bitmap(); | |
51 for (int r = 0; r < bitmap.height(); ++r) { | |
52 for (int c = 0; c < bitmap.width(); ++c) { | |
53 std::cout << (bitmap.getColor(r, c) > 0 ? "0" : ".") << "\t"; | |
54 } | |
55 std::cout << std::endl; | |
56 } | |
57 } | |
58 | |
59 void TearDown() override { | |
60 chromeos::NetworkHandler::Shutdown(); | |
61 this->test::AshTestBase::TearDown(); | |
62 } | |
63 | |
64 private: | |
65 DISALLOW_COPY_AND_ASSIGN(NetworkIconTest); | |
66 }; | |
67 | |
68 TEST_F(NetworkIconTest, NetworkNotVisible) { | |
Kyle Horimoto
2017/04/27 01:28:07
nit: Be more descriptive in your test names. How a
lesliewatkins
2017/04/28 21:30:43
Done.
| |
69 std::unique_ptr<chromeos::NetworkState> tether_network = | |
Kyle Horimoto
2017/04/27 01:28:07
You initialize these fields in every test. Initial
lesliewatkins
2017/04/28 21:30:42
I actually need to give each of them a unique netw
Kyle Horimoto
2017/04/28 22:07:28
See my comment below regarding PurgeNetworkIconCac
Kyle Horimoto
2017/05/01 17:09:26
Still not addressed.
lesliewatkins
2017/05/03 01:23:23
I'm not sure what the path would be for the Tether
lesliewatkins
2017/05/03 01:23:23
Done.
Kyle Horimoto
2017/05/03 01:53:33
Sure, that's fine. Really, we pass the GUID as the
| |
70 base::MakeUnique<chromeos::NetworkState>("tether"); | |
Kyle Horimoto
2017/04/27 01:28:07
Also, the service path which you pass to the const
lesliewatkins
2017/04/28 21:30:42
It does, because the path is what's used in the Ic
Kyle Horimoto
2017/04/28 22:07:28
Call PurgeNetworkIconCache() in Teardown() to avoi
Kyle Horimoto
2017/05/01 17:09:26
Still not addressed.
lesliewatkins
2017/05/03 01:23:23
Done.
| |
71 SetNetworkType(tether_network.get(), chromeos::kTypeTether); | |
72 gfx::ImageSkia tether_image_skia = | |
73 GetImageForNetwork(tether_network.get(), icon_type); | |
74 gfx::Image tether_image(tether_image_skia); | |
75 | |
76 std::unique_ptr<chromeos::NetworkState> wifi_network = | |
77 base::MakeUnique<chromeos::NetworkState>("wifi"); | |
78 SetNetworkType(wifi_network.get(), shill::kTypeWifi); | |
79 gfx::ImageSkia wifi_image_skia = | |
80 GetImageForNetwork(wifi_network.get(), icon_type); | |
81 gfx::Image wifi_image(wifi_image_skia); | |
82 | |
83 std::unique_ptr<chromeos::NetworkState> cellular_network = | |
84 base::MakeUnique<chromeos::NetworkState>("cellular"); | |
85 SetNetworkType(cellular_network.get(), shill::kTypeCellular); | |
86 gfx::ImageSkia cellular_image_skia = | |
87 GetImageForNetwork(cellular_network.get(), icon_type); | |
88 gfx::Image cellular_image(cellular_image_skia); | |
89 | |
90 EXPECT_FALSE(gfx::test::AreImagesEqual(tether_image, wifi_image)); | |
Kyle Horimoto
2017/04/27 01:28:07
In each test, after you set properties on the netw
lesliewatkins
2017/04/28 21:30:42
Done.
| |
91 EXPECT_FALSE(gfx::test::AreImagesEqual(cellular_image, wifi_image)); | |
92 EXPECT_TRUE(gfx::test::AreImagesEqual(tether_image, cellular_image)); | |
93 } | |
94 | |
95 TEST_F(NetworkIconTest, NetworkConnecting) { | |
96 std::unique_ptr<chromeos::NetworkState> tether_network = | |
97 base::MakeUnique<chromeos::NetworkState>("tether_connecting"); | |
98 tether_network->set_visible(true); | |
99 tether_network->set_connection_state(shill::kStateAssociation); | |
100 SetNetworkType(tether_network.get(), chromeos::kTypeTether); | |
101 gfx::ImageSkia tether_image_skia = | |
102 GetImageForNetwork(tether_network.get(), icon_type); | |
103 gfx::Image tether_image(tether_image_skia); | |
104 | |
105 std::unique_ptr<chromeos::NetworkState> wifi_network = | |
106 base::MakeUnique<chromeos::NetworkState>("wifi_connecting"); | |
107 wifi_network->set_visible(true); | |
108 wifi_network->set_connection_state(shill::kStateAssociation); | |
109 SetNetworkType(wifi_network.get(), shill::kTypeWifi); | |
110 gfx::ImageSkia wifi_image_skia = | |
111 GetImageForNetwork(wifi_network.get(), icon_type); | |
112 gfx::Image wifi_image(wifi_image_skia); | |
113 | |
114 std::unique_ptr<chromeos::NetworkState> cellular_network = | |
115 base::MakeUnique<chromeos::NetworkState>("cellular_connecting"); | |
116 cellular_network->set_visible(true); | |
117 cellular_network->set_connection_state(shill::kStateAssociation); | |
118 SetNetworkType(cellular_network.get(), shill::kTypeCellular); | |
119 gfx::ImageSkia cellular_image_skia = | |
120 GetImageForNetwork(cellular_network.get(), icon_type); | |
121 gfx::Image cellular_image(cellular_image_skia); | |
122 | |
123 EXPECT_FALSE(gfx::test::AreImagesEqual(tether_image, wifi_image)); | |
124 EXPECT_FALSE(gfx::test::AreImagesEqual(cellular_image, wifi_image)); | |
125 EXPECT_TRUE(gfx::test::AreImagesEqual(tether_image, cellular_image)); | |
126 } | |
127 | |
128 TEST_F(NetworkIconTest, NetworkConnected) { | |
129 std::unique_ptr<chromeos::NetworkState> tether_network = | |
130 base::MakeUnique<chromeos::NetworkState>("tether_connected"); | |
131 tether_network->set_visible(true); | |
132 tether_network->set_connection_state(shill::kStateOnline); | |
133 SetNetworkType(tether_network.get(), chromeos::kTypeTether); | |
134 gfx::ImageSkia tether_image_skia = | |
135 GetImageForNetwork(tether_network.get(), icon_type); | |
136 gfx::Image tether_image(tether_image_skia); | |
137 | |
138 std::unique_ptr<chromeos::NetworkState> wifi_network = | |
139 base::MakeUnique<chromeos::NetworkState>("wifi_connected"); | |
140 wifi_network->set_visible(true); | |
141 wifi_network->set_connection_state(shill::kStateOnline); | |
142 SetNetworkType(wifi_network.get(), shill::kTypeWifi); | |
143 gfx::ImageSkia wifi_image_skia = | |
144 GetImageForNetwork(wifi_network.get(), icon_type); | |
145 gfx::Image wifi_image(wifi_image_skia); | |
146 | |
147 std::unique_ptr<chromeos::NetworkState> cellular_network = | |
148 base::MakeUnique<chromeos::NetworkState>("cellular_connected"); | |
149 cellular_network->set_visible(true); | |
150 cellular_network->set_connection_state(shill::kStateOnline); | |
151 SetNetworkType(cellular_network.get(), shill::kTypeCellular); | |
152 gfx::ImageSkia cellular_image_skia = | |
153 GetImageForNetwork(cellular_network.get(), icon_type); | |
154 gfx::Image cellular_image(cellular_image_skia); | |
155 | |
156 EXPECT_FALSE(gfx::test::AreImagesEqual(tether_image, wifi_image)); | |
157 EXPECT_FALSE(gfx::test::AreImagesEqual(cellular_image, wifi_image)); | |
158 EXPECT_TRUE(gfx::test::AreImagesEqual(tether_image, cellular_image)); | |
159 } | |
160 | |
161 } // namespace network_icon | |
Ryan Hansberry
2017/04/27 16:32:26
there should be a newline between namespace closin
lesliewatkins
2017/04/28 21:30:43
Done.
| |
162 } // namespace ash | |
OLD | NEW |