Commit 6619bb72 authored by Andre Le's avatar Andre Le Committed by Commit Bot

[CrOS PhoneHub] Hook up PhoneModel to Phone status UI.

Add PhoneModel to PhoneStatusView and display phone data in the UI
through a set up labels and icons.

BUG=1106937,1126208

Change-Id: I0af9365e510940e5d1ac1ea15767b8c12c603cc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410762
Commit-Queue: Andre Le <leandre@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807946}
parent 15d440a3
...@@ -2088,6 +2088,7 @@ test("ash_unittests") { ...@@ -2088,6 +2088,7 @@ test("ash_unittests") {
"system/palette/tools/screenshot_unittest.cc", "system/palette/tools/screenshot_unittest.cc",
"system/phonehub/phone_hub_notification_controller_unittest.cc", "system/phonehub/phone_hub_notification_controller_unittest.cc",
"system/phonehub/phone_hub_tray_unittest.cc", "system/phonehub/phone_hub_tray_unittest.cc",
"system/phonehub/phone_status_view_unittest.cc",
"system/power/backlights_forced_off_setter_unittest.cc", "system/power/backlights_forced_off_setter_unittest.cc",
"system/power/peripheral_battery_notifier_unittest.cc", "system/power/peripheral_battery_notifier_unittest.cc",
"system/power/power_button_controller_unittest.cc", "system/power/power_button_controller_unittest.cc",
......
...@@ -138,6 +138,8 @@ aggregate_vector_icons("ash_vector_icons") { ...@@ -138,6 +138,8 @@ aggregate_vector_icons("ash_vector_icons") {
"palette_tray_icon_magnify.icon", "palette_tray_icon_magnify.icon",
"palette_tray_icon_metalayer.icon", "palette_tray_icon_metalayer.icon",
"pin_request_lock.icon", "pin_request_lock.icon",
"phone_hub_mobile_no_connection.icon",
"phone_hub_mobile_no_sim.icon",
"privacy_screen.icon", "privacy_screen.icon",
"send.icon", "send.icon",
"settings.icon", "settings.icon",
......
CANVAS_DIMENSIONS, 20,
MOVE_TO, 6.67f, 6,
LINE_TO, 8, 4.67f,
LINE_TO, 7.33f, 4,
LINE_TO, 6, 5.33f,
LINE_TO, 4.67f, 4,
LINE_TO, 4, 4.67f,
LINE_TO, 5.33f, 6,
LINE_TO, 4, 7.33f,
LINE_TO, 4.67f, 8,
LINE_TO, 6, 6.67f,
LINE_TO, 7.33f, 8,
LINE_TO, 8, 7.33f,
LINE_TO, 6.67f, 6,
CLOSE,
MOVE_TO, 15.5f, 15.5f,
V_LINE_TO, 6.21f,
LINE_TO, 6.21f, 15.5f,
H_LINE_TO, 15.5f,
CLOSE,
MOVE_TO, 16, 17,
R_CUBIC_TO, 0.55f, 0, 1, -0.45f, 1, -1,
V_LINE_TO, 5,
R_CUBIC_TO, 0, -0.89f, -1.08f, -1.34f, -1.71f, -0.71f,
LINE_TO, 4.29f, 15.29f,
CUBIC_TO, 3.66f, 15.92f, 4.11f, 17, 5, 17,
H_LINE_TO, 16,
CLOSE
CANVAS_DIMENSIONS, 20,
MOVE_TO, 2, 2.09f,
LINE_TO, 17.56f, 17.64f,
R_LINE_TO, -1.41f, 1.41f,
R_LINE_TO, -1.06f, -1.06f,
R_CUBIC_TO, -0.03f, 0, -0.05f, 0, -0.08f, 0,
H_LINE_TO, 5,
R_CUBIC_TO, -1.1f, 0, -2, -0.9f, -2, -2,
V_LINE_TO, 7,
R_LINE_TO, 0.54f, -0.54f,
LINE_TO, 0.59f, 3.5f,
LINE_TO, 2, 2.09f,
CLOSE,
MOVE_TO, 13.09f, 16,
LINE_TO, 5, 7.91f,
LINE_TO, 5, 16,
R_H_LINE_TO, 8.09f,
CLOSE,
R_MOVE_TO, 1.91f, -14,
R_CUBIC_TO, 1.1f, 0, 2, 0.9f, 2, 2,
R_V_LINE_TO, 10,
R_LINE_TO, -2, -2,
V_LINE_TO, 4,
H_LINE_TO, 8.83f,
R_LINE_TO, -0.91f, 0.91f,
R_LINE_TO, -1.41f, -1.41f,
R_LINE_TO, 1.5f, -1.5f,
R_H_LINE_TO, 7,
CLOSE
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ash/system/tray/tray_utils.h" #include "ash/system/tray/tray_utils.h"
#include "base/bind.h" #include "base/bind.h"
#include "chromeos/components/phonehub/phone_hub_manager.h" #include "chromeos/components/phonehub/phone_hub_manager.h"
#include "chromeos/components/phonehub/phone_model.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -47,15 +48,21 @@ constexpr int kPaddingBetweenTitleAndSeparator = 3; ...@@ -47,15 +48,21 @@ constexpr int kPaddingBetweenTitleAndSeparator = 3;
// such as phone status, task continuation, etc. // such as phone status, task continuation, etc.
class PhoneHubView : public views ::View { class PhoneHubView : public views ::View {
public: public:
explicit PhoneHubView(TrayBubbleView* bubble_view) explicit PhoneHubView(TrayBubbleView* bubble_view,
chromeos::phonehub::PhoneHubManager* phone_hub_manager)
: bubble_view_(bubble_view) { : bubble_view_(bubble_view) {
auto setup_layered_view = [](views::View* view) { auto setup_layered_view = [](views::View* view) {
view->SetPaintToLayer(); view->SetPaintToLayer();
view->layer()->SetFillsBoundsOpaquely(false); view->layer()->SetFillsBoundsOpaquely(false);
}; };
setup_layered_view( chromeos::phonehub::PhoneModel* phone_model =
bubble_view_->AddChildView(std::make_unique<PhoneStatusView>())); phone_hub_manager->GetPhoneModel();
if (phone_model) {
setup_layered_view(bubble_view->AddChildView(
std::make_unique<PhoneStatusView>(phone_model)));
}
AddSeparator(); AddSeparator();
...@@ -178,6 +185,8 @@ void PhoneHubTray::ShowBubble(bool show_by_click) { ...@@ -178,6 +185,8 @@ void PhoneHubTray::ShowBubble(bool show_by_click) {
if (bubble_) if (bubble_)
return; return;
DCHECK(phone_hub_manager_);
TrayBubbleView::InitParams init_params; TrayBubbleView::InitParams init_params;
init_params.delegate = this; init_params.delegate = this;
init_params.parent_window = GetBubbleWindowContainer(); init_params.parent_window = GetBubbleWindowContainer();
...@@ -195,7 +204,8 @@ void PhoneHubTray::ShowBubble(bool show_by_click) { ...@@ -195,7 +204,8 @@ void PhoneHubTray::ShowBubble(bool show_by_click) {
bubble_view->set_margins(GetSecondaryBubbleInsets()); bubble_view->set_margins(GetSecondaryBubbleInsets());
bubble_view->SetBorder(views::CreateEmptyBorder(kBubblePadding)); bubble_view->SetBorder(views::CreateEmptyBorder(kBubblePadding));
bubble_view->AddChildView(std::make_unique<PhoneHubView>(bubble_view)); bubble_view->AddChildView(
std::make_unique<PhoneHubView>(bubble_view, phone_hub_manager_));
bubble_ = std::make_unique<TrayBubbleWrapper>(this, bubble_view, bubble_ = std::make_unique<TrayBubbleWrapper>(this, bubble_view,
false /* is_persistent */); false /* is_persistent */);
......
...@@ -4,74 +4,206 @@ ...@@ -4,74 +4,206 @@
#include "ash/system/phonehub/phone_status_view.h" #include "ash/system/phonehub/phone_status_view.h"
#include "ash/public/cpp/network_icon_image_source.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_item_style.h" #include "ash/system/tray/tray_popup_item_style.h"
#include "base/i18n/number_formatting.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
namespace ash { namespace ash {
using PhoneStatusModel = chromeos::phonehub::PhoneStatusModel;
namespace { namespace {
constexpr int kTitleContainerSpacing = 16; constexpr int kTitleContainerSpacing = 16;
constexpr int kStatusSpacing = 6;
views::ImageView* CreateTitleIcon(const gfx::VectorIcon& vector_icon, constexpr gfx::Size kStatusIconSize(16, 16);
int tooltip_text_id) { constexpr int kSeparatorHeight = 18;
auto* icon = new views::ImageView();
icon->SetTooltipText(l10n_util::GetStringUTF16(tooltip_text_id)); int GetSignalStrengthAsInt(PhoneStatusModel::SignalStrength signal_strength) {
icon->SetImage(CreateVectorIcon( switch (signal_strength) {
vector_icon, AshColorProvider::Get()->GetContentLayerColor( case PhoneStatusModel::SignalStrength::kZeroBars:
AshColorProvider::ContentLayerType::kIconColorPrimary))); return 0;
return icon; case PhoneStatusModel::SignalStrength::kOneBar:
return 1;
case PhoneStatusModel::SignalStrength::kTwoBars:
return 2;
case PhoneStatusModel::SignalStrength::kThreeBars:
return 3;
case PhoneStatusModel::SignalStrength::kFourBars:
return 4;
}
} }
} // namespace } // namespace
PhoneStatusView::PhoneStatusView() : TriView(kTitleContainerSpacing) { PhoneStatusView::PhoneStatusView(chromeos::phonehub::PhoneModel* phone_model)
: TriView(kTitleContainerSpacing),
phone_model_(phone_model),
phone_name_label_(new views::Label),
signal_icon_(new views::ImageView),
mobile_provider_label_(new views::Label),
battery_icon_(new views::ImageView),
battery_label_(new views::Label) {
ConfigureTriViewContainer(TriView::Container::START); ConfigureTriViewContainer(TriView::Container::START);
ConfigureTriViewContainer(TriView::Container::CENTER); ConfigureTriViewContainer(TriView::Container::CENTER);
ConfigureTriViewContainer(TriView::Container::END); ConfigureTriViewContainer(TriView::Container::END);
// TODO(leandre): Update title and icons according to phone status. phone_model_->AddObserver(this);
auto* title_label = new views::Label(
l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME)); phone_name_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER, TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER,
true /* use_unified_theme */); true /* use_unified_theme */);
style.SetupLabel(title_label); style.SetupLabel(phone_name_label_);
AddView(TriView::Container::CENTER, title_label); AddView(TriView::Container::CENTER, phone_name_label_);
wifi_icon_ = CreateTitleIcon(kUnifiedMenuWifiNoConnectionIcon, AddView(TriView::Container::END, signal_icon_);
IDS_ASH_STATUS_TRAY_NO_NETWORKS);
AddView(TriView::Container::END, wifi_icon_);
volume_icon_ = CreateTitleIcon(kSystemMenuVolumeMuteIcon, mobile_provider_label_->SetAutoColorReadabilityEnabled(false);
IDS_ASH_STATUS_TRAY_VOLUME_STATE_MUTED); mobile_provider_label_->SetSubpixelRenderingEnabled(false);
AddView(TriView::Container::END, volume_icon_); mobile_provider_label_->SetEnabledColor(
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary));
AddView(TriView::Container::END, mobile_provider_label_);
battery_icon_ =
CreateTitleIcon(kBatteryIcon, IDS_ASH_STATUS_TRAY_BATTERY_FULL);
AddView(TriView::Container::END, battery_icon_); AddView(TriView::Container::END, battery_icon_);
battery_label_->SetAutoColorReadabilityEnabled(false);
battery_label_->SetSubpixelRenderingEnabled(false);
battery_label_->SetEnabledColor(AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary));
AddView(TriView::Container::END, battery_label_);
auto* separator = new views::Separator();
separator->SetColor(AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSeparatorColor));
separator->SetPreferredHeight(kSeparatorHeight);
AddView(TriView::Container::END, separator);
settings_button_ = new TopShortcutButton(this, kSystemMenuSettingsIcon, settings_button_ = new TopShortcutButton(this, kSystemMenuSettingsIcon,
IDS_ASH_STATUS_TRAY_SETTINGS); IDS_ASH_STATUS_TRAY_SETTINGS);
AddView(TriView::Container::END, settings_button_); AddView(TriView::Container::END, settings_button_);
Update();
} }
PhoneStatusView::~PhoneStatusView() = default; PhoneStatusView::~PhoneStatusView() {
phone_model_->RemoveObserver(this);
}
void PhoneStatusView::ButtonPressed(views::Button* sender, void PhoneStatusView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
// TODO(leandre): implement open settings/other buttons. // TODO(leandre): implement open settings/other buttons.
} }
void PhoneStatusView::OnModelChanged() {
Update();
}
void PhoneStatusView::Update() {
phone_name_label_->SetText(
phone_model_->phone_name().value_or(base::string16()));
if (!phone_model_->phone_status_model())
return;
UpdateMobileStatus();
UpdateBatteryStatus();
}
void PhoneStatusView::UpdateMobileStatus() {
const PhoneStatusModel& phone_status =
phone_model_->phone_status_model().value();
const SkColor primary_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPrimary);
gfx::ImageSkia signal_image;
switch (phone_status.mobile_status()) {
case PhoneStatusModel::MobileStatus::kNoSim:
signal_image = CreateVectorIcon(kPhoneHubMobileNoSimIcon, primary_color);
break;
case PhoneStatusModel::MobileStatus::kSimButNoReception:
signal_image =
CreateVectorIcon(kPhoneHubMobileNoConnectionIcon, primary_color);
break;
case PhoneStatusModel::MobileStatus::kSimWithReception:
const PhoneStatusModel::MobileConnectionMetadata& metadata =
phone_status.mobile_connection_metadata().value();
int signal_strength = GetSignalStrengthAsInt(metadata.signal_strength);
signal_image = gfx::CanvasImageSource::MakeImageSkia<
network_icon::SignalStrengthImageSource>(
network_icon::ImageType::BARS, primary_color, kStatusIconSize,
signal_strength);
mobile_provider_label_->SetText(metadata.mobile_provider);
break;
}
signal_icon_->SetImage(signal_image);
mobile_provider_label_->SetVisible(
phone_status.mobile_status() ==
PhoneStatusModel::MobileStatus::kSimWithReception);
}
void PhoneStatusView::UpdateBatteryStatus() {
const PhoneStatusModel& phone_status =
phone_model_->phone_status_model().value();
const PowerStatus::BatteryImageInfo& info = CalculateBatteryInfo();
const SkColor icon_bg_color = color_utils::GetResultingPaintColor(
ShelfConfig::Get()->GetShelfControlButtonColor(),
AshColorProvider::Get()->GetBackgroundColor());
const SkColor icon_fg_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPrimary);
battery_icon_->SetImage(PowerStatus::GetBatteryImage(
info, kUnifiedTrayIconSize, icon_bg_color, icon_fg_color));
battery_label_->SetText(
base::FormatPercent(phone_status.battery_percentage()));
}
PowerStatus::BatteryImageInfo PhoneStatusView::CalculateBatteryInfo() {
PowerStatus::BatteryImageInfo info;
const PhoneStatusModel& phone_status =
phone_model_->phone_status_model().value();
info.charge_percent = phone_status.battery_percentage();
switch (phone_status.charging_state()) {
case PhoneStatusModel::ChargingState::kNotCharging:
info.alert_if_low = true;
if (info.charge_percent < PowerStatus::kCriticalBatteryChargePercentage) {
info.icon_badge = &kUnifiedMenuBatteryAlertIcon;
info.badge_outline = &kUnifiedMenuBatteryAlertOutlineIcon;
}
break;
case PhoneStatusModel::ChargingState::kChargingAc:
info.icon_badge = &kUnifiedMenuBatteryBoltIcon;
info.badge_outline = &kUnifiedMenuBatteryBoltOutlineIcon;
break;
case PhoneStatusModel::ChargingState::kChargingUsb:
info.icon_badge = &kUnifiedMenuBatteryUnreliableIcon;
info.badge_outline = &kUnifiedMenuBatteryUnreliableOutlineIcon;
break;
}
return info;
}
void PhoneStatusView::ConfigureTriViewContainer(TriView::Container container) { void PhoneStatusView::ConfigureTriViewContainer(TriView::Container container) {
std::unique_ptr<views::BoxLayout> layout; std::unique_ptr<views::BoxLayout> layout;
...@@ -81,7 +213,7 @@ void PhoneStatusView::ConfigureTriViewContainer(TriView::Container container) { ...@@ -81,7 +213,7 @@ void PhoneStatusView::ConfigureTriViewContainer(TriView::Container container) {
case TriView::Container::END: case TriView::Container::END:
layout = std::make_unique<views::BoxLayout>( layout = std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(), views::BoxLayout::Orientation::kHorizontal, gfx::Insets(),
kUnifiedTopShortcutSpacing); kStatusSpacing);
layout->set_main_axis_alignment( layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kCenter); views::BoxLayout::MainAxisAlignment::kCenter);
layout->set_cross_axis_alignment( layout->set_cross_axis_alignment(
......
...@@ -6,22 +6,27 @@ ...@@ -6,22 +6,27 @@
#define ASH_SYSTEM_PHONEHUB_PHONE_STATUS_VIEW_H_ #define ASH_SYSTEM_PHONEHUB_PHONE_STATUS_VIEW_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/system/power/power_status.h"
#include "ash/system/tray/tri_view.h" #include "ash/system/tray/tri_view.h"
#include "ash/system/unified/top_shortcut_button.h" #include "ash/system/unified/top_shortcut_button.h"
#include "chromeos/components/phonehub/phone_model.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
namespace views { namespace views {
class ImageView; class ImageView;
} class Label;
} // namespace views
namespace ash { namespace ash {
// The header row at the top of the Phone Hub panel, showing phone title and // The header row at the top of the Phone Hub panel, showing phone title and
// status (wifi, volime, etc.). // status (wifi, volime, etc.).
class ASH_EXPORT PhoneStatusView : public TriView, class ASH_EXPORT PhoneStatusView
public views::ButtonListener { : public TriView,
public views::ButtonListener,
public chromeos::phonehub::PhoneModel::Observer {
public: public:
PhoneStatusView(); explicit PhoneStatusView(chromeos::phonehub::PhoneModel* phone_model);
~PhoneStatusView() override; ~PhoneStatusView() override;
PhoneStatusView(PhoneStatusView&) = delete; PhoneStatusView(PhoneStatusView&) = delete;
PhoneStatusView operator=(PhoneStatusView&) = delete; PhoneStatusView operator=(PhoneStatusView&) = delete;
...@@ -29,12 +34,30 @@ class ASH_EXPORT PhoneStatusView : public TriView, ...@@ -29,12 +34,30 @@ class ASH_EXPORT PhoneStatusView : public TriView,
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// chromeos::phonehub::PhoneHubModel::Observer:
void OnModelChanged() override;
private: private:
FRIEND_TEST_ALL_PREFIXES(PhoneStatusViewTest, MobileProviderVisibility);
FRIEND_TEST_ALL_PREFIXES(PhoneStatusViewTest, PhoneStatusLabelsContent);
// Update the labels and icons in the view to display current phone status.
void Update();
void UpdateMobileStatus();
void UpdateBatteryStatus();
PowerStatus::BatteryImageInfo CalculateBatteryInfo();
void ConfigureTriViewContainer(TriView::Container container); void ConfigureTriViewContainer(TriView::Container container);
views::ImageView* wifi_icon_ = nullptr; chromeos::phonehub::PhoneModel* phone_model_ = nullptr;
views::ImageView* volume_icon_ = nullptr;
// Owned by views hierarchy.
views::Label* phone_name_label_ = nullptr;
views::ImageView* signal_icon_ = nullptr;
views::Label* mobile_provider_label_ = nullptr;
views::ImageView* battery_icon_ = nullptr; views::ImageView* battery_icon_ = nullptr;
views::Label* battery_label_ = nullptr;
TopShortcutButton* settings_button_ = nullptr; TopShortcutButton* settings_button_ = nullptr;
}; };
......
// Copyright 2020 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/phonehub/phone_status_view.h"
#include "ash/test/ash_test_base.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/components/phonehub/mutable_phone_model.h"
#include "chromeos/constants/chromeos_features.h"
#include "ui/views/controls/label.h"
namespace ash {
using PhoneStatusModel = chromeos::phonehub::PhoneStatusModel;
class PhoneStatusViewTest : public AshTestBase {
public:
PhoneStatusViewTest() = default;
~PhoneStatusViewTest() override = default;
// AshTestBase:
void SetUp() override {
feature_list_.InitAndEnableFeature(chromeos::features::kPhoneHub);
AshTestBase::SetUp();
phone_status_view_ = std::make_unique<PhoneStatusView>(&phone_model_);
}
void TearDown() override {
phone_status_view_.reset();
AshTestBase::TearDown();
}
protected:
PhoneStatusView* status_view() { return phone_status_view_.get(); }
chromeos::phonehub::MutablePhoneModel* phone_model() { return &phone_model_; }
private:
std::unique_ptr<PhoneStatusView> phone_status_view_;
chromeos::phonehub::MutablePhoneModel phone_model_;
base::test::ScopedFeatureList feature_list_;
};
TEST_F(PhoneStatusViewTest, MobileProviderVisibility) {
PhoneStatusModel::MobileConnectionMetadata metadata = {
.signal_strength = PhoneStatusModel::SignalStrength::kZeroBars,
.mobile_provider = base::UTF8ToUTF16("Test Provider"),
};
auto phone_status =
PhoneStatusModel(PhoneStatusModel::MobileStatus::kNoSim, metadata,
PhoneStatusModel::ChargingState::kNotCharging,
PhoneStatusModel::BatterySaverState::kOff, 0);
phone_model()->SetPhoneStatusModel(phone_status);
// Mobile provider should not be shown when there is no sim.
EXPECT_FALSE(status_view()->mobile_provider_label_->GetVisible());
phone_status =
PhoneStatusModel(PhoneStatusModel::MobileStatus::kSimButNoReception,
metadata, PhoneStatusModel::ChargingState::kNotCharging,
PhoneStatusModel::BatterySaverState::kOff, 0);
phone_model()->SetPhoneStatusModel(phone_status);
// Mobile provider should not be shown when there is no connection.
EXPECT_FALSE(status_view()->mobile_provider_label_->GetVisible());
phone_status =
PhoneStatusModel(PhoneStatusModel::MobileStatus::kSimWithReception,
metadata, PhoneStatusModel::ChargingState::kNotCharging,
PhoneStatusModel::BatterySaverState::kOff, 0);
phone_model()->SetPhoneStatusModel(phone_status);
// Mobile provider should be shown when there is a connection.
EXPECT_TRUE(status_view()->mobile_provider_label_->GetVisible());
}
TEST_F(PhoneStatusViewTest, PhoneStatusLabelsContent) {
base::string16 expected_name_text = base::UTF8ToUTF16("Test Phone Name");
base::string16 expected_provider_text = base::UTF8ToUTF16("Test Provider");
base::string16 expected_battery_text = base::UTF8ToUTF16("10%");
phone_model()->SetPhoneName(expected_name_text);
PhoneStatusModel::MobileConnectionMetadata metadata = {
.signal_strength = PhoneStatusModel::SignalStrength::kZeroBars,
.mobile_provider = expected_provider_text,
};
auto phone_status =
PhoneStatusModel(PhoneStatusModel::MobileStatus::kSimWithReception,
metadata, PhoneStatusModel::ChargingState::kNotCharging,
PhoneStatusModel::BatterySaverState::kOff, 10);
phone_model()->SetPhoneStatusModel(phone_status);
// All labels should display phone's status and information.
EXPECT_EQ(expected_name_text, status_view()->phone_name_label_->GetText());
EXPECT_EQ(expected_provider_text,
status_view()->mobile_provider_label_->GetText());
EXPECT_EQ(expected_battery_text, status_view()->battery_label_->GetText());
expected_name_text = base::UTF8ToUTF16("New Phone Name");
expected_provider_text = base::UTF8ToUTF16("New Provider");
expected_battery_text = base::UTF8ToUTF16("20%");
phone_model()->SetPhoneName(expected_name_text);
metadata.mobile_provider = expected_provider_text;
phone_status =
PhoneStatusModel(PhoneStatusModel::MobileStatus::kSimWithReception,
metadata, PhoneStatusModel::ChargingState::kNotCharging,
PhoneStatusModel::BatterySaverState::kOff, 20);
phone_model()->SetPhoneStatusModel(phone_status);
// Changes in the model should be reflected in the labels.
EXPECT_EQ(expected_name_text, status_view()->phone_name_label_->GetText());
EXPECT_EQ(expected_provider_text,
status_view()->mobile_provider_label_->GetText());
EXPECT_EQ(expected_battery_text, status_view()->battery_label_->GetText());
}
} // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment