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

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

Issue 2854051: [Mac] Convert omnibox keyword hint to decoration. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: 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
Index: chrome/browser/cocoa/location_bar/keyword_hint_decoration_unittest.mm
diff --git a/chrome/browser/cocoa/location_bar/keyword_hint_decoration_unittest.mm b/chrome/browser/cocoa/location_bar/keyword_hint_decoration_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..1ee8c8ebe2703f87422e79870640a14c6363709a
--- /dev/null
+++ b/chrome/browser/cocoa/location_bar/keyword_hint_decoration_unittest.mm
@@ -0,0 +1,57 @@
+// 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/keyword_hint_decoration.h"
+
+#import "chrome/browser/cocoa/cocoa_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class KeywordHintDecorationTest : public CocoaTest {
+ public:
+ KeywordHintDecorationTest()
+ : decoration_(NULL) {
+ }
+
+ KeywordHintDecoration decoration_;
+};
+
+TEST_F(KeywordHintDecorationTest, GetWidthForSpace) {
+ decoration_.SetVisible(true);
+ decoration_.SetKeyword(std::wstring(L"Google"), false);
+
+ const CGFloat kVeryWide = 1000.0;
+ const CGFloat kFairlyWide = 100.0; // Estimate for full hint space.
+ const CGFloat kEditingSpace = 50.0;
+
+ // Wider than the [tab] image when we have lots of space.
+ EXPECT_NE(decoration_.GetWidthForSpace(kVeryWide),
+ LocationBarDecoration::kOmittedWidth);
+ EXPECT_GE(decoration_.GetWidthForSpace(kVeryWide), kFairlyWide);
+
+ // When there's not enough space for the text, trims to something
+ // narrower.
+ const CGFloat full_width = decoration_.GetWidthForSpace(kVeryWide);
+ const CGFloat not_wide_enough = full_width - 10.0;
+ EXPECT_NE(decoration_.GetWidthForSpace(not_wide_enough),
+ LocationBarDecoration::kOmittedWidth);
+ EXPECT_LT(decoration_.GetWidthForSpace(not_wide_enough), full_width);
+
+ // Even trims when there's enough space for everything, but it would
+ // eat "too much".
+ EXPECT_NE(decoration_.GetWidthForSpace(full_width + kEditingSpace),
+ LocationBarDecoration::kOmittedWidth);
+ EXPECT_LT(decoration_.GetWidthForSpace(full_width + kEditingSpace),
+ full_width);
+
+ // Omitted when not wide enough to fit even the image.
+ const CGFloat image_width = decoration_.GetWidthForSpace(not_wide_enough);
+ EXPECT_EQ(decoration_.GetWidthForSpace(image_width - 1.0),
+ LocationBarDecoration::kOmittedWidth);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698