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_edit_controller.h" | 15 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/base/ime/text_edit_commands.h" | 19 #include "ui/base/ime/text_edit_commands.h" |
20 #include "ui/events/event_utils.h" | 20 #include "ui/events/event_utils.h" |
21 #include "ui/events/keycodes/dom/dom_code.h" | 21 #include "ui/events/keycodes/dom/dom_code.h" |
22 #include "ui/views/controls/textfield/textfield_test_api.h" | 22 #include "ui/views/controls/textfield/textfield_test_api.h" |
23 | 23 |
24 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
25 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 25 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
26 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" | 26 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" |
27 #endif | 27 #endif |
28 | 28 |
| 29 using gfx::Range; |
| 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 class TestingOmniboxViewViews : public OmniboxViewViews { | 33 // TestingOmniboxView --------------------------------------------------------- |
| 34 |
| 35 class TestingOmniboxView : public OmniboxViewViews { |
32 public: | 36 public: |
33 TestingOmniboxViewViews(OmniboxEditController* controller, | 37 enum BaseTextEmphasis { |
34 Profile* profile, | 38 DEEMPHASIZED, |
35 CommandUpdater* command_updater) | 39 EMPHASIZED, |
36 : OmniboxViewViews(controller, | 40 UNSET, |
37 profile, | 41 }; |
38 command_updater, | |
39 false, | |
40 nullptr, | |
41 gfx::FontList()), | |
42 update_popup_call_count_(0), | |
43 profile_(profile), | |
44 base_text_is_emphasized_(false) {} | |
45 | 42 |
46 void CheckUpdatePopupCallInfo(size_t call_count, const base::string16& text, | 43 TestingOmniboxView(OmniboxEditController* controller, |
47 const gfx::Range& selection_range) { | 44 Profile* profile, |
48 EXPECT_EQ(call_count, update_popup_call_count_); | 45 CommandUpdater* command_updater); |
49 EXPECT_EQ(text, update_popup_text_); | 46 |
50 EXPECT_EQ(selection_range, update_popup_selection_range_); | 47 static BaseTextEmphasis to_base_text_emphasis(bool emphasize) { |
| 48 return emphasize ? EMPHASIZED : DEEMPHASIZED; |
51 } | 49 } |
52 | 50 |
53 void EmphasizeURLComponents() override { | 51 void ResetEmphasisTestState(); |
54 UpdateTextStyle(text(), ChromeAutocompleteSchemeClassifier(profile_)); | |
55 } | |
56 | 52 |
57 gfx::Range scheme_range() const { return scheme_range_; } | 53 void CheckUpdatePopupCallInfo(size_t call_count, |
58 gfx::Range emphasis_range() const { return emphasis_range_; } | 54 const base::string16& text, |
59 bool base_text_is_emphasized() const { return base_text_is_emphasized_; } | 55 const Range& selection_range); |
| 56 |
| 57 Range scheme_range() const { return scheme_range_; } |
| 58 Range emphasis_range() const { return emphasis_range_; } |
| 59 BaseTextEmphasis base_text_emphasis() const { return base_text_emphasis_; } |
| 60 |
| 61 // OmniboxViewViews: |
| 62 void EmphasizeURLComponents() override; |
60 | 63 |
61 private: | 64 private: |
62 // OmniboxView: | 65 // OmniboxViewViews: |
63 void UpdatePopup() override { | 66 // There is no popup and it doesn't actually matter whether we change the |
64 ++update_popup_call_count_; | 67 // visual style of the text, so these methods are all overridden merely to |
65 update_popup_text_ = text(); | 68 // capture relevant state at the time of the call, to be checked by test code. |
66 update_popup_selection_range_ = GetSelectedRange(); | 69 void UpdatePopup() override; |
67 } | 70 void SetEmphasis(bool emphasize, const Range& range) override; |
68 | 71 void UpdateSchemeStyle(const Range& range) override; |
69 void SetEmphasis(bool emphasize, const gfx::Range& range) override { | |
70 if (range == gfx::Range::InvalidRange()) { | |
71 base_text_is_emphasized_ = emphasize; | |
72 return; | |
73 } | |
74 | |
75 EXPECT_TRUE(emphasize); | |
76 emphasis_range_ = range; | |
77 } | |
78 | |
79 void UpdateSchemeStyle(const gfx::Range& range) override { | |
80 scheme_range_ = range; | |
81 } | |
82 | 72 |
83 // Simplistic test override returns whether a given string looks like a URL | 73 // Simplistic test override returns whether a given string looks like a URL |
84 // without having to mock AutocompleteClassifier objects and their | 74 // without having to mock AutocompleteClassifier objects and their |
85 // dependencies. | 75 // dependencies. |
86 bool CurrentTextIsURL() override { | 76 bool CurrentTextIsURL() override { |
87 bool looks_like_url = (text().find(':') != std::string::npos || | 77 bool looks_like_url = (text().find(':') != std::string::npos || |
88 text().find('/') != std::string::npos); | 78 text().find('/') != std::string::npos); |
89 return looks_like_url; | 79 return looks_like_url; |
90 } | 80 } |
91 | 81 |
92 size_t update_popup_call_count_; | 82 size_t update_popup_call_count_ = 0; |
93 base::string16 update_popup_text_; | 83 base::string16 update_popup_text_; |
94 gfx::Range update_popup_selection_range_; | 84 Range update_popup_selection_range_; |
95 Profile* profile_; | 85 Profile* profile_; |
96 | 86 |
97 // Range of the last scheme logged by UpdateSchemeStyle(). | 87 // Range of the last scheme logged by UpdateSchemeStyle(). |
98 gfx::Range scheme_range_; | 88 Range scheme_range_; |
99 | 89 |
100 // Range of the last text emphasized by SetEmphasis(). | 90 // Range of the last text emphasized by SetEmphasis(). |
101 gfx::Range emphasis_range_; | 91 Range emphasis_range_; |
102 | 92 |
103 // SetEmphasis() logs whether the base color of the text is emphasized. | 93 // SetEmphasis() logs whether the base color of the text is emphasized. |
104 bool base_text_is_emphasized_; | 94 BaseTextEmphasis base_text_emphasis_ = UNSET; |
105 | 95 |
106 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxViewViews); | 96 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxView); |
107 }; | 97 }; |
108 | 98 |
| 99 TestingOmniboxView::TestingOmniboxView(OmniboxEditController* controller, |
| 100 Profile* profile, |
| 101 CommandUpdater* command_updater) |
| 102 : OmniboxViewViews(controller, |
| 103 profile, |
| 104 command_updater, |
| 105 false, |
| 106 nullptr, |
| 107 gfx::FontList()), |
| 108 profile_(profile) {} |
| 109 |
| 110 void TestingOmniboxView::ResetEmphasisTestState() { |
| 111 base_text_emphasis_ = UNSET; |
| 112 emphasis_range_ = Range::InvalidRange(); |
| 113 scheme_range_ = Range::InvalidRange(); |
| 114 } |
| 115 |
| 116 void TestingOmniboxView::CheckUpdatePopupCallInfo( |
| 117 size_t call_count, |
| 118 const base::string16& text, |
| 119 const Range& selection_range) { |
| 120 EXPECT_EQ(call_count, update_popup_call_count_); |
| 121 EXPECT_EQ(text, update_popup_text_); |
| 122 EXPECT_EQ(selection_range, update_popup_selection_range_); |
| 123 } |
| 124 |
| 125 void TestingOmniboxView::EmphasizeURLComponents() { |
| 126 UpdateTextStyle(text(), ChromeAutocompleteSchemeClassifier(profile_)); |
| 127 } |
| 128 |
| 129 void TestingOmniboxView::UpdatePopup() { |
| 130 ++update_popup_call_count_; |
| 131 update_popup_text_ = text(); |
| 132 update_popup_selection_range_ = GetSelectedRange(); |
| 133 } |
| 134 |
| 135 void TestingOmniboxView::SetEmphasis(bool emphasize, const Range& range) { |
| 136 if (range == Range::InvalidRange()) { |
| 137 base_text_emphasis_ = to_base_text_emphasis(emphasize); |
| 138 return; |
| 139 } |
| 140 |
| 141 EXPECT_TRUE(emphasize); |
| 142 emphasis_range_ = range; |
| 143 } |
| 144 |
| 145 void TestingOmniboxView::UpdateSchemeStyle(const Range& range) { |
| 146 scheme_range_ = range; |
| 147 } |
| 148 |
| 149 // TestingOmniboxEditController ----------------------------------------------- |
| 150 |
109 class TestingOmniboxEditController : public ChromeOmniboxEditController { | 151 class TestingOmniboxEditController : public ChromeOmniboxEditController { |
110 public: | 152 public: |
111 explicit TestingOmniboxEditController(CommandUpdater* command_updater) | 153 explicit TestingOmniboxEditController(CommandUpdater* command_updater) |
112 : ChromeOmniboxEditController(command_updater) {} | 154 : ChromeOmniboxEditController(command_updater) {} |
113 | 155 |
114 protected: | 156 private: |
115 // ChromeOmniboxEditController: | 157 // ChromeOmniboxEditController: |
116 void UpdateWithoutTabRestore() override {} | 158 void UpdateWithoutTabRestore() override {} |
117 void OnChanged() override {} | 159 void OnChanged() override {} |
118 ToolbarModel* GetToolbarModel() override { return nullptr; } | 160 ToolbarModel* GetToolbarModel() override { return nullptr; } |
119 const ToolbarModel* GetToolbarModel() const override { return nullptr; } | 161 const ToolbarModel* GetToolbarModel() const override { return nullptr; } |
120 content::WebContents* GetWebContents() override { return nullptr; } | 162 content::WebContents* GetWebContents() override { return nullptr; } |
121 | 163 |
122 private: | |
123 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); | 164 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); |
124 }; | 165 }; |
125 | 166 |
126 } // namespace | 167 } // namespace |
127 | 168 |
| 169 // OmniboxViewViewsTest ------------------------------------------------------- |
| 170 |
128 class OmniboxViewViewsTest : public testing::Test { | 171 class OmniboxViewViewsTest : public testing::Test { |
129 public: | 172 public: |
130 OmniboxViewViewsTest() | 173 OmniboxViewViewsTest(); |
131 : command_updater_(NULL), | |
132 omnibox_edit_controller_(&command_updater_) { | |
133 } | |
134 | 174 |
135 TestingOmniboxViewViews* omnibox_view() { | 175 TestingOmniboxView* omnibox_view() { return omnibox_view_.get(); } |
136 return omnibox_view_.get(); | 176 views::Textfield* omnibox_textfield() { return omnibox_view(); } |
137 } | |
138 | |
139 views::Textfield* omnibox_textfield() { | |
140 return omnibox_view(); | |
141 } | |
142 | |
143 ui::TextEditCommand scheduled_text_edit_command() const { | 177 ui::TextEditCommand scheduled_text_edit_command() const { |
144 return test_api_->scheduled_text_edit_command(); | 178 return test_api_->scheduled_text_edit_command(); |
145 } | 179 } |
146 | 180 |
147 void SetAndEmphasizeText(const std::string& new_text) { | 181 // Sets |new_text| as the omnibox text, and emphasizes it appropriately. |
148 omnibox_textfield()->SetText(base::ASCIIToUTF16(new_text)); | 182 void SetAndEmphasizeText(const std::string& new_text); |
149 omnibox_view()->EmphasizeURLComponents(); | |
150 } | |
151 | 183 |
152 private: | 184 private: |
153 // testing::Test: | 185 // testing::Test: |
154 void SetUp() override { | 186 void SetUp() override; |
155 #if defined(OS_CHROMEOS) | 187 void TearDown() override; |
156 chromeos::input_method::InitializeForTesting( | |
157 new chromeos::input_method::MockInputMethodManagerImpl); | |
158 #endif | |
159 omnibox_view_.reset(new TestingOmniboxViewViews( | |
160 &omnibox_edit_controller_, &profile_, &command_updater_)); | |
161 test_api_.reset(new views::TextfieldTestApi(omnibox_view_.get())); | |
162 omnibox_view_->Init(); | |
163 } | |
164 | |
165 void TearDown() override { | |
166 omnibox_view_.reset(); | |
167 #if defined(OS_CHROMEOS) | |
168 chromeos::input_method::Shutdown(); | |
169 #endif | |
170 } | |
171 | 188 |
172 content::TestBrowserThreadBundle thread_bundle_; | 189 content::TestBrowserThreadBundle thread_bundle_; |
173 TestingProfile profile_; | 190 TestingProfile profile_; |
174 CommandUpdater command_updater_; | 191 CommandUpdater command_updater_; |
175 TestingOmniboxEditController omnibox_edit_controller_; | 192 TestingOmniboxEditController omnibox_edit_controller_; |
176 std::unique_ptr<TestingOmniboxViewViews> omnibox_view_; | 193 std::unique_ptr<TestingOmniboxView> omnibox_view_; |
177 std::unique_ptr<views::TextfieldTestApi> test_api_; | 194 std::unique_ptr<views::TextfieldTestApi> test_api_; |
178 | 195 |
179 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); | 196 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); |
180 }; | 197 }; |
181 | 198 |
| 199 OmniboxViewViewsTest::OmniboxViewViewsTest() |
| 200 : command_updater_(nullptr), omnibox_edit_controller_(&command_updater_) {} |
| 201 |
| 202 void OmniboxViewViewsTest::SetAndEmphasizeText(const std::string& new_text) { |
| 203 omnibox_view()->ResetEmphasisTestState(); |
| 204 omnibox_view()->SetText(base::ASCIIToUTF16(new_text)); |
| 205 omnibox_view()->EmphasizeURLComponents(); |
| 206 } |
| 207 |
| 208 void OmniboxViewViewsTest::SetUp() { |
| 209 #if defined(OS_CHROMEOS) |
| 210 chromeos::input_method::InitializeForTesting( |
| 211 new chromeos::input_method::MockInputMethodManagerImpl); |
| 212 #endif |
| 213 omnibox_view_ = base::MakeUnique<TestingOmniboxView>( |
| 214 &omnibox_edit_controller_, &profile_, &command_updater_); |
| 215 test_api_ = base::MakeUnique<views::TextfieldTestApi>(omnibox_view_.get()); |
| 216 omnibox_view_->Init(); |
| 217 } |
| 218 |
| 219 void OmniboxViewViewsTest::TearDown() { |
| 220 omnibox_view_.reset(); |
| 221 #if defined(OS_CHROMEOS) |
| 222 chromeos::input_method::Shutdown(); |
| 223 #endif |
| 224 } |
| 225 |
| 226 // Actual tests --------------------------------------------------------------- |
| 227 |
182 // Checks that a single change of the text in the omnibox invokes | 228 // Checks that a single change of the text in the omnibox invokes |
183 // only one call to OmniboxViewViews::UpdatePopup(). | 229 // only one call to OmniboxViewViews::UpdatePopup(). |
184 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { | 230 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { |
185 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0, | 231 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0, |
186 ui::DomKey::FromCharacter('a'), | 232 ui::DomKey::FromCharacter('a'), |
187 ui::EventTimeForNow()); | 233 ui::EventTimeForNow()); |
188 omnibox_textfield()->InsertChar(char_event); | 234 omnibox_textfield()->InsertChar(char_event); |
189 omnibox_view()->CheckUpdatePopupCallInfo( | 235 omnibox_view()->CheckUpdatePopupCallInfo(1, base::ASCIIToUTF16("a"), |
190 1, base::ASCIIToUTF16("a"), gfx::Range(1)); | 236 Range(1)); |
191 | 237 |
192 char_event = | 238 char_event = |
193 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_B, ui::DomCode::US_B, 0, | 239 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_B, ui::DomCode::US_B, 0, |
194 ui::DomKey::FromCharacter('b'), ui::EventTimeForNow()); | 240 ui::DomKey::FromCharacter('b'), ui::EventTimeForNow()); |
195 omnibox_textfield()->InsertChar(char_event); | 241 omnibox_textfield()->InsertChar(char_event); |
196 omnibox_view()->CheckUpdatePopupCallInfo( | 242 omnibox_view()->CheckUpdatePopupCallInfo(2, base::ASCIIToUTF16("ab"), |
197 2, base::ASCIIToUTF16("ab"), gfx::Range(2)); | 243 Range(2)); |
198 | 244 |
199 ui::KeyEvent pressed(ui::ET_KEY_PRESSED, ui::VKEY_BACK, 0); | 245 ui::KeyEvent pressed(ui::ET_KEY_PRESSED, ui::VKEY_BACK, 0); |
200 omnibox_textfield()->OnKeyEvent(&pressed); | 246 omnibox_textfield()->OnKeyEvent(&pressed); |
201 omnibox_view()->CheckUpdatePopupCallInfo( | 247 omnibox_view()->CheckUpdatePopupCallInfo(3, base::ASCIIToUTF16("a"), |
202 3, base::ASCIIToUTF16("a"), gfx::Range(1)); | 248 Range(1)); |
203 } | 249 } |
204 | 250 |
205 // Test that the scheduled text edit command is cleared when Textfield receives | 251 // Test that the scheduled text edit command is cleared when Textfield receives |
206 // a key press event. This ensures that the scheduled text edit command property | 252 // a key press event. This ensures that the scheduled text edit command property |
207 // is always in the correct state. Test for http://crbug.com/613948. | 253 // is always in the correct state. Test for http://crbug.com/613948. |
208 TEST_F(OmniboxViewViewsTest, ScheduledTextEditCommand) { | 254 TEST_F(OmniboxViewViewsTest, ScheduledTextEditCommand) { |
209 omnibox_textfield()->SetTextEditCommandForNextKeyEvent( | 255 omnibox_textfield()->SetTextEditCommandForNextKeyEvent( |
210 ui::TextEditCommand::MOVE_UP); | 256 ui::TextEditCommand::MOVE_UP); |
211 EXPECT_EQ(ui::TextEditCommand::MOVE_UP, scheduled_text_edit_command()); | 257 EXPECT_EQ(ui::TextEditCommand::MOVE_UP, scheduled_text_edit_command()); |
212 | 258 |
213 ui::KeyEvent up_pressed(ui::ET_KEY_PRESSED, ui::VKEY_UP, 0); | 259 ui::KeyEvent up_pressed(ui::ET_KEY_PRESSED, ui::VKEY_UP, 0); |
214 omnibox_textfield()->OnKeyEvent(&up_pressed); | 260 omnibox_textfield()->OnKeyEvent(&up_pressed); |
215 EXPECT_EQ(ui::TextEditCommand::INVALID_COMMAND, | 261 EXPECT_EQ(ui::TextEditCommand::INVALID_COMMAND, |
216 scheduled_text_edit_command()); | 262 scheduled_text_edit_command()); |
217 } | 263 } |
218 | 264 |
219 // Ensure that the scheme is emphasized for data: URLs. | 265 TEST_F(OmniboxViewViewsTest, Emphasis) { |
220 TEST_F(OmniboxViewViewsTest, TestEmphasisForDATA) { | 266 constexpr struct { |
221 SetAndEmphasizeText("data:text/html,Hello%20World"); | 267 const char* input; |
222 EXPECT_EQ(gfx::Range(0, 4), omnibox_view()->scheme_range()); | 268 bool expected_base_text_emphasized; |
223 EXPECT_FALSE(omnibox_view()->base_text_is_emphasized()); | 269 Range expected_emphasis_range; |
224 EXPECT_EQ(gfx::Range(0, 4), omnibox_view()->emphasis_range()); | 270 Range expected_scheme_range; |
| 271 } test_cases[] = { |
| 272 {"data:text/html,Hello%20World", false, Range(0, 4), Range(0, 4)}, |
| 273 {"http://www.example.com/path/file.htm", false, Range(7, 22), |
| 274 Range(0, 4)}, |
| 275 {"https://www.example.com/path/file.htm", false, Range(8, 23), |
| 276 Range(0, 5)}, |
| 277 {"chrome-extension://ldfbacdbackkjhclmhnjabngnppnkagl", false, |
| 278 Range::InvalidRange(), Range(0, 16)}, |
| 279 {"nosuchscheme://opaque/string", true, Range::InvalidRange(), |
| 280 Range(0, 12)}, |
| 281 {"nosuchscheme:opaquestring", true, Range::InvalidRange(), Range(0, 12)}, |
| 282 {"host.com/path/file", false, Range(0, 8), Range::InvalidRange()}, |
| 283 {"This is plain text", true, Range::InvalidRange(), |
| 284 Range::InvalidRange()}, |
| 285 }; |
| 286 |
| 287 for (const auto& test_case : test_cases) { |
| 288 SCOPED_TRACE(test_case.input); |
| 289 |
| 290 SetAndEmphasizeText(test_case.input); |
| 291 EXPECT_EQ(TestingOmniboxView::to_base_text_emphasis( |
| 292 test_case.expected_base_text_emphasized), |
| 293 omnibox_view()->base_text_emphasis()); |
| 294 EXPECT_EQ(test_case.expected_emphasis_range, |
| 295 omnibox_view()->emphasis_range()); |
| 296 EXPECT_EQ(test_case.expected_scheme_range, omnibox_view()->scheme_range()); |
| 297 } |
225 } | 298 } |
226 | |
227 // Ensure that the origin is emphasized for http: URLs. | |
228 TEST_F(OmniboxViewViewsTest, TestEmphasisForHTTP) { | |
229 SetAndEmphasizeText("http://www.example.com/path/file.htm"); | |
230 EXPECT_EQ(gfx::Range(0, 4), omnibox_view()->scheme_range()); | |
231 EXPECT_FALSE(omnibox_view()->base_text_is_emphasized()); | |
232 EXPECT_EQ(gfx::Range(7, 22), omnibox_view()->emphasis_range()); | |
233 } | |
234 | |
235 // Ensure that the origin is emphasized for https: URLs. | |
236 TEST_F(OmniboxViewViewsTest, TestEmphasisForHTTPS) { | |
237 SetAndEmphasizeText("https://www.example.com/path/file.htm"); | |
238 EXPECT_EQ(gfx::Range(0, 5), omnibox_view()->scheme_range()); | |
239 EXPECT_FALSE(omnibox_view()->base_text_is_emphasized()); | |
240 EXPECT_EQ(gfx::Range(8, 23), omnibox_view()->emphasis_range()); | |
241 } | |
242 | |
243 // Ensure that nothing is emphasized for chrome-extension: URLs. | |
244 TEST_F(OmniboxViewViewsTest, TestEmphasisForChromeExtensionScheme) { | |
245 SetAndEmphasizeText("chrome-extension://ldfbacdbackkjhclmhnjabngnppnkagl"); | |
246 EXPECT_EQ(gfx::Range(0, 16), omnibox_view()->scheme_range()); | |
247 EXPECT_FALSE(omnibox_view()->base_text_is_emphasized()); | |
248 EXPECT_EQ(gfx::Range(), omnibox_view()->emphasis_range()); | |
249 } | |
250 | |
251 // Ensure that everything is emphasized for unknown scheme hierarchical URLs. | |
252 TEST_F(OmniboxViewViewsTest, TestEmphasisForUnknownHierarchicalScheme) { | |
253 SetAndEmphasizeText("nosuchscheme://opaque/string"); | |
254 EXPECT_EQ(gfx::Range(0, 12), omnibox_view()->scheme_range()); | |
255 EXPECT_TRUE(omnibox_view()->base_text_is_emphasized()); | |
256 EXPECT_EQ(gfx::Range(), omnibox_view()->emphasis_range()); | |
257 } | |
258 | |
259 // Ensure that everything is emphasized for unknown scheme URLs. | |
260 TEST_F(OmniboxViewViewsTest, TestEmphasisForUnknownScheme) { | |
261 SetAndEmphasizeText("nosuchscheme:opaquestring"); | |
262 EXPECT_EQ(gfx::Range(0, 12), omnibox_view()->scheme_range()); | |
263 EXPECT_TRUE(omnibox_view()->base_text_is_emphasized()); | |
264 EXPECT_EQ(gfx::Range(), omnibox_view()->emphasis_range()); | |
265 } | |
266 | |
267 // Ensure that the origin is emphasized for URL-like text. | |
268 TEST_F(OmniboxViewViewsTest, TestEmphasisForPartialURLs) { | |
269 SetAndEmphasizeText("example/path/file"); | |
270 EXPECT_EQ(gfx::Range(), omnibox_view()->scheme_range()); | |
271 EXPECT_FALSE(omnibox_view()->base_text_is_emphasized()); | |
272 EXPECT_EQ(gfx::Range(0, 7), omnibox_view()->emphasis_range()); | |
273 } | |
274 | |
275 // Ensure that everything is emphasized for plain text. | |
276 TEST_F(OmniboxViewViewsTest, TestEmphasisForNonURLs) { | |
277 SetAndEmphasizeText("This is plain text"); | |
278 | |
279 EXPECT_EQ(gfx::Range(), omnibox_view()->scheme_range()); | |
280 EXPECT_TRUE(omnibox_view()->base_text_is_emphasized()); | |
281 EXPECT_EQ(gfx::Range(), omnibox_view()->emphasis_range()); | |
282 } | |
OLD | NEW |