- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / location_bar / selected_keyword_decoration_unittest.mm
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 #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"
12
13 namespace {
14
15 // A wide width which should fit everything.
16 const CGFloat kWidth(300.0);
17
18 // A narrow width for tests which test things that don't fit.
19 const CGFloat kNarrowWidth(5.0);
20
21 }  // namespace
22
23 class SelectedKeywordDecorationTest : public CocoaTest {
24  public:
25   SelectedKeywordDecorationTest() {
26   }
27
28   SelectedKeywordDecoration decoration_;
29 };
30
31 // Test that the cell correctly chooses the partial keyword if there's
32 // not enough room.
33 TEST_F(SelectedKeywordDecorationTest, UsesPartialKeywordIfNarrow) {
34
35   const string16 kKeyword = ASCIIToUTF16("Engine");
36   NSString* const kFullString = @"Search Engine:";
37   NSString* const kPartialString = @"Search En\u2026:";  // ellipses
38
39   decoration_.SetKeyword(kKeyword, false);
40
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_);
45
46   // If not enough space to include the image, uses exactly the full
47   // string.
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_);
52
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_);
58
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_);
64 }