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

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

Issue 2855793003: Fix RTL URL rendering in Omnibox (domain off screen on long URL). (Closed)
Patch Set: Fix comment nit. Created 3 years, 7 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
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/autocomplete_classifier_factory.h" 13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
14 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 14 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
15 #include "chrome/browser/command_updater.h" 15 #include "chrome/browser/command_updater.h"
16 #include "chrome/browser/search_engines/template_url_service_factory_test_util.h " 16 #include "chrome/browser/search_engines/template_url_service_factory_test_util.h "
17 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" 17 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h"
18 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h" 18 #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "components/omnibox/browser/omnibox_edit_model.h" 20 #include "components/omnibox/browser/omnibox_edit_model.h"
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"
28 #include "ui/gfx/geometry/vector2d.h"
29 #include "ui/gfx/render_text.h"
27 #include "ui/views/controls/textfield/textfield_test_api.h" 30 #include "ui/views/controls/textfield/textfield_test_api.h"
28 31
29 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
30 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" 33 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
31 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" 34 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h"
32 #endif 35 #endif
33 36
34 using gfx::Range; 37 using gfx::Range;
35 38
36 namespace { 39 namespace {
37 40
38 // TestingOmniboxView --------------------------------------------------------- 41 // TestingOmniboxView ---------------------------------------------------------
39 42
40 class TestingOmniboxView : public OmniboxViewViews { 43 class TestingOmniboxView : public OmniboxViewViews {
41 public: 44 public:
42 enum BaseTextEmphasis { 45 enum BaseTextEmphasis {
43 DEEMPHASIZED, 46 DEEMPHASIZED,
44 EMPHASIZED, 47 EMPHASIZED,
45 UNSET, 48 UNSET,
46 }; 49 };
47 50
48 TestingOmniboxView(OmniboxEditController* controller, 51 TestingOmniboxView(OmniboxEditController* controller,
49 std::unique_ptr<OmniboxClient> client, 52 std::unique_ptr<OmniboxClient> client,
50 CommandUpdater* command_updater); 53 CommandUpdater* command_updater);
51 54
52 static BaseTextEmphasis to_base_text_emphasis(bool emphasize) { 55 static BaseTextEmphasis to_base_text_emphasis(bool emphasize) {
53 return emphasize ? EMPHASIZED : DEEMPHASIZED; 56 return emphasize ? EMPHASIZED : DEEMPHASIZED;
54 } 57 }
55 58
59 using views::Textfield::GetRenderText;
60
56 void ResetEmphasisTestState(); 61 void ResetEmphasisTestState();
57 62
58 void CheckUpdatePopupCallInfo(size_t call_count, 63 void CheckUpdatePopupCallInfo(size_t call_count,
59 const base::string16& text, 64 const base::string16& text,
60 const Range& selection_range); 65 const Range& selection_range);
61 66
62 Range scheme_range() const { return scheme_range_; } 67 Range scheme_range() const { return scheme_range_; }
63 Range emphasis_range() const { return emphasis_range_; } 68 Range emphasis_range() const { return emphasis_range_; }
64 BaseTextEmphasis base_text_emphasis() const { return base_text_emphasis_; } 69 BaseTextEmphasis base_text_emphasis() const { return base_text_emphasis_; }
65 70
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 omnibox_textfield()->SetTextEditCommandForNextKeyEvent( 293 omnibox_textfield()->SetTextEditCommandForNextKeyEvent(
289 ui::TextEditCommand::MOVE_UP); 294 ui::TextEditCommand::MOVE_UP);
290 EXPECT_EQ(ui::TextEditCommand::MOVE_UP, scheduled_text_edit_command()); 295 EXPECT_EQ(ui::TextEditCommand::MOVE_UP, scheduled_text_edit_command());
291 296
292 ui::KeyEvent up_pressed(ui::ET_KEY_PRESSED, ui::VKEY_UP, 0); 297 ui::KeyEvent up_pressed(ui::ET_KEY_PRESSED, ui::VKEY_UP, 0);
293 omnibox_textfield()->OnKeyEvent(&up_pressed); 298 omnibox_textfield()->OnKeyEvent(&up_pressed);
294 EXPECT_EQ(ui::TextEditCommand::INVALID_COMMAND, 299 EXPECT_EQ(ui::TextEditCommand::INVALID_COMMAND,
295 scheduled_text_edit_command()); 300 scheduled_text_edit_command());
296 } 301 }
297 302
303 TEST_F(OmniboxViewViewsTest, OnBlur) {
304 // Make the Omnibox very narrow (so it couldn't fit the whole string).
305 int kOmniboxWidth = 60;
306 gfx::RenderText* render_text = omnibox_view()->GetRenderText();
307 render_text->SetDisplayRect(gfx::Rect(0, 0, kOmniboxWidth, 10));
308 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
309
310 // (In this example, uppercase Latin letters represent Hebrew letters.)
311 // The string |kContentsRtl| is equivalent to:
312 // RA.QWM/0123/abcd
313 // This is displayed as:
314 // 0123/MWQ.AR/abcd
315 // Enter focused mode, where the text should *not* be elided, and we expect
316 // SetWindowTextAndCaretPos to scroll such that the start of the string is
317 // on-screen. Because the domain is RTL, this scrolls to an offset greater
318 // than 0.
319 omnibox_view()->OnFocus();
320 const base::string16 kContentsRtl =
321 base::WideToUTF16(L"\x05e8\x05e2.\x05e7\x05d5\x05dd/0123/abcd");
322 static_cast<OmniboxView*>(omnibox_view())
323 ->SetWindowTextAndCaretPos(kContentsRtl, 0, false, false);
324 EXPECT_EQ(gfx::NO_ELIDE, render_text->elide_behavior());
325 // NOTE: Technically (depending on the font), this expectation could fail if
326 // the entire domain fits in 60 pixels. However, 60px is so small it should
327 // never happen with any font.
328 EXPECT_GT(0, render_text->GetUpdatedDisplayOffset().x());
329
330 // Now enter blurred mode, where the text should be elided to 60px. This means
331 // the string itself is truncated. Scrolling would therefore mean the text is
332 // off-screen. Ensure that the horizontal scrolling has been reset to 0.
333 omnibox_view()->OnBlur();
334 EXPECT_EQ(gfx::ELIDE_TAIL, render_text->elide_behavior());
335 EXPECT_EQ(0, render_text->GetUpdatedDisplayOffset().x());
336 }
337
298 TEST_F(OmniboxViewViewsTest, Emphasis) { 338 TEST_F(OmniboxViewViewsTest, Emphasis) {
299 constexpr struct { 339 constexpr struct {
300 const char* input; 340 const char* input;
301 bool expected_base_text_emphasized; 341 bool expected_base_text_emphasized;
302 Range expected_emphasis_range; 342 Range expected_emphasis_range;
303 Range expected_scheme_range; 343 Range expected_scheme_range;
304 } test_cases[] = { 344 } test_cases[] = {
305 {"data:text/html,Hello%20World", false, Range(0, 4), Range(0, 4)}, 345 {"data:text/html,Hello%20World", false, Range(0, 4), Range(0, 4)},
306 {"http://www.example.com/path/file.htm", false, Range(7, 22), 346 {"http://www.example.com/path/file.htm", false, Range(7, 22),
307 Range(0, 4)}, 347 Range(0, 4)},
(...skipping 25 matching lines...) Expand all
333 EXPECT_EQ(TestingOmniboxView::to_base_text_emphasis( 373 EXPECT_EQ(TestingOmniboxView::to_base_text_emphasis(
334 test_case.expected_base_text_emphasized), 374 test_case.expected_base_text_emphasized),
335 omnibox_view()->base_text_emphasis()); 375 omnibox_view()->base_text_emphasis());
336 EXPECT_EQ(test_case.expected_emphasis_range, 376 EXPECT_EQ(test_case.expected_emphasis_range,
337 omnibox_view()->emphasis_range()); 377 omnibox_view()->emphasis_range());
338 EXPECT_EQ(test_case.expected_scheme_range, 378 EXPECT_EQ(test_case.expected_scheme_range,
339 omnibox_view()->scheme_range()); 379 omnibox_view()->scheme_range());
340 } 380 }
341 } 381 }
342 } 382 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698