OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "bindings/core/v8/ScriptController.h" | 5 #include "bindings/core/v8/ScriptController.h" |
6 #include "core/dom/Document.h" | 6 #include "core/dom/Document.h" |
7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "core/html/HTMLIFrameElement.h" | 10 #include "core/html/HTMLIFrameElement.h" |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 "<style> html { background-image: linear-gradient(red, blue); " | 459 "<style> html { background-image: linear-gradient(red, blue); " |
460 "background-attachment: fixed; } </style>"); | 460 "background-attachment: fixed; } </style>"); |
461 | 461 |
462 // Move the frame offscreen to throttle it. | 462 // Move the frame offscreen to throttle it. |
463 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")); | 463 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")); |
464 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 464 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
465 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); | 465 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); |
466 compositeFrame(); | 466 compositeFrame(); |
467 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | 467 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); |
468 | 468 |
469 // Change style of the frame's content to make it in VisualUpdatePending state
. | 469 // Change style of the frame's content to make it in VisualUpdatePending |
| 470 // state. |
470 frameElement->contentDocument()->body()->setAttribute(styleAttr, | 471 frameElement->contentDocument()->body()->setAttribute(styleAttr, |
471 "background: green"); | 472 "background: green"); |
472 // Change root frame's layout so that the next lifecycle update will call | 473 // Change root frame's layout so that the next lifecycle update will call |
473 // ScrollingCoordinator::updateAfterCompositingChangeIfNeeded(). | 474 // ScrollingCoordinator::updateAfterCompositingChangeIfNeeded(). |
474 document().body()->setAttribute(styleAttr, "margin: 20px"); | 475 document().body()->setAttribute(styleAttr, "margin: 20px"); |
475 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, | 476 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, |
476 frameElement->contentDocument()->lifecycle().state()); | 477 frameElement->contentDocument()->lifecycle().state()); |
477 | 478 |
478 DocumentLifecycle::AllowThrottlingScope throttlingScope( | 479 DocumentLifecycle::AllowThrottlingScope throttlingScope( |
479 document().lifecycle()); | 480 document().lifecycle()); |
480 // This will call ScrollingCoordinator::updateAfterCompositingChangeIfNeeded()
and should not | 481 // This will call ScrollingCoordinator::updateAfterCompositingChangeIfNeeded() |
481 // cause assert failure about isAllowedToQueryCompositingState() in the thrott
led frame. | 482 // and should not cause assert failure about |
| 483 // isAllowedToQueryCompositingState() in the throttled frame. |
482 document().view()->updateAllLifecyclePhases(); | 484 document().view()->updateAllLifecyclePhases(); |
483 testing::runPendingTasks(); | 485 testing::runPendingTasks(); |
484 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, | 486 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, |
485 frameElement->contentDocument()->lifecycle().state()); | 487 frameElement->contentDocument()->lifecycle().state()); |
486 // The fixed background in the throttled sub frame should not cause main threa
d scrolling. | 488 // The fixed background in the throttled sub frame should not cause main |
| 489 // thread scrolling. |
487 EXPECT_FALSE(document().view()->shouldScrollOnMainThread()); | 490 EXPECT_FALSE(document().view()->shouldScrollOnMainThread()); |
488 | 491 |
489 // Make the frame visible by changing its transform. This doesn't cause a | 492 // Make the frame visible by changing its transform. This doesn't cause a |
490 // layout, but should still unthrottle the frame. | 493 // layout, but should still unthrottle the frame. |
491 frameElement->setAttribute(styleAttr, "transform: translateY(0px)"); | 494 frameElement->setAttribute(styleAttr, "transform: translateY(0px)"); |
492 compositeFrame(); | 495 compositeFrame(); |
493 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); | 496 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); |
494 // The fixed background in the throttled sub frame should be considered. | 497 // The fixed background in the throttled sub frame should be considered. |
495 EXPECT_TRUE(document().view()->shouldScrollOnMainThread()); | 498 EXPECT_TRUE(document().view()->shouldScrollOnMainThread()); |
496 } | 499 } |
(...skipping 15 matching lines...) Expand all Loading... |
512 "<div id=div style='transform: translateZ(0)' ontouchstart='foo()'>touch " | 515 "<div id=div style='transform: translateZ(0)' ontouchstart='foo()'>touch " |
513 "handler</div>"); | 516 "handler</div>"); |
514 | 517 |
515 // Move the frame offscreen to throttle it. | 518 // Move the frame offscreen to throttle it. |
516 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")); | 519 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")); |
517 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 520 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
518 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); | 521 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); |
519 compositeFrame(); | 522 compositeFrame(); |
520 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | 523 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); |
521 | 524 |
522 // Change style of the frame's content to make it in VisualUpdatePending state
. | 525 // Change style of the frame's content to make it in VisualUpdatePending |
| 526 // state. |
523 frameElement->contentDocument()->body()->setAttribute(styleAttr, | 527 frameElement->contentDocument()->body()->setAttribute(styleAttr, |
524 "background: green"); | 528 "background: green"); |
525 // Change root frame's layout so that the next lifecycle update will call | 529 // Change root frame's layout so that the next lifecycle update will call |
526 // ScrollingCoordinator::updateAfterCompositingChangeIfNeeded(). | 530 // ScrollingCoordinator::updateAfterCompositingChangeIfNeeded(). |
527 document().body()->setAttribute(styleAttr, "margin: 20px"); | 531 document().body()->setAttribute(styleAttr, "margin: 20px"); |
528 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, | 532 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, |
529 frameElement->contentDocument()->lifecycle().state()); | 533 frameElement->contentDocument()->lifecycle().state()); |
530 | 534 |
531 DocumentLifecycle::AllowThrottlingScope throttlingScope( | 535 DocumentLifecycle::AllowThrottlingScope throttlingScope( |
532 document().lifecycle()); | 536 document().lifecycle()); |
533 // This will call ScrollingCoordinator::updateAfterCompositingChangeIfNeeded()
and should not | 537 // This will call ScrollingCoordinator::updateAfterCompositingChangeIfNeeded() |
534 // cause assert failure about isAllowedToQueryCompositingState() in the thrott
led frame. | 538 // and should not cause assert failure about |
| 539 // isAllowedToQueryCompositingState() in the throttled frame. |
535 document().view()->updateAllLifecyclePhases(); | 540 document().view()->updateAllLifecyclePhases(); |
536 testing::runPendingTasks(); | 541 testing::runPendingTasks(); |
537 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, | 542 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, |
538 frameElement->contentDocument()->lifecycle().state()); | 543 frameElement->contentDocument()->lifecycle().state()); |
539 } | 544 } |
540 | 545 |
541 TEST_F(FrameThrottlingTest, | 546 TEST_F(FrameThrottlingTest, |
542 ScrollingCoordinatorShouldSkipCompositedThrottledFrame) { | 547 ScrollingCoordinatorShouldSkipCompositedThrottledFrame) { |
543 webView().settings()->setAcceleratedCompositingEnabled(true); | 548 webView().settings()->setAcceleratedCompositingEnabled(true); |
544 webView().settings()->setPreferCompositingToLCDTextEnabled(true); | 549 webView().settings()->setPreferCompositingToLCDTextEnabled(true); |
545 | 550 |
546 // Create a hidden frame which is throttled. | 551 // Create a hidden frame which is throttled. |
547 SimRequest mainResource("https://example.com/", "text/html"); | 552 SimRequest mainResource("https://example.com/", "text/html"); |
548 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 553 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
549 | 554 |
550 loadURL("https://example.com/"); | 555 loadURL("https://example.com/"); |
551 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); | 556 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); |
552 frameResource.complete("<div style='height: 2000px'></div>"); | 557 frameResource.complete("<div style='height: 2000px'></div>"); |
553 | 558 |
554 // Move the frame offscreen to throttle it. | 559 // Move the frame offscreen to throttle it. |
555 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")); | 560 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")); |
556 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 561 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
557 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); | 562 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); |
558 compositeFrame(); | 563 compositeFrame(); |
559 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | 564 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); |
560 | 565 |
561 // Change style of the frame's content to make it in VisualUpdatePending state
. | 566 // Change style of the frame's content to make it in VisualUpdatePending |
| 567 // state. |
562 frameElement->contentDocument()->body()->setAttribute(styleAttr, | 568 frameElement->contentDocument()->body()->setAttribute(styleAttr, |
563 "background: green"); | 569 "background: green"); |
564 // Change root frame's layout so that the next lifecycle update will call | 570 // Change root frame's layout so that the next lifecycle update will call |
565 // ScrollingCoordinator::updateAfterCompositingChangeIfNeeded(). | 571 // ScrollingCoordinator::updateAfterCompositingChangeIfNeeded(). |
566 document().body()->setAttribute(styleAttr, "margin: 20px"); | 572 document().body()->setAttribute(styleAttr, "margin: 20px"); |
567 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, | 573 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, |
568 frameElement->contentDocument()->lifecycle().state()); | 574 frameElement->contentDocument()->lifecycle().state()); |
569 | 575 |
570 DocumentLifecycle::AllowThrottlingScope throttlingScope( | 576 DocumentLifecycle::AllowThrottlingScope throttlingScope( |
571 document().lifecycle()); | 577 document().lifecycle()); |
572 // This will call ScrollingCoordinator::updateAfterCompositingChangeIfNeeded()
and should not | 578 // This will call ScrollingCoordinator::updateAfterCompositingChangeIfNeeded() |
573 // cause assert failure about isAllowedToQueryCompositingState() in the thrott
led frame. | 579 // and should not cause assert failure about |
| 580 // isAllowedToQueryCompositingState() in the throttled frame. |
574 compositeFrame(); | 581 compositeFrame(); |
575 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, | 582 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, |
576 frameElement->contentDocument()->lifecycle().state()); | 583 frameElement->contentDocument()->lifecycle().state()); |
577 | 584 |
578 // Make the frame visible by changing its transform. This doesn't cause a | 585 // Make the frame visible by changing its transform. This doesn't cause a |
579 // layout, but should still unthrottle the frame. | 586 // layout, but should still unthrottle the frame. |
580 frameElement->setAttribute(styleAttr, "transform: translateY(0px)"); | 587 frameElement->setAttribute(styleAttr, "transform: translateY(0px)"); |
581 compositeFrame(); // Unthrottle the frame. | 588 compositeFrame(); // Unthrottle the frame. |
582 compositeFrame(); // Handle the pending visual update of the unthrottled fram
e. | 589 compositeFrame(); // Handle the pending visual update of the unthrottled |
| 590 // frame. |
583 EXPECT_EQ(DocumentLifecycle::PaintClean, | 591 EXPECT_EQ(DocumentLifecycle::PaintClean, |
584 frameElement->contentDocument()->lifecycle().state()); | 592 frameElement->contentDocument()->lifecycle().state()); |
585 EXPECT_TRUE( | 593 EXPECT_TRUE( |
586 frameElement->contentDocument()->view()->usesCompositedScrolling()); | 594 frameElement->contentDocument()->view()->usesCompositedScrolling()); |
587 } | 595 } |
588 | 596 |
589 TEST_F(FrameThrottlingTest, UnthrottleByTransformingWithoutLayout) { | 597 TEST_F(FrameThrottlingTest, UnthrottleByTransformingWithoutLayout) { |
590 webView().settings()->setAcceleratedCompositingEnabled(true); | 598 webView().settings()->setAcceleratedCompositingEnabled(true); |
591 | 599 |
592 // Create a hidden frame which is throttled. | 600 // Create a hidden frame which is throttled. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 compositeFrame(); // Unthrottle the frame. | 652 compositeFrame(); // Unthrottle the frame. |
645 compositeFrame(); // Update touch handler regions. | 653 compositeFrame(); // Update touch handler regions. |
646 EXPECT_EQ(1u, touchHandlerRegionSize()); | 654 EXPECT_EQ(1u, touchHandlerRegionSize()); |
647 } | 655 } |
648 | 656 |
649 TEST_F(FrameThrottlingTest, ThrottledEventHandlerIgnored) { | 657 TEST_F(FrameThrottlingTest, ThrottledEventHandlerIgnored) { |
650 webView().settings()->setAcceleratedCompositingEnabled(true); | 658 webView().settings()->setAcceleratedCompositingEnabled(true); |
651 webView().settings()->setJavaScriptEnabled(true); | 659 webView().settings()->setJavaScriptEnabled(true); |
652 EXPECT_EQ(0u, touchHandlerRegionSize()); | 660 EXPECT_EQ(0u, touchHandlerRegionSize()); |
653 | 661 |
654 // Create a frame which is throttled and has a non-top-level touchstart handle
r. | 662 // Create a frame which is throttled and has a non-top-level touchstart |
| 663 // handler. |
655 SimRequest mainResource("https://example.com/", "text/html"); | 664 SimRequest mainResource("https://example.com/", "text/html"); |
656 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 665 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
657 | 666 |
658 loadURL("https://example.com/"); | 667 loadURL("https://example.com/"); |
659 mainResource.complete( | 668 mainResource.complete( |
660 "<iframe id=frame sandbox=allow-scripts src=iframe.html></iframe>"); | 669 "<iframe id=frame sandbox=allow-scripts src=iframe.html></iframe>"); |
661 frameResource.complete( | 670 frameResource.complete( |
662 "<div id=d>touch handler</div>" | 671 "<div id=d>touch handler</div>" |
663 "<script>" | 672 "<script>" |
664 "document.querySelector('#d').addEventListener('touchstart', " | 673 "document.querySelector('#d').addEventListener('touchstart', " |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 localFrame->script().executeScriptInMainWorld( | 868 localFrame->script().executeScriptInMainWorld( |
860 "window.requestAnimationFrame(function() {\n" | 869 "window.requestAnimationFrame(function() {\n" |
861 " var throttledFrame = window.parent.frames.first;\n" | 870 " var throttledFrame = window.parent.frames.first;\n" |
862 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" | 871 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" |
863 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\n" | 872 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\n" |
864 "});\n"); | 873 "});\n"); |
865 compositeFrame(); | 874 compositeFrame(); |
866 } | 875 } |
867 | 876 |
868 } // namespace blink | 877 } // namespace blink |
OLD | NEW |