Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/test/base/view_event_test_base.cc

Issue 8937007: Initialize shell and browser thread for views event tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: consolidated ui_thread in bookmark test and vieweventtestbase Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/base/view_event_test_base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <ole2.h> 8 #include <ole2.h>
9 #endif 9 #endif
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "chrome/browser/automation/ui_controls.h" 16 #include "chrome/browser/automation/ui_controls.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/browser_thread.h"
18 #include "ui/gfx/compositor/test/compositor_test_support.h" 19 #include "ui/gfx/compositor/test/compositor_test_support.h"
19 #include "ui/views/view.h" 20 #include "ui/views/view.h"
20 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
21 22
22 #if defined(USE_AURA) 23 #if defined(USE_AURA)
23 #include "ui/aura/root_window.h" 24 #include "ui/aura/root_window.h"
25 #include "ui/aura_shell/shell.h"
24 #endif 26 #endif
25 27
26 namespace { 28 namespace {
27 29
28 // View subclass that allows you to specify the preferred size. 30 // View subclass that allows you to specify the preferred size.
29 class TestView : public views::View { 31 class TestView : public views::View {
30 public: 32 public:
31 TestView() {} 33 TestView() {}
32 34
33 void SetPreferredSize(const gfx::Size& size) { 35 void SetPreferredSize(const gfx::Size& size) {
(...skipping 19 matching lines...) Expand all
53 }; 55 };
54 56
55 // Delay in background thread before posting mouse move. 57 // Delay in background thread before posting mouse move.
56 const int kMouseMoveDelayMS = 200; 58 const int kMouseMoveDelayMS = 200;
57 59
58 } // namespace 60 } // namespace
59 61
60 ViewEventTestBase::ViewEventTestBase() 62 ViewEventTestBase::ViewEventTestBase()
61 : window_(NULL), 63 : window_(NULL),
62 content_view_(NULL), 64 content_view_(NULL),
65 ui_thread_(content::BrowserThread::UI, &message_loop_),
63 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 66 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
64 } 67 }
65 68
66 void ViewEventTestBase::Done() { 69 void ViewEventTestBase::Done() {
67 // Cancel the pending time-out. 70 // Cancel the pending time-out.
68 method_factory_.RevokeAll(); 71 method_factory_.RevokeAll();
69 72
70 MessageLoop::current()->Quit(); 73 MessageLoop::current()->Quit();
71 74
72 #if defined(OS_WIN) 75 #if defined(OS_WIN)
73 // We need to post a message to tickle the Dispatcher getting called and 76 // We need to post a message to tickle the Dispatcher getting called and
74 // exiting out of the nested loop. Without this the quit never runs. 77 // exiting out of the nested loop. Without this the quit never runs.
75 PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0); 78 PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0);
76 #endif 79 #endif
77 80
78 // If we're in a nested message loop, as is the case with menus, we 81 // If we're in a nested message loop, as is the case with menus, we
79 // need to quit twice. The second quit does that for us. Finish all 82 // need to quit twice. The second quit does that for us. Finish all
80 // pending UI events before posting closure because events it may be 83 // pending UI events before posting closure because events it may be
81 // executed before UI events are executed. 84 // executed before UI events are executed.
82 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure()); 85 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure());
83 } 86 }
84 87
85 void ViewEventTestBase::SetUp() { 88 void ViewEventTestBase::SetUp() {
86 #if defined(OS_WIN) 89 #if defined(OS_WIN)
87 OleInitialize(NULL); 90 OleInitialize(NULL);
88 #endif 91 #endif
89 ui::CompositorTestSupport::Initialize(); 92 ui::CompositorTestSupport::Initialize();
90 #if defined(USE_AURA) 93 #if defined(USE_AURA)
91 aura::RootWindow::GetInstance(); 94 aura::RootWindow::GetInstance();
95 aura_shell::Shell::CreateInstance(NULL);
92 #endif 96 #endif
93 window_ = views::Widget::CreateWindow(this); 97 window_ = views::Widget::CreateWindow(this);
94 } 98 }
95 99
96 void ViewEventTestBase::TearDown() { 100 void ViewEventTestBase::TearDown() {
97 if (window_) { 101 if (window_) {
98 #if defined(OS_WIN) 102 #if defined(OS_WIN)
99 DestroyWindow(window_->GetNativeWindow()); 103 DestroyWindow(window_->GetNativeWindow());
100 #else 104 #else
101 window_->Close(); 105 window_->Close();
102 ui_test_utils::RunAllPendingInMessageLoop(); 106 ui_test_utils::RunAllPendingInMessageLoop();
103 #endif 107 #endif
104 window_ = NULL; 108 window_ = NULL;
105 } 109 }
106 #if defined(USE_AURA) 110 #if defined(USE_AURA)
111 aura_shell::Shell::DeleteInstance();
107 aura::RootWindow::DeleteInstance(); 112 aura::RootWindow::DeleteInstance();
108 #endif 113 #endif
109 ui::CompositorTestSupport::Terminate(); 114 ui::CompositorTestSupport::Terminate();
110 #if defined(OS_WIN) 115 #if defined(OS_WIN)
111 OleUninitialize(); 116 OleUninitialize();
112 #endif 117 #endif
113 } 118 }
114 119
115 bool ViewEventTestBase::CanResize() const { 120 bool ViewEventTestBase::CanResize() const {
116 return true; 121 return true;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 dnd_thread_.reset(NULL); 183 dnd_thread_.reset(NULL);
179 } 184 }
180 185
181 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { 186 void ViewEventTestBase::RunTestMethod(const base::Closure& task) {
182 StopBackgroundThread(); 187 StopBackgroundThread();
183 188
184 task.Run(); 189 task.Run();
185 if (HasFatalFailure()) 190 if (HasFatalFailure())
186 Done(); 191 Done();
187 } 192 }
OLDNEW
« no previous file with comments | « chrome/test/base/view_event_test_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698