Add memory space check routine before saving web storage data
[framework/web/webkit-efl.git] / LayoutTests / fullscreen / full-screen-test.js
1 var console = null;
2 var printFullTestDetails = true; // This is optionaly switched of by test whose tested values can differ. (see disableFullTestDetailsPrinting())
3 var runPixelTests;
4
5 logConsole();
6
7 if (window.testRunner) {
8     testRunner.dumpAsText(runPixelTests);
9     testRunner.waitUntilDone();
10 }
11
12 function runWithKeyDown(fn) 
13 {
14     // FIXME: WKTR does not yet support the keyDown() message.  Do a mouseDown here
15     // instead until keyDown support is added.
16     var eventName = !window.testRunner || eventSender.keyDown ? 'keypress' : 'mousedown'
17
18     function thunk() {
19         document.removeEventListener(eventName, thunk, false);
20         fn();
21     }
22     document.addEventListener(eventName, thunk, false);
23
24     if (window.testRunner) {
25         if (eventSender.keyDown)
26             eventSender.keyDown(" ", []);
27         else
28             eventSender.mouseDown();
29     }
30 }
31
32 function logConsole()
33 {
34     if (!console && document.body) {
35         console = document.createElement('div');
36         document.body.appendChild(console);
37     }
38     return console;
39 }
40
41 function testAndEnd(testFuncString)
42 {
43     test(testFuncString, true);
44 }
45
46 function test(testFuncString, endit)
47 {
48     logResult(eval(testFuncString), "TEST(" + testFuncString + ")");
49     if (endit)
50         endTest();  
51 }
52
53 function testExpected(testFuncString, expected, comparison)
54 {
55     try {
56         var observed = eval(testFuncString);
57     } catch (ex) {
58         consoleWrite(ex);
59         return;
60     }
61     
62     if (comparison === undefined)
63         comparison = '==';
64
65     var success = false;
66     switch (comparison)
67     {
68         case '<':  success = observed <  expected; break;
69         case '<=': success = observed <= expected; break;
70         case '>':  success = observed >  expected; break;
71         case '>=': success = observed >= expected; break;
72         case '!=': success = observed != expected; break;
73         case '==': success = observed == expected; break;
74     }
75     
76     reportExpected(success, testFuncString, comparison, expected, observed)
77 }
78
79 var testNumber = 0;
80
81 function reportExpected(success, testFuncString, comparison, expected, observed)
82 {
83     testNumber++;
84
85     var msg = "Test " + testNumber;
86
87     if (printFullTestDetails || !success)
88         msg = "EXPECTED (<em>" + testFuncString + " </em>" + comparison + " '<em>" + expected + "</em>')";
89
90     if (!success)
91         msg +=  ", OBSERVED '<em>" + observed + "</em>'";
92
93     logResult(success, msg);
94 }
95
96 function waitForEventAndEnd(element, eventName, funcString)
97 {
98     waitForEvent(element, eventName, funcString, true)
99 }
100
101 function waitForEventOnce(element, eventName, func, endit)
102 {
103     waitForEvent(element, eventName, func, endit, true)
104 }
105
106 function waitForEvent(element, eventName, func, endit, once)
107 {
108     function _eventCallback(event)
109     {
110         if (once)
111             element.removeEventListener(eventName, _eventCallback);
112
113         consoleWrite("EVENT(" + eventName + ")");
114
115         if (func)
116             func(event);
117         
118         if (endit)
119             endTest();    
120     }
121
122     element.addEventListener(eventName, _eventCallback);
123 }
124
125 function waitForEventAndTest(element, eventName, testFuncString, endit)
126 {
127     function _eventCallback(event)
128     {
129         logResult(eval(testFuncString), "EVENT(" + eventName + ") TEST(" + testFuncString + ")");
130         if (endit)
131             endTest();    
132     }
133
134     element.addEventListener(eventName, _eventCallback);
135 }
136
137 function waitForEventTestAndEnd(element, eventName, testFuncString)
138 {
139     waitForEventAndTest(element, eventName, testFuncString, true);
140 }
141   
142 var testEnded = false;
143
144 function endTest()
145 {
146     consoleWrite("END OF TEST");
147     testEnded = true;
148     if (window.testRunner)
149         testRunner.notifyDone();     
150 }
151
152 function logResult(success, text)
153 {
154     if (success)
155         consoleWrite(text + " <span style='color:green'>OK</span>");
156     else
157         consoleWrite(text + " <span style='color:red'>FAIL</span>");
158 }
159
160 function consoleWrite(text)
161 {
162     if (testEnded)
163         return;
164     logConsole().innerHTML += text + "<br>";
165 }