Commit e5bbe9cb authored by jamescook's avatar jamescook Committed by Commit bot

Add CreateTestWidget() to AshTestBase, collapse duplicates

This eliminates several near-identical copies of this function.

BUG=none
TEST=ash_unittests

Review-Url: https://codereview.chromium.org/2144003003
Cr-Commit-Position: refs/heads/master@{#405501}
parent 27b62f45
...@@ -42,23 +42,6 @@ namespace test { ...@@ -42,23 +42,6 @@ namespace test {
namespace { namespace {
std::unique_ptr<views::Widget> CreateTestWidget(views::WidgetDelegate* delegate,
int container_id) {
std::unique_ptr<views::Widget> widget(new views::Widget);
views::Widget::InitParams params;
params.delegate = delegate;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(0, 0, 100, 100);
WmShell::Get()
->GetPrimaryRootWindow()
->GetRootWindowController()
->ConfigureWidgetInitParamsForContainer(widget.get(), container_id,
&params);
widget->Init(params);
widget->Show();
return widget;
}
// Trivial item implementation that tracks its views for testing. // Trivial item implementation that tracks its views for testing.
class TestItem : public SystemTrayItem { class TestItem : public SystemTrayItem {
public: public:
...@@ -404,8 +387,8 @@ TEST_F(SystemTrayTest, PersistentBubble) { ...@@ -404,8 +387,8 @@ TEST_F(SystemTrayTest, PersistentBubble) {
TestItem* test_item = new TestItem; TestItem* test_item = new TestItem;
tray->AddTrayItem(test_item); tray->AddTrayItem(test_item);
std::unique_ptr<views::Widget> widget( std::unique_ptr<views::Widget> widget(CreateTestWidget(
CreateTestWidget(nullptr, kShellWindowId_DefaultContainer)); nullptr, kShellWindowId_DefaultContainer, gfx::Rect(0, 0, 100, 100)));
// Tests for usual default view while activating a window. // Tests for usual default view while activating a window.
tray->ShowDefaultView(BUBBLE_CREATE_NEW); tray->ShowDefaultView(BUBBLE_CREATE_NEW);
...@@ -448,7 +431,8 @@ TEST_F(SystemTrayTest, MAYBE_WithSystemModal) { ...@@ -448,7 +431,8 @@ TEST_F(SystemTrayTest, MAYBE_WithSystemModal) {
// Check if the accessibility item is created even with system modal dialog. // Check if the accessibility item is created even with system modal dialog.
WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled(true); WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled(true);
std::unique_ptr<views::Widget> widget(CreateTestWidget( std::unique_ptr<views::Widget> widget(CreateTestWidget(
new ModalWidgetDelegate, kShellWindowId_SystemModalContainer)); new ModalWidgetDelegate, kShellWindowId_SystemModalContainer,
gfx::Rect(0, 0, 100, 100)));
SystemTray* tray = GetPrimarySystemTray(); SystemTray* tray = GetPrimarySystemTray();
tray->ShowDefaultView(BUBBLE_CREATE_NEW); tray->ShowDefaultView(BUBBLE_CREATE_NEW);
......
...@@ -6,11 +6,9 @@ ...@@ -6,11 +6,9 @@
#include <memory> #include <memory>
#include "ash/common/wm/window_state.h" #include "ash/common/shell_window_ids.h"
#include "ash/frame/caption_buttons/frame_caption_button_container_view.h" #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ui/gfx/font_list.h"
#include "ui/views/test/test_views.h" #include "ui/views/test/test_views.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/window/non_client_view.h" #include "ui/views/window/non_client_view.h"
...@@ -21,22 +19,12 @@ using views::Widget; ...@@ -21,22 +19,12 @@ using views::Widget;
namespace ash { namespace ash {
class DefaultHeaderPainterTest : public ash::test::AshTestBase { using DefaultHeaderPainterTest = 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;
}
};
// Ensure the title text is vertically aligned with the window icon. // Ensure the title text is vertically aligned with the window icon.
TEST_F(DefaultHeaderPainterTest, TitleIconAlignment) { TEST_F(DefaultHeaderPainterTest, TitleIconAlignment) {
std::unique_ptr<Widget> w(CreateTestWidget()); std::unique_ptr<Widget> w = CreateTestWidget(
nullptr, kShellWindowId_DefaultContainer, gfx::Rect(1, 2, 3, 4));
ash::FrameCaptionButtonContainerView container(w.get()); ash::FrameCaptionButtonContainerView container(w.get());
views::StaticSizedView window_icon(gfx::Size(16, 16)); views::StaticSizedView window_icon(gfx::Size(16, 16));
window_icon.SetBounds(0, 0, 16, 16); window_icon.SetBounds(0, 0, 16, 16);
...@@ -54,7 +42,8 @@ TEST_F(DefaultHeaderPainterTest, TitleIconAlignment) { ...@@ -54,7 +42,8 @@ TEST_F(DefaultHeaderPainterTest, TitleIconAlignment) {
// Ensure the light icons are used when appropriate. // Ensure the light icons are used when appropriate.
TEST_F(DefaultHeaderPainterTest, LightIcons) { TEST_F(DefaultHeaderPainterTest, LightIcons) {
std::unique_ptr<Widget> w(CreateTestWidget()); std::unique_ptr<Widget> w = CreateTestWidget(
nullptr, kShellWindowId_DefaultContainer, gfx::Rect(1, 2, 3, 4));
ash::FrameCaptionButtonContainerView container(w.get()); ash::FrameCaptionButtonContainerView container(w.get());
views::StaticSizedView window_icon(gfx::Size(16, 16)); views::StaticSizedView window_icon(gfx::Size(16, 16));
window_icon.SetBounds(0, 0, 16, 16); window_icon.SetBounds(0, 0, 16, 16);
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "ash/common/shell_window_ids.h" #include "ash/common/shell_window_ids.h"
#include "ash/common/wm_lookup.h" #include "ash/common/wm_lookup.h"
#include "ash/common/wm_root_window_controller.h" #include "ash/common/wm_root_window_controller.h"
#include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h" #include "ash/common/wm_window.h"
#include "ash/display/display_manager.h" #include "ash/display/display_manager.h"
#include "ash/shell.h" #include "ash/shell.h"
...@@ -88,21 +87,6 @@ class AshPopupAlignmentDelegateTest : public test::AshTestBase { ...@@ -88,21 +87,6 @@ class AshPopupAlignmentDelegateTest : public test::AshTestBase {
gfx::Rect GetWorkArea() { return alignment_delegate_->work_area_; } gfx::Rect GetWorkArea() { return alignment_delegate_->work_area_; }
std::unique_ptr<views::Widget> CreateTestWidget(int container_id) {
std::unique_ptr<views::Widget> widget(new views::Widget);
views::Widget::InitParams params;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(0, 0, 50, 50);
WmShell::Get()
->GetPrimaryRootWindow()
->GetRootWindowController()
->ConfigureWidgetInitParamsForContainer(widget.get(), container_id,
&params);
widget->Init(params);
widget->Show();
return widget;
}
private: private:
std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_; std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_;
...@@ -169,8 +153,8 @@ TEST_F(AshPopupAlignmentDelegateTest, AutoHide) { ...@@ -169,8 +153,8 @@ TEST_F(AshPopupAlignmentDelegateTest, AutoHide) {
int baseline = alignment_delegate()->GetBaseLine(); int baseline = alignment_delegate()->GetBaseLine();
// Create a window, otherwise autohide doesn't work. // Create a window, otherwise autohide doesn't work.
std::unique_ptr<views::Widget> widget = std::unique_ptr<views::Widget> widget = CreateTestWidget(
CreateTestWidget(kShellWindowId_DefaultContainer); nullptr, kShellWindowId_DefaultContainer, gfx::Rect(0, 0, 50, 50));
WmShelf* shelf = GetPrimaryShelf(); WmShelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size));
...@@ -184,8 +168,8 @@ TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { ...@@ -184,8 +168,8 @@ TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) {
int origin_x = alignment_delegate()->GetToastOriginX(toast_size); int origin_x = alignment_delegate()->GetToastOriginX(toast_size);
int baseline = alignment_delegate()->GetBaseLine(); int baseline = alignment_delegate()->GetBaseLine();
std::unique_ptr<views::Widget> widget = std::unique_ptr<views::Widget> widget = CreateTestWidget(
CreateTestWidget(kShellWindowId_DockedContainer); nullptr, kShellWindowId_DockedContainer, gfx::Rect(0, 0, 50, 50));
// Left-side dock should not affect popup alignment // Left-side dock should not affect popup alignment
EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size));
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
#include "ash/common/system/web_notification/ash_popup_alignment_delegate.h" #include "ash/common/system/web_notification/ash_popup_alignment_delegate.h"
#include "ash/common/wm/window_state.h" #include "ash/common/wm/window_state.h"
#include "ash/common/wm_lookup.h" #include "ash/common/wm_lookup.h"
#include "ash/common/wm_root_window_controller.h"
#include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h" #include "ash/common/wm_window.h"
#include "ash/display/display_manager.h" #include "ash/display/display_manager.h"
#include "ash/shell.h" #include "ash/shell.h"
...@@ -144,19 +142,9 @@ class WebNotificationTrayTest : public test::AshTestBase { ...@@ -144,19 +142,9 @@ class WebNotificationTrayTest : public test::AshTestBase {
bool IsPopupVisible() { return GetTray()->IsPopupVisible(); } bool IsPopupVisible() { return GetTray()->IsPopupVisible(); }
std::unique_ptr<views::Widget> CreateTestWidget() { static std::unique_ptr<views::Widget> CreateTestWidget() {
std::unique_ptr<views::Widget> widget(new views::Widget); return AshTestBase::CreateTestWidget(
views::Widget::InitParams params; nullptr, kShellWindowId_DefaultContainer, gfx::Rect(1, 2, 3, 4));
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(1, 2, 3, 4);
WmShell::Get()
->GetPrimaryRootWindow()
->GetRootWindowController()
->ConfigureWidgetInitParamsForContainer(
widget.get(), kShellWindowId_DefaultContainer, &params);
widget->Init(params);
widget->Show();
return widget;
} }
private: private:
......
...@@ -223,6 +223,26 @@ aura::Window* AshTestBase::CurrentContext() { ...@@ -223,6 +223,26 @@ aura::Window* AshTestBase::CurrentContext() {
return ash_test_helper_->CurrentContext(); return ash_test_helper_->CurrentContext();
} }
// static
std::unique_ptr<views::Widget> AshTestBase::CreateTestWidget(
views::WidgetDelegate* delegate,
int container_id,
const gfx::Rect& bounds) {
std::unique_ptr<views::Widget> widget(new views::Widget);
views::Widget::InitParams params;
params.delegate = delegate;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = bounds;
WmShell::Get()
->GetPrimaryRootWindow()
->GetRootWindowController()
->ConfigureWidgetInitParamsForContainer(widget.get(), container_id,
&params);
widget->Init(params);
widget->Show();
return widget;
}
aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) { aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) {
return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect()); return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect());
} }
......
...@@ -24,6 +24,12 @@ ...@@ -24,6 +24,12 @@
#include "ui/base/win/scoped_ole_initializer.h" #include "ui/base/win/scoped_ole_initializer.h"
#endif #endif
namespace aura {
class RootWindow;
class Window;
class WindowDelegate;
} // namespace aura
namespace gfx { namespace gfx {
class Rect; class Rect;
} }
...@@ -34,11 +40,10 @@ class EventGenerator; ...@@ -34,11 +40,10 @@ class EventGenerator;
} }
} }
namespace aura { namespace views {
class RootWindow; class Widget;
class Window; class WidgetDelegate;
class WindowDelegate; }
} // namespace aura
namespace ash { namespace ash {
class DisplayManager; class DisplayManager;
...@@ -75,6 +80,13 @@ class AshTestBase : public testing::Test { ...@@ -75,6 +80,13 @@ class AshTestBase : public testing::Test {
// primary root Window. // primary root Window.
aura::Window* CurrentContext(); aura::Window* CurrentContext();
// Creates and shows a widget. See ash/common/shell_window_ids.h for values
// for |container_id|.
static std::unique_ptr<views::Widget> CreateTestWidget(
views::WidgetDelegate* delegate,
int container_id,
const gfx::Rect& bounds);
// 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);
......
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