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

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

Issue 295036: [Mac] Simplify field editor code which tracks whether editor rect changed. (Closed)
Patch Set: Pinks comments. Created 11 years, 2 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
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
index 7908094861ab7dc4eaa323862210961d2a663846..c56054c9a8be43fe17831026fbe753602fdfab1e 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
@@ -73,227 +73,41 @@ TEST_F(AutocompleteTextFieldCellTest, Display) {
[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" availableWidth:kWidth];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-
- // Changing the search hint needs a reset.
- [cell setSearchHintString:@"Type to find" availableWidth:kWidth];
- 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" availableWidth:kWidth];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-}
-
-TEST_F(AutocompleteTextFieldCellTest, KeywordHint) {
+// Verify that transitions between states clear other states.
+TEST_F(AutocompleteTextFieldCellTest, StateTransitionsResetOthers) {
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"
- availableWidth:kWidth];
- 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"
- availableWidth:kWidth];
- 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"
- availableWidth:kWidth];
- 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:"
- partialString:@"Search Eng:"
- availableWidth:kWidth];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-
- // Changing the keyword string needs a reset.
- [cell setKeywordString:@"Search on Engine:"
- partialString:@"Search Eng:"
- availableWidth:kWidth];
- 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:"
- partialString:@"Search Eng:"
- availableWidth:kWidth];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-}
-
-TEST_F(AutocompleteTextFieldCellTest, SecurityIcon) {
- AutocompleteTextFieldCell* cell =
- static_cast<AutocompleteTextFieldCell*>([view_ cell]);
-
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-
- NSImage* image1 = [NSImage imageNamed:@"NSApplicationIcon"];
- // Setting a security icon will need a reset.
- [cell setHintIcon:image1 label:nil color:nil];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-
- // Changing the security icon needs a reset.
- NSImage* image2 = [NSImage imageNamed:@"NSComputer"];
- [cell setHintIcon:image2 label:nil color:nil];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-
- // Changing to an identical security icon doesn't need a reset.
- [cell setHintIcon:image2 label:nil color:nil];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-
- // Adding a label without changing the icon needs a reset.
- NSColor *color = [NSColor blackColor];
- [cell setHintIcon:image2 label:@"New Label" color:color];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
-
- // Removing the label without changing the icon needs a reset.
- [cell setHintIcon:image2 label:nil color:nil];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
-}
-
-TEST_F(AutocompleteTextFieldCellTest, SecurityIconLabel) {
- AutocompleteTextFieldCell* cell =
- static_cast<AutocompleteTextFieldCell*>([view_ cell]);
- NSColor *color = [NSColor blackColor];
-
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-
- NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
- // Setting a security icon will need a reset.
- [cell setHintIcon:image label:@"Hello, world" color:color];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-
- // Changing the label needs a reset.
- [cell setHintIcon:image label:@"Hello, you" color:color];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
-
- // Changing to an identical label doesn't need a reset
- [cell setHintIcon:image label:@"Hello, you" color:color];
- 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" availableWidth:kWidth];
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
- [cell setKeywordString:@"Search Engine:"
- partialString:@"Search Eng:"
- availableWidth:kWidth];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
-
- [cell setSearchHintString:@"Type to search" availableWidth:kWidth];
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
- [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"
- availableWidth:kWidth];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
-
- [cell setSearchHintString:@"Type to search" availableWidth:kWidth];
- [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"
- availableWidth:kWidth];
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ // Setting hint leaves keyword empty.
[cell setSearchHintString:@"Type to search" availableWidth:kWidth];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ EXPECT_TRUE([cell hintString]);
+ EXPECT_FALSE([cell keywordString]);
- [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"
- availableWidth:kWidth];
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ // Setting keyword clears hint.
[cell setKeywordString:@"Search Engine:"
partialString:@"Search Eng:"
availableWidth:kWidth];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ EXPECT_FALSE([cell hintString]);
+ EXPECT_TRUE([cell keywordString]);
+ // Setting hint clears keyword.
[cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"
availableWidth:kWidth];
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ EXPECT_TRUE([cell hintString]);
+ EXPECT_FALSE([cell keywordString]);
+
+ // Clear clears keyword.
[cell clearKeywordAndHint];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ EXPECT_FALSE([cell hintString]);
+ EXPECT_FALSE([cell keywordString]);
- // Transitions from keyword string to either type of hint, or
- // cleared.
- [cell setKeywordString:@"Search on Engine:"
- partialString:@"Search Eng:"
- availableWidth:kWidth];
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ // Clear clears hint.
[cell setSearchHintString:@"Type to search" availableWidth:kWidth];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
-
- [cell setKeywordString:@"Search on Engine:"
- partialString:@"Search Eng:"
- availableWidth:kWidth];
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
- [cell setKeywordHintPrefix:@"Press " image:image suffix:@" to search Engine"
- availableWidth:kWidth];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
-
- [cell setKeywordString:@"Search on Engine:"
- partialString:@"Search Eng:"
- availableWidth:kWidth];
- [cell setFieldEditorNeedsReset:NO];
- EXPECT_FALSE([cell fieldEditorNeedsReset]);
+ EXPECT_TRUE([cell hintString]);
[cell clearKeywordAndHint];
- EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ EXPECT_FALSE([cell hintString]);
+ EXPECT_FALSE([cell keywordString]);
}
TEST_F(AutocompleteTextFieldCellTest, TextFrame) {
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_cell.mm ('k') | chrome/browser/cocoa/autocomplete_text_field_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698