Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / console / console-tainted-globals.html
blob29dc150122c5bec402d398135aac5535d9dd2582
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>
7 var originalError = window.Error;
9 (function() {
10 var originalFunctionCall = Function.prototype.call;
11 var originalFunctionApply = Function.prototype.apply;
13 var overriddenFunctionCall = function() {
14 original();
15 console.error("FAIL: Function.prototype.call should not be called!");
16 var result = originalFunctionCall.apply(this, arguments);
17 overridden();
18 return result;
21 var overriddenFunctionApply = function(thisArg, argsArray) {
22 original();
23 console.error("FAIL: Function.prototype.apply should not be called!");
24 var result = originalFunctionApply.call(this, thisArg, argsArray);
25 overridden();
26 return result;
29 function original()
31 Function.prototype.call = originalFunctionCall;
32 Function.prototype.apply = originalFunctionApply;
35 function overridden()
37 Function.prototype.call = overriddenFunctionCall;
38 Function.prototype.apply = overriddenFunctionApply;
41 overridden();
42 })();
44 function throwGetter()
46 console.error("FAIL: Should not be called!");
47 throw new Error("FAIL");
50 function testOverriddenArrayPushAndMathMax()
52 Object.defineProperty(Array.prototype, "push", {
53 get: throwGetter
54 });
55 Object.defineProperty(Math, "max", {
56 get: throwGetter
57 });
58 return [1, 2, 3];
61 function testOverriddenConstructorName()
63 var obj = {};
64 obj.constructor = { name: "foo" };
65 return obj;
68 function testThrowConstructorName()
70 var obj = {};
71 Object.defineProperty(obj, "constructor", {
72 get: throwGetter
73 });
74 return obj;
77 function testOverriddenIsFinite()
79 window.isFinite = throwGetter;
80 var out;
81 (function() {
82 out = arguments;
83 })("arg1", "arg2");
84 return out;
87 function testOverriddenError()
89 window.Error = 42;
90 return { result: "PASS" };
93 function restoreError()
95 window.Error = originalError;
96 return { result: "PASS" };
99 function testOverriddenToString(obj, overrideThrow)
101 if (overrideThrow)
102 var func = function() { throw new Error; }
103 else
104 var func = function() { return [1]; }
106 Object.defineProperty(obj, "toString", { value: func, enumerable: false });
107 Object.defineProperty(obj, "valueOf", { value: func, enumerable: false });
109 // Now the ("" + obj) expression should throw.
110 try {
111 var dummy = "" + obj;
112 console.error("FAIL: Expected to throw but got: " + dummy);
113 } catch (e) {
116 return obj;
119 function test()
121 InspectorTest.runTestSuite([
122 function evaluateInConsole(next)
124 var expressions = [
125 "testOverriddenArrayPushAndMathMax()",
126 "testOverriddenConstructorName()",
127 "testThrowConstructorName()",
128 "testOverriddenIsFinite()",
129 "testOverriddenError()",
130 "restoreError()",
131 "testOverriddenToString(function func() {}, true)",
132 "testOverriddenToString(function func() {}, false)",
133 "testOverriddenToString(new Function, true)",
134 "testOverriddenToString(new Function, false)",
135 "testOverriddenToString(/^regex$/, true)",
136 "testOverriddenToString(/^regex$/, false)",
137 "testOverriddenToString(new Date, true)",
138 "testOverriddenToString(new Date, false)",
139 "testOverriddenToString({}, true)",
140 "testOverriddenToString({}, false)",
141 "testOverriddenToString(new Number(1), true)",
142 "testOverriddenToString(new Number(1), false)",
145 function iterate()
147 var expr = expressions.shift();
148 if (!expr) {
149 InspectorTest.runAfterPendingDispatches(next);
150 return;
152 InspectorTest.evaluateInConsole(expr, iterate);
154 iterate();
157 function testRuntimeAgentCallFunctionOn(next)
159 InspectorTest.RuntimeAgent.evaluate("({ a : 1, b : 2 })", step1);
161 function step1(error, result, wasThrown)
163 function sum()
165 return this.a + this.b;
167 InspectorTest.RuntimeAgent.callFunctionOn(result.objectId, sum.toString(), step2);
170 function step2(error, result, wasThrown)
172 InspectorTest.assertEquals(3, result.value);
173 next();
177 function dumpConsoleMessages(next)
179 InspectorTest.dumpConsoleMessages();
180 next();
184 </script>
185 </head>
187 <body onload="runTest()">
189 Tests that overriding global methods (like Array.prototype.push, Math.max) will not break the inspector.
190 </p>
192 </body>
193 </html>