GoogleURLTrackerInfoBarDelegate: Initialize uninitialized member in constructor.
[chromium-blink-merge.git] / ui / views / controls / native / native_view_host_aura_unittest.cc
blobf6dc561f2f04fdaffb166e61141631d07b5dafce
1 // Copyright (c) 2013 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_aura.h"
7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/aura/window.h"
10 #include "ui/base/cursor/cursor.h"
11 #include "ui/views/controls/native/native_view_host.h"
12 #include "ui/views/test/views_test_base.h"
13 #include "ui/views/view.h"
14 #include "ui/views/view_constants_aura.h"
15 #include "ui/views/widget/widget.h"
17 namespace views {
19 class NativeViewHostAuraTest : public ViewsTestBase {
20 public:
21 NativeViewHostAuraTest() {
24 NativeViewHostAura* native_host() {
25 return static_cast<NativeViewHostAura*>(host_->native_wrapper_.get());
28 Widget* toplevel() {
29 return toplevel_.get();
32 NativeViewHost* host() {
33 return host_.get();
36 Widget* child() {
37 return child_.get();
40 void CreateHost() {
41 // Create the top level widget.
42 toplevel_.reset(new Widget);
43 Widget::InitParams toplevel_params =
44 CreateParams(Widget::InitParams::TYPE_WINDOW);
45 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
46 toplevel_->Init(toplevel_params);
48 // And the child widget.
49 View* test_view = new View;
50 child_.reset(new Widget);
51 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL);
52 child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
53 child_params.parent = toplevel_->GetNativeView();
54 child_->Init(child_params);
55 child_->SetContentsView(test_view);
57 // Owned by |toplevel|.
58 host_.reset(new NativeViewHost);
59 toplevel_->GetRootView()->AddChildView(host_.get());
60 host_->Attach(child_->GetNativeView());
63 void DestroyHost() {
64 host_.reset();
67 private:
68 scoped_ptr<Widget> toplevel_;
69 scoped_ptr<NativeViewHost> host_;
70 scoped_ptr<Widget> child_;
72 DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest);
75 // Verifies NativeViewHostAura stops observing native view on destruction.
76 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) {
77 CreateHost();
78 aura::Window* child_win = child()->GetNativeView();
79 NativeViewHostAura* aura_host = native_host();
81 EXPECT_TRUE(child_win->HasObserver(aura_host));
82 DestroyHost();
83 EXPECT_FALSE(child_win->HasObserver(aura_host));
86 // Tests that the kHostViewKey is correctly set and cleared.
87 TEST_F(NativeViewHostAuraTest, HostViewPropertyKey) {
88 // Create the NativeViewHost and attach a NativeView.
89 CreateHost();
90 aura::Window* child_win = child()->GetNativeView();
91 EXPECT_EQ(host(), child_win->GetProperty(views::kHostViewKey));
93 host()->Detach();
94 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey));
96 host()->Attach(child_win);
97 EXPECT_EQ(host(), child_win->GetProperty(views::kHostViewKey));
99 DestroyHost();
100 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey));
103 // Tests that the NativeViewHost reports the cursor set on its native view.
104 TEST_F(NativeViewHostAuraTest, CursorForNativeView) {
105 CreateHost();
107 toplevel()->SetCursor(ui::kCursorHand);
108 child()->SetCursor(ui::kCursorWait);
109 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0),
110 gfx::Point(0, 0), 0, 0);
112 EXPECT_EQ(ui::kCursorWait, host()->GetCursor(move_event).native_type());
114 DestroyHost();
117 } // namespace views