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

Side by Side Diff: views/controls/textfield/textfield_views_model_unittest.cc

Issue 6314012: Make uneditable when readonly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/textfield/textfield_views_model.cc ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/clipboard/clipboard.h" 10 #include "ui/base/clipboard/clipboard.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 EXPECT_STR_EQ("EL", model.GetSelectedText()); 97 EXPECT_STR_EQ("EL", model.GetSelectedText());
98 98
99 model.MoveCursorToStart(true); 99 model.MoveCursorToStart(true);
100 EXPECT_STR_EQ("H", model.GetSelectedText()); 100 EXPECT_STR_EQ("H", model.GetSelectedText());
101 model.MoveCursorToEnd(true); 101 model.MoveCursorToEnd(true);
102 EXPECT_STR_EQ("ELLO", model.GetSelectedText()); 102 EXPECT_STR_EQ("ELLO", model.GetSelectedText());
103 model.ClearSelection(); 103 model.ClearSelection();
104 EXPECT_EQ(string16(), model.GetSelectedText()); 104 EXPECT_EQ(string16(), model.GetSelectedText());
105 model.SelectAll(); 105 model.SelectAll();
106 EXPECT_STR_EQ("HELLO", model.GetSelectedText()); 106 EXPECT_STR_EQ("HELLO", model.GetSelectedText());
107 // SelectAll should select towards the end.
108 TextRange range;
109 model.GetSelectedRange(&range);
110 EXPECT_EQ(0U, range.start());
111 EXPECT_EQ(5U, range.end());
107 112
108 // Select and move cursor 113 // Select and move cursor
109 model.MoveCursorTo(1U, false); 114 model.MoveCursorTo(1U, false);
110 model.MoveCursorTo(3U, true); 115 model.MoveCursorTo(3U, true);
111 EXPECT_STR_EQ("EL", model.GetSelectedText()); 116 EXPECT_STR_EQ("EL", model.GetSelectedText());
112 model.MoveCursorLeft(false); 117 model.MoveCursorLeft(false);
113 EXPECT_EQ(1U, model.cursor_pos()); 118 EXPECT_EQ(1U, model.cursor_pos());
114 model.MoveCursorTo(1U, false); 119 model.MoveCursorTo(1U, false);
115 model.MoveCursorTo(3U, true); 120 model.MoveCursorTo(3U, true);
116 model.MoveCursorRight(false); 121 model.MoveCursorRight(false);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 EXPECT_STR_EQ("*****", model.GetVisibleText()); 166 EXPECT_STR_EQ("*****", model.GetVisibleText());
162 EXPECT_STR_EQ("HELLO", model.text()); 167 EXPECT_STR_EQ("HELLO", model.text());
163 EXPECT_TRUE(model.Delete()); 168 EXPECT_TRUE(model.Delete());
164 169
165 EXPECT_STR_EQ("****", model.GetVisibleText()); 170 EXPECT_STR_EQ("****", model.GetVisibleText());
166 EXPECT_STR_EQ("ELLO", model.text()); 171 EXPECT_STR_EQ("ELLO", model.text());
167 EXPECT_EQ(0U, model.cursor_pos()); 172 EXPECT_EQ(0U, model.cursor_pos());
168 173
169 model.SelectAll(); 174 model.SelectAll();
170 EXPECT_STR_EQ("ELLO", model.GetSelectedText()); 175 EXPECT_STR_EQ("ELLO", model.GetSelectedText());
171 EXPECT_EQ(0U, model.cursor_pos()); 176 EXPECT_EQ(4U, model.cursor_pos());
172 177
173 model.Insert('X'); 178 model.Insert('X');
174 EXPECT_STR_EQ("*", model.GetVisibleText()); 179 EXPECT_STR_EQ("*", model.GetVisibleText());
175 EXPECT_STR_EQ("X", model.text()); 180 EXPECT_STR_EQ("X", model.text());
176 } 181 }
177 182
178 TEST_F(TextfieldViewsModelTest, Word) { 183 TEST_F(TextfieldViewsModelTest, Word) {
179 TextfieldViewsModel model; 184 TextfieldViewsModel model;
180 model.Append( 185 model.Append(
181 ASCIIToUTF16("The answer to Life, the Universe, and Everything")); 186 ASCIIToUTF16("The answer to Life, the Universe, and Everything"));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 286
282 TEST_F(TextfieldViewsModelTest, SetText) { 287 TEST_F(TextfieldViewsModelTest, SetText) {
283 TextfieldViewsModel model; 288 TextfieldViewsModel model;
284 model.Append(ASCIIToUTF16("HELLO")); 289 model.Append(ASCIIToUTF16("HELLO"));
285 model.MoveCursorToEnd(false); 290 model.MoveCursorToEnd(false);
286 model.SetText(ASCIIToUTF16("GOODBYE")); 291 model.SetText(ASCIIToUTF16("GOODBYE"));
287 EXPECT_STR_EQ("GOODBYE", model.text()); 292 EXPECT_STR_EQ("GOODBYE", model.text());
288 EXPECT_EQ(5U, model.cursor_pos()); 293 EXPECT_EQ(5U, model.cursor_pos());
289 model.SelectAll(); 294 model.SelectAll();
290 EXPECT_STR_EQ("GOODBYE", model.GetSelectedText()); 295 EXPECT_STR_EQ("GOODBYE", model.GetSelectedText());
291 // Selection move the current pos to the begining. 296 // Selection move the current pos to the end.
297 EXPECT_EQ(7U, model.cursor_pos());
298 model.MoveCursorToStart(false);
292 EXPECT_EQ(0U, model.cursor_pos()); 299 EXPECT_EQ(0U, model.cursor_pos());
293 model.MoveCursorToEnd(false); 300 model.MoveCursorToEnd(false);
294 EXPECT_EQ(7U, model.cursor_pos());
295 301
296 model.SetText(ASCIIToUTF16("BYE")); 302 model.SetText(ASCIIToUTF16("BYE"));
297 EXPECT_EQ(3U, model.cursor_pos()); 303 EXPECT_EQ(3U, model.cursor_pos());
298 EXPECT_EQ(string16(), model.GetSelectedText()); 304 EXPECT_EQ(string16(), model.GetSelectedText());
299 model.SetText(ASCIIToUTF16("")); 305 model.SetText(ASCIIToUTF16(""));
300 EXPECT_EQ(0U, model.cursor_pos()); 306 EXPECT_EQ(0U, model.cursor_pos());
301 } 307 }
302 308
303 TEST_F(TextfieldViewsModelTest, Clipboard) { 309 TEST_F(TextfieldViewsModelTest, Clipboard) {
304 scoped_ptr<TestViewsDelegate> test_views_delegate(new TestViewsDelegate()); 310 scoped_ptr<TestViewsDelegate> test_views_delegate(new TestViewsDelegate());
(...skipping 30 matching lines...) Expand all
335 EXPECT_STR_EQ("HELLO ", model.text()); 341 EXPECT_STR_EQ("HELLO ", model.text());
336 EXPECT_EQ(6U, model.cursor_pos()); 342 EXPECT_EQ(6U, model.cursor_pos());
337 343
338 // Test for copy: Non-empty selection. 344 // Test for copy: Non-empty selection.
339 model.Append(ASCIIToUTF16("HELLO WORLD")); 345 model.Append(ASCIIToUTF16("HELLO WORLD"));
340 model.SelectAll(); 346 model.SelectAll();
341 model.Copy(); 347 model.Copy();
342 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); 348 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
343 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); 349 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
344 EXPECT_STR_EQ("HELLO HELLO WORLD", model.text()); 350 EXPECT_STR_EQ("HELLO HELLO WORLD", model.text());
345 EXPECT_EQ(0U, model.cursor_pos()); 351 EXPECT_EQ(17U, model.cursor_pos());
346 352
347 // Test for paste. 353 // Test for paste.
348 model.ClearSelection(); 354 model.ClearSelection();
349 model.MoveCursorToEnd(false); 355 model.MoveCursorToEnd(false);
350 model.MoveCursorToPreviousWord(true); 356 model.MoveCursorToPreviousWord(true);
351 EXPECT_TRUE(model.Paste()); 357 EXPECT_TRUE(model.Paste());
352 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); 358 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
353 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); 359 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
354 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.text()); 360 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.text());
355 EXPECT_EQ(29U, model.cursor_pos()); 361 EXPECT_EQ(29U, model.cursor_pos());
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 model.SelectRange(range); 464 model.SelectRange(range);
459 EXPECT_TRUE(model.GetSelectedText().empty()); 465 EXPECT_TRUE(model.GetSelectedText().empty());
460 466
461 range.SetRange(1000, 1000); 467 range.SetRange(1000, 1000);
462 EXPECT_TRUE(range.is_empty()); 468 EXPECT_TRUE(range.is_empty());
463 model.SelectRange(range); 469 model.SelectRange(range);
464 EXPECT_TRUE(model.GetSelectedText().empty()); 470 EXPECT_TRUE(model.GetSelectedText().empty());
465 } 471 }
466 472
467 } // namespace views 473 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield_views_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698