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 "core/dom/Document.h" | 5 #include "core/dom/Document.h" |
6 #include "core/dom/Element.h" | 6 #include "core/dom/Element.h" |
7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
8 #include "core/html/HTMLIFrameElement.h" | 8 #include "core/html/HTMLIFrameElement.h" |
| 9 #include "platform/testing/URLTestHelpers.h" |
9 #include "platform/testing/UnitTestHelpers.h" | 10 #include "platform/testing/UnitTestHelpers.h" |
10 #include "public/web/WebHitTestResult.h" | 11 #include "public/web/WebHitTestResult.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "web/WebLocalFrameImpl.h" |
| 14 #include "web/WebRemoteFrameImpl.h" |
12 #include "web/tests/sim/SimCompositor.h" | 15 #include "web/tests/sim/SimCompositor.h" |
13 #include "web/tests/sim/SimDisplayItemList.h" | 16 #include "web/tests/sim/SimDisplayItemList.h" |
14 #include "web/tests/sim/SimRequest.h" | 17 #include "web/tests/sim/SimRequest.h" |
15 #include "web/tests/sim/SimTest.h" | 18 #include "web/tests/sim/SimTest.h" |
16 | 19 |
17 namespace blink { | 20 namespace blink { |
18 | 21 |
19 using namespace HTMLNames; | 22 using namespace HTMLNames; |
20 | 23 |
21 // NOTE: This test uses <iframe sandbox> to create cross origin iframes. | 24 // NOTE: This test uses <iframe sandbox> to create cross origin iframes. |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 247 |
245 // Change the size of a div in the throttled frame. | 248 // Change the size of a div in the throttled frame. |
246 auto* divElement = frameElement->contentDocument()->getElementById("div"); | 249 auto* divElement = frameElement->contentDocument()->getElementById("div"); |
247 divElement->setAttribute(styleAttr, "width: 50px"); | 250 divElement->setAttribute(styleAttr, "width: 50px"); |
248 | 251 |
249 // Querying the width of the div should do a synchronous layout update even | 252 // Querying the width of the div should do a synchronous layout update even |
250 // though the frame is being throttled. | 253 // though the frame is being throttled. |
251 EXPECT_EQ(50, divElement->clientWidth()); | 254 EXPECT_EQ(50, divElement->clientWidth()); |
252 } | 255 } |
253 | 256 |
| 257 TEST(RemoteFrameThrottlingTest, ThrottledLocalRoot) |
| 258 { |
| 259 FrameTestHelpers::TestWebViewClient viewClient; |
| 260 WebViewImpl* webView = WebViewImpl::create(&viewClient); |
| 261 webView->resize(WebSize(640, 480)); |
| 262 |
| 263 // Create a remote root frame with a local child frame. |
| 264 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; |
| 265 webView->setMainFrame(remoteClient.frame()); |
| 266 remoteClient.frame()->setReplicatedOrigin(WebSecurityOrigin::createUnique())
; |
| 267 |
| 268 WebFrameOwnerProperties properties; |
| 269 FrameTestHelpers::TestWebFrameClient localFrameClient; |
| 270 WebRemoteFrame* rootFrame = webView->mainFrame()->toWebRemoteFrame(); |
| 271 WebLocalFrame* localFrame = rootFrame->createLocalChild(WebTreeScopeType::Do
cument, "", WebSandboxFlags::None, &localFrameClient, nullptr, properties); |
| 272 |
| 273 WebString baseURL("http://internal.test/"); |
| 274 URLTestHelpers::registerMockedURLFromBaseURL(baseURL, "simple_div.html"); |
| 275 FrameTestHelpers::loadFrame(localFrame, baseURL.utf8() + "simple_div.html"); |
| 276 |
| 277 FrameView* frameView = toWebLocalFrameImpl(localFrame)->frameView(); |
| 278 EXPECT_TRUE(frameView->frame().isLocalRoot()); |
| 279 |
| 280 // Enable throttling for the child frame. |
| 281 frameView->setFrameRect(IntRect(0, 480, frameView->width(), frameView->heigh
t())); |
| 282 frameView->frame().securityContext()->setSecurityOrigin(SecurityOrigin::crea
teUnique()); |
| 283 frameView->updateAllLifecyclePhases(); |
| 284 testing::runPendingTasks(); |
| 285 EXPECT_TRUE(frameView->shouldThrottleRendering()); |
| 286 |
| 287 Document* frameDocument = frameView->frame().document(); |
| 288 if (RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled()) |
| 289 EXPECT_EQ(DocumentLifecycle::PaintClean, frameDocument->lifecycle().stat
e()); |
| 290 else |
| 291 EXPECT_EQ(DocumentLifecycle::PaintInvalidationClean, frameDocument->life
cycle().state()); |
| 292 |
| 293 // Mutate the local child frame contents. |
| 294 auto* divElement = frameDocument->getElementById("div"); |
| 295 divElement->setAttribute(styleAttr, "width: 50px"); |
| 296 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); |
| 297 |
| 298 // Update the lifecycle again. The frame's lifecycle should not advance |
| 299 // because of throttling even though it is the local root. |
| 300 frameView->updateAllLifecyclePhases(); |
| 301 testing::runPendingTasks(); |
| 302 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); |
| 303 webView->close(); |
| 304 } |
| 305 |
254 } // namespace blink | 306 } // namespace blink |
OLD | NEW |