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

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

Issue 2553603002: New accessibility virtual keyboard behavior in non-sticky mode. (Closed)
Patch Set: rebase Created 3 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/format_macros.h" 15 #include "base/format_macros.h"
16 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/pickle.h" 18 #include "base/pickle.h"
19 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "ui/accessibility/ax_node_data.h" 23 #include "ui/accessibility/ax_node_data.h"
24 #include "ui/aura/window.h"
24 #include "ui/base/clipboard/clipboard.h" 25 #include "ui/base/clipboard/clipboard.h"
25 #include "ui/base/clipboard/scoped_clipboard_writer.h" 26 #include "ui/base/clipboard/scoped_clipboard_writer.h"
26 #include "ui/base/dragdrop/drag_drop_types.h" 27 #include "ui/base/dragdrop/drag_drop_types.h"
27 #include "ui/base/ime/input_method_base.h" 28 #include "ui/base/ime/input_method_base.h"
28 #include "ui/base/ime/input_method_delegate.h" 29 #include "ui/base/ime/input_method_delegate.h"
29 #include "ui/base/ime/input_method_factory.h" 30 #include "ui/base/ime/input_method_factory.h"
30 #include "ui/base/ime/text_edit_commands.h" 31 #include "ui/base/ime/text_edit_commands.h"
31 #include "ui/base/ime/text_input_client.h" 32 #include "ui/base/ime/text_input_client.h"
32 #include "ui/base/ui_base_switches.h" 33 #include "ui/base/ui_base_switches.h"
33 #include "ui/base/ui_base_switches_util.h" 34 #include "ui/base/ui_base_switches_util.h"
(...skipping 2906 matching lines...) Expand 10 before | Expand all | Expand 10 after
2940 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { 2941 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) {
2941 InitTextfield(); 2942 InitTextfield();
2942 textfield_->SetText(ASCIIToUTF16("abc")); 2943 textfield_->SetText(ASCIIToUTF16("abc"));
2943 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); 2944 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning());
2944 textfield_->SelectRange(gfx::Range(1, 2)); 2945 textfield_->SelectRange(gfx::Range(1, 2));
2945 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); 2946 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning());
2946 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); 2947 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo"));
2947 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); 2948 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning());
2948 } 2949 }
2949 2950
2951 #if defined(OS_CHROMEOS)
2952 // Check that when accessibility virtual keyboard is enabled, windows are
2953 // shifted up when focused and restored when focus is lost.
2954 TEST_F(TextfieldTest, VirtualKeyboardFocusEnsureCaretNotInRect) {
2955 InitTextfield();
2956
2957 // Enable new virtual keyboard behavior.
2958 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
2959 if (!command_line->HasSwitch(::switches::kUseNewVirtualKeyboardBehavior)) {
2960 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior);
2961 }
2962
2963 aura::Window* root_window = widget_->GetNativeView()->GetRootWindow();
2964 int keyboard_height = 200;
2965 gfx::Rect root_bounds = root_window->bounds();
2966 gfx::Rect orig_widget_bounds = gfx::Rect(0, 300, 400, 200);
2967 gfx::Rect shifted_widget_bounds = gfx::Rect(0, 200, 400, 200);
2968 gfx::Rect keyboard_view_bounds =
2969 gfx::Rect(0, root_bounds.height() - keyboard_height, root_bounds.width(),
2970 keyboard_height);
2971
2972 // Focus the window.
2973 widget_->SetBounds(orig_widget_bounds);
2974 input_method_->SetFocusedTextInputClient(textfield_);
2975 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds);
2976
2977 // Simulate virtual keyboard.
2978 input_method_->SetOnScreenKeyboardBounds(keyboard_view_bounds);
2979
2980 // Window should be shifted.
2981 EXPECT_EQ(widget_->GetNativeView()->bounds(), shifted_widget_bounds);
2982
2983 // Change the focus.
2984 input_method_->SetFocusedTextInputClient(nullptr);
2985
2986 // Window should be restored.
2987 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds);
2988 }
2989 #endif // defined(OS_CHROMEOS)
2990
2950 class TextfieldTouchSelectionTest : public TextfieldTest { 2991 class TextfieldTouchSelectionTest : public TextfieldTest {
2951 protected: 2992 protected:
2952 // Simulates a complete tap. 2993 // Simulates a complete tap.
2953 void Tap(const gfx::Point& point) { 2994 void Tap(const gfx::Point& point) {
2954 GestureEventForTest begin( 2995 GestureEventForTest begin(
2955 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); 2996 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN));
2956 textfield_->OnGestureEvent(&begin); 2997 textfield_->OnGestureEvent(&begin);
2957 2998
2958 GestureEventForTest tap_down( 2999 GestureEventForTest tap_down(
2959 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); 3000 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN));
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3117 InitTextfield(); 3158 InitTextfield();
3118 3159
3119 textfield_->SetCursorEnabled(false); 3160 textfield_->SetCursorEnabled(false);
3120 EXPECT_FALSE(test_api_->IsCursorVisible()); 3161 EXPECT_FALSE(test_api_->IsCursorVisible());
3121 3162
3122 textfield_->SetCursorEnabled(true); 3163 textfield_->SetCursorEnabled(true);
3123 EXPECT_TRUE(test_api_->IsCursorVisible()); 3164 EXPECT_TRUE(test_api_->IsCursorVisible());
3124 } 3165 }
3125 3166
3126 } // namespace views 3167 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698