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

Delta Between Two Patch Sets: chrome/content/tests/policy.js

Issue 6280417539784704: Issue 101 - Fix policy tests (Closed)
Left Patch Set: Created July 9, 2014, 5:04 p.m.
Right Patch Set: Created July 10, 2014, 7:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 (function() 1 (function()
2 { 2 {
3 let server = null; 3 let server = null;
4 let frame = null; 4 let frame = null;
5 let requestNotifier = null; 5 let requestNotifier = null;
6 6
7 module("Content policy", { 7 module("Content policy", {
8 setup: function() 8 setup: function()
9 { 9 {
10 prepareFilterComponents.call(this); 10 prepareFilterComponents.call(this);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 [ 195 [
196 "HTML object (Java)", 196 "HTML object (Java)",
197 '<object type="application/x-java-applet" data="test.class"></object>', 197 '<object type="application/x-java-applet" data="test.class"></object>',
198 "http://127.0.0.1:1234/test.class", "object", false, false 198 "http://127.0.0.1:1234/test.class", "object", false, false
199 ]); 199 ]);
200 } 200 }
201 201
202 let policyHits = []; 202 let policyHits = [];
203 function onPolicyHit(wnd, node, item, scanComplete) 203 function onPolicyHit(wnd, node, item, scanComplete)
204 { 204 {
205 if (!item) { 205 if (!item)
Wladimir Palant 2014/07/09 18:48:32 Nit: opening { belongs onto the next line. Alterna
206 return; 206 return;
207 }
208 if (item.location == "http://127.0.0.1:1234/test" || 207 if (item.location == "http://127.0.0.1:1234/test" ||
209 item.location == "http://127.0.0.1:1234/redirect.gif" || 208 item.location == "http://127.0.0.1:1234/redirect.gif" ||
210 item.location == "http://127.0.0.1:1234/redirect2.gif") 209 item.location == "http://127.0.0.1:1234/redirect2.gif")
211 { 210 {
212 return; 211 return;
213 } 212 }
214 if (item.filter instanceof WhitelistFilter) 213 if (item.filter instanceof WhitelistFilter)
215 return; 214 return;
216 215
217 if (policyHits.length > 0) 216 if (policyHits.length > 0)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 287
289 equal(actualStatus, expectedStatus, "Request blocked"); 288 equal(actualStatus, expectedStatus, "Request blocked");
290 equal(item.typeDescr.toLowerCase(), expectedType, "Request type"); 289 equal(item.typeDescr.toLowerCase(), expectedType, "Request type");
291 equal(item.thirdParty, expectedThirdParty, "Third-party flag"); 290 equal(item.thirdParty, expectedThirdParty, "Third-party flag");
292 equal(item.docDomain, "127.0.0.1", "Document domain"); 291 equal(item.docDomain, "127.0.0.1", "Document domain");
293 } 292 }
294 } 293 }
295 server.registerPathHandler(expectedURL.replace(/http:\/\/[^\/]+/, ""), nul l); 294 server.registerPathHandler(expectedURL.replace(/http:\/\/[^\/]+/, ""), nul l);
296 equal(serverHit, expectedStatus == "allowed", "Request received by server" ); 295 equal(serverHit, expectedStatus == "allowed", "Request received by server" );
297 296
298 if (waitForMessage) { 297 window.removeEventListener("message", callback, true);
Wladimir Palant 2014/07/09 18:48:32 Nit: As above, the opening { belongs onto the next
299 window.removeEventListener("message", callback, true) 298 frame.removeEventListener("load", callback, true);
300 }
Wladimir Palant 2014/07/09 18:48:32 No need to remove conditionally, we can simply alw
301 299
302 start(); 300 start();
303 }; 301 };
304 frame.contentWindow.location.href = "http://127.0.0.1:1234/test"; 302 frame.contentWindow.location.href = "http://127.0.0.1:1234/test";
305 303
306 if (waitForMessage) { 304 if (waitForMessage)
Wladimir Palant 2014/07/09 18:48:32 Nit: As above, the opening { belongs onto the next
307 window.addEventListener("message", callback, true, true); 305 window.addEventListener("message", callback, true, true);
308 } else { 306 else
309 frame.onload = callback; 307 frame.addEventListener("load", callback, true, true);
Wladimir Palant 2014/07/09 18:48:32 Feel free to use frame.addEventListener("load", ..
Wladimir Palant 2014/07/14 13:33:54 I don't think that we need a capturing listener, a
310 }
311
312 } 308 }
313 309
314 let stageDescriptions = { 310 let stageDescriptions = {
315 1: "running without filters", 311 1: "running without filters",
316 2: "running with filter %S", 312 2: "running with filter %S",
317 3: "running with filter %S and site exception", 313 3: "running with filter %S and site exception",
318 4: "running with filter %S and exception not applicable to sites", 314 4: "running with filter %S and exception not applicable to sites",
319 }; 315 };
320 316
321 for (let test = 0; test < tests.length; test++) 317 for (let test = 0; test < tests.length; test++)
322 { 318 {
323 let [name, body, expectedURL, expectedType, expectedDomain, expectedThirdPar ty] = tests[test]; 319 let [name, body, expectedURL, expectedType, expectedDomain, expectedThirdPar ty] = tests[test];
324 for (let stage = 1; stage in stageDescriptions; stage++) 320 for (let stage = 1; stage in stageDescriptions; stage++)
325 { 321 {
326 let stageDescription = stageDescriptions[stage]; 322 let stageDescription = stageDescriptions[stage];
327 if (stageDescription.indexOf("%S") >= 0) 323 if (stageDescription.indexOf("%S") >= 0)
328 stageDescription = stageDescription.replace("%S", expectedURL); 324 stageDescription = stageDescription.replace("%S", expectedURL);
329 325
330 asyncTest(name + " (" + stageDescription + ")", runTest.bind(null, tests[t est], stage)); 326 asyncTest(name + " (" + stageDescription + ")", runTest.bind(null, tests[t est], stage));
331 } 327 }
332 } 328 }
333 })(); 329 })();
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld