mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 17:55:50 +00:00
Bug 1264685 - [rep tests] Add tests for grip rep. r=Honza
This commit is contained in:
parent
c9ebf6bbda
commit
4f748ab59f
@ -7,6 +7,7 @@ support-files =
|
||||
[test_notification_box_02.html]
|
||||
[test_notification_box_03.html]
|
||||
[test_reps_date-time.html]
|
||||
[test_reps_grip.html]
|
||||
[test_reps_object-with-url.html]
|
||||
[test_reps_stylesheet.html]
|
||||
[test_reps_undefined.html]
|
||||
|
@ -0,0 +1,435 @@
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
Test grip rep
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Rep test - grip</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 { Grip } = browserRequire("devtools/client/shared/components/reps/grip");
|
||||
|
||||
try {
|
||||
yield testBasic();
|
||||
|
||||
// Test property iterator
|
||||
yield testMaxProps();
|
||||
yield testMoreThanMaxProps();
|
||||
yield testUninterestingProps();
|
||||
|
||||
// Test that properties are rendered as expected by PropRep
|
||||
yield testNestedObject();
|
||||
yield testNestedArray();
|
||||
} catch(e) {
|
||||
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
|
||||
} finally {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function testBasic() {
|
||||
// Test object: `{}`
|
||||
const testName = "testBasic";
|
||||
|
||||
// Test that correct rep is chosen
|
||||
const gripStub = getGripStub("testBasic");
|
||||
const renderedRep = shallowRenderComponent(Rep, { object: gripStub });
|
||||
is(renderedRep.type, Grip.rep, `Rep correctly selects ${Grip.rep.displayName}`);
|
||||
|
||||
// Test rendering
|
||||
const defaultOutput = `Object`;
|
||||
|
||||
const modeTests = [
|
||||
{
|
||||
mode: undefined,
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "tiny",
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "short",
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "long",
|
||||
expectedOutput: defaultOutput,
|
||||
}
|
||||
];
|
||||
|
||||
testRenderingInMode(modeTests, testName);
|
||||
}
|
||||
|
||||
function testMaxProps() {
|
||||
// Test object: `{a: "a", b: "b", c: "c"}`;
|
||||
const testName = "testMaxProps";
|
||||
|
||||
const defaultOutput = `Object {a: "a", b: "b", c: "c"}`;
|
||||
|
||||
const modeTests = [
|
||||
{
|
||||
mode: undefined,
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "tiny",
|
||||
expectedOutput: `Object`,
|
||||
},
|
||||
{
|
||||
mode: "short",
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "long",
|
||||
expectedOutput: defaultOutput,
|
||||
}
|
||||
];
|
||||
|
||||
testRenderingInMode(modeTests, testName);
|
||||
}
|
||||
|
||||
function testMoreThanMaxProps() {
|
||||
// Test object = `{a: "a", b: "b", c: "c", d: "d", e: "e"}`
|
||||
const testName = "testMoreThanMaxProps";
|
||||
|
||||
const defaultOutput = `Object {a: "a", b: "b", c: "c", more...}`;
|
||||
|
||||
const modeTests = [
|
||||
{
|
||||
mode: undefined,
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "tiny",
|
||||
expectedOutput: `Object`,
|
||||
},
|
||||
{
|
||||
mode: "short",
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
// @TODO Fix this test case.
|
||||
// See Bug 1281489 - Reps: Grips rep renders only 3 properties in long mode
|
||||
{
|
||||
mode: "long",
|
||||
expectedOutput: defaultOutput,
|
||||
}
|
||||
];
|
||||
|
||||
testRenderingInMode(modeTests, testName);
|
||||
}
|
||||
|
||||
function testUninterestingProps() {
|
||||
// Test object: `{a: undefined, b: undefined, c: "c", d: 1}`
|
||||
// @TODO This is not how we actually want the preview to be output.
|
||||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1276376
|
||||
const expectedOutput = `Object {a: undefined, b: undefined, c: "c", more...}`;
|
||||
}
|
||||
|
||||
function testNestedObject() {
|
||||
// Test object: `{objProp: {id: 1}, strProp: "test string"}`
|
||||
const testName = "testNestedObject";
|
||||
|
||||
const defaultOutput = `Object {objProp: Object, strProp: "test string"}`;
|
||||
|
||||
const modeTests = [
|
||||
{
|
||||
mode: undefined,
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "tiny",
|
||||
expectedOutput: `Object`,
|
||||
},
|
||||
{
|
||||
mode: "short",
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "long",
|
||||
expectedOutput: defaultOutput,
|
||||
}
|
||||
];
|
||||
|
||||
testRenderingInMode(modeTests, testName);
|
||||
}
|
||||
|
||||
function testNestedArray() {
|
||||
// Test object: `{arrProp: ["foo", "bar", "baz"]}`
|
||||
const testName = "testNestedArray";
|
||||
|
||||
const defaultOutput = `Object {arrProp: [3]}`;
|
||||
|
||||
const modeTests = [
|
||||
{
|
||||
mode: undefined,
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "tiny",
|
||||
expectedOutput: `Object`,
|
||||
},
|
||||
{
|
||||
mode: "short",
|
||||
expectedOutput: defaultOutput,
|
||||
},
|
||||
{
|
||||
mode: "long",
|
||||
expectedOutput: defaultOutput,
|
||||
}
|
||||
];
|
||||
|
||||
testRenderingInMode(modeTests, testName);
|
||||
}
|
||||
|
||||
function testRenderingInMode(modeTests, testName) {
|
||||
modeTests.forEach(({mode, expectedOutput, message}) => {
|
||||
const modeString = typeof mode === "undefined" ? "no mode" : mode;
|
||||
if (!message) {
|
||||
message = `${testName}: ${modeString} renders correctly.`
|
||||
}
|
||||
const gripStub = getGripStub(testName);
|
||||
|
||||
const rendered = renderComponent(Grip.rep, { object: gripStub, mode });
|
||||
is(rendered.textContent, expectedOutput, message);
|
||||
});
|
||||
}
|
||||
|
||||
function getGripStub(functionName) {
|
||||
switch (functionName) {
|
||||
case "testBasic":
|
||||
return {
|
||||
"type": "object",
|
||||
"class": "Object",
|
||||
"actor": "server1.conn0.obj304",
|
||||
"extensible": true,
|
||||
"frozen": false,
|
||||
"sealed": false,
|
||||
"ownPropertyLength": 0,
|
||||
"preview": {
|
||||
"kind": "Object",
|
||||
"ownProperties": {},
|
||||
"ownPropertiesLength": 0,
|
||||
"safeGetterValues": {}
|
||||
}
|
||||
};
|
||||
|
||||
case "testMaxProps":
|
||||
return {
|
||||
"type": "object",
|
||||
"class": "Object",
|
||||
"actor": "server1.conn0.obj337",
|
||||
"extensible": true,
|
||||
"frozen": false,
|
||||
"sealed": false,
|
||||
"ownPropertyLength": 3,
|
||||
"preview": {
|
||||
"kind": "Object",
|
||||
"ownProperties": {
|
||||
"a": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "a"
|
||||
},
|
||||
"b": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "b"
|
||||
},
|
||||
"c": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "c"
|
||||
}
|
||||
},
|
||||
"ownPropertiesLength": 3,
|
||||
"safeGetterValues": {}
|
||||
}
|
||||
};
|
||||
|
||||
case "testMoreThanMaxProps":
|
||||
return {
|
||||
"type": "object",
|
||||
"class": "Object",
|
||||
"actor": "server1.conn0.obj332",
|
||||
"extensible": true,
|
||||
"frozen": false,
|
||||
"sealed": false,
|
||||
"ownPropertyLength": 5,
|
||||
"preview": {
|
||||
"kind": "Object",
|
||||
"ownProperties": {
|
||||
"a": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "a"
|
||||
},
|
||||
"b": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "b"
|
||||
},
|
||||
"c": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "c"
|
||||
},
|
||||
"d": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "d"
|
||||
},
|
||||
"e": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "e"
|
||||
}
|
||||
},
|
||||
"ownPropertiesLength": 5,
|
||||
"safeGetterValues": {}
|
||||
}
|
||||
};
|
||||
|
||||
case "testUninterestingProps":
|
||||
return {
|
||||
"type": "object",
|
||||
"class": "Object",
|
||||
"actor": "server1.conn0.obj342",
|
||||
"extensible": true,
|
||||
"frozen": false,
|
||||
"sealed": false,
|
||||
"ownPropertyLength": 4,
|
||||
"preview": {
|
||||
"kind": "Object",
|
||||
"ownProperties": {
|
||||
"a": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": {
|
||||
"type": "undefined"
|
||||
}
|
||||
},
|
||||
"b": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": {
|
||||
"type": "undefined"
|
||||
}
|
||||
},
|
||||
"c": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "c"
|
||||
},
|
||||
"d": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": 1
|
||||
}
|
||||
},
|
||||
"ownPropertiesLength": 4,
|
||||
"safeGetterValues": {}
|
||||
}
|
||||
};
|
||||
|
||||
case "testNestedObject":
|
||||
return {
|
||||
"type": "object",
|
||||
"class": "Object",
|
||||
"actor": "server1.conn0.obj145",
|
||||
"extensible": true,
|
||||
"frozen": false,
|
||||
"sealed": false,
|
||||
"ownPropertyLength": 2,
|
||||
"preview": {
|
||||
"kind": "Object",
|
||||
"ownProperties": {
|
||||
"objProp": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": {
|
||||
"type": "object",
|
||||
"class": "Object",
|
||||
"actor": "server1.conn0.obj146",
|
||||
"extensible": true,
|
||||
"frozen": false,
|
||||
"sealed": false,
|
||||
"ownPropertyLength": 1
|
||||
}
|
||||
},
|
||||
"strProp": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": "test string"
|
||||
}
|
||||
},
|
||||
"ownPropertiesLength": 2,
|
||||
"safeGetterValues": {}
|
||||
}
|
||||
};
|
||||
|
||||
case "testNestedArray":
|
||||
return {
|
||||
"type": "object",
|
||||
"class": "Object",
|
||||
"actor": "server1.conn0.obj326",
|
||||
"extensible": true,
|
||||
"frozen": false,
|
||||
"sealed": false,
|
||||
"ownPropertyLength": 1,
|
||||
"preview": {
|
||||
"kind": "Object",
|
||||
"ownProperties": {
|
||||
"arrProp": {
|
||||
"configurable": true,
|
||||
"enumerable": true,
|
||||
"writable": true,
|
||||
"value": {
|
||||
"type": "object",
|
||||
"class": "Array",
|
||||
"actor": "server1.conn0.obj327",
|
||||
"extensible": true,
|
||||
"frozen": false,
|
||||
"sealed": false,
|
||||
"ownPropertyLength": 4,
|
||||
"preview": {
|
||||
"kind": "ArrayLike",
|
||||
"length": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ownPropertiesLength": 1,
|
||||
"safeGetterValues": {}
|
||||
},
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user