1 // Copyright 2015 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 #ifndef COMPONENTS_EXO_TEST_EXO_TEST_BASE_H_
6 #define COMPONENTS_EXO_TEST_EXO_TEST_BASE_H_
7 
8 #include <memory>
9 
10 #include "ash/test/ash_test_base.h"
11 #include "base/macros.h"
12 #include "components/exo/test/exo_test_helper.h"
13 
14 namespace viz {
15 class SurfaceManager;
16 }
17 
18 namespace exo {
19 class WMHelper;
20 class Buffer;
21 
22 namespace test {
23 class ExoTestHelper;
24 
25 class ExoTestBase : public ash::AshTestBase {
26  public:
27   ExoTestBase();
28 
29   // Constructs an ExoTestBase with |traits| being forwarded to its
30   // TaskEnvironment. See the corresponding |AshTestBase| constructor.
31   template <typename... TaskEnvironmentTraits>
ExoTestBase(TaskEnvironmentTraits &&...traits)32   NOINLINE explicit ExoTestBase(TaskEnvironmentTraits&&... traits)
33       : AshTestBase(std::forward<TaskEnvironmentTraits>(traits)...) {}
34 
35   ~ExoTestBase() override;
36 
37   // TODO(oshima): Convert unit tests to use this.
38   class ShellSurfaceHolder {
39    public:
40     ShellSurfaceHolder(std::unique_ptr<Buffer> buffer,
41                        std::unique_ptr<Surface> surface,
42                        std::unique_ptr<ShellSurface> shell_surface);
43     ~ShellSurfaceHolder();
44     ShellSurfaceHolder(const ShellSurfaceHolder&) = delete;
45     ShellSurfaceHolder& operator=(const ShellSurfaceHolder&) = delete;
46 
shell_surface()47     ShellSurface* shell_surface() { return shell_surface_.get(); }
48 
49    private:
50     std::unique_ptr<Buffer> buffer_;
51     std::unique_ptr<Surface> surface_;
52     std::unique_ptr<ShellSurface> shell_surface_;
53   };
54 
55   // ash::AshTestBase:
56   void SetUp() override;
57   void TearDown() override;
58 
59   viz::SurfaceManager* GetSurfaceManager();
60 
61   std::unique_ptr<ShellSurfaceHolder> CreateShellSurfaceHolder(
62       const gfx::Size& buffer_size,
63       ShellSurface* parent);
64 
exo_test_helper()65   ExoTestHelper* exo_test_helper() { return &exo_test_helper_; }
wm_helper()66   WMHelper* wm_helper() { return wm_helper_.get(); }
67 
68  private:
69   ExoTestHelper exo_test_helper_;
70   std::unique_ptr<WMHelper> wm_helper_;
71 
72   DISALLOW_COPY_AND_ASSIGN(ExoTestBase);
73 };
74 
75 }  // namespace test
76 }  // namespace exo
77 
78 #endif  // COMPONENTS_EXO_TEST_EXO_TEST_BASE_H_
79