123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- waitForExplicitFinish();
- requestLongerTimeout(2); // see bug 660123 -- this test is slow on Mac.
- // A hold on the current timer, so it doens't get GCed out from
- // under us
- var gTimer;
- // Browsing to a new URL - pushing us into the bfcache - should cause
- // animations to stop, and resume when we return
- function testBFCache() {
- function theTest() {
- var abort = false;
- var chances, gImage, gFrames;
- gBrowser.selectedTab = gBrowser.addTab(TESTROOT + "image.html");
- gBrowser.selectedBrowser.addEventListener("pageshow", function () {
- gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, true);
- var window = gBrowser.contentWindow;
- // If false, we are in an optimized build, and we abort this and
- // all further tests
- if (!actOnMozImage(window.document, "img1", function(image) {
- gImage = image;
- gFrames = gImage.framesNotified;
- })) {
- gBrowser.removeCurrentTab();
- abort = true;
- }
- goer.next();
- }, true);
- yield;
- if (abort) {
- finish();
- yield; // optimized build
- }
- // Let animation run for a bit
- chances = 120;
- do {
- gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- gTimer.initWithCallback(function() {
- if (gImage.framesNotified >= 20) {
- goer.send(true);
- } else {
- chances--;
- goer.send(chances == 0); // maybe if we wait a bit, it will happen
- }
- }, 500, Ci.nsITimer.TYPE_ONE_SHOT);
- } while (!(yield));
- is(chances > 0, true, "Must have animated a few frames so far");
- // Browse elsewhere; push our animating page into the bfcache
- gBrowser.loadURI("about:blank");
- // Wait a bit for page to fully load, then wait a while and
- // see that no animation occurs.
- gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- gTimer.initWithCallback(function() {
- gFrames = gImage.framesNotified;
- gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- gTimer.initWithCallback(function() {
- // Might have a few stray frames, until other page totally loads
- var additionalFrames = gImage.framesNotified - gFrames;
- is(additionalFrames == 0, true, "Must have not animated in bfcache! Got " + additionalFrames + " additional frames");
- goer.next();
- }, 4000, Ci.nsITimer.TYPE_ONE_SHOT); // 4 seconds - expect 40 frames
- }, 0, Ci.nsITimer.TYPE_ONE_SHOT); // delay of 0 - wait for next event loop
- yield;
- // Go back
- gBrowser.goBack();
- chances = 120;
- do {
- gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- gTimer.initWithCallback(function() {
- if (gImage.framesNotified - gFrames >= 20) {
- goer.send(true);
- } else {
- chances--;
- goer.send(chances == 0); // maybe if we wait a bit, it will happen
- }
- }, 500, Ci.nsITimer.TYPE_ONE_SHOT);
- } while (!(yield));
- is(chances > 0, true, "Must have animated once out of bfcache!");
- // Finally, check that the css background image has essentially the same
- // # of frames, implying that it animated at the same times as the regular
- // image. We can easily retrieve regular images through their HTML image
- // elements, which is what we did before. For the background image, we
- // create a regular image now, and read the current frame count.
- var doc = gBrowser.selectedBrowser.contentWindow.document;
- var div = doc.getElementById("background_div");
- div.innerHTML += '<img src="animated2.gif" id="img3">';
- actOnMozImage(doc, "img3", function(image) {
- is(Math.abs(image.framesNotified - gImage.framesNotified)/gImage.framesNotified < 0.5, true,
- "Must have also animated the background image, and essentially the same # of frames. " +
- "Regular image got " + gImage.framesNotified + " frames but background image got " + image.framesNotified);
- });
- gBrowser.removeCurrentTab();
- nextTest();
- }
- var goer = theTest();
- goer.next();
- }
- // Check that imgContainers are shared on the same page and
- // between tabs
- function testSharedContainers() {
- function theTest() {
- var gImages = [];
- var gFrames;
- gBrowser.selectedTab = gBrowser.addTab(TESTROOT + "image.html");
- gBrowser.selectedBrowser.addEventListener("pageshow", function () {
- gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, true);
- actOnMozImage(gBrowser.contentDocument, "img1", function(image) {
- gImages[0] = image;
- gFrames = image.framesNotified; // May in theory have frames from last test
- // in this counter - so subtract them out
- });
- goer.next();
- }, true);
- yield;
- // Load next tab somewhat later
- gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- gTimer.initWithCallback(function() {
- goer.next();
- }, 1500, Ci.nsITimer.TYPE_ONE_SHOT);
- yield;
- gBrowser.selectedTab = gBrowser.addTab(TESTROOT + "imageX2.html");
- gBrowser.selectedBrowser.addEventListener("pageshow", function () {
- gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, true);
- [1,2].forEach(function(i) {
- actOnMozImage(gBrowser.contentDocument, "img"+i, function(image) {
- gImages[i] = image;
- });
- });
- goer.next();
- }, true);
- yield;
- var chances = 120;
- do {
- gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- gTimer.initWithCallback(function() {
- if (gImages[0].framesNotified - gFrames >= 10) {
- goer.send(true);
- } else {
- chances--;
- goer.send(chances == 0); // maybe if we wait a bit, it will happen
- }
- }, 500, Ci.nsITimer.TYPE_ONE_SHOT);
- } while (!(yield));
- is(chances > 0, true, "Must have been animating while showing several images");
- // Check they all have the same frame counts
- var theFrames = null;
- [0,1,2].forEach(function(i) {
- var frames = gImages[i].framesNotified;
- if (theFrames == null) {
- theFrames = frames;
- } else {
- is(theFrames, frames, "Sharing the same imgContainer means *exactly* the same frame counts!");
- }
- });
- gBrowser.removeCurrentTab();
- gBrowser.removeCurrentTab();
- nextTest();
- }
- var goer = theTest();
- goer.next();
- }
- var tests = [testBFCache, testSharedContainers];
- function nextTest() {
- if (tests.length == 0) {
- finish();
- return;
- }
- tests.shift()();
- }
- function test() {
- ignoreAllUncaughtExceptions();
- nextTest();
- }
|