| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_AURA_TEST_AURA_TEST_HELPER_H_ | 5 #ifndef UI_AURA_TEST_AURA_TEST_HELPER_H_ |
| 6 #define UI_AURA_TEST_AURA_TEST_HELPER_H_ | 6 #define UI_AURA_TEST_AURA_TEST_HELPER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 class TestWindowParentingClient; | 46 class TestWindowParentingClient; |
| 47 | 47 |
| 48 // A helper class owned by tests that does common initialization required for | 48 // A helper class owned by tests that does common initialization required for |
| 49 // Aura use. This class creates a root window with clients and other objects | 49 // Aura use. This class creates a root window with clients and other objects |
| 50 // that are necessary to run test on Aura. | 50 // that are necessary to run test on Aura. |
| 51 class AuraTestHelper { | 51 class AuraTestHelper { |
| 52 public: | 52 public: |
| 53 explicit AuraTestHelper(base::MessageLoopForUI* message_loop); | 53 explicit AuraTestHelper(base::MessageLoopForUI* message_loop); |
| 54 ~AuraTestHelper(); | 54 ~AuraTestHelper(); |
| 55 | 55 |
| 56 void EnableMus(WindowTreeClientDelegate* window_tree_delegate, | 56 // Makes aura target mus with a mock WindowTree (TestWindowTree). Must be |
| 57 WindowManagerDelegate* window_manager_delegate); | 57 // called before SetUp(). |
| 58 void EnableMusWithTestWindowTree( |
| 59 WindowTreeClientDelegate* window_tree_delegate, |
| 60 WindowManagerDelegate* window_manager_delegate); |
| 61 |
| 62 // Makes aura target mus with the specified WindowTreeClient. Must be called |
| 63 // before SetUp(). |
| 64 void EnableMusWithWindowTreeClient(WindowTreeClient* window_tree_client); |
| 58 | 65 |
| 59 // Creates and initializes (shows and sizes) the RootWindow for use in tests. | 66 // Creates and initializes (shows and sizes) the RootWindow for use in tests. |
| 60 void SetUp(ui::ContextFactory* context_factory); | 67 void SetUp(ui::ContextFactory* context_factory); |
| 61 | 68 |
| 62 // Clean up objects that are created for tests. This also deletes the Env | 69 // Clean up objects that are created for tests. This also deletes the Env |
| 63 // object. | 70 // object. |
| 64 void TearDown(); | 71 void TearDown(); |
| 65 | 72 |
| 66 // Flushes message loop. | 73 // Flushes message loop. |
| 67 void RunAllPendingInMessageLoop(); | 74 void RunAllPendingInMessageLoop(); |
| 68 | 75 |
| 69 Window* root_window() { return host_->window(); } | 76 Window* root_window() { return host_->window(); } |
| 70 ui::EventProcessor* event_processor() { return host_->event_processor(); } | 77 ui::EventProcessor* event_processor() { return host_->event_processor(); } |
| 71 WindowTreeHost* host() { return host_.get(); } | 78 WindowTreeHost* host() { return host_.get(); } |
| 72 | 79 |
| 73 TestScreen* test_screen() { return test_screen_.get(); } | 80 TestScreen* test_screen() { return test_screen_.get(); } |
| 74 | 81 |
| 82 // This function only returns a valid value if EnableMusWithTestWindowTree() |
| 83 // was called. |
| 75 TestWindowTree* window_tree(); | 84 TestWindowTree* window_tree(); |
| 85 |
| 86 // Returns a WindowTreeClient only if one of the EnableMus functions is |
| 87 // called. |
| 76 WindowTreeClient* window_tree_client(); | 88 WindowTreeClient* window_tree_client(); |
| 77 | 89 |
| 78 client::FocusClient* focus_client() { return focus_client_.get(); } | 90 client::FocusClient* focus_client() { return focus_client_.get(); } |
| 79 client::CaptureClient* capture_client(); | 91 client::CaptureClient* capture_client(); |
| 80 | 92 |
| 81 private: | 93 private: |
| 82 Env::WindowPortFactory InitMus(); | 94 enum class Mode { |
| 95 // Classic aura. |
| 96 LOCAL, |
| 83 | 97 |
| 84 std::unique_ptr<WindowPort> CreateWindowPortMus(Window* window); | 98 // Mus with a test WindowTree implementation that does not target the real |
| 99 // service:ui. |
| 100 MUS_CREATE_WINDOW_TREE_CLIENT, |
| 85 | 101 |
| 86 base::MessageLoopForUI* message_loop_; | 102 // Mus without creating a WindowTree. This is used when the test wants to |
| 87 bool use_mus_ = false; | 103 // create the WindowTreeClient itself. This mode is enabled by way of |
| 104 // EnableMusWithWindowTreeClient(). |
| 105 MUS, |
| 106 }; |
| 107 |
| 108 // Initializes a WindowTreeClient with a test WindowTree. |
| 109 void InitWindowTreeClient(); |
| 110 |
| 111 // Factory function for creating the appropriate WindowPort function. |
| 112 std::unique_ptr<WindowPort> CreateWindowPort(Window* window); |
| 113 |
| 114 Mode mode_ = Mode::LOCAL; |
| 88 bool setup_called_; | 115 bool setup_called_; |
| 89 bool teardown_called_; | 116 bool teardown_called_; |
| 90 std::unique_ptr<TestWindowTreeClientSetup> window_tree_client_setup_; | 117 std::unique_ptr<TestWindowTreeClientSetup> window_tree_client_setup_; |
| 91 std::unique_ptr<aura::Env> env_; | 118 std::unique_ptr<aura::Env> env_; |
| 92 std::unique_ptr<wm::WMState> wm_state_; | 119 std::unique_ptr<wm::WMState> wm_state_; |
| 93 std::unique_ptr<WindowTreeHost> host_; | 120 std::unique_ptr<WindowTreeHost> host_; |
| 94 std::unique_ptr<TestWindowParentingClient> parenting_client_; | 121 std::unique_ptr<TestWindowParentingClient> parenting_client_; |
| 95 std::unique_ptr<client::DefaultCaptureClient> capture_client_; | 122 std::unique_ptr<client::DefaultCaptureClient> capture_client_; |
| 96 std::unique_ptr<client::FocusClient> focus_client_; | 123 std::unique_ptr<client::FocusClient> focus_client_; |
| 97 std::unique_ptr<TestScreen> test_screen_; | 124 std::unique_ptr<TestScreen> test_screen_; |
| 98 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; | 125 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; |
| 99 WindowTreeClientDelegate* window_tree_delegate_ = nullptr; | 126 WindowTreeClientDelegate* window_tree_delegate_ = nullptr; |
| 100 WindowManagerDelegate* window_manager_delegate_ = nullptr; | 127 WindowManagerDelegate* window_manager_delegate_ = nullptr; |
| 101 | 128 |
| 129 WindowTreeClient* window_tree_client_ = nullptr; |
| 130 |
| 102 DISALLOW_COPY_AND_ASSIGN(AuraTestHelper); | 131 DISALLOW_COPY_AND_ASSIGN(AuraTestHelper); |
| 103 }; | 132 }; |
| 104 | 133 |
| 105 } // namespace test | 134 } // namespace test |
| 106 } // namespace aura | 135 } // namespace aura |
| 107 | 136 |
| 108 #endif // UI_AURA_TEST_AURA_TEST_HELPER_H_ | 137 #endif // UI_AURA_TEST_AURA_TEST_HELPER_H_ |
| OLD | NEW |