OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/browser/command_updater.h" | 13 #include "chrome/browser/command_updater.h" |
14 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" | 14 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/base/ime/text_edit_commands.h" |
18 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
19 #include "ui/events/keycodes/dom/dom_code.h" | 20 #include "ui/events/keycodes/dom/dom_code.h" |
| 21 #include "ui/views/controls/textfield/textfield_test_api.h" |
20 | 22 |
21 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
22 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 24 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
23 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" | 25 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" |
24 #endif | 26 #endif |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 class TestingOmniboxViewViews : public OmniboxViewViews { | 30 class TestingOmniboxViewViews : public OmniboxViewViews { |
29 public: | 31 public: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 87 } |
86 | 88 |
87 TestingOmniboxViewViews* omnibox_view() { | 89 TestingOmniboxViewViews* omnibox_view() { |
88 return omnibox_view_.get(); | 90 return omnibox_view_.get(); |
89 } | 91 } |
90 | 92 |
91 views::Textfield* omnibox_textfield() { | 93 views::Textfield* omnibox_textfield() { |
92 return omnibox_view(); | 94 return omnibox_view(); |
93 } | 95 } |
94 | 96 |
| 97 ui::TextEditCommand scheduled_text_edit_command() const { |
| 98 return test_api_->scheduled_text_edit_command(); |
| 99 } |
| 100 |
95 private: | 101 private: |
96 // testing::Test: | 102 // testing::Test: |
97 void SetUp() override { | 103 void SetUp() override { |
98 #if defined(OS_CHROMEOS) | 104 #if defined(OS_CHROMEOS) |
99 chromeos::input_method::InitializeForTesting( | 105 chromeos::input_method::InitializeForTesting( |
100 new chromeos::input_method::MockInputMethodManager); | 106 new chromeos::input_method::MockInputMethodManager); |
101 #endif | 107 #endif |
102 omnibox_view_.reset(new TestingOmniboxViewViews( | 108 omnibox_view_.reset(new TestingOmniboxViewViews( |
103 &omnibox_edit_controller_, &profile_, &command_updater_)); | 109 &omnibox_edit_controller_, &profile_, &command_updater_)); |
| 110 test_api_.reset(new views::TextfieldTestApi(omnibox_view_.get())); |
104 omnibox_view_->Init(); | 111 omnibox_view_->Init(); |
105 } | 112 } |
106 | 113 |
107 void TearDown() override { | 114 void TearDown() override { |
108 omnibox_view_.reset(); | 115 omnibox_view_.reset(); |
109 #if defined(OS_CHROMEOS) | 116 #if defined(OS_CHROMEOS) |
110 chromeos::input_method::Shutdown(); | 117 chromeos::input_method::Shutdown(); |
111 #endif | 118 #endif |
112 } | 119 } |
113 | 120 |
114 content::TestBrowserThreadBundle thread_bundle_; | 121 content::TestBrowserThreadBundle thread_bundle_; |
115 TestingProfile profile_; | 122 TestingProfile profile_; |
116 CommandUpdater command_updater_; | 123 CommandUpdater command_updater_; |
117 TestingOmniboxEditController omnibox_edit_controller_; | 124 TestingOmniboxEditController omnibox_edit_controller_; |
118 std::unique_ptr<TestingOmniboxViewViews> omnibox_view_; | 125 std::unique_ptr<TestingOmniboxViewViews> omnibox_view_; |
| 126 std::unique_ptr<views::TextfieldTestApi> test_api_; |
| 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); |
119 }; | 129 }; |
120 | 130 |
121 // Checks that a single change of the text in the omnibox invokes | 131 // Checks that a single change of the text in the omnibox invokes |
122 // only one call to OmniboxViewViews::UpdatePopup(). | 132 // only one call to OmniboxViewViews::UpdatePopup(). |
123 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { | 133 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { |
124 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0, | 134 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0, |
125 ui::DomKey::FromCharacter('a'), | 135 ui::DomKey::FromCharacter('a'), |
126 ui::EventTimeForNow()); | 136 ui::EventTimeForNow()); |
127 omnibox_textfield()->InsertChar(char_event); | 137 omnibox_textfield()->InsertChar(char_event); |
128 omnibox_view()->CheckUpdatePopupCallInfo( | 138 omnibox_view()->CheckUpdatePopupCallInfo( |
129 1, base::ASCIIToUTF16("a"), gfx::Range(1)); | 139 1, base::ASCIIToUTF16("a"), gfx::Range(1)); |
130 | 140 |
131 char_event = | 141 char_event = |
132 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_B, ui::DomCode::US_B, 0, | 142 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_B, ui::DomCode::US_B, 0, |
133 ui::DomKey::FromCharacter('b'), ui::EventTimeForNow()); | 143 ui::DomKey::FromCharacter('b'), ui::EventTimeForNow()); |
134 omnibox_textfield()->InsertChar(char_event); | 144 omnibox_textfield()->InsertChar(char_event); |
135 omnibox_view()->CheckUpdatePopupCallInfo( | 145 omnibox_view()->CheckUpdatePopupCallInfo( |
136 2, base::ASCIIToUTF16("ab"), gfx::Range(2)); | 146 2, base::ASCIIToUTF16("ab"), gfx::Range(2)); |
137 | 147 |
138 ui::KeyEvent pressed(ui::ET_KEY_PRESSED, ui::VKEY_BACK, 0); | 148 ui::KeyEvent pressed(ui::ET_KEY_PRESSED, ui::VKEY_BACK, 0); |
139 omnibox_textfield()->OnKeyPressed(pressed); | 149 omnibox_textfield()->OnKeyEvent(&pressed); |
140 omnibox_view()->CheckUpdatePopupCallInfo( | 150 omnibox_view()->CheckUpdatePopupCallInfo( |
141 3, base::ASCIIToUTF16("a"), gfx::Range(1)); | 151 3, base::ASCIIToUTF16("a"), gfx::Range(1)); |
142 } | 152 } |
| 153 |
| 154 // Test that the scheduled text edit command is cleared when Textfield receives |
| 155 // a key press event. This ensures that the scheduled text edit command property |
| 156 // is always in the correct state. Test for http://crbug.com/613948. |
| 157 TEST_F(OmniboxViewViewsTest, ScheduledTextEditCommand) { |
| 158 omnibox_textfield()->SetTextEditCommandForNextKeyEvent( |
| 159 ui::TextEditCommand::MOVE_UP); |
| 160 EXPECT_EQ(ui::TextEditCommand::MOVE_UP, scheduled_text_edit_command()); |
| 161 |
| 162 ui::KeyEvent up_pressed(ui::ET_KEY_PRESSED, ui::VKEY_UP, 0); |
| 163 omnibox_textfield()->OnKeyEvent(&up_pressed); |
| 164 EXPECT_EQ(ui::TextEditCommand::INVALID_COMMAND, |
| 165 scheduled_text_edit_command()); |
| 166 } |
OLD | NEW |