Chromium Code Reviews| 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 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 (somewhat indirectly) tests that the correct icons are being generated | |
|
Kyle Horimoto
2017/04/28 22:07:28
If something is indirect/not obvious, explain it.
lesliewatkins
2017/04/29 00:57:54
Done.
| |
| 72 // for the correct networks by pairwise comparison of three different network | |
| 73 // types. | |
| 74 TEST_F(NetworkIconTest, CompareImagesByNetworkType_NotVisible) { | |
| 75 std::unique_ptr<chromeos::NetworkState> tether_network = | |
| 76 base::MakeUnique<chromeos::NetworkState>("tether"); | |
| 77 SetNetworkType(tether_network.get(), chromeos::kTypeTether); | |
| 78 | |
| 79 std::unique_ptr<chromeos::NetworkState> wifi_network = | |
| 80 base::MakeUnique<chromeos::NetworkState>("wifi"); | |
| 81 SetNetworkType(wifi_network.get(), shill::kTypeWifi); | |
| 82 | |
| 83 std::unique_ptr<chromeos::NetworkState> cellular_network = | |
| 84 base::MakeUnique<chromeos::NetworkState>("cellular"); | |
| 85 SetNetworkType(cellular_network.get(), shill::kTypeCellular); | |
| 86 | |
| 87 GetAndCompareImagesByNetworkType(tether_network.get(), wifi_network.get(), | |
| 88 cellular_network.get()); | |
| 89 } | |
| 90 | |
| 91 TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connecting) { | |
| 92 std::unique_ptr<chromeos::NetworkState> tether_network = | |
| 93 base::MakeUnique<chromeos::NetworkState>("tether_connecting"); | |
| 94 tether_network->set_visible(true); | |
| 95 tether_network->set_connection_state(shill::kStateAssociation); | |
| 96 SetNetworkType(tether_network.get(), chromeos::kTypeTether); | |
| 97 | |
| 98 std::unique_ptr<chromeos::NetworkState> wifi_network = | |
| 99 base::MakeUnique<chromeos::NetworkState>("wifi_connecting"); | |
| 100 wifi_network->set_visible(true); | |
| 101 wifi_network->set_connection_state(shill::kStateAssociation); | |
| 102 SetNetworkType(wifi_network.get(), shill::kTypeWifi); | |
| 103 | |
| 104 std::unique_ptr<chromeos::NetworkState> cellular_network = | |
| 105 base::MakeUnique<chromeos::NetworkState>("cellular_connecting"); | |
| 106 cellular_network->set_visible(true); | |
| 107 cellular_network->set_connection_state(shill::kStateAssociation); | |
| 108 SetNetworkType(cellular_network.get(), shill::kTypeCellular); | |
| 109 | |
| 110 GetAndCompareImagesByNetworkType(tether_network.get(), wifi_network.get(), | |
| 111 cellular_network.get()); | |
| 112 } | |
| 113 | |
| 114 TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connected) { | |
| 115 std::unique_ptr<chromeos::NetworkState> tether_network = | |
| 116 base::MakeUnique<chromeos::NetworkState>("tether_connected"); | |
| 117 tether_network->set_visible(true); | |
| 118 tether_network->set_connection_state(shill::kStateOnline); | |
| 119 SetNetworkType(tether_network.get(), chromeos::kTypeTether); | |
| 120 | |
| 121 std::unique_ptr<chromeos::NetworkState> wifi_network = | |
| 122 base::MakeUnique<chromeos::NetworkState>("wifi_connected"); | |
| 123 wifi_network->set_visible(true); | |
| 124 wifi_network->set_connection_state(shill::kStateOnline); | |
| 125 SetNetworkType(wifi_network.get(), shill::kTypeWifi); | |
| 126 | |
| 127 std::unique_ptr<chromeos::NetworkState> cellular_network = | |
| 128 base::MakeUnique<chromeos::NetworkState>("cellular_connected"); | |
| 129 cellular_network->set_visible(true); | |
| 130 cellular_network->set_connection_state(shill::kStateOnline); | |
| 131 SetNetworkType(cellular_network.get(), shill::kTypeCellular); | |
| 132 | |
| 133 GetAndCompareImagesByNetworkType(tether_network.get(), wifi_network.get(), | |
| 134 cellular_network.get()); | |
| 135 } | |
| 136 | |
| 137 } // namespace network_icon | |
| 138 | |
| 139 } // namespace ash | |
| OLD | NEW |