| 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/autocomplete/chrome_autocomplete_scheme_classifier.h" | 13 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 14 #include "chrome/browser/command_updater.h" | 14 #include "chrome/browser/command_updater.h" |
| 15 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" |
| 15 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" | 16 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "components/omnibox/browser/omnibox_edit_model.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/ime/text_edit_commands.h" | 21 #include "ui/base/ime/text_edit_commands.h" |
| 20 #include "ui/events/event_utils.h" | 22 #include "ui/events/event_utils.h" |
| 21 #include "ui/events/keycodes/dom/dom_code.h" | 23 #include "ui/events/keycodes/dom/dom_code.h" |
| 22 #include "ui/views/controls/textfield/textfield_test_api.h" | 24 #include "ui/views/controls/textfield/textfield_test_api.h" |
| 23 | 25 |
| 24 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
| 25 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 27 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 26 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" | 28 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" |
| 27 #endif | 29 #endif |
| 28 | 30 |
| 29 using gfx::Range; | 31 using gfx::Range; |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 // TestingOmniboxView --------------------------------------------------------- | 35 // TestingOmniboxView --------------------------------------------------------- |
| 34 | 36 |
| 35 class TestingOmniboxView : public OmniboxViewViews { | 37 class TestingOmniboxView : public OmniboxViewViews { |
| 36 public: | 38 public: |
| 37 enum BaseTextEmphasis { | 39 enum BaseTextEmphasis { |
| 38 DEEMPHASIZED, | 40 DEEMPHASIZED, |
| 39 EMPHASIZED, | 41 EMPHASIZED, |
| 40 UNSET, | 42 UNSET, |
| 41 }; | 43 }; |
| 42 | 44 |
| 43 TestingOmniboxView(OmniboxEditController* controller, | 45 TestingOmniboxView(OmniboxEditController* controller, |
| 44 Profile* profile, | 46 std::unique_ptr<OmniboxClient> client, |
| 45 CommandUpdater* command_updater); | 47 CommandUpdater* command_updater); |
| 46 | 48 |
| 47 static BaseTextEmphasis to_base_text_emphasis(bool emphasize) { | 49 static BaseTextEmphasis to_base_text_emphasis(bool emphasize) { |
| 48 return emphasize ? EMPHASIZED : DEEMPHASIZED; | 50 return emphasize ? EMPHASIZED : DEEMPHASIZED; |
| 49 } | 51 } |
| 50 | 52 |
| 51 void ResetEmphasisTestState(); | 53 void ResetEmphasisTestState(); |
| 52 | 54 |
| 53 void CheckUpdatePopupCallInfo(size_t call_count, | 55 void CheckUpdatePopupCallInfo(size_t call_count, |
| 54 const base::string16& text, | 56 const base::string16& text, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 75 // dependencies. | 77 // dependencies. |
| 76 bool CurrentTextIsURL() override { | 78 bool CurrentTextIsURL() override { |
| 77 bool looks_like_url = (text().find(':') != std::string::npos || | 79 bool looks_like_url = (text().find(':') != std::string::npos || |
| 78 text().find('/') != std::string::npos); | 80 text().find('/') != std::string::npos); |
| 79 return looks_like_url; | 81 return looks_like_url; |
| 80 } | 82 } |
| 81 | 83 |
| 82 size_t update_popup_call_count_ = 0; | 84 size_t update_popup_call_count_ = 0; |
| 83 base::string16 update_popup_text_; | 85 base::string16 update_popup_text_; |
| 84 Range update_popup_selection_range_; | 86 Range update_popup_selection_range_; |
| 85 Profile* profile_; | |
| 86 | 87 |
| 87 // Range of the last scheme logged by UpdateSchemeStyle(). | 88 // Range of the last scheme logged by UpdateSchemeStyle(). |
| 88 Range scheme_range_; | 89 Range scheme_range_; |
| 89 | 90 |
| 90 // Range of the last text emphasized by SetEmphasis(). | 91 // Range of the last text emphasized by SetEmphasis(). |
| 91 Range emphasis_range_; | 92 Range emphasis_range_; |
| 92 | 93 |
| 93 // SetEmphasis() logs whether the base color of the text is emphasized. | 94 // SetEmphasis() logs whether the base color of the text is emphasized. |
| 94 BaseTextEmphasis base_text_emphasis_ = UNSET; | 95 BaseTextEmphasis base_text_emphasis_ = UNSET; |
| 95 | 96 |
| 96 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxView); | 97 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxView); |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 TestingOmniboxView::TestingOmniboxView(OmniboxEditController* controller, | 100 TestingOmniboxView::TestingOmniboxView(OmniboxEditController* controller, |
| 100 Profile* profile, | 101 std::unique_ptr<OmniboxClient> client, |
| 101 CommandUpdater* command_updater) | 102 CommandUpdater* command_updater) |
| 102 : OmniboxViewViews(controller, | 103 : OmniboxViewViews(controller, |
| 103 profile, | 104 std::move(client), |
| 104 command_updater, | 105 command_updater, |
| 105 false, | 106 false, |
| 106 nullptr, | 107 nullptr, |
| 107 gfx::FontList()), | 108 gfx::FontList()) {} |
| 108 profile_(profile) {} | |
| 109 | 109 |
| 110 void TestingOmniboxView::ResetEmphasisTestState() { | 110 void TestingOmniboxView::ResetEmphasisTestState() { |
| 111 base_text_emphasis_ = UNSET; | 111 base_text_emphasis_ = UNSET; |
| 112 emphasis_range_ = Range::InvalidRange(); | 112 emphasis_range_ = Range::InvalidRange(); |
| 113 scheme_range_ = Range::InvalidRange(); | 113 scheme_range_ = Range::InvalidRange(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void TestingOmniboxView::CheckUpdatePopupCallInfo( | 116 void TestingOmniboxView::CheckUpdatePopupCallInfo( |
| 117 size_t call_count, | 117 size_t call_count, |
| 118 const base::string16& text, | 118 const base::string16& text, |
| 119 const Range& selection_range) { | 119 const Range& selection_range) { |
| 120 EXPECT_EQ(call_count, update_popup_call_count_); | 120 EXPECT_EQ(call_count, update_popup_call_count_); |
| 121 EXPECT_EQ(text, update_popup_text_); | 121 EXPECT_EQ(text, update_popup_text_); |
| 122 EXPECT_EQ(selection_range, update_popup_selection_range_); | 122 EXPECT_EQ(selection_range, update_popup_selection_range_); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void TestingOmniboxView::EmphasizeURLComponents() { | 125 void TestingOmniboxView::EmphasizeURLComponents() { |
| 126 UpdateTextStyle(text(), ChromeAutocompleteSchemeClassifier(profile_)); | 126 UpdateTextStyle(text(), model()->client()->GetSchemeClassifier()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void TestingOmniboxView::UpdatePopup() { | 129 void TestingOmniboxView::UpdatePopup() { |
| 130 ++update_popup_call_count_; | 130 ++update_popup_call_count_; |
| 131 update_popup_text_ = text(); | 131 update_popup_text_ = text(); |
| 132 update_popup_selection_range_ = GetSelectedRange(); | 132 update_popup_selection_range_ = GetSelectedRange(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void TestingOmniboxView::SetEmphasis(bool emphasize, const Range& range) { | 135 void TestingOmniboxView::SetEmphasis(bool emphasize, const Range& range) { |
| 136 if (range == Range::InvalidRange()) { | 136 if (range == Range::InvalidRange()) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 omnibox_view()->SetText(base::ASCIIToUTF16(new_text)); | 204 omnibox_view()->SetText(base::ASCIIToUTF16(new_text)); |
| 205 omnibox_view()->EmphasizeURLComponents(); | 205 omnibox_view()->EmphasizeURLComponents(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void OmniboxViewViewsTest::SetUp() { | 208 void OmniboxViewViewsTest::SetUp() { |
| 209 #if defined(OS_CHROMEOS) | 209 #if defined(OS_CHROMEOS) |
| 210 chromeos::input_method::InitializeForTesting( | 210 chromeos::input_method::InitializeForTesting( |
| 211 new chromeos::input_method::MockInputMethodManagerImpl); | 211 new chromeos::input_method::MockInputMethodManagerImpl); |
| 212 #endif | 212 #endif |
| 213 omnibox_view_ = base::MakeUnique<TestingOmniboxView>( | 213 omnibox_view_ = base::MakeUnique<TestingOmniboxView>( |
| 214 &omnibox_edit_controller_, &profile_, &command_updater_); | 214 &omnibox_edit_controller_, |
| 215 base::MakeUnique<ChromeOmniboxClient>(&omnibox_edit_controller_, |
| 216 &profile_), |
| 217 &command_updater_); |
| 215 test_api_ = base::MakeUnique<views::TextfieldTestApi>(omnibox_view_.get()); | 218 test_api_ = base::MakeUnique<views::TextfieldTestApi>(omnibox_view_.get()); |
| 216 omnibox_view_->Init(); | 219 omnibox_view_->Init(); |
| 217 } | 220 } |
| 218 | 221 |
| 219 void OmniboxViewViewsTest::TearDown() { | 222 void OmniboxViewViewsTest::TearDown() { |
| 220 omnibox_view_.reset(); | 223 omnibox_view_.reset(); |
| 221 #if defined(OS_CHROMEOS) | 224 #if defined(OS_CHROMEOS) |
| 222 chromeos::input_method::Shutdown(); | 225 chromeos::input_method::Shutdown(); |
| 223 #endif | 226 #endif |
| 224 } | 227 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 292 |
| 290 SetAndEmphasizeText(test_case.input); | 293 SetAndEmphasizeText(test_case.input); |
| 291 EXPECT_EQ(TestingOmniboxView::to_base_text_emphasis( | 294 EXPECT_EQ(TestingOmniboxView::to_base_text_emphasis( |
| 292 test_case.expected_base_text_emphasized), | 295 test_case.expected_base_text_emphasized), |
| 293 omnibox_view()->base_text_emphasis()); | 296 omnibox_view()->base_text_emphasis()); |
| 294 EXPECT_EQ(test_case.expected_emphasis_range, | 297 EXPECT_EQ(test_case.expected_emphasis_range, |
| 295 omnibox_view()->emphasis_range()); | 298 omnibox_view()->emphasis_range()); |
| 296 EXPECT_EQ(test_case.expected_scheme_range, omnibox_view()->scheme_range()); | 299 EXPECT_EQ(test_case.expected_scheme_range, omnibox_view()->scheme_range()); |
| 297 } | 300 } |
| 298 } | 301 } |
| OLD | NEW |