Commit fb330032 authored by Abhijeet Singh's avatar Abhijeet Singh Committed by Commit Bot

Add tests for QuickAnswersView

Add a test-fixture and basic tests for QuickAnswersView. Current tests
verify the view's positioning with respect to its anchor and more tests
will be added in follow-up CLs.

Bug: b:157182213
Test: Built and ran ash:ash_unittests on local build.
Change-Id: I44634313ff6538e48ef7375641e1971bfc989ab1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2210977Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Abhijeet Singh <siabhijeet@google.com>
Cr-Commit-Position: refs/heads/master@{#771207}
parent d4898f7b
......@@ -1962,6 +1962,7 @@ test("ash_unittests") {
"power/hfp_battery_listener_unittest.cc",
"power/hid_battery_listener_unittest.cc",
"power/hid_battery_util_unittest.cc",
"quick_answers/ui/quick_answers_view_unittest.cc",
"root_window_controller_unittest.cc",
"rotator/screen_rotation_animation_unittest.cc",
"rotator/screen_rotation_animator_unittest.cc",
......
......@@ -80,6 +80,10 @@ class ASH_EXPORT QuickAnswersControllerImpl
// Open Quick-Answers dogfood URL.
void OpenQuickAnswersDogfoodLink();
QuickAnswersUiController* quick_answers_ui_controller() {
return quick_answers_ui_controller_.get();
}
private:
void MaybeDismissQuickAnswersConsent();
......
// 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/quick_answers/ui/quick_answers_view.h"
#include "ash/quick_answers/quick_answers_controller_impl.h"
#include "ash/test/ash_test_base.h"
namespace ash {
namespace {
constexpr int kMarginDip = 10;
constexpr int kSmallTop = 30;
constexpr gfx::Rect kDefaultAnchorBoundsInScreen =
gfx::Rect(gfx::Point(500, 250), gfx::Size(80, 140));
} // namespace
class QuickAnswersViewsTest : public AshTestBase {
protected:
QuickAnswersViewsTest() = default;
QuickAnswersViewsTest(const QuickAnswersViewsTest&) = delete;
QuickAnswersViewsTest& operator=(const QuickAnswersViewsTest&) = delete;
~QuickAnswersViewsTest() override = default;
// AshTestBase:
void SetUp() override {
AshTestBase::SetUp();
dummy_anchor_bounds_ = kDefaultAnchorBoundsInScreen;
controller_ = std::make_unique<QuickAnswersControllerImpl>();
CreateQuickAnswersView(dummy_anchor_bounds_, "dummy_title");
}
void TearDown() override {
quick_answers_view_.reset();
controller_.reset();
AshTestBase::TearDown();
}
// Currently instantiated QuickAnswersView instance.
QuickAnswersView* view() { return quick_answers_view_.get(); }
// Needed to poll the current bounds of the mock anchor.
const gfx::Rect& dummy_anchor_bounds() { return dummy_anchor_bounds_; }
// Create a QuickAnswersView instance with custom anchor-bounds and
// title-text.
void CreateQuickAnswersView(const gfx::Rect anchor_bounds,
const char* title) {
// Reset existing view if any.
quick_answers_view_.reset();
dummy_anchor_bounds_ = anchor_bounds;
quick_answers_view_ = std::make_unique<QuickAnswersView>(
dummy_anchor_bounds_, title,
controller_->quick_answers_ui_controller());
}
private:
std::unique_ptr<QuickAnswersView> quick_answers_view_;
std::unique_ptr<QuickAnswersControllerImpl> controller_;
gfx::Rect dummy_anchor_bounds_;
};
TEST_F(QuickAnswersViewsTest, DefaultLayoutAroundAnchor) {
gfx::Rect view_bounds = view()->GetBoundsInScreen();
gfx::Rect anchor_bounds = dummy_anchor_bounds();
// Vertically aligned with anchor.
EXPECT_EQ(view_bounds.x(), anchor_bounds.x());
EXPECT_EQ(view_bounds.right(), anchor_bounds.right());
// View is positioned above the anchor.
EXPECT_EQ(view_bounds.bottom() + kMarginDip, anchor_bounds.y());
}
TEST_F(QuickAnswersViewsTest, PositionedBelowAnchorIfLessSpaceAbove) {
gfx::Rect anchor_bounds = dummy_anchor_bounds();
// Update anchor-bounds' position so that it does not leave enough vertical
// space above it to show the QuickAnswersView.
anchor_bounds.set_y(kSmallTop);
CreateQuickAnswersView(anchor_bounds, "dummy_title");
gfx::Rect view_bounds = view()->GetBoundsInScreen();
// Anchor is positioned above the view.
EXPECT_EQ(anchor_bounds.bottom() + kMarginDip, view_bounds.y());
}
} // 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