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_VIEWS_TEST_VIEWS_TEST_BASE_H_ | 5 #ifndef UI_VIEWS_TEST_VIEWS_TEST_BASE_H_ |
6 #define UI_VIEWS_TEST_VIEWS_TEST_BASE_H_ | 6 #define UI_VIEWS_TEST_VIEWS_TEST_BASE_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
12 #include "ui/views/test/test_views_delegate.h" | 12 #include "ui/views/test/test_views_delegate.h" |
| 13 #include "ui/views/widget/widget.h" |
13 | 14 |
14 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
15 #include "ui/base/win/scoped_ole_initializer.h" | 16 #include "ui/base/win/scoped_ole_initializer.h" |
16 #endif | 17 #endif |
17 | 18 |
18 namespace views { | 19 namespace views { |
19 | 20 |
20 class ViewsTestHelper; | 21 class ViewsTestHelper; |
21 | 22 |
22 // A base class for views unit test. It creates a message loop necessary | 23 // A base class for views unit test. It creates a message loop necessary |
23 // to drive UI events and takes care of OLE initialization for windows. | 24 // to drive UI events and takes care of OLE initialization for windows. |
24 class ViewsTestBase : public PlatformTest { | 25 class ViewsTestBase : public PlatformTest { |
25 public: | 26 public: |
26 ViewsTestBase(); | 27 ViewsTestBase(); |
27 ~ViewsTestBase() override; | 28 ~ViewsTestBase() override; |
28 | 29 |
29 // testing::Test: | 30 // testing::Test: |
30 void SetUp() override; | 31 void SetUp() override; |
31 void TearDown() override; | 32 void TearDown() override; |
32 | 33 |
33 void RunPendingMessages(); | 34 void RunPendingMessages(); |
34 | 35 |
35 // Creates a widget of |type| with any platform specific data for use in | 36 // Creates a widget of |type| with any platform specific data for use in |
36 // cross-platform tests. | 37 // cross-platform tests. |
37 Widget::InitParams CreateParams(Widget::InitParams::Type type); | 38 Widget::InitParams CreateParams(Widget::InitParams::Type type); |
38 | 39 |
39 protected: | 40 protected: |
40 TestViewsDelegate& views_delegate() const { return *views_delegate_.get(); } | 41 TestViewsDelegate* views_delegate() const { return views_delegate_.get(); } |
41 | 42 |
42 void set_views_delegate(TestViewsDelegate* views_delegate) { | 43 void set_views_delegate(scoped_ptr<TestViewsDelegate> views_delegate) { |
43 views_delegate_.reset(views_delegate); | 44 views_delegate_.swap(views_delegate); |
44 } | 45 } |
45 | 46 |
46 base::MessageLoopForUI* message_loop() { return &message_loop_; } | 47 base::MessageLoopForUI* message_loop() { return &message_loop_; } |
47 | 48 |
48 // Returns a context view. In aura builds, this will be the | 49 // Returns a context view. In aura builds, this will be the |
49 // RootWindow. Everywhere else, NULL. | 50 // RootWindow. Everywhere else, NULL. |
50 gfx::NativeWindow GetContext(); | 51 gfx::NativeWindow GetContext(); |
51 | 52 |
52 private: | 53 private: |
53 base::MessageLoopForUI message_loop_; | 54 base::MessageLoopForUI message_loop_; |
54 scoped_ptr<TestViewsDelegate> views_delegate_; | 55 scoped_ptr<TestViewsDelegate> views_delegate_; |
55 scoped_ptr<ViewsTestHelper> test_helper_; | 56 scoped_ptr<ViewsTestHelper> test_helper_; |
56 bool setup_called_; | 57 bool setup_called_; |
57 bool teardown_called_; | 58 bool teardown_called_; |
58 | 59 |
59 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
60 ui::ScopedOleInitializer ole_initializer_; | 61 ui::ScopedOleInitializer ole_initializer_; |
61 #endif | 62 #endif |
62 | 63 |
63 DISALLOW_COPY_AND_ASSIGN(ViewsTestBase); | 64 DISALLOW_COPY_AND_ASSIGN(ViewsTestBase); |
64 }; | 65 }; |
65 | 66 |
66 } // namespace views | 67 } // namespace views |
67 | 68 |
68 #endif // UI_VIEWS_TEST_VIEWS_TEST_BASE_H_ | 69 #endif // UI_VIEWS_TEST_VIEWS_TEST_BASE_H_ |
OLD | NEW |