Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / console / console-tainted-globals.html
index 2ef6471..804c118 100644 (file)
 <script src="../../http/tests/inspector/console-test.js"></script>
 <script>
 
-function foo()
+(function() {
+    var _originalFunctionCall = Function.prototype.call;
+    var _originalFunctionApply = Function.prototype.apply;
+
+    var _overriddenFunctionCall = function() {
+        original();
+        console.error("FAIL: Function.prototype.call should not be called!");
+        var result = _originalFunctionCall.apply(this, arguments);
+        overridden();
+        return result;
+    }
+
+    var _overriddenFunctionApply = function(thisArg, argsArray) {
+        original();
+        console.error("FAIL: Function.prototype.apply should not be called!");
+        var result = _originalFunctionApply.call(this, thisArg, argsArray);
+        overridden();
+        return result;
+    }
+
+    function original()
+    {
+        Function.prototype.call = _originalFunctionCall;
+        Function.prototype.apply = _originalFunctionApply;
+    }
+
+    function overridden()
+    {
+        Function.prototype.call = _overriddenFunctionCall;
+        Function.prototype.apply = _overriddenFunctionApply;
+    }
+
+    overridden();
+})();
+
+function throwGetter()
+{
+   console.error("FAIL: Should not be called!");
+   throw new Error("FAIL");
+}
+
+function testOverriddenArrayPushAndMathMax()
 {
     Object.defineProperty(Array.prototype, "push", {
-        get: function () { throw new Error("FAIL"); }
+        get: throwGetter
     });
     Object.defineProperty(Math, "max", {
-        get: function () { throw new Error("FAIL"); }
+        get: throwGetter
     });
     return [1, 2, 3];
 }
 
+function testOverriddenConstructorName()
+{
+    var obj = {};
+    obj.constructor = { name: "foo" };
+    return obj;
+}
+
+function testThrowConstructorName()
+{
+    var obj = {};
+    Object.defineProperty(obj, "constructor", {
+        get: throwGetter
+    });
+    return obj;
+}
+
 function test()
 {
-    InspectorTest.evaluateInConsole("foo()");
-    InspectorTest.runAfterPendingDispatches(step1);
+    InspectorTest.runTestSuite([
+        function evaluateInConsole(next)
+        {
+            InspectorTest.evaluateInConsole("testOverriddenArrayPushAndMathMax()");
+            InspectorTest.evaluateInConsole("testOverriddenConstructorName()");
+            InspectorTest.evaluateInConsole("testThrowConstructorName()");
+            InspectorTest.runAfterPendingDispatches(next);
+        },
 
-    function step1()
-    {
-        InspectorTest.dumpConsoleMessages();
-        InspectorTest.completeTest();
-    }
+        function testRuntimeAgentCallFunctionOn(next)
+        {
+            RuntimeAgent.evaluate("({ a : 1, b : 2 })", step1);
+
+            function step1(error, result, wasThrown)
+            {
+                function sum()
+                {
+                    return this.a + this.b;
+                }
+                RuntimeAgent.callFunctionOn(result.objectId, sum.toString(), step2);
+            }
+
+            function step2(error, result, wasThrown)
+            {
+                InspectorTest.assertEquals(3, result.value);
+                next();
+            }
+        },
+
+        function dumpConsoleMessages(next)
+        {
+            InspectorTest.dumpConsoleMessages();
+            next();
+        }
+    ]);
 }
 </script>
 </head>