10f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
20f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
30f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// found in the LICENSE file.
40f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
50f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "ui/ozone/platform/test/ozone_platform_test.h"
60f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
70f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/command_line.h"
80f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/files/file_path.h"
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
1003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "ui/events/platform/platform_event_source.h"
11116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/ozone/platform/test/test_window.h"
12116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/ozone/platform/test/test_window_manager.h"
136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "ui/ozone/public/cursor_factory_ozone.h"
14116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/ozone/public/gpu_platform_support.h"
15116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/ozone/public/gpu_platform_support_host.h"
16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/ozone/public/ozone_platform.h"
17116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/ozone/public/ozone_switches.h"
180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
19a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#if defined(OS_CHROMEOS)
20a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/ozone/common/chromeos/native_display_delegate_ozone.h"
21a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#endif
22a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace ui {
240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochnamespace {
260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// OzonePlatform for testing
280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch//
290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// This platform dumps images to a file for testing purposes.
300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass OzonePlatformTest : public OzonePlatform {
310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch public:
32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  OzonePlatformTest(const base::FilePath& dump_file) : file_path_(dump_file) {}
330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual ~OzonePlatformTest() {}
340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // OzonePlatform:
366d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE {
37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return window_manager_.get();
380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual CursorFactoryOzone* GetCursorFactoryOzone() OVERRIDE {
40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return cursor_factory_ozone_.get();
410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual GpuPlatformSupport* GetGpuPlatformSupport() OVERRIDE {
43116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return gpu_platform_support_.get();
446d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
456d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual GpuPlatformSupportHost* GetGpuPlatformSupportHost() OVERRIDE {
46116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return gpu_platform_support_host_.get();
47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual scoped_ptr<PlatformWindow> CreatePlatformWindow(
49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      PlatformWindowDelegate* delegate,
50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const gfx::Rect& bounds) OVERRIDE {
51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return make_scoped_ptr<PlatformWindow>(
52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        new TestWindow(delegate, window_manager_.get(), bounds));
536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#if defined(OS_CHROMEOS)
56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate()
570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      OVERRIDE {
58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone());
59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#endif
610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void InitializeUI() OVERRIDE {
63116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    window_manager_.reset(new TestWindowManager(file_path_));
64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    window_manager_->Initialize();
6503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // This unbreaks tests that create their own.
6603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (!PlatformEventSource::GetInstance())
6703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      platform_event_source_ = PlatformEventSource::CreateDefault();
6803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
73116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void InitializeGPU() OVERRIDE {
74116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    gpu_platform_support_.reset(CreateStubGpuPlatformSupport());
75116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
76cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch private:
78116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<TestWindowManager> window_manager_;
7903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  scoped_ptr<PlatformEventSource> platform_event_source_;
80cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<CursorFactoryOzone> cursor_factory_ozone_;
81116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<GpuPlatformSupport> gpu_platform_support_;
82116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<GpuPlatformSupportHost> gpu_platform_support_host_;
83cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  base::FilePath file_path_;
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DISALLOW_COPY_AND_ASSIGN(OzonePlatformTest);
860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}  // namespace
89a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)OzonePlatform* CreateOzonePlatformTest() {
910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  CommandLine* cmd = CommandLine::ForCurrentProcess();
926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  base::FilePath location;
930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  if (cmd->HasSwitch(switches::kOzoneDumpFile))
940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    location = cmd->GetSwitchValuePath(switches::kOzoneDumpFile);
950f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  return new OzonePlatformTest(location);
960f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}  // namespace ui
99