Bug 1312697 - Mochitest. r=tnikkel

MozReview-Commit-ID: LUWZMdkOdgY

--HG--
extra : rebase_source : 26cd1cd74d1bb9cef28d57a6af225e497188d6a3
This commit is contained in:
Botond Ballo 2017-03-17 19:12:53 -04:00
parent 253843616c
commit 098b03ac55
3 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,41 @@
"use strict";
const Cc = Components.classes;
const Ci = Components.interfaces;
let timer;
const DELAY_MS = 5000;
function handleRequest(request, response) {
response.processAsync();
response.setHeader("Content-Type", "text/html", false);
// Include paint_listener.js so that we can call waitForAllPaintsFlushed
// on the window in which this is opened.
response.write("<script type=\"text/javascript\" src=\"/tests/SimpleTest/paint_listener.js\"></script>");
// Allow the opening window to react to loading being complete.
response.write("<body onload=\"window.opener.fullyLoaded()\">");
// Send half of the content.
for (var i = 0; i < 100; ++i) {
response.write("<p>Some text.</p>");
}
// Allow the opening window to react to being partially loaded.
response.write("<script>window.opener.partiallyLoaded();</script>");
// Wait for 5 seconds, then send the rest of the content.
timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.init(() => {
for (var i = 0; i < 100; ++i) {
response.write("<p>Some text.</p>");
}
response.write("</body>");
response.finish();
}, DELAY_MS, Ci.nsITimer.TYPE_ONE_SHOT);
}

View File

@ -15,6 +15,7 @@ support-files =
file_IconTestServer.sjs
file_LoadingImageReference.png
file_SlowImage.sjs
file_SlowPage.sjs
bug1174521.html
[test_bug240933.html]
@ -136,5 +137,6 @@ support-files = selection_expanding_xbl.xml
support-files = file_taintedfilters_feDisplacementMap-tainted-1.svg file_taintedfilters_feDisplacementMap-tainted-2.svg file_taintedfilters_feDisplacementMap-tainted-3.svg file_taintedfilters_feDisplacementMap-tainted-ref.svg file_taintedfilters_feDisplacementMap-untainted-ref.svg file_taintedfilters_feDisplacementMap-untainted-1.svg file_taintedfilters_feDisplacementMap-untainted-2.svg file_taintedfilters_red-flood-for-feImage-cors.svg file_taintedfilters_red-flood-for-feImage-cors.svg^headers^ file_taintedfilters_red-flood-for-feImage.svg
[test_scroll_position_restore.html]
support-files = file_scroll_position_restore.html
[test_scroll_position_restore_after_stop.html]
[test_scroll_animation_restore.html]
[test_scroll_position_iframe.html]

View File

@ -0,0 +1,76 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1312697
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1312697</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1312697">Mozilla Bug 1312697</a>
<p id="display"></p>
<script>
SimpleTest.waitForExplicitFinish();
var loadCount = 0;
var childWin = window.open('file_SlowPage.sjs', '_blank');
var targetPos = 0;
// Called by the page in the child window when it's halfway loaded.
function partiallyLoaded() {
if (loadCount == 1) {
// Halfway through the first reload, stop loading.
childWin.stop();
// Force a reflow in the stopped state. This triggers the buggy behaviour.
var newNode = childWin.document.createElement('p');
newNode.innerHTML = "Added text.";
childWin.document.body.insertBefore(newNode, childWin.document.body.childNodes[0]);
childWin.waitForAllPaintsFlushed(function() {
// Since we're only partially loaded, we should not have been able to
// reach the target scroll position.
ok(childWin.scrollY < targetPos, "Expected page to not be fully loaded");
// Now re-load again. Continue reading in fullyLoaded(), the
// 'loadCount == 2' case.
loadCount++;
childWin.location.reload();
});
}
}
// Called by the page in the child window when it's fully loaded.
function fullyLoaded() {
if (loadCount == 0) {
// Scroll to a target position near the end of the page (past the
// half-way point.)
targetPos = childWin.scrollMaxY - 100;
childWin.scrollTo(0, targetPos);
childWin.waitForAllPaintsFlushed(function() {
ok(childWin.scrollY == targetPos, "Expected page to have scrolled");
// Reload the page.
loadCount++;
childWin.location.reload();
// Next, we'll get into partiallyLoaded(). Read on there.
});
} else if (loadCount == 2) {
// After the second reload is complete, check that the initial target
// position was remembered and scrolled to.
childWin.waitForAllPaintsFlushed(function() {
ok(childWin.scrollY == targetPos, "Expected page to have scrolled to target position");
childWin.close();
SimpleTest.finish();
});
}
}
</script>
</body>
</html>