зеркало из https://github.com/mozilla/gecko-dev.git
Back out 01093b5a774b (bug 948194) for not fixing enough races
--HG-- extra : rebase_source : 7e2d451639be57ef03818d84ba2e4e7fd72fa63d
This commit is contained in:
Родитель
44fbf3bf13
Коммит
c0127916ec
|
@ -8,5 +8,6 @@ support-files =
|
|||
imageX2.html
|
||||
|
||||
[browser_bug666317.js]
|
||||
skip-if = e10s # Bug 948194 - Decoded Images seem to not be discarded on memory-pressure notification with e10s enabled
|
||||
[browser_image.js]
|
||||
skip-if = e10s || !debug # Test is only to run on debug builds
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
waitForExplicitFinish();
|
||||
|
||||
let pageSource =
|
||||
'<html><meta charset=UTF-8><body>' +
|
||||
'<html><body>' +
|
||||
'<img id="testImg" src="' + TESTROOT + 'big.png">' +
|
||||
'</body></html>';
|
||||
|
||||
|
@ -12,67 +10,47 @@ let prefBranch = Cc["@mozilla.org/preferences-service;1"]
|
|||
.getService(Ci.nsIPrefService)
|
||||
.getBranch('image.mem.');
|
||||
|
||||
function imgDiscardingFrameScript() {
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
function ImageDiscardObserver(result) {
|
||||
this.discard = function onDiscard(request) {
|
||||
result.wasDiscarded = true;
|
||||
}
|
||||
function ImageDiscardObserver(result) {
|
||||
this.discard = function onDiscard(request)
|
||||
{
|
||||
result.wasDiscarded = true;
|
||||
this.synchronous = false;
|
||||
}
|
||||
|
||||
function currentRequest() {
|
||||
let img = content.document.getElementById('testImg');
|
||||
img.QueryInterface(Ci.nsIImageLoadingContent);
|
||||
return img.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
||||
}
|
||||
this.synchronous = true;
|
||||
}
|
||||
|
||||
function attachDiscardObserver(result) {
|
||||
// Create the discard observer.
|
||||
let observer = new ImageDiscardObserver(result);
|
||||
let scriptedObserver = Cc["@mozilla.org/image/tools;1"]
|
||||
.getService(Ci.imgITools)
|
||||
.createScriptedObserver(observer);
|
||||
function currentRequest() {
|
||||
let img = gBrowser.getBrowserForTab(newTab).contentWindow
|
||||
.document.getElementById('testImg');
|
||||
img.QueryInterface(Ci.nsIImageLoadingContent);
|
||||
return img.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
||||
}
|
||||
|
||||
// Clone the current imgIRequest with our new observer.
|
||||
let request = currentRequest();
|
||||
return [ request.clone(scriptedObserver), scriptedObserver ];
|
||||
}
|
||||
function attachDiscardObserver(result) {
|
||||
// Create the discard observer.
|
||||
let observer = new ImageDiscardObserver(result);
|
||||
let scriptedObserver = Cc["@mozilla.org/image/tools;1"]
|
||||
.getService(Ci.imgITools)
|
||||
.createScriptedObserver(observer);
|
||||
|
||||
// Attach a discard listener and create a place to hold the result.
|
||||
var result = { wasDiscarded: false };
|
||||
var scriptedObserver;
|
||||
var clonedRequest;
|
||||
// Clone the current imgIRequest with our new observer.
|
||||
let request = currentRequest();
|
||||
return request.clone(scriptedObserver);
|
||||
}
|
||||
|
||||
addMessageListener("test666317:testPart1", function(message) {
|
||||
// Ensure that the image is decoded by drawing it to a canvas.
|
||||
let doc = content.document;
|
||||
let img = doc.getElementById('testImg');
|
||||
let canvas = doc.createElement('canvas');
|
||||
let ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
function isImgDecoded() {
|
||||
let request = currentRequest();
|
||||
return request.imageStatus & Ci.imgIRequest.STATUS_FRAME_COMPLETE ? true : false;
|
||||
}
|
||||
|
||||
// Verify that we decoded the image.
|
||||
// Note: We grab a reference to the scripted observer because the image
|
||||
// holds a weak ref to it. If we don't hold a strong reference, we might
|
||||
// end up using a deleted pointer.
|
||||
[ clonedRequest, scriptedObserver ] = attachDiscardObserver(result)
|
||||
let decoded = clonedRequest.imageStatus & Ci.imgIRequest.STATUS_FRAME_COMPLETE ? true : false;
|
||||
|
||||
message.target.sendAsyncMessage("test666317:testPart1:Answer",
|
||||
{ decoded });
|
||||
});
|
||||
|
||||
addMessageListener("test666317:wasImgDiscarded", function(message) {
|
||||
let discarded = result.wasDiscarded;
|
||||
|
||||
// NOTE: We know that this is the last test.
|
||||
clonedRequest.cancelAndForgetObserver(0);
|
||||
scriptedObserver = null;
|
||||
message.target.sendAsyncMessage("test666317:wasImgDiscarded:Answer",
|
||||
{ discarded });
|
||||
});
|
||||
// Ensure that the image is decoded by drawing it to a canvas.
|
||||
function forceDecodeImg() {
|
||||
let doc = gBrowser.getBrowserForTab(newTab).contentWindow.document;
|
||||
let img = doc.getElementById('testImg');
|
||||
let canvas = doc.createElement('canvas');
|
||||
let ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
}
|
||||
|
||||
function test() {
|
||||
|
@ -91,38 +69,25 @@ function test() {
|
|||
}
|
||||
|
||||
function step2() {
|
||||
let mm = gBrowser.getBrowserForTab(newTab).QueryInterface(Ci.nsIFrameLoaderOwner)
|
||||
.frameLoader.messageManager;
|
||||
mm.loadFrameScript("data:,(" + escape(imgDiscardingFrameScript.toString()) + ")();", false);
|
||||
// Attach a discard listener and create a place to hold the result.
|
||||
var result = { wasDiscarded: false };
|
||||
var clonedRequest = attachDiscardObserver(result);
|
||||
|
||||
// Check that the image is decoded.
|
||||
mm.addMessageListener("test666317:testPart1:Answer", function(message) {
|
||||
let decoded = message.data.decoded;
|
||||
ok(decoded, 'Image should initially be decoded.');
|
||||
forceDecodeImg();
|
||||
ok(isImgDecoded(), 'Image should initially be decoded.');
|
||||
|
||||
// Focus the old tab, then fire a memory-pressure notification. This should
|
||||
// cause the decoded image in the new tab to be discarded.
|
||||
gBrowser.selectedTab = oldTab;
|
||||
waitForFocus(() => {
|
||||
var os = Cc["@mozilla.org/observer-service;1"]
|
||||
.getService(Ci.nsIObserverService);
|
||||
// Focus the old tab, then fire a memory-pressure notification. This should
|
||||
// cause the decoded image in the new tab to be discarded.
|
||||
gBrowser.selectedTab = oldTab;
|
||||
var os = Cc["@mozilla.org/observer-service;1"]
|
||||
.getService(Ci.nsIObserverService);
|
||||
os.notifyObservers(null, 'memory-pressure', 'heap-minimize');
|
||||
ok(result.wasDiscarded, 'Image should be discarded.');
|
||||
|
||||
os.notifyObservers(null, 'memory-pressure', 'heap-minimize');
|
||||
|
||||
// Now ask if it was.
|
||||
mm.sendAsyncMessage("test666317:wasImgDiscarded");
|
||||
}, oldTab.contentWindow);
|
||||
});
|
||||
|
||||
mm.addMessageListener("test666317:wasImgDiscarded:Answer", function(message) {
|
||||
let discarded = message.data.discarded;
|
||||
ok(discarded, 'Image should be discarded.');
|
||||
|
||||
// And we're done.
|
||||
gBrowser.removeTab(newTab);
|
||||
prefBranch.setBoolPref('discardable', oldDiscardingPref);
|
||||
finish();
|
||||
});
|
||||
|
||||
mm.sendAsyncMessage("test666317:testPart1");
|
||||
// And we're done.
|
||||
gBrowser.removeTab(newTab);
|
||||
prefBranch.setBoolPref('discardable', oldDiscardingPref);
|
||||
clonedRequest.cancelAndForgetObserver(0);
|
||||
finish();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче