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.
5 #import <Cocoa/Cocoa.h>
7 #include "base/strings/utf_string_conversions.h"
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
9 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #import "testing/gtest_mac.h"
15 // A wide width which should fit everything.
16 const CGFloat kWidth(300.0);
18 // A narrow width for tests which test things that don't fit.
19 const CGFloat kNarrowWidth(5.0);
23 class SelectedKeywordDecorationTest : public CocoaTest {
25 SelectedKeywordDecorationTest() {
28 SelectedKeywordDecoration decoration_;
31 // Test that the cell correctly chooses the partial keyword if there's
33 TEST_F(SelectedKeywordDecorationTest, UsesPartialKeywordIfNarrow) {
35 const string16 kKeyword = ASCIIToUTF16("Engine");
36 NSString* const kFullString = @"Search Engine:";
37 NSString* const kPartialString = @"Search En\u2026:"; // ellipses
39 decoration_.SetKeyword(kKeyword, false);
41 // Wide width chooses the full string and image.
42 const CGFloat all_width = decoration_.GetWidthForSpace(kWidth);
43 EXPECT_TRUE(decoration_.image_);
44 EXPECT_NSEQ(kFullString, decoration_.label_);
46 // If not enough space to include the image, uses exactly the full
48 const CGFloat full_width = decoration_.GetWidthForSpace(all_width - 5.0);
49 EXPECT_LT(full_width, all_width);
50 EXPECT_FALSE(decoration_.image_);
51 EXPECT_NSEQ(kFullString, decoration_.label_);
53 // Narrow width chooses the partial string.
54 const CGFloat partial_width = decoration_.GetWidthForSpace(kNarrowWidth);
55 EXPECT_LT(partial_width, full_width);
56 EXPECT_FALSE(decoration_.image_);
57 EXPECT_NSEQ(kPartialString, decoration_.label_);
59 // Narrow doesn't choose partial string if there is not one.
60 decoration_.partial_string_.reset();
61 decoration_.GetWidthForSpace(kNarrowWidth);
62 EXPECT_FALSE(decoration_.image_);
63 EXPECT_NSEQ(kFullString, decoration_.label_);