diff options
Diffstat (limited to 'devtools/client/shared/components/test/mochitest/test_reps_number.html')
-rw-r--r-- | devtools/client/shared/components/test/mochitest/test_reps_number.html | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/devtools/client/shared/components/test/mochitest/test_reps_number.html b/devtools/client/shared/components/test/mochitest/test_reps_number.html new file mode 100644 index 000000000..50f91d8b0 --- /dev/null +++ b/devtools/client/shared/components/test/mochitest/test_reps_number.html @@ -0,0 +1,97 @@ +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> +<!DOCTYPE HTML> +<html> +<!-- +Test Number rep +--> +<head> + <meta charset="utf-8"> + <title>Rep test - Number</title> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> +</head> +<body> +<pre id="test"> +<script src="head.js" type="application/javascript;version=1.8"></script> +<script type="application/javascript;version=1.8"> +window.onload = Task.async(function* () { + let { Rep } = browserRequire("devtools/client/shared/components/reps/rep"); + let { Number } = browserRequire("devtools/client/shared/components/reps/number"); + + try { + yield testInt(); + yield testBoolean(); + yield testNegativeZero(); + yield testUnsafeInt(); + } catch(e) { + ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e)); + } finally { + SimpleTest.finish(); + } + + + function testInt() { + const renderedRep = shallowRenderComponent(Rep, { object: getGripStub("testInt") }); + is(renderedRep.type, Number.rep, `Rep correctly selects ${Number.rep.displayName} for integer value`); + + const renderedComponent = renderComponent(Number.rep, { object: getGripStub("testInt") }); + is(renderedComponent.textContent, "5", "Number rep has expected text content for integer"); + } + + function testBoolean() { + const renderedRep = shallowRenderComponent(Rep, { object: getGripStub("testTrue") }); + is(renderedRep.type, Number.rep, `Rep correctly selects ${Number.rep.displayName} for boolean value`); + + let renderedComponent = renderComponent(Number.rep, { object: getGripStub("testTrue") }); + is(renderedComponent.textContent, "true", "Number rep has expected text content for boolean true"); + + renderedComponent = renderComponent(Number.rep, { object: getGripStub("testFalse") }); + is(renderedComponent.textContent, "false", "Number rep has expected text content for boolean false"); + } + + function testNegativeZero() { + const renderedRep = shallowRenderComponent(Rep, { object: getGripStub("testNegZeroGrip") }); + is(renderedRep.type, Number.rep, `Rep correctly selects ${Number.rep.displayName} for negative zero value`); + + let renderedComponent = renderComponent(Number.rep, { object: getGripStub("testNegZeroGrip") }); + is(renderedComponent.textContent, "-0", "Number rep has expected text content for negative zero grip"); + + renderedComponent = renderComponent(Number.rep, { object: getGripStub("testNegZeroValue") }); + is(renderedComponent.textContent, "-0", "Number rep has expected text content for negative zero value"); + } + + function testUnsafeInt() { + const renderedComponent = renderComponent(Number.rep, { object: getGripStub("testUnsafeInt") }); + is(renderedComponent.textContent, "900719925474099100", "Number rep has expected text content for a long number"); + } + + function getGripStub(name) { + switch (name) { + case "testInt": + return 5; + + case "testTrue": + return true; + + case "testFalse": + return false; + + case "testNegZeroValue": + return -0; + + case "testNegZeroGrip": + return { + "type": "-0" + }; + + case "testUnsafeInt": + return 900719925474099122; + } + } +}); +</script> +</pre> +</body> +</html> |