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_PLATFORM_WINDOWS_WRAPPER_TESTING_STUB_FLUTTER_WINDOWS_API_H_ 6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_WRAPPER_TESTING_STUB_FLUTTER_WINDOWS_API_H_ 7 8 #include <memory> 9 10 #include "flutter/shell/platform/windows/public/flutter_windows.h" 11 12 namespace flutter { 13 namespace testing { 14 15 // Base class for a object that provides test implementations of the APIs in 16 // the headers in platform/windows/public/. 17 18 // Linking this class into a test binary will provide dummy forwarding 19 // implementantions of that C API, so that the wrapper can be tested separately 20 // from the actual library. 21 class StubFlutterWindowsApi { 22 public: 23 // Sets |stub| as the instance to which calls to the Flutter library C APIs 24 // will be forwarded. 25 static void SetTestStub(StubFlutterWindowsApi* stub); 26 27 // Returns the current stub, as last set by SetTestFluttterStub. 28 static StubFlutterWindowsApi* GetTestStub(); 29 ~StubFlutterWindowsApi()30 virtual ~StubFlutterWindowsApi() {} 31 32 // Called for FlutterDesktopInit. Init()33 virtual bool Init() { return true; } 34 35 // Called for FlutterDesktopTerminate. Terminate()36 virtual void Terminate() {} 37 38 // Called for FlutterDesktopCreateWindow. CreateWindow(int initial_width,int initial_height,const char * title,const char * assets_path,const char * icu_data_path,const char ** arguments,size_t argument_count)39 virtual FlutterDesktopWindowControllerRef CreateWindow( 40 int initial_width, 41 int initial_height, 42 const char* title, 43 const char* assets_path, 44 const char* icu_data_path, 45 const char** arguments, 46 size_t argument_count) { 47 return nullptr; 48 } 49 50 // Called for FlutterDesktopDestroyWindow. DestroyWindow()51 virtual void DestroyWindow() {} 52 53 // Called for FlutterDesktopSetHoverEnabled. SetHoverEnabled(bool enabled)54 virtual void SetHoverEnabled(bool enabled) {} 55 56 // Called for FlutterDesktopSetWindowTitle. SetWindowTitle(const char * title)57 virtual void SetWindowTitle(const char* title) {} 58 59 // Called for FlutterDesktopSetWindowIcon. SetWindowIcon(uint8_t * pixel_data,int width,int height)60 virtual void SetWindowIcon(uint8_t* pixel_data, int width, int height) {} 61 62 // Called for FlutterDesktopRunWindowLoop. RunWindowLoop()63 virtual void RunWindowLoop() {} 64 65 // Called for FlutterDesktopRunEngine. RunEngine(const char * assets_path,const char * icu_data_path,const char ** arguments,size_t argument_count)66 virtual FlutterDesktopEngineRef RunEngine(const char* assets_path, 67 const char* icu_data_path, 68 const char** arguments, 69 size_t argument_count) { 70 return nullptr; 71 } 72 73 // Called for FlutterDesktopShutDownEngine. ShutDownEngine()74 virtual bool ShutDownEngine() { return true; } 75 }; 76 77 // A test helper that owns a stub implementation, making it the test stub for 78 // the lifetime of the object, then restoring the previous value. 79 class ScopedStubFlutterWindowsApi { 80 public: 81 // Calls SetTestFlutterStub with |stub|. 82 ScopedStubFlutterWindowsApi(std::unique_ptr<StubFlutterWindowsApi> stub); 83 84 // Restores the previous test stub. 85 ~ScopedStubFlutterWindowsApi(); 86 stub()87 StubFlutterWindowsApi* stub() { return stub_.get(); } 88 89 private: 90 std::unique_ptr<StubFlutterWindowsApi> stub_; 91 // The previous stub. 92 StubFlutterWindowsApi* previous_stub_; 93 }; 94 95 } // namespace testing 96 } // namespace flutter 97 98 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_TESTING_STUB_FLUTTER_WINDOWS_API_H_ 99