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

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

Issue 2731123002: Fix some issues with OmniboxViewViews' use of OmniboxClient. (Closed)
Patch Set: Resync 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 (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_emphasis(bool emphasize) { 49 static BaseTextEmphasis to_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 17 matching lines...) Expand all
72 // dependencies. 74 // dependencies.
73 bool CurrentTextIsURL() override { 75 bool CurrentTextIsURL() override {
74 bool looks_like_url = (text().find(':') != std::string::npos || 76 bool looks_like_url = (text().find(':') != std::string::npos ||
75 text().find('/') != std::string::npos); 77 text().find('/') != std::string::npos);
76 return looks_like_url; 78 return looks_like_url;
77 } 79 }
78 80
79 size_t update_popup_call_count_ = 0; 81 size_t update_popup_call_count_ = 0;
80 base::string16 update_popup_text_; 82 base::string16 update_popup_text_;
81 Range update_popup_selection_range_; 83 Range update_popup_selection_range_;
82 Profile* profile_;
83 84
84 // Range of the last scheme logged by UpdateSchemeStyle(). 85 // Range of the last scheme logged by UpdateSchemeStyle().
85 Range scheme_range_; 86 Range scheme_range_;
86 87
87 // Range of the last text emphasized by SetEmphasis(). 88 // Range of the last text emphasized by SetEmphasis().
88 Range emphasis_range_; 89 Range emphasis_range_;
89 90
90 // SetEmphasis() logs whether the base color of the text is emphasized. 91 // SetEmphasis() logs whether the base color of the text is emphasized.
91 BaseTextEmphasis base_text_emphasis_ = UNSET; 92 BaseTextEmphasis base_text_emphasis_ = UNSET;
92 93
93 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxView); 94 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxView);
94 }; 95 };
95 96
96 TestingOmniboxView::TestingOmniboxView(OmniboxEditController* controller, 97 TestingOmniboxView::TestingOmniboxView(OmniboxEditController* controller,
97 Profile* profile, 98 std::unique_ptr<OmniboxClient> client,
98 CommandUpdater* command_updater) 99 CommandUpdater* command_updater)
99 : OmniboxViewViews(controller, 100 : OmniboxViewViews(controller,
100 profile, 101 std::move(client),
101 command_updater, 102 command_updater,
102 false, 103 false,
103 nullptr, 104 nullptr,
104 gfx::FontList()), 105 gfx::FontList()) {}
105 profile_(profile) {}
106 106
107 void TestingOmniboxView::ResetEmphasisTestState() { 107 void TestingOmniboxView::ResetEmphasisTestState() {
108 base_text_emphasis_ = UNSET; 108 base_text_emphasis_ = UNSET;
109 emphasis_range_ = Range::InvalidRange(); 109 emphasis_range_ = Range::InvalidRange();
110 scheme_range_ = Range::InvalidRange(); 110 scheme_range_ = Range::InvalidRange();
111 } 111 }
112 112
113 void TestingOmniboxView::CheckUpdatePopupCallInfo( 113 void TestingOmniboxView::CheckUpdatePopupCallInfo(
114 size_t call_count, 114 size_t call_count,
115 const base::string16& text, 115 const base::string16& text,
116 const Range& selection_range) { 116 const Range& selection_range) {
117 EXPECT_EQ(call_count, update_popup_call_count_); 117 EXPECT_EQ(call_count, update_popup_call_count_);
118 EXPECT_EQ(text, update_popup_text_); 118 EXPECT_EQ(text, update_popup_text_);
119 EXPECT_EQ(selection_range, update_popup_selection_range_); 119 EXPECT_EQ(selection_range, update_popup_selection_range_);
120 } 120 }
121 121
122 void TestingOmniboxView::EmphasizeURLComponents() { 122 void TestingOmniboxView::EmphasizeURLComponents() {
123 UpdateTextStyle(text(), ChromeAutocompleteSchemeClassifier(profile_)); 123 UpdateTextStyle(text(), model()->client()->GetSchemeClassifier());
124 } 124 }
125 125
126 void TestingOmniboxView::UpdatePopup() { 126 void TestingOmniboxView::UpdatePopup() {
127 ++update_popup_call_count_; 127 ++update_popup_call_count_;
128 update_popup_text_ = text(); 128 update_popup_text_ = text();
129 update_popup_selection_range_ = GetSelectedRange(); 129 update_popup_selection_range_ = GetSelectedRange();
130 } 130 }
131 131
132 void TestingOmniboxView::SetEmphasis(bool emphasize, const Range& range) { 132 void TestingOmniboxView::SetEmphasis(bool emphasize, const Range& range) {
133 if (range == Range::InvalidRange()) { 133 if (range == Range::InvalidRange()) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 omnibox_view()->SetText(base::ASCIIToUTF16(new_text)); 201 omnibox_view()->SetText(base::ASCIIToUTF16(new_text));
202 omnibox_view()->EmphasizeURLComponents(); 202 omnibox_view()->EmphasizeURLComponents();
203 } 203 }
204 204
205 void OmniboxViewViewsTest::SetUp() { 205 void OmniboxViewViewsTest::SetUp() {
206 #if defined(OS_CHROMEOS) 206 #if defined(OS_CHROMEOS)
207 chromeos::input_method::InitializeForTesting( 207 chromeos::input_method::InitializeForTesting(
208 new chromeos::input_method::MockInputMethodManagerImpl); 208 new chromeos::input_method::MockInputMethodManagerImpl);
209 #endif 209 #endif
210 omnibox_view_ = base::MakeUnique<TestingOmniboxView>( 210 omnibox_view_ = base::MakeUnique<TestingOmniboxView>(
211 &omnibox_edit_controller_, &profile_, &command_updater_); 211 &omnibox_edit_controller_,
212 base::MakeUnique<ChromeOmniboxClient>(&omnibox_edit_controller_,
213 &profile_),
214 &command_updater_);
212 test_api_ = base::MakeUnique<views::TextfieldTestApi>(omnibox_view_.get()); 215 test_api_ = base::MakeUnique<views::TextfieldTestApi>(omnibox_view_.get());
213 omnibox_view_->Init(); 216 omnibox_view_->Init();
214 } 217 }
215 218
216 void OmniboxViewViewsTest::TearDown() { 219 void OmniboxViewViewsTest::TearDown() {
217 omnibox_view_.reset(); 220 omnibox_view_.reset();
218 #if defined(OS_CHROMEOS) 221 #if defined(OS_CHROMEOS)
219 chromeos::input_method::Shutdown(); 222 chromeos::input_method::Shutdown();
220 #endif 223 #endif
221 } 224 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 for (const auto& test_case : test_cases) { 287 for (const auto& test_case : test_cases) {
285 SCOPED_TRACE(test_case.input); 288 SCOPED_TRACE(test_case.input);
286 289
287 SetAndEmphasizeText(test_case.input); 290 SetAndEmphasizeText(test_case.input);
288 EXPECT_EQ(TestingOmniboxView::to_emphasis(test_case.base_text_emphasized), 291 EXPECT_EQ(TestingOmniboxView::to_emphasis(test_case.base_text_emphasized),
289 omnibox_view()->base_text_emphasis()); 292 omnibox_view()->base_text_emphasis());
290 EXPECT_EQ(test_case.emphasis_range, omnibox_view()->emphasis_range()); 293 EXPECT_EQ(test_case.emphasis_range, omnibox_view()->emphasis_range());
291 EXPECT_EQ(test_case.scheme_range, omnibox_view()->scheme_range()); 294 EXPECT_EQ(test_case.scheme_range, omnibox_view()->scheme_range());
292 } 295 }
293 } 296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698