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