Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / gamepad / gamepad-api.html
index cac3874..30a082d 100644 (file)
@@ -2,8 +2,66 @@
 <body>
 <script src="../resources/js-test.js"></script>
 <script>
+    description("Validates the exposed Gamepad API.")
+
     shouldBeDefined("navigator.webkitGetGamepads");
     shouldBeDefined("navigator.getGamepads");
+    shouldBeDefined("GamepadEvent");
+
+    webkitGamepads = navigator.webkitGetGamepads();
+    shouldBe("webkitGamepads.length", "4");
+    shouldBeUndefined("webkitGamepads[0]");
+    shouldBe("webkitGamepads.item.__proto__", "Function.prototype")
+    shouldBeNull("webkitGamepads.item(0)");
+
+    gamepads = navigator.getGamepads();
+    shouldBe("gamepads.length", "4");
+    shouldBeUndefined("gamepads[0]");
+    shouldBe("gamepads.item.__proto__", "Function.prototype")
+    shouldBeNull("gamepads.item(0)");
+
+    if (window.gamepadController)
+    {
+        gamepadController.connect(0);
+        gamepadController.setId(0, "MockStick 3000");
+        gamepadController.setButtonCount(0, 1);
+        gamepadController.setAxisCount(0, 1);
+
+        function checkProperties(isPrefixed) {
+            shouldBe("gamepad.id.__proto__", "String.prototype");
+            shouldBe("gamepad.connected.__proto__", "Boolean.prototype");
+            shouldBe("gamepad.index.__proto__", "Number.prototype");
+            shouldBe("gamepad.timestamp.__proto__", "Number.prototype");
+            shouldBe("gamepad.axes.__proto__", "Array.prototype");
+            shouldBe("gamepad.axes[0].__proto__", "Number.prototype");
+
+            shouldBe("gamepad.buttons.__proto__", "Array.prototype");
+            if (isPrefixed) {
+                shouldBe("gamepad.buttons[0].__proto__", "Number.prototype");
+            } else {
+                shouldBe("gamepad.buttons[0].pressed.__proto__", "Boolean.prototype");
+                shouldBe("gamepad.buttons[0].value.__proto__", "Number.prototype");
+            }
+
+            if (!isPrefixed)
+                shouldBe("gamepad.mapping.__proto__", "String.prototype");
+        }
+
+        gamepad = navigator.webkitGetGamepads()[0];
+        shouldBeNonNull("gamepad");
+        shouldBeTrue("gamepad.connected");
+        shouldBe("gamepad.__proto__", "WebKitGamepad.prototype");
+        checkProperties(true);
+
+        gamepad = navigator.getGamepads()[0];
+        shouldBeNonNull("gamepad");
+        shouldBeTrue("gamepad.connected");
+        shouldBe("gamepad.__proto__", "Gamepad.prototype");
+        checkProperties(false);
+    }
+    else
+    {
+        testFailed("no gamepadController available.");
+    }
 </script>
-<p>Make sure the main polling access point exists on navigator.</p>
 </body>