Try to make some xssAuditor tests less flakey.
[webkit:qtwebkit.git] / LayoutTests / http / tests / security / xssAuditor / resources / utilities.js
1 function checkIfFrameLocationMatchesURLAndCallDone(frameId, expectedURL)
2 {
3     if (!window.layoutTestController)
4         return;
5     if (document.getElementById(frameId).contentWindow.location == expectedURL)
6         layoutTestController.notifyDone();
7 }
8
9 function sendRequestFromIFrame(url, params, HTTPMethod, callbackWhenDone)
10 {
11     if (!params || !params.length)
12         return;
13         
14     if (!HTTPMethod)
15         HTTPMethod = 'GET';
16         
17     if (document.getElementById('frame'))
18         document.body.removeChild(document.getElementById('frame'));
19     var iFrameObj = document.createElement('iframe');
20     iFrameObj.id = 'frame';
21     document.body.appendChild(iFrameObj);
22     var frameContent = iFrameObj.contentDocument;
23     frameContent.open();
24     frameContent.write('<form method="' + HTTPMethod + '" name="form" id="form" action="' + url + '">');
25     if (params.length > 0) {
26         var paramArray = params.split('&');
27         for (var i = 0; i < paramArray.length; ++i) {
28             var paramElement = paramArray[i].split('=', 2);
29             frameContent.write('<input type="text" name="' + paramElement[0] + '" value="' + paramElement[1] + '">');
30         }   
31     }
32     frameContent.write('</form>');
33     frameContent.close();
34     if (callbackWhenDone)
35         iFrameObj.onload = callbackWhenDone;
36     frameContent.getElementById('form').submit();
37 }
38
39
40 function notifyDoneAfterReceivingBeforeloadFromIds(ids)
41 {
42     var loadAttempted = 0;
43     window.addEventListener("message", function(event) {
44         var index = ids.indexOf(event.data);
45         if (index == -1)
46             return;
47
48         loadAttempted = loadAttempted | (1 << index);
49         if (loadAttempted == (1 << ids.length) - 1)
50             layoutTestController.notifyDone();
51     }, false);
52 }
53