Commit 2db00087 authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Rename TestChildModalParent and move to //ash/wm

The policy for test code in //ash is that it should live in the
directory of the code under test, which in this case is //ash/wm.

This fixes a TODO in //ash/BUILD.gn

Bug: none
Test: ash_unittests
Change-Id: Id40eaa137991efbb47b83c322eb6cf9c7bb405ec
Reviewed-on: https://chromium-review.googlesource.com/892198
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532958}
parent ff1eda67
...@@ -1814,10 +1814,6 @@ static_library("test_support_common") { ...@@ -1814,10 +1814,6 @@ static_library("test_support_common") {
"test/ash_test_suite.h", "test/ash_test_suite.h",
"test/ash_test_views_delegate.cc", "test/ash_test_views_delegate.cc",
"test/ash_test_views_delegate.h", "test/ash_test_views_delegate.h",
# TODO(jamescook): Rename to TestChildModalWindow and move to //ash/wm
"test/child_modal_window.cc",
"test/child_modal_window.h",
"test/ui_controls_factory_ash.cc", "test/ui_controls_factory_ash.cc",
"test/ui_controls_factory_ash.h", "test/ui_controls_factory_ash.h",
"test_media_client.cc", "test_media_client.cc",
...@@ -1836,6 +1832,8 @@ static_library("test_support_common") { ...@@ -1836,6 +1832,8 @@ static_library("test_support_common") {
"wm/lock_state_controller_test_api.h", "wm/lock_state_controller_test_api.h",
"wm/test_activation_delegate.cc", "wm/test_activation_delegate.cc",
"wm/test_activation_delegate.h", "wm/test_activation_delegate.h",
"wm/test_child_modal_parent.cc",
"wm/test_child_modal_parent.h",
"wm/test_overlay_delegate.cc", "wm/test_overlay_delegate.cc",
"wm/test_overlay_delegate.h", "wm/test_overlay_delegate.h",
"wm/test_session_state_animator.cc", "wm/test_session_state_animator.cc",
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "ash/shell/toplevel_window.h" #include "ash/shell/toplevel_window.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/system/web_notification/web_notification_tray.h" #include "ash/system/web_notification/web_notification_tray.h"
#include "ash/test/child_modal_window.h" #include "ash/wm/test_child_modal_parent.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_event_dispatcher.h"
...@@ -283,7 +283,7 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender, ...@@ -283,7 +283,7 @@ 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_) {
test::CreateChildModalParent(GetWidget()->GetNativeView()->GetRootWindow()); TestChildModalParent::Create(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_) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// 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/test/child_modal_window.h" #include "ash/wm/test_child_modal_parent.h"
#include <memory> #include <memory>
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
using views::Widget; using views::Widget;
namespace ash { namespace ash {
namespace test {
namespace { namespace {
...@@ -49,13 +48,6 @@ const SkColor kChildColor = SK_ColorWHITE; ...@@ -49,13 +48,6 @@ const SkColor kChildColor = SK_ColorWHITE;
} // namespace } // namespace
void CreateChildModalParent(aura::Window* context) {
Widget::CreateWindowWithContextAndBounds(
new ChildModalParent(context), context,
gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight))
->Show();
}
class ChildModalWindow : public views::WidgetDelegateView { class ChildModalWindow : public views::WidgetDelegateView {
public: public:
ChildModalWindow(); ChildModalWindow();
...@@ -103,7 +95,15 @@ ui::ModalType ChildModalWindow::GetModalType() const { ...@@ -103,7 +95,15 @@ ui::ModalType ChildModalWindow::GetModalType() const {
return ui::MODAL_TYPE_CHILD; return ui::MODAL_TYPE_CHILD;
} }
ChildModalParent::ChildModalParent(aura::Window* context) // static
void TestChildModalParent::Create(aura::Window* context) {
Widget::CreateWindowWithContextAndBounds(
new TestChildModalParent(context), context,
gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight))
->Show();
}
TestChildModalParent::TestChildModalParent(aura::Window* context)
: widget_(std::make_unique<Widget>()), : widget_(std::make_unique<Widget>()),
button_(new views::LabelButton( button_(new views::LabelButton(
this, this,
...@@ -123,25 +123,25 @@ ChildModalParent::ChildModalParent(aura::Window* context) ...@@ -123,25 +123,25 @@ ChildModalParent::ChildModalParent(aura::Window* context)
AddChildView(host_); AddChildView(host_);
} }
ChildModalParent::~ChildModalParent() = default; TestChildModalParent::~TestChildModalParent() = default;
void ChildModalParent::ShowChild() { void TestChildModalParent::ShowChild() {
if (!child_) if (!child_)
child_ = CreateChild(); child_ = CreateChild();
child_->Show(); child_->Show();
} }
aura::Window* ChildModalParent::GetModalParent() const { aura::Window* TestChildModalParent::GetModalParent() const {
return widget_->GetNativeView(); return widget_->GetNativeView();
} }
aura::Window* ChildModalParent::GetChild() const { aura::Window* TestChildModalParent::GetChild() const {
if (child_) if (child_)
return child_->GetNativeView(); return child_->GetNativeView();
return nullptr; return nullptr;
} }
Widget* ChildModalParent::CreateChild() { Widget* TestChildModalParent::CreateChild() {
Widget* child = Widget::CreateWindowWithParent(new ChildModalWindow, Widget* child = Widget::CreateWindowWithParent(new ChildModalWindow,
GetWidget()->GetNativeView()); GetWidget()->GetNativeView());
wm::SetModalParent(child->GetNativeView(), GetModalParent()); wm::SetModalParent(child->GetNativeView(), GetModalParent());
...@@ -150,15 +150,15 @@ Widget* ChildModalParent::CreateChild() { ...@@ -150,15 +150,15 @@ Widget* ChildModalParent::CreateChild() {
return child; return child;
} }
base::string16 ChildModalParent::GetWindowTitle() const { base::string16 TestChildModalParent::GetWindowTitle() const {
return base::ASCIIToUTF16("Examples: Child Modal Parent"); return base::ASCIIToUTF16("Examples: Child Modal Parent");
} }
bool ChildModalParent::CanResize() const { bool TestChildModalParent::CanResize() const {
return false; return false;
} }
void ChildModalParent::DeleteDelegate() { void TestChildModalParent::DeleteDelegate() {
if (child_) { if (child_) {
child_->RemoveObserver(this); child_->RemoveObserver(this);
child_->Close(); child_->Close();
...@@ -168,7 +168,7 @@ void ChildModalParent::DeleteDelegate() { ...@@ -168,7 +168,7 @@ void ChildModalParent::DeleteDelegate() {
delete this; delete this;
} }
void ChildModalParent::Layout() { void TestChildModalParent::Layout() {
int running_y = y(); int running_y = y();
button_->SetBounds(x(), running_y, width(), kButtonHeight); button_->SetBounds(x(), running_y, width(), kButtonHeight);
running_y += kButtonHeight; running_y += kButtonHeight;
...@@ -177,7 +177,7 @@ void ChildModalParent::Layout() { ...@@ -177,7 +177,7 @@ void ChildModalParent::Layout() {
host_->SetBounds(x(), running_y, width(), height() - running_y); host_->SetBounds(x(), running_y, width(), height() - running_y);
} }
void ChildModalParent::ViewHierarchyChanged( void TestChildModalParent::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) { const ViewHierarchyChangedDetails& details) {
if (details.is_add && details.child == this) { if (details.is_add && details.child == this) {
host_->Attach(widget_->GetNativeWindow()); host_->Attach(widget_->GetNativeWindow());
...@@ -185,7 +185,7 @@ void ChildModalParent::ViewHierarchyChanged( ...@@ -185,7 +185,7 @@ void ChildModalParent::ViewHierarchyChanged(
} }
} }
void ChildModalParent::ButtonPressed(views::Button* sender, void TestChildModalParent::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
if (sender == button_) { if (sender == button_) {
if (!child_) if (!child_)
...@@ -197,12 +197,11 @@ void ChildModalParent::ButtonPressed(views::Button* sender, ...@@ -197,12 +197,11 @@ void ChildModalParent::ButtonPressed(views::Button* sender,
} }
} }
void ChildModalParent::OnWidgetDestroying(Widget* widget) { void TestChildModalParent::OnWidgetDestroying(Widget* widget) {
if (child_) { if (child_) {
DCHECK_EQ(child_, widget); DCHECK_EQ(child_, widget);
child_ = NULL; child_ = NULL;
} }
} }
} // namespace test
} // namespace ash } // namespace ash
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// 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.
#ifndef ASH_TEST_CHILD_MODAL_WINDOW_H_ #ifndef ASH_WM_TEST_CHILD_MODAL_PARENT_H_
#define ASH_TEST_CHILD_MODAL_WINDOW_H_ #define ASH_WM_TEST_CHILD_MODAL_PARENT_H_
#include <memory> #include <memory>
...@@ -18,21 +18,20 @@ class NativeViewHost; ...@@ -18,21 +18,20 @@ class NativeViewHost;
class Textfield; class Textfield;
class View; class View;
class Widget; class Widget;
} } // namespace views
namespace ash { namespace ash {
namespace test {
void CreateChildModalParent(aura::Window* context); // Test window that can act as a parent for modal child windows.
class TestChildModalParent : public views::WidgetDelegateView,
// TODO(jamescook): Rename to TestChildModalParent, remove the test namespcae,
// and move to //ash/wm.
class ChildModalParent : public views::WidgetDelegateView,
public views::ButtonListener, public views::ButtonListener,
public views::WidgetObserver { public views::WidgetObserver {
public: public:
ChildModalParent(aura::Window* context); // Creates the test window.
~ChildModalParent() override; static void Create(aura::Window* context);
explicit TestChildModalParent(aura::Window* context);
~TestChildModalParent() override;
void ShowChild(); void ShowChild();
aura::Window* GetModalParent() const; aura::Window* GetModalParent() const;
...@@ -74,10 +73,9 @@ class ChildModalParent : public views::WidgetDelegateView, ...@@ -74,10 +73,9 @@ class ChildModalParent : public views::WidgetDelegateView,
// The child window. // The child window.
views::Widget* child_; views::Widget* child_;
DISALLOW_COPY_AND_ASSIGN(ChildModalParent); DISALLOW_COPY_AND_ASSIGN(TestChildModalParent);
}; };
} // namespace test
} // namespace ash } // namespace ash
#endif // ASH_TEST_CHILD_MODAL_WINDOW_H_ #endif // ASH_WM_TEST_CHILD_MODAL_PARENT_H_
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/test/child_modal_window.h" #include "ash/wm/test_child_modal_parent.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "services/ui/public/interfaces/window_manager.mojom.h" #include "services/ui/public/interfaces/window_manager.mojom.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
...@@ -463,8 +463,7 @@ TEST_F(WindowModalityControllerTest, TouchEvent) { ...@@ -463,8 +463,7 @@ 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) {
test::ChildModalParent* delegate = TestChildModalParent* delegate = new TestChildModalParent(CurrentContext());
new test::ChildModalParent(CurrentContext());
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400)); delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400));
widget->Show(); widget->Show();
...@@ -523,8 +522,7 @@ TEST_F(WindowModalityControllerTest, ChildModal) { ...@@ -523,8 +522,7 @@ 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) {
test::ChildModalParent* delegate = TestChildModalParent* delegate = new TestChildModalParent(CurrentContext());
new test::ChildModalParent(CurrentContext());
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400)); delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400));
widget->Show(); widget->Show();
......
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