Bug 1403196 - rename and enable browser_webconsole_object_inspector_key_sorting.js;r=bgrins draft
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 12 Feb 2018 13:47:34 +0100
changeset 754049 75f3fba6f97207626eb39ba03cbf69c407c82147
parent 754048 d8b74f789f8c97f3a3145ab527a6179b3ae07501
push id98738
push userjdescottes@mozilla.com
push dateMon, 12 Feb 2018 19:24:19 +0000
reviewersbgrins
bugs1403196
milestone60.0a1
Bug 1403196 - rename and enable browser_webconsole_object_inspector_key_sorting.js;r=bgrins MozReview-Commit-ID: DfjO8aQqnsD
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_object_inspector_key_sorting.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_variables_view_dont_sort_non_sortable_classes_properties.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -314,16 +314,17 @@ skip-if = true #	Bug 1403448
 [browser_webconsole_network_messages_status_code.js]
 [browser_webconsole_network_requests_from_chrome.js]
 [browser_webconsole_network_reset_filter.js]
 [browser_webconsole_nodes_highlight.js]
 [browser_webconsole_nodes_select.js]
 [browser_webconsole_object_in_sidebar.js]
 [browser_webconsole_object_inspector.js]
 [browser_webconsole_object_inspector_entries.js]
+[browser_webconsole_object_inspector_key_sorting.js]
 [browser_webconsole_object_inspector_while_debugging_and_inspecting.js]
 [browser_webconsole_observer_notifications.js]
 [browser_webconsole_optimized_out_vars.js]
 [browser_webconsole_output_copy.js]
 subsuite = clipboard
 [browser_webconsole_output_copy_newlines.js]
 subsuite = clipboard
 [browser_webconsole_output_order.js]
@@ -356,17 +357,15 @@ skip-if = true #	Bug 1405649
 [browser_webconsole_stacktrace_location_scratchpad_link.js]
 [browser_webconsole_strict_mode_errors.js]
 [browser_webconsole_string.js]
 [browser_webconsole_time_methods.js]
 skip-if = true #	Bug 1404877
 [browser_webconsole_timestamps.js]
 [browser_webconsole_trackingprotection_errors.js]
 tags = trackingprotection
-[browser_webconsole_variables_view_dont_sort_non_sortable_classes_properties.js]
-skip-if = true #	Bug 1403196
 [browser_webconsole_view_source.js]
 [browser_webconsole_violation.js]
 skip-if = true #	Bug 1405245
 # old console skip-if = e10s && (os == 'win') # Bug 1264955
 [browser_webconsole_visibility_messages.js]
 [browser_webconsole_warn_about_replaced_api.js]
 [browser_webconsole_websocket.js]
rename from devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_variables_view_dont_sort_non_sortable_classes_properties.js
rename to devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_object_inspector_key_sorting.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_variables_view_dont_sort_non_sortable_classes_properties.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_object_inspector_key_sorting.js
@@ -1,135 +1,100 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-/* Test case that ensures Array and other list types are not sorted in variables
- * view.
+/* Test case that ensures Array and other list types are not alphabetically sorted in the
+ * Object Inspector.
  *
  * The tested types are:
  *  - Array
+ *  - NodeList
+ *  - Object
  *  - Int8Array
  *  - Int16Array
  *  - Int32Array
  *  - Uint8Array
  *  - Uint16Array
  *  - Uint32Array
  *  - Uint8ClampedArray
  *  - Float32Array
  *  - Float64Array
- *  - NodeList
  */
 
