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

Unified Diff: chrome/browser/ui/cocoa/location_bar/search_token_decoration_unittest.mm

Issue 12042002: Alternate NTP: Add search token to omnibox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 7 years, 11 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
Index: chrome/browser/ui/cocoa/location_bar/search_token_decoration_unittest.mm
diff --git a/chrome/browser/ui/cocoa/location_bar/search_token_decoration_unittest.mm b/chrome/browser/ui/cocoa/location_bar/search_token_decoration_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..adccc1f1e3d6c8a239c9e69109495e84d4ecc1f2
--- /dev/null
+++ b/chrome/browser/ui/cocoa/location_bar/search_token_decoration_unittest.mm
@@ -0,0 +1,46 @@
+// Copyright (c) 2013 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 "chrome/browser/ui/cocoa/location_bar/search_token_decoration.h"
+
+#include "base/utf_string_conversions.h"
+#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+typedef CocoaTest SearchTokenDecorationTest;
+
+TEST_F(SearchTokenDecorationTest, GetWidthForSpace) {
+ SearchTokenDecoration decoration;
+
+ decoration.SetSearchProviderName(ASCIIToUTF16("short"));
+ CGFloat short_width = decoration.GetWidthForSpace(1000, 0);
+ EXPECT_LT(0, short_width);
+
+ decoration.SetSearchProviderName(ASCIIToUTF16("longer name"));
+ CGFloat long_width = decoration.GetWidthForSpace(1000, 0);
+ EXPECT_LT(short_width, long_width);
+
+ CGFloat omit_width = decoration.GetWidthForSpace(1, 0);
+ EXPECT_EQ(omit_width, LocationBarDecoration::kOmittedWidth);
+}
+
+// Test that the search token is hidden if the omnibox text would overlap.
+TEST_F(SearchTokenDecorationTest, AutoCollapse) {
+ SearchTokenDecoration decoration;
+ decoration.SetSearchProviderName(ASCIIToUTF16("short"));
+ CGFloat width = decoration.GetWidthForSpace(1000, 1000);
+ EXPECT_EQ(width, LocationBarDecoration::kOmittedWidth);
+}
+
+TEST_F(SearchTokenDecorationTest, DrawInFrame) {
+ NSRect frame = NSMakeRect(0, 0, 100, 100);
+ scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:frame]);
+ [[test_window() contentView] addSubview:view];
+
+ [view lockFocus];
+ SearchTokenDecoration decoration;
+ decoration.SetSearchProviderName(ASCIIToUTF16("short"));
+ decoration.DrawInFrame(frame, view);
+ [view unlockFocus];
+}

Powered by Google App Engine
This is Rietveld 408576698