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

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

Issue 6267002: Implement double/triple click functionality in views textfield. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: minor refactoring 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
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/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/base/clipboard/clipboard.h" 9 #include "ui/base/clipboard/clipboard.h"
10 #include "ui/base/keycodes/keyboard_codes.h" 10 #include "ui/base/keycodes/keyboard_codes.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 DCHECK(textfield_view_); 93 DCHECK(textfield_view_);
94 model_ = textfield_view_->model_.get(); 94 model_ = textfield_view_->model_.get();
95 } 95 }
96 96
97 views::Menu2* GetContextMenu() { 97 views::Menu2* GetContextMenu() {
98 textfield_view_->InitContextMenuIfRequired(); 98 textfield_view_->InitContextMenuIfRequired();
99 return textfield_view_->context_menu_menu_.get(); 99 return textfield_view_->context_menu_menu_.get();
100 } 100 }
101 101
102 bool IsTrackingTripleClick() {
103 return textfield_view_->tracking_triple_click_;
104 }
105
102 protected: 106 protected:
103 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code, 107 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code,
104 bool shift, 108 bool shift,
105 bool control, 109 bool control,
106 bool capslock) { 110 bool capslock) {
107 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | 111 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) |
108 (control ? KeyEvent::EF_CONTROL_DOWN : 0) | 112 (control ? KeyEvent::EF_CONTROL_DOWN : 0) |
109 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0); 113 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0);
110 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); 114 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0);
111 return textfield_->OnKeyPressed(event); 115 return textfield_->OnKeyPressed(event);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 views::ViewsDelegate::views_delegate = test_views_delegate.get(); 420 views::ViewsDelegate::views_delegate = test_views_delegate.get();
417 InitTextfield(Textfield::STYLE_DEFAULT); 421 InitTextfield(Textfield::STYLE_DEFAULT);
418 textfield_->SetText(ASCIIToUTF16("hello world")); 422 textfield_->SetText(ASCIIToUTF16("hello world"));
419 EXPECT_TRUE(GetContextMenu()); 423 EXPECT_TRUE(GetContextMenu());
420 VerifyTextfieldContextMenuContents(false, GetContextMenu()->model()); 424 VerifyTextfieldContextMenuContents(false, GetContextMenu()->model());
421 425
422 textfield_->SelectAll(); 426 textfield_->SelectAll();
423 VerifyTextfieldContextMenuContents(true, GetContextMenu()->model()); 427 VerifyTextfieldContextMenuContents(true, GetContextMenu()->model());
424 } 428 }
425 429
430 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) {
431 InitTextfield(Textfield::STYLE_DEFAULT);
432 textfield_->SetText(ASCIIToUTF16("hello world"));
433 MouseEvent me(MouseEvent::ET_MOUSE_PRESSED, 0, 0, Event::EF_LEFT_BUTTON_DOWN);
434 EXPECT_FALSE(IsTrackingTripleClick());
435
436 // Test for double click.
437 textfield_view_->OnMousePressed(me);
438 textfield_view_->OnMousePressed(me);
439 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
440 EXPECT_TRUE(IsTrackingTripleClick());
441
442 // Test for triple click.
443 textfield_view_->OnMousePressed(me);
444 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText());
445 EXPECT_FALSE(IsTrackingTripleClick());
446 }
447
426 } // namespace views 448 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698