MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / ui / views / controls / native / native_view_host_test_base.cc
blobf8f957c6cf825afedcde33d883ec63ccd79f3e12
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"
10 namespace views {
11 namespace test {
13 // Testing wrapper of the NativeViewHost.
14 class NativeViewHostTestBase::NativeViewHostTesting : public NativeViewHost {
15 public:
16 explicit NativeViewHostTesting(NativeViewHostTestBase* owner)
17 : owner_(owner) {}
18 virtual ~NativeViewHostTesting() { owner_->host_destroyed_count_++; }
20 private:
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,
46 View* parent_view,
47 View* contents_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());
60 return child;
63 void NativeViewHostTestBase::DestroyTopLevel() {
64 toplevel_.reset();
67 void NativeViewHostTestBase::DestroyHost() {
68 host_.reset();
71 NativeViewHost* NativeViewHostTestBase::ReleaseHost() {
72 return host_.release();
75 NativeViewHostWrapper* NativeViewHostTestBase::GetNativeWrapper() {
76 return host_->native_wrapper_.get();
79 } // namespace test
80 } // namespace views