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

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

Issue 29329739: Issue 3226 - Adjust content policy unit tests for e10s-related content policy changes (Closed)
Patch Set: Created Nov. 4, 2015, 11:09 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 | « no previous file | no next file » | 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,22 +9,23 @@
setup: function()
{
prepareFilterComponents.call(this);
preparePrefs.call(this);
server = new nsHttpServer();
server.start(1234);
- frame = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "iframe");
+ frame = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "browser");
frame.setAttribute("type", "content");
+ frame.setAttribute("disablehistory", "true");
frame.style.visibility = "collapse";
document.body.appendChild(frame);
- requestNotifier = new RequestNotifier(frame.contentWindow, onPolicyHit);
+ requestNotifier = new RequestNotifier(frame.outerWindowID, 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);
@@ -265,37 +266,37 @@
[
"HTML object (Java)",
'<object type="application/x-java-applet" data="test.class"></object>',
"http://127.0.0.1:1234/test.class", "object", false, false
]);
}
let policyHits = [];
- function onPolicyHit(wnd, node, item, scanComplete)
+ function onPolicyHit(item, scanComplete)
{
if (!item)
return;
if (item.location == "http://127.0.0.1:1234/test" ||
item.location == "http://127.0.0.1:1234/redirect.gif" ||
item.location == "http://127.0.0.1:1234/redirect2.gif")
{
return;
}
- if (item.filter instanceof WhitelistFilter)
+ if (item.filter && item.filter.substr(0, 2) == "@@")
return;
if (policyHits.length > 0)
{
// 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)
+ let prevItem = policyHits[policyHits.length - 1];
+ if (prevItem.location == item.location && prevItem.type == item.type && prevItem.docDomain == item.docDomain)
policyHits.pop();
}
- policyHits.push([wnd, node, item]);
+ policyHits.push(item);
}
function runTest([name, body, expectedURL, expectedType, expectedThirdParty, explicitEvent], stage)
{
defaultMatcher.clear();
if (stage == 7)
defaultMatcher.add(Filter.fromText(expectedURL + "$domain=127.0.0.1"));
@@ -362,49 +363,57 @@
response.setHeader("Content-Type", "text/html");
// Work around weird Firefox behavior, where worker scripts succesfully load with empty 404 pages.
var error = "<b>Not found...<b>";
response.bodyOutputStream.write(error, error.length);
});
policyHits = [];
- var callback = function()
+ let callback = function()
{
+ frame.messageManager.removeMessageListener("ready", callback);
+
let expectedStatus = "allowed";
if (stage == 3)
equal(policyHits.length, 0, "Number of policy hits");
// We cannot rely on the correctness of policy hits for sitekey filters due to blocking
// filter hits being counted even if the resource doesn't end up getting blocked
else if (stage != 5 && stage != 6 && stage != 8)
{
equal(policyHits.length, 1, "Number of policy hits");
if (policyHits.length == 1)
{
- let [wnd, node, item] = policyHits[0];
+ let item = policyHits[0];
equal(item.location, expectedURL, "Request URL");
expectedStatus = (stage == 1 ? "allowed" : "blocked");
let actualStatus = (item.filter ? "blocked" : "allowed");
equal(actualStatus, expectedStatus, "Request blocked");
equal(item.type.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");
- frame.removeEventListener("abp:frameready", callback, false);
-
start();
};
- frame.addEventListener("abp:frameready", callback, false, true);
+ let callback2 = function()
+ {
+ // The frame will report hits asynchronously so make the frame send us a
+ // message and only process the results after it is received.
+ frame.removeEventListener("abp:frameready", callback2, false);
+ frame.messageManager.addMessageListener("ready", callback);
+ frame.messageManager.loadFrameScript("data:text/javascript,sendAsyncMessage('ready')", false);
+ };
+ frame.addEventListener("abp:frameready", callback2, 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",
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld