OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #import "ui/views/cocoa/bridged_native_widget.h" | 5 #import "ui/views/cocoa/bridged_native_widget.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 class MockNativeWidgetMac : public NativeWidgetMac { | 44 class MockNativeWidgetMac : public NativeWidgetMac { |
45 public: | 45 public: |
46 MockNativeWidgetMac(Widget* delegate) : NativeWidgetMac(delegate) {} | 46 MockNativeWidgetMac(Widget* delegate) : NativeWidgetMac(delegate) {} |
47 | 47 |
48 // Expose a reference, so that it can be reset() independently. | 48 // Expose a reference, so that it can be reset() independently. |
49 scoped_ptr<BridgedNativeWidget>& bridge() { | 49 scoped_ptr<BridgedNativeWidget>& bridge() { |
50 return bridge_; | 50 return bridge_; |
51 } | 51 } |
52 | 52 |
53 // internal::NativeWidgetPrivate: | 53 // internal::NativeWidgetPrivate: |
54 virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE { | 54 virtual void InitNativeWidget(const Widget::InitParams& params) override { |
55 ownership_ = params.ownership; | 55 ownership_ = params.ownership; |
56 | 56 |
57 // Usually the bridge gets initialized here. It is skipped to run extra | 57 // Usually the bridge gets initialized here. It is skipped to run extra |
58 // checks in tests, and so that a second window isn't created. | 58 // checks in tests, and so that a second window isn't created. |
59 delegate()->OnNativeWidgetCreated(true); | 59 delegate()->OnNativeWidgetCreated(true); |
60 } | 60 } |
61 | 61 |
62 virtual void ReorderNativeViews() OVERRIDE { | 62 virtual void ReorderNativeViews() override { |
63 // Called via Widget::Init to set the content view. No-op in these tests. | 63 // Called via Widget::Init to set the content view. No-op in these tests. |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 DISALLOW_COPY_AND_ASSIGN(MockNativeWidgetMac); | 67 DISALLOW_COPY_AND_ASSIGN(MockNativeWidgetMac); |
68 }; | 68 }; |
69 | 69 |
70 // Helper test base to construct a BridgedNativeWidget with a valid parent. | 70 // Helper test base to construct a BridgedNativeWidget with a valid parent. |
71 class BridgedNativeWidgetTestBase : public ui::CocoaTest { | 71 class BridgedNativeWidgetTestBase : public ui::CocoaTest { |
72 public: | 72 public: |
73 BridgedNativeWidgetTestBase() | 73 BridgedNativeWidgetTestBase() |
74 : widget_(new Widget), | 74 : widget_(new Widget), |
75 native_widget_mac_(new MockNativeWidgetMac(widget_.get())) { | 75 native_widget_mac_(new MockNativeWidgetMac(widget_.get())) { |
76 } | 76 } |
77 | 77 |
78 scoped_ptr<BridgedNativeWidget>& bridge() { | 78 scoped_ptr<BridgedNativeWidget>& bridge() { |
79 return native_widget_mac_->bridge(); | 79 return native_widget_mac_->bridge(); |
80 } | 80 } |
81 | 81 |
82 // Overridden from testing::Test: | 82 // Overridden from testing::Test: |
83 virtual void SetUp() OVERRIDE { | 83 virtual void SetUp() override { |
84 ui::CocoaTest::SetUp(); | 84 ui::CocoaTest::SetUp(); |
85 | 85 |
86 Widget::InitParams params; | 86 Widget::InitParams params; |
87 params.native_widget = native_widget_mac_; | 87 params.native_widget = native_widget_mac_; |
88 // To control the lifetime without an actual window that must be closed, | 88 // To control the lifetime without an actual window that must be closed, |
89 // tests in this file need to use WIDGET_OWNS_NATIVE_WIDGET. | 89 // tests in this file need to use WIDGET_OWNS_NATIVE_WIDGET. |
90 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 90 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
91 native_widget_mac_->GetWidget()->Init(params); | 91 native_widget_mac_->GetWidget()->Init(params); |
92 } | 92 } |
93 | 93 |
94 protected: | 94 protected: |
95 scoped_ptr<Widget> widget_; | 95 scoped_ptr<Widget> widget_; |
96 MockNativeWidgetMac* native_widget_mac_; // Weak. Owned by |widget_|. | 96 MockNativeWidgetMac* native_widget_mac_; // Weak. Owned by |widget_|. |
97 }; | 97 }; |
98 | 98 |
99 class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase { | 99 class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase { |
100 public: | 100 public: |
101 BridgedNativeWidgetTest(); | 101 BridgedNativeWidgetTest(); |
102 virtual ~BridgedNativeWidgetTest(); | 102 virtual ~BridgedNativeWidgetTest(); |
103 | 103 |
104 // Install a textfield in the view hierarchy and make it the text input | 104 // Install a textfield in the view hierarchy and make it the text input |
105 // client. | 105 // client. |
106 void InstallTextField(const std::string& text); | 106 void InstallTextField(const std::string& text); |
107 | 107 |
108 // Returns the current text as std::string. | 108 // Returns the current text as std::string. |
109 std::string GetText(); | 109 std::string GetText(); |
110 | 110 |
111 // testing::Test: | 111 // testing::Test: |
112 virtual void SetUp() OVERRIDE; | 112 virtual void SetUp() override; |
113 virtual void TearDown() OVERRIDE; | 113 virtual void TearDown() override; |
114 | 114 |
115 protected: | 115 protected: |
116 // TODO(tapted): Make this a EventCountView from widget_unittest.cc. | 116 // TODO(tapted): Make this a EventCountView from widget_unittest.cc. |
117 scoped_ptr<views::View> view_; | 117 scoped_ptr<views::View> view_; |
118 scoped_ptr<BridgedNativeWidget> bridge_; | 118 scoped_ptr<BridgedNativeWidget> bridge_; |
119 BridgedContentView* ns_view_; // Weak. Owned by bridge_. | 119 BridgedContentView* ns_view_; // Weak. Owned by bridge_. |
120 | 120 |
121 private: | 121 private: |
122 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest); | 122 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest); |
123 }; | 123 }; |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 410 |
411 // Should succeed after moving left first. | 411 // Should succeed after moving left first. |
412 [ns_view_ doCommandBySelector:@selector(moveLeft:)]; | 412 [ns_view_ doCommandBySelector:@selector(moveLeft:)]; |
413 [ns_view_ doCommandBySelector:@selector(deleteForward:)]; | 413 [ns_view_ doCommandBySelector:@selector(deleteForward:)]; |
414 EXPECT_EQ("", GetText()); | 414 EXPECT_EQ("", GetText()); |
415 EXPECT_EQ_RANGE(NSMakeRange(0, 0), [ns_view_ selectedRange]); | 415 EXPECT_EQ_RANGE(NSMakeRange(0, 0), [ns_view_ selectedRange]); |
416 } | 416 } |
417 | 417 |
418 } // namespace test | 418 } // namespace test |
419 } // namespace views | 419 } // namespace views |
OLD | NEW |