Commit a2e6af18 authored by erg@chromium.org's avatar erg@chromium.org

Continue threading context through unit tests.

- views_unittest now passes with the assert that checks that we have context.
- ash_unittest...is making progress towards that and this patch is already big.

BUG=161882

Review URL: https://codereview.chromium.org/11795004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175389 0039d316-1c4b-4281-b951-d872f2087c98
parent 7a97aa86
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/wm/coordinate_conversion.h" #include "ash/wm/coordinate_conversion.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/client/screen_position_client.h" #include "ui/aura/client/screen_position_client.h"
#include "ui/aura/root_window.h"
#include "ui/base/animation/throb_animation.h" #include "ui/base/animation/throb_animation.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/display.h" #include "ui/gfx/display.h"
...@@ -51,6 +52,9 @@ views::Widget* CreateWidget(const gfx::Rect& bounds, ...@@ -51,6 +52,9 @@ views::Widget* CreateWidget(const gfx::Rect& bounds,
params.transparent = true; params.transparent = true;
params.can_activate = false; params.can_activate = false;
params.keep_on_top = true; params.keep_on_top = true;
// We set the context to the primary root window; this is OK because the ash
// stacking controller will still place us in the correct RootWindow.
params.context = Shell::GetPrimaryRootWindow();
widget->set_focus_on_creation(false); widget->set_focus_on_creation(false);
widget->Init(params); widget->Init(params);
widget->SetVisibilityChangedAnimationsEnabled(false); widget->SetVisibilityChangedAnimationsEnabled(false);
......
...@@ -33,24 +33,6 @@ ...@@ -33,24 +33,6 @@
namespace ash { namespace ash {
namespace { namespace {
views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
const gfx::Rect& bounds,
bool child) {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
if (parent)
params.parent = parent->GetNativeView();
params.bounds = bounds;
params.child = child;
views::Widget* widget = new views::Widget;
widget->Init(params);
widget->Show();
return widget;
}
views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
return CreateTestWidgetWithParent(NULL, bounds, false);
}
void SetSecondaryDisplayLayout(DisplayLayout::Position position) { void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
DisplayController* display_controller = DisplayController* display_controller =
Shell::GetInstance()->display_controller(); Shell::GetInstance()->display_controller();
...@@ -104,7 +86,36 @@ class MoveWindowByClickEventFilter : public ui::EventHandler { ...@@ -104,7 +86,36 @@ class MoveWindowByClickEventFilter : public ui::EventHandler {
} // namespace } // namespace
typedef test::AshTestBase ExtendedDesktopTest; class ExtendedDesktopTest : public test::AshTestBase {
public:
views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
return CreateTestWidgetWithParentAndContext(
NULL, CurrentContext(), bounds, false);
}
views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
const gfx::Rect& bounds,
bool child) {
CHECK(parent);
return CreateTestWidgetWithParentAndContext(parent, NULL, bounds, child);
}
views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
gfx::NativeView context,
const gfx::Rect& bounds,
bool child) {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
if (parent)
params.parent = parent->GetNativeView();
params.context = context;
params.bounds = bounds;
params.child = child;
views::Widget* widget = new views::Widget;
widget->Init(params);
widget->Show();
return widget;
}
};
// Test conditions that root windows in extended desktop mode // Test conditions that root windows in extended desktop mode
// must satisfy. // must satisfy.
...@@ -170,8 +181,10 @@ TEST_F(ExtendedDesktopTest, SystemModal) { ...@@ -170,8 +181,10 @@ TEST_F(ExtendedDesktopTest, SystemModal) {
EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
// Open system modal. Make sure it's on 2nd root window and active. // Open system modal. Make sure it's on 2nd root window and active.
views::Widget* modal_widget = views::Widget::CreateWindowWithBounds( views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100)); new ModalWidgetDelegate(),
CurrentContext(),
gfx::Rect(1200, 100, 100, 100));
modal_widget->Show(); modal_widget->Show();
EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow()); EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
...@@ -608,8 +621,7 @@ TEST_F(ExtendedDesktopTest, OpenSystemTray) { ...@@ -608,8 +621,7 @@ TEST_F(ExtendedDesktopTest, OpenSystemTray) {
TEST_F(ExtendedDesktopTest, StayInSameRootWindow) { TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
UpdateDisplay("100x100,200x200"); UpdateDisplay("100x100,200x200");
Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
views::Widget* w1 = CreateTestWidgetWithParent( views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
NULL, gfx::Rect(10, 10, 50, 50), false);
EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
w1->SetBounds(gfx::Rect(150, 10, 50, 50)); w1->SetBounds(gfx::Rect(150, 10, 50, 50));
EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
......
...@@ -76,41 +76,42 @@ class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate, ...@@ -76,41 +76,42 @@ class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate,
DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
}; };
views::Widget* CreateTestWidget(const gfx::Rect& bounds) { } // namespace
views::Widget* widget =
views::Widget::CreateWindowWithBounds(NULL, bounds);
widget->Show();
return widget;
}
views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
views::Widget* widget =
views::Widget::CreateWindowWithBounds(new TestDelegate(true), bounds);
widget->Show();
return widget;
}
views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds, namespace test {
gfx::NativeWindow parent) {
views::Widget* widget =
views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
parent,
bounds);
widget->Show();
return widget;
}
aura::Window* GetModalContainer(aura::RootWindow* root_window) { class RootWindowControllerTest : public test::AshTestBase {
return Shell::GetContainer( public:
root_window, views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
ash::internal::kShellWindowId_SystemModalContainer); views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
} NULL, CurrentContext(), bounds);
widget->Show();
return widget;
}
} // namespace views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
new TestDelegate(true), CurrentContext(), bounds);
widget->Show();
return widget;
}
namespace test { views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds,
gfx::NativeWindow parent) {
views::Widget* widget =
views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
parent,
bounds);
widget->Show();
return widget;
}
typedef test::AshTestBase RootWindowControllerTest; aura::Window* GetModalContainer(aura::RootWindow* root_window) {
return Shell::GetContainer(
root_window,
ash::internal::kShellWindowId_SystemModalContainer);
}
};
TEST_F(RootWindowControllerTest, MoveWindows_Basic) { TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
UpdateDisplay("600x600,500x500"); UpdateDisplay("600x600,500x500");
......
...@@ -25,11 +25,11 @@ TEST_F(ScreenAshTest, Bounds) { ...@@ -25,11 +25,11 @@ TEST_F(ScreenAshTest, Bounds) {
Shell::GetPrimaryRootWindowController()->SetShelfAutoHideBehavior( Shell::GetPrimaryRootWindowController()->SetShelfAutoHideBehavior(
ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
views::Widget* primary = views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
views::Widget::CreateWindowWithBounds(NULL, gfx::Rect(10, 10, 100, 100)); NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
primary->Show(); primary->Show();
views::Widget* secondary = views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
views::Widget::CreateWindowWithBounds(NULL, gfx::Rect(610, 10, 100, 100)); NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
secondary->Show(); secondary->Show();
// Maximized bounds // Maximized bounds
...@@ -60,11 +60,11 @@ TEST_F(ScreenAshTest, Bounds) { ...@@ -60,11 +60,11 @@ TEST_F(ScreenAshTest, Bounds) {
TEST_F(ScreenAshTest, ConvertRect) { TEST_F(ScreenAshTest, ConvertRect) {
UpdateDisplay("600x600,500x500"); UpdateDisplay("600x600,500x500");
views::Widget* primary = views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
views::Widget::CreateWindowWithBounds(NULL, gfx::Rect(10, 10, 100, 100)); NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
primary->Show(); primary->Show();
views::Widget* secondary = views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
views::Widget::CreateWindowWithBounds(NULL, gfx::Rect(610, 10, 100, 100)); NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
secondary->Show(); secondary->Show();
EXPECT_EQ( EXPECT_EQ(
......
...@@ -4,8 +4,12 @@ ...@@ -4,8 +4,12 @@
#include "ash/shell/toplevel_window.h" #include "ash/shell/toplevel_window.h"
#include "ash/display/display_controller.h"
#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "ash/wm/property_util.h" #include "ash/wm/property_util.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -24,9 +28,14 @@ void ToplevelWindow::CreateToplevelWindow(const CreateParams& params) { ...@@ -24,9 +28,14 @@ void ToplevelWindow::CreateToplevelWindow(const CreateParams& params) {
static int count = 0; static int count = 0;
int x = count == 0 ? 150 : 750; int x = count == 0 ? 150 : 750;
count = (count + 1) % 2; count = (count + 1) % 2;
views::Widget* widget =
views::Widget::CreateWindowWithBounds(new ToplevelWindow(params), gfx::Rect bounds(x, 150, 300, 300);
gfx::Rect(x, 150, 300, 300)); gfx::Display display =
ash::Shell::GetInstance()->display_manager()->GetDisplayMatching(bounds);
aura::RootWindow* root = ash::Shell::GetInstance()->display_controller()->
GetRootWindowForDisplayId(display.id());
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
new ToplevelWindow(params), root, bounds);
widget->GetNativeView()->SetName("Examples:ToplevelWindow"); widget->GetNativeView()->SetName("Examples:ToplevelWindow");
if (params.persist_across_all_workspaces) { if (params.persist_across_all_workspaces) {
SetPersistsAcrossAllWorkspaces( SetPersistsAcrossAllWorkspaces(
......
...@@ -322,7 +322,8 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender, ...@@ -322,7 +322,8 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender,
ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(), ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(),
ui::MODAL_TYPE_WINDOW); ui::MODAL_TYPE_WINDOW);
} else if (sender == child_modal_button_) { } else if (sender == child_modal_button_) {
views::test::CreateChildModalParent(); views::test::CreateChildModalParent(
GetWidget()->GetNativeView()->GetRootWindow());
} else if (sender == transient_button_) { } else if (sender == transient_button_) {
NonModalTransient::OpenNonModalTransient(GetWidget()->GetNativeView()); NonModalTransient::OpenNonModalTransient(GetWidget()->GetNativeView());
} else if (sender == show_hide_window_button_) { } else if (sender == show_hide_window_button_) {
......
...@@ -31,12 +31,6 @@ namespace ash { ...@@ -31,12 +31,6 @@ namespace ash {
namespace { namespace {
views::Widget* CreateTestWindow(const views::Widget::InitParams& params) {
views::Widget* widget = new views::Widget;
widget->Init(params);
return widget;
}
aura::Window* GetDefaultContainer() { aura::Window* GetDefaultContainer() {
return Shell::GetContainer( return Shell::GetContainer(
Shell::GetPrimaryRootWindow(), Shell::GetPrimaryRootWindow(),
...@@ -82,22 +76,6 @@ void ExpectAllContainers() { ...@@ -82,22 +76,6 @@ void ExpectAllContainers() {
root_window, internal::kShellWindowId_OverlayContainer)); root_window, internal::kShellWindowId_OverlayContainer));
} }
void TestCreateWindow(views::Widget::InitParams::Type type,
bool always_on_top,
aura::Window* expected_container) {
views::Widget::InitParams widget_params(type);
widget_params.keep_on_top = always_on_top;
views::Widget* widget = CreateTestWindow(widget_params);
widget->Show();
EXPECT_TRUE(expected_container->Contains(
widget->GetNativeWindow()->parent())) <<
"TestCreateWindow: type=" << type << ", always_on_top=" << always_on_top;
widget->Close();
}
class ModalWindow : public views::WidgetDelegateView { class ModalWindow : public views::WidgetDelegateView {
public: public:
ModalWindow() {} ModalWindow() {}
...@@ -123,7 +101,33 @@ class ModalWindow : public views::WidgetDelegateView { ...@@ -123,7 +101,33 @@ class ModalWindow : public views::WidgetDelegateView {
} // namespace } // namespace
typedef test::AshTestBase ShellTest; class ShellTest : public test::AshTestBase {
public:
views::Widget* CreateTestWindow(views::Widget::InitParams params) {
views::Widget* widget = new views::Widget;
params.context = CurrentContext();
widget->Init(params);
return widget;
}
void TestCreateWindow(views::Widget::InitParams::Type type,
bool always_on_top,
aura::Window* expected_container) {
views::Widget::InitParams widget_params(type);
widget_params.keep_on_top = always_on_top;
views::Widget* widget = CreateTestWindow(widget_params);
widget->Show();
EXPECT_TRUE(
expected_container->Contains(widget->GetNativeWindow()->parent())) <<
"TestCreateWindow: type=" << type << ", always_on_top=" <<
always_on_top;
widget->Close();
}
};
TEST_F(ShellTest, CreateWindow) { TEST_F(ShellTest, CreateWindow) {
// Normal window should be created in default container. // Normal window should be created in default container.
......
...@@ -98,6 +98,14 @@ void AshTestBase::UpdateDisplay(const std::string& display_specs) { ...@@ -98,6 +98,14 @@ void AshTestBase::UpdateDisplay(const std::string& display_specs) {
display_manager_test_api.UpdateDisplay(display_specs); display_manager_test_api.UpdateDisplay(display_specs);
} }
aura::RootWindow* AshTestBase::CurrentContext() {
aura::RootWindow* root_window = Shell::GetActiveRootWindow();
if (!root_window)
root_window = Shell::GetPrimaryRootWindow();
DCHECK(root_window);
return root_window;
}
aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) { aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) {
return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect()); return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect());
} }
......
...@@ -56,6 +56,11 @@ class AshTestBase : public testing::Test { ...@@ -56,6 +56,11 @@ class AshTestBase : public testing::Test {
// See ash::test::DisplayManagerTestApi::UpdateDisplay for more details. // See ash::test::DisplayManagerTestApi::UpdateDisplay for more details.
void UpdateDisplay(const std::string& display_specs); void UpdateDisplay(const std::string& display_specs);
// Returns a RootWindow. Usually this is the active RootWindow, but that
// method can return NULL sometimes, and in those cases, we fall back on the
// primary RootWindow.
aura::RootWindow* CurrentContext();
// Versions of the functions in aura::test:: that go through our shell // Versions of the functions in aura::test:: that go through our shell
// StackingController instead of taking a parent. // StackingController instead of taking a parent.
aura::Window* CreateTestWindowInShellWithId(int id); aura::Window* CreateTestWindowInShellWithId(int id);
......
...@@ -79,6 +79,7 @@ class CustomFrameViewAshTest : public ash::test::AshTestBase { ...@@ -79,6 +79,7 @@ class CustomFrameViewAshTest : public ash::test::AshTestBase {
views::Widget* CreateWidget() { views::Widget* CreateWidget() {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
params.context = CurrentContext();
params.delegate = new TestWidgetDelegate; params.delegate = new TestWidgetDelegate;
widget->Init(params); widget->Init(params);
widget->Show(); widget->Show();
......
...@@ -78,40 +78,44 @@ class WindowRepaintChecker : public aura::WindowObserver { ...@@ -78,40 +78,44 @@ class WindowRepaintChecker : public aura::WindowObserver {
DISALLOW_COPY_AND_ASSIGN(WindowRepaintChecker); DISALLOW_COPY_AND_ASSIGN(WindowRepaintChecker);
}; };
// Creates a test widget that owns its native widget.
Widget* CreateTestWidget() {
Widget* widget = new Widget;
Widget::InitParams params;
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget->Init(params);
return widget;
}
Widget* CreateAlwaysOnTopWidget() {
Widget* widget = new Widget;
Widget::InitParams params;
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.keep_on_top = true;
widget->Init(params);
return widget;
}
Widget* CreateResizableWidget() {
Widget* widget = new Widget;
Widget::InitParams params;
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.keep_on_top = true;
params.delegate = new ResizableWidgetDelegate(widget);
params.type = Widget::InitParams::TYPE_WINDOW;
widget->Init(params);
return widget;
}
} // namespace } // namespace
namespace ash { namespace ash {
typedef ash::test::AshTestBase FramePainterTest; class FramePainterTest : public ash::test::AshTestBase {
public:
// Creates a test widget that owns its native widget.
Widget* CreateTestWidget() {
Widget* widget = new Widget;
Widget::InitParams params;
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.context = CurrentContext();
widget->Init(params);
return widget;
}
Widget* CreateAlwaysOnTopWidget() {
Widget* widget = new Widget;
Widget::InitParams params;
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.context = CurrentContext();
params.keep_on_top = true;
widget->Init(params);
return widget;
}
Widget* CreateResizableWidget() {
Widget* widget = new Widget;
Widget::InitParams params;
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.context = CurrentContext();
params.keep_on_top = true;
params.delegate = new ResizableWidgetDelegate(widget);
params.type = Widget::InitParams::TYPE_WINDOW;
widget->Init(params);
return widget;
}
};
TEST_F(FramePainterTest, Basics) { TEST_F(FramePainterTest, Basics) {
// Other tests might have created a FramePainter, so we cannot assert that // Other tests might have created a FramePainter, so we cannot assert that
......
...@@ -65,6 +65,7 @@ views::Widget* CreateAffordanceWidget(aura::RootWindow* root_window) { ...@@ -65,6 +65,7 @@ views::Widget* CreateAffordanceWidget(aura::RootWindow* root_window) {
params.keep_on_top = true; params.keep_on_top = true;
params.accept_events = false; params.accept_events = false;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.context = root_window;
params.transparent = true; params.transparent = true;
widget->Init(params); widget->Init(params);
widget->SetOpacity(0xFF); widget->SetOpacity(0xFF);
......
...@@ -299,6 +299,7 @@ TEST_F(ShelfLayoutManagerTest, DontReferenceLauncherAfterDeletion) { ...@@ -299,6 +299,7 @@ TEST_F(ShelfLayoutManagerTest, DontReferenceLauncherAfterDeletion) {
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200); params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
// Widget is now owned by the parent window. // Widget is now owned by the parent window.
widget->Init(params); widget->Init(params);
widget->SetFullscreen(true); widget->SetFullscreen(true);
...@@ -315,6 +316,7 @@ TEST_F(ShelfLayoutManagerTest, AutoHide) { ...@@ -315,6 +316,7 @@ TEST_F(ShelfLayoutManagerTest, AutoHide) {
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200); params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
// Widget is now owned by the parent window. // Widget is now owned by the parent window.
widget->Init(params); widget->Init(params);
widget->Maximize(); widget->Maximize();
...@@ -381,6 +383,7 @@ TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) { ...@@ -381,6 +383,7 @@ TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200); params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
// Widget is now owned by the parent window. // Widget is now owned by the parent window.
widget->Init(params); widget->Init(params);
widget->Maximize(); widget->Maximize();
...@@ -403,6 +406,7 @@ TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) { ...@@ -403,6 +406,7 @@ TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
views::Widget::InitParams lock_params( views::Widget::InitParams lock_params(
views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams::TYPE_WINDOW);
lock_params.bounds = gfx::Rect(0, 0, 200, 200); lock_params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
lock_params.parent = lock_container; lock_params.parent = lock_container;
// Widget is now owned by the parent window. // Widget is now owned by the parent window.
lock_widget->Init(lock_params); lock_widget->Init(lock_params);
...@@ -432,6 +436,7 @@ TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) { ...@@ -432,6 +436,7 @@ TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) {
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200); params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
// Widget is now owned by the parent window. // Widget is now owned by the parent window.
widget->Init(params); widget->Init(params);
widget->Show(); widget->Show();
...@@ -476,6 +481,7 @@ TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrLauncherFocused) { ...@@ -476,6 +481,7 @@ TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrLauncherFocused) {
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200); params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
// Widget is now owned by the parent window. // Widget is now owned by the parent window.
widget->Init(params); widget->Init(params);
widget->Show(); widget->Show();
...@@ -676,6 +682,7 @@ TEST_F(ShelfLayoutManagerTest, GestureDrag) { ...@@ -676,6 +682,7 @@ TEST_F(ShelfLayoutManagerTest, GestureDrag) {
views::Widget* widget = new views::Widget; views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200); params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params); widget->Init(params);
widget->Show(); widget->Show();
widget->Maximize(); widget->Maximize();
...@@ -850,6 +857,7 @@ TEST_F(ShelfLayoutManagerTest, WorkAreaChangeWorkspace) { ...@@ -850,6 +857,7 @@ TEST_F(ShelfLayoutManagerTest, WorkAreaChangeWorkspace) {
views::Widget* widget_one = new views::Widget; views::Widget* widget_one = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200); params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget_one->Init(params); widget_one->Init(params);
widget_one->Show(); widget_one->Show();
widget_one->Maximize(); widget_one->Maximize();
......
...@@ -591,8 +591,8 @@ TEST_F(SystemGestureEventFilterTest, LongPressAffordanceStateOnCaptureLoss) { ...@@ -591,8 +591,8 @@ TEST_F(SystemGestureEventFilterTest, LongPressAffordanceStateOnCaptureLoss) {
TEST_F(SystemGestureEventFilterTest, MultiFingerSwipeGestures) { TEST_F(SystemGestureEventFilterTest, MultiFingerSwipeGestures) {
aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
views::Widget* toplevel = views::Widget::CreateWindowWithBounds( views::Widget* toplevel = views::Widget::CreateWindowWithContextAndBounds(
new ResizableWidgetDelegate, gfx::Rect(0, 0, 100, 100)); new ResizableWidgetDelegate, root_window, gfx::Rect(0, 0, 100, 100));
toplevel->Show(); toplevel->Show();
const int kSteps = 15; const int kSteps = 15;
...@@ -647,8 +647,8 @@ TEST_F(SystemGestureEventFilterTest, MultiFingerSwipeGestures) { ...@@ -647,8 +647,8 @@ TEST_F(SystemGestureEventFilterTest, MultiFingerSwipeGestures) {
TEST_F(SystemGestureEventFilterTest, TwoFingerDrag) { TEST_F(SystemGestureEventFilterTest, TwoFingerDrag) {
gfx::Rect bounds(0, 0, 100, 100); gfx::Rect bounds(0, 0, 100, 100);
aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
views::Widget* toplevel = views::Widget::CreateWindowWithBounds( views::Widget* toplevel = views::Widget::CreateWindowWithContextAndBounds(
new ResizableWidgetDelegate, bounds); new ResizableWidgetDelegate, root_window, bounds);
toplevel->Show(); toplevel->Show();
const int kSteps = 15; const int kSteps = 15;
...@@ -703,8 +703,8 @@ TEST_F(SystemGestureEventFilterTest, TwoFingerDrag) { ...@@ -703,8 +703,8 @@ TEST_F(SystemGestureEventFilterTest, TwoFingerDrag) {
TEST_F(SystemGestureEventFilterTest, WindowsWithMaxSizeDontSnap) { TEST_F(SystemGestureEventFilterTest, WindowsWithMaxSizeDontSnap) {
gfx::Rect bounds(150, 150, 100, 100); gfx::Rect bounds(150, 150, 100, 100);
aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
views::Widget* toplevel = views::Widget::CreateWindowWithBounds( views::Widget* toplevel = views::Widget::CreateWindowWithContextAndBounds(
new MaxSizeWidgetDelegate, bounds); new MaxSizeWidgetDelegate, root_window, bounds);
toplevel->Show(); toplevel->Show();
const int kSteps = 15; const int kSteps = 15;
...@@ -760,8 +760,8 @@ TEST_F(SystemGestureEventFilterTest, WindowsWithMaxSizeDontSnap) { ...@@ -760,8 +760,8 @@ TEST_F(SystemGestureEventFilterTest, WindowsWithMaxSizeDontSnap) {
TEST_F(SystemGestureEventFilterTest, TwoFingerDragEdge) { TEST_F(SystemGestureEventFilterTest, TwoFingerDragEdge) {
gfx::Rect bounds(0, 0, 100, 100); gfx::Rect bounds(0, 0, 100, 100);
aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
views::Widget* toplevel = views::Widget::CreateWindowWithBounds( views::Widget* toplevel = views::Widget::CreateWindowWithContextAndBounds(
new ResizableWidgetDelegate, bounds); new ResizableWidgetDelegate, root_window, bounds);
toplevel->Show(); toplevel->Show();
const int kSteps = 15; const int kSteps = 15;
......
...@@ -362,9 +362,10 @@ TEST_F(WindowModalityControllerTest, TouchEvent) { ...@@ -362,9 +362,10 @@ TEST_F(WindowModalityControllerTest, TouchEvent) {
// |child| window. // |child| window.
// - Focus should follow the active window. // - Focus should follow the active window.
TEST_F(WindowModalityControllerTest, ChildModal) { TEST_F(WindowModalityControllerTest, ChildModal) {
views::test::ChildModalParent* delegate = new views::test::ChildModalParent; views::test::ChildModalParent* delegate =
views::Widget* widget = views::Widget::CreateWindowWithBounds( new views::test::ChildModalParent(CurrentContext());
delegate, gfx::Rect(0, 0, 400, 400)); views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400));
widget->Show(); widget->Show();
aura::Window* parent = widget->GetNativeView(); aura::Window* parent = widget->GetNativeView();
...@@ -421,9 +422,10 @@ TEST_F(WindowModalityControllerTest, ChildModal) { ...@@ -421,9 +422,10 @@ TEST_F(WindowModalityControllerTest, ChildModal) {
// Same as |ChildModal| test, but using |EventGenerator| rather than bypassing // Same as |ChildModal| test, but using |EventGenerator| rather than bypassing
// it by calling |ActivateWindow|. // it by calling |ActivateWindow|.
TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) { TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) {
views::test::ChildModalParent* delegate = new views::test::ChildModalParent; views::test::ChildModalParent* delegate =
views::Widget* widget = views::Widget::CreateWindowWithBounds( new views::test::ChildModalParent(CurrentContext());
delegate, gfx::Rect(0, 0, 400, 400)); views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400));
widget->Show(); widget->Show();
aura::Window* parent = widget->GetNativeView(); aura::Window* parent = widget->GetNativeView();
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#endif #endif
#if defined(USE_AURA) #if defined(USE_AURA)
#include "ui/aura/root_window.h"
#include "ui/aura/test/aura_test_helper.h" #include "ui/aura/test/aura_test_helper.h"
#endif #endif
...@@ -121,8 +122,14 @@ class AccessibilityEventRouterViewsTest ...@@ -121,8 +122,14 @@ class AccessibilityEventRouterViewsTest
} }
views::Widget* CreateWindowWithContents(views::View* contents) { views::Widget* CreateWindowWithContents(views::View* contents) {
return views::Widget::CreateWindowWithBounds( gfx::NativeView context = NULL;
#if defined(USE_AURA)
context = aura_test_helper_->root_window();
#endif
return views::Widget::CreateWindowWithContextAndBounds(
new AccessibilityWindowDelegate(contents), new AccessibilityWindowDelegate(contents),
context,
gfx::Rect(0, 0, 500, 500)); gfx::Rect(0, 0, 500, 500));
} }
......
...@@ -43,7 +43,16 @@ void FirstRunBubbleTest::SetUp() { ...@@ -43,7 +43,16 @@ void FirstRunBubbleTest::SetUp() {
} }
TEST_F(FirstRunBubbleTest, CreateAndClose) { TEST_F(FirstRunBubbleTest, CreateAndClose) {
FirstRunBubble* delegate = FirstRunBubble::ShowBubble(NULL, NULL); // Create the anchor and parent widgets.
views::Widget::InitParams params =
CreateParams(views::Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
scoped_ptr<views::Widget> anchor_widget(new views::Widget);
anchor_widget->Init(params);
anchor_widget->Show();
FirstRunBubble* delegate =
FirstRunBubble::ShowBubble(NULL, anchor_widget->GetContentsView());
EXPECT_TRUE(delegate != NULL); EXPECT_TRUE(delegate != NULL);
delegate->GetWidget()->CloseNow(); delegate->GetWidget()->CloseNow();
} }
...@@ -73,7 +73,7 @@ class TabTest : public views::ViewsTestBase { ...@@ -73,7 +73,7 @@ class TabTest : public views::ViewsTestBase {
TEST_F(TabTest, HitTestTopPixel) { TEST_F(TabTest, HitTestTopPixel) {
Widget widget; Widget widget;
Widget::InitParams params; Widget::InitParams params(CreateParams(Widget::InitParams::TYPE_WINDOW));
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds.SetRect(10, 20, 300, 400); params.bounds.SetRect(10, 20, 300, 400);
widget.Init(params); widget.Init(params);
......
...@@ -45,9 +45,10 @@ const SkColor kChildColor = SK_ColorWHITE; ...@@ -45,9 +45,10 @@ const SkColor kChildColor = SK_ColorWHITE;
} // namespace } // namespace
void CreateChildModalParent() { void CreateChildModalParent(gfx::NativeView context) {
Widget::CreateWindowWithBounds( Widget::CreateWindowWithContextAndBounds(
new ChildModalParent, new ChildModalParent(context),
context,
gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight))->Show(); gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight))->Show();
} }
...@@ -106,7 +107,7 @@ ui::ModalType ChildModalWindow::GetModalType() const { ...@@ -106,7 +107,7 @@ ui::ModalType ChildModalWindow::GetModalType() const {
return ui::MODAL_TYPE_CHILD; return ui::MODAL_TYPE_CHILD;
} }
ChildModalParent::ChildModalParent() ChildModalParent::ChildModalParent(gfx::NativeView context)
: ALLOW_THIS_IN_INITIALIZER_LIST(button_(new NativeTextButton( : ALLOW_THIS_IN_INITIALIZER_LIST(button_(new NativeTextButton(
this, ASCIIToUTF16("Show/Hide Child Modal Window")))), this, ASCIIToUTF16("Show/Hide Child Modal Window")))),
textfield_(new Textfield), textfield_(new Textfield),
...@@ -114,7 +115,9 @@ ChildModalParent::ChildModalParent() ...@@ -114,7 +115,9 @@ ChildModalParent::ChildModalParent()
modal_parent_(NULL), modal_parent_(NULL),
child_(NULL) { child_(NULL) {
Widget* widget = new Widget; Widget* widget = new Widget;
widget->Init(Widget::InitParams(Widget::InitParams::TYPE_CONTROL)); Widget::InitParams params(Widget::InitParams::TYPE_CONTROL);
params.context = context;
widget->Init(params);
widget->GetRootView()->set_background( widget->GetRootView()->set_background(
Background::CreateSolidBackground(kModalParentColor)); Background::CreateSolidBackground(kModalParentColor));
modal_parent_ = widget->GetNativeView(); modal_parent_ = widget->GetNativeView();
......
...@@ -17,13 +17,13 @@ class View; ...@@ -17,13 +17,13 @@ class View;
class Widget; class Widget;
namespace test { namespace test {
void CreateChildModalParent(); void CreateChildModalParent(gfx::NativeView context);
class ChildModalParent : public WidgetDelegateView, class ChildModalParent : public WidgetDelegateView,
public ButtonListener, public ButtonListener,
public WidgetObserver { public WidgetObserver {
public: public:
ChildModalParent(); ChildModalParent(gfx::NativeView context);
virtual ~ChildModalParent(); virtual ~ChildModalParent();
void ShowChild(); void ShowChild();
......
...@@ -840,7 +840,7 @@ TEST_F(ViewTest, DISABLED_Painting) { ...@@ -840,7 +840,7 @@ TEST_F(ViewTest, DISABLED_Painting) {
TEST_F(ViewTest, RemoveNotification) { TEST_F(ViewTest, RemoveNotification) {
ViewStorage* vs = ViewStorage::GetInstance(); ViewStorage* vs = ViewStorage::GetInstance();
Widget* widget = new Widget; Widget* widget = new Widget;
widget->Init(Widget::InitParams(Widget::InitParams::TYPE_POPUP)); widget->Init(CreateParams(Widget::InitParams::TYPE_POPUP));
View* root_view = widget->GetRootView(); View* root_view = widget->GetRootView();
View* v1 = new View; View* v1 = new View;
......
...@@ -612,7 +612,7 @@ TEST_F(WidgetOwnershipTest, Ownership_PlatformNativeWidgetOwnsWidget) { ...@@ -612,7 +612,7 @@ TEST_F(WidgetOwnershipTest, Ownership_PlatformNativeWidgetOwnsWidget) {
OwnershipTestState state; OwnershipTestState state;
Widget* widget = new OwnershipTestWidget(&state); Widget* widget = new OwnershipTestWidget(&state);
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.native_widget = params.native_widget =
new OwnershipTestNativeWidgetPlatform(widget, &state); new OwnershipTestNativeWidgetPlatform(widget, &state);
widget->Init(params); widget->Init(params);
...@@ -631,7 +631,7 @@ TEST_F(WidgetOwnershipTest, Ownership_ViewsNativeWidgetOwnsWidget) { ...@@ -631,7 +631,7 @@ TEST_F(WidgetOwnershipTest, Ownership_ViewsNativeWidgetOwnsWidget) {
Widget* toplevel = CreateTopLevelPlatformWidget(); Widget* toplevel = CreateTopLevelPlatformWidget();
Widget* widget = new OwnershipTestWidget(&state); Widget* widget = new OwnershipTestWidget(&state);
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.native_widget = params.native_widget =
new OwnershipTestNativeWidgetPlatform(widget, &state); new OwnershipTestNativeWidgetPlatform(widget, &state);
params.parent = toplevel->GetNativeView(); params.parent = toplevel->GetNativeView();
...@@ -655,7 +655,7 @@ TEST_F(WidgetOwnershipTest, ...@@ -655,7 +655,7 @@ TEST_F(WidgetOwnershipTest,
OwnershipTestState state; OwnershipTestState state;
Widget* widget = new OwnershipTestWidget(&state); Widget* widget = new OwnershipTestWidget(&state);
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.native_widget = params.native_widget =
new OwnershipTestNativeWidgetPlatform(widget, &state); new OwnershipTestNativeWidgetPlatform(widget, &state);
widget->Init(params); widget->Init(params);
...@@ -680,7 +680,7 @@ TEST_F(WidgetOwnershipTest, ...@@ -680,7 +680,7 @@ TEST_F(WidgetOwnershipTest,
Widget* toplevel = CreateTopLevelPlatformWidget(); Widget* toplevel = CreateTopLevelPlatformWidget();
Widget* widget = new OwnershipTestWidget(&state); Widget* widget = new OwnershipTestWidget(&state);
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.native_widget = params.native_widget =
new OwnershipTestNativeWidgetPlatform(widget, &state); new OwnershipTestNativeWidgetPlatform(widget, &state);
params.parent = toplevel->GetNativeView(); params.parent = toplevel->GetNativeView();
...@@ -706,7 +706,7 @@ TEST_F(WidgetOwnershipTest, ...@@ -706,7 +706,7 @@ TEST_F(WidgetOwnershipTest,
Widget* toplevel = CreateTopLevelPlatformWidget(); Widget* toplevel = CreateTopLevelPlatformWidget();
Widget* widget = new OwnershipTestWidget(&state); Widget* widget = new OwnershipTestWidget(&state);
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.native_widget = params.native_widget =
new OwnershipTestNativeWidgetPlatform(widget, &state); new OwnershipTestNativeWidgetPlatform(widget, &state);
params.parent = toplevel->GetNativeView(); params.parent = toplevel->GetNativeView();
......
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