Index: ash/system/network/network_icon_unittest.cc |
diff --git a/ash/system/network/network_icon_unittest.cc b/ash/system/network/network_icon_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8717355f58f5dbf0038ba404bb21b4e1c88fda8b |
--- /dev/null |
+++ b/ash/system/network/network_icon_unittest.cc |
@@ -0,0 +1,128 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/system/network/network_icon.h" |
+ |
+#include "ash/test/ash_test_base.h" |
+#include "base/logging.h" |
+#include "base/memory/ptr_util.h" |
+#include "chromeos/network/network_handler.h" |
+#include "chromeos/network/network_state.h" |
+#include "chromeos/network/tether_constants.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
+#include "ui/gfx/image/image_unittest_util.h" |
+ |
+namespace ash { |
+ |
+namespace network_icon { |
+ |
+class NetworkIconTest : public test::AshTestBase { |
+ public: |
+ NetworkIconTest() {} |
+ ~NetworkIconTest() override {} |
+ |
+ void SetUp() override { |
+ test::AshTestBase::SetUp(); |
+ chromeos::NetworkHandler::Initialize(); |
+ |
+ 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.
|
+ base::MakeUnique<chromeos::NetworkState>("tetherNetworkPath"); |
+ wifi_network = base::MakeUnique<chromeos::NetworkState>("wifiServicePath"); |
+ cellular_network = |
+ base::MakeUnique<chromeos::NetworkState>("cellularServicePath"); |
+ wifi_tether_network = |
+ base::MakeUnique<chromeos::NetworkState>("wifiTetherServicePath"); |
+ |
+ tether_network->set_type(chromeos::kTypeTether); |
+ wifi_network->set_type(shill::kTypeWifi); |
+ cellular_network->set_type(shill::kTypeCellular); |
+ wifi_tether_network->set_type(shill::kTypeWifi); |
+ |
+ wifi_tether_network.get()->set_tether_guid("tetherNetworkGuid"); |
+ } |
+ |
+ void TearDown() override { |
+ PurgeNetworkIconCache(); |
+ chromeos::NetworkHandler::Shutdown(); |
+ test::AshTestBase::TearDown(); |
+ } |
+ |
+ gfx::Image ImageForNetwork(chromeos::NetworkState* network) { |
+ gfx::ImageSkia image_skia = GetImageForNetwork(network, icon_type); |
+ return gfx::Image(image_skia); |
+ } |
+ |
+ // The icon for a Tether network should be the same as one for a cellular |
+ // network. The icon for a Tether network should be different from one for a |
+ // Wi-Fi network. The icon for a cellular network should be different from one |
+ // for a Wi-Fi network. The icon for a Tether network should be the same as |
+ // one for a Wi-Fi network with an associated Tether guid. |
+ void GetAndCompareImagesByNetworkType() { |
+ gfx::Image tether_image = ImageForNetwork(tether_network.get()); |
+ gfx::Image wifi_image = ImageForNetwork(wifi_network.get()); |
+ gfx::Image cellular_image = ImageForNetwork(cellular_network.get()); |
+ gfx::Image wifi_tether_image = ImageForNetwork(wifi_tether_network.get()); |
+ |
+ EXPECT_FALSE(gfx::test::AreImagesEqual(tether_image, wifi_image)); |
+ EXPECT_FALSE(gfx::test::AreImagesEqual(cellular_image, wifi_image)); |
+ EXPECT_TRUE(gfx::test::AreImagesEqual(tether_image, cellular_image)); |
+ |
+ EXPECT_TRUE(gfx::test::AreImagesEqual(tether_image, wifi_tether_image)); |
+ } |
+ |
+ IconType icon_type = ICON_TYPE_TRAY; |
+ |
+ 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.
|
+ 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.
|
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(NetworkIconTest); |
+}; |
+ |
+// This tests that the correct icons are being generated for the correct |
+// networks by pairwise comparison of three different network types, verifying |
+// that the Tether and cellular icon are the same, Tether and Wi-Fi icons are |
+// different, and cellular and Wi-Fi icons are different. Additionaly, it |
+// verifies that the Tether network and Wi-Fi network with associated Tether |
+// guid are treated the same for purposes of icon display |
+TEST_F(NetworkIconTest, CompareImagesByNetworkType_NotVisible) { |
+ GetAndCompareImagesByNetworkType(); |
+} |
+ |
+TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connecting) { |
+ tether_network->set_visible(true); |
+ tether_network->set_connection_state(shill::kStateAssociation); |
+ |
+ wifi_network->set_visible(true); |
+ wifi_network->set_connection_state(shill::kStateAssociation); |
+ |
+ cellular_network->set_visible(true); |
+ cellular_network->set_connection_state(shill::kStateAssociation); |
+ |
+ wifi_tether_network->set_visible(true); |
+ wifi_tether_network->set_connection_state(shill::kStateAssociation); |
+ |
+ GetAndCompareImagesByNetworkType(); |
+} |
+ |
+TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connected) { |
+ tether_network->set_visible(true); |
+ tether_network->set_connection_state(shill::kStateOnline); |
+ |
+ wifi_network->set_visible(true); |
+ wifi_network->set_connection_state(shill::kStateOnline); |
+ |
+ cellular_network->set_visible(true); |
+ cellular_network->set_connection_state(shill::kStateOnline); |
+ |
+ wifi_tether_network->set_visible(true); |
+ wifi_tether_network->set_connection_state(shill::kStateOnline); |
+ |
+ GetAndCompareImagesByNetworkType(); |
+} |
+ |
+} // namespace network_icon |
+ |
+} // namespace ash |