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/test | |
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/test')
-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 |
6 files changed, 85 insertions, 23 deletions
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_ + |