Commit 01004b52 authored by Azeem Arshad's avatar Azeem Arshad Committed by Commit Bot

[Bluetooth] Add unittest for bluetooth tray list.

This CL is a followup to https://crrev.com/c/2482443.
This adds simple unittest that verifies that device
scroll list in bluetooth tray view is updated correctly.

Fixed: 1141995
Change-Id: I8237871ff6c06f864a804d106a0556d3552b6109
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2508234Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Azeem Arshad <azeemarshad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826377}
parent 54eb4b61
...@@ -2149,6 +2149,7 @@ test("ash_unittests") { ...@@ -2149,6 +2149,7 @@ test("ash_unittests") {
"system/bluetooth/bluetooth_notification_controller_unittest.cc", "system/bluetooth/bluetooth_notification_controller_unittest.cc",
"system/bluetooth/bluetooth_power_controller_unittest.cc", "system/bluetooth/bluetooth_power_controller_unittest.cc",
"system/bluetooth/tray_bluetooth_helper_legacy_unittest.cc", "system/bluetooth/tray_bluetooth_helper_legacy_unittest.cc",
"system/bluetooth/unified_bluetooth_detailed_view_controller_unittest.cc",
"system/caps_lock_notification_controller_unittest.cc", "system/caps_lock_notification_controller_unittest.cc",
"system/gesture_education/gesture_education_notification_controller_unittest.cc", "system/gesture_education/gesture_education_notification_controller_unittest.cc",
"system/holding_space/holding_space_tray_unittest.cc", "system/holding_space/holding_space_tray_unittest.cc",
......
...@@ -245,7 +245,7 @@ void BluetoothDetailedView::UpdateDeviceScrollList( ...@@ -245,7 +245,7 @@ void BluetoothDetailedView::UpdateDeviceScrollList(
} else { } else {
scroll_content()->ReorderChildView(bluetooth_discovering_label_, index++); scroll_content()->ReorderChildView(bluetooth_discovering_label_, index++);
} }
} else { } else if (bluetooth_discovering_label_) {
scroll_content()->RemoveChildView(bluetooth_discovering_label_); scroll_content()->RemoveChildView(bluetooth_discovering_label_);
bluetooth_discovering_label_ = nullptr; bluetooth_discovering_label_ = nullptr;
} }
...@@ -273,6 +273,7 @@ const char* BluetoothDetailedView::GetClassName() const { ...@@ -273,6 +273,7 @@ const char* BluetoothDetailedView::GetClassName() const {
void BluetoothDetailedView::CreateItems() { void BluetoothDetailedView::CreateItems() {
CreateScrollableList(); CreateScrollableList();
scroll_content()->SetID(kScrollContentID);
CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH);
} }
......
...@@ -25,6 +25,9 @@ namespace tray { ...@@ -25,6 +25,9 @@ namespace tray {
class BluetoothDetailedView : public TrayDetailedView { class BluetoothDetailedView : public TrayDetailedView {
public: public:
// ID for scroll content view. Used in testing.
static const int kScrollContentID = 1;
BluetoothDetailedView(DetailedViewDelegate* delegate, LoginStatus login); BluetoothDetailedView(DetailedViewDelegate* delegate, LoginStatus login);
~BluetoothDetailedView() override; ~BluetoothDetailedView() override;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "ash/ash_export.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h" #include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/system/unified/detailed_view_controller.h" #include "ash/system/unified/detailed_view_controller.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -22,7 +23,7 @@ class DetailedViewDelegate; ...@@ -22,7 +23,7 @@ class DetailedViewDelegate;
class UnifiedSystemTrayController; class UnifiedSystemTrayController;
// Controller of Bluetooth detailed view in UnifiedSystemTray. // Controller of Bluetooth detailed view in UnifiedSystemTray.
class UnifiedBluetoothDetailedViewController class ASH_EXPORT UnifiedBluetoothDetailedViewController
: public DetailedViewController, : public DetailedViewController,
public TrayBluetoothHelper::Observer { public TrayBluetoothHelper::Observer {
public: public:
......
// 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/bluetooth/unified_bluetooth_detailed_view_controller.h"
#include <memory>
#include "ash/system/bluetooth/bluetooth_detailed_view.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/system/unified/unified_system_tray_model.h"
#include "ash/test/ash_test_base.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
#include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
#include "ui/views/view.h"
namespace ash {
namespace {
const base::TimeDelta kUpdateFrequencyMs =
base::TimeDelta::FromMilliseconds(1000);
} // namespace
class UnifiedBluetoothDetailedViewControllerTest : public AshTestBase {
public:
UnifiedBluetoothDetailedViewControllerTest()
: AshTestBase(base::test::TaskEnvironment::TimeSource::MOCK_TIME) {}
UnifiedBluetoothDetailedViewControllerTest(
const UnifiedBluetoothDetailedViewControllerTest&) = delete;
UnifiedBluetoothDetailedViewControllerTest& operator=(
const UnifiedBluetoothDetailedViewControllerTest&) = delete;
~UnifiedBluetoothDetailedViewControllerTest() override = default;
void SetUp() override {
bluez::BluezDBusManager::InitializeFake();
AshTestBase::SetUp();
// Set fake adapter client to powered-on and initialize with zero simulation
// interval.
adapter_client_ = static_cast<bluez::FakeBluetoothAdapterClient*>(
bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient());
adapter_client_->SetSimulationIntervalMs(0);
adapter_client_
->GetProperties(
dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath))
->powered.ReplaceValue(true);
// Enable fake device client and initialize with zero simulation interval.
device_client_ = static_cast<bluez::FakeBluetoothDeviceClient*>(
bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient());
device_client_->SetSimulationIntervalMs(0);
task_environment()->RunUntilIdle();
tray_model_ = std::make_unique<UnifiedSystemTrayModel>(nullptr);
tray_controller_ =
std::make_unique<UnifiedSystemTrayController>(tray_model_.get());
bt_detailed_view_controller_ =
std::make_unique<UnifiedBluetoothDetailedViewController>(
tray_controller_.get());
}
void TearDown() override {
bt_detailed_view_controller_.reset();
tray_controller_.reset();
tray_model_.reset();
AshTestBase::TearDown();
}
void AddTestDevice() {
bluez::FakeBluetoothDeviceClient::IncomingDeviceProperties props;
props.device_path = "/fake/hci0/dev123";
props.device_address = "00:00:00:00:00:01";
props.device_name = "Test Device";
props.device_class = 0x000104;
device_client_->CreateDeviceWithProperties(
dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
props);
}
UnifiedBluetoothDetailedViewController* bt_detailed_view_controller() {
return bt_detailed_view_controller_.get();
}
private:
bluez::FakeBluetoothAdapterClient* adapter_client_;
bluez::FakeBluetoothDeviceClient* device_client_;
std::unique_ptr<UnifiedSystemTrayModel> tray_model_;
std::unique_ptr<UnifiedSystemTrayController> tray_controller_;
std::unique_ptr<UnifiedBluetoothDetailedViewController>
bt_detailed_view_controller_;
};
TEST_F(UnifiedBluetoothDetailedViewControllerTest, UpdateScrollListTest) {
tray::BluetoothDetailedView* bluetooth_detailed_view =
static_cast<tray::BluetoothDetailedView*>(
bt_detailed_view_controller()->CreateView());
task_environment()->FastForwardBy(kUpdateFrequencyMs);
// Verify that default devices simulated by FakeBluetoothDeviceClient are
// displayed.
const views::View* scroll_content = bluetooth_detailed_view->GetViewByID(
tray::BluetoothDetailedView::kScrollContentID);
const size_t scroll_content_size = scroll_content->children().size();
// Expect at least 1 paired device, 1 unpaired device and 2 headers.
EXPECT_GE(scroll_content_size, 4u);
// Fast forward to next bluetooth list sync and verify that child views
// are re-used after update.
views::View* scroll_content_child = scroll_content->children()[1];
task_environment()->FastForwardBy(kUpdateFrequencyMs);
EXPECT_EQ(scroll_content_child, scroll_content->children()[1]);
// Verify that newly added devices is displayed.
AddTestDevice();
task_environment()->FastForwardBy(kUpdateFrequencyMs);
EXPECT_EQ(scroll_content_size + 1u, scroll_content->children().size());
}
} // namespace ash
\ No newline at end of file
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