1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/views/controls/native/native_view_host_test_base.h"
7 #include "ui/views/controls/native/native_view_host.h"
8 #include "ui/views/widget/widget.h"
13 // Testing wrapper of the NativeViewHost.
14 class NativeViewHostTestBase::NativeViewHostTesting
: public NativeViewHost
{
16 explicit NativeViewHostTesting(NativeViewHostTestBase
* owner
)
18 ~NativeViewHostTesting() override
{ owner_
->host_destroyed_count_
++; }
21 NativeViewHostTestBase
* owner_
;
23 DISALLOW_COPY_AND_ASSIGN(NativeViewHostTesting
);
26 NativeViewHostTestBase::NativeViewHostTestBase() : host_destroyed_count_(0) {
29 NativeViewHostTestBase::~NativeViewHostTestBase() {
32 void NativeViewHostTestBase::TearDown() {
34 ViewsTestBase::TearDown();
37 void NativeViewHostTestBase::CreateTopLevel() {
38 toplevel_
.reset(new Widget
);
39 Widget::InitParams toplevel_params
=
40 CreateParams(Widget::InitParams::TYPE_WINDOW
);
41 toplevel_params
.ownership
= Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
42 toplevel_
->Init(toplevel_params
);
45 void NativeViewHostTestBase::CreateTestingHost() {
46 host_
.reset(new NativeViewHostTesting(this));
49 Widget
* NativeViewHostTestBase::CreateChildForHost(
50 gfx::NativeView native_parent_view
,
53 NativeViewHost
* host
) {
54 Widget
* child
= new Widget
;
55 Widget::InitParams
child_params(Widget::InitParams::TYPE_CONTROL
);
56 child_params
.ownership
= Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
57 child_params
.parent
= native_parent_view
;
58 child
->Init(child_params
);
59 child
->SetContentsView(contents_view
);
61 // Owned by |parent_view|.
62 parent_view
->AddChildView(host
);
63 host
->Attach(child
->GetNativeView());
68 void NativeViewHostTestBase::DestroyTopLevel() {
72 void NativeViewHostTestBase::DestroyHost() {
76 NativeViewHost
* NativeViewHostTestBase::ReleaseHost() {
77 return host_
.release();
80 NativeViewHostWrapper
* NativeViewHostTestBase::GetNativeWrapper() {
81 return host_
->native_wrapper_
.get();