Bug 1404849 - migrate mochitest for generators autocompletion to xpcshell;r=nchevobbe draft
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 10 Jan 2018 12:04:12 +0100
changeset 718511 32dd75785d886134a012bb2bddb38c976441e065
parent 718290 e4de69553e3faf8136eb9bb7f2f741e1b7e6f866
child 745489 40c42499f95347be1126fbca377499e71d572bad
push id94932
push userjdescottes@mozilla.com
push dateWed, 10 Jan 2018 11:04:41 +0000
reviewersnchevobbe
bugs1404849
milestone59.0a1
Bug 1404849 - migrate mochitest for generators autocompletion to xpcshell;r=nchevobbe MozReview-Commit-ID: 74EaFkIZva7
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_iterators_generators.js
devtools/client/webconsole/new-console-output/test/mochitest/test-bug-632347-iterators-generators.html
devtools/shared/webconsole/test/unit/test_js_property_provider.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -46,17 +46,16 @@ support-files =
   test-bug-595934-svg.xhtml
   test-bug-595934-workers.html
   test-bug-595934-workers.js
   test-bug-599725-response-headers.sjs
   test-bug-601177-log-levels.html
   test-bug-601177-log-levels.js
   test-bug-630733-response-redirect-headers.sjs
   test-bug-632275-getters.html
-  test-bug-632347-iterators-generators.html
   test-bug-644419-log-limits.html
   test-bug-646025-console-file-location.html
   test-bug-658368-time-methods.html
   test-bug-737873-mixedcontent.html
   test-bug-752559-ineffective-iframe-sandbox-warning-inner.html
   test-bug-752559-ineffective-iframe-sandbox-warning-nested1.html
   test-bug-752559-ineffective-iframe-sandbox-warning-nested2.html
   test-bug-752559-ineffective-iframe-sandbox-warning0.html
@@ -299,19 +298,16 @@ skip-if = true #	Bug 1404371
 skip-if = true #	Bug 1405343
 [browser_webconsole_input_focus.js]
 [browser_webconsole_insecure_passwords_about_blank_web_console_warning.js]
 skip-if = true #	Bug 1404884
 [browser_webconsole_insecure_passwords_web_console_warning.js]
 skip-if = true #	Bug 1404888
 # old console skip-if = true # Bug 1110500 - mouse event failure in test
 [browser_webconsole_inspect_cross_domain_object.js]
-[browser_webconsole_iterators_generators.js]
-skip-if = true #	Bug 1404849
-# old console skip-if = e10s # Bug 1042253 - webconsole tests disabled with e10s
 [browser_webconsole_js_input_expansion.js]
 [browser_webconsole_jsterm.js]
 skip-if = true #	Bug 1405352
 # old console skip-if = e10s # Bug 1042253 - webconsole e10s tests (Linux debug timeout)
 [browser_webconsole_jsterm_copy.js]
 subsuite = clipboard
 skip-if = true #	Bug 1404831
 # old console skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 debug devtools for timeouts
