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

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 2817403002: [Omnibox] Elide omnibox text (Closed)
Patch Set: Add line invalidation test on OSX Created 3 years, 8 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
« ui/gfx/render_text.h ('K') | « ui/gfx/render_text_harfbuzz.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 const Font& font, 527 const Font& font,
528 const FontRenderParams& params, 528 const FontRenderParams& params,
529 internal::TextRunHarfBuzz* run) { 529 internal::TextRunHarfBuzz* run) {
530 return GetRenderTextHarfBuzz()->ShapeRunWithFont(text, font, params, run); 530 return GetRenderTextHarfBuzz()->ShapeRunWithFont(text, font, params, run);
531 } 531 }
532 532
533 int GetCursorYForTesting(int line_num = 0) { 533 int GetCursorYForTesting(int line_num = 0) {
534 return GetRenderText()->GetLineOffset(line_num).y() + 1; 534 return GetRenderText()->GetLineOffset(line_num).y() + 1;
535 } 535 }
536 536
537 void EnsureLayoutRunList() { GetRenderTextHarfBuzz()->EnsureLayoutRunList(); }
msw 2017/04/18 17:23:44 nit: remove this, just call |test_api()->EnsureLay
simonhong 2017/04/18 19:56:02 For emptiness test, this is added. When EnsureLayo
msw 2017/04/18 20:13:02 Oh, hmm... I suppose this is okay, but it would al
538
537 private: 539 private:
538 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest); 540 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest);
539 }; 541 };
540 542
541 #if defined(OS_MACOSX) 543 #if defined(OS_MACOSX)
542 // Test fixture class. Use for tests which are only to be run for RenderTextMac. 544 // Test fixture class. Use for tests which are only to be run for RenderTextMac.
543 class RenderTextMacTest : public RenderTextTest { 545 class RenderTextMacTest : public RenderTextTest {
544 public: 546 public:
545 RenderTextMacTest() {} 547 RenderTextMacTest() {}
546 548
(...skipping 3409 matching lines...) Expand 10 before | Expand all | Expand 10 after
3956 static_cast<size_t>(CTLineGetGlyphCount(GetCoreTextLine()))); 3958 static_cast<size_t>(CTLineGetGlyphCount(GetCoreTextLine())));
3957 3959
3958 render_text->SetElideBehavior(ELIDE_TAIL); 3960 render_text->SetElideBehavior(ELIDE_TAIL);
3959 string_size.set_width(string_size.width() / 2); 3961 string_size.set_width(string_size.width() / 2);
3960 render_text->SetDisplayRect(Rect(string_size)); 3962 render_text->SetDisplayRect(Rect(string_size));
3961 test_api()->EnsureLayout(); 3963 test_api()->EnsureLayout();
3962 CFIndex glyph_count = CTLineGetGlyphCount(GetCoreTextLine()); 3964 CFIndex glyph_count = CTLineGetGlyphCount(GetCoreTextLine());
3963 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); 3965 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count));
3964 EXPECT_NE(0, glyph_count); 3966 EXPECT_NE(0, glyph_count);
3965 } 3967 }
3968
3969 TEST_P(RenderTextMacTest, LinesInvalidationOnElideBehaviorChange) {
3970 RenderTextMac* render_text = GetRenderTextMac();
3971 render_text->SetText(ASCIIToUTF16("This is an example"));
3972 test_api()->EnsureLayout();
3973 EXPECT_TRUE(GetCoreTextLine());
3974
3975 // Lines are cleared when elide behavior changes.
3976 render_text->SetElideBehavior(gfx::ELIDE_TAIL);
3977 EXPECT_FALSE(GetCoreTextLine());
3978 }
3966 #endif // defined(OS_MACOSX) 3979 #endif // defined(OS_MACOSX)
3967 3980
3968 // Ensure color changes are picked up by the RenderText implementation. 3981 // Ensure color changes are picked up by the RenderText implementation.
3969 TEST_P(RenderTextTest, ColorChange) { 3982 TEST_P(RenderTextTest, ColorChange) {
3970 RenderText* render_text = GetRenderText(); 3983 RenderText* render_text = GetRenderText();
3971 render_text->SetText(ASCIIToUTF16("x")); 3984 render_text->SetText(ASCIIToUTF16("x"));
3972 DrawVisualText(); 3985 DrawVisualText();
3973 3986
3974 std::vector<TestSkiaTextRenderer::TextLog> text_log; 3987 std::vector<TestSkiaTextRenderer::TextLog> text_log;
3975 renderer()->GetTextLogAndReset(&text_log); 3988 renderer()->GetTextLogAndReset(&text_log);
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
4402 #endif 4415 #endif
4403 const std::string font_name = "invalid_font"; 4416 const std::string font_name = "invalid_font";
4404 const int kFontSize = 13; 4417 const int kFontSize = 13;
4405 RenderText* render_text = GetRenderText(); 4418 RenderText* render_text = GetRenderText();
4406 render_text->SetFontList(FontList(Font(font_name, kFontSize))); 4419 render_text->SetFontList(FontList(Font(font_name, kFontSize)));
4407 render_text->SetText(ASCIIToUTF16("abc")); 4420 render_text->SetText(ASCIIToUTF16("abc"));
4408 4421
4409 DrawVisualText(); 4422 DrawVisualText();
4410 } 4423 }
4411 4424
4425 TEST_P(RenderTextHarfBuzzTest, LinesInvalidationOnElideBehaviorChange) {
4426 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
4427 render_text->SetText(ASCIIToUTF16("This is an example"));
4428 test_api()->EnsureLayout();
4429 EXPECT_FALSE(test_api()->lines().empty());
4430
4431 // Lines are cleared when elide behavior changes.
4432 render_text->SetElideBehavior(gfx::ELIDE_TAIL);
4433 EnsureLayoutRunList();
4434 EXPECT_TRUE(test_api()->lines().empty());
4435 }
4436
4412 // Ensures that text is centered vertically and consistently when either the 4437 // Ensures that text is centered vertically and consistently when either the
4413 // display rectangle height changes, or when the minimum line height changes. 4438 // display rectangle height changes, or when the minimum line height changes.
4414 // The difference between the two is the selection rectangle, which should match 4439 // The difference between the two is the selection rectangle, which should match
4415 // the line height. 4440 // the line height.
4416 TEST_P(RenderTextHarfBuzzTest, BaselineWithLineHeight) { 4441 TEST_P(RenderTextHarfBuzzTest, BaselineWithLineHeight) {
4417 RenderText* render_text = GetRenderText(); 4442 RenderText* render_text = GetRenderText();
4418 const int font_height = render_text->font_list().GetHeight(); 4443 const int font_height = render_text->font_list().GetHeight();
4419 render_text->SetDisplayRect(Rect(500, font_height)); 4444 render_text->SetDisplayRect(Rect(500, font_height));
4420 render_text->SetText(ASCIIToUTF16("abc")); 4445 render_text->SetText(ASCIIToUTF16("abc"));
4421 4446
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
4521 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4546 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4522 PrintRenderTextBackend()); 4547 PrintRenderTextBackend());
4523 #endif 4548 #endif
4524 4549
4525 INSTANTIATE_TEST_CASE_P(, 4550 INSTANTIATE_TEST_CASE_P(,
4526 RenderTextHarfBuzzTest, 4551 RenderTextHarfBuzzTest,
4527 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4552 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4528 PrintRenderTextBackend()); 4553 PrintRenderTextBackend());
4529 4554
4530 } // namespace gfx 4555 } // namespace gfx
OLDNEW
« ui/gfx/render_text.h ('K') | « ui/gfx/render_text_harfbuzz.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698