• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter 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 FLUTTER_SHELL_COMMON_SHELL_TEST_H_
6 #define FLUTTER_SHELL_COMMON_SHELL_TEST_H_
7 
8 #include <memory>
9 
10 #include "flutter/common/settings.h"
11 #include "flutter/fml/macros.h"
12 #include "flutter/lib/ui/window/platform_message.h"
13 #include "flutter/shell/common/run_configuration.h"
14 #include "flutter/shell/common/shell.h"
15 #include "flutter/shell/common/thread_host.h"
16 #include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
17 #include "flutter/testing/test_dart_native_resolver.h"
18 #include "flutter/testing/test_gl_surface.h"
19 #include "flutter/testing/thread_test.h"
20 
21 namespace flutter {
22 namespace testing {
23 
24 class ShellTest : public ThreadTest {
25  public:
26   ShellTest();
27 
28   ~ShellTest();
29 
30   Settings CreateSettingsForFixture();
31   std::unique_ptr<Shell> CreateShell(Settings settings);
32   std::unique_ptr<Shell> CreateShell(Settings settings,
33                                      TaskRunners task_runners);
34   TaskRunners GetTaskRunnersForFixture();
35 
36   void SendEnginePlatformMessage(Shell* shell,
37                                  fml::RefPtr<PlatformMessage> message);
38 
39   void AddNativeCallback(std::string name, Dart_NativeFunction callback);
40 
41   static void PlatformViewNotifyCreated(
42       Shell* shell);  // This creates the surface
43   static void RunEngine(Shell* shell, RunConfiguration configuration);
44 
45   static void PumpOneFrame(Shell* shell);
46 
47   // Declare |UnreportedTimingsCount|, |GetNeedsReportTimings| and
48   // |SetNeedsReportTimings| inside |ShellTest| mainly for easier friend class
49   // declarations as shell unit tests and Shell are in different name spaces.
50 
51   static bool GetNeedsReportTimings(Shell* shell);
52   static void SetNeedsReportTimings(Shell* shell, bool value);
53 
54   // Do not assert |UnreportedTimingsCount| to be positive in any tests.
55   // Otherwise those tests will be flaky as the clearing of unreported timings
56   // is unpredictive.
57   static int UnreportedTimingsCount(Shell* shell);
58 
59  protected:
60   // |testing::ThreadTest|
61   void SetUp() override;
62 
63   // |testing::ThreadTest|
64   void TearDown() override;
65 
66  private:
67   fml::UniqueFD assets_dir_;
68   std::shared_ptr<TestDartNativeResolver> native_resolver_;
69   std::unique_ptr<ThreadHost> thread_host_;
70 
71   void SetSnapshotsAndAssets(Settings& settings);
72 };
73 
74 class ShellTestPlatformView : public PlatformView, public GPUSurfaceGLDelegate {
75  public:
76   ShellTestPlatformView(PlatformView::Delegate& delegate,
77                         TaskRunners task_runners);
78 
79   ~ShellTestPlatformView() override;
80 
81  private:
82   TestGLSurface gl_surface_;
83 
84   // |PlatformView|
85   std::unique_ptr<Surface> CreateRenderingSurface() override;
86 
87   // |GPUSurfaceGLDelegate|
88   bool GLContextMakeCurrent() override;
89 
90   // |GPUSurfaceGLDelegate|
91   bool GLContextClearCurrent() override;
92 
93   // |GPUSurfaceGLDelegate|
94   bool GLContextPresent() override;
95 
96   // |GPUSurfaceGLDelegate|
97   intptr_t GLContextFBO() const override;
98 
99   // |GPUSurfaceGLDelegate|
100   GLProcResolver GetGLProcResolver() const override;
101 
102   // |GPUSurfaceGLDelegate|
103   ExternalViewEmbedder* GetExternalViewEmbedder() override;
104 
105   FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
106 };
107 
108 }  // namespace testing
109 }  // namespace flutter
110 
111 #endif  // FLUTTER_SHELL_COMMON_SHELL_TEST_H_
112