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 #include "chrome/test/base/view_event_test_base.h" | 5 #include "chrome/test/base/view_event_test_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "chrome/test/base/chrome_unit_test_suite.h" | 9 #include "chrome/test/base/chrome_unit_test_suite.h" |
10 #include "chrome/test/base/interactive_test_utils.h" | 10 #include "chrome/test/base/interactive_test_utils.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 void ViewEventTestBase::Done() { | 61 void ViewEventTestBase::Done() { |
62 run_loop_.Quit(); | 62 run_loop_.Quit(); |
63 } | 63 } |
64 | 64 |
65 void ViewEventTestBase::SetUpTestCase() { | 65 void ViewEventTestBase::SetUpTestCase() { |
66 ChromeUnitTestSuite::InitializeProviders(); | 66 ChromeUnitTestSuite::InitializeProviders(); |
67 ChromeUnitTestSuite::InitializeResourceBundle(); | 67 ChromeUnitTestSuite::InitializeResourceBundle(); |
68 } | 68 } |
69 | 69 |
70 void ViewEventTestBase::SetUp() { | 70 void ViewEventTestBase::SetUp() { |
71 views::ViewsDelegate::views_delegate = &views_delegate_; | |
72 ui::InitializeInputMethodForTesting(); | 71 ui::InitializeInputMethodForTesting(); |
73 | 72 |
74 // The ContextFactory must exist before any Compositors are created. | 73 // The ContextFactory must exist before any Compositors are created. |
75 bool enable_pixel_output = false; | 74 bool enable_pixel_output = false; |
76 ui::ContextFactory* context_factory = | 75 ui::ContextFactory* context_factory = |
77 ui::InitializeContextFactoryForTests(enable_pixel_output); | 76 ui::InitializeContextFactoryForTests(enable_pixel_output); |
78 views_delegate_.set_context_factory(context_factory); | 77 views_delegate_.set_context_factory(context_factory); |
79 views_delegate_.set_use_desktop_native_widgets(true); | 78 views_delegate_.set_use_desktop_native_widgets(true); |
80 | 79 |
81 platform_part_.reset(ViewEventTestPlatformPart::Create(context_factory)); | 80 platform_part_.reset(ViewEventTestPlatformPart::Create(context_factory)); |
82 gfx::NativeWindow context = platform_part_->GetContext(); | 81 gfx::NativeWindow context = platform_part_->GetContext(); |
83 window_ = views::Widget::CreateWindowWithContext(this, context); | 82 window_ = views::Widget::CreateWindowWithContext(this, context); |
84 window_->Show(); | 83 window_->Show(); |
85 } | 84 } |
86 | 85 |
87 void ViewEventTestBase::TearDown() { | 86 void ViewEventTestBase::TearDown() { |
88 if (window_) { | 87 if (window_) { |
89 window_->Close(); | 88 window_->Close(); |
90 content::RunAllPendingInMessageLoop(); | 89 content::RunAllPendingInMessageLoop(); |
91 window_ = NULL; | 90 window_ = NULL; |
92 } | 91 } |
93 | 92 |
94 ui::Clipboard::DestroyClipboardForCurrentThread(); | 93 ui::Clipboard::DestroyClipboardForCurrentThread(); |
95 platform_part_.reset(); | 94 platform_part_.reset(); |
96 | 95 |
97 ui::TerminateContextFactoryForTests(); | 96 ui::TerminateContextFactoryForTests(); |
98 | 97 |
99 ui::ShutdownInputMethodForTesting(); | 98 ui::ShutdownInputMethodForTesting(); |
100 views::ViewsDelegate::views_delegate = NULL; | |
101 } | 99 } |
102 | 100 |
103 bool ViewEventTestBase::CanResize() const { | 101 bool ViewEventTestBase::CanResize() const { |
104 return true; | 102 return true; |
105 } | 103 } |
106 | 104 |
107 views::View* ViewEventTestBase::GetContentsView() { | 105 views::View* ViewEventTestBase::GetContentsView() { |
108 if (!content_view_) { | 106 if (!content_view_) { |
109 // Wrap the real view (as returned by CreateContentsView) in a View so | 107 // Wrap the real view (as returned by CreateContentsView) in a View so |
110 // that we can customize the preferred size. | 108 // that we can customize the preferred size. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 dnd_thread_.reset(NULL); | 160 dnd_thread_.reset(NULL); |
163 } | 161 } |
164 | 162 |
165 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 163 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
166 StopBackgroundThread(); | 164 StopBackgroundThread(); |
167 | 165 |
168 task.Run(); | 166 task.Run(); |
169 if (HasFatalFailure()) | 167 if (HasFatalFailure()) |
170 Done(); | 168 Done(); |
171 } | 169 } |
OLD | NEW |