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_emphasis(bool emphasize) { |
Mark P
2017/03/07 21:10:18
nit: awkward function name, hard to read outside o
Peter Kasting
2017/03/08 10:57:31
Done.
| |
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 void UpdatePopup() override; |
64 ++update_popup_call_count_; | 67 void SetEmphasis(bool emphasize, const Range& range) override; |
65 update_popup_text_ = text(); | 68 void UpdateSchemeStyle(const Range& range) override; |
66 update_popup_selection_range_ = GetSelectedRange(); | |
67 } | |
68 | |
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 | 69 |
83 // Simplistic test override returns whether a given string looks like a URL | 70 // Simplistic test override returns whether a given string looks like a URL |
84 // without having to mock AutocompleteClassifier objects and their | 71 // without having to mock AutocompleteClassifier objects and their |
85 // dependencies. | 72 // dependencies. |
86 bool CurrentTextIsURL() override { | 73 bool CurrentTextIsURL() override { |
87 bool looks_like_url = (text().find(':') != std::string::npos || | 74 bool looks_like_url = (text().find(':') != std::string::npos || |
88 text().find('/') != std::string::npos); | 75 text().find('/') != std::string::npos); |
89 return looks_like_url; | 76 return looks_like_url; |
90 } | 77 } |
91 | 78 |
92 size_t update_popup_call_count_; | 79 size_t update_popup_call_count_ = 0; |
93 base::string16 update_popup_text_; | 80 base::string16 update_popup_text_; |
94 gfx::Range update_popup_selection_range_; | 81 Range update_popup_selection_range_; |
95 Profile* profile_; | 82 Profile* profile_; |
96 | 83 |
97 // Range of the last scheme logged by UpdateSchemeStyle(). | 84 // Range of the last scheme logged by UpdateSchemeStyle(). |
98 gfx::Range scheme_range_; | 85 Range scheme_range_; |
99 | 86 |
100 // Range of the last text emphasized by SetEmphasis(). | 87 // Range of the last text emphasized by SetEmphasis(). |
101 gfx::Range emphasis_range_; | 88 Range emphasis_range_; |
102 | 89 |
103 // SetEmphasis() logs whether the base color of the text is emphasized. | 90 // SetEmphasis() logs whether the base color of the text is emphasized. |
104 bool base_text_is_emphasized_; | 91 BaseTextEmphasis base_text_emphasis_ = UNSET; |
105 | 92 |
106 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxViewViews); | 93 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxView); |
107 }; | 94 }; |
108 | 95 |
96 TestingOmniboxView::TestingOmniboxView(OmniboxEditController* controller, | |
97 Profile* profile, | |
98 CommandUpdater* command_updater) | |
99 : OmniboxViewViews(controller, | |
100 profile, | |
101 command_updater, | |
102 false, | |
103 nullptr, | |
104 gfx::FontList()), | |
105 profile_(profile) {} | |
106 | |
107 void TestingOmniboxView::ResetEmphasisTestState() { | |
108 base_text_emphasis_ = UNSET; | |
109 emphasis_range_ = Range::InvalidRange(); | |
110 scheme_range_ = Range::InvalidRange(); | |
111 } | |
112 | |
113 void TestingOmniboxView::CheckUpdatePopupCallInfo( | |
114 size_t call_count, | |
115 const base::string16& text, | |
116 const Range& selection_range) { | |
117 EXPECT_EQ(call_count, update_popup_call_count_); | |
118 EXPECT_EQ(text, update_popup_text_); | |
119 EXPECT_EQ(selection_range, update_popup_selection_range_); | |
120 } | |
121 | |
122 void TestingOmniboxView::EmphasizeURLComponents() { | |
123 UpdateTextStyle(text(), ChromeAutocompleteSchemeClassifier(profile_)); | |
124 } | |
125 | |
126 void TestingOmniboxView::UpdatePopup() { | |
127 ++update_popup_call_count_; | |
128 update_popup_text_ = text(); | |
129 update_popup_selection_range_ = GetSelectedRange(); | |
130 } | |
131 | |
132 void TestingOmniboxView::SetEmphasis(bool emphasize, const Range& range) { | |
133 if (range == Range::InvalidRange()) { | |
134 base_text_emphasis_ = to_emphasis(emphasize); | |
135 return; | |
136 } | |
137 | |
138 EXPECT_TRUE(emphasize); | |
139 emphasis_range_ = range; | |
140 } | |
141 | |
142 void TestingOmniboxView::UpdateSchemeStyle(const Range& range) { | |
143 scheme_range_ = range; | |
144 } | |
145 | |
146 // TestingOmniboxEditController ----------------------------------------------- | |
147 | |
109 class TestingOmniboxEditController : public ChromeOmniboxEditController { | 148 class TestingOmniboxEditController : public ChromeOmniboxEditController { |
110 public: | 149 public: |
111 explicit TestingOmniboxEditController(CommandUpdater* command_updater) | 150 explicit TestingOmniboxEditController(CommandUpdater* command_updater) |
112 : ChromeOmniboxEditController(command_updater) {} | 151 : ChromeOmniboxEditController(command_updater) {} |
113 | 152 |
114 protected: | 153 private: |
115 // ChromeOmniboxEditController: | 154 // ChromeOmniboxEditController: |
116 void UpdateWithoutTabRestore() override {} | 155 void UpdateWithoutTabRestore() override {} |
117 void OnChanged() override {} | 156 void OnChanged() override {} |
118 ToolbarModel* GetToolbarModel() override { return nullptr; } | 157 ToolbarModel* GetToolbarModel() override { return nullptr; } |
119 const ToolbarModel* GetToolbarModel() const override { return nullptr; } | 158 const ToolbarModel* GetToolbarModel() const override { return nullptr; } |
120 content::WebContents* GetWebContents() override { return nullptr; } | 159 content::WebContents* GetWebContents() override { return nullptr; } |
121 | 160 |
122 private: | |
123 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); | 161 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); |
124 }; | 162 }; |
125 | 163 |
126 } // namespace | 164 } // namespace |
127 | 165 |
166 // OmniboxViewViewsTest ------------------------------------------------------- | |
167 | |
128 class OmniboxViewViewsTest : public testing::Test { | 168 class OmniboxViewViewsTest : public testing::Test { |
129 public: | 169 public: |
130 OmniboxViewViewsTest() | 170 OmniboxViewViewsTest(); |
131 : command_updater_(NULL), | |
132 omnibox_edit_controller_(&command_updater_) { | |
133 } | |
134 | 171 |
135 TestingOmniboxViewViews* omnibox_view() { | 172 TestingOmniboxView* omnibox_view() { return omnibox_view_.get(); } |
136 return omnibox_view_.get(); | 173 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 { | 174 ui::TextEditCommand scheduled_text_edit_command() const { |
144 return test_api_->scheduled_text_edit_command(); | 175 return test_api_->scheduled_text_edit_command(); |
145 } | 176 } |
146 | 177 |
147 void SetAndEmphasizeText(const std::string& new_text) { | 178 // Sets |new_text| as the omnibox text, and emphasizes it appropriately. |
148 omnibox_textfield()->SetText(base::ASCIIToUTF16(new_text)); | 179 void SetAndEmphasizeText(const std::string& new_text); |
149 omnibox_view()->EmphasizeURLComponents(); | |
150 } | |
151 | 180 |
152 private: | 181 private: |
153 // testing::Test: | 182 // testing::Test: |
154 void SetUp() override { | 183 void SetUp() override; |
155 #if defined(OS_CHROMEOS) | 184 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 | 185 |
172 content::TestBrowserThreadBundle thread_bundle_; | 186 content::TestBrowserThreadBundle thread_bundle_; |
173 TestingProfile profile_; | 187 TestingProfile profile_; |
174 CommandUpdater command_updater_; | 188 CommandUpdater command_updater_; |
175 TestingOmniboxEditController omnibox_edit_controller_; | 189 TestingOmniboxEditController omnibox_edit_controller_; |
176 std::unique_ptr<TestingOmniboxViewViews> omnibox_view_; | 190 std::unique_ptr<TestingOmniboxView> omnibox_view_; |
177 std::unique_ptr<views::TextfieldTestApi> test_api_; | 191 std::unique_ptr<views::TextfieldTestApi> test_api_; |
178 | 192 |
179 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); | 193 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); |
180 }; | 194 }; |
181 | 195 |
196 OmniboxViewViewsTest::OmniboxViewViewsTest() | |
197 : command_updater_(nullptr), omnibox_edit_controller_(&command_updater_) {} | |
198 | |
199 void OmniboxViewViewsTest::SetAndEmphasizeText(const std::string& new_text) { | |
200 omnibox_view()->ResetEmphasisTestState(); | |
201 omnibox_view()->SetText(base::ASCIIToUTF16(new_text)); | |
202 omnibox_view()->EmphasizeURLComponents(); | |
203 } | |
204 | |
205 void OmniboxViewViewsTest::SetUp() { | |
206 #if defined(OS_CHROMEOS) | |
207 chromeos::input_method::InitializeForTesting( | |
208 new chromeos::input_method::MockInputMethodManagerImpl); | |
209 #endif | |
210 omnibox_view_ = base::MakeUnique<TestingOmniboxView>( | |
211 &omnibox_edit_controller_, &profile_, &command_updater_); | |
212 test_api_ = base::MakeUnique<views::TextfieldTestApi>(omnibox_view_.get()); | |
213 omnibox_view_->Init(); | |
214 } | |
215 | |
216 void OmniboxViewViewsTest::TearDown() { | |
217 omnibox_view_.reset(); | |
218 #if defined(OS_CHROMEOS) | |
219 chromeos::input_method::Shutdown(); | |
220 #endif | |
221 } | |
222 | |
223 // Actual tests --------------------------------------------------------------- | |
224 | |
182 // Checks that a single change of the text in the omnibox invokes | 225 // Checks that a single change of the text in the omnibox invokes |
183 // only one call to OmniboxViewViews::UpdatePopup(). | 226 // only one call to OmniboxViewViews::UpdatePopup(). |
184 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { | 227 TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { |
185 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0, | 228 ui::KeyEvent char_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, 0, |
186 ui::DomKey::FromCharacter('a'), | 229 ui::DomKey::FromCharacter('a'), |
187 ui::EventTimeForNow()); | 230 ui::EventTimeForNow()); |
188 omnibox_textfield()->InsertChar(char_event); | 231 omnibox_textfield()->InsertChar(char_event); |
189 omnibox_view()->CheckUpdatePopupCallInfo( | 232 omnibox_view()->CheckUpdatePopupCallInfo(1, base::ASCIIToUTF16("a"), |
190 1, base::ASCIIToUTF16("a"), gfx::Range(1)); | 233 Range(1)); |
191 | 234 |
192 char_event = | 235 char_event = |
193 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_B, ui::DomCode::US_B, 0, | 236 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_B, ui::DomCode::US_B, 0, |
194 ui::DomKey::FromCharacter('b'), ui::EventTimeForNow()); | 237 ui::DomKey::FromCharacter('b'), ui::EventTimeForNow()); |
195 omnibox_textfield()->InsertChar(char_event); | 238 omnibox_textfield()->InsertChar(char_event); |
196 omnibox_view()->CheckUpdatePopupCallInfo( | 239 omnibox_view()->CheckUpdatePopupCallInfo(2, base::ASCIIToUTF16("ab"), |
197 2, base::ASCIIToUTF16("ab"), gfx::Range(2)); | 240 Range(2)); |
198 | 241 |
199 ui::KeyEvent pressed(ui::ET_KEY_PRESSED, ui::VKEY_BACK, 0); | 242 ui::KeyEvent pressed(ui::ET_KEY_PRESSED, ui::VKEY_BACK, 0); |
200 omnibox_textfield()->OnKeyEvent(&pressed); | 243 omnibox_textfield()->OnKeyEvent(&pressed); |
201 omnibox_view()->CheckUpdatePopupCallInfo( | 244 omnibox_view()->CheckUpdatePopupCallInfo(3, base::ASCIIToUTF16("a"), |
202 3, base::ASCIIToUTF16("a"), gfx::Range(1)); | 245 Range(1)); |
203 } | 246 } |
204 | 247 |
205 // Test that the scheduled text edit command is cleared when Textfield receives | 248 // 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 | 249 // 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. | 250 // is always in the correct state. Test for http://crbug.com/613948. |
208 TEST_F(OmniboxViewViewsTest, ScheduledTextEditCommand) { | 251 TEST_F(OmniboxViewViewsTest, ScheduledTextEditCommand) { |
209 omnibox_textfield()->SetTextEditCommandForNextKeyEvent( | 252 omnibox_textfield()->SetTextEditCommandForNextKeyEvent( |
210 ui::TextEditCommand::MOVE_UP); | 253 ui::TextEditCommand::MOVE_UP); |
211 EXPECT_EQ(ui::TextEditCommand::MOVE_UP, scheduled_text_edit_command()); | 254 EXPECT_EQ(ui::TextEditCommand::MOVE_UP, scheduled_text_edit_command()); |
212 | 255 |
213 ui::KeyEvent up_pressed(ui::ET_KEY_PRESSED, ui::VKEY_UP, 0); | 256 ui::KeyEvent up_pressed(ui::ET_KEY_PRESSED, ui::VKEY_UP, 0); |
214 omnibox_textfield()->OnKeyEvent(&up_pressed); | 257 omnibox_textfield()->OnKeyEvent(&up_pressed); |
215 EXPECT_EQ(ui::TextEditCommand::INVALID_COMMAND, | 258 EXPECT_EQ(ui::TextEditCommand::INVALID_COMMAND, |
216 scheduled_text_edit_command()); | 259 scheduled_text_edit_command()); |
217 } | 260 } |
218 | 261 |
219 // Ensure that the scheme is emphasized for data: URLs. | 262 TEST_F(OmniboxViewViewsTest, Emphasis) { |
220 TEST_F(OmniboxViewViewsTest, TestEmphasisForDATA) { | 263 const struct { |
221 SetAndEmphasizeText("data:text/html,Hello%20World"); | 264 const char* input; |
222 EXPECT_EQ(gfx::Range(0, 4), omnibox_view()->scheme_range()); | 265 bool base_text_emphasized; |
Mark P
2017/03/07 21:10:18
nit: consider expected_ as appropriate to distingu
Peter Kasting
2017/03/08 10:57:31
Done.
| |
223 EXPECT_FALSE(omnibox_view()->base_text_is_emphasized()); | 266 Range emphasis_range; |
224 EXPECT_EQ(gfx::Range(0, 4), omnibox_view()->emphasis_range()); | 267 Range scheme_range; |
268 } test_cases[] = { | |
269 {"data:text/html,Hello%20World", false, Range(0, 4), Range(0, 4)}, | |
270 {"http://www.example.com/path/file.htm", false, Range(7, 22), | |
271 Range(0, 4)}, | |
272 {"https://www.example.com/path/file.htm", false, Range(8, 23), | |
273 Range(0, 5)}, | |
274 {"chrome-extension://ldfbacdbackkjhclmhnjabngnppnkagl", false, | |
275 Range::InvalidRange(), Range(0, 16)}, | |
276 {"nosuchscheme://opaque/string", true, Range::InvalidRange(), | |
277 Range(0, 12)}, | |
278 {"nosuchscheme:opaquestring", true, Range::InvalidRange(), Range(0, 12)}, | |
279 {"host.com/path/file", false, Range(0, 8), Range::InvalidRange()}, | |
280 {"This is plain text", true, Range::InvalidRange(), | |
281 Range::InvalidRange()}, | |
282 }; | |
283 | |
284 for (const auto& test_case : test_cases) { | |
285 SCOPED_TRACE(test_case.input); | |
286 | |
287 SetAndEmphasizeText(test_case.input); | |
288 EXPECT_EQ(TestingOmniboxView::to_emphasis(test_case.base_text_emphasized), | |
289 omnibox_view()->base_text_emphasis()); | |
290 EXPECT_EQ(test_case.emphasis_range, omnibox_view()->emphasis_range()); | |
291 EXPECT_EQ(test_case.scheme_range, omnibox_view()->scheme_range()); | |
292 } | |
225 } | 293 } |
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 |