Bug 1322083 - Fix Reps with safeGetterValues; r=ntim draft
authorNicolas Chevobbe <chevobbe.nicolas@gmail.com>
Sat, 17 Dec 2016 20:07:29 +0100
changeset 450670 44461f378681407665c6426c0b30be87ae95488a
parent 450435 5a536a16e33798fe7b16de35c968d5bc0cbf8448
child 539824 5ae26540ebf1230de63cca82d3cdcc6e0223138b
push id38942
push userchevobbe.nicolas@gmail.com
push dateSun, 18 Dec 2016 13:04:47 +0000
reviewersntim
bugs1322083
milestone53.0a1
Bug 1322083 - Fix Reps with safeGetterValues; r=ntim Sometimes (e.g. for window.applicationCache), Reps was shown with a negative number before the "more..." label. This was due to displaying the children of safeGeterValues property but not taking them into account for the total number of properties in the object when displaying the "more..." label. We fix this and add a test case to make sure we won't have this bug later MozReview-Commit-ID: 1qBCvehV0Jc
devtools/client/shared/components/reps/grip.js
devtools/client/shared/components/test/mochitest/test_reps_grip.html
--- a/devtools/client/shared/components/reps/grip.js
+++ b/devtools/client/shared/components/reps/grip.js
@@ -99,17 +99,17 @@ define(function (require, exports, modul
       let props = this.getProps(properties, indexes, truncate);
       if (truncate) {
         // There are some undisplayed props. Then display "more...".
         let objectLink = this.props.objectLink || span;
 
         props.push(Caption({
           object: objectLink({
             object: object
-          }, `${object.ownPropertyLength - max} more…`)
+          }, `${propertiesLength - max} more…`)
         }));
       }
 
       return props;
     },
 
     /**
      * Get props ordered by index.
--- a/devtools/client/shared/components/test/mochitest/test_reps_grip.html
+++ b/devtools/client/shared/components/test/mochitest/test_reps_grip.html
@@ -26,16 +26,17 @@ window.onload = Task.async(function* () 
   try {
     yield testBasic();
     yield testBooleanObject();
     yield testNumberObject();
     yield testStringObject();
     yield testProxy();
     yield testArrayBuffer();
     yield testSharedArrayBuffer();
+    yield testApplicationCache();
 
     // Test property iterator
     yield testMaxProps();
     yield testMoreThanMaxProps();
     yield testUninterestingProps();
     yield testNonEnumerableProps();
 
     // Test that properties are rendered as expected by PropRep
@@ -283,16 +284,53 @@ window.onload = Task.async(function* () 
         mode: MODE.LONG,
         expectedOutput: defaultOutput,
       }
     ];
 
     testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
   }
 
+  function testApplicationCache() {
+    // Test object: `window.applicationCache`
+    const testName = "testApplicationCache";
+
+    // Test that correct rep is chosen
+    const gripStub = getGripStub(testName);
+    const renderedRep = shallowRenderComponent(Rep, { object: gripStub });
+    is(renderedRep.type, Grip.rep, `Rep correctly selects ${Grip.rep.displayName}`);
+
+    // Test rendering
+    const defaultOutput =
+      "OfflineResourceList { status: 0, onchecking: null, onerror: null, 7 more… }";
+
+    const modeTests = [
+      {
+        mode: undefined,
+        expectedOutput: defaultOutput,
+      },
+      {
+        mode: MODE.TINY,
+        expectedOutput: "OfflineResourceList",
+      },
+      {
+        mode: MODE.SHORT,
+        expectedOutput: defaultOutput,
+      },
+      {
+        mode: MODE.LONG,
+        expectedOutput: "OfflineResourceList { status: 0, onchecking: null, " +
+          "onerror: null, onnoupdate: null, ondownloading: null, onprogress: null, " +
+          "onupdateready: null, oncached: null, onobsolete: null, mozItems: [] }",
+      }
+    ];
+
+    testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(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 = [
       {
@@ -873,15 +911,117 @@ window.onload = Task.async(function* () 
                 "getterValue": 5,
                 "getterPrototypeLevel": 1,
                 "enumerable": false,
                 "writable": true
               }
             }
           }
         };
+      case "testApplicationCache":
+        return {
+          "type": "object",
+          "actor": "server2.conn1.child2/obj45",
+          "class": "OfflineResourceList",
+          "ownPropertyLength": 0,
+          "preview": {
+            "kind": "Object",
+            "ownProperties": {},
+            "ownPropertiesLength": 0,
+            "safeGetterValues": {
+              "status": {
+                "getterValue": 0,
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              },
+              "onchecking": {
+                "getterValue": {
+                  "type": "null"
+                },
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              },
+              "onerror": {
+                "getterValue": {
+                  "type": "null"
+                },
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              },
+              "onnoupdate": {
+                "getterValue": {
+                  "type": "null"
+                },
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              },
+              "ondownloading": {
+                "getterValue": {
+                  "type": "null"
+                },
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              },
+              "onprogress": {
+                "getterValue": {
+                  "type": "null"
+                },
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              },
+              "onupdateready": {
+                "getterValue": {
+                  "type": "null"
+                },
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              },
+              "oncached": {
+                "getterValue": {
+                  "type": "null"
+                },
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              },
+              "onobsolete": {
+                "getterValue": {
+                  "type": "null"
+                },
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              },
+              "mozItems": {
+                "getterValue": {
+                  "type": "object",
+                  "actor": "server2.conn1.child2/obj46",
+                  "class": "DOMStringList",
+                  "extensible": true,
+                  "frozen": false,
+                  "sealed": false,
+                  "ownPropertyLength": 0,
+                  "preview": {
+                    "kind": "ArrayLike",
+                    "length": 0
+                  }
+                },
+                "getterPrototypeLevel": 1,
+                "enumerable": true,
+                "writable": true
+              }
+            }
+          }
+        };
     }
   }
 });
 </script>
 </pre>
 </body>
 </html>