| 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_matrix.h" | 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.h" |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 8 #import "ui/events/test/cocoa_test_event_utils.h" | 8 #import "ui/events/test/cocoa_test_event_utils.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 NSEvent* MouseEventInRow(NSMatrix* matrix, NSEventType type, NSInteger row) { | 12 NSEvent* MouseEventInRow(NSMatrix* matrix, NSEventType type, NSInteger row) { |
| 13 NSRect cell_rect = [matrix cellFrameAtRow:row column:0]; | 13 NSRect cell_rect = [matrix cellFrameAtRow:row column:0]; |
| 14 NSPoint point_in_view = NSMakePoint(NSMidX(cell_rect), NSMidY(cell_rect)); | 14 NSPoint point_in_view = NSMakePoint(NSMidX(cell_rect), NSMidY(cell_rect)); |
| 15 NSPoint point_in_window = [matrix convertPoint:point_in_view toView:nil]; | 15 NSPoint point_in_window = [matrix convertPoint:point_in_view toView:nil]; |
| 16 return cocoa_test_event_utils::MouseEventAtPoint( | 16 return cocoa_test_event_utils::MouseEventAtPoint( |
| 17 point_in_window, type, 0); | 17 point_in_window, type, 0); |
| 18 } | 18 } |
| 19 | 19 |
| 20 class OmniboxPopupMatrixTest : public CocoaTest, | 20 class OmniboxPopupMatrixTest : public CocoaTest, |
| 21 public OmniboxPopupMatrixDelegate { | 21 public OmniboxPopupMatrixDelegate { |
| 22 public: | 22 public: |
| 23 OmniboxPopupMatrixTest() | 23 OmniboxPopupMatrixTest() |
| 24 : selected_row_(0), | 24 : selected_row_(0), |
| 25 clicked_row_(0), | 25 clicked_row_(0), |
| 26 middle_clicked_row_(0) { | 26 middle_clicked_row_(0) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 virtual void SetUp() OVERRIDE { | 29 virtual void SetUp() override { |
| 30 CocoaTest::SetUp(); | 30 CocoaTest::SetUp(); |
| 31 matrix_.reset([[OmniboxPopupMatrix alloc] initWithDelegate:this]); | 31 matrix_.reset([[OmniboxPopupMatrix alloc] initWithDelegate:this]); |
| 32 [[test_window() contentView] addSubview:matrix_]; | 32 [[test_window() contentView] addSubview:matrix_]; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 virtual void OnMatrixRowSelected(OmniboxPopupMatrix* matrix, | 35 virtual void OnMatrixRowSelected(OmniboxPopupMatrix* matrix, |
| 36 size_t row) OVERRIDE { | 36 size_t row) override { |
| 37 selected_row_ = row; | 37 selected_row_ = row; |
| 38 [matrix_ selectCellAtRow:row column:0]; | 38 [matrix_ selectCellAtRow:row column:0]; |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual void OnMatrixRowClicked(OmniboxPopupMatrix* matrix, | 41 virtual void OnMatrixRowClicked(OmniboxPopupMatrix* matrix, |
| 42 size_t row) OVERRIDE { | 42 size_t row) override { |
| 43 clicked_row_ = row; | 43 clicked_row_ = row; |
| 44 } | 44 } |
| 45 | 45 |
| 46 virtual void OnMatrixRowMiddleClicked(OmniboxPopupMatrix* matrix, | 46 virtual void OnMatrixRowMiddleClicked(OmniboxPopupMatrix* matrix, |
| 47 size_t row) OVERRIDE { | 47 size_t row) override { |
| 48 middle_clicked_row_ = row; | 48 middle_clicked_row_ = row; |
| 49 } | 49 } |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 base::scoped_nsobject<OmniboxPopupMatrix> matrix_; | 52 base::scoped_nsobject<OmniboxPopupMatrix> matrix_; |
| 53 size_t selected_row_; | 53 size_t selected_row_; |
| 54 size_t clicked_row_; | 54 size_t clicked_row_; |
| 55 size_t middle_clicked_row_; | 55 size_t middle_clicked_row_; |
| 56 | 56 |
| 57 private: | 57 private: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 78 | 78 |
| 79 [NSApp postEvent:MouseEventInRow(matrix_, NSLeftMouseUp, 2) atStart:YES]; | 79 [NSApp postEvent:MouseEventInRow(matrix_, NSLeftMouseUp, 2) atStart:YES]; |
| 80 [matrix_ mouseDown:MouseEventInRow(matrix_, NSLeftMouseDown, 2)]; | 80 [matrix_ mouseDown:MouseEventInRow(matrix_, NSLeftMouseDown, 2)]; |
| 81 | 81 |
| 82 EXPECT_EQ(2u, selected_row_); | 82 EXPECT_EQ(2u, selected_row_); |
| 83 EXPECT_EQ(2u, clicked_row_); | 83 EXPECT_EQ(2u, clicked_row_); |
| 84 EXPECT_EQ(0u, middle_clicked_row_); | 84 EXPECT_EQ(0u, middle_clicked_row_); |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace | 87 } // namespace |
| OLD | NEW |