1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
|
// Copyright 2017 The Chromium Authors
// 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 <memory>
#include <set>
#include "ash/public/cpp/network_config_service.h"
#include "ash/public/cpp/style/dark_light_mode_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/color_util.h"
#include "ash/system/network/active_network_icon.h"
#include "ash/system/network/tray_network_state_model.h"
#include "ash/test/ash_test_base.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "chromeos/ash/components/network/network_state_handler.h"
#include "chromeos/ash/components/network/network_state_test_helper.h"
#include "chromeos/ash/components/network/tether_constants.h"
#include "chromeos/ash/services/network_config/public/cpp/cros_network_config_test_helper.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/views/controls/image_view.h"
// This tests both the helper functions in network_icon, and ActiveNetworkIcon
// which is a primary consumer of the helper functions.
namespace ash::network_icon {
using chromeos::network_config::mojom::ConnectionStateType;
using chromeos::network_config::mojom::NetworkStateProperties;
using chromeos::network_config::mojom::NetworkStatePropertiesPtr;
using chromeos::network_config::mojom::NetworkType;
class NetworkIconTest : public AshTestBase {
public:
NetworkIconTest() = default;
NetworkIconTest(const NetworkIconTest&) = delete;
NetworkIconTest& operator=(const NetworkIconTest&) = delete;
~NetworkIconTest() override = default;
void SetUp() override {
AshTestBase::SetUp();
SetUpDefaultNetworkState();
network_state_model_ = std::make_unique<TrayNetworkStateModel>();
active_network_icon_ =
std::make_unique<ActiveNetworkIcon>(network_state_model_.get());
}
void TearDown() override {
active_network_icon_.reset();
PurgeNetworkIconCache(std::set<std::string>());
AshTestBase::TearDown();
}
const ui::ColorProvider* GetColorProvider() {
// TODO(b/279177422): Replace with a stable ColorProvider
return ColorUtil::GetColorProviderSourceForWindow(
Shell::GetPrimaryRootWindow())
->GetColorProvider();
}
std::string ConfigureService(const std::string& shill_json_string) {
return helper().ConfigureService(shill_json_string);
}
void SetServiceProperty(const std::string& service_path,
const std::string& key,
const base::Value& value) {
helper().SetServiceProperty(service_path, key, value);
}
void SetUpDefaultNetworkState() {
// NetworkStateTestHelper default has a wifi device only and no services.
helper().device_test()->AddDevice("/device/stub_cellular_device",
shill::kTypeCellular,
"stub_cellular_device");
base::RunLoop().RunUntilIdle();
wifi1_path_ = ConfigureService(
R"({"GUID": "wifi1_guid", "Type": "wifi", "State": "idle"})");
ASSERT_FALSE(wifi1_path_.empty());
wifi2_path_ = ConfigureService(
R"({"GUID": "wifi2_guid", "Type": "wifi", "State": "idle"})");
ASSERT_FALSE(wifi2_path_.empty());
cellular_path_ = ConfigureService(
R"({"GUID": "cellular_guid", "Type": "cellular", "Technology": "LTE",
"State": "idle"})");
ASSERT_FALSE(cellular_path_.empty());
}
NetworkStatePropertiesPtr CreateStandaloneNetworkProperties(
const std::string& id,
NetworkType type,
ConnectionStateType connection_state,
int signal_strength) {
return network_config_helper_.CreateStandaloneNetworkProperties(
id, type, connection_state, signal_strength);
}
gfx::Image GetImageForNonVirtualNetwork(const NetworkStateProperties* network,
bool badge_vpn) {
return gfx::Image(network_icon::GetImageForNonVirtualNetwork(
GetColorProvider(), network, icon_type_, badge_vpn));
}
gfx::Image ImageForNetwork(const NetworkStateProperties* network) {
return GetImageForNonVirtualNetwork(network, false /* show_vpn_badge */);
}
gfx::ImageSkia GetDefaultNetworkImage(IconType icon_type, bool* animating) {
return active_network_icon_->GetImage(GetColorProvider(),
ActiveNetworkIcon::Type::kSingle,
icon_type, animating);
}
// 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(
const NetworkStateProperties* wifi_network,
const NetworkStateProperties* cellular_network,
const NetworkStateProperties* tether_network) {
ASSERT_EQ(wifi_network->type, NetworkType::kWiFi);
gfx::Image wifi_image = ImageForNetwork(wifi_network);
ASSERT_EQ(cellular_network->type, NetworkType::kCellular);
gfx::Image cellular_image = ImageForNetwork(cellular_network);
ASSERT_EQ(tether_network->type, NetworkType::kTether);
gfx::Image tether_image = ImageForNetwork(tether_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));
}
void SetCellularUnavailable() {
helper().manager_test()->RemoveTechnology(shill::kTypeCellular);
base::RunLoop().RunUntilIdle();
ASSERT_EQ(NetworkStateHandler::TechnologyState::TECHNOLOGY_UNAVAILABLE,
helper().network_state_handler()->GetTechnologyState(
NetworkTypePattern::Cellular()));
}
NetworkStateTestHelper& helper() {
return network_config_helper_.network_state_helper();
}
const std::string& wifi1_path() const { return wifi1_path_; }
const std::string& wifi2_path() const { return wifi2_path_; }
const std::string& cellular_path() const { return cellular_path_; }
IconType icon_type_ = ICON_TYPE_TRAY_REGULAR;
private:
network_config::CrosNetworkConfigTestHelper network_config_helper_;
std::unique_ptr<TrayNetworkStateModel> network_state_model_;
std::unique_ptr<ActiveNetworkIcon> active_network_icon_;
// Preconfigured service paths:
std::string wifi1_path_;
std::string wifi2_path_;
std::string cellular_path_;
};
// 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. Additionally, 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) {
NetworkStatePropertiesPtr wifi_network = CreateStandaloneNetworkProperties(
"wifi", NetworkType::kWiFi, ConnectionStateType::kNotConnected, 50);
NetworkStatePropertiesPtr cellular_network =
CreateStandaloneNetworkProperties("cellular", NetworkType::kCellular,
ConnectionStateType::kNotConnected, 50);
NetworkStatePropertiesPtr tether_network = CreateStandaloneNetworkProperties(
"tether", NetworkType::kTether, ConnectionStateType::kNotConnected, 50);
GetAndCompareImagesByNetworkType(wifi_network.get(), cellular_network.get(),
tether_network.get());
}
TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connecting) {
NetworkStatePropertiesPtr wifi_network = CreateStandaloneNetworkProperties(
"wifi", NetworkType::kWiFi, ConnectionStateType::kConnecting, 50);
NetworkStatePropertiesPtr cellular_network =
CreateStandaloneNetworkProperties("cellular", NetworkType::kCellular,
ConnectionStateType::kConnecting, 50);
NetworkStatePropertiesPtr tether_network = CreateStandaloneNetworkProperties(
"tether", NetworkType::kTether, ConnectionStateType::kConnecting, 50);
GetAndCompareImagesByNetworkType(wifi_network.get(), cellular_network.get(),
tether_network.get());
}
TEST_F(NetworkIconTest, CompareImagesByNetworkType_Connected) {
NetworkStatePropertiesPtr wifi_network = CreateStandaloneNetworkProperties(
"wifi", NetworkType::kWiFi, ConnectionStateType::kOnline, 50);
NetworkStatePropertiesPtr cellular_network =
CreateStandaloneNetworkProperties("cellular", NetworkType::kCellular,
ConnectionStateType::kOnline, 50);
NetworkStatePropertiesPtr tether_network = CreateStandaloneNetworkProperties(
"tether", NetworkType::kTether, ConnectionStateType::kOnline, 50);
GetAndCompareImagesByNetworkType(wifi_network.get(), cellular_network.get(),
tether_network.get());
}
TEST_F(NetworkIconTest, NetworkSignalStrength) {
// Signal strength is divided into four categories: none, weak, medium and
// strong. They are meant to match the number of sections in the wifi icon.
// The wifi icon currently has four levels; signals [0, 100] are mapped to [1,
// 4]. There are only three signal strengths so icons that were mapped to 2
// are also considered weak.
EXPECT_EQ(SignalStrength::NONE, GetSignalStrength(0));
EXPECT_EQ(SignalStrength::WEAK, GetSignalStrength(50));
EXPECT_EQ(SignalStrength::MEDIUM, GetSignalStrength(51));
EXPECT_EQ(SignalStrength::MEDIUM, GetSignalStrength(75));
EXPECT_EQ(SignalStrength::STRONG, GetSignalStrength(76));
EXPECT_EQ(SignalStrength::STRONG, GetSignalStrength(100));
}
TEST_F(NetworkIconTest, DefaultImageWifiConnected) {
// Set the Wifi service as connected.
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(45));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
NetworkStatePropertiesPtr reference_network =
CreateStandaloneNetworkProperties("reference", NetworkType::kWiFi,
ConnectionStateType::kOnline, 45);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network.get())));
}
TEST_F(NetworkIconTest, DefaultImageWifiConnecting) {
// Set the Wifi service as connected.
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(45));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateAssociation));
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_TRUE(animating);
NetworkStatePropertiesPtr reference_network =
CreateStandaloneNetworkProperties("reference", NetworkType::kWiFi,
ConnectionStateType::kConnecting, 45);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network.get())));
}
TEST_F(NetworkIconTest, ConnectingIconChangesInDarkMode) {
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateAssociation));
DarkLightModeController::Get()->SetDarkModeEnabledForTest(true);
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_TRUE(animating);
DarkLightModeController::Get()->SetDarkModeEnabledForTest(false);
gfx::ImageSkia light_mode_image =
GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(light_mode_image.isNull());
EXPECT_TRUE(animating);
EXPECT_FALSE(gfx::test::AreImagesEqual(gfx::Image(default_image),
gfx::Image(light_mode_image)));
}
// Tests that the default network image is a cellular network icon when cellular
// network is the default network, even if a wifi network is connected.
// Generally, shill will prefer wifi over cellular networks when both are
// connected, but that is not always the case. For example, if the connected
// wifi service has no Internet connectivity, cellular service will be selected
// as default.
TEST_F(NetworkIconTest, DefaultImageCellularDefaultWithWifiConnected) {
// Set both wifi and cellular networks in a connected state, but with wifi not
// online - this should prompt fake shill manager implementation to prefer
// cellular network over wifi.
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(45));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateReady));
SetServiceProperty(cellular_path(), shill::kSignalStrengthProperty,
base::Value(65));
SetServiceProperty(cellular_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
NetworkStatePropertiesPtr reference_network =
CreateStandaloneNetworkProperties("reference", NetworkType::kCellular,
ConnectionStateType::kOnline, 65);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network.get())));
}
// Tests the use case where the default network starts reconnecting while
// another network is connected.
TEST_F(NetworkIconTest, DefaultImageReconnectingWifiWithCellularConnected) {
// First connect both wifi and cellular network (with wifi as default).
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(45));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
SetServiceProperty(cellular_path(), shill::kSignalStrengthProperty,
base::Value(65));
SetServiceProperty(cellular_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
// Start reconnecting wifi network.
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateAssociation));
// Verify that the default network is connecting icon for the initial default
// network (even though the default network as reported by shill actually
// changed).
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_TRUE(animating);
NetworkStatePropertiesPtr reference_network_1 =
CreateStandaloneNetworkProperties("reference1", NetworkType::kWiFi,
ConnectionStateType::kConnecting, 45);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network_1.get())));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateReady));
// At this point the wifi network is not connecting, but is not yet default -
// the default network icon should have image for the cellular network (which
// is the default one at this point).
// TODO(tbarzic): This creates a unoptimal behavior in the UI where cellular
// icon could flash between wifi connecting and connected icons - this
// should be fixed, for example by not showing connecting icon when
// reconnecting a network if another network is connected.
NetworkStatePropertiesPtr reference_network_2 =
CreateStandaloneNetworkProperties("reference2", NetworkType::kCellular,
ConnectionStateType::kOnline, 65);
default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network_2.get())));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
// The wifi network is online, and thus default - the default network icon
// should display the wifi network's associated image again.
NetworkStatePropertiesPtr reference_network_3 =
CreateStandaloneNetworkProperties("reference3", NetworkType::kWiFi,
ConnectionStateType::kOnline, 45);
default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network_3.get())));
}
TEST_F(NetworkIconTest, DefaultImageDisconnectWifiWithCellularConnected) {
// First connect both wifi and cellular network (with wifi as default).
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(45));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
SetServiceProperty(cellular_path(), shill::kSignalStrengthProperty,
base::Value(65));
SetServiceProperty(cellular_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
// Disconnect wifi network, and verify the default icon changes to cellular.
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateIdle));
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
NetworkStatePropertiesPtr reference_network =
CreateStandaloneNetworkProperties("reference", NetworkType::kCellular,
ConnectionStateType::kOnline, 65);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network.get())));
}
// Tests that the default network image remains the same if non-default network
// reconnects.
TEST_F(NetworkIconTest, DefaultImageWhileNonDefaultNetworkReconnecting) {
// First connect both wifi and cellular network (with wifi as default).
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(45));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
SetServiceProperty(cellular_path(), shill::kSignalStrengthProperty,
base::Value(65));
SetServiceProperty(cellular_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
// Start reconnecting the non-default, cellular network.
SetServiceProperty(cellular_path(), shill::kStateProperty,
base::Value(shill::kStateAssociation));
// Currently, a connecting icon is used as default network icon even if
// another network connected and used as default.
// TODO(tbarzic): Consider changing network icon logic to use a connected
// network icon if a network is connected while a network is reconnecting.
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_TRUE(animating);
NetworkStatePropertiesPtr reference_network_1 =
CreateStandaloneNetworkProperties("reference1", NetworkType::kCellular,
ConnectionStateType::kConnecting, 65);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network_1.get())));
// Move the cellular network to connected, but not yet online state - the
// default network image changes back to the default network.
SetServiceProperty(cellular_path(), shill::kStateProperty,
base::Value(shill::kStateReady));
default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
NetworkStatePropertiesPtr reference_network_2 =
CreateStandaloneNetworkProperties("reference2", NetworkType::kWiFi,
ConnectionStateType::kOnline, 45);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network_2.get())));
// Move the cellular network to online state - the default network image
// should remain the same.
SetServiceProperty(cellular_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network_2.get())));
}
// Tests that the default network image shows a cellular network icon if
// cellular network is connected while wifi is connecting.
TEST_F(NetworkIconTest, DefaultImageConnectingToWifiWhileCellularConnected) {
// Connect cellular network, and set the wifi as connecting.
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(45));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateAssociation));
SetServiceProperty(cellular_path(), shill::kSignalStrengthProperty,
base::Value(65));
SetServiceProperty(cellular_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
NetworkStatePropertiesPtr reference_network =
CreateStandaloneNetworkProperties("reference", NetworkType::kCellular,
ConnectionStateType::kOnline, 65);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network.get())));
}
// Test that a connecting cellular icon is displayed when activating a cellular
// network (if other networks are not connected).
TEST_F(NetworkIconTest, DefaultNetworkImageActivatingCellularNetwork) {
SetServiceProperty(cellular_path(), shill::kSignalStrengthProperty,
base::Value(65));
SetServiceProperty(cellular_path(), shill::kActivationStateProperty,
base::Value(shill::kActivationStateActivating));
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
NetworkStatePropertiesPtr reference_network =
CreateStandaloneNetworkProperties("reference", NetworkType::kCellular,
ConnectionStateType::kNotConnected, 65);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network.get())));
}
// Tests that default network image is a wifi network image if wifi network is
// connected during cellular network activation.
TEST_F(NetworkIconTest,
DefaultNetworkImageActivatingCellularNetworkWithConnectedWifi) {
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(45));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
SetServiceProperty(cellular_path(), shill::kSignalStrengthProperty,
base::Value(65));
SetServiceProperty(cellular_path(), shill::kActivationStateProperty,
base::Value(shill::kActivationStateActivating));
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
NetworkStatePropertiesPtr reference_network =
CreateStandaloneNetworkProperties("reference", NetworkType::kWiFi,
ConnectionStateType::kNotConnected, 45);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network.get())));
}
// Tests VPN badging for the default network.
TEST_F(NetworkIconTest, DefaultNetworkVpnBadge) {
// Set up initial state with Ethernet and WiFi connected.
std::string ethernet_path = ConfigureService(
R"({"GUID": "ethernet_guid", "Type": "ethernet", "State": "online"})");
ASSERT_FALSE(ethernet_path.empty());
// Wifi1 is set up by default but not connected. Also set its strength.
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateOnline));
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(45));
// Gets the benchmark ethernet images.
NetworkStatePropertiesPtr reference_eth = CreateStandaloneNetworkProperties(
"reference_eth", NetworkType::kEthernet, ConnectionStateType::kOnline, 0);
gfx::Image reference_eth_unbadged = GetImageForNonVirtualNetwork(
reference_eth.get(), false /* show_vpn_badge */);
gfx::Image reference_eth_badged = GetImageForNonVirtualNetwork(
reference_eth.get(), true /* show_vpn_badge */);
// With Ethernet and WiFi connected, the default icon should be the Ethernet
// icon.
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
EXPECT_TRUE(gfx::test::AreImagesEqual(gfx::Image(default_image),
reference_eth_unbadged));
// Add a connected VPN.
std::string vpn_path = ConfigureService(
R"({"GUID": "vpn_guid", "Type": "vpn", "State": "online"})");
ASSERT_FALSE(vpn_path.empty());
// When a VPN is connected, the default icon should be Ethernet with a badge.
default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
EXPECT_FALSE(gfx::test::AreImagesEqual(gfx::Image(default_image),
reference_eth_unbadged));
EXPECT_TRUE(gfx::test::AreImagesEqual(gfx::Image(default_image),
reference_eth_badged));
// Disconnect Ethernet. The default icon should become WiFi with a badge.
SetServiceProperty(ethernet_path, shill::kStateProperty,
base::Value(shill::kStateIdle));
default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_FALSE(animating);
NetworkStatePropertiesPtr reference_wifi = CreateStandaloneNetworkProperties(
"reference_wifi", NetworkType::kWiFi, ConnectionStateType::kOnline, 45);
gfx::Image reference_wifi_badged = GetImageForNonVirtualNetwork(
reference_wifi.get(), true /* show_vpn_badge */);
EXPECT_TRUE(gfx::test::AreImagesEqual(gfx::Image(default_image),
reference_wifi_badged));
// Set the VPN to connecting; the default icon should be animating.
SetServiceProperty(vpn_path, shill::kStateProperty,
base::Value(shill::kStateAssociation));
default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_TRUE(animating);
}
// Tests that wifi image is shown when connecting to wifi network with vpn.
TEST_F(NetworkIconTest, DefaultNetworkImageVpnAndWifi) {
SetServiceProperty(wifi1_path(), shill::kSignalStrengthProperty,
base::Value(65));
SetServiceProperty(wifi1_path(), shill::kStateProperty,
base::Value(shill::kStateAssociation));
std::string vpn_path = ConfigureService(
R"({"GUID": "vpn_guid", "Type": "vpn", "State": "online"})");
ASSERT_FALSE(vpn_path.empty());
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_TRUE(animating);
NetworkStatePropertiesPtr reference_network =
CreateStandaloneNetworkProperties("reference", NetworkType::kWiFi,
ConnectionStateType::kConnecting, 65);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network.get())));
}
// Tests that cellular image is shown when connecting to cellular network with
// VPN.
TEST_F(NetworkIconTest, DefaultNetworkImageVpnAndCellular) {
SetServiceProperty(cellular_path(), shill::kSignalStrengthProperty,
base::Value(65));
SetServiceProperty(cellular_path(), shill::kStateProperty,
base::Value(shill::kStateAssociation));
std::string vpn_path = ConfigureService(
R"({"GUID": "vpn_guid", "Type": "vpn", "State": "online"})");
ASSERT_FALSE(vpn_path.empty());
bool animating = false;
gfx::ImageSkia default_image = GetDefaultNetworkImage(icon_type_, &animating);
ASSERT_FALSE(default_image.isNull());
EXPECT_TRUE(animating);
NetworkStatePropertiesPtr reference_network =
CreateStandaloneNetworkProperties("reference", NetworkType::kCellular,
ConnectionStateType::kConnecting, 65);
EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(default_image), ImageForNetwork(reference_network.get())));
}
// Tests the case of getting the WiFi Enabled state icon when there is
// no color provider, in which case the window background color is used.
TEST_F(NetworkIconTest, GetImageModelForWiFiEnabledState) {
views::ImageView* image_view =
new views::ImageView(GetImageModelForWiFiEnabledState(true));
std::unique_ptr<views::Widget> widget = CreateFramelessTestWidget();
widget->SetFullscreen(true);
widget->SetContentsView(image_view);
ui::NativeTheme* native_theme = widget->GetNativeTheme();
native_theme->set_use_dark_colors(true);
native_theme->NotifyOnNativeThemeUpdated();
gfx::Image dark_mode_image = gfx::Image(image_view->GetImage());
// Change the color scheme.
native_theme->set_use_dark_colors(false);
native_theme->NotifyOnNativeThemeUpdated();
gfx::Image light_mode_image = gfx::Image(image_view->GetImage());
EXPECT_FALSE(gfx::test::AreImagesEqual(dark_mode_image, light_mode_image));
}
} // namespace ash::network_icon
|