Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/omnibox/omnibox_popup_cell.h" | |
| 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.h" | 6 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.h" |
| 6 | 7 |
| 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 8 #import "ui/events/test/cocoa_test_event_utils.h" | 9 #import "ui/events/test/cocoa_test_event_utils.h" |
| 9 | 10 |
| 10 namespace { | 11 namespace { |
| 11 | 12 |
| 12 NSEvent* MouseEventInRow(NSMatrix* matrix, NSEventType type, NSInteger row) { | 13 NSEvent* MouseEventInRow(OmniboxPopupMatrix* matrix, |
| 13 NSRect cell_rect = [matrix cellFrameAtRow:row column:0]; | 14 NSEventType type, |
| 15 NSInteger row) { | |
| 16 NSRect cell_rect = [matrix rectOfRow:row]; | |
| 14 NSPoint point_in_view = NSMakePoint(NSMidX(cell_rect), NSMidY(cell_rect)); | 17 NSPoint point_in_view = NSMakePoint(NSMidX(cell_rect), NSMidY(cell_rect)); |
| 15 NSPoint point_in_window = [matrix convertPoint:point_in_view toView:nil]; | 18 NSPoint point_in_window = [matrix convertPoint:point_in_view toView:nil]; |
| 16 return cocoa_test_event_utils::MouseEventAtPoint( | 19 return cocoa_test_event_utils::MouseEventAtPoint( |
| 17 point_in_window, type, 0); | 20 point_in_window, type, 0); |
| 18 } | 21 } |
| 19 | 22 |
| 20 class OmniboxPopupMatrixTest : public CocoaTest, | 23 class OmniboxPopupMatrixTest : public CocoaTest, |
| 21 public OmniboxPopupMatrixDelegate { | 24 public OmniboxPopupMatrixDelegate { |
| 22 public: | 25 public: |
| 23 OmniboxPopupMatrixTest() | 26 OmniboxPopupMatrixTest() |
| 24 : selected_row_(0), | 27 : selected_row_(0), clicked_row_(0), middle_clicked_row_(0) {} |
| 25 clicked_row_(0), | |
| 26 middle_clicked_row_(0) { | |
| 27 } | |
| 28 | 28 |
| 29 void SetUp() override { | 29 void SetUp() override { |
| 30 CocoaTest::SetUp(); | 30 CocoaTest::SetUp(); |
| 31 matrix_.reset([[OmniboxPopupMatrix alloc] initWithDelegate:this]); | 31 matrix_.reset([[OmniboxPopupMatrix alloc] initWithDelegate:this]); |
|
Scott Hess - ex-Googler
2015/05/07 22:35:42
Matrix is seeming misleading!
dschuyler
2015/05/13 01:41:11
I'd like to separate the name change to another CL
| |
| 32 [[test_window() contentView] addSubview:matrix_]; | 32 [[test_window() contentView] addSubview:matrix_]; |
| 33 | |
| 34 base::scoped_nsobject<NSTableColumn> column( | |
| 35 [[NSTableColumn alloc] initWithIdentifier:@"MainCell"]); | |
| 36 [column setDataCell:[[[OmniboxPopupCell alloc] init] autorelease]]; | |
| 37 [matrix_ addTableColumn:[column retain]]; | |
|
Scott Hess - ex-Googler
2015/05/07 22:35:42
Seems like the receiver is going to -retain, so th
dschuyler
2015/05/13 01:41:11
Done.
| |
| 38 NSInteger testWidth = 400; | |
| 39 NSInteger testHeight = 25; | |
|
Scott Hess - ex-Googler
2015/05/07 22:35:42
CGFloat, since they're floats in use below.
dschuyler
2015/05/13 01:41:11
Done.
| |
| 40 | |
| 41 NSMutableArray* array = [NSMutableArray array]; | |
| 42 NSInteger popupHeight = 0; | |
|
Scott Hess - ex-Googler
2015/05/07 22:35:42
CGFloat here, too.
dschuyler
2015/05/13 01:41:11
Done.
| |
| 43 NSRect cellRect = NSZeroRect; | |
| 44 cellRect.size.width = testWidth; | |
| 45 for (size_t ii = 0; ii < 3; ++ii) { | |
| 46 NSMutableDictionary* dictionary = [NSMutableDictionary dictionary]; | |
| 47 AutocompleteMatchWrapper* acm = | |
| 48 [[[AutocompleteMatchWrapper alloc] init] autorelease]; | |
| 49 [dictionary setObject:acm forKey:@"match"]; | |
| 50 cellRect.origin.y = popupHeight; | |
| 51 cellRect.size.height = testHeight; | |
| 52 [dictionary setObject:[NSValue valueWithRect:cellRect] forKey:@"rect"]; | |
| 53 popupHeight += testHeight; | |
| 54 [array addObject:dictionary]; | |
| 55 } | |
| 56 [matrix_ setDataArray:array]; | |
| 57 [matrix_ reloadData]; | |
| 58 | |
| 59 NSRect table_frame = NSZeroRect; | |
| 60 table_frame.size.width = testWidth; | |
| 61 table_frame.size.height = popupHeight; | |
| 62 [matrix_ setFrame:table_frame]; | |
| 33 }; | 63 }; |
| 34 | 64 |
| 35 void OnMatrixRowSelected(OmniboxPopupMatrix* matrix, size_t row) override { | 65 void OnMatrixRowSelected(OmniboxPopupMatrix* matrix, size_t row) override { |
| 36 selected_row_ = row; | 66 selected_row_ = row; |
| 37 [matrix_ selectCellAtRow:row column:0]; | |
| 38 } | 67 } |
| 39 | 68 |
| 40 void OnMatrixRowClicked(OmniboxPopupMatrix* matrix, size_t row) override { | 69 void OnMatrixRowClicked(OmniboxPopupMatrix* matrix, size_t row) override { |
| 41 clicked_row_ = row; | 70 clicked_row_ = row; |
| 42 } | 71 } |
| 43 | 72 |
| 44 void OnMatrixRowMiddleClicked(OmniboxPopupMatrix* matrix, | 73 void OnMatrixRowMiddleClicked(OmniboxPopupMatrix* matrix, |
| 45 size_t row) override { | 74 size_t row) override { |
| 46 middle_clicked_row_ = row; | 75 middle_clicked_row_ = row; |
| 47 } | 76 } |
| 48 | 77 |
| 49 protected: | 78 protected: |
| 50 base::scoped_nsobject<OmniboxPopupMatrix> matrix_; | 79 base::scoped_nsobject<OmniboxPopupMatrix> matrix_; |
| 51 size_t selected_row_; | 80 size_t selected_row_; |
| 52 size_t clicked_row_; | 81 size_t clicked_row_; |
| 53 size_t middle_clicked_row_; | 82 size_t middle_clicked_row_; |
| 54 | 83 |
| 55 private: | 84 private: |
| 56 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupMatrixTest); | 85 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupMatrixTest); |
| 57 }; | 86 }; |
| 58 | 87 |
| 59 TEST_VIEW(OmniboxPopupMatrixTest, matrix_); | 88 TEST_VIEW(OmniboxPopupMatrixTest, matrix_); |
| 60 | 89 |
| 61 TEST_F(OmniboxPopupMatrixTest, HighlightedRow) { | 90 TEST_F(OmniboxPopupMatrixTest, HighlightedRow) { |
| 62 [matrix_ renewRows:3 columns:1]; | |
| 63 EXPECT_EQ(-1, [matrix_ highlightedRow]); | 91 EXPECT_EQ(-1, [matrix_ highlightedRow]); |
| 64 | 92 |
| 65 [matrix_ mouseEntered:MouseEventInRow(matrix_, NSMouseMoved, 0)]; | 93 [matrix_ mouseEntered:MouseEventInRow(matrix_, NSMouseMoved, 0)]; |
| 66 EXPECT_EQ(0, [matrix_ highlightedRow]); | 94 EXPECT_EQ(0, [matrix_ highlightedRow]); |
| 67 [matrix_ mouseEntered:MouseEventInRow(matrix_, NSMouseMoved, 2)]; | 95 [matrix_ mouseEntered:MouseEventInRow(matrix_, NSMouseMoved, 2)]; |
| 68 EXPECT_EQ(2, [matrix_ highlightedRow]); | 96 EXPECT_EQ(2, [matrix_ highlightedRow]); |
| 69 | 97 |
| 70 [matrix_ mouseExited:MouseEventInRow(matrix_, NSMouseMoved, 2)]; | 98 [matrix_ mouseExited:MouseEventInRow(matrix_, NSMouseMoved, 2)]; |
| 71 EXPECT_EQ(-1, [matrix_ highlightedRow]); | 99 EXPECT_EQ(-1, [matrix_ highlightedRow]); |
| 72 } | 100 } |
| 73 | 101 |
| 74 TEST_F(OmniboxPopupMatrixTest, SelectedRow) { | 102 TEST_F(OmniboxPopupMatrixTest, SelectedRow) { |
| 75 [matrix_ renewRows:3 columns:1]; | |
| 76 | |
| 77 [NSApp postEvent:MouseEventInRow(matrix_, NSLeftMouseUp, 2) atStart:YES]; | 103 [NSApp postEvent:MouseEventInRow(matrix_, NSLeftMouseUp, 2) atStart:YES]; |
| 78 [matrix_ mouseDown:MouseEventInRow(matrix_, NSLeftMouseDown, 2)]; | 104 [matrix_ mouseDown:MouseEventInRow(matrix_, NSLeftMouseDown, 2)]; |
| 79 | 105 |
| 80 EXPECT_EQ(2u, selected_row_); | 106 EXPECT_EQ(2u, selected_row_); |
| 81 EXPECT_EQ(2u, clicked_row_); | 107 EXPECT_EQ(2u, clicked_row_); |
| 82 EXPECT_EQ(0u, middle_clicked_row_); | 108 EXPECT_EQ(0u, middle_clicked_row_); |
| 83 } | 109 } |
| 84 | 110 |
| 85 } // namespace | 111 } // namespace |
| OLD | NEW |