Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1092)

Unified Diff: third_party/WebKit/Source/web/tests/WebFrameTest.cpp

Issue 2564633002: Don't create layout objects for children of display-none iframes. (Closed)
Patch Set: Add new layout tests. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/tests/WebFrameTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
index 6841b213fbd6e180f7a97976cf27cd7a8527820a..e23c83bfba2820cba71c627560499f8b515c9a8b 100644
--- a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
+++ b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
@@ -10781,6 +10781,76 @@ TEST_F(WebFrameTest, UniqueNames) {
EXPECT_EQ(10u, names.size());
}
+namespace {
+bool DocumentElementChildrenHaveLayoutObjects(Document* doc) {
+ for (Node* child = doc->documentElement()->firstChild(); child;
esprehn 2016/12/15 21:36:48 There's no need to check this, if the documentElem
erikchen 2016/12/16 20:56:12 but the document element does have a layout object
+ child = child->nextSibling()) {
+ if (child->layoutObject())
+ return true;
+ }
+ return false;
+}
+} // namespace
+
+TEST_F(WebFrameTest, DisplayNoneIFrameHasNoLayoutObjects) {
esprehn 2016/12/15 21:36:48 If you use a SimTest instead this whole this can b
erikchen 2016/12/16 20:56:12 Done.
+ registerMockedHttpURLLoad("single_invisible_iframe.html");
+ registerMockedHttpURLLoad("visible_iframe.html");
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ webViewHelper.initializeAndLoad(m_baseURL + "single_invisible_iframe.html",
+ true);
+
+ WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
+ Element* element = frame->frame()->document()->querySelector("iframe");
+ HTMLFrameOwnerElement* frameOwnerElement =
+ static_cast<HTMLFrameOwnerElement*>(element);
+
+ Document* iframeDoc = frameOwnerElement->contentDocument();
+ EXPECT_FALSE(DocumentElementChildrenHaveLayoutObjects(iframeDoc));
+
+ // Changing the display from 'none' -> 'block' should cause layout objects to
+ // appear.
+ frame->executeScript(
+ WebScriptSource("d = document.querySelector('iframe');"
+ "d.style.display = 'block';"));
+ frame->view()->updateAllLifecyclePhases();
+ runPendingTasks();
+ EXPECT_TRUE(DocumentElementChildrenHaveLayoutObjects(iframeDoc));
+
+ // Changing the display from 'block' -> 'none' should cause layout objects to
+ // disappear.
+ frame->executeScript(
esprehn 2016/12/15 21:36:48 No need for JS, you can just do element->setInline
erikchen 2016/12/16 20:56:12 Done.
+ WebScriptSource("d = document.querySelector('iframe');"
+ "d.style.display = 'none';"));
+
+ frame->view()->updateAllLifecyclePhases();
+ runPendingTasks();
+ EXPECT_FALSE(DocumentElementChildrenHaveLayoutObjects(iframeDoc));
+}
+
+TEST_F(WebFrameTest, NormalIFrameHasLayoutObjects) {
esprehn 2016/12/15 21:36:48 SimTests will make this simpler: ex. https://cs.ch
erikchen 2016/12/16 20:56:12 Done.
+ registerMockedHttpURLLoad("single_iframe.html");
+ registerMockedHttpURLLoad("visible_iframe.html");
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ webViewHelper.initializeAndLoad(m_baseURL + "single_iframe.html", true);
+
+ WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl();
+ Element* element = frame->frame()->document()->querySelector("iframe");
+ HTMLFrameOwnerElement* frameOwnerElement =
+ static_cast<HTMLFrameOwnerElement*>(element);
+
+ Document* iframeDoc = frameOwnerElement->contentDocument();
+ EXPECT_TRUE(DocumentElementChildrenHaveLayoutObjects(iframeDoc));
+
+ // Changing the display from 'block' -> 'none' should cause layout objects to
+ // disappear.
+ frame->executeScript(
+ WebScriptSource("d = document.querySelector('iframe');"
+ "d.style.display = 'none';"));
+ frame->view()->updateAllLifecyclePhases();
+ runPendingTasks();
+ EXPECT_FALSE(DocumentElementChildrenHaveLayoutObjects(iframeDoc));
+}
+
TEST_F(WebFrameTest, NoLoadingCompletionCallbacksInDetach) {
class LoadingObserverFrameClient
: public FrameTestHelpers::TestWebFrameClient {

Powered by Google App Engine
This is Rietveld 408576698