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

Unified Diff: chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm

Issue 173194: [Mac] Omnibox keyword, keyword hint, and search hint support.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 4 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/autocomplete_text_field_cell_unittest.mm
===================================================================
--- chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm (revision 23951)
+++ chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm (working copy)
@@ -11,16 +11,12 @@
namespace {
-// TODO(shess): Make a sensible distinction between
-// AutocompleteTextField unittesting and AutocompleteTextFieldCell
-// unittesting - or, since AutocompleteTextFieldCell doesn't really
-// have independent existence, just put tests for both in
-// autocomplete_text_field_unittest.mm.
-
class AutocompleteTextFieldCellTest : public testing::Test {
public:
AutocompleteTextFieldCellTest() {
- NSRect frame = NSMakeRect(0, 0, 50, 30);
+ // Make sure this is wide enough to play games with the cell
+ // decorations.
+ NSRect frame = NSMakeRect(0, 0, 300, 30);
view_.reset([[NSTextField alloc] initWithFrame:frame]);
scoped_nsobject<AutocompleteTextFieldCell> cell(
[[AutocompleteTextFieldCell alloc] initTextCell:@"Testing"]);
@@ -43,6 +39,213 @@
// Test drawing, mostly to ensure nothing leaks or crashes.
TEST_F(AutocompleteTextFieldCellTest, Display) {
[view_ display];
+
+ // Test display of various cell configurations.
+ AutocompleteTextFieldCell* cell =
+ static_cast<AutocompleteTextFieldCell*>([view_ cell]);
+
+ [cell setSearchHintString:@"Type to search"];
+ [view_ display];
+
+ NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
+ [cell setKeywordHintPrefix:@"prefix" image:image suffix:@"suffix"];
+ [view_ display];
+
+ [cell setKeywordString:@"Search Engine:"];
+ [view_ display];
}
+TEST_F(AutocompleteTextFieldCellTest, SearchHint) {
+ AutocompleteTextFieldCell* cell =
+ static_cast<AutocompleteTextFieldCell*>([view_ cell]);
+
+ // At default settings, everything is already good to go.
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Setting a search hint will need a reset.
+ [cell setSearchHintString:@"Type to search"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing the search hint needs a reset.
+ [cell setSearchHintString:@"Type to find"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing to an identical string doesn't need a reset.
+ [cell setSearchHintString:@"Type to find"];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+}
+
+TEST_F(AutocompleteTextFieldCellTest, KeywordHint) {
+ AutocompleteTextFieldCell* cell =
+ static_cast<AutocompleteTextFieldCell*>([view_ cell]);
+ NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
+
+ // At default settings, everything is already good to go.
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Setting a keyword hint will need a reset.
+ [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing the keyword hint needs a reset.
+ [cell setKeywordHintPrefix:@"Type " image:image suffix:@" to search Engine"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing to identical strings doesn't need a reset.
+ [cell setKeywordHintPrefix:@"Type " image:image suffix:@" to search Engine"];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+}
+
+TEST_F(AutocompleteTextFieldCellTest, KeywordString) {
+ AutocompleteTextFieldCell* cell =
+ static_cast<AutocompleteTextFieldCell*>([view_ cell]);
+
+ // At default settings, everything is already good to go.
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Setting a keyword string will need a reset.
+ [cell setKeywordString:@"Search Engine:"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing the keyword string needs a reset.
+ [cell setKeywordString:@"Search on Engine:"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing to an identical string doesn't need a reset.
+ [cell setKeywordString:@"Search on Engine:"];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+}
+
+// Test that transitions between various modes set the reset flag.
+TEST_F(AutocompleteTextFieldCellTest, Transitions) {
+ AutocompleteTextFieldCell* cell =
+ static_cast<AutocompleteTextFieldCell*>([view_ cell]);
+ NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
+
+ // Transitions from hint to keyword string, keyword hint, and
+ // cleared.
+ [cell setSearchHintString:@"Type to search"];
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ [cell setKeywordString:@"Search Engine:"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+
+ [cell setSearchHintString:@"Type to search"];
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+
+ [cell setSearchHintString:@"Type to search"];
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ [cell clearKeywordAndHint];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+
+ // Transitions from keyword hint to keyword string, simple hint, and
+ // cleared.
+ [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"];
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ [cell setSearchHintString:@"Type to search"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+
+ [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"];
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ [cell setKeywordString:@"Search Engine:"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+
+ [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"];
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ [cell clearKeywordAndHint];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+
+ // Transitions from keyword string to either type of hint, or
+ // cleared.
+ [cell setKeywordString:@"Search on Engine:"];
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ [cell setSearchHintString:@"Type to search"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+
+ [cell setKeywordString:@"Search on Engine:"];
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+
+ [cell setKeywordString:@"Search on Engine:"];
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ [cell clearKeywordAndHint];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+}
+
+TEST_F(AutocompleteTextFieldCellTest, TextFrame) {
+ AutocompleteTextFieldCell* cell =
+ static_cast<AutocompleteTextFieldCell*>([view_ cell]);
+ const NSRect bounds([view_ bounds]);
+ NSRect textFrame;
+
+ // At default settings, everything goes to the text area.
+ textFrame = [cell textFrameForFrame:bounds];
+ EXPECT_FALSE(NSIsEmptyRect(textFrame));
+ EXPECT_TRUE(NSContainsRect(bounds, textFrame));
+ EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame));
+ EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
+
+ // Small search hint leaves text frame to left.
+ [cell setSearchHintString:@"Search hint"];
+ textFrame = [cell textFrameForFrame:bounds];
+ EXPECT_FALSE(NSIsEmptyRect(textFrame));
+ EXPECT_TRUE(NSContainsRect(bounds, textFrame));
+ EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds));
+
+ // Save search-hint's frame for future reference.
+ const CGFloat searchHintMaxX(NSMaxX(textFrame));
+
+ // Keyword hint also leaves text to left. Arrange for it to be
+ // larger than the search hint just to make sure that things have
+ // changed (keyword hint overrode search hint), and that they aren't
+ // handled identically w/out reference to the actual button cell.
+ NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
+ [cell setKeywordHintPrefix:@"Keyword " image:image suffix:@" hint"];
+ textFrame = [cell textFrameForFrame:bounds];
+ EXPECT_FALSE(NSIsEmptyRect(textFrame));
+ EXPECT_TRUE(NSContainsRect(bounds, textFrame));
+ EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds));
+ EXPECT_LT(NSMaxX(textFrame), searchHintMaxX);
+
+ // Keyword search leaves text area to right.
+ [cell setKeywordString:@"Search Engine:"];
+ textFrame = [cell textFrameForFrame:bounds];
+ EXPECT_FALSE(NSIsEmptyRect(textFrame));
+ EXPECT_TRUE(NSContainsRect(bounds, textFrame));
+ EXPECT_GT(NSMinX(textFrame), NSMinX(bounds));
+ EXPECT_LT(NSMinX(textFrame), searchHintMaxX);
+ EXPECT_GT(NSMaxX(textFrame), searchHintMaxX);
+
+ // Text frame should take everything over again on reset.
+ [cell clearKeywordAndHint];
+ textFrame = [cell textFrameForFrame:bounds];
+ EXPECT_FALSE(NSIsEmptyRect(textFrame));
+ EXPECT_TRUE(NSContainsRect(bounds, textFrame));
+ EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame));
+ EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
+}
+
} // namespace
Property changes on: chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
___________________________________________________________________
Name: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_cell.mm ('k') | chrome/browser/cocoa/autocomplete_text_field_editor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698