1 // Copyright (c) 2016 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #include "include/base/cef_callback.h" 6 #include "include/base/cef_weak_ptr.h" 7 #include "include/cef_waitable_event.h" 8 #include "include/views/cef_window.h" 9 #include "include/views/cef_window_delegate.h" 10 11 class TestWindowDelegate : public CefWindowDelegate { 12 public: 13 // Default window size. 14 static const int kWSize; 15 16 // Test execution callback. 17 typedef base::Callback<void(CefRefPtr<CefWindow>)> OnWindowCreatedCallback; 18 typedef base::Callback<void(CefRefPtr<CefWindow>)> OnWindowDestroyedCallback; 19 typedef base::Callback<bool(CefRefPtr<CefWindow>, int)> OnAcceleratorCallback; 20 typedef base::Callback<bool(CefRefPtr<CefWindow>, const CefKeyEvent&)> 21 OnKeyEventCallback; 22 23 struct Config { 24 OnWindowCreatedCallback on_window_created; 25 OnWindowDestroyedCallback on_window_destroyed; 26 OnAcceleratorCallback on_accelerator; 27 OnKeyEventCallback on_key_event; 28 bool frameless = false; 29 bool close_window = true; 30 int window_size = kWSize; 31 CefPoint window_origin = {}; 32 }; 33 34 // Creates a Window with a new TestWindowDelegate instance and executes 35 // |window_test| after the Window is created. |event| will be signaled once 36 // the Window is closed. If |frameless| is true the Window will be created 37 // without a frame. If |close_window| is true the Window will be closed 38 // immediately after |window_test| returns. Otherwise, the caller is 39 // responsible for closing the Window passed to |window_test|. 40 static void RunTest(CefRefPtr<CefWaitableEvent> event, const Config& config); 41 42 // CefWindowDelegate methods: 43 void OnWindowCreated(CefRefPtr<CefWindow> window) override; 44 void OnWindowDestroyed(CefRefPtr<CefWindow> window) override; 45 bool IsFrameless(CefRefPtr<CefWindow> window) override; 46 CefRect GetInitialBounds(CefRefPtr<CefWindow> window) override; 47 CefSize GetPreferredSize(CefRefPtr<CefView> view) override; 48 bool OnAccelerator(CefRefPtr<CefWindow> window, int command_id) override; 49 bool OnKeyEvent(CefRefPtr<CefWindow> window, 50 const CefKeyEvent& event) override; 51 52 private: 53 TestWindowDelegate(CefRefPtr<CefWaitableEvent> event, 54 const Config& config, 55 const CefSize& window_size); 56 ~TestWindowDelegate() override; 57 58 void OnCloseWindow(); 59 void OnTimeoutWindow(); 60 61 CefRefPtr<CefWaitableEvent> event_; 62 const Config config_; 63 const CefSize window_size_; 64 65 CefRefPtr<CefWindow> window_; 66 67 bool got_get_initial_bounds_ = false; 68 bool got_get_preferred_size_ = false; 69 70 // Must be the last member. 71 base::WeakPtrFactory<TestWindowDelegate> weak_ptr_factory_; 72 73 IMPLEMENT_REFCOUNTING(TestWindowDelegate); 74 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); 75 }; 76