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/widget/native_widget_mac.h" | 5 #import "ui/views/widget/native_widget_mac.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/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #import "base/mac/scoped_objc_class_swizzler.h" | 11 #import "base/mac/scoped_objc_class_swizzler.h" |
12 #include "base/macros.h" | 12 #include "base/macros.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 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
17 #import "testing/gtest_mac.h" | 17 #import "testing/gtest_mac.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
20 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" | 20 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" |
21 #import "ui/base/cocoa/window_size_constants.h" | 21 #import "ui/base/cocoa/window_size_constants.h" |
22 #import "ui/base/test/scoped_fake_full_keyboard_access.h" | |
22 #import "ui/events/test/cocoa_test_event_utils.h" | 23 #import "ui/events/test/cocoa_test_event_utils.h" |
23 #include "ui/events/test/event_generator.h" | 24 #include "ui/events/test/event_generator.h" |
24 #import "ui/gfx/mac/coordinate_conversion.h" | 25 #import "ui/gfx/mac/coordinate_conversion.h" |
25 #include "ui/views/bubble/bubble_dialog_delegate.h" | 26 #include "ui/views/bubble/bubble_dialog_delegate.h" |
27 #import "ui/views/cocoa/bridged_content_view.h" | |
26 #import "ui/views/cocoa/bridged_native_widget.h" | 28 #import "ui/views/cocoa/bridged_native_widget.h" |
27 #import "ui/views/cocoa/native_widget_mac_nswindow.h" | 29 #import "ui/views/cocoa/native_widget_mac_nswindow.h" |
28 #include "ui/views/controls/button/label_button.h" | 30 #include "ui/views/controls/button/label_button.h" |
29 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
30 #include "ui/views/controls/native/native_view_host.h" | 32 #include "ui/views/controls/native/native_view_host.h" |
31 #include "ui/views/native_cursor.h" | 33 #include "ui/views/native_cursor.h" |
32 #include "ui/views/test/native_widget_factory.h" | 34 #include "ui/views/test/native_widget_factory.h" |
33 #include "ui/views/test/test_widget_observer.h" | 35 #include "ui/views/test/test_widget_observer.h" |
34 #include "ui/views/test/widget_test.h" | 36 #include "ui/views/test/widget_test.h" |
35 #include "ui/views/widget/native_widget_mac.h" | 37 #include "ui/views/widget/native_widget_mac.h" |
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1366 | 1368 |
1367 [widget->GetNativeWindow() makeFirstResponder:child_view]; | 1369 [widget->GetNativeWindow() makeFirstResponder:child_view]; |
1368 EXPECT_FALSE(manager->GetFocusedView()); | 1370 EXPECT_FALSE(manager->GetFocusedView()); |
1369 | 1371 |
1370 [widget->GetNativeWindow() makeFirstResponder:widget->GetNativeView()]; | 1372 [widget->GetNativeWindow() makeFirstResponder:widget->GetNativeView()]; |
1371 EXPECT_EQ(manager->GetFocusedView(), widget->GetRootView()); | 1373 EXPECT_EQ(manager->GetFocusedView(), widget->GetRootView()); |
1372 | 1374 |
1373 widget->CloseNow(); | 1375 widget->CloseNow(); |
1374 } | 1376 } |
1375 | 1377 |
1378 // Test class for Full Keyboard Access related tests. | |
1379 class NativeWidgetMacFullKeyboardAccessTest : public NativeWidgetMacTest { | |
1380 public: | |
1381 NativeWidgetMacFullKeyboardAccessTest() {} | |
1382 | |
1383 protected: | |
1384 // testing::Test: | |
1385 void SetUp() override { | |
1386 NativeWidgetMacTest::SetUp(); | |
1387 | |
1388 widget_ = CreateTopLevelPlatformWidget(); | |
1389 bridge_ = | |
1390 NativeWidgetMac::GetBridgeForNativeWindow(widget_->GetNativeWindow()); | |
1391 fake_full_keyboard_access_ = | |
1392 ui::test::ScopedFakeFullKeyboardAccess::GetInstance(); | |
1393 DCHECK(fake_full_keyboard_access_); | |
1394 widget_->Show(); | |
1395 } | |
1396 | |
1397 void TearDown() override { | |
1398 widget_->CloseNow(); | |
1399 NativeWidgetMacTest::TearDown(); | |
1400 } | |
1401 | |
1402 Widget* widget_ = nullptr; | |
1403 BridgedNativeWidget* bridge_ = nullptr; | |
1404 ui::test::ScopedFakeFullKeyboardAccess* fake_full_keyboard_access_ = nullptr; | |
1405 }; | |
1406 | |
1407 // Test that updateFullKeyboardAccess method on BridgedContentView correctly | |
1408 // sets the keyboard accessibility mode on the associated focus manager. | |
1409 TEST_F(NativeWidgetMacFullKeyboardAccessTest, FullKeyboardToggle) { | |
1410 EXPECT_TRUE(widget_->GetFocusManager()->keyboard_accessible()); | |
1411 fake_full_keyboard_access_->SetFullKeyboardAccessState(false); | |
1412 [bridge_->ns_view() updateFullKeyboardAccess]; | |
1413 EXPECT_FALSE(widget_->GetFocusManager()->keyboard_accessible()); | |
1414 fake_full_keyboard_access_->SetFullKeyboardAccessState(true); | |
1415 [bridge_->ns_view() updateFullKeyboardAccess]; | |
1416 EXPECT_TRUE(widget_->GetFocusManager()->keyboard_accessible()); | |
1417 } | |
1418 | |
1419 // Test that a widget's associated focus manager is initialized with the correct | |
tapted
2016/05/03 08:08:26
nit: widget -> Widget, focus manager -> FocusManag
karandeepb
2016/05/04 01:56:38
Done.
| |
1420 // keyboard accessibility value. | |
1421 TEST_F(NativeWidgetMacFullKeyboardAccessTest, Initialization) { | |
1422 EXPECT_TRUE(widget_->GetFocusManager()->keyboard_accessible()); | |
1423 | |
1424 fake_full_keyboard_access_->SetFullKeyboardAccessState(false); | |
1425 Widget* widget2 = CreateTopLevelPlatformWidget(); | |
1426 EXPECT_FALSE(widget2->GetFocusManager()->keyboard_accessible()); | |
1427 widget2->CloseNow(); | |
1428 } | |
1429 | |
1430 // Test that the correct keyboard accessibility mode is set when the window | |
1431 // becomes active. | |
1432 TEST_F(NativeWidgetMacFullKeyboardAccessTest, Activation) { | |
1433 EXPECT_TRUE(widget_->GetFocusManager()->keyboard_accessible()); | |
1434 | |
1435 widget_->Hide(); | |
1436 fake_full_keyboard_access_->SetFullKeyboardAccessState(false); | |
1437 // [bridge_->ns_view() updateFullKeyboardAccess] is not explicitly called | |
1438 // since we may not receive full keyboard access toggle notifications when our | |
1439 // application is inactive. | |
1440 | |
1441 widget_->Show(); | |
1442 EXPECT_FALSE(widget_->GetFocusManager()->keyboard_accessible()); | |
1443 | |
1444 widget_->Hide(); | |
1445 fake_full_keyboard_access_->SetFullKeyboardAccessState(true); | |
1446 | |
1447 widget_->Show(); | |
1448 EXPECT_TRUE(widget_->GetFocusManager()->keyboard_accessible()); | |
1449 } | |
1450 | |
1376 class NativeWidgetMacViewsOrderTest : public WidgetTest { | 1451 class NativeWidgetMacViewsOrderTest : public WidgetTest { |
1377 public: | 1452 public: |
1378 NativeWidgetMacViewsOrderTest() {} | 1453 NativeWidgetMacViewsOrderTest() {} |
1379 | 1454 |
1380 protected: | 1455 protected: |
1381 // testing::Test: | 1456 // testing::Test: |
1382 void SetUp() override { | 1457 void SetUp() override { |
1383 WidgetTest::SetUp(); | 1458 WidgetTest::SetUp(); |
1384 | 1459 |
1385 widget_ = CreateTopLevelPlatformWidget(); | 1460 widget_ = CreateTopLevelPlatformWidget(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1510 lastDirtyRect_ = dirtyRect; | 1585 lastDirtyRect_ = dirtyRect; |
1511 } | 1586 } |
1512 | 1587 |
1513 @end | 1588 @end |
1514 | 1589 |
1515 @implementation FocusableTestNSView | 1590 @implementation FocusableTestNSView |
1516 - (BOOL)acceptsFirstResponder { | 1591 - (BOOL)acceptsFirstResponder { |
1517 return YES; | 1592 return YES; |
1518 } | 1593 } |
1519 @end | 1594 @end |
OLD | NEW |