Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / Window / resources / window-property-collector.js
1 function collectProperties()
2 {
3     // Collect properties of the top-level window, since touching the properties
4     // of a DOMWindow affects its internal C++ state.
5     collectPropertiesHelper(window, []);
6
7     propertiesToVerify.sort(function (a, b)
8     {
9         if (a.property < b.property)
10             return -1
11         if (a.property > b.property)
12             return 1;
13         return 0;
14     });
15 }
16
17 function emitExpectedResult(path, expected)
18 {
19     // Skip internals properties, since they aren't web accessible.
20     if (path[0] == 'internals'
21         || path[0] == 'propertiesToVerify' // Skip the list we're building...
22         || path[0] == 'clientInformation' // Just an alias for navigator.
23         || path[0] == 'testRunner' // Skip testRunner since they are only for testing.
24         || path[0] == 'layoutTestController' // Just an alias for testRunner.
25         || path[0] == 'eventSender') { // Skip eventSender since they are only for testing.
26         return;
27     }
28
29     // Skip the properties which are hard to expect a stable result.
30     if (path[0] == 'accessibilityController' // we can hardly estimate the states of the cached WebAXObjects.
31         || path[0] == 'localStorage') { // local storage is not reliably cleared between tests.
32         return;
33     }
34
35     // FIXME: Skip MemoryInfo for now, since it's not implemented as a DOMWindowProperty, and has
36     // no way of knowing when it's detached. Eventually this should have the same behavior.
37     if (path.length >= 2 && (path[0] == 'console' || path[0] == 'performance') && path[1] == 'memory')
38         return;
39
40     // Skip things that are assumed to be constants.
41     if (path[path.length - 1].toUpperCase() == path[path.length - 1])
42         return;
43
44     // Various special cases for legacy reasons. Please do not add entries to this list.
45     var propertyPath = path.join('.');
46     switch (propertyPath) {
47     case "location.href":
48         expected = "'about:blank'";
49         break;
50     case "location.origin":
51         expected = "'null'";
52         break;
53     case "location.pathname":
54         expected = "'blank'";
55         break;
56     case "location.protocol":
57         expected = "'about:'";
58         break;
59     case "navigator.appCodeName":
60     case "navigator.appName":
61     case "navigator.language":
62     case "navigator.onLine":
63     case "navigator.platform":
64     case "navigator.product":
65     case "navigator.productSub":
66     case "navigator.vendor":
67         expected = "window." + propertyPath;
68         break;
69     case "screen.orientation":
70         expected = "'portrait-primary'";
71         break;
72     }
73
74     insertExpectedResult(path, expected);
75 }
76
77 function collectPropertiesHelper(object, path)
78 {
79     if (path.length > 20)
80         throw 'Error: probably looping';
81
82     for (var property in object) {
83         path.push(property);
84         var type = typeof(object[property]);
85         if (type == "object") {
86             if (object[property] === null) {
87                 emitExpectedResult(path, "null");
88             } else if (!object[property].Window
89                 && !(object[property] instanceof Node)
90                 && !(object[property] instanceof MimeTypeArray)
91                 && !(object[property] instanceof PluginArray)) {
92                 // Skip some traversing through types that will end up in cycles...
93                 collectPropertiesHelper(object[property], path);
94             }
95         } else if (type == "string") {
96             emitExpectedResult(path, "''");
97         } else if (type == "number") {
98             emitExpectedResult(path, "0");
99         } else if (type == "boolean") {
100             emitExpectedResult(path, "false");
101         }
102         path.pop();
103     }
104 }