| 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/html/HTMLIFrameElement.h" | 6 #include "core/html/HTMLIFrameElement.h" |
| 7 #include "core/layout/api/LayoutViewItem.h" | 7 #include "core/layout/api/LayoutViewItem.h" |
| 8 #include "core/paint/PaintLayer.h" | 8 #include "core/paint/PaintLayer.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "web/tests/sim/SimCompositor.h" | 10 #include "web/tests/sim/SimCompositor.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 334 |
| 335 // Finish loading the CSS resource (no change to painting). | 335 // Finish loading the CSS resource (no change to painting). |
| 336 cssBodyResource.complete("a { color: red; }"); | 336 cssBodyResource.complete("a { color: red; }"); |
| 337 EXPECT_TRUE(document().isRenderingReady()); | 337 EXPECT_TRUE(document().isRenderingReady()); |
| 338 | 338 |
| 339 // Finish the load, painting should stay enabled. | 339 // Finish the load, painting should stay enabled. |
| 340 mainResource.finish(); | 340 mainResource.finish(); |
| 341 EXPECT_TRUE(document().isRenderingReady()); | 341 EXPECT_TRUE(document().isRenderingReady()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 // Regression test for crbug.com/646323 | |
| 345 TEST_F(DocumentLoadingRenderingTest, ShouldNotPerformRepeatedLayoutWithPendingIm
port) | |
| 346 { | |
| 347 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 348 SimRequest cssResource("https://example.com/test.css", "text/css"); | |
| 349 | |
| 350 loadURL("https://example.com/test.html"); | |
| 351 | |
| 352 mainResource.start(); | |
| 353 mainResource.write("<!DOCTYPE html><div>foo bar.</div>"); | |
| 354 compositor().beginFrame(); | |
| 355 | |
| 356 // Insert a pending sheet with @import. | |
| 357 mainResource.write("<style>@import url('test.css')</style>"); | |
| 358 | |
| 359 // Do a layout with pending sheet. | |
| 360 document().updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 361 | |
| 362 // HTML import is required. | |
| 363 mainResource.write("<link rel=import>"); | |
| 364 | |
| 365 // Perform two subsequent updateStyleAndLayoutIgnorePendingStylesheets(). | |
| 366 // The second one should be a no-op. | |
| 367 document().updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 368 unsigned styleCountBeforeSecondLayout = document().styleEngine().styleForEle
mentCount(); | |
| 369 | |
| 370 document().updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 371 EXPECT_EQ(styleCountBeforeSecondLayout, document().styleEngine().styleForEle
mentCount()); | |
| 372 | |
| 373 // The content of the pending sheet doesn't matter. | |
| 374 cssResource.complete(""); | |
| 375 mainResource.finish(); | |
| 376 } | |
| 377 | |
| 378 // Regression test for a wrong fix to crbug.com/646323, which simply stops | |
| 379 // updateStyleAndLayoutIgnorePendingStylesheets from forcing layout when there | |
| 380 // are nodes with placeholder style. | |
| 381 TEST_F(DocumentLoadingRenderingTest, ShouldClearPlaceholderStyleWhenIgnoringPend
ingStylesheet) | |
| 382 { | |
| 383 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 384 SimRequest cssResource("https://example.com/test.css", "text/css"); | |
| 385 | |
| 386 loadURL("https://example.com/test.html"); | |
| 387 | |
| 388 mainResource.start(); | |
| 389 mainResource.write("<!DOCTYPE html>"); | |
| 390 | |
| 391 // Insert a render blocking pending stylesheet. Do not let it finish. | |
| 392 mainResource.write("<link rel=stylesheet href=test.css>"); | |
| 393 | |
| 394 // Insert a non-empty body. | |
| 395 mainResource.write("foo"); | |
| 396 | |
| 397 // Do a layout with the pending sheet ignored, so that <body> does not get a | |
| 398 // placeholder style. | |
| 399 document().updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 400 EXPECT_FALSE(document().hasNodesWithPlaceholderStyle()); | |
| 401 | |
| 402 // Insert a <div>, which should get a placeholder style later. | |
| 403 mainResource.write("<div>bar</div>"); | |
| 404 EXPECT_TRUE(document().needsLayoutTreeUpdate()); | |
| 405 | |
| 406 // <div> gets a placeholder style if the pending sheet is not ignored. | |
| 407 document().updateStyleAndLayout(); | |
| 408 EXPECT_TRUE(document().hasNodesWithPlaceholderStyle()); | |
| 409 EXPECT_FALSE(document().needsLayoutTreeUpdate()); | |
| 410 | |
| 411 // updateStyleAndLayoutIgnorePendingStylesheets should clear the placeholder | |
| 412 // style and redo layout, even if called on clean layout tree. | |
| 413 document().updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 414 EXPECT_FALSE(document().hasNodesWithPlaceholderStyle()); | |
| 415 | |
| 416 // The content of the pending sheet doesn't matter. | |
| 417 cssResource.complete(""); | |
| 418 mainResource.finish(); | |
| 419 } | |
| 420 | 344 |
| 421 } // namespace blink | 345 } // namespace blink |
| OLD | NEW |