Bug 1311168 - Handle document fragment in grip array rep; r=Honza

MozReview-Commit-ID: Cq2YyKlMjjQ

--HG--
extra : rebase_source : 9a2eee2d7cec16eb3a27938fd5e0174ab0e5989e
This commit is contained in:
Nicolas Chevobbe 2016-10-23 19:31:41 +02:00
Родитель 287872b90b
Коммит 4ce68bc581
2 изменённых файлов: 240 добавлений и 74 удалений

Просмотреть файл

@ -30,7 +30,11 @@ define(function (require, exports, module) {
}, },
getLength: function (grip) { getLength: function (grip) {
return grip.preview ? grip.preview.length : 0; if (!grip.preview) {
return 0;
}
return grip.preview.length || grip.preview.childNodesLength || 0;
}, },
getTitle: function (object, context) { getTitle: function (object, context) {
@ -43,28 +47,37 @@ define(function (require, exports, module) {
return ""; return "";
}, },
getPreviewItems: function (grip) {
if (!grip.preview) {
return null;
}
return grip.preview.items || grip.preview.childNodes || null;
},
arrayIterator: function (grip, max) { arrayIterator: function (grip, max) {
let items = []; let items = [];
const gripLength = this.getLength(grip);
if (!grip.preview || !grip.preview.length) { if (!gripLength) {
return items; return items;
} }
let array = grip.preview.items; const previewItems = this.getPreviewItems(grip);
if (!array) { if (!previewItems) {
return items; return items;
} }
let delim; let delim;
// number of grip.preview.items is limited to 10, but we may have more // number of grip preview items is limited to 10, but we may have more
// items in grip-array // items in grip-array.
let delimMax = grip.preview.length > array.length ? let delimMax = gripLength > previewItems.length ?
array.length : array.length - 1; previewItems.length : previewItems.length - 1;
let provider = this.props.provider; let provider = this.props.provider;
for (let i = 0; i < array.length && i < max; i++) { for (let i = 0; i < previewItems.length && i < max; i++) {
try { try {
let itemGrip = array[i]; let itemGrip = previewItems[i];
let value = provider ? provider.getValue(itemGrip) : itemGrip; let value = provider ? provider.getValue(itemGrip) : itemGrip;
delim = (i == delimMax ? "" : ", "); delim = (i == delimMax ? "" : ", ");
@ -80,10 +93,10 @@ define(function (require, exports, module) {
}))); })));
} }
} }
if (array.length > max || grip.preview.length > array.length) { if (previewItems.length > max || gripLength > previewItems.length) {
let objectLink = this.props.objectLink || span; let objectLink = this.props.objectLink || span;
let leftItemNum = grip.preview.length - max > 0 ? let leftItemNum = gripLength - max > 0 ?
grip.preview.length - max : grip.preview.length - array.length; gripLength - max : gripLength - previewItems.length;
items.push(Caption({ items.push(Caption({
object: objectLink({ object: objectLink({
object: this.props.object object: this.props.object
@ -170,7 +183,11 @@ define(function (require, exports, module) {
return false; return false;
} }
return (grip.preview && grip.preview.kind == "ArrayLike"); return (grip.preview && (
grip.preview.kind == "ArrayLike" ||
type === "DocumentFragment"
)
);
} }
// Exports from this module // Exports from this module

Просмотреть файл

@ -37,6 +37,7 @@ window.onload = Task.async(function* () {
yield testPreviewLimit(); yield testPreviewLimit();
yield testNamedNodeMap(); yield testNamedNodeMap();
yield testNodeList(); yield testNodeList();
yield testDocumentFragment();
} catch(e) { } catch(e) {
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e)); ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
} finally { } finally {
@ -272,6 +273,38 @@ window.onload = Task.async(function* () {
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName)); testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
} }
function testDocumentFragment() {
const testName = "testDocumentFragment";
const defaultOutput = "DocumentFragment [ li#li-0.list-element, " +
"li#li-1.list-element, li#li-2.list-element, 2 more… ]";
const longOutput = "DocumentFragment [ " +
"li#li-0.list-element, li#li-1.list-element, li#li-2.list-element, " +
"li#li-3.list-element, li#li-4.list-element ]";
const modeTests = [
{
mode: undefined,
expectedOutput: defaultOutput,
},
{
mode: "tiny",
expectedOutput: `[5]`,
},
{
mode: "short",
expectedOutput: defaultOutput,
},
{
mode: "long",
expectedOutput: longOutput,
}
];
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function getGripStub(functionName) { function getGripStub(functionName) {
switch (functionName) { switch (functionName) {
case "testBasic": case "testBasic":
@ -412,67 +445,68 @@ window.onload = Task.async(function* () {
} }
}; };
case "testNamedNodeMap": case "testNamedNodeMap":
return { return {
"type": "object", "type": "object",
"class": "NamedNodeMap", "class": "NamedNodeMap",
"actor": "server1.conn3.obj42", "actor": "server1.conn3.obj42",
"extensible": true, "extensible": true,
"frozen": false, "frozen": false,
"sealed": false, "sealed": false,
"ownPropertyLength": 6, "ownPropertyLength": 6,
"preview": { "preview": {
"kind": "ArrayLike", "kind": "ArrayLike",
"length": 3, "length": 3,
"items": [ "items": [
{ {
"type": "object", "type": "object",
"class": "Attr", "class": "Attr",
"actor": "server1.conn3.obj43", "actor": "server1.conn3.obj43",
"extensible": true, "extensible": true,
"frozen": false, "frozen": false,
"sealed": false, "sealed": false,
"ownPropertyLength": 0, "ownPropertyLength": 0,
"preview": { "preview": {
"kind": "DOMNode", "kind": "DOMNode",
"nodeType": 2, "nodeType": 2,
"nodeName": "class", "nodeName": "class",
"value": "myclass" "value": "myclass"
}
},
{
"type": "object",
"class": "Attr",
"actor": "server1.conn3.obj44",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 2,
"nodeName": "cellpadding",
"value": "7"
}
},
{
"type": "object",
"class": "Attr",
"actor": "server1.conn3.obj44",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 2,
"nodeName": "border",
"value": "3"
}
} }
] },
} {
}; "type": "object",
"class": "Attr",
"actor": "server1.conn3.obj44",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 2,
"nodeName": "cellpadding",
"value": "7"
}
},
{
"type": "object",
"class": "Attr",
"actor": "server1.conn3.obj44",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 2,
"nodeName": "border",
"value": "3"
}
}
]
}
};
case "testNodeList": case "testNodeList":
return { return {
"type": "object", "type": "object",
@ -549,7 +583,122 @@ window.onload = Task.async(function* () {
] ]
} }
}; };
case "testDocumentFragment":
return {
"type": "object",
"actor": "server1.conn1.child1/obj45",
"class": "DocumentFragment",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 11,
"nodeName": "#document-fragment",
"childNodesLength": 5,
"childNodes": [
{
"type": "object",
"actor": "server1.conn1.child1/obj46",
"class": "HTMLLIElement",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 1,
"nodeName": "li",
"attributes": {
"id": "li-0",
"class": "list-element"
},
"attributesLength": 2
}
},
{
"type": "object",
"actor": "server1.conn1.child1/obj47",
"class": "HTMLLIElement",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 1,
"nodeName": "li",
"attributes": {
"id": "li-1",
"class": "list-element"
},
"attributesLength": 2
}
},
{
"type": "object",
"actor": "server1.conn1.child1/obj48",
"class": "HTMLLIElement",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 1,
"nodeName": "li",
"attributes": {
"id": "li-2",
"class": "list-element"
},
"attributesLength": 2
}
},
{
"type": "object",
"actor": "server1.conn1.child1/obj49",
"class": "HTMLLIElement",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 1,
"nodeName": "li",
"attributes": {
"id": "li-3",
"class": "list-element"
},
"attributesLength": 2
}
},
{
"type": "object",
"actor": "server1.conn1.child1/obj50",
"class": "HTMLLIElement",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 0,
"preview": {
"kind": "DOMNode",
"nodeType": 1,
"nodeName": "li",
"attributes": {
"id": "li-4",
"class": "list-element"
},
"attributesLength": 2
}
}
]
}
};
} }
return null;
} }
}); });
</script> </script>