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

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

Issue 10916214: Try 2 - 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: Moved to BrowserThreadsStarted 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 16 matching lines...) Expand all
27 #include "ui/base/ui_base_switches.h" 27 #include "ui/base/ui_base_switches.h"
28 #include "ui/gfx/render_text.h" 28 #include "ui/gfx/render_text.h"
29 #include "ui/views/controls/textfield/native_textfield_views.h" 29 #include "ui/views/controls/textfield/native_textfield_views.h"
30 #include "ui/views/controls/textfield/textfield.h" 30 #include "ui/views/controls/textfield/textfield.h"
31 #include "ui/views/controls/textfield/textfield_controller.h" 31 #include "ui/views/controls/textfield/textfield_controller.h"
32 #include "ui/views/controls/textfield/textfield_views_model.h" 32 #include "ui/views/controls/textfield/textfield_views_model.h"
33 #include "ui/views/focus/focus_manager.h" 33 #include "ui/views/focus/focus_manager.h"
34 #include "ui/views/ime/mock_input_method.h" 34 #include "ui/views/ime/mock_input_method.h"
35 #include "ui/views/test/test_views_delegate.h" 35 #include "ui/views/test/test_views_delegate.h"
36 #include "ui/views/test/views_test_base.h" 36 #include "ui/views/test/views_test_base.h"
37 #include "ui/views/views_delegate.h"
38 #include "ui/views/widget/native_widget_private.h" 37 #include "ui/views/widget/native_widget_private.h"
39 #include "ui/views/widget/widget.h" 38 #include "ui/views/widget/widget.h"
40 39
41 namespace { 40 namespace {
42 41
43 // A wrapper of Textfield to intercept the result of OnKeyPressed() and 42 // A wrapper of Textfield to intercept the result of OnKeyPressed() and
44 // OnKeyReleased() methods. 43 // OnKeyReleased() methods.
45 class TestTextfield : public views::Textfield { 44 class TestTextfield : public views::Textfield {
46 public: 45 public:
47 explicit TestTextfield(StyleFlags style) 46 explicit TestTextfield(StyleFlags style)
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 SendKeyEvent(code); 227 SendKeyEvent(code);
229 } else { 228 } else {
230 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0); 229 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0);
231 event.set_character(ch); 230 event.set_character(ch);
232 input_method_->DispatchKeyEvent(event); 231 input_method_->DispatchKeyEvent(event);
233 } 232 }
234 } 233 }
235 234
236 string16 GetClipboardText() const { 235 string16 GetClipboardText() const {
237 string16 text; 236 string16 text;
238 views::ViewsDelegate::views_delegate->GetClipboard()-> 237 ui::Clipboard::GetForCurrentThread()->
239 ReadText(ui::Clipboard::BUFFER_STANDARD, &text); 238 ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
240 return text; 239 return text;
241 } 240 }
242 241
243 void SetClipboardText(const std::string& text) { 242 void SetClipboardText(const std::string& text) {
244 ui::ScopedClipboardWriter clipboard_writer( 243 ui::ScopedClipboardWriter clipboard_writer(
245 views::ViewsDelegate::views_delegate->GetClipboard(), 244 ui::Clipboard::GetForCurrentThread(),
246 ui::Clipboard::BUFFER_STANDARD); 245 ui::Clipboard::BUFFER_STANDARD);
247 clipboard_writer.WriteText(ASCIIToUTF16(text)); 246 clipboard_writer.WriteText(ASCIIToUTF16(text));
248 } 247 }
249 248
250 View* GetFocusedView() { 249 View* GetFocusedView() {
251 return widget_->GetFocusManager()->GetFocusedView(); 250 return widget_->GetFocusManager()->GetFocusedView();
252 } 251 }
253 252
254 int GetCursorPositionX(int cursor_pos) { 253 int GetCursorPositionX(int cursor_pos) {
255 gfx::RenderText* render_text = textfield_view_->GetRenderText(); 254 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()); 1095 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText());
1097 1096
1098 // CUT&PASTE does not work, but COPY works 1097 // CUT&PASTE does not work, but COPY works
1099 SetClipboardText("Test"); 1098 SetClipboardText("Test");
1100 SendKeyEvent(ui::VKEY_X, false, true); 1099 SendKeyEvent(ui::VKEY_X, false, true);
1101 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); 1100 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText());
1102 string16 str(GetClipboardText()); 1101 string16 str(GetClipboardText());
1103 EXPECT_STR_NE(" one two three ", str); 1102 EXPECT_STR_NE(" one two three ", str);
1104 1103
1105 SendKeyEvent(ui::VKEY_C, false, true); 1104 SendKeyEvent(ui::VKEY_C, false, true);
1106 views::ViewsDelegate::views_delegate->GetClipboard()-> 1105 ui::Clipboard::GetForCurrentThread()->
1107 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); 1106 ReadText(ui::Clipboard::BUFFER_STANDARD, &str);
1108 EXPECT_STR_EQ(" one two three ", str); 1107 EXPECT_STR_EQ(" one two three ", str);
1109 1108
1110 // SetText should work even in read only mode. 1109 // SetText should work even in read only mode.
1111 textfield_->SetText(ASCIIToUTF16(" four five six ")); 1110 textfield_->SetText(ASCIIToUTF16(" four five six "));
1112 EXPECT_STR_EQ(" four five six ", textfield_->text()); 1111 EXPECT_STR_EQ(" four five six ", textfield_->text());
1113 1112
1114 // Paste shouldn't work. 1113 // Paste shouldn't work.
1115 SendKeyEvent(ui::VKEY_V, false, true); 1114 SendKeyEvent(ui::VKEY_V, false, true);
1116 EXPECT_STR_EQ(" four five six ", textfield_->text()); 1115 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; 1677 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i;
1679 } 1678 }
1680 1679
1681 // Return false if the index is out of range. 1680 // Return false if the index is out of range.
1682 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); 1681 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect));
1683 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); 1682 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect));
1684 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); 1683 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect));
1685 } 1684 }
1686 1685
1687 } // namespace views 1686 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/native_textfield_views.cc ('k') | ui/views/controls/textfield/native_textfield_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698