Commit 26af59f1 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Use DragEventGenerator for SplitView Resize test

This also adds extra scenarios.
* Resizing with overview on the other side.
* touch event

I also found the scenario that splitview controller can be
called recursively during shutdown, which is fixed by the change
in SplitViewController

Bug: None
Change-Id: I293ed17bba4961d338ac0f9a389f42f8f233d4ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1637244
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666091}
parent a1add4d0
...@@ -261,7 +261,9 @@ class SplitViewController::DividerSnapAnimation ...@@ -261,7 +261,9 @@ class SplitViewController::DividerSnapAnimation
CurrentValueBetween(starting_position_, ending_position_); CurrentValueBetween(starting_position_, ending_position_);
split_view_controller_->NotifyDividerPositionChanged(); split_view_controller_->NotifyDividerPositionChanged();
split_view_controller_->UpdateSnappedWindowsAndDividerBounds(); split_view_controller_->UpdateSnappedWindowsAndDividerBounds();
split_view_controller_->SetWindowsTransformDuringResizing(); // Updating the window may stop animation.
if (is_animating())
split_view_controller_->SetWindowsTransformDuringResizing();
} }
SplitViewController* split_view_controller_; SplitViewController* split_view_controller_;
...@@ -672,8 +674,11 @@ void SplitViewController::EndSplitView(EndReason end_reason) { ...@@ -672,8 +674,11 @@ void SplitViewController::EndSplitView(EndReason end_reason) {
const bool is_divider_animating = IsDividerAnimating(); const bool is_divider_animating = IsDividerAnimating();
if (is_resizing_ || is_divider_animating) { if (is_resizing_ || is_divider_animating) {
is_resizing_ = false; is_resizing_ = false;
if (is_divider_animating) if (is_divider_animating) {
StopAndShoveAnimatedDivider(); // Don't call StopAndShoveAnimatedDivider as it will call observers.
divider_snap_animation_->Stop();
divider_position_ = divider_snap_animation_->ending_position();
}
EndResizeImpl(); EndResizeImpl();
} }
......
...@@ -3900,6 +3900,8 @@ static_library("test_support") { ...@@ -3900,6 +3900,8 @@ static_library("test_support") {
if (is_chromeos) { if (is_chromeos) {
sources += [ sources += [
"ash/ash_test_util.cc",
"ash/ash_test_util.h",
"ash/fake_tablet_mode_controller.cc", "ash/fake_tablet_mode_controller.cc",
"ash/fake_tablet_mode_controller.h", "ash/fake_tablet_mode_controller.h",
"ash/test_login_screen.cc", "ash/test_login_screen.cc",
......
// Copyright 2019 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 "chrome/browser/ui/ash/ash_test_util.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/public/cpp/window_state_type.h"
#include "base/run_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/base/test/ui_controls.h"
#include "ui/wm/core/window_util.h"
namespace test {
namespace {
// Wait until the window's state changes to given the snapped state.
// The window should stay alive, so no need to observer destroying.
class SnapWaiter : public aura::WindowObserver {
public:
SnapWaiter(aura::Window* window, ash::WindowStateType type)
: window_(window), type_(type) {
window->AddObserver(this);
}
~SnapWaiter() override { window_->RemoveObserver(this); }
// aura::WindowObserver:
void OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) override {
if (key == ash::kWindowStateTypeKey && IsSnapped())
run_loop_.Quit();
}
void Wait() { run_loop_.Run(); }
bool IsSnapped() const {
return window_->GetProperty(ash::kWindowStateTypeKey) == type_;
}
private:
aura::Window* window_;
ash::WindowStateType type_;
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(SnapWaiter);
};
} // namespace
void ActivateAndSnapWindow(aura::Window* window, ash::WindowStateType type) {
DCHECK(window);
if (!wm::IsActiveWindow(window))
wm::ActivateWindow(window);
ASSERT_TRUE(wm::IsActiveWindow(window));
SnapWaiter snap_waiter(window, type);
ASSERT_TRUE(type == ash::WindowStateType::kRightSnapped ||
type == ash::WindowStateType::kLeftSnapped);
// Early return if it's already snapped.
if (snap_waiter.IsSnapped())
return;
ui_controls::SendKeyPress(window,
type == ash::WindowStateType::kLeftSnapped
? ui::VKEY_OEM_4
: ui::VKEY_OEM_6,
/*control=*/false,
/*shift=*/false,
/*alt=*/true,
/*command=*/false);
snap_waiter.Wait();
}
} // namespace test
// Copyright 2019 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.
#ifndef CHROME_BROWSER_UI_ASH_ASH_TEST_UTIL_H_
#define CHROME_BROWSER_UI_ASH_ASH_TEST_UTIL_H_
namespace aura {
class Window;
}
namespace ash {
enum class WindowStateType;
}
namespace test {
// The snap window. This will activate the |window|.
void ActivateAndSnapWindow(aura::Window* window, ash::WindowStateType type);
} // namespace test
#endif // CHROME_BROWSER_UI_ASH_ASH_TEST_UTIL_H_
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/public/cpp/window_properties.h"
#include "ash/public/cpp/window_state_type.h" #include "ash/public/cpp/window_state_type.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "chrome/browser/ui/ash/ash_test_util.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/interactive_test_utils.h"
...@@ -107,41 +107,6 @@ class MultiPointProducer ...@@ -107,41 +107,6 @@ class MultiPointProducer
DISALLOW_COPY_AND_ASSIGN(MultiPointProducer); DISALLOW_COPY_AND_ASSIGN(MultiPointProducer);
}; };
// Wait until the window's state changed to given snapped state.
// The window should stay alive, so no need to observer destroying.
class SnapWaiter : public aura::WindowObserver {
public:
SnapWaiter(aura::Window* window, ash::WindowStateType type)
: window_(window), type_(type) {
window->AddObserver(this);
}
~SnapWaiter() override { window_->RemoveObserver(this); }
// aura::WindowObserver:
void OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) override {
if (key == ash::kWindowStateTypeKey && IsSnapped())
run_loop_.Quit();
}
void Wait() {
if (!IsSnapped())
run_loop_.Run();
}
private:
bool IsSnapped() const {
return window_->GetProperty(ash::kWindowStateTypeKey) == type_;
}
aura::Window* window_;
ash::WindowStateType type_;
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(SnapWaiter);
};
} // namespace } // namespace
// Test window resize performance in clamshell mode. // Test window resize performance in clamshell mode.
...@@ -191,13 +156,8 @@ class WindowResizeTest ...@@ -191,13 +156,8 @@ class WindowResizeTest
IN_PROC_BROWSER_TEST_P(WindowResizeTest, Single) { IN_PROC_BROWSER_TEST_P(WindowResizeTest, Single) {
aura::Window* browser_window = browser()->window()->GetNativeWindow(); aura::Window* browser_window = browser()->window()->GetNativeWindow();
SnapWaiter snap_waiter(browser_window, ash::WindowStateType::kLeftSnapped); test::ActivateAndSnapWindow(browser_window,
ui_controls::SendKeyPress(browser_window, ui::VKEY_OEM_4, ash::WindowStateType::kLeftSnapped);
/*control=*/false,
/*shift=*/false,
/*alt=*/true,
/*command=*/false);
snap_waiter.Wait();
gfx::Rect bounds = browser_window->GetBoundsInScreen(); gfx::Rect bounds = browser_window->GetBoundsInScreen();
gfx::Point start_point = gfx::Point(bounds.right_center()); gfx::Point start_point = gfx::Point(bounds.right_center());
...@@ -221,15 +181,8 @@ IN_PROC_BROWSER_TEST_P(WindowResizeTest, Single) { ...@@ -221,15 +181,8 @@ IN_PROC_BROWSER_TEST_P(WindowResizeTest, Single) {
IN_PROC_BROWSER_TEST_P(WindowResizeTest, Multi) { IN_PROC_BROWSER_TEST_P(WindowResizeTest, Multi) {
aura::Window* browser_window = browser()->window()->GetNativeWindow(); aura::Window* browser_window = browser()->window()->GetNativeWindow();
{ test::ActivateAndSnapWindow(browser_window,
SnapWaiter snap_waiter(browser_window, ash::WindowStateType::kLeftSnapped); ash::WindowStateType::kLeftSnapped);
ui_controls::SendKeyPress(browser_window, ui::VKEY_OEM_4,
/*control=*/false,
/*shift=*/false,
/*alt=*/true,
/*command=*/false);
snap_waiter.Wait();
}
Browser* browser2 = CreateBrowser(browser()->profile()); Browser* browser2 = CreateBrowser(browser()->profile());
if (use_ntp()) { if (use_ntp()) {
...@@ -237,18 +190,10 @@ IN_PROC_BROWSER_TEST_P(WindowResizeTest, Multi) { ...@@ -237,18 +190,10 @@ IN_PROC_BROWSER_TEST_P(WindowResizeTest, Multi) {
ui_test_utils::NavigateToURL(browser2, ntp_url); ui_test_utils::NavigateToURL(browser2, ntp_url);
} }
aura::Window* browser_window2 = browser2->window()->GetNativeWindow();
// Snap Right // Snap Right
{ test::ActivateAndSnapWindow(browser_window2,
aura::Window* browser_window2 = browser2->window()->GetNativeWindow(); ash::WindowStateType::kRightSnapped);
SnapWaiter snap_waiter(browser_window2,
ash::WindowStateType::kRightSnapped);
ui_controls::SendKeyPress(browser_window2, ui::VKEY_OEM_6,
/*control=*/false,
/*shift=*/false,
/*alt=*/true,
/*command=*/false);
snap_waiter.Wait();
}
gfx::Rect bounds = browser_window->GetBoundsInScreen(); gfx::Rect bounds = browser_window->GetBoundsInScreen();
gfx::Point start_point = gfx::Point(bounds.right_center()); gfx::Point start_point = gfx::Point(bounds.right_center());
......
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