keyword_hint_decoration_unittest.mm revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright (c) 2010 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.
4
5#import <Cocoa/Cocoa.h>
6
7#import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h"
8
9#include "base/strings/utf_string_conversions.h"
10#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
11#include "testing/gtest/include/gtest/gtest.h"
12
13namespace {
14
15class KeywordHintDecorationTest : public CocoaTest {
16 public:
17  KeywordHintDecorationTest() {
18  }
19
20  KeywordHintDecoration decoration_;
21};
22
23TEST_F(KeywordHintDecorationTest, GetWidthForSpace) {
24  decoration_.SetVisible(true);
25  decoration_.SetKeyword(base::ASCIIToUTF16("google"), false);
26
27  const CGFloat kVeryWide = 1000.0;
28  const CGFloat kFairlyWide = 100.0;  // Estimate for full hint space.
29  const CGFloat kEditingSpace = 50.0;
30
31  // Wider than the [tab] image when we have lots of space.
32  EXPECT_NE(decoration_.GetWidthForSpace(kVeryWide),
33            LocationBarDecoration::kOmittedWidth);
34  EXPECT_GE(decoration_.GetWidthForSpace(kVeryWide), kFairlyWide);
35
36  // When there's not enough space for the text, trims to something
37  // narrower.
38  const CGFloat full_width = decoration_.GetWidthForSpace(kVeryWide);
39  const CGFloat not_wide_enough = full_width - 10.0;
40  EXPECT_NE(decoration_.GetWidthForSpace(not_wide_enough),
41            LocationBarDecoration::kOmittedWidth);
42  EXPECT_LT(decoration_.GetWidthForSpace(not_wide_enough), full_width);
43
44  // Even trims when there's enough space for everything, but it would
45  // eat "too much".
46  EXPECT_NE(decoration_.GetWidthForSpace(full_width + kEditingSpace),
47            LocationBarDecoration::kOmittedWidth);
48  EXPECT_LT(decoration_.GetWidthForSpace(full_width + kEditingSpace),
49            full_width);
50
51  // Omitted when not wide enough to fit even the image.
52  const CGFloat image_width = decoration_.GetWidthForSpace(not_wide_enough);
53  EXPECT_EQ(decoration_.GetWidthForSpace(image_width - 1.0),
54            LocationBarDecoration::kOmittedWidth);
55}
56
57}  // namespace
58