OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/native/native_view_host_aura.h" | 5 #include "ui/views/controls/native/native_view_host_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/views/controls/native/native_view_host.h" | 10 #include "ui/views/controls/native/native_view_host.h" |
11 #include "ui/views/test/views_test_base.h" | 11 #include "ui/views/test/views_test_base.h" |
12 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
| 13 #include "ui/views/view_constants_aura.h" |
13 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
14 | 15 |
15 namespace views { | 16 namespace views { |
16 | 17 |
17 class NativeViewHostAuraTest : public ViewsTestBase { | 18 class NativeViewHostAuraTest : public ViewsTestBase { |
18 public: | 19 public: |
19 NativeViewHostAuraTest() { | 20 NativeViewHostAuraTest() { |
20 } | 21 } |
21 | 22 |
22 NativeViewHostAura* native_host() { | 23 NativeViewHostAura* native_host() { |
23 return static_cast<NativeViewHostAura*>(host_->native_wrapper_.get()); | 24 return static_cast<NativeViewHostAura*>(host_->native_wrapper_.get()); |
24 } | 25 } |
25 | 26 |
| 27 NativeViewHost* host() { |
| 28 return host_.get(); |
| 29 } |
| 30 |
26 Widget* child() { | 31 Widget* child() { |
27 return child_.get(); | 32 return child_.get(); |
28 } | 33 } |
29 | 34 |
30 void CreateHost() { | 35 void CreateHost() { |
31 // Create the top level widget. | 36 // Create the top level widget. |
32 toplevel_.reset(new Widget); | 37 toplevel_.reset(new Widget); |
33 Widget::InitParams toplevel_params = | 38 Widget::InitParams toplevel_params = |
34 CreateParams(Widget::InitParams::TYPE_WINDOW); | 39 CreateParams(Widget::InitParams::TYPE_WINDOW); |
35 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 40 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
(...skipping 30 matching lines...) Expand all Loading... |
66 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) { | 71 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) { |
67 CreateHost(); | 72 CreateHost(); |
68 aura::Window* child_win = child()->GetNativeView(); | 73 aura::Window* child_win = child()->GetNativeView(); |
69 NativeViewHostAura* aura_host = native_host(); | 74 NativeViewHostAura* aura_host = native_host(); |
70 | 75 |
71 EXPECT_TRUE(child_win->HasObserver(aura_host)); | 76 EXPECT_TRUE(child_win->HasObserver(aura_host)); |
72 DestroyHost(); | 77 DestroyHost(); |
73 EXPECT_FALSE(child_win->HasObserver(aura_host)); | 78 EXPECT_FALSE(child_win->HasObserver(aura_host)); |
74 } | 79 } |
75 | 80 |
| 81 // Tests that the kHostViewKey is correctly set and cleared. |
| 82 TEST_F(NativeViewHostAuraTest, HostViewPropertyKey) { |
| 83 // Create the NativeViewHost and attach a NativeView. |
| 84 CreateHost(); |
| 85 aura::Window* child_win = child()->GetNativeView(); |
| 86 EXPECT_EQ(host(), child_win->GetProperty(views::kHostViewKey)); |
| 87 |
| 88 host()->Detach(); |
| 89 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey)); |
| 90 |
| 91 host()->Attach(child_win); |
| 92 EXPECT_EQ(host(), child_win->GetProperty(views::kHostViewKey)); |
| 93 |
| 94 DestroyHost(); |
| 95 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey)); |
| 96 } |
| 97 |
76 } // namespace views | 98 } // namespace views |
OLD | NEW |