// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_VIEWS_TEST_VIEWS_TEST_BASE_H_ #define UI_VIEWS_TEST_VIEWS_TEST_BASE_H_ #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" #include "ui/views/test/test_views_delegate.h" #if defined(OS_WIN) #include "ui/base/win/scoped_ole_initializer.h" #endif namespace views { class ViewsTestHelper; // A base class for views unit test. It creates a message loop necessary // to drive UI events and takes care of OLE initialization for windows. class ViewsTestBase : public PlatformTest { public: ViewsTestBase(); ~ViewsTestBase() override; // testing::Test: void SetUp() override; void TearDown() override; void RunPendingMessages(); // Creates a widget of |type| with any platform specific data for use in // cross-platform tests. Widget::InitParams CreateParams(Widget::InitParams::Type type); protected: TestViewsDelegate& views_delegate() const { return *views_delegate_.get(); } void set_views_delegate(TestViewsDelegate* views_delegate) { views_delegate_.reset(views_delegate); } base::MessageLoopForUI* message_loop() { return &message_loop_; } // Returns a context view. In aura builds, this will be the // RootWindow. Everywhere else, NULL. gfx::NativeWindow GetContext(); private: base::MessageLoopForUI message_loop_; scoped_ptr views_delegate_; scoped_ptr test_helper_; bool setup_called_; bool teardown_called_; #if defined(OS_WIN) ui::ScopedOleInitializer ole_initializer_; #endif DISALLOW_COPY_AND_ASSIGN(ViewsTestBase); }; } // namespace views #endif // UI_VIEWS_TEST_VIEWS_TEST_BASE_H_