Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 06e7696

Browse files
author
Victor Porof
committed
Bug 1561435 - Format image/, a=automatic-formatting
# ignore-this-changeset Differential Revision: https://phabricator.services.mozilla.com/D35906 --HG-- extra : source : a224e9d645e49dd7a343f88bd95c0da61aff0f6a
1 parent 054a393 commit 06e7696

18 files changed

Lines changed: 2828 additions & 1783 deletions

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ module.exports = {
4545
"overrides": [{
4646
"files": [
4747
"devtools/**",
48-
"image/**",
4948
"intl/**",
5049
"ipc/**",
5150
"js/**",

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ toolkit/components/telemetry/datareporting-prefs.js
4040
toolkit/components/telemetry/healthreport-prefs.js
4141

4242
# Ignore all top-level directories for now.
43-
image/**
4443
intl/**
4544
ipc/**
4645
js/**

image/test/browser/browser_bug666317.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
waitForExplicitFinish();
22

33
var pageSource =
4-
'<html><body>' +
5-
'<img id="testImg" src="' + TESTROOT + 'big.png">' +
6-
'</body></html>';
4+
"<html><body>" +
5+
'<img id="testImg" src="' +
6+
TESTROOT +
7+
'big.png">' +
8+
"</body></html>";
79

810
var oldDiscardingPref, oldTab, newTab;
911
var prefBranch = Cc["@mozilla.org/preferences-service;1"]
10-
.getService(Ci.nsIPrefService)
11-
.getBranch('image.mem.');
12+
.getService(Ci.nsIPrefService)
13+
.getBranch("image.mem.");
1214

1315
var gWaitingForDiscard = false;
1416
var gScriptedObserver;
@@ -17,81 +19,83 @@ var gClonedRequest;
1719
function ImageObserver(decodeCallback, discardCallback) {
1820
this.decodeComplete = function onDecodeComplete(aRequest) {
1921
decodeCallback();
20-
}
22+
};
2123

22-
this.discard = function onDiscard(request)
23-
{
24+
this.discard = function onDiscard(request) {
2425
if (!gWaitingForDiscard) {
2526
return;
2627
}
2728

2829
this.synchronous = false;
2930
discardCallback();
30-
}
31+
};
3132

3233
this.synchronous = true;
3334
}
3435

3536
function currentRequest() {
36-
let img = gBrowser.getBrowserForTab(newTab).contentWindow
37-
.document.getElementById('testImg');
37+
let img = gBrowser
38+
.getBrowserForTab(newTab)
39+
.contentWindow.document.getElementById("testImg");
3840
return img.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
3941
}
4042

4143
function isImgDecoded() {
4244
let request = currentRequest();
43-
return request.imageStatus & Ci.imgIRequest.STATUS_DECODE_COMPLETE ? true : false;
45+
return request.imageStatus & Ci.imgIRequest.STATUS_DECODE_COMPLETE
46+
? true
47+
: false;
4448
}
4549

4650
// Ensure that the image is decoded by drawing it to a canvas.
4751
function forceDecodeImg() {
4852
let doc = gBrowser.getBrowserForTab(newTab).contentWindow.document;
49-
let img = doc.getElementById('testImg');
50-
let canvas = doc.createElement('canvas');
51-
let ctx = canvas.getContext('2d');
53+
let img = doc.getElementById("testImg");
54+
let canvas = doc.createElement("canvas");
55+
let ctx = canvas.getContext("2d");
5256
ctx.drawImage(img, 0, 0);
5357
}
5458

5559
function runAfterAsyncEvents(aCallback) {
5660
function handlePostMessage(aEvent) {
57-
if (aEvent.data == 'next') {
58-
window.removeEventListener('message', handlePostMessage);
61+
if (aEvent.data == "next") {
62+
window.removeEventListener("message", handlePostMessage);
5963
aCallback();
6064
}
6165
}
6266

63-
window.addEventListener('message', handlePostMessage);
67+
window.addEventListener("message", handlePostMessage);
6468

6569
// We'll receive the 'message' event after everything else that's currently in
6670
// the event queue (which is a stronger guarantee than setTimeout, because
6771
// setTimeout events may be coalesced). This lets us ensure that we run
6872
// aCallback *after* any asynchronous events are delivered.
69-
window.postMessage('next', '*');
73+
window.postMessage("next", "*");
7074
}
7175

7276
function test() {
7377
// Enable the discarding pref.
74-
oldDiscardingPref = prefBranch.getBoolPref('discardable');
75-
prefBranch.setBoolPref('discardable', true);
78+
oldDiscardingPref = prefBranch.getBoolPref("discardable");
79+
prefBranch.setBoolPref("discardable", true);
7680

7781
// Create and focus a new tab.
7882
oldTab = gBrowser.selectedTab;
79-
newTab = BrowserTestUtils.addTab(gBrowser, 'data:text/html,' + pageSource);
83+
newTab = BrowserTestUtils.addTab(gBrowser, "data:text/html," + pageSource);
8084
gBrowser.selectedTab = newTab;
8185

8286
// Run step2 after the tab loads.
83-
gBrowser.getBrowserForTab(newTab)
84-
.addEventListener("pageshow", step2);
87+
gBrowser.getBrowserForTab(newTab).addEventListener("pageshow", step2);
8588
}
8689

8790
function step2() {
8891
// Create the image observer.
89-
var observer =
90-
new ImageObserver(() => runAfterAsyncEvents(step3), // DECODE_COMPLETE
91-
() => runAfterAsyncEvents(step5)); // DISCARD
92+
var observer = new ImageObserver(
93+
() => runAfterAsyncEvents(step3), // DECODE_COMPLETE
94+
() => runAfterAsyncEvents(step5)
95+
); // DISCARD
9296
gScriptedObserver = Cc["@mozilla.org/image/tools;1"]
93-
.getService(Ci.imgITools)
94-
.createScriptedObserver(observer);
97+
.getService(Ci.imgITools)
98+
.createScriptedObserver(observer);
9599

96100
// Clone the current imgIRequest with our new observer.
97101
var request = currentRequest();
@@ -105,7 +109,7 @@ function step2() {
105109
}
106110

107111
function step3() {
108-
ok(isImgDecoded(), 'Image should initially be decoded.');
112+
ok(isImgDecoded(), "Image should initially be decoded.");
109113

110114
// Focus the old tab, then fire a memory-pressure notification. This should
111115
// cause the decoded image in the new tab to be discarded.
@@ -118,20 +122,21 @@ function step3() {
118122
function step4() {
119123
gWaitingForDiscard = true;
120124

121-
var os = Cc["@mozilla.org/observer-service;1"]
122-
.getService(Ci.nsIObserverService);
123-
os.notifyObservers(null, 'memory-pressure', 'heap-minimize');
125+
var os = Cc["@mozilla.org/observer-service;1"].getService(
126+
Ci.nsIObserverService
127+
);
128+
os.notifyObservers(null, "memory-pressure", "heap-minimize");
124129

125130
// The DISCARD notification is delivered asynchronously. ImageObserver will
126131
// eventually call step5. (Or else, sadly, the test will time out.)
127132
}
128133

129134
function step5() {
130-
ok(true, 'Image should be discarded.');
135+
ok(true, "Image should be discarded.");
131136

132137
// And we're done.
133138
gBrowser.removeTab(newTab);
134-
prefBranch.setBoolPref('discardable', oldDiscardingPref);
139+
prefBranch.setBoolPref("discardable", oldDiscardingPref);
135140

136141
gClonedRequest.cancelAndForgetObserver(0);
137142

Lines changed: 94 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
"use strict";
32

43
const SIMPLE_HTML = "data:text/html,<html><head></head><body></body></html>";
@@ -10,8 +9,7 @@ const SIMPLE_HTML = "data:text/html,<html><head></head><body></body></html>";
109
*/
1110
function getManifestDir() {
1211
let path = getTestFilePath("browser_docshell_type_editor");
13-
let file = Cc["@mozilla.org/file/local;1"]
14-
.createInstance(Ci.nsIFile);
12+
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
1513
file.initWithPath(path);
1614
return file;
1715
}
@@ -28,92 +26,111 @@ add_task(async function() {
2826
let manifestDir = getManifestDir();
2927
Components.manager.addBootstrappedManifestLocation(manifestDir);
3028

31-
await BrowserTestUtils.withNewTab({
32-
gBrowser,
33-
url: SIMPLE_HTML
34-
}, async function(browser) {
35-
await ContentTask.spawn(browser, null, async function() {
36-
let rootDocShell = docShell.QueryInterface(Ci.nsIDocShellTreeItem)
37-
.rootTreeItem
38-
.QueryInterface(Ci.nsIInterfaceRequestor)
39-
.getInterface(Ci.nsIDocShell);
40-
let defaultAppType = rootDocShell.appType;
41-
42-
rootDocShell.appType = Ci.nsIDocShell.APP_TYPE_EDITOR;
43-
44-
is(rootDocShell.appType, Ci.nsIDocShell.APP_TYPE_EDITOR,
45-
"sanity check: appType after update should be type editor");
46-
47-
48-
return new Promise(resolve => {
49-
let doc = content.document;
50-
let image = doc.createElement("img");
51-
image.onload = function() {
52-
ok(true, "APP_TYPE_EDITOR is allowed to load privileged image");
53-
// restore appType of rootDocShell before moving on to the next test
54-
rootDocShell.appType = defaultAppType;
55-
resolve();
56-
}
57-
image.onerror = function() {
58-
ok(false, "APP_TYPE_EDITOR is allowed to load privileged image");
59-
// restore appType of rootDocShell before moving on to the next test
60-
rootDocShell.appType = defaultAppType;
61-
resolve();
62-
}
63-
doc.body.appendChild(image);
64-
image.src = "chrome://test1/skin/privileged.png";
29+
await BrowserTestUtils.withNewTab(
30+
{
31+
gBrowser,
32+
url: SIMPLE_HTML,
33+
},
34+
async function(browser) {
35+
await ContentTask.spawn(browser, null, async function() {
36+
let rootDocShell = docShell
37+
.QueryInterface(Ci.nsIDocShellTreeItem)
38+
.rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor)
39+
.getInterface(Ci.nsIDocShell);
40+
let defaultAppType = rootDocShell.appType;
41+
42+
rootDocShell.appType = Ci.nsIDocShell.APP_TYPE_EDITOR;
43+
44+
is(
45+
rootDocShell.appType,
46+
Ci.nsIDocShell.APP_TYPE_EDITOR,
47+
"sanity check: appType after update should be type editor"
48+
);
49+
50+
return new Promise(resolve => {
51+
let doc = content.document;
52+
let image = doc.createElement("img");
53+
image.onload = function() {
54+
ok(true, "APP_TYPE_EDITOR is allowed to load privileged image");
55+
// restore appType of rootDocShell before moving on to the next test
56+
rootDocShell.appType = defaultAppType;
57+
resolve();
58+
};
59+
image.onerror = function() {
60+
ok(false, "APP_TYPE_EDITOR is allowed to load privileged image");
61+
// restore appType of rootDocShell before moving on to the next test
62+
rootDocShell.appType = defaultAppType;
63+
resolve();
64+
};
65+
doc.body.appendChild(image);
66+
image.src = "chrome://test1/skin/privileged.png";
67+
});
6568
});
66-
});
67-
});
69+
}
70+
);
6871

6972
Components.manager.removeBootstrappedManifestLocation(manifestDir);
7073
});
7174

7275
add_task(async function() {
73-
info("docshell of appType APP_TYPE_UNKNOWN can *not* access privileged images.");
76+
info(
77+
"docshell of appType APP_TYPE_UNKNOWN can *not* access privileged images."
78+
);
7479

7580
// Load a temporary manifest adding a route to a privileged image
7681
let manifestDir = getManifestDir();
7782
Components.manager.addBootstrappedManifestLocation(manifestDir);
7883

79-
await BrowserTestUtils.withNewTab({
80-
gBrowser,
81-
url: SIMPLE_HTML
82-
}, async function(browser) {
83-
await ContentTask.spawn(browser, null, async function() {
84-
let rootDocShell = docShell.QueryInterface(Ci.nsIDocShellTreeItem)
85-
.rootTreeItem
86-
.QueryInterface(Ci.nsIInterfaceRequestor)
87-
.getInterface(Ci.nsIDocShell);
88-
let defaultAppType = rootDocShell.appType;
89-
90-
rootDocShell.appType = Ci.nsIDocShell.APP_TYPE_UNKNOWN;
91-
92-
is(rootDocShell.appType, Ci.nsIDocShell.APP_TYPE_UNKNOWN,
93-
"sanity check: appType of docshell should be unknown");
94-
95-
return new Promise(resolve => {
96-
let doc = content.document;
97-
let image = doc.createElement("img");
98-
image.onload = function() {
99-
ok(false, "APP_TYPE_UNKNOWN is *not* allowed to acces privileged image");
100-
// restore appType of rootDocShell before moving on to the next test
101-
rootDocShell.appType = defaultAppType;
102-
resolve();
103-
}
104-
image.onerror = function() {
105-
ok(true, "APP_TYPE_UNKNOWN is *not* allowed to acces privileged image");
106-
// restore appType of rootDocShell before moving on to the next test
107-
rootDocShell.appType = defaultAppType;
108-
resolve();
109-
}
110-
doc.body.appendChild(image);
111-
// Set the src via wrappedJSObject so the load is triggered with
112-
// the content page's principal rather than ours.
113-
image.wrappedJSObject.src = "chrome://test1/skin/privileged.png";
84+
await BrowserTestUtils.withNewTab(
85+
{
86+
gBrowser,
87+
url: SIMPLE_HTML,
88+
},
89+
async function(browser) {
90+
await ContentTask.spawn(browser, null, async function() {
91+
let rootDocShell = docShell
92+
.QueryInterface(Ci.nsIDocShellTreeItem)
93+
.rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor)
94+
.getInterface(Ci.nsIDocShell);
95+
let defaultAppType = rootDocShell.appType;
96+
97+
rootDocShell.appType = Ci.nsIDocShell.APP_TYPE_UNKNOWN;
98+
99+
is(
100+
rootDocShell.appType,
101+
Ci.nsIDocShell.APP_TYPE_UNKNOWN,
102+
"sanity check: appType of docshell should be unknown"
103+
);
104+
105+
return new Promise(resolve => {
106+
let doc = content.document;
107+
let image = doc.createElement("img");
108+
image.onload = function() {
109+
ok(
110+
false,
111+
"APP_TYPE_UNKNOWN is *not* allowed to acces privileged image"
112+
);
113+
// restore appType of rootDocShell before moving on to the next test
114+
rootDocShell.appType = defaultAppType;
115+
resolve();
116+
};
117+
image.onerror = function() {
118+
ok(
119+
true,
120+
"APP_TYPE_UNKNOWN is *not* allowed to acces privileged image"
121+
);
122+
// restore appType of rootDocShell before moving on to the next test
123+
rootDocShell.appType = defaultAppType;
124+
resolve();
125+
};
126+
doc.body.appendChild(image);
127+
// Set the src via wrappedJSObject so the load is triggered with
128+
// the content page's principal rather than ours.
129+
image.wrappedJSObject.src = "chrome://test1/skin/privileged.png";
130+
});
114131
});
115-
});
116-
});
132+
}
133+
);
117134

118135
Components.manager.removeBootstrappedManifestLocation(manifestDir);
119136
});

0 commit comments

Comments
 (0)