Commit ad93a98b authored by Aga Wronska's avatar Aga Wronska Committed by Commit Bot

Make ParentAccessWidget adapt to tablet mode

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: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692805}
parent d46219a2
...@@ -799,6 +799,8 @@ void ParentAccessView::UpdatePreferredSize() { ...@@ -799,6 +799,8 @@ void ParentAccessView::UpdatePreferredSize() {
pin_keyboard_to_footer_spacer_->SetPreferredSize( pin_keyboard_to_footer_spacer_->SetPreferredSize(
GetPinKeyboardToFooterSpacerSize()); GetPinKeyboardToFooterSpacerSize());
SetPreferredSize(CalculatePreferredSize()); SetPreferredSize(CalculatePreferredSize());
if (GetWidget())
GetWidget()->CenterWindow(GetPreferredSize());
} }
void ParentAccessView::FocusSubmitButton() { void ParentAccessView::FocusSubmitButton() {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/work_area_insets.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/session_manager/session_manager_types.h" #include "components/session_manager/session_manager_types.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/events/event.h" #include "ui/events/event.h"
...@@ -74,6 +76,14 @@ class ParentAccessViewTest : public LoginTestBase { ...@@ -74,6 +76,14 @@ class ParentAccessViewTest : public LoginTestBase {
login_client_ = std::make_unique<MockLoginScreenClient>(); 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|. // Simulates mouse press event on a |button|.
void SimulateButtonPress(views::Button* button) { void SimulateButtonPress(views::Button* button) {
ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
...@@ -533,8 +543,10 @@ TEST_F(ParentAccessViewTest, BackwardTabKeyTraversal) { ...@@ -533,8 +543,10 @@ TEST_F(ParentAccessViewTest, BackwardTabKeyTraversal) {
EXPECT_TRUE(HasFocusInAnyChildView(test_api.access_code_view())); EXPECT_TRUE(HasFocusInAnyChildView(test_api.access_code_view()));
} }
using ParentAccessWidgetTest = ParentAccessViewTest;
// Tests that correct usage metric is reported. // Tests that correct usage metric is reported.
TEST_F(ParentAccessViewTest, UMAUsageMetric) { TEST_F(ParentAccessWidgetTest, UMAUsageMetric) {
ShowWidget(ParentAccessRequestReason::kUnlockTimeLimits); ShowWidget(ParentAccessRequestReason::kUnlockTimeLimits);
DismissWidget(); DismissWidget();
histogram_tester_.ExpectBucketCount( histogram_tester_.ExpectBucketCount(
...@@ -576,4 +588,47 @@ TEST_F(ParentAccessViewTest, UMAUsageMetric) { ...@@ -576,4 +588,47 @@ TEST_F(ParentAccessViewTest, UMAUsageMetric) {
ParentAccessView::kUMAParentAccessCodeUsage, 5); 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 } // 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