OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/layout/LayoutObject.h" | 5 #include "core/layout/LayoutObject.h" |
6 #include "core/layout/LayoutTestHelper.h" | 6 #include "core/layout/LayoutTestHelper.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | |
11 class TextAutosizerTest : public RenderingTest { | 10 class TextAutosizerTest : public RenderingTest { |
12 private: | 11 private: |
13 void SetUp() override { | 12 void SetUp() override { |
14 RenderingTest::SetUp(); | 13 RenderingTest::SetUp(); |
15 document().settings()->setTextAutosizingEnabled(true); | 14 document().settings()->setTextAutosizingEnabled(true); |
16 document().settings()->setTextAutosizingWindowSizeOverride( | 15 document().settings()->setTextAutosizingWindowSizeOverride( |
17 IntSize(320, 480)); | 16 IntSize(320, 480)); |
18 } | 17 } |
19 }; | 18 }; |
20 | 19 |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 document().getElementById("longText")->layoutObject(); | 653 document().getElementById("longText")->layoutObject(); |
655 EXPECT_FLOAT_EQ(16.f, longText->style()->specifiedFontSize()); | 654 EXPECT_FLOAT_EQ(16.f, longText->style()->specifiedFontSize()); |
656 //(specified font-size = 16px) * (block width = 560px) / | 655 //(specified font-size = 16px) * (block width = 560px) / |
657 // (window width = 320px) = 28px. | 656 // (window width = 320px) = 28px. |
658 EXPECT_FLOAT_EQ(28.f, longText->style()->computedFontSize()); | 657 EXPECT_FLOAT_EQ(28.f, longText->style()->computedFontSize()); |
659 LayoutObject* shortText = | 658 LayoutObject* shortText = |
660 document().getElementById("shortText")->layoutObject(); | 659 document().getElementById("shortText")->layoutObject(); |
661 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); | 660 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); |
662 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); | 661 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); |
663 } | 662 } |
663 | |
664 TEST_F(TextAutosizerTest, AutosizeInnerContentOfRuby) { | |
665 setBodyInnerHTML( | |
666 "<meta name='viewport' content='width=800'>" | |
667 "<style>" | |
668 " html { font-size: 16px; }" | |
669 " body { width: 800px; margin: 0; overflow-y: hidden; }" | |
670 "</style>" | |
671 "<div id='autosized'>" | |
672 " 東京特許許可局許可局長 今日" | |
673 " <ruby>" | |
674 " <rb id='rubyInline'>急遽</rb>" | |
675 " <rp>(</rp>" | |
676 " <rt>きゅうきょ</rt>" | |
677 " <rp>)</rp>" | |
678 " </ruby>" | |
679 " 許可却下、<br><br>" | |
680 " <span>" | |
681 " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec " | |
682 " sed diam facilisis, elementum elit at, elementum sem. Aliquam " | |
683 " consectetur leo at nisi fermentum, vitae maximus libero " | |
684 "sodales. Sed " | |
685 " laoreet congue ipsum, at tincidunt ante tempor sed. Cras eget " | |
686 "erat " | |
687 " mattis urna vestibulum porta. Sed tempus vitae dui et suscipit. " | |
688 " Curabitur laoreet accumsan pharetra. Nunc facilisis, elit sit " | |
689 "amet " | |
690 " sollicitudin condimentum, ipsum velit ultricies mi, eget " | |
691 "dapibus nunc " | |
692 " nulla nec sapien. Fusce dictum imperdiet aliquet." | |
693 " </span>" | |
694 " <ruby style='display:block'>" | |
695 " <rb id='rubyBlock'>拼音</rb>" | |
696 " <rt>pin yin</rt>" | |
697 " </ruby>" | |
698 "</div>"); | |
699 document().view()->updateAllLifecyclePhases(); | |
700 | |
701 Element* rubyInline = document().getElementById("rubyInline"); | |
702 EXPECT_FLOAT_EQ(16.f, | |
703 rubyInline->layoutObject()->style()->specifiedFontSize()); | |
704 // (specified font-size = 16px) * (viewport width = 800px) / | |
705 // (window width = 320px) = 40px. | |
706 EXPECT_FLOAT_EQ(40.f, | |
707 rubyInline->layoutObject()->style()->computedFontSize()); | |
708 | |
709 Element* rubyBlock = document().getElementById("rubyBlock"); | |
710 EXPECT_FLOAT_EQ(16.f, | |
711 rubyBlock->layoutObject()->style()->specifiedFontSize()); | |
712 // (specified font-size = 16px) * (viewport width = 800px) / | |
713 // (window width = 320px) = 40px. | |
714 EXPECT_FLOAT_EQ(40.f, rubyBlock->layoutObject()->style()->computedFontSize()); | |
715 } | |
716 | |
717 TEST_F(TextAutosizerTest, ResizeRubyPage) { | |
cathiechentx
2017/02/13 14:53:56
To produce DCHECK fail in LayoutText, we should us
| |
718 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(360, 640)); | |
719 Element* html = document().body()->parentElement(); | |
720 html->setInnerHTML( | |
721 "<head>" | |
722 " <meta name='viewport' content='width=800'>" | |
723 " <style>" | |
724 " html { font-size: 16px; }" | |
725 " body { width: 784px; margin: 0;}" | |
726 " </style>" | |
727 "</head>" | |
728 "<body>" | |
729 " <ruby id='ruby'>" | |
730 " <rb id='rubyInline'>急遽</rb>" | |
731 " <rt>きゅうきょ</rt>" | |
732 " </ruby>" | |
733 " <span>" | |
734 " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec " | |
735 " sed diam facilisis, elementum elit at, elementum sem. Aliquam " | |
736 " consectetur leo at nisi fermentum, vitae maximus libero " | |
737 "sodales. Sed " | |
738 " laoreet congue ipsum, at tincidunt ante tempor sed. Cras eget " | |
739 "erat " | |
740 " mattis urna vestibulum porta. Sed tempus vitae dui et suscipit. " | |
741 " Curabitur laoreet accumsan pharetra. Nunc facilisis, elit sit " | |
742 "amet " | |
743 " sollicitudin condimentum, ipsum velit ultricies mi, eget " | |
744 "dapibus nunc " | |
745 " nulla nec sapien. Fusce dictum imperdiet aliquet." | |
746 " </span>" | |
747 " <ruby style='display:block'>" | |
748 " <rb id='rubyBlock'>拼音</rb>" | |
749 " <rt>pin yin</rt>" | |
750 " </ruby>" | |
751 "</body>", | |
752 ASSERT_NO_EXCEPTION); | |
753 document().view()->updateAllLifecyclePhases(); | |
754 | |
755 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(640, 360)); | |
756 document().view()->updateAllLifecyclePhases(); | |
757 } | |
664 } // namespace blink | 758 } // namespace blink |
OLD | NEW |