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

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

Issue 155790: Properly collapse newlines (and leading/trailing whitespace) from pasted... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 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
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_editor.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
===================================================================
--- chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm (revision 21067)
+++ chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm (working copy)
@@ -7,10 +7,12 @@
#include "base/scoped_nsobject.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
+#include "base/sys_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace {
+
int NumTypesOnPasteboard(NSPasteboard* pb) {
return [[pb types] count];
}
@@ -30,6 +32,10 @@
return [clipboard_text isEqualToString:cmp];
}
+bool PutStringOnPasteboard(NSPasteboard* pb, NSString* string) {
+ return ([pb setString:string forType:NSStringPboardType] != NO);
+}
+
} // namespace
class AutocompleteTextFieldEditorTest : public PlatformTest {
@@ -86,3 +92,41 @@
ASSERT_TRUE(ClipboardContainsText(clipboard(), test_string_2));
ASSERT_EQ([[field_editor.get() textStorage] length], 0U);
}
+
+TEST_F(AutocompleteTextFieldEditorTest, PasteTest) {
+ const int num_tests = 5;
+ NSString *test_string_input[num_tests] = {
+ @"Has_no_spaces",
+ @"Has spaces inside",
+ @" \t Has leading whitespace",
+ @"Has trailing whitespace \t ",
+ @"\rHas s\n cat\rtered new \nlines and spaces\n\n\r"
+ };
+
+ // Clear the pasteboard is empty and double-check.
+ NSPasteboard* pb = clipboard();
+ ClearPasteboard(pb);
+ ASSERT_EQ(NumTypesOnPasteboard(pb), 0);
+
+ // Set up the pasteboard to take strings.
+ [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
+
+ for(int i = 0; i < num_tests; i++) {
+ // Make a field editor and make sure it's empty.
+ scoped_nsobject<AutocompleteTextFieldEditor> field_editor(
+ [[AutocompleteTextFieldEditor alloc] init]);
+ ASSERT_EQ([[field_editor.get() textStorage] length], 0U);
+
+ // Put test_string_input[i] on pasteboard and make sure it's there.
+ ASSERT_TRUE(PutStringOnPasteboard(pb, test_string_input[i]));
+ ASSERT_TRUE(ClipboardContainsText(pb, test_string_input[i]));
+
+ // Paste and make sure we get the corresponding output from
+ // CollapseWhitespace(...,true). CollapseWhitespace() should be tested
+ // elsewhere and should yield the desired output.
+ [field_editor.get() performPaste:pb];
+ EXPECT_EQ(
+ CollapseWhitespace(base::SysNSStringToWide(test_string_input[i]),true),
+ base::SysNSStringToWide([[field_editor.get() textStorage] string]));
+ }
+}
Property changes on: chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
___________________________________________________________________
Name: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_editor.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698