deleted file mode 100644
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_iterators_generators.js
+++ /dev/null
@@ -1,69 +0,0 @@
-/* -*- 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";
-
-// See Bug 632347.
-
-const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
-                 "test/test-bug-632347-iterators-generators.html";
-
-function test() {
-  requestLongerTimeout(6);
-
-  loadTab(TEST_URI).then(() => {
-    openConsole().then(consoleOpened);
-  });
-}
-
-function consoleOpened(HUD) {
-  let {JSPropertyProvider} = require("devtools/shared/webconsole/js-property-provider");
-
-  let tmp = Cu.import("resource://gre/modules/jsdebugger.jsm", {});
-  tmp.addDebuggerToGlobal(tmp);
-  let dbg = new tmp.Debugger();
-
-  let jsterm = HUD.jsterm;
-  let win = content.wrappedJSObject;
-  let dbgWindow = dbg.addDebuggee(content);
-  let container = win._container;
-
-  // Make sure autocomplete does not walk through generators.
-  let result = container.gen1.next();
-  let completion = JSPropertyProvider(dbgWindow, null, "_container.gen1.");
-  isnot(completion.matches.length, 0, "Got matches for gen1");
-
-  is(result + 1, container.gen1.next(), "gen1.next() did not execute");
-
-  result = container.gen2.next().value;
-
-  completion = JSPropertyProvider(dbgWindow, null, "_container.gen2.");
-  isnot(completion.matches.length, 0, "Got matches for gen2");
-
-  is((result / 2 + 1) * 2, container.gen2.next().value,
-     "gen2.next() did not execute");
-
-  completion = JSPropertyProvider(dbgWindow, null, "window._container.");
-  ok(completion, "matches available for window._container");
-  ok(completion.matches.length, "matches available for window (length)");
-
-  dbg.removeDebuggee(content);
-  jsterm.clearOutput();
-
-  jsterm.execute("window._container", (msg) => {
-    jsterm.once("variablesview-fetched", testVariablesView.bind(null, HUD));
-    let anchor = msg.querySelector(".message-body a");
-    EventUtils.synthesizeMouse(anchor, 2, 2, {}, HUD.iframeWindow);
-  });
-}
-
-function testVariablesView(aWebconsole, aEvent, aView) {
-  findVariableViewProperties(aView, [
-    { name: "gen1", isGenerator: true },
-    { name: "gen2", isGenerator: true },
-  ], { webconsole: aWebconsole }).then(function () {
-    executeSoon(finishTest);
-  });
-}
deleted file mode 100644
--- a/devtools/client/webconsole/new-console-output/test/mochitest/test-bug-632347-iterators-generators.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="utf-8">
-    <title>Web Console test for bug 632347 - generators</title>
-    <!-- Any copyright is dedicated to the Public Domain.
-         http://creativecommons.org/publicdomain/zero/1.0/ -->
-<script type="application/javascript">
-(function(){
-function genFunc() {
-  var a = 5;
-  while (a < 10) {
-    yield a++;
-  }
-}
-
-window._container = {};
-
-_container.gen1 = genFunc();
-_container.gen1.next();
-
-_container.gen2 = (function* () { for (let i = 3; i <= 15; ++i) yield i * 2; })();
-})();
-</script>
-  </head>
-  <body>
-    <p>Web Console test for bug 632347 - generators.</p>
-  </body>
-</html>
--- a/devtools/shared/webconsole/test/unit/test_js_property_provider.js
+++ b/devtools/shared/webconsole/test/unit/test_js_property_provider.js
@@ -23,33 +23,51 @@ function run_test() {
       {propE: "E"}
     ]
   ]`;
 
   const testObject = 'var testObject = {"propA": [{"propB": "B"}]}';
   const testHyphenated = 'var testHyphenated = {"prop-A": "res-A"}';
   const testLet = "let foobar = {a: ''}; const blargh = {a: 1};";
 
+  const testGenerators = `
+  // Test with generator using a named function.
+  function* genFunc() {
+    for (let i = 0; i < 10; i++) {
+      yield i;
+    }
+  }
+  let gen1 = genFunc();
+  gen1.next();
+
+  // Test with generator using an anonymous function.
+  let gen2 = (function* () {
+    for (let i = 0; i < 10; i++) {
+      yield i;
+    }
+  })();`;
+
   let sandbox = Components.utils.Sandbox("http://example.com");
   let dbg = new Debugger();
   let dbgObject = dbg.addDebuggee(sandbox);
   let dbgEnv = dbgObject.asEnvironment();
   Components.utils.evalInSandbox(testArray, sandbox);
   Components.utils.evalInSandbox(testObject, sandbox);
   Components.utils.evalInSandbox(testHyphenated, sandbox);
   Components.utils.evalInSandbox(testLet, sandbox);
+  Components.utils.evalInSandbox(testGenerators, sandbox);
 
   info("Running tests with dbgObject");
-  runChecks(dbgObject, null);
+  runChecks(dbgObject, null, sandbox);
 
   info("Running tests with dbgEnv");
-  runChecks(null, dbgEnv);
+  runChecks(null, dbgEnv, sandbox);
 }
 
-function runChecks(dbgObject, dbgEnv) {
+function runChecks(dbgObject, dbgEnv, sandbox) {
   info("Test that suggestions are given for 'this'");
   let results = JSPropertyProvider(dbgObject, dbgEnv, "t");
   test_has_result(results, "this");
 
   if (dbgObject != null) {
     info("Test that suggestions are given for 'this.'");
     results = JSPropertyProvider(dbgObject, dbgEnv, "this.");
     test_has_result(results, "testObject");
@@ -140,16 +158,31 @@ function runChecks(dbgObject, dbgEnv) {
   Assert.equal(null, results);
 
   results = JSPropertyProvider(dbgObject, dbgEnv, "testArray[][1].");
   Assert.equal(null, results);
 
   info("Test that suggestions are not given if there is an hyphen in the chain.");
   results = JSPropertyProvider(dbgObject, dbgEnv, "testHyphenated['prop-A'].");
   Assert.equal(null, results);
+
+  info("Test that we have suggestions for generators.");
+  let gen1Result = Components.utils.evalInSandbox("gen1.next().value", sandbox);
+  results = JSPropertyProvider(dbgObject, dbgEnv, "gen1.");
+  test_has_result(results, "next");
+  info("Test that the generator next() was not executed");
+  let gen1NextResult = Components.utils.evalInSandbox("gen1.next().value", sandbox);
+  Assert.equal(gen1Result + 1, gen1NextResult);
+
+  info("Test with an anonymous generator.");
+  let gen2Result = Components.utils.evalInSandbox("gen2.next().value", sandbox);
+  results = JSPropertyProvider(dbgObject, dbgEnv, "gen2.");
+  test_has_result(results, "next");
+  let gen2NextResult = Components.utils.evalInSandbox("gen2.next().value", sandbox);
+  Assert.equal(gen2Result + 1, gen2NextResult);
 }
 
 /**
  * A helper that ensures an empty array of results were found.
  * @param Object results
  *        The results returned by JSPropertyProvider.
  */
 function test_has_no_results(results) {