This source file includes following definitions.
- ValidateStacking
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- last_event_type_
- reset
- received_touch
- last_event_type
- OnTouchEvent
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ui/wm/core/window_modality_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/test/capture_tracking_view.h"
#include "ui/views/test/child_modal_window.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_util.h"
namespace ash {
typedef test::AshTestBase WindowModalityControllerTest;
namespace {
bool ValidateStacking(aura::Window* parent, int ids[], int count) {
for (int i = 0; i < count; ++i) {
if (parent->children().at(i)->id() != ids[i])
return false;
}
return true;
}
}
TEST_F(WindowModalityControllerTest, BasicActivation) {
aura::test::TestWindowDelegate d;
scoped_ptr<aura::Window> w1(
CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
scoped_ptr<aura::Window> w11(
CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect()));
scoped_ptr<aura::Window> w12(
CreateTestWindowInShellWithDelegate(&d, -12, gfx::Rect()));
::wm::AddTransientChild(w1.get(), w11.get());
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
wm::ActivateWindow(w11.get());
EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
w12->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
::wm::AddTransientChild(w1.get(), w12.get());
wm::ActivateWindow(w12.get());
EXPECT_TRUE(wm::IsActiveWindow(w12.get()));
wm::ActivateWindow(w11.get());
EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
int check1[] = { -1, -12, -11 };
EXPECT_TRUE(ValidateStacking(w1->parent(), check1, arraysize(check1)));
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w12.get()));
int check2[] = { -1, -11, -12 };
EXPECT_TRUE(ValidateStacking(w1->parent(), check2, arraysize(check2)));
w12.reset();
EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
w11.reset();
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
}
TEST_F(WindowModalityControllerTest, NestedModals) {
aura::test::TestWindowDelegate d;
scoped_ptr<aura::Window> w1(
CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
scoped_ptr<aura::Window> w11(
CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect()));
scoped_ptr<aura::Window> w111(
CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect()));
scoped_ptr<aura::Window> w2(
CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
::wm::AddTransientChild(w1.get(), w11.get());
::wm::AddTransientChild(w11.get(), w111.get());
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
wm::ActivateWindow(w2.get());
EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
w111->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w111.get()));
int check1[] = { -2, -1, -11, -111 };
EXPECT_TRUE(ValidateStacking(w1->parent(), check1, arraysize(check1)));
wm::ActivateWindow(w11.get());
EXPECT_TRUE(wm::IsActiveWindow(w111.get()));
EXPECT_TRUE(ValidateStacking(w1->parent(), check1, arraysize(check1)));
wm::ActivateWindow(w111.get());
EXPECT_TRUE(wm::IsActiveWindow(w111.get()));
EXPECT_TRUE(ValidateStacking(w1->parent(), check1, arraysize(check1)));
wm::ActivateWindow(w2.get());
EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
int check2[] = { -1, -11, -111, -2 };
EXPECT_TRUE(ValidateStacking(w1->parent(), check2, arraysize(check2)));
w2.reset();
EXPECT_TRUE(wm::IsActiveWindow(w111.get()));
w111.reset();
EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
w11.reset();
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
}
TEST_F(WindowModalityControllerTest, NestedModalsOuterClosed) {
aura::test::TestWindowDelegate d;
scoped_ptr<aura::Window> w1(
CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
scoped_ptr<aura::Window> w11(
CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect()));
aura::Window* w111 =
CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect());
scoped_ptr<aura::Window> w2(
CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
::wm::AddTransientChild(w1.get(), w11.get());
::wm::AddTransientChild(w11.get(), w111);
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
wm::ActivateWindow(w2.get());
EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
w111->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w111));
w111->Hide();
EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
w11.reset();
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
}
TEST_F(WindowModalityControllerTest, Events) {
aura::test::TestWindowDelegate d;
scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1,
gfx::Rect(0, 0, 100, 100)));
scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11,
gfx::Rect(20, 20, 50, 50)));
::wm::AddTransientChild(w1.get(), w11.get());
{
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
gfx::Point(10, 10));
generator.ClickLeftButton();
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
}
w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
{
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
gfx::Point(10, 10));
generator.ClickLeftButton();
EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
}
}
TEST_F(WindowModalityControllerTest, GetModalTransient) {
aura::test::TestWindowDelegate d;
scoped_ptr<aura::Window> w1(
CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
scoped_ptr<aura::Window> w11(
aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
scoped_ptr<aura::Window> w2(
CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
aura::Window* wt;
wt = ::wm::GetModalTransient(w1.get());
ASSERT_EQ(static_cast<aura::Window*>(NULL), wt);
::wm::AddTransientChild(w1.get(), w2.get());
ASSERT_EQ(2U, w1->parent()->children().size());
EXPECT_EQ(-2, w1->parent()->children().at(1)->id());
wt = ::wm::GetModalTransient(w1.get());
ASSERT_NE(static_cast<aura::Window*>(NULL), wt);
EXPECT_EQ(-2, wt->id());
wt = ::wm::GetModalTransient(w11.get());
ASSERT_NE(static_cast<aura::Window*>(NULL), wt);
EXPECT_EQ(-2, wt->id());
}
TEST_F(WindowModalityControllerTest, ChangeCapture) {
views::Widget* widget = views::Widget::CreateWindowWithContext(
NULL, Shell::GetPrimaryRootWindow());
scoped_ptr<aura::Window> widget_window(widget->GetNativeView());
views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView;
widget->client_view()->AddChildView(view);
widget->SetBounds(gfx::Rect(0, 0, 200, 200));
view->SetBoundsRect(widget->client_view()->GetLocalBounds());
widget->Show();
gfx::Point center(view->width() / 2, view->height() / 2);
views::View::ConvertPointToScreen(view, ¢er);
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center);
generator.PressLeftButton();
EXPECT_TRUE(view->got_press());
views::Widget* modal_widget =
views::Widget::CreateWindowWithParent(NULL, widget->GetNativeView());
scoped_ptr<aura::Window> modal_window(modal_widget->GetNativeView());
modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
views::test::CaptureTrackingView* modal_view =
new views::test::CaptureTrackingView;
modal_widget->client_view()->AddChildView(modal_view);
modal_widget->SetBounds(gfx::Rect(50, 50, 200, 200));
modal_view->SetBoundsRect(modal_widget->client_view()->GetLocalBounds());
modal_widget->Show();
EXPECT_TRUE(view->got_capture_lost());
generator.ReleaseLeftButton();
view->reset();
EXPECT_FALSE(modal_view->got_capture_lost());
EXPECT_FALSE(modal_view->got_press());
gfx::Point modal_center(modal_view->width() / 2, modal_view->height() / 2);
views::View::ConvertPointToScreen(modal_view, &modal_center);
generator.MoveMouseTo(modal_center, 1);
generator.PressLeftButton();
EXPECT_TRUE(modal_view->got_press());
EXPECT_FALSE(modal_view->got_capture_lost());
EXPECT_FALSE(view->got_capture_lost());
EXPECT_FALSE(view->got_press());
}
class TouchTrackerWindowDelegate : public aura::test::TestWindowDelegate {
public:
TouchTrackerWindowDelegate()
: received_touch_(false),
last_event_type_(ui::ET_UNKNOWN) {
}
virtual ~TouchTrackerWindowDelegate() {}
void reset() {
received_touch_ = false;
last_event_type_ = ui::ET_UNKNOWN;
}
bool received_touch() const { return received_touch_; }
ui::EventType last_event_type() const { return last_event_type_; }
private:
virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
received_touch_ = true;
last_event_type_ = event->type();
aura::test::TestWindowDelegate::OnTouchEvent(event);
}
bool received_touch_;
ui::EventType last_event_type_;
DISALLOW_COPY_AND_ASSIGN(TouchTrackerWindowDelegate);
};
TEST_F(WindowModalityControllerTest, TouchEvent) {
TouchTrackerWindowDelegate d1;
scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d1,
-1, gfx::Rect(0, 0, 100, 100)));
TouchTrackerWindowDelegate d11;
scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d11,
-11, gfx::Rect(20, 20, 50, 50)));
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
gfx::Point(10, 10));
::wm::AddTransientChild(w1.get(), w11.get());
d1.reset();
d11.reset();
{
generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10));
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
EXPECT_TRUE(d1.received_touch());
EXPECT_FALSE(d11.received_touch());
}
{
generator.PressTouch();
generator.MoveTouch(gfx::Point(10, 10));
d1.reset();
d11.reset();
w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
EXPECT_TRUE(d1.received_touch());
EXPECT_EQ(ui::ET_TOUCH_CANCELLED, d1.last_event_type());
EXPECT_FALSE(d11.received_touch());
}
}
TEST_F(WindowModalityControllerTest, ChildModal) {
views::test::ChildModalParent* delegate =
new views::test::ChildModalParent(CurrentContext());
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400));
widget->Show();
aura::Window* parent = widget->GetNativeView();
EXPECT_TRUE(wm::IsActiveWindow(parent));
aura::Window* modal_parent = delegate->GetModalParent();
EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent);
EXPECT_NE(parent, modal_parent);
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
delegate->ShowChild();
aura::Window* child = delegate->GetChild();
EXPECT_NE(static_cast<aura::Window*>(NULL), child);
EXPECT_TRUE(wm::IsActiveWindow(child));
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
EXPECT_FALSE(wm::IsActiveWindow(parent));
EXPECT_TRUE(child->HasFocus());
EXPECT_FALSE(modal_parent->HasFocus());
EXPECT_FALSE(parent->HasFocus());
wm::ActivateWindow(modal_parent);
EXPECT_TRUE(wm::IsActiveWindow(child));
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
EXPECT_FALSE(wm::IsActiveWindow(parent));
EXPECT_TRUE(child->HasFocus());
EXPECT_FALSE(modal_parent->HasFocus());
EXPECT_FALSE(parent->HasFocus());
wm::ActivateWindow(parent);
EXPECT_FALSE(wm::IsActiveWindow(child));
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
EXPECT_TRUE(wm::IsActiveWindow(parent));
EXPECT_FALSE(child->HasFocus());
EXPECT_FALSE(modal_parent->HasFocus());
EXPECT_TRUE(parent->HasFocus());
wm::ActivateWindow(child);
EXPECT_TRUE(wm::IsActiveWindow(child));
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
EXPECT_FALSE(wm::IsActiveWindow(parent));
EXPECT_TRUE(child->HasFocus());
EXPECT_FALSE(modal_parent->HasFocus());
EXPECT_FALSE(parent->HasFocus());
}
TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) {
views::test::ChildModalParent* delegate =
new views::test::ChildModalParent(CurrentContext());
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400));
widget->Show();
aura::Window* parent = widget->GetNativeView();
EXPECT_TRUE(wm::IsActiveWindow(parent));
aura::Window* modal_parent = delegate->GetModalParent();
EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent);
EXPECT_NE(parent, modal_parent);
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
delegate->ShowChild();
aura::Window* child = delegate->GetChild();
EXPECT_NE(static_cast<aura::Window*>(NULL), child);
EXPECT_TRUE(wm::IsActiveWindow(child));
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
EXPECT_FALSE(wm::IsActiveWindow(parent));
EXPECT_TRUE(child->HasFocus());
EXPECT_FALSE(modal_parent->HasFocus());
EXPECT_FALSE(parent->HasFocus());
{
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(),
parent->bounds().origin() +
gfx::Vector2d(10, parent->bounds().height() - 10));
generator.ClickLeftButton();
generator.ClickLeftButton();
EXPECT_TRUE(wm::IsActiveWindow(child));
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
EXPECT_FALSE(wm::IsActiveWindow(parent));
EXPECT_TRUE(child->HasFocus());
EXPECT_FALSE(modal_parent->HasFocus());
EXPECT_FALSE(parent->HasFocus());
}
{
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(),
parent->bounds().origin() + gfx::Vector2d(10, 10));
generator.ClickLeftButton();
EXPECT_FALSE(wm::IsActiveWindow(child));
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
EXPECT_TRUE(wm::IsActiveWindow(parent));
EXPECT_FALSE(child->HasFocus());
EXPECT_FALSE(modal_parent->HasFocus());
EXPECT_TRUE(parent->HasFocus());
}
{
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(),
child->bounds().origin() + gfx::Vector2d(10, 10));
generator.ClickLeftButton();
EXPECT_TRUE(wm::IsActiveWindow(child));
EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
EXPECT_FALSE(wm::IsActiveWindow(parent));
EXPECT_TRUE(child->HasFocus());
EXPECT_FALSE(modal_parent->HasFocus());
EXPECT_FALSE(parent->HasFocus());
}
}
TEST_F(WindowModalityControllerTest, WindowModalAncestor) {
aura::test::TestWindowDelegate d;
scoped_ptr<aura::Window> w1(
CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
scoped_ptr<aura::Window> w2(
aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
scoped_ptr<aura::Window> w3(
aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get()));
scoped_ptr<aura::Window> w4(
CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
::wm::AddTransientChild(w1.get(), w4.get());
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
wm::ActivateWindow(w2.get());
EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
wm::ActivateWindow(w3.get());
EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
wm::ActivateWindow(w4.get());
EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
}
TEST_F(WindowModalityControllerTest, ChildModalAncestor) {
aura::test::TestWindowDelegate d;
scoped_ptr<aura::Window> w1(
CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
scoped_ptr<aura::Window> w2(
aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
scoped_ptr<aura::Window> w3(
aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get()));
scoped_ptr<aura::Window> w4(
CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD);
::wm::SetModalParent(w4.get(), w2.get());
::wm::AddTransientChild(w1.get(), w4.get());
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
wm::ActivateWindow(w2.get());
EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
wm::ActivateWindow(w3.get());
EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
wm::ActivateWindow(w4.get());
EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
}
}