This source file includes following definitions.
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- QuitNestedLoopAndCloseWidget
- TEST_F
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "base/bind.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/public/dispatcher_client.h"
namespace views {
typedef ViewsTestBase DesktopNativeWidgetAuraTest;
TEST_F(DesktopNativeWidgetAuraTest, CreateWithParentNotInRootWindow) {
scoped_ptr<aura::Window> window(new aura::Window(NULL));
Widget widget;
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.parent = window.get();
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.native_widget = new DesktopNativeWidgetAura(&widget);
widget.Init(params);
}
TEST_F(DesktopNativeWidgetAuraTest, DesktopAuraWindowSizeTest) {
Widget widget;
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.native_widget = new DesktopNativeWidgetAura(&widget);
widget.Init(init_params);
gfx::Rect bounds(0, 0, 100, 100);
widget.SetBounds(bounds);
widget.Show();
EXPECT_EQ(bounds.ToString(),
widget.GetNativeView()->GetRootWindow()->bounds().ToString());
EXPECT_EQ(bounds.ToString(), widget.GetNativeView()->bounds().ToString());
EXPECT_EQ(bounds.ToString(),
widget.GetNativeView()->parent()->bounds().ToString());
gfx::Rect new_bounds(0, 0, 200, 200);
widget.SetBounds(new_bounds);
EXPECT_EQ(new_bounds.ToString(),
widget.GetNativeView()->GetRootWindow()->bounds().ToString());
EXPECT_EQ(new_bounds.ToString(), widget.GetNativeView()->bounds().ToString());
EXPECT_EQ(new_bounds.ToString(),
widget.GetNativeView()->parent()->bounds().ToString());
}
TEST_F(DesktopNativeWidgetAuraTest, NativeViewInitiallyHidden) {
Widget widget;
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW);
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.native_widget = new DesktopNativeWidgetAura(&widget);
widget.Init(init_params);
EXPECT_FALSE(widget.GetNativeView()->IsVisible());
}
TEST_F(DesktopNativeWidgetAuraTest, GlobalCursorState) {
Widget widget_a;
Widget::InitParams init_params_a =
CreateParams(Widget::InitParams::TYPE_WINDOW);
init_params_a.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
DesktopNativeWidgetAura* desktop_native_widget_aura_a =
new DesktopNativeWidgetAura(&widget_a);
init_params_a.native_widget = desktop_native_widget_aura_a;
widget_a.Init(init_params_a);
Widget widget_b;
Widget::InitParams init_params_b =
CreateParams(Widget::InitParams::TYPE_WINDOW);
init_params_b.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
DesktopNativeWidgetAura* desktop_native_widget_aura_b =
new DesktopNativeWidgetAura(&widget_b);
init_params_b.native_widget = desktop_native_widget_aura_b;
widget_b.Init(init_params_b);
aura::client::CursorClient* cursor_client_a = aura::client::GetCursorClient(
desktop_native_widget_aura_a->host()->window());
aura::client::CursorClient* cursor_client_b = aura::client::GetCursorClient(
desktop_native_widget_aura_b->host()->window());
EXPECT_FALSE(cursor_client_a->IsCursorLocked());
EXPECT_FALSE(cursor_client_b->IsCursorLocked());
cursor_client_a->LockCursor();
EXPECT_TRUE(cursor_client_a->IsCursorLocked());
EXPECT_TRUE(cursor_client_b->IsCursorLocked());
cursor_client_b->UnlockCursor();
EXPECT_FALSE(cursor_client_a->IsCursorLocked());
EXPECT_FALSE(cursor_client_b->IsCursorLocked());
EXPECT_TRUE(cursor_client_a->IsCursorVisible());
EXPECT_TRUE(cursor_client_b->IsCursorVisible());
EXPECT_TRUE(cursor_client_a->IsMouseEventsEnabled());
EXPECT_TRUE(cursor_client_b->IsMouseEventsEnabled());
cursor_client_b->DisableMouseEvents();
EXPECT_FALSE(cursor_client_a->IsCursorVisible());
EXPECT_FALSE(cursor_client_b->IsCursorVisible());
EXPECT_FALSE(cursor_client_a->IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client_b->IsMouseEventsEnabled());
cursor_client_a->EnableMouseEvents();
EXPECT_TRUE(cursor_client_a->IsCursorVisible());
EXPECT_TRUE(cursor_client_b->IsCursorVisible());
EXPECT_TRUE(cursor_client_a->IsMouseEventsEnabled());
EXPECT_TRUE(cursor_client_b->IsMouseEventsEnabled());
EXPECT_EQ(ui::kCursorNone, cursor_client_a->GetCursor().native_type());
EXPECT_EQ(ui::kCursorNone, cursor_client_b->GetCursor().native_type());
cursor_client_b->SetCursor(ui::kCursorPointer);
EXPECT_EQ(ui::kCursorPointer, cursor_client_a->GetCursor().native_type());
EXPECT_EQ(ui::kCursorPointer, cursor_client_b->GetCursor().native_type());
cursor_client_a->HideCursor();
EXPECT_FALSE(cursor_client_a->IsCursorVisible());
EXPECT_FALSE(cursor_client_b->IsCursorVisible());
EXPECT_TRUE(cursor_client_a->IsMouseEventsEnabled());
EXPECT_TRUE(cursor_client_b->IsMouseEventsEnabled());
cursor_client_b->LockCursor();
cursor_client_a->ShowCursor();
EXPECT_FALSE(cursor_client_a->IsCursorVisible());
EXPECT_FALSE(cursor_client_b->IsCursorVisible());
cursor_client_b->UnlockCursor();
EXPECT_TRUE(cursor_client_a->IsCursorVisible());
EXPECT_TRUE(cursor_client_b->IsCursorVisible());
}
TEST_F(DesktopNativeWidgetAuraTest, DontAccessContentWindowDuringDestruction) {
aura::test::TestWindowDelegate delegate;
{
Widget widget;
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW);
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
DesktopNativeWidgetAura* desktop_native_widget_aura =
new DesktopNativeWidgetAura(&widget);
init_params.native_widget = desktop_native_widget_aura;
widget.Init(init_params);
aura::Window* window = new aura::Window(&delegate);
window->Show();
widget.GetNativeWindow()->parent()->AddChild(window);
widget.Show();
}
}
void QuitNestedLoopAndCloseWidget(scoped_ptr<Widget> widget,
aura::client::DispatcherClient* client) {
client->QuitNestedMessageLoop();
}
TEST_F(DesktopNativeWidgetAuraTest, WidgetCanBeDestroyedFromNestedLoop) {
scoped_ptr<Widget> widget(new Widget);
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.native_widget = new DesktopNativeWidgetAura(widget.get());
widget->Init(params);
widget->Show();
aura::Window* window = widget->GetNativeView();
aura::Window* root = window->GetRootWindow();
aura::client::DispatcherClient* client =
aura::client::GetDispatcherClient(root);
message_loop()->PostTask(FROM_HERE,
base::Bind(&QuitNestedLoopAndCloseWidget, base::Passed(&widget), client));
client->RunWithDispatcher(NULL);
}
}