upload tizen1.0 source
[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.layoutTestController) {
8     layoutTestController.dumpAsText(runPixelTests);
9     layoutTestController.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.layoutTestController || 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.layoutTestController) {
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 waitForEvent(element, eventName, func, endit)
102 {
103     function _eventCallback(event)
104     {
105         consoleWrite("EVENT(" + eventName + ")");
106
107         if (func)
108             func(event);
109         
110         if (endit)
111             endTest();    
112     }
113
114     element.addEventListener(eventName, _eventCallback);
115 }
116
117 function waitForEventAndTest(element, eventName, testFuncString, endit)
118 {
119     function _eventCallback(event)
120     {
121         logResult(eval(testFuncString), "EVENT(" + eventName + ") TEST(" + testFuncString + ")");
122         if (endit)
123             endTest();    
124     }
125
126     element.addEventListener(eventName, _eventCallback);
127 }
128
129 function waitForEventTestAndEnd(element, eventName, testFuncString)
130 {
131     waitForEventAndTest(element, eventName, testFuncString, true);
132 }
133   
134 var testEnded = false;
135
136 function endTest()
137 {
138     consoleWrite("END OF TEST");
139     testEnded = true;
140     if (window.layoutTestController)
141         layoutTestController.notifyDone();     
142 }
143
144 function logResult(success, text)
145 {
146     if (success)
147         consoleWrite(text + " <span style='color:green'>OK</span>");
148     else
149         consoleWrite(text + " <span style='color:red'>FAIL</span>");
150 }
151
152 function consoleWrite(text)
153 {
154     if (testEnded)
155         return;
156     logConsole().innerHTML += text + "<br>";
157 }