Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / autofill / down_arrow_popup_menu_cell_unittest.mm
blob02bb1e35ee5f5909dafca72a8401947838647711
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/autofill/down_arrow_popup_menu_cell.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/mac/scoped_nsobject.h"
10 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h"
13 #import "ui/gfx/test/ui_cocoa_test_helper.h"
15 namespace {
17 class DownArrowPopupMenuCellTest : public ui::CocoaTest {
18  public:
19   DownArrowPopupMenuCellTest() {
20     NSRect frame = NSMakeRect(0, 0, 50, 30);
21     view_.reset([[NSButton alloc] initWithFrame:frame]);
22     base::scoped_nsobject<DownArrowPopupMenuCell> cell(
23         [[DownArrowPopupMenuCell alloc] initTextCell:@"Testing"]);
24     [view_ setCell:cell.get()];
25     [[test_window() contentView] addSubview:view_];  }
27  protected:
28   base::scoped_nsobject<NSButton> view_;
30  private:
31   DISALLOW_COPY_AND_ASSIGN(DownArrowPopupMenuCellTest);
34 TEST_VIEW(DownArrowPopupMenuCellTest, view_)
36 }  // namespace
38 // Make internal messages visible for testing
39 @interface DownArrowPopupMenuCell (Testing)
41 - (NSSize)cellSize;
42 - (NSSize)imageSize;
44 @end
46 // Test size computations, make sure they deliver correct results.
47 TEST_F(DownArrowPopupMenuCellTest, Defaults) {
48   DownArrowPopupMenuCell* cell =
49       static_cast<DownArrowPopupMenuCell*>([view_ cell]);
50   ASSERT_TRUE([cell isKindOfClass:[DownArrowPopupMenuCell class]]);
52   NSRect rect = NSMakeRect(0, 0, 11, 17);
53   base::scoped_nsobject<NSImage> image(
54       [[NSImage alloc] initWithSize:rect.size]);
55   [cell setImage:image forButtonState:image_button_cell::kDefaultState];
56   [view_ setTitle:@"Testing"];
58   EXPECT_EQ(NSWidth(rect), [cell imageSize].width);
59   EXPECT_EQ(NSHeight(rect), [cell imageSize].height);
61   NSAttributedString* title = [cell attributedTitle];
62   NSSize titleSize = [title size];
63   EXPECT_LE(titleSize.width + [image size].width + autofill::kButtonGap,
64             [cell cellSize].width);
65   EXPECT_LE(std::max(titleSize.height, [image size].height),
66             [cell cellSize].height);