blob: 1a6f5c9b017af9017f26ada258a477b59c16c97b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// 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.
#include "ui/views/test/views_test_base.h"
#include "base/run_loop.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/ime/input_method_initializer.h"
#if defined(USE_AURA)
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/aura_test_helper.h"
#include "ui/views/corewm/capture_controller.h"
#endif
namespace views {
ViewsTestBase::ViewsTestBase()
: setup_called_(false),
teardown_called_(false) {
}
ViewsTestBase::~ViewsTestBase() {
CHECK(setup_called_)
<< "You have overridden SetUp but never called super class's SetUp";
CHECK(teardown_called_)
<< "You have overrideen TearDown but never called super class's TearDown";
}
void ViewsTestBase::SetUp() {
testing::Test::SetUp();
setup_called_ = true;
if (!views_delegate_.get())
views_delegate_.reset(new TestViewsDelegate());
#if defined(USE_AURA)
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp();
#endif // USE_AURA
ui::InitializeInputMethodForTesting();
}
void ViewsTestBase::TearDown() {
ui::Clipboard::DestroyClipboardForCurrentThread();
// Flush the message loop because we have pending release tasks
// and these tasks if un-executed would upset Valgrind.
RunPendingMessages();
teardown_called_ = true;
views_delegate_.reset();
testing::Test::TearDown();
ui::ShutdownInputMethodForTesting();
#if defined(USE_AURA)
aura_test_helper_->TearDown();
CHECK(!corewm::ScopedCaptureClient::IsActive());
#endif // USE_AURA
}
void ViewsTestBase::RunPendingMessages() {
base::RunLoop run_loop;
#if defined(USE_AURA)
run_loop.set_dispatcher(aura::Env::GetInstance()->GetDispatcher());
#endif
run_loop.RunUntilIdle();
}
Widget::InitParams ViewsTestBase::CreateParams(
Widget::InitParams::Type type) {
Widget::InitParams params(type);
#if defined(USE_AURA)
params.context = aura_test_helper_->root_window();
#endif
return params;
}
gfx::NativeView ViewsTestBase::GetContext() {
#if defined(USE_AURA)
return aura_test_helper_->root_window();
#else
return NULL;
#endif
}
} // namespace views
|