Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4847)

Unified Diff: chrome/browser/cocoa/location_bar/selected_keyword_decoration_unittest.mm

Issue 2805070: [Mac] First part of Omnibox decoration refactor. Enable ev bubble. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: comment clarification Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/location_bar/selected_keyword_decoration.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/location_bar/selected_keyword_decoration_unittest.mm
diff --git a/chrome/browser/cocoa/location_bar/selected_keyword_decoration_unittest.mm b/chrome/browser/cocoa/location_bar/selected_keyword_decoration_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..bd0f42f7c55dfef235d142d1095803f234e27c98
--- /dev/null
+++ b/chrome/browser/cocoa/location_bar/selected_keyword_decoration_unittest.mm
@@ -0,0 +1,64 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Cocoa/Cocoa.h>
+
+#import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h"
+
+#import "chrome/browser/cocoa/cocoa_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// A wide width which should fit everything.
+const CGFloat kWidth(300.0);
+
+// A narrow width for tests which test things that don't fit.
+const CGFloat kNarrowWidth(5.0);
+
+} // namespace
+
+class SelectedKeywordDecorationTest : public CocoaTest {
+ public:
+ SelectedKeywordDecorationTest()
+ : decoration_([NSFont userFontOfSize:12]) {
+ }
+
+ SelectedKeywordDecoration decoration_;
+};
+
+// Test that the cell correctly chooses the partial keyword if there's
+// not enough room.
+TEST_F(SelectedKeywordDecorationTest, UsesPartialKeywordIfNarrow) {
+
+ const std::wstring kKeyword(L"Engine");
+ NSString* const kFullString = @"Search Engine:";
+ NSString* const kPartialString = @"Search En\u2026:"; // ellipses
+
+ decoration_.SetKeyword(kKeyword, false);
+
+ // Wide width chooses the full string and image.
+ const CGFloat all_width = decoration_.GetWidthForSpace(kWidth);
+ EXPECT_TRUE(decoration_.image_);
+ EXPECT_TRUE([decoration_.label_ isEqualToString:kFullString]);
+
+ // If not enough space to include the image, uses exactly the full
+ // string.
+ const CGFloat full_width = decoration_.GetWidthForSpace(all_width - 5.0);
+ EXPECT_LT(full_width, all_width);
+ EXPECT_FALSE(decoration_.image_);
+ EXPECT_TRUE([decoration_.label_ isEqualToString:kFullString]);
+
+ // Narrow width chooses the partial string.
+ const CGFloat partial_width = decoration_.GetWidthForSpace(kNarrowWidth);
+ EXPECT_LT(partial_width, full_width);
+ EXPECT_FALSE(decoration_.image_);
+ EXPECT_TRUE([decoration_.label_ isEqualToString:kPartialString]);
+
+ // Narrow doesn't choose partial string if there is not one.
+ decoration_.partial_string_.reset();
+ decoration_.GetWidthForSpace(kNarrowWidth);
+ EXPECT_FALSE(decoration_.image_);
+ EXPECT_TRUE([decoration_.label_ isEqualToString:kFullString]);
+}
« no previous file with comments | « chrome/browser/cocoa/location_bar/selected_keyword_decoration.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698