Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/content/tests/policy.js

Issue 5745141503492096: Issue 1561 - Move unit tests out of the browser`s content area (Closed)
Patch Set: Rebased patch Created Jan. 10, 2015, 12:44 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/content/tests/elemhide.js ('k') | chrome/content/tests/popupBlocker.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/tests/policy.js
===================================================================
--- a/chrome/content/tests/policy.js
+++ b/chrome/content/tests/policy.js
@@ -9,21 +9,22 @@
setup: function()
{
prepareFilterComponents.call(this);
preparePrefs.call(this);
server = new nsHttpServer();
server.start(1234);
- frame = document.createElement("iframe");
+ frame = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "iframe");
+ frame.setAttribute("type", "content");
frame.style.visibility = "collapse";
document.body.appendChild(frame);
- requestNotifier = new RequestNotifier(window, onPolicyHit);
+ requestNotifier = new RequestNotifier(frame.contentWindow, onPolicyHit);
httpProtocol = Utils.httpProtocol;
Utils.httpProtocol = {userAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"};
},
teardown: function()
{
restoreFilterComponents.call(this);
restorePrefs.call(this);
@@ -87,17 +88,29 @@
],
[
"HTML image button inside a nested frame",
'<iframe src="data:text/html,%3Ciframe%20src%3D%22data%3Atext%2Fhtml%2C%253Cinput%2520type%253D%2522image%2522%2520src%253D%2522http%253A%252F%252F127.0.0.1%3A1234%252Ftest.gif%2522%253E%22%3E%3C%2Fiframe%3E"></iframe>',
"http://127.0.0.1:1234/test.gif", "image", false, false
],
[
"Dynamically inserted image button",
- '<div id="insert"></div><script>window.addEventListener("DOMContentLoaded", function() { var div = document.getElementById("insert"); div.innerHTML = \'<input type="image" id="image" src="test.gif">\'; var image = document.getElementById("image"); image.onload = image.onerror = function () { parent.postMessage("loaded", "*"); }; }, false);<' + '/script>',
+ '<div id="insert"></div>' +
+ '<script>' +
+ 'window.addEventListener("DOMContentLoaded", function()' +
+ '{' +
+ 'var div = document.getElementById("insert");' +
+ 'div.innerHTML = \'<input type="image" id="image" src="test.gif">\';' +
+ 'var image = document.getElementById("image");' +
+ 'image.onload = image.onerror = function ()' +
+ '{' +
+ 'document.dispatchEvent(new CustomEvent("abp:frameready", {bubbles: true}));' +
+ '};' +
+ '}, false);' +
+ '</script>',
"http://127.0.0.1:1234/test.gif", "image", false, true
],
[
"CSS background-image",
'<div style="background-image: url(test.gif)"></div>',
"http://127.0.0.1:1234/test.gif", "image", false, false
],
[
@@ -172,27 +185,58 @@
],
[
"CSS fonts",
'<style type="text/css">@font-face { font-family: Test; src: url("test.otf"); } html { font-family: Test; }</style>',
"http://127.0.0.1:1234/test.otf", "font", false, false
],
[
"XMLHttpRequest loading",
- '<script>var request = new XMLHttpRequest();request.open("GET", "test.xml", false);request.send(null);</script>',
+ '<script>' +
+ 'try' +
+ '{' +
+ 'var request = new XMLHttpRequest();' +
+ 'request.open("GET", "test.xml", false);' +
+ 'request.send(null);' +
+ '}' +
+ 'catch(e){}' +
+ '</script>',
"http://127.0.0.1:1234/test.xml", "xmlhttprequest", false, false
],
[
"XML document loading",
- '<script>var xmlDoc = document.implementation.createDocument(null, "root", null);xmlDoc.async = false;xmlDoc.load("test.xml")</script>',
+ '<script>' +
+ 'try' +
+ '{' +
+ 'var xmlDoc = document.implementation.createDocument(null, "root", null);' +
+ 'xmlDoc.async = false;' +
+ 'xmlDoc.load("test.xml");' +
+ '}' +
+ 'catch(e){}' +
+ '</script>',
"http://127.0.0.1:1234/test.xml", "xmlhttprequest", false, false
],
[
"Web worker",
- '<script>try { var worker = new Worker("test.js"); worker.onerror = function() { parent.postMessage("loaded", "*"); }; } catch (e) { parent.postMessage("error", "*"); }</script>',
+ '<script>' +
+ 'var e = new CustomEvent(\'abp:frameready\', {bubbles: true});' +
+ 'try' +
+ '{' +
+ 'var worker = new Worker("test.js");' +
+ 'worker.onerror = function(event)' +
+ '{' +
+ 'event.preventDefault();' +
+ 'document.dispatchEvent(e);' +
+ '};' +
+ '}' +
+ 'catch (x)' +
+ '{' +
+ 'document.dispatchEvent(e);' +
+ '}' +
+ '</script>',
"http://127.0.0.1:1234/test.js", "script", false, true
],
];
if (window.navigator.mimeTypes["application/x-shockwave-flash"] && window.navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
{
tests.push([
"HTML embed (Flash)",
@@ -243,29 +287,43 @@
// Ignore duplicate policy calls (possible due to prefetching)
let [prevWnd, prevNode, prevItem] = policyHits[policyHits.length - 1];
if (prevWnd == wnd && prevItem.location == item.location && prevItem.type == item.type && prevItem.docDomain == item.docDomain)
policyHits.pop();
}
policyHits.push([wnd, node, item]);
}
- function runTest([name, body, expectedURL, expectedType, expectedThirdParty, waitForMessage], stage)
+ function runTest([name, body, expectedURL, expectedType, expectedThirdParty, explicitEvent], stage)
{
defaultMatcher.clear();
if (stage > 1)
defaultMatcher.add(Filter.fromText(expectedURL));
if (stage == 3)
defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document"));
if (stage == 4)
defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$~document"));
if (stage == 5)
defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document,sitekey=" + publickey));
+ if (!explicitEvent)
+ {
+ if (body.indexOf("2000/svg") >= 0)
+ {
+ // SVG image: add an onload attribute to the document element
+ body = body.replace(/(<svg\b)/, '$1 onload="this.dispatchEvent(new CustomEvent(\'abp:frameready\', {bubbles: true}));"');
+ }
+ else
+ {
+ // HTML data: wrap it into a <body> tag
+ body = '<body onload="this.dispatchEvent(new CustomEvent(\'abp:frameready\', {bubbles: true}));">' + body + '</body>';
+ }
+ }
+
let serverHit = false;
server.registerPathHandler("/test", function(metadata, response)
{
response.setStatusLine("1.1", "200", "OK");
let contentType = "text/html";
if (body.indexOf("2000/svg") >= 0)
{
@@ -323,27 +381,22 @@
equal(item.typeDescr.toLowerCase(), expectedType, "Request type");
equal(item.thirdParty, expectedThirdParty, "Third-party flag");
equal(item.docDomain, "127.0.0.1", "Document domain");
}
}
server.registerPathHandler(expectedURL.replace(/http:\/\/[^\/]+/, ""), null);
equal(serverHit, expectedStatus == "allowed", "Request received by server");
- window.removeEventListener("message", callback, false);
- frame.removeEventListener("load", callback, false);
+ frame.removeEventListener("abp:frameready", callback, false);
start();
};
- frame.contentWindow.location.href = "http://127.0.0.1:1234/test";
-
- if (waitForMessage)
- window.addEventListener("message", callback, false, true);
- else
- frame.addEventListener("load", callback, false);
+ frame.addEventListener("abp:frameready", callback, false, true);
+ frame.setAttribute("src", "http://127.0.0.1:1234/test");
}
let stageDescriptions = {
1: "running without filters",
2: "running with filter %S",
3: "running with filter %S and site exception",
4: "running with filter %S and exception not applicable to sites",
5: "running with filter %S and sitekey exception"
« no previous file with comments | « chrome/content/tests/elemhide.js ('k') | chrome/content/tests/popupBlocker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld