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

Side by Side Diff: chrome/browser/cocoa/autocomplete_text_field_unittest.mm

Issue 337027: [Mac] Adjust Omnibox implementation to not break undo chain. (Closed)
Patch Set: Tweak a comment Created 11 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "base/cocoa_protocols_mac.h" 7 #import "base/cocoa_protocols_mac.h"
8 #include "base/scoped_nsobject.h" 8 #include "base/scoped_nsobject.h"
9 #import "chrome/browser/cocoa/autocomplete_text_field.h" 9 #import "chrome/browser/cocoa/autocomplete_text_field.h"
10 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" 10 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 scoped_nsobject<NSImage> hintIcon( 571 scoped_nsobject<NSImage> hintIcon(
572 [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]); 572 [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]);
573 [cell setHintIcon:hintIcon.get() label:nil color:nil]; 573 [cell setHintIcon:hintIcon.get() label:nil color:nil];
574 NSRect iconFrame([cell hintImageFrameForFrame:[field_ bounds]]); 574 NSRect iconFrame([cell hintImageFrameForFrame:[field_ bounds]]);
575 NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame))); 575 NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)));
576 NSEvent* event(Event(field_, location, NSLeftMouseDown, 1)); 576 NSEvent* event(Event(field_, location, NSLeftMouseDown, 1));
577 EXPECT_CALL(field_observer_, OnSecurityIconClicked()); 577 EXPECT_CALL(field_observer_, OnSecurityIconClicked());
578 [field_ mouseDown:event]; 578 [field_ mouseDown:event];
579 } 579 }
580 580
581 // Verify that -setAttributedStringValue: works as expected when
582 // focussed or when not focussed. Our code mostly depends on about
583 // whether -stringValue works right.
584 TEST_F(AutocompleteTextFieldTest, SetAttributedStringBaseline) {
585 EXPECT_EQ(nil, [field_ currentEditor]);
586
587 // So that we can set rich text.
588 [field_ setAllowsEditingTextAttributes:YES];
589
590 // Set an attribute different from the field's default so we can
591 // tell we got the same string out as we put in.
592 NSFont* font = [NSFont fontWithDescriptor:[[field_ font] fontDescriptor]
593 size:[[field_ font] pointSize] + 2];
594 NSDictionary* attributes =
595 [NSDictionary dictionaryWithObject:font
596 forKey:NSFontAttributeName];
597 static const NSString* kString = @"This is a test";
598 scoped_nsobject<NSAttributedString> attributedString(
599 [[NSAttributedString alloc] initWithString:kString
600 attributes:attributes]);
601
602 // Check that what we get back looks like what we put in.
603 EXPECT_FALSE([[field_ stringValue] isEqualToString:kString]);
604 [field_ setAttributedStringValue:attributedString];
605 EXPECT_TRUE([[field_ attributedStringValue]
606 isEqualToAttributedString:attributedString]);
607 EXPECT_TRUE([[field_ stringValue] isEqualToString:kString]);
608
609 // Try that again with focus.
610 cocoa_helper_.makeFirstResponder(field_);
611 EXPECT_TRUE([field_ currentEditor]);
612
613 // Check that what we get back looks like what we put in.
614 [field_ setStringValue:@""];
615 EXPECT_FALSE([[field_ stringValue] isEqualToString:kString]);
616 [field_ setAttributedStringValue:attributedString];
617 EXPECT_TRUE([[field_ attributedStringValue]
618 isEqualToAttributedString:attributedString]);
619 EXPECT_TRUE([[field_ stringValue] isEqualToString:kString]);
620 }
621
622 // -setAttributedStringValue: shouldn't reset the undo state if things
623 // are being editted.
624 TEST_F(AutocompleteTextFieldTest, SetAttributedStringUndo) {
625 NSColor* redColor = [NSColor redColor];
626 NSDictionary* attributes =
627 [NSDictionary dictionaryWithObject:redColor
628 forKey:NSForegroundColorAttributeName];
629 static const NSString* kString = @"This is a test";
630 scoped_nsobject<NSAttributedString> attributedString(
631 [[NSAttributedString alloc] initWithString:kString
632 attributes:attributes]);
633
634 cocoa_helper_.makeFirstResponder(field_);
635 EXPECT_TRUE([field_ currentEditor]);
636 NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]);
637 NSUndoManager* undoManager = [editor undoManager];
638 EXPECT_TRUE(undoManager);
639
640 // Nothing to undo, yet.
641 EXPECT_FALSE([undoManager canUndo]);
642
643 // Starting an editing action creates an undoable item.
644 [editor shouldChangeTextInRange:NSMakeRange(0, 0) replacementString:@""];
645 [editor didChangeText];
646 EXPECT_TRUE([undoManager canUndo]);
647
648 // -setStringValue: resets the editor's undo chain.
649 [field_ setStringValue:kString];
650 EXPECT_FALSE([undoManager canUndo]);
651
652 // Verify that -setAttributedStringValue: does not reset the
653 // editor's undo chain.
654 [field_ setStringValue:@""];
655 [editor shouldChangeTextInRange:NSMakeRange(0, 0) replacementString:@""];
656 [editor didChangeText];
657 EXPECT_TRUE([undoManager canUndo]);
658 [field_ setAttributedStringValue:attributedString];
659 EXPECT_TRUE([undoManager canUndo]);
660 }
661
581 } // namespace 662 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698