| Index: chrome/content/tests/policy.js |
| =================================================================== |
| --- a/chrome/content/tests/policy.js |
| +++ b/chrome/content/tests/policy.js |
| @@ -8,21 +8,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); |
| }, |
| teardown: function() |
| { |
| restoreFilterComponents.call(this); |
| restorePrefs.call(this); |
| stop(); |
| server.stop(function() |
| @@ -62,17 +63,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("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 |
| ], |
| [ |
| @@ -147,27 +160,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(\'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)", |
| @@ -218,27 +262,41 @@ |
| // 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 (!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(\'frameready\', {bubbles: true}));"'); |
| + } |
| + else |
| + { |
| + // HTML data: wrap it into a <body> tag |
| + body = '<body onload="this.dispatchEvent(new CustomEvent(\'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) |
| contentType = "image/svg+xml"; |
| @@ -289,27 +347,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("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("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", |
| }; |