| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "components/toolbar/test_toolbar_model.h" | 21 #include "components/toolbar/test_toolbar_model.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "ui/base/ime/text_edit_commands.h" | 24 #include "ui/base/ime/text_edit_commands.h" |
| 25 #include "ui/events/event_utils.h" | 25 #include "ui/events/event_utils.h" |
| 26 #include "ui/events/keycodes/dom/dom_code.h" | 26 #include "ui/events/keycodes/dom/dom_code.h" |
| 27 #include "ui/gfx/geometry/rect.h" | 27 #include "ui/gfx/geometry/rect.h" |
| 28 #include "ui/gfx/geometry/vector2d.h" | 28 #include "ui/gfx/geometry/vector2d.h" |
| 29 #include "ui/gfx/render_text.h" | 29 #include "ui/gfx/render_text.h" |
| 30 #include "ui/views/controls/textfield/textfield_test_api.h" | 30 #include "ui/views/controls/textfield/textfield_test_api.h" |
| 31 #include "ui/views/test/views_test_base.h" |
| 31 | 32 |
| 32 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
| 33 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 34 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 34 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" | 35 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 using gfx::Range; | 38 using gfx::Range; |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 167 |
| 167 ToolbarModel* toolbar_model_; | 168 ToolbarModel* toolbar_model_; |
| 168 | 169 |
| 169 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); | 170 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 } // namespace | 173 } // namespace |
| 173 | 174 |
| 174 // OmniboxViewViewsTest ------------------------------------------------------- | 175 // OmniboxViewViewsTest ------------------------------------------------------- |
| 175 | 176 |
| 176 class OmniboxViewViewsTest : public testing::Test { | 177 class OmniboxViewViewsTest : public views::ViewsTestBase { |
| 177 public: | 178 public: |
| 178 OmniboxViewViewsTest(); | 179 OmniboxViewViewsTest(); |
| 179 | 180 |
| 180 TestingOmniboxView* omnibox_view() { return omnibox_view_.get(); } | 181 TestingOmniboxView* omnibox_view() { return omnibox_view_.get(); } |
| 181 views::Textfield* omnibox_textfield() { return omnibox_view(); } | 182 views::Textfield* omnibox_textfield() { return omnibox_view(); } |
| 182 ui::TextEditCommand scheduled_text_edit_command() const { | 183 ui::TextEditCommand scheduled_text_edit_command() const { |
| 183 return test_api_->scheduled_text_edit_command(); | 184 return test_api_->scheduled_text_edit_command(); |
| 184 } | 185 } |
| 185 | 186 |
| 186 // Sets |new_text| as the omnibox text, and emphasizes it appropriately. If | 187 // Sets |new_text| as the omnibox text, and emphasizes it appropriately. If |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (accept_input) { | 222 if (accept_input) { |
| 222 // We don't need to actually navigate in this case (and doing so in a test | 223 // We don't need to actually navigate in this case (and doing so in a test |
| 223 // would be difficult); it's sufficient to mark input as "no longer in | 224 // would be difficult); it's sufficient to mark input as "no longer in |
| 224 // progress", and the edit model will assume the current text is a URL. | 225 // progress", and the edit model will assume the current text is a URL. |
| 225 omnibox_view()->model()->SetInputInProgress(false); | 226 omnibox_view()->model()->SetInputInProgress(false); |
| 226 } | 227 } |
| 227 omnibox_view()->EmphasizeURLComponents(); | 228 omnibox_view()->EmphasizeURLComponents(); |
| 228 } | 229 } |
| 229 | 230 |
| 230 void OmniboxViewViewsTest::SetUp() { | 231 void OmniboxViewViewsTest::SetUp() { |
| 232 ViewsTestBase::SetUp(); |
| 231 #if defined(OS_CHROMEOS) | 233 #if defined(OS_CHROMEOS) |
| 232 chromeos::input_method::InitializeForTesting( | 234 chromeos::input_method::InitializeForTesting( |
| 233 new chromeos::input_method::MockInputMethodManagerImpl); | 235 new chromeos::input_method::MockInputMethodManagerImpl); |
| 234 #endif | 236 #endif |
| 235 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( | 237 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( |
| 236 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); | 238 &profile_, &AutocompleteClassifierFactory::BuildInstanceFor); |
| 237 omnibox_view_ = base::MakeUnique<TestingOmniboxView>( | 239 omnibox_view_ = base::MakeUnique<TestingOmniboxView>( |
| 238 &omnibox_edit_controller_, | 240 &omnibox_edit_controller_, |
| 239 base::MakeUnique<ChromeOmniboxClient>(&omnibox_edit_controller_, | 241 base::MakeUnique<ChromeOmniboxClient>(&omnibox_edit_controller_, |
| 240 &profile_), | 242 &profile_), |
| 241 &command_updater_); | 243 &command_updater_); |
| 242 test_api_ = base::MakeUnique<views::TextfieldTestApi>(omnibox_view_.get()); | 244 test_api_ = base::MakeUnique<views::TextfieldTestApi>(omnibox_view_.get()); |
| 243 omnibox_view_->Init(); | 245 omnibox_view_->Init(); |
| 244 } | 246 } |
| 245 | 247 |
| 246 void OmniboxViewViewsTest::TearDown() { | 248 void OmniboxViewViewsTest::TearDown() { |
| 247 omnibox_view_.reset(); | 249 omnibox_view_.reset(); |
| 248 #if defined(OS_CHROMEOS) | 250 #if defined(OS_CHROMEOS) |
| 249 chromeos::input_method::Shutdown(); | 251 chromeos::input_method::Shutdown(); |
| 250 #endif | 252 #endif |
| 253 ViewsTestBase::TearDown(); |
| 251 } | 254 } |
| 252 | 255 |
| 253 // Actual tests --------------------------------------------------------------- | 256 // Actual tests --------------------------------------------------------------- |
| 254 | 257 |
| 255 // Checks that a single change of the text in the omnibox invokes | 258 // Checks that a single change of the text in the omnibox invokes |
| 256 // only one call to OmniboxViewViews::UpdatePopup(). | 259 // only one call to OmniboxViewViews::UpdatePopup(). |
| 257 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { | 260 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { |
| 258 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0, | 261 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0, |
| 259 ui::DomKey::FromCharacter('a'), | 262 ui::DomKey::FromCharacter('a'), |
| 260 ui::EventTimeForNow()); | 263 ui::EventTimeForNow()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 EXPECT_EQ(TestingOmniboxView::to_base_text_emphasis( | 376 EXPECT_EQ(TestingOmniboxView::to_base_text_emphasis( |
| 374 test_case.expected_base_text_emphasized), | 377 test_case.expected_base_text_emphasized), |
| 375 omnibox_view()->base_text_emphasis()); | 378 omnibox_view()->base_text_emphasis()); |
| 376 EXPECT_EQ(test_case.expected_emphasis_range, | 379 EXPECT_EQ(test_case.expected_emphasis_range, |
| 377 omnibox_view()->emphasis_range()); | 380 omnibox_view()->emphasis_range()); |
| 378 EXPECT_EQ(test_case.expected_scheme_range, | 381 EXPECT_EQ(test_case.expected_scheme_range, |
| 379 omnibox_view()->scheme_range()); | 382 omnibox_view()->scheme_range()); |
| 380 } | 383 } |
| 381 } | 384 } |
| 382 } | 385 } |
| OLD | NEW |