-function test() {
-  const TEST_URI = "data:text/html;charset=utf-8,   \
-    <html>                                          \
-      <head>                                        \
-        <title>Test document for bug 977500</title> \
-      </head>                                       \
-      <body>                                        \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      <div></div>                                   \
-      </body>                                       \
-    </html>";
-
-  let jsterm;
+const TEST_URI = `data:text/html;charset=utf-8,
+  <html>
+    <head>
+      <title>Test document for bug 977500</title>
+    </head>
+    <body>
+    <div></div> <div></div> <div></div>
+    <div></div> <div></div> <div></div>
+    <div></div> <div></div> <div></div>
+    <div></div> <div></div> <div></div>
+    </body>
+  </html>`;
 
-  function* runner() {
-    const typedArrayTypes = ["Int8Array", "Int16Array", "Int32Array",
-                             "Uint8Array", "Uint16Array", "Uint32Array",
-                             "Uint8ClampedArray", "Float32Array",
-                             "Float64Array"];
-
-    const {tab} = yield loadTab(TEST_URI);
-    const hud = yield openConsole(tab);
-    jsterm = hud.jsterm;
+const typedArrayTypes = [
+  "Int8Array",
+  "Int16Array",
+  "Int32Array",
+  "Uint8Array",
+  "Uint16Array",
+  "Uint32Array",
+  "Uint8ClampedArray",
+  "Float32Array",
+  "Float64Array"
+];
 
-    // Create an ArrayBuffer of 80 bytes to test TypedArrays. 80 bytes is
-    // enough to get 10 items in all different TypedArrays.
-    yield jsterm.execute("let buf = new ArrayBuffer(80);");
+add_task(async function () {
+  const hud = await openNewTabAndConsole(TEST_URI);
 
-    // Array
-    yield testNotSorted("Array(0,1,2,3,4,5,6,7,8,9,10)");
-    // NodeList
-    yield testNotSorted("document.querySelectorAll('div')");
-    // Object
-    yield testSorted("Object({'hello':1,1:5,10:2,4:2,'abc':1})");
-
-    // Typed arrays.
-    for (let type of typedArrayTypes) {
-      yield testNotSorted("new " + type + "(buf)");
-    }
-  }
+  // Array
+  await testKeyOrder(hud, "Array(0,1,2,3,4,5,6,7,8,9,10)",
+                    ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]);
+  // NodeList
+  await testKeyOrder(hud, "document.querySelectorAll('div')",
+                    ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]);
+  // Object
+  await testKeyOrder(hud, "Object({'hello':1, 1:5, 10:2, 4:2, 'abc':1})",
+                    ["1", "4", "10", "abc", "hello"]);
 
-  /**
-   * A helper that ensures the properties are not sorted when an object
-   * specified by aObject is inspected.
-   *
-   * @param string aObject
-   *        A string that, once executed, creates and returns the object to
-   *        inspect.
-   */
-  function* testNotSorted(aObject) {
-    info("Testing " + aObject);
-    let deferred = defer();
-    jsterm.once("variablesview-fetched", (_, aVar) => deferred.resolve(aVar));
-    jsterm.execute("inspect(" + aObject + ")");
-
-    let variableScope = yield deferred.promise;
-    ok(variableScope, "Variables view opened");
-
-    // If the properties are sorted: keys = ["0", "1", "10",...] <- incorrect
-    // If the properties are not sorted: keys = ["0", "1", "2",...] <- correct
-    let keyIterator = variableScope._store.keys();
-    is(keyIterator.next().value, "0", "First key is 0");
-    is(keyIterator.next().value, "1", "Second key is 1");
-
-    // If the properties are sorted, the next one will be 10.
-    is(keyIterator.next().value, "2", "Third key is 2, not 10");
+  // Typed arrays.
+  for (let type of typedArrayTypes) {
+    // size of 80 is enough to get 11 items on all ArrayTypes except for Float64Array.
+    let size = type === "Float64Array" ? 120 : 80;
+    await testKeyOrder(hud, `new ${type}(new ArrayBuffer(${size}))`,
+                      ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]);
   }
-  /**
-   * A helper that ensures the properties are sorted when an object
-   * specified by aObject is inspected.
-   *
-   * @param string aObject
-   *        A string that, once executed, creates and returns the object to
-   *        inspect.
-   */
-  function* testSorted(aObject) {
-    info("Testing " + aObject);
-    let deferred = defer();
-    jsterm.once("variablesview-fetched", (_, aVar) => deferred.resolve(aVar));
-    jsterm.execute("inspect(" + aObject + ")");
+});
 
-    let variableScope = yield deferred.promise;
-    ok(variableScope, "Variables view opened");
+async function testKeyOrder(hud, command, expectedKeys) {
+  info(`Testing command: [${command}]`);
 
-    // If the properties are sorted:
-    // keys = ["1", "4", "10",..., "abc", "hello"] <- correct
-    // If the properties are not sorted:
-    // keys = ["1", "10", "4",...] <- incorrect
-    let keyIterator = variableScope._store.keys();
-    is(keyIterator.next().value, "1", "First key should be 1");
-    is(keyIterator.next().value, "4", "Second key should be 4");
+  info("Wait for a new .result message with an object inspector to be displayed");
+  let resultsCount = findMessages(hud, "", ".result").length;
+  hud.jsterm.execute(command);
+  let oi = await waitFor(() => {
+    let results = findMessages(hud, "", ".result");
+    if (results.length == resultsCount + 1) {
+      return results.pop().querySelector(".tree");
+    }
+    return false;
+  });
 
-    // If the properties are sorted, the next one will be 10.
-    is(keyIterator.next().value, "10", "Third key is 10");
-    // If sorted next properties should be "abc" then "hello"
-    is(keyIterator.next().value, "abc", "Fourth key is abc");
-    is(keyIterator.next().value, "hello", "Fifth key is hello");
+  info("Expand object inspector");
+  let onOiExpanded = waitFor(() => {
+    return oi.querySelectorAll(".node").length >= expectedKeys.length;
+  });
+  oi.querySelector(".arrow").click();
+  await onOiExpanded;
+
+  let labelNodes = oi.querySelectorAll(".object-label");
+  for (let i = 0; i < expectedKeys.length; i++) {
+    let key = expectedKeys[i];
+    let labelNode = labelNodes[i];
+    is(labelNode.textContent, key, `Object inspector key is sorted as expected (${key})`);
   }
-
-  Task.spawn(runner).then(finishTest);
 }