diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-14 01:56:05 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-14 01:56:05 +0000 |
commit | f1c9826afffc7f26e760d3a987b822ec401af0d9 (patch) | |
tree | a4b348ca510cda478d9e1d4982b5744e51bbf8b0 /ash | |
parent | edf82d1c54334d45226bbb91d2cb51cd000f7b6f (diff) | |
download | chromium_src-f1c9826afffc7f26e760d3a987b822ec401af0d9.zip chromium_src-f1c9826afffc7f26e760d3a987b822ec401af0d9.tar.gz chromium_src-f1c9826afffc7f26e760d3a987b822ec401af0d9.tar.bz2 |
Reduce creation of ViewsDelegate
By consolidating override of OnBeforeWidgetInit that finds shell many
of the places that were setting a viewsdelegate no longer need to.
Also, made AshTestHelper install a ViewsDelegate so that tests don't have.
Because of removed an include of views_delegate from ash_test_helper I had to update some includes.
BUG=none
TEST=none
R=ben@chromium.org
Review URL: https://codereview.chromium.org/280863002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270290 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/drag_drop/drag_drop_controller_unittest.cc | 3 | ||||
-rw-r--r-- | ash/first_run/first_run_helper_unittest.cc | 1 | ||||
-rw-r--r-- | ash/screensaver/screensaver_view_unittest.cc | 2 | ||||
-rw-r--r-- | ash/test/ash_test_base.cc | 8 | ||||
-rw-r--r-- | ash/test/ash_test_base.h | 13 | ||||
-rw-r--r-- | ash/test/ash_test_helper.cc | 6 | ||||
-rw-r--r-- | ash/test/ash_test_helper.h | 6 | ||||
-rw-r--r-- | ash/test/ash_test_views_delegate.cc | 38 | ||||
-rw-r--r-- | ash/test/ash_test_views_delegate.h | 37 | ||||
-rw-r--r-- | ash/touch/touch_observer_hud_unittest.cc | 1 | ||||
-rw-r--r-- | ash/wm/system_gesture_event_filter_unittest.cc | 2 |
12 files changed, 91 insertions, 28 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index a69869d..d23db52 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -804,6 +804,8 @@ 'test/ash_test_base.h', 'test/ash_test_helper.cc', 'test/ash_test_helper.h', + 'test/ash_test_views_delegate.cc', + 'test/ash_test_views_delegate.h', 'test/cursor_manager_test_api.cc', 'test/cursor_manager_test_api.h', 'test/display_manager_test_api.cc', diff --git a/ash/drag_drop/drag_drop_controller_unittest.cc b/ash/drag_drop/drag_drop_controller_unittest.cc index 9ef0b9b..7e84ed4 100644 --- a/ash/drag_drop/drag_drop_controller_unittest.cc +++ b/ash/drag_drop/drag_drop_controller_unittest.cc @@ -26,7 +26,6 @@ #include "ui/events/gestures/gesture_types.h" #include "ui/gfx/animation/linear_animation.h" #include "ui/gfx/image/image_skia_rep.h" -#include "ui/views/test/test_views_delegate.h" #include "ui/views/view.h" #include "ui/views/views_delegate.h" #include "ui/views/widget/native_widget_aura.h" @@ -299,7 +298,6 @@ class DragDropControllerTest : public AshTestBase { drag_drop_controller_->set_should_block_during_drag_drop(false); aura::client::SetDragDropClient(Shell::GetPrimaryRootWindow(), drag_drop_controller_.get()); - views_delegate_.reset(new views::TestViewsDelegate); } virtual void TearDown() OVERRIDE { @@ -344,7 +342,6 @@ class DragDropControllerTest : public AshTestBase { protected: scoped_ptr<TestDragDropController> drag_drop_controller_; - scoped_ptr<views::TestViewsDelegate> views_delegate_; private: DISALLOW_COPY_AND_ASSIGN(DragDropControllerTest); diff --git a/ash/first_run/first_run_helper_unittest.cc b/ash/first_run/first_run_helper_unittest.cc index a86c064..15e42bf 100644 --- a/ash/first_run/first_run_helper_unittest.cc +++ b/ash/first_run/first_run_helper_unittest.cc @@ -10,6 +10,7 @@ #include "ash/test/ash_test_base.h" #include "ui/aura/test/event_generator.h" #include "ui/events/event_handler.h" +#include "ui/views/widget/widget.h" #include "ui/views/window/dialog_delegate.h" namespace ash { diff --git a/ash/screensaver/screensaver_view_unittest.cc b/ash/screensaver/screensaver_view_unittest.cc index 19be19e..2809025 100644 --- a/ash/screensaver/screensaver_view_unittest.cc +++ b/ash/screensaver/screensaver_view_unittest.cc @@ -18,7 +18,6 @@ class ScreensaverViewTest : public ash::test::AshTestBase { public: ScreensaverViewTest() { url_ = GURL("http://www.google.com"); - views_delegate_.reset(new AshTestViewsDelegate()); webview_test_helper_.reset(new views::WebViewTestHelper()); } @@ -44,7 +43,6 @@ class ScreensaverViewTest : public ash::test::AshTestBase { GURL url_; private: - scoped_ptr<AshTestViewsDelegate> views_delegate_; scoped_ptr<views::WebViewTestHelper> webview_test_helper_; DISALLOW_COPY_AND_ASSIGN(ScreensaverViewTest); diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index 61fa218..cfd3142 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -19,7 +19,6 @@ #include "ash/wm/coordinate_conversion.h" #include "ash/wm/window_positioner.h" #include "base/command_line.h" -#include "content/public/test/web_contents_tester.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/screen_position_client.h" #include "ui/aura/client/window_tree_client.h" @@ -81,13 +80,6 @@ class AshEventGeneratorDelegate : public aura::test::EventGeneratorDelegate { } // namespace -content::WebContents* AshTestViewsDelegate::CreateWebContents( - content::BrowserContext* browser_context, - content::SiteInstance* site_instance) { - return content::WebContentsTester::CreateTestWebContents(browser_context, - site_instance); -} - ///////////////////////////////////////////////////////////////////////////// AshTestBase::AshTestBase() diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h index 4ac828e..6ef1591 100644 --- a/ash/test/ash_test_base.h +++ b/ash/test/ash_test_base.h @@ -13,13 +13,16 @@ #include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkColor.h" -#include "ui/views/test/test_views_delegate.h" #include "ui/wm/public/window_types.h" #if defined(OS_WIN) #include "ui/base/win/scoped_ole_initializer.h" #endif +namespace gfx { +class Rect; +} + namespace aura { class RootWindow; class Window; @@ -42,14 +45,6 @@ class TestSystemTrayDelegate; class TestMetroViewerProcessHost; #endif -class AshTestViewsDelegate : public views::TestViewsDelegate { - public: - // Overriden from TestViewsDelegate. - virtual content::WebContents* CreateWebContents( - content::BrowserContext* browser_context, - content::SiteInstance* site_instance) OVERRIDE; -}; - class AshTestBase : public testing::Test { public: AshTestBase(); diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc index 9cf3488..a59019b 100644 --- a/ash/test/ash_test_helper.cc +++ b/ash/test/ash_test_helper.cc @@ -7,6 +7,7 @@ #include "ash/accelerators/accelerator_controller.h" #include "ash/ash_switches.h" #include "ash/shell.h" +#include "ash/test/ash_test_views_delegate.h" #include "ash/test/display_manager_test_api.h" #include "ash/test/shell_test_api.h" #include "ash/test/test_screenshot_delegate.h" @@ -22,7 +23,6 @@ #include "ui/compositor/test/context_factories_for_test.h" #include "ui/message_center/message_center.h" #include "ui/wm/core/capture_controller.h" -#include "ui/wm/core/wm_state.h" #if defined(OS_CHROMEOS) #include "chromeos/audio/cras_audio_handler.h" @@ -56,7 +56,7 @@ AshTestHelper::~AshTestHelper() { } void AshTestHelper::SetUp(bool start_session) { - wm_state_.reset(new wm::WMState); + views_delegate_.reset(new AshTestViewsDelegate); // Disable animations during tests. zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( @@ -133,7 +133,7 @@ void AshTestHelper::TearDown() { CHECK(!wm::ScopedCaptureClient::IsActive()); - wm_state_.reset(); + views_delegate_.reset(); } void AshTestHelper::RunAllPendingInMessageLoop() { diff --git a/ash/test/ash_test_helper.h b/ash/test/ash_test_helper.h index 6fb266f..b42cc72 100644 --- a/ash/test/ash_test_helper.h +++ b/ash/test/ash_test_helper.h @@ -20,8 +20,8 @@ namespace ui { class ScopedAnimationDurationScaleMode; } // namespace ui -namespace wm { -class WMState; +namespace views { +class ViewsDelegate; } namespace ash { @@ -77,7 +77,7 @@ class AshTestHelper { // Owned by ash::AcceleratorController TestScreenshotDelegate* test_screenshot_delegate_; - scoped_ptr<wm::WMState> wm_state_; + scoped_ptr<views::ViewsDelegate> views_delegate_; // Check if DBus Thread Manager was initialized here. bool dbus_thread_manager_initialized_; diff --git a/ash/test/ash_test_views_delegate.cc b/ash/test/ash_test_views_delegate.cc new file mode 100644 index 0000000..c47bdba --- /dev/null +++ b/ash/test/ash_test_views_delegate.cc @@ -0,0 +1,38 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/test/ash_test_views_delegate.h" + +#include "ash/shell.h" +#include "content/public/test/web_contents_tester.h" + +namespace ash { +namespace test { + +AshTestViewsDelegate::AshTestViewsDelegate() { +} + +AshTestViewsDelegate::~AshTestViewsDelegate() { +} + +content::WebContents* AshTestViewsDelegate::CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) { + return content::WebContentsTester::CreateTestWebContents(browser_context, + site_instance); +} + +void AshTestViewsDelegate::OnBeforeWidgetInit( + views::Widget::InitParams* params, + views::internal::NativeWidgetDelegate* delegate) { + TestViewsDelegate::OnBeforeWidgetInit(params, delegate); + + if (!params->parent && !params->context && ash::Shell::HasInstance()) { + // If the window has neither a parent nor a context add to the root. + params->parent = ash::Shell::GetInstance()->GetPrimaryRootWindow(); + } +} + +} // namespace test +} // namespace ash diff --git a/ash/test/ash_test_views_delegate.h b/ash/test/ash_test_views_delegate.h new file mode 100644 index 0000000..6fd8bd4 --- /dev/null +++ b/ash/test/ash_test_views_delegate.h @@ -0,0 +1,37 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_TEST_ASH_TEST_VIEWS_DELEGATE_H_ +#define ASH_TEST_ASH_TEST_VIEWS_DELEGATE_H_ + +#include "ui/views/test/test_views_delegate.h" + +namespace ash { +namespace test { + +// Ash specific ViewsDelegate. In addition to creating a TestWebContents this +// parents widget with no parent/context to the shell. This is created by +// default AshTestHelper. +class AshTestViewsDelegate : public views::TestViewsDelegate { + public: + AshTestViewsDelegate(); + virtual ~AshTestViewsDelegate(); + + // Overriden from TestViewsDelegate. + virtual content::WebContents* CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) OVERRIDE; + virtual void OnBeforeWidgetInit( + views::Widget::InitParams* params, + views::internal::NativeWidgetDelegate* delegate) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(AshTestViewsDelegate); +}; + +} // namespace test +} // namespace ash + +#endif // ASH_TEST_ASH_TEST_VIEWS_DELEGATE_H_ + diff --git a/ash/touch/touch_observer_hud_unittest.cc b/ash/touch/touch_observer_hud_unittest.cc index e0e133f..d5c7e2a 100644 --- a/ash/touch/touch_observer_hud_unittest.cc +++ b/ash/touch/touch_observer_hud_unittest.cc @@ -17,6 +17,7 @@ #include "base/format_macros.h" #include "base/strings/stringprintf.h" #include "ui/aura/window.h" +#include "ui/views/widget/widget.h" namespace ash { diff --git a/ash/wm/system_gesture_event_filter_unittest.cc b/ash/wm/system_gesture_event_filter_unittest.cc index 47f46df..fe1da3d 100644 --- a/ash/wm/system_gesture_event_filter_unittest.cc +++ b/ash/wm/system_gesture_event_filter_unittest.cc @@ -35,7 +35,9 @@ #include "ui/events/test/test_event_handler.h" #include "ui/gfx/screen.h" #include "ui/gfx/size.h" +#include "ui/views/widget/widget.h" #include "ui/views/widget/widget_delegate.h" +#include "ui/views/window/non_client_view.h" namespace ash { namespace test { |