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.
4
5#include "base/macros.h"
6#include "base/memory/scoped_ptr.h"
7#include "ui/views/test/views_test_base.h"
8
9namespace views {
10
11class NativeViewHost;
12class NativeViewHostWrapper;
13class Widget;
14
15namespace test {
16
17// Base class for NativeViewHost tests on different platforms.
18class NativeViewHostTestBase : public ViewsTestBase {
19 public:
20  NativeViewHostTestBase();
21  virtual ~NativeViewHostTestBase();
22
23  // Create the |toplevel_| widget.
24  void CreateTopLevel();
25
26  // Create a testing |host_| that tracks destructor calls.
27  void CreateTestingHost();
28
29  // The number of times a host created by CreateHost() has been destroyed.
30  int host_destroyed_count() { return host_destroyed_count_; }
31  void ResetHostDestroyedCount() { host_destroyed_count_ = 0; }
32
33  // Create a child widget whose native parent is |native_parent_view|, uses
34  // |contents_view|, and is attached to |host| which is added as a child to
35  // |parent_view|. This effectively borrows the native content view from a
36  // newly created child Widget, and attaches it to |host|.
37  Widget* CreateChildForHost(gfx::NativeView native_parent_view,
38                             View* parent_view,
39                             View* contents_view,
40                             NativeViewHost* host);
41
42  Widget* toplevel() { return toplevel_.get(); }
43  void DestroyTopLevel();
44
45  NativeViewHost* host() { return host_.get(); }
46  void DestroyHost();
47  NativeViewHost* ReleaseHost();
48
49  NativeViewHostWrapper* GetNativeWrapper();
50
51 private:
52  class NativeViewHostTesting;
53
54  scoped_ptr<Widget> toplevel_;
55  scoped_ptr<NativeViewHost> host_;
56  int host_destroyed_count_;
57
58  DISALLOW_COPY_AND_ASSIGN(NativeViewHostTestBase);
59};
60
61}  // namespace test
62}  // namespace views
63