Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/frame/FrameView.h" | |
| 6 #include "core/layout/LayoutView.h" | |
| 7 #include "core/paint/PaintLayer.h" | |
| 8 #include "core/paint/PaintLayerScrollableArea.h" | |
| 9 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | |
| 10 #include "platform/testing/TestingPlatformSupport.h" | |
| 11 #include "platform/testing/UnitTestHelpers.h" | |
| 12 #include "public/web/WebScriptSource.h" | |
| 13 #include "public/web/WebSettings.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #include "web/WebLocalFrameImpl.h" | |
| 16 #include "web/tests/sim/SimDisplayItemList.h" | |
| 17 #include "web/tests/sim/SimRequest.h" | |
| 18 #include "web/tests/sim/SimTest.h" | |
| 19 | |
| 20 namespace blink { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 void enableViewport(WebSettings* settings) { | |
| 25 settings->setViewportEnabled(true); | |
| 26 } | |
| 27 | |
| 28 class PaintInvalidationTest : public SimTest { | |
| 29 public: | |
| 30 PaintInvalidationTest() : SimTest(enableViewport) | |
| 31 { } | |
| 32 | |
| 33 protected: | |
| 34 bool invalidationArrayContains(JSONArray* invalidations, LayoutObject& object) { | |
|
pdr.
2017/02/23 18:24:33
This unittest is basically equivalent to a layout
bokan
2017/02/23 18:41:17
I don't mind deleting it if I can (I feel bad havi
pdr.
2017/02/23 19:42:07
Do we need to run the full lifecycle though? In ot
| |
| 35 for (size_t i = 0; i < invalidations->size(); ++i) { | |
| 36 JSONValue* value = invalidations->at(i); | |
| 37 if (!value) | |
| 38 continue; | |
| 39 | |
| 40 if (value->getType() != JSONValue::TypeObject) | |
| 41 continue; | |
| 42 | |
| 43 JSONObject* invalidationPair = JSONObject::cast(value); | |
| 44 DCHECK(invalidationPair); | |
| 45 JSONValue* name = invalidationPair->get("object"); | |
| 46 if (name && name->getType() == JSONValue::TypeString) { | |
| 47 String nameString; | |
| 48 name->asString(&nameString); | |
| 49 if (nameString == object.debugName()) | |
| 50 return true; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 return false; | |
| 55 } | |
| 56 }; | |
| 57 | |
| 58 class NoCompositingPlatform : public TestingPlatformSupport { | |
| 59 public: | |
| 60 NoCompositingPlatform() {} | |
| 61 ~NoCompositingPlatform() override {} | |
| 62 bool isThreadedAnimationEnabled() override { return false; } | |
| 63 | |
| 64 private: | |
| 65 DISALLOW_COPY_AND_ASSIGN(NoCompositingPlatform); | |
| 66 }; | |
| 67 | |
| 68 TEST_F(PaintInvalidationTest, AnimatedTransformOverflowInvalidatesBackground) { | |
| 69 // SimCompositor doesn't yet support animations ticked on the compositor so | |
| 70 // ensure we tick it on the main thread. | |
| 71 ScopedTestingPlatformSupport<NoCompositingPlatform> platform; | |
| 72 | |
| 73 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | |
| 74 webView().resize(WebSize(800, 600)); | |
| 75 SimRequest request("https://example.com/test.html", "text/html"); | |
| 76 loadURL("https://example.com/test.html"); | |
| 77 request.complete( | |
| 78 "<!DOCTYPE html>" | |
| 79 "<style type='text/css'>" | |
| 80 " body, html {" | |
| 81 " width: 95%;" | |
| 82 " height: 95%;" | |
| 83 " margin: 0px;" | |
| 84 " }" | |
| 85 " #container {" | |
| 86 " width: 100%;" | |
| 87 " height: 100%;" | |
| 88 " transform-origin: 0% 100%;" | |
| 89 " transform: rotateZ(0);" | |
| 90 " transition: transform 1s;" | |
| 91 " background-color: red;" | |
| 92 " }" | |
| 93 " #container.tilted {" | |
| 94 " transform: rotateZ(45deg);" | |
| 95 " }" | |
| 96 "</style>" | |
| 97 "<div id='container'></div>"); | |
| 98 | |
| 99 ScrollableArea* scrollableArea = document().view(); | |
| 100 compositor().beginFrame(); | |
| 101 ASSERT_EQ(scrollableArea->maximumScrollOffset().height(), 0); | |
| 102 | |
| 103 // Apply the tilted class so that the animated transition begins. | |
| 104 mainFrame().executeScript(WebScriptSource( | |
| 105 "document.querySelector('#container').className = 'tilted';")); | |
| 106 | |
| 107 // Tick one frame to ensure the animation is started. | |
| 108 document().updateStyleAndLayoutTreeIgnorePendingStylesheets(); | |
| 109 compositor().beginFrame(); | |
| 110 | |
| 111 // Reset paint invalidation tracking. | |
| 112 document().view()->setTracksPaintInvalidations(false); | |
| 113 document().view()->setTracksPaintInvalidations(true); | |
| 114 | |
| 115 // Tick ahead about half way through the animation. The animation isn't | |
| 116 // finished but it should have caused overflow to be added so the main frame | |
| 117 // is scrollable. | |
| 118 document().updateStyleAndLayoutTreeIgnorePendingStylesheets(); | |
| 119 compositor().beginFrame(0.5); | |
| 120 ASSERT_GT(scrollableArea->maximumScrollOffset().height(), 100); | |
| 121 | |
| 122 // Ensure that we invalidated the LayoutView due to the new overflow so that | |
| 123 // scrolling it into the viewport doesn't expose an unpainted region. | |
| 124 std::unique_ptr<JSONArray> invalidations = | |
| 125 document().view()->trackedObjectPaintInvalidationsAsJSON(); | |
| 126 EXPECT_TRUE( | |
| 127 invalidationArrayContains(invalidations.get(), *document().layoutView())); | |
| 128 } | |
| 129 | |
| 130 } // namespace | |
| 131 | |
| 132 } // namespace blink | |
| OLD | NEW |