Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / console / console-tainted-globals.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/console-test.js"></script>
5 <script>
6
7 (function() {
8     var _originalFunctionCall = Function.prototype.call;
9     var _originalFunctionApply = Function.prototype.apply;
10
11     var _overriddenFunctionCall = function() {
12         original();
13         console.error("FAIL: Function.prototype.call should not be called!");
14         var result = _originalFunctionCall.apply(this, arguments);
15         overridden();
16         return result;
17     }
18
19     var _overriddenFunctionApply = function(thisArg, argsArray) {
20         original();
21         console.error("FAIL: Function.prototype.apply should not be called!");
22         var result = _originalFunctionApply.call(this, thisArg, argsArray);
23         overridden();
24         return result;
25     }
26
27     function original()
28     {
29         Function.prototype.call = _originalFunctionCall;
30         Function.prototype.apply = _originalFunctionApply;
31     }
32
33     function overridden()
34     {
35         Function.prototype.call = _overriddenFunctionCall;
36         Function.prototype.apply = _overriddenFunctionApply;
37     }
38
39     overridden();
40 })();
41
42 function throwGetter()
43 {
44    console.error("FAIL: Should not be called!");
45    throw new Error("FAIL");
46 }
47
48 function testOverriddenArrayPushAndMathMax()
49 {
50     Object.defineProperty(Array.prototype, "push", {
51         get: throwGetter
52     });
53     Object.defineProperty(Math, "max", {
54         get: throwGetter
55     });
56     return [1, 2, 3];
57 }
58
59 function testOverriddenConstructorName()
60 {
61     var obj = {};
62     obj.constructor = { name: "foo" };
63     return obj;
64 }
65
66 function testThrowConstructorName()
67 {
68     var obj = {};
69     Object.defineProperty(obj, "constructor", {
70         get: throwGetter
71     });
72     return obj;
73 }
74
75 function testOverriddenIsFinite()
76 {
77     window.isFinite = throwGetter;
78     var out;
79     (function() {
80         out = arguments;
81     })("arg1", "arg2");
82     return out;
83 }
84
85 function test()
86 {
87     InspectorTest.runTestSuite([
88         function evaluateInConsole(next)
89         {
90             var expressions = [
91                 "testOverriddenArrayPushAndMathMax()",
92                 "testOverriddenConstructorName()",
93                 "testThrowConstructorName()",
94                 "testOverriddenIsFinite()"
95             ];
96
97             function iterate()
98             {
99                 var expr = expressions.shift();
100                 if (!expr) {
101                     InspectorTest.runAfterPendingDispatches(next);
102                     return;
103                 }
104                 InspectorTest.evaluateInConsole(expr, iterate);
105             }
106             iterate();
107         },
108
109         function testRuntimeAgentCallFunctionOn(next)
110         {
111             RuntimeAgent.evaluate("({ a : 1, b : 2 })", step1);
112
113             function step1(error, result, wasThrown)
114             {
115                 function sum()
116                 {
117                     return this.a + this.b;
118                 }
119                 RuntimeAgent.callFunctionOn(result.objectId, sum.toString(), step2);
120             }
121
122             function step2(error, result, wasThrown)
123             {
124                 InspectorTest.assertEquals(3, result.value);
125                 next();
126             }
127         },
128
129         function dumpConsoleMessages(next)
130         {
131             InspectorTest.dumpConsoleMessages();
132             next();
133         }
134     ]);
135 }
136 </script>
137 </head>
138
139 <body onload="runTest()">
140 <p>
141 Tests that overriding global methods (like Array.prototype.push, Math.max) will not break the inspector.
142 </p>
143
144 </body>
145 </html>