| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h" | 7 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h" |
| 8 | 8 |
| 9 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #import "testing/gtest_mac.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 // A wide width which should fit everything. | 15 // A wide width which should fit everything. |
| 15 const CGFloat kWidth(300.0); | 16 const CGFloat kWidth(300.0); |
| 16 | 17 |
| 17 // A narrow width for tests which test things that don't fit. | 18 // A narrow width for tests which test things that don't fit. |
| 18 const CGFloat kNarrowWidth(5.0); | 19 const CGFloat kNarrowWidth(5.0); |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 | 35 |
| 35 const std::wstring kKeyword(L"Engine"); | 36 const std::wstring kKeyword(L"Engine"); |
| 36 NSString* const kFullString = @"Search Engine:"; | 37 NSString* const kFullString = @"Search Engine:"; |
| 37 NSString* const kPartialString = @"Search En\u2026:"; // ellipses | 38 NSString* const kPartialString = @"Search En\u2026:"; // ellipses |
| 38 | 39 |
| 39 decoration_.SetKeyword(kKeyword, false); | 40 decoration_.SetKeyword(kKeyword, false); |
| 40 | 41 |
| 41 // Wide width chooses the full string and image. | 42 // Wide width chooses the full string and image. |
| 42 const CGFloat all_width = decoration_.GetWidthForSpace(kWidth); | 43 const CGFloat all_width = decoration_.GetWidthForSpace(kWidth); |
| 43 EXPECT_TRUE(decoration_.image_); | 44 EXPECT_TRUE(decoration_.image_); |
| 44 EXPECT_TRUE([decoration_.label_ isEqualToString:kFullString]); | 45 EXPECT_NSEQ(kFullString, decoration_.label_); |
| 45 | 46 |
| 46 // If not enough space to include the image, uses exactly the full | 47 // If not enough space to include the image, uses exactly the full |
| 47 // string. | 48 // string. |
| 48 const CGFloat full_width = decoration_.GetWidthForSpace(all_width - 5.0); | 49 const CGFloat full_width = decoration_.GetWidthForSpace(all_width - 5.0); |
| 49 EXPECT_LT(full_width, all_width); | 50 EXPECT_LT(full_width, all_width); |
| 50 EXPECT_FALSE(decoration_.image_); | 51 EXPECT_FALSE(decoration_.image_); |
| 51 EXPECT_TRUE([decoration_.label_ isEqualToString:kFullString]); | 52 EXPECT_NSEQ(kFullString, decoration_.label_); |
| 52 | 53 |
| 53 // Narrow width chooses the partial string. | 54 // Narrow width chooses the partial string. |
| 54 const CGFloat partial_width = decoration_.GetWidthForSpace(kNarrowWidth); | 55 const CGFloat partial_width = decoration_.GetWidthForSpace(kNarrowWidth); |
| 55 EXPECT_LT(partial_width, full_width); | 56 EXPECT_LT(partial_width, full_width); |
| 56 EXPECT_FALSE(decoration_.image_); | 57 EXPECT_FALSE(decoration_.image_); |
| 57 EXPECT_TRUE([decoration_.label_ isEqualToString:kPartialString]); | 58 EXPECT_NSEQ(kPartialString, decoration_.label_); |
| 58 | 59 |
| 59 // Narrow doesn't choose partial string if there is not one. | 60 // Narrow doesn't choose partial string if there is not one. |
| 60 decoration_.partial_string_.reset(); | 61 decoration_.partial_string_.reset(); |
| 61 decoration_.GetWidthForSpace(kNarrowWidth); | 62 decoration_.GetWidthForSpace(kNarrowWidth); |
| 62 EXPECT_FALSE(decoration_.image_); | 63 EXPECT_FALSE(decoration_.image_); |
| 63 EXPECT_TRUE([decoration_.label_ isEqualToString:kFullString]); | 64 EXPECT_NSEQ(kFullString, decoration_.label_); |
| 64 } | 65 } |
| OLD | NEW |