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 3 // found in the LICENSE file. 4 5 #ifndef UI_AURA_TEST_AURA_TEST_HELPER_H_ 6 #define UI_AURA_TEST_AURA_TEST_HELPER_H_ 7 8 #include "base/basictypes.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "ui/aura/window_event_dispatcher.h" 11 #include "ui/aura/window_tree_host.h" 12 13 namespace base { 14 class MessageLoopForUI; 15 } 16 17 namespace ui { 18 class ContextFactory; 19 class InputMethod; 20 class ScopedAnimationDurationScaleMode; 21 } 22 23 namespace aura { 24 class TestScreen; 25 namespace client { 26 class DefaultCaptureClient; 27 class FocusClient; 28 } 29 namespace test { 30 class TestWindowTreeClient; 31 32 // A helper class owned by tests that does common initialization required for 33 // Aura use. This class creates a root window with clients and other objects 34 // that are necessary to run test on Aura. 35 class AuraTestHelper { 36 public: 37 explicit AuraTestHelper(base::MessageLoopForUI* message_loop); 38 ~AuraTestHelper(); 39 40 // Creates and initializes (shows and sizes) the RootWindow for use in tests. 41 void SetUp(ui::ContextFactory* context_factory); 42 43 // Clean up objects that are created for tests. This also deletes the Env 44 // object. 45 void TearDown(); 46 47 // Flushes message loop. 48 void RunAllPendingInMessageLoop(); 49 root_window()50 Window* root_window() { return host_->window(); } event_processor()51 ui::EventProcessor* event_processor() { return host_->event_processor(); } host()52 WindowTreeHost* host() { return host_.get(); } 53 test_screen()54 TestScreen* test_screen() { return test_screen_.get(); } 55 56 private: 57 base::MessageLoopForUI* message_loop_; 58 bool setup_called_; 59 bool teardown_called_; 60 bool owns_host_; 61 scoped_ptr<WindowTreeHost> host_; 62 scoped_ptr<TestWindowTreeClient> stacking_client_; 63 scoped_ptr<client::DefaultCaptureClient> capture_client_; 64 scoped_ptr<ui::InputMethod> test_input_method_; 65 scoped_ptr<client::FocusClient> focus_client_; 66 scoped_ptr<TestScreen> test_screen_; 67 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; 68 69 DISALLOW_COPY_AND_ASSIGN(AuraTestHelper); 70 }; 71 72 } // namespace test 73 } // namespace aura 74 75 #endif // UI_AURA_TEST_AURA_TEST_HELPER_H_ 76