Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: ui/views/cocoa/bridged_native_widget_unittest.mm

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
10
9 #import "base/mac/foundation_util.h" 11 #import "base/mac/foundation_util.h"
10 #import "base/mac/mac_util.h" 12 #import "base/mac/mac_util.h"
11 #import "base/mac/sdk_forward_declarations.h" 13 #import "base/mac/sdk_forward_declarations.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #import "testing/gtest_mac.h" 18 #import "testing/gtest_mac.h"
18 #import "ui/base/cocoa/window_size_constants.h" 19 #import "ui/base/cocoa/window_size_constants.h"
19 #include "ui/base/ime/input_method.h" 20 #include "ui/base/ime/input_method.h"
21 #import "ui/gfx/mac/coordinate_conversion.h"
20 #import "ui/gfx/test/ui_cocoa_test_helper.h" 22 #import "ui/gfx/test/ui_cocoa_test_helper.h"
21 #import "ui/gfx/mac/coordinate_conversion.h"
22 #import "ui/views/cocoa/bridged_content_view.h" 23 #import "ui/views/cocoa/bridged_content_view.h"
23 #import "ui/views/cocoa/native_widget_mac_nswindow.h" 24 #import "ui/views/cocoa/native_widget_mac_nswindow.h"
24 #import "ui/views/cocoa/views_nswindow_delegate.h" 25 #import "ui/views/cocoa/views_nswindow_delegate.h"
25 #include "ui/views/controls/textfield/textfield.h" 26 #include "ui/views/controls/textfield/textfield.h"
26 #include "ui/views/view.h" 27 #include "ui/views/view.h"
27 #include "ui/views/widget/native_widget_mac.h" 28 #include "ui/views/widget/native_widget_mac.h"
28 #include "ui/views/widget/root_view.h" 29 #include "ui/views/widget/root_view.h"
29 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
30 #include "ui/views/widget/widget_observer.h" 31 #include "ui/views/widget/widget_observer.h"
31 32
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 119
119 namespace views { 120 namespace views {
120 namespace test { 121 namespace test {
121 122
122 // Provides the |parent| argument to construct a BridgedNativeWidget. 123 // Provides the |parent| argument to construct a BridgedNativeWidget.
123 class MockNativeWidgetMac : public NativeWidgetMac { 124 class MockNativeWidgetMac : public NativeWidgetMac {
124 public: 125 public:
125 MockNativeWidgetMac(Widget* delegate) : NativeWidgetMac(delegate) {} 126 MockNativeWidgetMac(Widget* delegate) : NativeWidgetMac(delegate) {}
126 127
127 // Expose a reference, so that it can be reset() independently. 128 // Expose a reference, so that it can be reset() independently.
128 scoped_ptr<BridgedNativeWidget>& bridge() { 129 std::unique_ptr<BridgedNativeWidget>& bridge() { return bridge_; }
129 return bridge_;
130 }
131 130
132 // internal::NativeWidgetPrivate: 131 // internal::NativeWidgetPrivate:
133 void InitNativeWidget(const Widget::InitParams& params) override { 132 void InitNativeWidget(const Widget::InitParams& params) override {
134 ownership_ = params.ownership; 133 ownership_ = params.ownership;
135 134
136 // Usually the bridge gets initialized here. It is skipped to run extra 135 // Usually the bridge gets initialized here. It is skipped to run extra
137 // checks in tests, and so that a second window isn't created. 136 // checks in tests, and so that a second window isn't created.
138 delegate()->OnNativeWidgetCreated(true); 137 delegate()->OnNativeWidgetCreated(true);
139 138
140 // To allow events to dispatch to a view, it needs a way to get focus. 139 // To allow events to dispatch to a view, it needs a way to get focus.
141 bridge_->SetFocusManager(GetWidget()->GetFocusManager()); 140 bridge_->SetFocusManager(GetWidget()->GetFocusManager());
142 } 141 }
143 142
144 void ReorderNativeViews() override { 143 void ReorderNativeViews() override {
145 // Called via Widget::Init to set the content view. No-op in these tests. 144 // Called via Widget::Init to set the content view. No-op in these tests.
146 } 145 }
147 146
148 private: 147 private:
149 DISALLOW_COPY_AND_ASSIGN(MockNativeWidgetMac); 148 DISALLOW_COPY_AND_ASSIGN(MockNativeWidgetMac);
150 }; 149 };
151 150
152 // Helper test base to construct a BridgedNativeWidget with a valid parent. 151 // Helper test base to construct a BridgedNativeWidget with a valid parent.
153 class BridgedNativeWidgetTestBase : public ui::CocoaTest { 152 class BridgedNativeWidgetTestBase : public ui::CocoaTest {
154 public: 153 public:
155 BridgedNativeWidgetTestBase() 154 BridgedNativeWidgetTestBase()
156 : widget_(new Widget), 155 : widget_(new Widget),
157 native_widget_mac_(new MockNativeWidgetMac(widget_.get())) { 156 native_widget_mac_(new MockNativeWidgetMac(widget_.get())) {
158 } 157 }
159 158
160 scoped_ptr<BridgedNativeWidget>& bridge() { 159 std::unique_ptr<BridgedNativeWidget>& bridge() {
161 return native_widget_mac_->bridge(); 160 return native_widget_mac_->bridge();
162 } 161 }
163 162
164 // Overridden from testing::Test: 163 // Overridden from testing::Test:
165 void SetUp() override { 164 void SetUp() override {
166 ui::CocoaTest::SetUp(); 165 ui::CocoaTest::SetUp();
167 166
168 init_params_.native_widget = native_widget_mac_; 167 init_params_.native_widget = native_widget_mac_;
169 168
170 // Use a frameless window, otherwise Widget will try to center the window 169 // Use a frameless window, otherwise Widget will try to center the window
171 // before the tests covering the Init() flow are ready to do that. 170 // before the tests covering the Init() flow are ready to do that.
172 init_params_.type = Widget::InitParams::TYPE_WINDOW_FRAMELESS; 171 init_params_.type = Widget::InitParams::TYPE_WINDOW_FRAMELESS;
173 172
174 // To control the lifetime without an actual window that must be closed, 173 // To control the lifetime without an actual window that must be closed,
175 // tests in this file need to use WIDGET_OWNS_NATIVE_WIDGET. 174 // tests in this file need to use WIDGET_OWNS_NATIVE_WIDGET.
176 init_params_.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 175 init_params_.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
177 176
178 // Opacity defaults to "infer" which is usually updated by ViewsDelegate. 177 // Opacity defaults to "infer" which is usually updated by ViewsDelegate.
179 init_params_.opacity = Widget::InitParams::OPAQUE_WINDOW; 178 init_params_.opacity = Widget::InitParams::OPAQUE_WINDOW;
180 179
181 init_params_.bounds = gfx::Rect(100, 100, 100, 100); 180 init_params_.bounds = gfx::Rect(100, 100, 100, 100);
182 181
183 native_widget_mac_->GetWidget()->Init(init_params_); 182 native_widget_mac_->GetWidget()->Init(init_params_);
184 } 183 }
185 184
186 protected: 185 protected:
187 scoped_ptr<Widget> widget_; 186 std::unique_ptr<Widget> widget_;
188 MockNativeWidgetMac* native_widget_mac_; // Weak. Owned by |widget_|. 187 MockNativeWidgetMac* native_widget_mac_; // Weak. Owned by |widget_|.
189 188
190 // Make the InitParams available to tests to cover initialization codepaths. 189 // Make the InitParams available to tests to cover initialization codepaths.
191 Widget::InitParams init_params_; 190 Widget::InitParams init_params_;
192 }; 191 };
193 192
194 class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase { 193 class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase {
195 public: 194 public:
196 BridgedNativeWidgetTest(); 195 BridgedNativeWidgetTest();
197 ~BridgedNativeWidgetTest() override; 196 ~BridgedNativeWidgetTest() override;
198 197
199 // Install a textfield with input type |text_input_type| in the view hierarchy 198 // Install a textfield with input type |text_input_type| in the view hierarchy
200 // and make it the text input client. 199 // and make it the text input client.
201 void InstallTextField(const std::string& text, 200 void InstallTextField(const std::string& text,
202 ui::TextInputType text_input_type); 201 ui::TextInputType text_input_type);
203 202
204 // Install a textfield with input type ui::TEXT_INPUT_TYPE_TEXT in the view 203 // Install a textfield with input type ui::TEXT_INPUT_TYPE_TEXT in the view
205 // hierarchy and make it the text input client. 204 // hierarchy and make it the text input client.
206 void InstallTextField(const std::string& text); 205 void InstallTextField(const std::string& text);
207 206
208 // Returns the current text as std::string. 207 // Returns the current text as std::string.
209 std::string GetText(); 208 std::string GetText();
210 209
211 // testing::Test: 210 // testing::Test:
212 void SetUp() override; 211 void SetUp() override;
213 void TearDown() override; 212 void TearDown() override;
214 213
215 protected: 214 protected:
216 scoped_ptr<views::View> view_; 215 std::unique_ptr<views::View> view_;
217 BridgedContentView* ns_view_; // Weak. Owned by bridge(). 216 BridgedContentView* ns_view_; // Weak. Owned by bridge().
218 base::MessageLoopForUI message_loop_; 217 base::MessageLoopForUI message_loop_;
219 218
220 private: 219 private:
221 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest); 220 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest);
222 }; 221 };
223 222
224 BridgedNativeWidgetTest::BridgedNativeWidgetTest() { 223 BridgedNativeWidgetTest::BridgedNativeWidgetTest() {
225 } 224 }
226 225
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 [center postNotificationName:NSWindowDidExitFullScreenNotification 743 [center postNotificationName:NSWindowDidExitFullScreenNotification
745 object:window]; 744 object:window];
746 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. 745 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change.
747 EXPECT_FALSE(bridge()->target_fullscreen_state()); 746 EXPECT_FALSE(bridge()->target_fullscreen_state());
748 747
749 widget_->CloseNow(); 748 widget_->CloseNow();
750 } 749 }
751 750
752 } // namespace test 751 } // namespace test
753 } // namespace views 752 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_native_widget_interactive_uitest.mm ('k') | ui/views/cocoa/cocoa_mouse_capture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698