OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #import "chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h" |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" | 7 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #import "ui/base/test/ui_cocoa_test_helper.h" | 9 #import "ui/base/test/ui_cocoa_test_helper.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 class AutofillSuggestionContainerTest : public ui::CocoaTest { | 13 class AutofillSuggestionContainerTest : public ui::CocoaTest { |
14 public: | 14 public: |
15 virtual void SetUp() { | 15 virtual void SetUp() { |
16 CocoaTest::SetUp(); | 16 CocoaTest::SetUp(); |
17 container_.reset([[AutofillSuggestionContainer alloc] init]); | 17 container_.reset([[AutofillSuggestionContainer alloc] init]); |
18 [[test_window() contentView] addSubview:[container_ view]]; | 18 [[test_window() contentView] addSubview:[container_ view]]; |
19 view_ = [container_ view]; | |
19 } | 20 } |
20 | 21 |
21 protected: | 22 protected: |
22 base::scoped_nsobject<AutofillSuggestionContainer> container_; | 23 base::scoped_nsobject<AutofillSuggestionContainer> container_; |
24 NSView* view_; | |
23 }; | 25 }; |
24 | 26 |
25 } // namespace | 27 } // namespace |
26 | 28 |
27 TEST_VIEW(AutofillSuggestionContainerTest, [container_ view]) | 29 TEST_VIEW(AutofillSuggestionContainerTest, [container_ view]) |
28 | 30 |
29 TEST_F(AutofillSuggestionContainerTest, HasSubviews) { | 31 TEST_F(AutofillSuggestionContainerTest, HasSubviews) { |
30 ASSERT_EQ(3U, [[[container_ view] subviews] count]); | 32 ASSERT_EQ(3U, [[[container_ view] subviews] count]); |
31 | 33 |
32 bool has_text_view = false; | 34 bool has_text_view = false; |
33 bool has_edit_field = false; | 35 bool has_edit_field = false; |
34 | 36 |
35 // Ignore |spacer_| NSBox in this test. | 37 // Ignore |spacer_| NSBox in this test. |
36 for (id view in [[container_ view] subviews]) { | 38 for (id view in [[container_ view] subviews]) { |
37 if ([view isKindOfClass:[AutofillTextField class]]) { | 39 if ([view isKindOfClass:[AutofillTextField class]]) { |
38 has_edit_field = true; | 40 has_edit_field = true; |
39 } else if ([view isKindOfClass:[NSTextView class]]) { | 41 } else if ([view isKindOfClass:[NSTextView class]]) { |
40 has_text_view = true; | 42 has_text_view = true; |
41 } | 43 } |
42 } | 44 } |
43 | 45 |
44 EXPECT_TRUE(has_text_view); | 46 EXPECT_TRUE(has_text_view); |
45 EXPECT_TRUE(has_edit_field); | 47 EXPECT_TRUE(has_edit_field); |
46 } | 48 } |
49 | |
50 // Test that mouse events outside the input field are ignored. | |
51 TEST_F(AutofillSuggestionContainerTest, HitTestInputField) { | |
52 base::scoped_nsobject<NSImage> icon( | |
53 [[NSImage alloc] initWithSize:NSMakeSize(16, 16)]); | |
54 [container_ setSuggestionWithVerticallyCompactText:@"suggest" | |
55 horizontallyCompactText:@"suggest" | |
56 icon:nil | |
57 maxWidth:200]; | |
58 [container_ showInputField:@"input" withIcon:icon]; | |
59 [view_ setFrameSize:[container_ preferredSize]]; | |
60 [container_ performLayout]; | |
61 | |
62 // Point not touching any subviews, in |view_|'s coordinate system. | |
63 NSPoint pointOutsideSubviews = | |
Robert Sesek
2014/01/08 14:50:19
naming: under_scores (also update the comments)
groby-ooo-7-16
2014/01/08 19:20:58
Done.
| |
64 NSMakePoint(NSMinX([view_ bounds]), NSMaxY([view_ bounds]) - 1); | |
65 NSPoint pointInsideTextView = NSZeroPoint; | |
66 | |
67 // hitTests on all inputs should be false, except for the inputField. | |
68 for (id fieldView in [view_ subviews]) { | |
Robert Sesek
2014/01/08 14:50:19
naming: field_view
groby-ooo-7-16
2014/01/08 19:20:58
Done.
| |
69 // Ensure |pointOutsideSubviews| really is outside subviews. | |
70 ASSERT_FALSE([fieldView hitTest:pointOutsideSubviews]); | |
71 | |
72 // Compute center of |fieldView| in |view_|'s parent coordinate system. | |
73 NSPoint point = | |
74 [view_ convertPoint:NSMakePoint(NSMidX([fieldView frame]), | |
75 NSMidY([fieldView frame])) | |
76 toView:[view_ superview]]; | |
77 if (fieldView == [container_ inputField]) { | |
78 pointInsideTextView = point; | |
79 EXPECT_TRUE([view_ hitTest:point]); | |
80 } else { | |
81 EXPECT_FALSE([view_ hitTest:point]); | |
82 } | |
83 } | |
84 | |
85 // Mouse events directly on the main view should be ignored. | |
86 EXPECT_FALSE([view_ hitTest: | |
87 [view_ convertPoint:pointOutsideSubviews | |
88 toView:[view_ superview]]]); | |
89 | |
90 // Mouse events on the text view's editor should propagate. | |
91 [[view_ window] makeFirstResponder:[container_ inputField]]; | |
92 NSView* editorView = [view_ hitTest:pointInsideTextView]; | |
93 ASSERT_NE(editorView, [container_ inputField]); | |
Robert Sesek
2014/01/08 14:50:19
Generally stick with EXPECT_ unless you need to st
groby-ooo-7-16
2014/01/08 19:20:58
This was intentional - it confirms a precondition
| |
94 ASSERT_TRUE([editorView isDescendantOf:[container_ inputField]]); | |
95 EXPECT_TRUE(editorView); | |
96 } | |
OLD | NEW |