Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / omnibox / omnibox_popup_matrix_unittest.mm
blob54d1e4743f0f89c11933eafb844c191efbc1a0c7
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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.h"
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
8 #import "ui/base/test/cocoa_test_event_utils.h"
10 namespace {
12 NSEvent* MouseEventInRow(NSMatrix* matrix, NSEventType type, NSInteger row) {
13   NSRect cell_rect = [matrix cellFrameAtRow:row column:0];
14   NSPoint point_in_view = NSMakePoint(NSMidX(cell_rect), NSMidY(cell_rect));
15   NSPoint point_in_window = [matrix convertPoint:point_in_view toView:nil];
16   return cocoa_test_event_utils::MouseEventAtPoint(
17       point_in_window, type, 0);
20 class OmniboxPopupMatrixTest : public CocoaTest,
21                                public OmniboxPopupMatrixDelegate {
22  public:
23   OmniboxPopupMatrixTest()
24       : selected_row_(0),
25         clicked_row_(0),
26         middle_clicked_row_(0) {
27   }
29   virtual void SetUp() OVERRIDE {
30     CocoaTest::SetUp();
31     matrix_.reset([[OmniboxPopupMatrix alloc] initWithDelegate:this]);
32     [[test_window() contentView] addSubview:matrix_];
33   };
35   virtual void OnMatrixRowSelected(OmniboxPopupMatrix* matrix,
36                                    size_t row) OVERRIDE {
37     selected_row_ = row;
38     [matrix_ selectCellAtRow:row column:0];
39   }
41   virtual void OnMatrixRowClicked(OmniboxPopupMatrix* matrix,
42                                 size_t row) OVERRIDE {
43     clicked_row_ = row;
44   }
46   virtual void OnMatrixRowMiddleClicked(OmniboxPopupMatrix* matrix,
47                                         size_t row) OVERRIDE {
48     middle_clicked_row_ = row;
49   }
51  protected:
52   base::scoped_nsobject<OmniboxPopupMatrix> matrix_;
53   size_t selected_row_;
54   size_t clicked_row_;
55   size_t middle_clicked_row_;
57  private:
58   DISALLOW_COPY_AND_ASSIGN(OmniboxPopupMatrixTest);
61 TEST_VIEW(OmniboxPopupMatrixTest, matrix_);
63 TEST_F(OmniboxPopupMatrixTest, HighlightedRow) {
64   [matrix_ renewRows:3 columns:1];
65   EXPECT_EQ(-1, [matrix_ highlightedRow]);
67   [matrix_ mouseEntered:MouseEventInRow(matrix_, NSMouseMoved, 0)];
68   EXPECT_EQ(0, [matrix_ highlightedRow]);
69   [matrix_ mouseEntered:MouseEventInRow(matrix_, NSMouseMoved, 2)];
70   EXPECT_EQ(2, [matrix_ highlightedRow]);
72   [matrix_ mouseExited:MouseEventInRow(matrix_, NSMouseMoved, 2)];
73   EXPECT_EQ(-1, [matrix_ highlightedRow]);
76 TEST_F(OmniboxPopupMatrixTest, SelectedRow) {
77   [matrix_ renewRows:3 columns:1];
79   [NSApp postEvent:MouseEventInRow(matrix_, NSLeftMouseUp, 2) atStart:YES];
80   [matrix_ mouseDown:MouseEventInRow(matrix_, NSLeftMouseDown, 2)];
82   EXPECT_EQ(2u, selected_row_);
83   EXPECT_EQ(2u, clicked_row_);
84   EXPECT_EQ(0u, middle_clicked_row_);
87 }  // namespace