da94ba4b3f7e1ab18de5dbd0036183b8e2451fc7
[platform/framework/web/crosswalk.git] / src / ui / ozone / platform / test / ozone_platform_test.cc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/ozone/platform/test/ozone_platform_test.h"
6
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "ui/base/cursor/ozone/cursor_factory_ozone.h"
10 #include "ui/events/ozone/evdev/event_factory_evdev.h"
11 #include "ui/gfx/ozone/impl/file_surface_factory.h"
12 #include "ui/ozone/ime/input_method_context_factory_ozone.h"
13 #include "ui/ozone/ozone_platform.h"
14 #include "ui/ozone/ozone_switches.h"
15
16 #if defined(OS_CHROMEOS)
17 #include "ui/ozone/common/chromeos/native_display_delegate_ozone.h"
18 #endif
19
20 namespace ui {
21
22 namespace {
23
24 // OzonePlatform for testing
25 //
26 // This platform dumps images to a file for testing purposes.
27 class OzonePlatformTest : public OzonePlatform {
28  public:
29   OzonePlatformTest(const base::FilePath& dump_file)
30       : surface_factory_ozone_(dump_file) {}
31   virtual ~OzonePlatformTest() {}
32
33   // OzonePlatform:
34   virtual gfx::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE {
35     return &surface_factory_ozone_;
36   }
37   virtual ui::EventFactoryOzone* GetEventFactoryOzone() OVERRIDE {
38     return &event_factory_ozone_;
39   }
40   virtual ui::InputMethodContextFactoryOzone*
41   GetInputMethodContextFactoryOzone() OVERRIDE {
42     return &input_method_context_factory_ozone_;
43   }
44   virtual ui::CursorFactoryOzone* GetCursorFactoryOzone() OVERRIDE {
45     return &cursor_factory_ozone_;
46   }
47
48 #if defined(OS_CHROMEOS)
49   virtual scoped_ptr<ui::NativeDisplayDelegate> CreateNativeDisplayDelegate()
50       OVERRIDE {
51     return scoped_ptr<ui::NativeDisplayDelegate>(
52         new NativeDisplayDelegateOzone());
53   }
54 #endif
55
56  private:
57   gfx::FileSurfaceFactory surface_factory_ozone_;
58   ui::EventFactoryEvdev event_factory_ozone_;
59   ui::InputMethodContextFactoryOzone input_method_context_factory_ozone_;
60   ui::CursorFactoryOzone cursor_factory_ozone_;
61
62   DISALLOW_COPY_AND_ASSIGN(OzonePlatformTest);
63 };
64
65 }  // namespace
66
67 OzonePlatform* CreateOzonePlatformTest() {
68   CommandLine* cmd = CommandLine::ForCurrentProcess();
69   base::FilePath location = base::FilePath("/dev/null");
70   if (cmd->HasSwitch(switches::kOzoneDumpFile))
71     location = cmd->GetSwitchValuePath(switches::kOzoneDumpFile);
72   return new OzonePlatformTest(location);
73 }
74
75 }  // namespace ui