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 virtual ~NativeViewHostTesting() { 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::CreateTopLevel() {
33 toplevel_.reset(new Widget);
34 Widget::InitParams toplevel_params =
35 CreateParams(Widget::InitParams::TYPE_WINDOW);
36 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
37 toplevel_->Init(toplevel_params);
40 void NativeViewHostTestBase::CreateTestingHost() {
41 host_.reset(new NativeViewHostTesting(this));
44 Widget* NativeViewHostTestBase::CreateChildForHost(
45 gfx::NativeView native_parent_view,
48 NativeViewHost* host) {
49 Widget* child = new Widget;
50 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL);
51 child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
52 child_params.parent = native_parent_view;
53 child->Init(child_params);
54 child->SetContentsView(contents_view);
56 // Owned by |parent_view|.
57 parent_view->AddChildView(host);
58 host->Attach(child->GetNativeView());
63 void NativeViewHostTestBase::DestroyTopLevel() {
67 void NativeViewHostTestBase::DestroyHost() {
71 NativeViewHost* NativeViewHostTestBase::ReleaseHost() {
72 return host_.release();
75 NativeViewHostWrapper* NativeViewHostTestBase::GetNativeWrapper() {
76 return host_->native_wrapper_.get();