| 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 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 "consequat. Duis aute irure" | 33 "consequat. Duis aute irure" |
| 34 " dolor in reprehenderit in voluptate velit esse cillum dolore eu " | 34 " dolor in reprehenderit in voluptate velit esse cillum dolore eu " |
| 35 "fugiat nulla pariatur." | 35 "fugiat nulla pariatur." |
| 36 " Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " | 36 " Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " |
| 37 "officia deserunt" | 37 "officia deserunt" |
| 38 " mollit anim id est laborum." | 38 " mollit anim id est laborum." |
| 39 "</div>"); | 39 "</div>"); |
| 40 Element* autosized = document().getElementById("autosized"); | 40 Element* autosized = document().getElementById("autosized"); |
| 41 EXPECT_FLOAT_EQ(16.f, | 41 EXPECT_FLOAT_EQ(16.f, |
| 42 autosized->layoutObject()->style()->specifiedFontSize()); | 42 autosized->layoutObject()->style()->specifiedFontSize()); |
| 43 // (specified font-size = 16px) * (viewport width = 800px) / (window width = 3
20px) = 40px. | 43 // (specified font-size = 16px) * (viewport width = 800px) / |
| 44 // (window width = 320px) = 40px. |
| 44 EXPECT_FLOAT_EQ(40.f, autosized->layoutObject()->style()->computedFontSize()); | 45 EXPECT_FLOAT_EQ(40.f, autosized->layoutObject()->style()->computedFontSize()); |
| 45 } | 46 } |
| 46 | 47 |
| 47 TEST_F(TextAutosizerTest, TextSizeAdjustDisablesAutosizing) { | 48 TEST_F(TextAutosizerTest, TextSizeAdjustDisablesAutosizing) { |
| 48 setBodyInnerHTML( | 49 setBodyInnerHTML( |
| 49 "<style>" | 50 "<style>" |
| 50 " html { font-size: 16px; }" | 51 " html { font-size: 16px; }" |
| 51 " body { width: 800px; margin: 0; overflow-y: hidden; }" | 52 " body { width: 800px; margin: 0; overflow-y: hidden; }" |
| 52 "</style>" | 53 "</style>" |
| 53 "<div id='textSizeAdjustAuto' style='text-size-adjust: auto;'>" | 54 "<div id='textSizeAdjustAuto' style='text-size-adjust: auto;'>" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 "consequat. Duis aute irure" | 325 "consequat. Duis aute irure" |
| 325 " dolor in reprehenderit in voluptate velit esse cillum dolore eu " | 326 " dolor in reprehenderit in voluptate velit esse cillum dolore eu " |
| 326 "fugiat nulla pariatur." | 327 "fugiat nulla pariatur." |
| 327 " Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " | 328 " Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " |
| 328 "officia deserunt" | 329 "officia deserunt" |
| 329 " mollit anim id est laborum." | 330 " mollit anim id est laborum." |
| 330 "</div>"); | 331 "</div>"); |
| 331 Element* autosized = document().getElementById("autosized"); | 332 Element* autosized = document().getElementById("autosized"); |
| 332 EXPECT_FLOAT_EQ(16.f, | 333 EXPECT_FLOAT_EQ(16.f, |
| 333 autosized->layoutObject()->style()->specifiedFontSize()); | 334 autosized->layoutObject()->style()->specifiedFontSize()); |
| 334 // 1.5 * (specified font-size = 16px) * (viewport width = 800px) / (window wid
th = 320px) = 60px. | 335 // 1.5 * (specified font-size = 16px) * (viewport width = 800px) / |
| 336 // (window width = 320px) = 60px. |
| 335 EXPECT_FLOAT_EQ(60.f, autosized->layoutObject()->style()->computedFontSize()); | 337 EXPECT_FLOAT_EQ(60.f, autosized->layoutObject()->style()->computedFontSize()); |
| 336 } | 338 } |
| 337 | 339 |
| 338 TEST_F(TextAutosizerTest, ChangingAccessibilityFontScaleFactor) { | 340 TEST_F(TextAutosizerTest, ChangingAccessibilityFontScaleFactor) { |
| 339 document().settings()->setAccessibilityFontScaleFactor(1); | 341 document().settings()->setAccessibilityFontScaleFactor(1); |
| 340 setBodyInnerHTML( | 342 setBodyInnerHTML( |
| 341 "<style>" | 343 "<style>" |
| 342 " html { font-size: 16px; }" | 344 " html { font-size: 16px; }" |
| 343 " body { width: 800px; margin: 0; overflow-y: hidden; }" | 345 " body { width: 800px; margin: 0; overflow-y: hidden; }" |
| 344 "</style>" | 346 "</style>" |
| 345 "<div id='autosized'>" | 347 "<div id='autosized'>" |
| 346 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " | 348 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " |
| 347 "eiusmod tempor" | 349 "eiusmod tempor" |
| 348 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " | 350 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " |
| 349 "veniam, quis nostrud" | 351 "veniam, quis nostrud" |
| 350 " exercitation ullamco laboris nisi ut aliquip ex ea commodo " | 352 " exercitation ullamco laboris nisi ut aliquip ex ea commodo " |
| 351 "consequat. Duis aute irure" | 353 "consequat. Duis aute irure" |
| 352 " dolor in reprehenderit in voluptate velit esse cillum dolore eu " | 354 " dolor in reprehenderit in voluptate velit esse cillum dolore eu " |
| 353 "fugiat nulla pariatur." | 355 "fugiat nulla pariatur." |
| 354 " Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " | 356 " Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " |
| 355 "officia deserunt" | 357 "officia deserunt" |
| 356 " mollit anim id est laborum." | 358 " mollit anim id est laborum." |
| 357 "</div>"); | 359 "</div>"); |
| 358 Element* autosized = document().getElementById("autosized"); | 360 Element* autosized = document().getElementById("autosized"); |
| 359 EXPECT_FLOAT_EQ(16.f, | 361 EXPECT_FLOAT_EQ(16.f, |
| 360 autosized->layoutObject()->style()->specifiedFontSize()); | 362 autosized->layoutObject()->style()->specifiedFontSize()); |
| 361 // 1.0 * (specified font-size = 16px) * (viewport width = 800px) / (window wid
th = 320px) = 40px. | 363 // 1.0 * (specified font-size = 16px) * (viewport width = 800px) / |
| 364 // (window width = 320px) = 40px. |
| 362 EXPECT_FLOAT_EQ(40.f, autosized->layoutObject()->style()->computedFontSize()); | 365 EXPECT_FLOAT_EQ(40.f, autosized->layoutObject()->style()->computedFontSize()); |
| 363 | 366 |
| 364 document().settings()->setAccessibilityFontScaleFactor(2); | 367 document().settings()->setAccessibilityFontScaleFactor(2); |
| 365 document().view()->updateAllLifecyclePhases(); | 368 document().view()->updateAllLifecyclePhases(); |
| 366 | 369 |
| 367 EXPECT_FLOAT_EQ(16.f, | 370 EXPECT_FLOAT_EQ(16.f, |
| 368 autosized->layoutObject()->style()->specifiedFontSize()); | 371 autosized->layoutObject()->style()->specifiedFontSize()); |
| 369 // 2.0 * (specified font-size = 16px) * (viewport width = 800px) / (window wid
th = 320px) = 80px. | 372 // 2.0 * (specified font-size = 16px) * (viewport width = 800px) / |
| 373 // (window width = 320px) = 80px. |
| 370 EXPECT_FLOAT_EQ(80.f, autosized->layoutObject()->style()->computedFontSize()); | 374 EXPECT_FLOAT_EQ(80.f, autosized->layoutObject()->style()->computedFontSize()); |
| 371 } | 375 } |
| 372 | 376 |
| 373 TEST_F(TextAutosizerTest, TextSizeAdjustDoesNotDisableAccessibility) { | 377 TEST_F(TextAutosizerTest, TextSizeAdjustDoesNotDisableAccessibility) { |
| 374 document().settings()->setAccessibilityFontScaleFactor(1.5); | 378 document().settings()->setAccessibilityFontScaleFactor(1.5); |
| 375 setBodyInnerHTML( | 379 setBodyInnerHTML( |
| 376 "<style>" | 380 "<style>" |
| 377 " html { font-size: 16px; }" | 381 " html { font-size: 16px; }" |
| 378 " body { width: 800px; margin: 0; overflow-y: hidden; }" | 382 " body { width: 800px; margin: 0; overflow-y: hidden; }" |
| 379 "</style>" | 383 "</style>" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 24.f, textSizeAdjustNone->layoutObject()->style()->computedFontSize()); | 415 24.f, textSizeAdjustNone->layoutObject()->style()->computedFontSize()); |
| 412 | 416 |
| 413 Element* textSizeAdjustDouble = | 417 Element* textSizeAdjustDouble = |
| 414 document().getElementById("textSizeAdjustDouble"); | 418 document().getElementById("textSizeAdjustDouble"); |
| 415 EXPECT_FLOAT_EQ( | 419 EXPECT_FLOAT_EQ( |
| 416 16.f, textSizeAdjustDouble->layoutObject()->style()->specifiedFontSize()); | 420 16.f, textSizeAdjustDouble->layoutObject()->style()->specifiedFontSize()); |
| 417 // 1.5 * (specified font-size = 16px) * (text size adjustment = 2) = 48px. | 421 // 1.5 * (specified font-size = 16px) * (text size adjustment = 2) = 48px. |
| 418 EXPECT_FLOAT_EQ( | 422 EXPECT_FLOAT_EQ( |
| 419 48.f, textSizeAdjustDouble->layoutObject()->style()->computedFontSize()); | 423 48.f, textSizeAdjustDouble->layoutObject()->style()->computedFontSize()); |
| 420 | 424 |
| 421 // Changing the accessibility font scale factor should change the adjusted siz
e. | 425 // Changing the accessibility font scale factor should change the adjusted |
| 426 // size. |
| 422 document().settings()->setAccessibilityFontScaleFactor(2); | 427 document().settings()->setAccessibilityFontScaleFactor(2); |
| 423 document().view()->updateAllLifecyclePhases(); | 428 document().view()->updateAllLifecyclePhases(); |
| 424 | 429 |
| 425 EXPECT_FLOAT_EQ( | 430 EXPECT_FLOAT_EQ( |
| 426 16.f, textSizeAdjustNone->layoutObject()->style()->specifiedFontSize()); | 431 16.f, textSizeAdjustNone->layoutObject()->style()->specifiedFontSize()); |
| 427 // 2.0 * (specified font-size = 16px) = 32px. | 432 // 2.0 * (specified font-size = 16px) = 32px. |
| 428 EXPECT_FLOAT_EQ( | 433 EXPECT_FLOAT_EQ( |
| 429 32.f, textSizeAdjustNone->layoutObject()->style()->computedFontSize()); | 434 32.f, textSizeAdjustNone->layoutObject()->style()->computedFontSize()); |
| 430 | 435 |
| 431 EXPECT_FLOAT_EQ( | 436 EXPECT_FLOAT_EQ( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 " mollit anim id est laborum." | 481 " mollit anim id est laborum." |
| 477 "</div>"); | 482 "</div>"); |
| 478 | 483 |
| 479 document().settings()->setViewportMetaEnabled(true); | 484 document().settings()->setViewportMetaEnabled(true); |
| 480 document().settings()->setDeviceScaleAdjustment(1.5f); | 485 document().settings()->setDeviceScaleAdjustment(1.5f); |
| 481 document().view()->updateAllLifecyclePhases(); | 486 document().view()->updateAllLifecyclePhases(); |
| 482 | 487 |
| 483 Element* autosized = document().getElementById("autosized"); | 488 Element* autosized = document().getElementById("autosized"); |
| 484 EXPECT_FLOAT_EQ(16.f, | 489 EXPECT_FLOAT_EQ(16.f, |
| 485 autosized->layoutObject()->style()->specifiedFontSize()); | 490 autosized->layoutObject()->style()->specifiedFontSize()); |
| 486 // (specified font-size = 16px) * (viewport width = 800px) / (window width = 3
20px) = 40px. | 491 // (specified font-size = 16px) * (viewport width = 800px) / |
| 492 // (window width = 320px) = 40px. |
| 487 // The device scale adjustment of 1.5 is ignored. | 493 // The device scale adjustment of 1.5 is ignored. |
| 488 EXPECT_FLOAT_EQ(40.f, autosized->layoutObject()->style()->computedFontSize()); | 494 EXPECT_FLOAT_EQ(40.f, autosized->layoutObject()->style()->computedFontSize()); |
| 489 | 495 |
| 490 document().settings()->setViewportMetaEnabled(false); | 496 document().settings()->setViewportMetaEnabled(false); |
| 491 document().view()->updateAllLifecyclePhases(); | 497 document().view()->updateAllLifecyclePhases(); |
| 492 | 498 |
| 493 autosized = document().getElementById("autosized"); | 499 autosized = document().getElementById("autosized"); |
| 494 EXPECT_FLOAT_EQ(16.f, | 500 EXPECT_FLOAT_EQ(16.f, |
| 495 autosized->layoutObject()->style()->specifiedFontSize()); | 501 autosized->layoutObject()->style()->specifiedFontSize()); |
| 496 // (device scale adjustment = 1.5) * (specified font-size = 16px) * (viewport
width = 800px) / (window width = 320px) = 60px. | 502 // (device scale adjustment = 1.5) * (specified font-size = 16px) * |
| 503 // (viewport width = 800px) / (window width = 320px) = 60px. |
| 497 EXPECT_FLOAT_EQ(60.f, autosized->layoutObject()->style()->computedFontSize()); | 504 EXPECT_FLOAT_EQ(60.f, autosized->layoutObject()->style()->computedFontSize()); |
| 498 } | 505 } |
| 499 | 506 |
| 500 } // namespace blink | 507 } // namespace blink |
| OLD | NEW |