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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc

Issue 2273263002: MacViewsBrowser: Fix omnibox crash due to failed DCHECK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile. Created 4 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
OLDNEW
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
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
101 bool OnKeyPressed(const ui::KeyEvent& event) {
102 return test_api_->OnKeyPressed(event);
103 }
104
95 private: 105 private:
96 // testing::Test: 106 // testing::Test:
97 void SetUp() override { 107 void SetUp() override {
98 #if defined(OS_CHROMEOS) 108 #if defined(OS_CHROMEOS)
99 chromeos::input_method::InitializeForTesting( 109 chromeos::input_method::InitializeForTesting(
100 new chromeos::input_method::MockInputMethodManager); 110 new chromeos::input_method::MockInputMethodManager);
101 #endif 111 #endif
102 omnibox_view_.reset(new TestingOmniboxViewViews( 112 omnibox_view_.reset(new TestingOmniboxViewViews(
103 &omnibox_edit_controller_, &profile_, &command_updater_)); 113 &omnibox_edit_controller_, &profile_, &command_updater_));
114 test_api_.reset(new views::TextfieldTestApi(omnibox_view_.get()));
104 omnibox_view_->Init(); 115 omnibox_view_->Init();
105 } 116 }
106 117
107 void TearDown() override { 118 void TearDown() override {
108 omnibox_view_.reset(); 119 omnibox_view_.reset();
109 #if defined(OS_CHROMEOS) 120 #if defined(OS_CHROMEOS)
110 chromeos::input_method::Shutdown(); 121 chromeos::input_method::Shutdown();
111 #endif 122 #endif
112 } 123 }
113 124
114 content::TestBrowserThreadBundle thread_bundle_; 125 content::TestBrowserThreadBundle thread_bundle_;
115 TestingProfile profile_; 126 TestingProfile profile_;
116 CommandUpdater command_updater_; 127 CommandUpdater command_updater_;
117 TestingOmniboxEditController omnibox_edit_controller_; 128 TestingOmniboxEditController omnibox_edit_controller_;
118 std::unique_ptr<TestingOmniboxViewViews> omnibox_view_; 129 std::unique_ptr<TestingOmniboxViewViews> omnibox_view_;
130 std::unique_ptr<views::TextfieldTestApi> test_api_;
131
132 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest);
119 }; 133 };
120 134
121 // Checks that a single change of the text in the omnibox invokes 135 // Checks that a single change of the text in the omnibox invokes
122 // only one call to OmniboxViewViews::UpdatePopup(). 136 // only one call to OmniboxViewViews::UpdatePopup().
123 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { 137 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) {
124 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0, 138 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0,
125 ui::DomKey::FromCharacter('a'), 139 ui::DomKey::FromCharacter('a'),
126 ui::EventTimeForNow()); 140 ui::EventTimeForNow());
127 omnibox_textfield()->InsertChar(char_event); 141 omnibox_textfield()->InsertChar(char_event);
128 omnibox_view()->CheckUpdatePopupCallInfo( 142 omnibox_view()->CheckUpdatePopupCallInfo(
129 1, base::ASCIIToUTF16("a"), gfx::Range(1)); 143 1, base::ASCIIToUTF16("a"), gfx::Range(1));
130 144
131 char_event = 145 char_event =
132 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_B, ui::DomCode::US_B, 0, 146 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_B, ui::DomCode::US_B, 0,
133 ui::DomKey::FromCharacter('b'), ui::EventTimeForNow()); 147 ui::DomKey::FromCharacter('b'), ui::EventTimeForNow());
134 omnibox_textfield()->InsertChar(char_event); 148 omnibox_textfield()->InsertChar(char_event);
135 omnibox_view()->CheckUpdatePopupCallInfo( 149 omnibox_view()->CheckUpdatePopupCallInfo(
136 2, base::ASCIIToUTF16("ab"), gfx::Range(2)); 150 2, base::ASCIIToUTF16("ab"), gfx::Range(2));
137 151
138 ui::KeyEvent pressed(ui::ET_KEY_PRESSED, ui::VKEY_BACK, 0); 152 ui::KeyEvent pressed(ui::ET_KEY_PRESSED, ui::VKEY_BACK, 0);
139 omnibox_textfield()->OnKeyPressed(pressed); 153 OnKeyPressed(pressed);
140 omnibox_view()->CheckUpdatePopupCallInfo( 154 omnibox_view()->CheckUpdatePopupCallInfo(
141 3, base::ASCIIToUTF16("a"), gfx::Range(1)); 155 3, base::ASCIIToUTF16("a"), gfx::Range(1));
142 } 156 }
157
158 // Test that the scheduled text edit command is cleared when
159 // Textfield::OnKeyPressed is invoked. This ensures that the scheduled text edit
160 // command property is always in the correct state. Test for
161 // http://crbug.com/613948.
162 TEST_F(OmniboxViewViewsTest, ScheduledTextEditCommand) {
163 omnibox_textfield()->SetTextEditCommandForNextKeyEvent(
164 ui::TextEditCommand::MOVE_UP);
165 EXPECT_EQ(ui::TextEditCommand::MOVE_UP, scheduled_text_edit_command());
166
167 ui::KeyEvent up_pressed(ui::ET_KEY_PRESSED, ui::VKEY_UP, 0);
168 OnKeyPressed(up_pressed);
169 EXPECT_EQ(ui::TextEditCommand::INVALID_COMMAND,
170 scheduled_text_edit_command());
171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698