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 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #import "testing/gtest_mac.h" | 16 #import "testing/gtest_mac.h" |
17 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 17 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
18 #import "ui/views/cocoa/bridged_content_view.h" | 18 #import "ui/views/cocoa/bridged_content_view.h" |
19 #include "ui/views/controls/textfield/textfield.h" | 19 #include "ui/views/controls/textfield/textfield.h" |
20 #include "ui/views/ime/input_method.h" | 20 #include "ui/views/ime/input_method.h" |
21 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
22 #include "ui/views/widget/native_widget_mac.h" | 22 #include "ui/views/widget/native_widget_mac.h" |
| 23 #include "ui/views/widget/root_view.h" |
23 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
24 #include "ui/views/widget/widget_observer.h" | 25 #include "ui/views/widget/widget_observer.h" |
25 | 26 |
26 using base::ASCIIToUTF16; | 27 using base::ASCIIToUTF16; |
27 using base::SysNSStringToUTF8; | 28 using base::SysNSStringToUTF8; |
28 using base::SysNSStringToUTF16; | 29 using base::SysNSStringToUTF16; |
29 using base::SysUTF8ToNSString; | 30 using base::SysUTF8ToNSString; |
30 | 31 |
31 #define EXPECT_EQ_RANGE(a, b) \ | 32 #define EXPECT_EQ_RANGE(a, b) \ |
32 EXPECT_EQ(a.location, b.location); \ | 33 EXPECT_EQ(a.location, b.location); \ |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void InstallTextField(const std::string& text); | 217 void InstallTextField(const std::string& text); |
217 | 218 |
218 // Returns the current text as std::string. | 219 // Returns the current text as std::string. |
219 std::string GetText(); | 220 std::string GetText(); |
220 | 221 |
221 // testing::Test: | 222 // testing::Test: |
222 virtual void SetUp() override; | 223 virtual void SetUp() override; |
223 virtual void TearDown() override; | 224 virtual void TearDown() override; |
224 | 225 |
225 protected: | 226 protected: |
226 // TODO(tapted): Make this a EventCountView from widget_unittest.cc. | |
227 scoped_ptr<views::View> view_; | 227 scoped_ptr<views::View> view_; |
228 scoped_ptr<BridgedNativeWidget> bridge_; | 228 scoped_ptr<BridgedNativeWidget> bridge_; |
229 BridgedContentView* ns_view_; // Weak. Owned by bridge_. | 229 BridgedContentView* ns_view_; // Weak. Owned by bridge_. |
230 | 230 |
231 private: | 231 private: |
232 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest); | 232 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest); |
233 }; | 233 }; |
234 | 234 |
235 BridgedNativeWidgetTest::BridgedNativeWidgetTest() { | 235 BridgedNativeWidgetTest::BridgedNativeWidgetTest() { |
236 } | 236 } |
(...skipping 11 matching lines...) Expand all Loading... |
248 std::string BridgedNativeWidgetTest::GetText() { | 248 std::string BridgedNativeWidgetTest::GetText() { |
249 NSRange range = NSMakeRange(0, NSUIntegerMax); | 249 NSRange range = NSMakeRange(0, NSUIntegerMax); |
250 NSAttributedString* text = | 250 NSAttributedString* text = |
251 [ns_view_ attributedSubstringForProposedRange:range actualRange:NULL]; | 251 [ns_view_ attributedSubstringForProposedRange:range actualRange:NULL]; |
252 return SysNSStringToUTF8([text string]); | 252 return SysNSStringToUTF8([text string]); |
253 } | 253 } |
254 | 254 |
255 void BridgedNativeWidgetTest::SetUp() { | 255 void BridgedNativeWidgetTest::SetUp() { |
256 BridgedNativeWidgetTestBase::SetUp(); | 256 BridgedNativeWidgetTestBase::SetUp(); |
257 | 257 |
258 view_.reset(new views::View); | 258 view_.reset(new views::internal::RootView(widget_.get())); |
259 base::scoped_nsobject<NSWindow> window([test_window() retain]); | 259 base::scoped_nsobject<NSWindow> window([test_window() retain]); |
260 | 260 |
261 // BridgedNativeWidget expects to be initialized with a hidden (deferred) | 261 // BridgedNativeWidget expects to be initialized with a hidden (deferred) |
262 // window. | 262 // window. |
263 [window orderOut:nil]; | 263 [window orderOut:nil]; |
264 EXPECT_FALSE([window delegate]); | 264 EXPECT_FALSE([window delegate]); |
265 bridge()->Init(window, Widget::InitParams()); | 265 bridge()->Init(window, Widget::InitParams()); |
266 | 266 |
267 // The delegate should exist before setting the root view. | 267 // The delegate should exist before setting the root view. |
268 EXPECT_TRUE([window delegate]); | 268 EXPECT_TRUE([window delegate]); |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 [center postNotificationName:NSWindowDidExitFullScreenNotification | 683 [center postNotificationName:NSWindowDidExitFullScreenNotification |
684 object:window]; | 684 object:window]; |
685 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 685 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
686 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 686 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
687 | 687 |
688 widget_->CloseNow(); | 688 widget_->CloseNow(); |
689 } | 689 } |
690 | 690 |
691 } // namespace test | 691 } // namespace test |
692 } // namespace views | 692 } // namespace views |
OLD | NEW |