Chromium Code Reviews| 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..3bd0d1b8cc860153fe331e4941e32bb3cc100758 |
| --- /dev/null |
| +++ b/ash/system/network/network_icon_unittest.cc |
| @@ -0,0 +1,139 @@ |
| +// 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 {} |
| + |
| + std::unique_ptr<chromeos::NetworkState> tether_network, wifi_network, |
| + cellular_network; |
| + void SetUp() override { |
| + test::AshTestBase::SetUp(); |
| + chromeos::NetworkHandler::Initialize(); |
| + } |
| + |
| + void SetNetworkType(chromeos::NetworkState* network, |
| + const std::string& type) { |
| + network->set_type(type); |
| + } |
| + |
| + void TearDown() override { |
| + 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 |
| + // wifi network. The icon for a cellular network should be different from one |
| + // for a wifi network. |
| + void GetAndCompareImagesByNetworkType( |
| + chromeos::NetworkState* tether_network, |
| + chromeos::NetworkState* wifi_network, |
| + chromeos::NetworkState* cellular_network) { |
| + gfx::Image tether_image = ImageForNetwork(tether_network); |
| + gfx::Image wifi_image = ImageForNetwork(wifi_network); |
| + gfx::Image cellular_image = ImageForNetwork(cellular_network); |
| + |
| + 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)); |
| + } |
| + |
| + IconType icon_type = ICON_TYPE_TRAY; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(NetworkIconTest); |
| +}; |
| + |
| +// 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.
|
| +// for the correct networks by pairwise comparison of three different network |
| +// types. |
| +TEST_F(NetworkIconTest, CompareImagesByNetworkType_NotVisible) { |
| + std::unique_ptr<chromeos::NetworkState> tether_network = |
| + base::MakeUnique<chromeos::NetworkState>("tether"); |
| + SetNetworkType(tether_network.get(), chromeos::kTypeTether); |
| + |
| + std::unique_ptr<chromeos::NetworkState> wifi_network = |
| + base::MakeUnique<chromeos::NetworkState>("wifi"); |
| + SetNetworkType(wifi_network.get(), shill::kTypeWifi); |
| + |
| + std::unique_ptr<chromeos::NetworkState> cellular_network = |
| + base::MakeUnique<chromeos::NetworkState>("cellular"); |
| + SetNetworkType(cellular_network.get(), shill::kTypeCellular); |
| + |
| + GetAndCompareImagesByNetworkType(tether_network.get(), wifi_network.get(), |
| + cellular_network.get()); |
| +} |
| + |
| +TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connecting) { |
| + std::unique_ptr<chromeos::NetworkState> tether_network = |
| + base::MakeUnique<chromeos::NetworkState>("tether_connecting"); |
| + tether_network->set_visible(true); |
| + tether_network->set_connection_state(shill::kStateAssociation); |
| + SetNetworkType(tether_network.get(), chromeos::kTypeTether); |
| + |
| + std::unique_ptr<chromeos::NetworkState> wifi_network = |
| + base::MakeUnique<chromeos::NetworkState>("wifi_connecting"); |
| + wifi_network->set_visible(true); |
| + wifi_network->set_connection_state(shill::kStateAssociation); |
| + SetNetworkType(wifi_network.get(), shill::kTypeWifi); |
| + |
| + std::unique_ptr<chromeos::NetworkState> cellular_network = |
| + base::MakeUnique<chromeos::NetworkState>("cellular_connecting"); |
| + cellular_network->set_visible(true); |
| + cellular_network->set_connection_state(shill::kStateAssociation); |
| + SetNetworkType(cellular_network.get(), shill::kTypeCellular); |
| + |
| + GetAndCompareImagesByNetworkType(tether_network.get(), wifi_network.get(), |
| + cellular_network.get()); |
| +} |
| + |
| +TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connected) { |
| + std::unique_ptr<chromeos::NetworkState> tether_network = |
| + base::MakeUnique<chromeos::NetworkState>("tether_connected"); |
| + tether_network->set_visible(true); |
| + tether_network->set_connection_state(shill::kStateOnline); |
| + SetNetworkType(tether_network.get(), chromeos::kTypeTether); |
| + |
| + std::unique_ptr<chromeos::NetworkState> wifi_network = |
| + base::MakeUnique<chromeos::NetworkState>("wifi_connected"); |
| + wifi_network->set_visible(true); |
| + wifi_network->set_connection_state(shill::kStateOnline); |
| + SetNetworkType(wifi_network.get(), shill::kTypeWifi); |
| + |
| + std::unique_ptr<chromeos::NetworkState> cellular_network = |
| + base::MakeUnique<chromeos::NetworkState>("cellular_connected"); |
| + cellular_network->set_visible(true); |
| + cellular_network->set_connection_state(shill::kStateOnline); |
| + SetNetworkType(cellular_network.get(), shill::kTypeCellular); |
| + |
| + GetAndCompareImagesByNetworkType(tether_network.get(), wifi_network.get(), |
| + cellular_network.get()); |
| +} |
| + |
| +} // namespace network_icon |
| + |
| +} // namespace ash |