Commit fa69f2b6 authored by sky@chromium.org's avatar sky@chromium.org

Makes Env contain a ContextFactory

This way when creating the Compositor we can supply the ContextFactory
from the thread local Env to it. This is part of making aura thread
safe.

BUG=none
TEST=none
R=ben@chromium.org

Review URL: https://codereview.chromium.org/296053009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272332 0039d316-1c4b-4281-b951-d872f2087c98
parent 15b4290d
......@@ -5,6 +5,7 @@
#include "apps/shell/browser/shell_desktop_controller.h"
#include "apps/shell/browser/shell_app_window.h"
#include "content/public/browser/context_factory.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/env.h"
#include "ui/aura/layout_manager.h"
......@@ -226,7 +227,8 @@ void ShellDesktopController::CreateRootWindow() {
gfx::Size size = GetPrimaryDisplaySize();
if (size.IsEmpty())
size = gfx::Size(800, 600);
wm_test_helper_.reset(new wm::WMTestHelper(size));
wm_test_helper_.reset(
new wm::WMTestHelper(size, content::GetContextFactory()));
// Ensure new windows fill the display.
aura::WindowTreeHost* host = wm_test_helper_->host();
......
......@@ -843,10 +843,8 @@ void Shell::Init(const ShellInitParams& init_params) {
// Shelf, and WallPaper could be created by the factory.
views::FocusManagerFactory::Install(new AshFocusManagerFactory);
// Env creates the compositor. Historically it seems to have been implicitly
// initialized first by the ActivationController, but now that FocusController
// no longer does this we need to do it explicitly.
aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
// The WindowModalityController needs to be at the front of the input event
// pretarget handler list to ensure that it processes input events when modal
......
......@@ -18,6 +18,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "content/public/browser/context_factory.h"
#include "content/public/common/content_switches.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_net_log.h"
......@@ -124,6 +125,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
ash::ShellInitParams init_params;
init_params.delegate = delegate_;
init_params.context_factory = content::GetContextFactory();
ash::Shell::CreateInstance(init_params);
delegate_->set_browser_context(browser_context_.get());
ash::Shell::GetInstance()->CreateShelf();
......
......@@ -10,6 +10,7 @@
#include "ash/shell_init_params.h"
#include "ash/system/user/login_status.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h"
namespace ash {
......@@ -25,6 +26,7 @@ TEST_F(WindowWatcherTest, ShellDeleteInstance) {
shell::ShellDelegateImpl* delegate = new ash::shell::ShellDelegateImpl;
ash::ShellInitParams init_params;
init_params.context_factory = aura::Env::GetInstance()->context_factory();
init_params.delegate = delegate;
Shell::CreateInstance(init_params);
Shell::GetPrimaryRootWindow()->GetHost()->Show();
......
......@@ -8,11 +8,13 @@
namespace ash {
ShellInitParams::ShellInitParams()
: delegate(NULL),
context_factory(NULL)
#if defined(OS_WIN)
ShellInitParams::ShellInitParams() : delegate(NULL), remote_hwnd(NULL) {}
#else
ShellInitParams::ShellInitParams() : delegate(NULL) {}
, remote_hwnd(NULL)
#endif
{}
ShellInitParams::~ShellInitParams() {}
......
......@@ -13,6 +13,10 @@
#include "ash/ash_export.h"
namespace ui {
class ContextFactory;
}
namespace ash {
class ShellDelegate;
......@@ -23,6 +27,8 @@ struct ASH_EXPORT ShellInitParams {
ShellDelegate* delegate;
ui::ContextFactory* context_factory;
#if defined(OS_WIN)
HWND remote_hwnd;
#endif
......
......@@ -65,7 +65,8 @@ void AshTestHelper::SetUp(bool start_session) {
ui::InitializeInputMethodForTesting();
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
// Creates Shell and hook with Desktop.
if (!test_shell_delegate_)
......@@ -87,6 +88,7 @@ void AshTestHelper::SetUp(bool start_session) {
#endif
ShellInitParams init_params;
init_params.delegate = test_shell_delegate_;
init_params.context_factory = context_factory;
ash::Shell::CreateInstance(init_params);
aura::test::EnvTestHelper(aura::Env::GetInstance()).SetInputStateLookup(
scoped_ptr<aura::InputStateLookup>());
......
......@@ -19,6 +19,7 @@
#include "chrome/browser/ui/ash/screenshot_taker.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/context_factory.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h"
......@@ -62,6 +63,7 @@ void OpenAsh(gfx::AcceleratedWidget remote_window) {
ash::ShellInitParams shell_init_params;
// Shell takes ownership of ChromeShellDelegate.
shell_init_params.delegate = new ChromeShellDelegate;
shell_init_params.context_factory = content::GetContextFactory();
#if defined(OS_WIN)
shell_init_params.remote_hwnd = remote_window;
#endif
......
......@@ -52,6 +52,7 @@ class AccessibilityViewsDelegate : public views::TestViewsDelegate {
view, event_type);
}
private:
DISALLOW_COPY_AND_ASSIGN(AccessibilityViewsDelegate);
};
......@@ -110,10 +111,11 @@ class AccessibilityEventRouterViewsTest
#if defined(USE_AURA)
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp();
aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window());
#endif // USE_AURA
EnableAccessibilityAndListenToFocusNotifications();
......@@ -126,7 +128,6 @@ class AccessibilityEventRouterViewsTest
ui::TerminateContextFactoryForTests();
#endif
delete views::ViewsDelegate::views_delegate;
views::ViewsDelegate::views_delegate = NULL;
// The Widget's FocusManager is deleted using DeleteSoon - this
// forces it to be deleted now, so we don't have any memory leaks
......
......@@ -19,6 +19,7 @@
#if defined(USE_AURA)
#include "ui/aura/test/aura_test_helper.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/test/context_factories_for_test.h"
#include "ui/wm/core/default_activation_client.h"
#endif
......@@ -68,11 +69,12 @@ void BrowserWithTestWindowTest::SetUp() {
#elif defined(USE_AURA)
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset(new aura::test::AuraTestHelper(
base::MessageLoopForUI::current()));
aura_test_helper_->SetUp();
aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window());
#endif // USE_AURA
#if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS)
......
......@@ -109,7 +109,8 @@ void ViewEventTestBase::SetUp() {
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
#if defined(OS_CHROMEOS)
// Ash Shell can't just live on its own without a browser process, we need to
......@@ -122,6 +123,7 @@ void ViewEventTestBase::SetUp() {
new ash::test::TestShellDelegate();
ash::ShellInitParams init_params;
init_params.delegate = shell_delegate;
init_params.context_factory = context_factory;
ash::Shell::CreateInstance(init_params);
shell_delegate->test_session_state_delegate()
->SetActiveUserSessionStarted(true);
......@@ -133,12 +135,13 @@ void ViewEventTestBase::SetUp() {
gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen());
aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory);
#elif defined(USE_AURA)
// Instead of using the ash shell, use an AuraTestHelper to create and manage
// the test screen.
aura_test_helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
aura_test_helper_->SetUp();
aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window());
context = aura_test_helper_->root_window();
#endif
......
......@@ -67,6 +67,7 @@
#endif
#if defined(USE_AURA)
#include "content/public/browser/context_factory.h"
#include "ui/aura/env.h"
#endif
......@@ -942,6 +943,12 @@ int BrowserMainLoop::BrowserThreadsStarted() {
}
BrowserGpuChannelHostFactory::Initialize(established_gpu_channel);
ImageTransportFactory::Initialize();
#if defined(USE_AURA)
if (aura::Env::GetInstance()) {
aura::Env::GetInstance()->set_context_factory(
content::GetContextFactory());
}
#endif
}
#elif defined(OS_ANDROID)
established_gpu_channel = true;
......
......@@ -90,9 +90,11 @@ SoftwareBrowserCompositorOutputSurfaceTest::
void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() {
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget));
compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
context_factory));
surface_proxy_ =
new content::BrowserCompositorOutputSurfaceProxy(&surface_map_);
}
......
......@@ -99,13 +99,15 @@ SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() {
}
void SoftwareOutputDeviceOzoneTest::SetUp() {
ui::InitializeContextFactoryForTests(enable_pixel_output_);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output_);
surface_factory_.reset(new MockSurfaceFactoryOzone());
const gfx::Size size(500, 400);
compositor_.reset(new ui::Compositor(
gfx::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget()));
gfx::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget(),
context_factory));
compositor_->SetScaleAndSize(1.0f, size);
output_device_.reset(new content::SoftwareOutputDeviceOzone(
......
......@@ -63,9 +63,10 @@ class DesktopCaptureDeviceAuraTest : public testing::Test {
virtual void SetUp() OVERRIDE {
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
helper_->SetUp();
helper_->SetUp(context_factory);
new wm::DefaultActivationClient(helper_->root_window());
// We need a window to cover desktop area so that DesktopCaptureDeviceAura
......
......@@ -209,10 +209,11 @@ class RenderWidgetHostViewAuraTest : public testing::Test {
: browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
void SetUpEnvironment() {
ui::ContextFactory* context_factory = new ui::InProcessContextFactory;
ImageTransportFactory::InitializeForUnitTests(
scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory));
scoped_ptr<ui::ContextFactory>(context_factory));
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp();
aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window());
browser_context_.reset(new TestBrowserContext);
......
......@@ -170,11 +170,12 @@ void RenderViewHostTestHarness::SetUp() {
#if defined(USE_AURA)
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
aura_test_helper_->SetUp();
aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window());
#endif
......
......@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/context_factory.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/context_menu_params.h"
......@@ -424,7 +425,8 @@ void Shell::PlatformInitialize(const gfx::Size& default_window_size) {
chromeos::DBusThreadManager::Initialize();
gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create());
wm_test_helper_ = new wm::WMTestHelper(default_window_size);
wm_test_helper_ = new wm::WMTestHelper(default_window_size,
GetContextFactory());
#else
gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen());
......
......@@ -48,6 +48,7 @@ WindowTreeHostMojo::WindowTreeHostMojo(
}
context_factory_ = new ContextFactoryMojo(gles2_handle.Pass());
ui::ContextFactory::SetInstance(context_factory_);
aura::Env::GetInstance()->set_context_factory(context_factory_);
CHECK(context_factory_) << "No GL bindings.";
native_viewport_->CreateGLES2Context(gles2_client_handle.Pass());
......
......@@ -305,6 +305,7 @@ int main(int argc, char** argv) {
base::MessageLoopForUI message_loop;
aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory.get());
scoped_ptr<aura::TestScreen> test_screen(
aura::TestScreen::CreateFullscreen());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
......
......@@ -129,6 +129,7 @@ int DemoMain() {
base::MessageLoopForUI message_loop;
aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory.get());
scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
scoped_ptr<aura::WindowTreeHost> host(
......
......@@ -66,7 +66,8 @@ bool Env::IsMouseButtonDown() const {
Env::Env()
: mouse_button_flags_(0),
is_touch_down_(false),
input_state_lookup_(InputStateLookup::Create().Pass()) {
input_state_lookup_(InputStateLookup::Create().Pass()),
context_factory_(NULL) {
DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL);
lazy_tls_ptr.Pointer()->Set(this);
}
......
......@@ -13,6 +13,7 @@
#include "ui/gfx/point.h"
namespace ui {
class ContextFactory;
class PlatformEventSource;
}
namespace aura {
......@@ -59,6 +60,11 @@ class AURA_EXPORT Env : public ui::EventTarget {
bool is_touch_down() const { return is_touch_down_; }
void set_touch_down(bool value) { is_touch_down_ = value; }
void set_context_factory(ui::ContextFactory* context_factory) {
context_factory_ = context_factory;
}
ui::ContextFactory* context_factory() { return context_factory_; }
private:
friend class test::EnvTestHelper;
friend class Window;
......@@ -95,6 +101,8 @@ class AURA_EXPORT Env : public ui::EventTarget {
scoped_ptr<InputStateLookup> input_state_lookup_;
scoped_ptr<ui::PlatformEventSource> event_source_;
ui::ContextFactory* context_factory_;
DISALLOW_COPY_AND_ASSIGN(Env);
};
......
......@@ -73,10 +73,11 @@ void AuraTestBase::SetUp() {
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
helper_.reset(new AuraTestHelper(&message_loop_));
helper_->SetUp();
helper_->SetUp(context_factory);
}
void AuraTestBase::TearDown() {
......
......@@ -52,10 +52,11 @@ AuraTestHelper::~AuraTestHelper() {
<< "AuraTestHelper::TearDown() never called.";
}
void AuraTestHelper::SetUp() {
void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) {
setup_called_ = true;
Env::CreateInstance(true);
Env::GetInstance()->set_context_factory(context_factory);
// Unit tests generally don't want to query the system, rather use the state
// from RootWindow.
EnvTestHelper(Env::GetInstance()).SetInputStateLookup(
......
......@@ -15,6 +15,7 @@ class MessageLoopForUI;
}
namespace ui {
class ContextFactory;
class InputMethod;
class ScopedAnimationDurationScaleMode;
}
......@@ -37,7 +38,7 @@ class AuraTestHelper {
~AuraTestHelper();
// Creates and initializes (shows and sizes) the RootWindow for use in tests.
void SetUp();
void SetUp(ui::ContextFactory* context_factory);
// Clean up objects that are created for tests. This also deletes the Env
// object.
......
......@@ -198,8 +198,11 @@ void WindowTreeHost::DestroyDispatcher() {
void WindowTreeHost::CreateCompositor(
gfx::AcceleratedWidget accelerated_widget) {
compositor_.reset(new ui::Compositor(GetAcceleratedWidget()));
DCHECK(compositor_.get());
DCHECK(Env::GetInstance());
ui::ContextFactory* context_factory = Env::GetInstance()->context_factory();
DCHECK(context_factory);
compositor_.reset(
new ui::Compositor(GetAcceleratedWidget(), context_factory));
// TODO(beng): I think this setup should probably all move to a "accelerated
// widget available" function.
if (!dispatcher()) {
......
......@@ -18,6 +18,7 @@
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer_type.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/context_factories_for_test.h"
......@@ -165,10 +166,11 @@ class KeyboardControllerTest : public testing::Test {
virtual void SetUp() OVERRIDE {
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp();
aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window());
ui::SetUpInputMethodFactoryForTesting();
focus_controller_.reset(new TestFocusController(root_window()));
......
......@@ -13,6 +13,7 @@
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/test/context_factories_for_test.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
......@@ -89,11 +90,12 @@ class SnapshotAuraTest : public testing::Test {
// The ContextFactory must exist before any Compositors are created.
// Snapshot test tests real drawing and readback, so needs pixel output.
bool enable_pixel_output = true;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
helper_->SetUp();
helper_->SetUp(context_factory);
new ::wm::DefaultActivationClient(helper_->root_window());
}
......
......@@ -11,6 +11,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "content/public/browser/context_factory.h"
#include "content/public/common/content_switches.h"
#include "content/shell/browser/shell_browser_context.h"
#include "ui/aura/env.h"
......@@ -54,7 +55,8 @@ void ExamplesBrowserMainParts::PreMainMessageLoopRun() {
gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create());
// Set up basic pieces of views::corewm.
wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600)));
wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600),
content::GetContextFactory()));
// Ensure the X window gets mapped.
wm_test_helper_->host()->Show();
// Ensure Aura knows where to open new windows.
......
......@@ -15,11 +15,7 @@ namespace views {
TestViewsDelegate::TestViewsDelegate()
: use_desktop_native_widgets_(false),
use_transparent_windows_(false)
#if defined(USE_AURA)
, context_factory_(NULL)
#endif
{
use_transparent_windows_(false) {
DCHECK(!ViewsDelegate::views_delegate);
ViewsDelegate::views_delegate = this;
#if defined(USE_AURA)
......@@ -46,10 +42,4 @@ void TestViewsDelegate::OnBeforeWidgetInit(
#endif // !defined(OS_CHROMEOS)
}
#if defined(USE_AURA)
ui::ContextFactory* TestViewsDelegate::GetContextFactory() {
return context_factory_;
}
#endif
} // namespace views
......@@ -30,19 +30,10 @@ class TestViewsDelegate : public ViewsDelegate {
use_transparent_windows_ = transparent;
}
#if defined(USE_AURA)
void set_context_factory(ui::ContextFactory* context_factory) {
context_factory_ = context_factory;
}
#endif
// ViewsDelegate:
virtual void OnBeforeWidgetInit(
Widget::InitParams* params,
internal::NativeWidgetDelegate* delegate) OVERRIDE;
#if defined(USE_AURA)
virtual ui::ContextFactory* GetContextFactory() OVERRIDE;
#endif
private:
bool use_desktop_native_widgets_;
......
......@@ -31,9 +31,10 @@ void ViewsTestBase::SetUp() {
views_delegate_.reset(new TestViewsDelegate());
// The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
test_helper_.reset(ViewsTestHelper::Create(&message_loop_));
test_helper_.reset(ViewsTestHelper::Create(&message_loop_, context_factory));
test_helper_->SetUp();
ui::InitializeInputMethodForTesting();
}
......
......@@ -8,7 +8,8 @@ namespace views {
#if !defined(USE_AURA)
// static
ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop) {
ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop,
ui::ContextFactory* context_factory) {
return new ViewsTestHelper;
}
#endif
......
......@@ -11,6 +11,10 @@ namespace base {
class MessageLoopForUI;
}
namespace ui {
class ContextFactory;
}
namespace views {
// A helper class owned by tests that performs platform specific initialization
......@@ -21,7 +25,8 @@ class ViewsTestHelper {
virtual ~ViewsTestHelper();
// Create a platform specific instance.
static ViewsTestHelper* Create(base::MessageLoopForUI* message_loop);
static ViewsTestHelper* Create(base::MessageLoopForUI* message_loop,
ui::ContextFactory* context_factory);
// Creates objects that are needed for tests.
virtual void SetUp();
......
......@@ -12,11 +12,14 @@
namespace views {
// static
ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop) {
return new ViewsTestHelperAura(message_loop);
ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop,
ui::ContextFactory* context_factory) {
return new ViewsTestHelperAura(message_loop, context_factory);
}
ViewsTestHelperAura::ViewsTestHelperAura(base::MessageLoopForUI* message_loop) {
ViewsTestHelperAura::ViewsTestHelperAura(base::MessageLoopForUI* message_loop,
ui::ContextFactory* context_factory)
: context_factory_(context_factory) {
aura_test_helper_.reset(new aura::test::AuraTestHelper(message_loop));
}
......@@ -24,7 +27,7 @@ ViewsTestHelperAura::~ViewsTestHelperAura() {
}
void ViewsTestHelperAura::SetUp() {
aura_test_helper_->SetUp();
aura_test_helper_->SetUp(context_factory_);
new wm::DefaultActivationClient(aura_test_helper_->root_window());
wm_state_.reset(new wm::WMState);
}
......
......@@ -28,7 +28,8 @@ namespace views {
class ViewsTestHelperAura : public ViewsTestHelper {
public:
explicit ViewsTestHelperAura(base::MessageLoopForUI* message_loop);
ViewsTestHelperAura(base::MessageLoopForUI* message_loop,
ui::ContextFactory* context_factory);
virtual ~ViewsTestHelperAura();
// Overridden from ViewsTestHelper:
......@@ -37,6 +38,7 @@ class ViewsTestHelperAura : public ViewsTestHelper {
virtual gfx::NativeView GetContext() OVERRIDE;
private:
ui::ContextFactory* context_factory_;
scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
scoped_ptr<wm::WMState> wm_state_;
......
......@@ -14,8 +14,10 @@
namespace wm {
WMTestHelper::WMTestHelper(const gfx::Size& default_window_size) {
WMTestHelper::WMTestHelper(const gfx::Size& default_window_size,
ui::ContextFactory* context_factory) {
aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory);
host_.reset(aura::WindowTreeHost::Create(gfx::Rect(default_window_size)));
host_->InitHost();
aura::client::SetWindowTreeClient(host_->window(), this);
......
......@@ -24,6 +24,10 @@ class Rect;
class Size;
}
namespace ui {
class ContextFactory;
}
namespace wm {
class CompoundEventFilter;
......@@ -34,7 +38,8 @@ class InputMethodEventFilter;
// the ash parts of the code.
class WMTestHelper : public aura::client::WindowTreeClient {
public:
explicit WMTestHelper(const gfx::Size& default_window_size);
WMTestHelper(const gfx::Size& default_window_size,
ui::ContextFactory* context_factory);
virtual ~WMTestHelper();
aura::WindowTreeHost* host() { return host_.get(); }
......
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