Upstream version 6.34.113.0
[platform/framework/web/crosswalk.git] / src / xwalk / sysapps / device_capabilities / device_capabilities_api_browsertest.html
1 <html>
2   <head>
3     <title></title>
4   </head>
5   <body>
6     <script>
7       var current_test = 0;
8       var test_list = [
9         getAVCodecs,
10         getCPUInfo,
11         getDisplayInfo,
12         getMemoryInfo,
13         getStorageInfo,
14         endTest
15       ];
16
17       function runNextTest() {
18         test_list[current_test++]();
19       };
20
21       function reportFail(message) {
22         console.log(message);
23         document.title = "Fail";
24       };
25
26       function endTest() {
27         document.title = "Pass";
28       };
29
30       var api = xwalk.experimental.system;
31
32       function getAVCodecs() {
33         function checkAVCodecsInfo(info) {
34           if (!info.audioCodecs)
35             reportFail("Missing AudioCodec attribute in the SystemAVCodecs object.");
36
37           if (!info.videoCodecs)
38             reportFail("Missing VideoCodec name in the SystemAVCodecs object.");
39
40           for (var i = 0; i < info.audioCodecs.length; ++i) {
41             if (info.audioCodecs[i].format == null)
42               reportFail("Missing audio encoding format in the AudioCodec object.");
43
44             if (typeof info.audioCodecs[i].format != "string")
45               reportFail("Audio encoding format is not a string.");
46           }
47
48           for (var i = 0; i < info.videoCodecs.length; ++i) {
49             if (info.videoCodecs[i].format == null)
50               reportFail("Missing video encoding format in the VideoCodec object.");
51
52             if (typeof info.videoCodecs[i].format != "string")
53               reportFail("Video encoding format is not a string.");
54
55             if (info.videoCodecs[i].hwAccel == null)
56               reportFail("Missing hwAccel in the VideoCodec object.");
57
58             if (typeof info.videoCodecs[i].hwAccel != "boolean")
59               reportFail("hwAccel is not a boolean.");
60
61             if (info.videoCodecs[i].encode == null)
62               reportFail("Missing encode in the VideoCodec object.");
63
64             if (typeof info.videoCodecs[i].encode != "boolean")
65               reportFail("encode is not a boolean.");
66           }
67
68           if (document.title != "Fail")
69             runNextTest();
70         };
71
72         api.getAVCodecs().then(checkAVCodecsInfo);
73       };
74
75       function getCPUInfo() {
76         var call_max = 1000;
77         var call_count = 0;
78
79         function checkCPUInfo(info) {
80           if (info.numOfProcessors < 1)
81             reportFail("What!? A computer with less than 1 CPU?");
82
83           if (!info.archName)
84             reportFail("Missing archtecture name in the SystemCPU object.");
85
86           if (typeof info.archName != "string")
87             reportFail("Archtecture name is not a string.");
88
89           if (info.load < 0 || info.load > 1)
90             reportFail("Load should be in the range of 0 and 1.");
91
92           if (++call_count == call_max)
93             runNextTest();
94         };
95
96         for (var i = 0; i < call_max; ++i)
97           api.getCPUInfo().then(checkCPUInfo, reportFail);
98       };
99
100       function getDisplayInfo() {
101         function checkDisplayInfo(info) {
102           for (var i = 0; i < info.displays.length; ++i) {
103             if (typeof info.displays[i].id != "string")
104               reportFail("Display id is not a string.");
105
106             if (info.displays[i].id.length == 0)
107               reportFail("Display id can't be empty.");
108
109             if (typeof info.displays[i].name != "string")
110               reportFail("Display name is not a string.");
111
112             if (typeof info.displays[i].primary != "boolean")
113               reportFail("Display type is not a boolean.");
114
115             if (typeof info.displays[i].external != "boolean")
116               reportFail("Display type is not a boolean.");
117
118             if (typeof info.displays[i].deviceXDPI != "number")
119               reportFail("Display deviceXDPI must be a number.");
120
121             if (typeof info.displays[i].deviceYDPI != "number")
122               reportFail("Display deviceYDPI must be a number.");
123
124             if (typeof info.displays[i].width != "number")
125               reportFail("Display width must be a number.");
126
127             if (typeof info.displays[i].height != "number")
128               reportFail("Display height must be a number.");
129
130             if (typeof info.displays[i].availWidth != "number")
131               reportFail("Display availWidth must be a number.");
132
133             if (typeof info.displays[i].availHeight != "number")
134               reportFail("Display availHeight must be a number.");
135
136             if (typeof info.displays[i].colorDepth != "number")
137               reportFail("Display colorDepth must be a number.");
138
139             if (typeof info.displays[i].pixelDepth != "number")
140               reportFail("Display pixelDepth must be a number.");
141           }
142
143           if (document.title != "Fail")
144             runNextTest();
145         };
146
147         api.getDisplayInfo().then(checkDisplayInfo);
148       };
149
150       function getMemoryInfo() {
151         function checkMemoryInfo(info) {
152           if (info.capacity <= 0)
153             reportFail("How can we run this in a computer with no memory?");
154
155           if (info.availCapacity <= 0)
156             reportFail("You should have some free memory to run this test.");
157
158           if (info.availCapacity > info.capacity)
159             reportFail("Availiable memory cannot be more than the total memory.");
160
161           if (document.title != "Fail")
162             runNextTest();
163         };
164
165         api.getMemoryInfo().then(checkMemoryInfo, reportFail);
166       };
167
168       function getStorageInfo() {
169         function checkStorageInfo(info) {
170           if (!info.storages)
171             reportFail("We must have at least 1 storage device.");
172
173           for (var i = 0; i < info.storages.length; ++i) {
174             if (typeof info.storages[i].id != "string")
175               reportFail("Storage id is not a string.");
176
177             if (info.storages[i].id.length == 0)
178               reportFail("Storage id can't be empty.");
179
180             if (typeof info.storages[i].name != "string")
181               reportFail("Storage name is not a string.");
182
183             if (typeof info.storages[i].type != "string")
184               reportFail("Storage type is not a string.");
185
186             if (info.storages[i].type.length == 0)
187               reportFail("Storage type can't be empty.");
188
189             if (typeof info.storages[i].capacity != "number")
190               reportFail("Storage capacity must be a number.");
191
192             if (info.storages[i].capacty <= 0)
193               reportFail("Storage has to be able to store something.");
194           }
195
196           if (document.title != "Fail")
197             runNextTest();
198         };
199
200         api.getStorageInfo().then(checkStorageInfo);
201       };
202
203       runNextTest();
204     </script>
205   </body>
206 </html>