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

Side by Side Diff: ui/views/controls/textfield/native_textfield_views_unittest.cc

Issue 10911074: Change how ui::Clipboard is accessed so there's only one per thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix various windows compile failures. Created 8 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 SendKeyEvent(code); 228 SendKeyEvent(code);
229 } else { 229 } else {
230 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0); 230 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0);
231 event.set_character(ch); 231 event.set_character(ch);
232 input_method_->DispatchKeyEvent(event); 232 input_method_->DispatchKeyEvent(event);
233 } 233 }
234 } 234 }
235 235
236 string16 GetClipboardText() const { 236 string16 GetClipboardText() const {
237 string16 text; 237 string16 text;
238 views::ViewsDelegate::views_delegate->GetClipboard()-> 238 ui::Clipboard::GetForCurrentThread()->
239 ReadText(ui::Clipboard::BUFFER_STANDARD, &text); 239 ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
240 return text; 240 return text;
241 } 241 }
242 242
243 void SetClipboardText(const std::string& text) { 243 void SetClipboardText(const std::string& text) {
244 ui::ScopedClipboardWriter clipboard_writer( 244 ui::ScopedClipboardWriter clipboard_writer(
245 views::ViewsDelegate::views_delegate->GetClipboard(), 245 ui::Clipboard::GetForCurrentThread(),
246 ui::Clipboard::BUFFER_STANDARD); 246 ui::Clipboard::BUFFER_STANDARD);
247 clipboard_writer.WriteText(ASCIIToUTF16(text)); 247 clipboard_writer.WriteText(ASCIIToUTF16(text));
248 } 248 }
249 249
250 View* GetFocusedView() { 250 View* GetFocusedView() {
251 return widget_->GetFocusManager()->GetFocusedView(); 251 return widget_->GetFocusManager()->GetFocusedView();
252 } 252 }
253 253
254 int GetCursorPositionX(int cursor_pos) { 254 int GetCursorPositionX(int cursor_pos) {
255 gfx::RenderText* render_text = textfield_view_->GetRenderText(); 255 gfx::RenderText* render_text = textfield_view_->GetRenderText();
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); 1096 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText());
1097 1097
1098 // CUT&PASTE does not work, but COPY works 1098 // CUT&PASTE does not work, but COPY works
1099 SetClipboardText("Test"); 1099 SetClipboardText("Test");
1100 SendKeyEvent(ui::VKEY_X, false, true); 1100 SendKeyEvent(ui::VKEY_X, false, true);
1101 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); 1101 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText());
1102 string16 str(GetClipboardText()); 1102 string16 str(GetClipboardText());
1103 EXPECT_STR_NE(" one two three ", str); 1103 EXPECT_STR_NE(" one two three ", str);
1104 1104
1105 SendKeyEvent(ui::VKEY_C, false, true); 1105 SendKeyEvent(ui::VKEY_C, false, true);
1106 views::ViewsDelegate::views_delegate->GetClipboard()-> 1106 ui::Clipboard::GetForCurrentThread()->
1107 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); 1107 ReadText(ui::Clipboard::BUFFER_STANDARD, &str);
1108 EXPECT_STR_EQ(" one two three ", str); 1108 EXPECT_STR_EQ(" one two three ", str);
1109 1109
1110 // SetText should work even in read only mode. 1110 // SetText should work even in read only mode.
1111 textfield_->SetText(ASCIIToUTF16(" four five six ")); 1111 textfield_->SetText(ASCIIToUTF16(" four five six "));
1112 EXPECT_STR_EQ(" four five six ", textfield_->text()); 1112 EXPECT_STR_EQ(" four five six ", textfield_->text());
1113 1113
1114 // Paste shouldn't work. 1114 // Paste shouldn't work.
1115 SendKeyEvent(ui::VKEY_V, false, true); 1115 SendKeyEvent(ui::VKEY_V, false, true);
1116 EXPECT_STR_EQ(" four five six ", textfield_->text()); 1116 EXPECT_STR_EQ(" four five six ", textfield_->text());
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i; 1678 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i;
1679 } 1679 }
1680 1680
1681 // Return false if the index is out of range. 1681 // Return false if the index is out of range.
1682 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); 1682 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect));
1683 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); 1683 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect));
1684 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); 1684 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect));
1685 } 1685 }
1686 1686
1687 } // namespace views 1687 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698