Skip to content

Commit

Permalink
Make ParentAccessWidget adapt to tablet mode
Browse files Browse the repository at this point in the history
Parent access view has different layout and size in tablet mode
(virtual PIN keyboard is shown). The widget should resize together
with the view.

Bug: 991387
Test: ParentAccessWidgetTest
Change-Id: I8f0232e2618198950b4e23acf7a7ada82400e570
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1779663
Commit-Queue: Aga Wronska <agawronska@chromium.org>
Reviewed-by: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692805}
  • Loading branch information
Aga Wronska authored and Commit Bot committed Sep 3, 2019
1 parent d46219a commit ad93a98
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ash/login/ui/parent_access_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ void ParentAccessView::UpdatePreferredSize() {
pin_keyboard_to_footer_spacer_->SetPreferredSize(
GetPinKeyboardToFooterSpacerSize());
SetPreferredSize(CalculatePreferredSize());
if (GetWidget())
GetWidget()->CenterWindow(GetPreferredSize());
}

void ParentAccessView::FocusSubmitButton() {
Expand Down
57 changes: 56 additions & 1 deletion ash/login/ui/parent_access_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/work_area_insets.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/optional.h"
Expand All @@ -27,6 +28,7 @@
#include "components/account_id/account_id.h"
#include "components/session_manager/session_manager_types.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
Expand Down Expand Up @@ -74,6 +76,14 @@ class ParentAccessViewTest : public LoginTestBase {
login_client_ = std::make_unique<MockLoginScreenClient>();
}

void TearDown() override {
LoginTestBase::TearDown();

// If the test did not explicitly dismissed the widget, destroy it now.
if (ParentAccessWidget::Get())
ParentAccessWidget::Get()->Destroy();
}

// Simulates mouse press event on a |button|.
void SimulateButtonPress(views::Button* button) {
ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
Expand Down Expand Up @@ -533,8 +543,10 @@ TEST_F(ParentAccessViewTest, BackwardTabKeyTraversal) {
EXPECT_TRUE(HasFocusInAnyChildView(test_api.access_code_view()));
}

using ParentAccessWidgetTest = ParentAccessViewTest;

// Tests that correct usage metric is reported.
TEST_F(ParentAccessViewTest, UMAUsageMetric) {
TEST_F(ParentAccessWidgetTest, UMAUsageMetric) {
ShowWidget(ParentAccessRequestReason::kUnlockTimeLimits);
DismissWidget();
histogram_tester_.ExpectBucketCount(
Expand Down Expand Up @@ -576,4 +588,47 @@ TEST_F(ParentAccessViewTest, UMAUsageMetric) {
ParentAccessView::kUMAParentAccessCodeUsage, 5);
}

// Tests that the widget is properly resized when tablet mode changes.
TEST_F(ParentAccessWidgetTest, WidgetResizingInTabletMode) {
// Set display large enough to fit preferred view sizes.
UpdateDisplay("1200x800");
ShowWidget(ParentAccessRequestReason::kUnlockTimeLimits);

ParentAccessWidget* widget = ParentAccessWidget::Get();
ASSERT_TRUE(widget);
ParentAccessView* view =
ParentAccessWidget::TestApi(widget).parent_access_view();

constexpr auto kClamshellModeSize = gfx::Size(340, 340);
constexpr auto kTabletModeSize = gfx::Size(340, 580);

const auto widget_size = [&view]() -> gfx::Size {
return view->GetWidget()->GetWindowBoundsInScreen().size();
};

const auto widget_center = [&view]() -> gfx::Point {
return view->GetWidget()->GetWindowBoundsInScreen().CenterPoint();
};

const auto user_work_area_center = [&view]() -> gfx::Point {
return WorkAreaInsets::ForWindow(view->GetWidget()->GetNativeWindow())
->user_work_area_bounds()
.CenterPoint();
};

EXPECT_EQ(kClamshellModeSize, view->size());
EXPECT_EQ(kClamshellModeSize, widget_size());
EXPECT_EQ(user_work_area_center(), widget_center());

Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
EXPECT_EQ(kTabletModeSize, view->size());
EXPECT_EQ(kTabletModeSize, widget_size());
EXPECT_EQ(user_work_area_center(), widget_center());

Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_EQ(kClamshellModeSize, view->size());
EXPECT_EQ(kClamshellModeSize, widget_size());
EXPECT_EQ(user_work_area_center(), widget_center());
}

} // namespace ash

0 comments on commit ad93a98

Please sign in to comment.