summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authortapted <tapted@chromium.org>2014-11-11 14:17:04 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-11 22:17:48 +0000
commit36ffc47612b07a3d74467ae56bbbb48d256d0361 (patch)
tree90bc873a1119ec7bc7297bd5e97f38246cfd8594 /ui
parent9092fec775d634e00ffab6163b09890592b96d11 (diff)
downloadchromium_src-36ffc47612b07a3d74467ae56bbbb48d256d0361.zip
chromium_src-36ffc47612b07a3d74467ae56bbbb48d256d0361.tar.gz
chromium_src-36ffc47612b07a3d74467ae56bbbb48d256d0361.tar.bz2
MacViews: Support ViewsDelegate::ContextFactory without Aura
This is done by removing the USE_AURA guards around ViewsDelegate::GetContextFactory() and providing TestViewsDelegate::set_context_factory(..) for tests/examples. In ViewsContentClient, the context factory is set to content::GetContextFactory() (This is already returned in ChromeViewsDelegate). Doing this provides a ContextFactory for views_examples_with_content_exe and app_list_demo without requiring it to be provided by aura::Env::context_factory() (which MacViews doesn't have). tests (e.g. app_list_unittests, which need a compositor) will use an InProcessContextFactory, created in ViewsTestBase. BUG=424058 Review URL: https://codereview.chromium.org/714033002 Cr-Commit-Position: refs/heads/master@{#303731}
Diffstat (limited to 'ui')
-rw-r--r--ui/app_list/test/run_all_unittests.cc7
-rw-r--r--ui/views/test/test_views_delegate.h10
-rw-r--r--ui/views/test/test_views_delegate_aura.cc12
-rw-r--r--ui/views/test/test_views_delegate_mac.mm7
-rw-r--r--ui/views/test/views_test_base.cc2
-rw-r--r--ui/views/views_delegate.cc2
-rw-r--r--ui/views/views_delegate.h2
-rw-r--r--ui/views_content_client/views_content_client_main_parts.cc7
8 files changed, 37 insertions, 12 deletions
diff --git a/ui/app_list/test/run_all_unittests.cc b/ui/app_list/test/run_all_unittests.cc
index b730cfb..b60b438 100644
--- a/ui/app_list/test/run_all_unittests.cc
+++ b/ui/app_list/test/run_all_unittests.cc
@@ -14,7 +14,9 @@
#if defined(OS_MACOSX)
#include "base/test/mock_chrome_application_mac.h"
-#else
+#endif
+
+#if defined(TOOLKIT_VIEWS)
#include "ui/gl/gl_surface.h"
#endif
@@ -28,7 +30,8 @@ class AppListTestSuite : public base::TestSuite {
void Initialize() override {
#if defined(OS_MACOSX)
mock_cr_app::RegisterMockCrApp();
-#else
+#endif
+#if defined(TOOLKIT_VIEWS)
gfx::GLSurface::InitializeOneOffForTests();
#endif
base::TestSuite::Initialize();
diff --git a/ui/views/test/test_views_delegate.h b/ui/views/test/test_views_delegate.h
index bbb1174..3e2b96f 100644
--- a/ui/views/test/test_views_delegate.h
+++ b/ui/views/test/test_views_delegate.h
@@ -30,19 +30,23 @@ class TestViewsDelegate : public ViewsDelegate {
use_transparent_windows_ = transparent;
}
+ // Allows tests to provide a ContextFactory via the ViewsDelegate interface.
+ void set_context_factory(ui::ContextFactory* context_factory) {
+ context_factory_ = context_factory;
+ }
+
// ViewsDelegate:
void OnBeforeWidgetInit(Widget::InitParams* params,
internal::NativeWidgetDelegate* delegate) override;
+ ui::ContextFactory* GetContextFactory() override;
private:
+ ui::ContextFactory* context_factory_;
bool use_desktop_native_widgets_;
-
bool use_transparent_windows_;
#if defined(USE_AURA)
scoped_ptr<wm::WMState> wm_state_;
-
- ui::ContextFactory* context_factory_;
#endif
DISALLOW_COPY_AND_ASSIGN(TestViewsDelegate);
diff --git a/ui/views/test/test_views_delegate_aura.cc b/ui/views/test/test_views_delegate_aura.cc
index 62efccf..8eb1a86 100644
--- a/ui/views/test/test_views_delegate_aura.cc
+++ b/ui/views/test/test_views_delegate_aura.cc
@@ -4,6 +4,7 @@
#include "ui/views/test/test_views_delegate.h"
+#include "ui/aura/env.h"
#include "ui/wm/core/wm_state.h"
#if !defined(OS_CHROMEOS)
@@ -14,7 +15,8 @@
namespace views {
TestViewsDelegate::TestViewsDelegate()
- : use_desktop_native_widgets_(false),
+ : context_factory_(nullptr),
+ use_desktop_native_widgets_(false),
use_transparent_windows_(false) {
DCHECK(!ViewsDelegate::views_delegate);
ViewsDelegate::views_delegate = this;
@@ -42,4 +44,12 @@ void TestViewsDelegate::OnBeforeWidgetInit(
#endif // !defined(OS_CHROMEOS)
}
+ui::ContextFactory* TestViewsDelegate::GetContextFactory() {
+ if (context_factory_)
+ return context_factory_;
+ if (aura::Env::GetInstance())
+ return aura::Env::GetInstance()->context_factory();
+ return nullptr;
+}
+
} // namespace views
diff --git a/ui/views/test/test_views_delegate_mac.mm b/ui/views/test/test_views_delegate_mac.mm
index 79b620b..5d3c352 100644
--- a/ui/views/test/test_views_delegate_mac.mm
+++ b/ui/views/test/test_views_delegate_mac.mm
@@ -9,7 +9,8 @@
namespace views {
TestViewsDelegate::TestViewsDelegate()
- : use_desktop_native_widgets_(false),
+ : context_factory_(nullptr),
+ use_desktop_native_widgets_(false),
use_transparent_windows_(false) {
DCHECK(!ViewsDelegate::views_delegate);
ViewsDelegate::views_delegate = this;
@@ -33,4 +34,8 @@ void TestViewsDelegate::OnBeforeWidgetInit(
params->native_widget = new NativeWidgetMac(delegate);
}
+ui::ContextFactory* TestViewsDelegate::GetContextFactory() {
+ return context_factory_;
+}
+
} // namespace views
diff --git a/ui/views/test/views_test_base.cc b/ui/views/test/views_test_base.cc
index ade40e8..e508fd7 100644
--- a/ui/views/test/views_test_base.cc
+++ b/ui/views/test/views_test_base.cc
@@ -29,10 +29,12 @@ void ViewsTestBase::SetUp() {
setup_called_ = true;
if (!views_delegate_.get())
views_delegate_.reset(new TestViewsDelegate());
+
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
+ views_delegate_->set_context_factory(context_factory);
test_helper_.reset(ViewsTestHelper::Create(&message_loop_, context_factory));
test_helper_->SetUp();
diff --git a/ui/views/views_delegate.cc b/ui/views/views_delegate.cc
index c1c7ca6..6ed6529 100644
--- a/ui/views/views_delegate.cc
+++ b/ui/views/views_delegate.cc
@@ -81,11 +81,9 @@ bool ViewsDelegate::WindowManagerProvidesTitleBar(bool maximized) {
return false;
}
-#if defined(USE_AURA)
ui::ContextFactory* ViewsDelegate::GetContextFactory() {
return NULL;
}
-#endif
#if defined(OS_WIN)
int ViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor,
diff --git a/ui/views/views_delegate.h b/ui/views/views_delegate.h
index 0175c8b..b3dd4bb 100644
--- a/ui/views/views_delegate.h
+++ b/ui/views/views_delegate.h
@@ -130,10 +130,8 @@ class VIEWS_EXPORT ViewsDelegate {
// maximized windows; otherwise to restored windows.
virtual bool WindowManagerProvidesTitleBar(bool maximized);
-#if defined(USE_AURA)
// Returns the context factory for new windows.
virtual ui::ContextFactory* GetContextFactory();
-#endif
#if defined(OS_WIN)
// Starts a query for the appbar autohide edges of the specified monitor and
diff --git a/ui/views_content_client/views_content_client_main_parts.cc b/ui/views_content_client/views_content_client_main_parts.cc
index d51ceb2..dcb0e47 100644
--- a/ui/views_content_client/views_content_client_main_parts.cc
+++ b/ui/views_content_client/views_content_client_main_parts.cc
@@ -5,6 +5,7 @@
#include "ui/views_content_client/views_content_client_main_parts.h"
#include "base/run_loop.h"
+#include "content/public/browser/context_factory.h"
#include "content/shell/browser/shell_browser_context.h"
#include "ui/base/ime/input_method_initializer.h"
#include "ui/views/test/desktop_test_views_delegate.h"
@@ -23,7 +24,11 @@ ViewsContentClientMainParts::~ViewsContentClientMainParts() {
void ViewsContentClientMainParts::PreMainMessageLoopRun() {
ui::InitializeInputMethodForTesting();
browser_context_.reset(new content::ShellBrowserContext(false, NULL));
- views_delegate_.reset(new views::DesktopTestViewsDelegate);
+
+ scoped_ptr<views::TestViewsDelegate> test_views_delegate(
+ new views::DesktopTestViewsDelegate);
+ test_views_delegate->set_context_factory(content::GetContextFactory());
+ views_delegate_ = test_views_delegate.Pass();
}
void ViewsContentClientMainParts::PostMainMessageLoopRun() {