Bug 1335778 - Synchronize navigate() for trigger methods using generators. draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 07 Apr 2017 21:44:32 +0200
changeset 568547 1016c179421984746d72d4abce5395365ed1a302
parent 568546 0c1bb81b7a6bf276af0771929b24a36ad8c77d69
child 568548 bf1ee74d77455e3bb8d6c002fddc44ff18990a74
push id55897
push userbmo:hskupin@gmail.com
push dateWed, 26 Apr 2017 09:17:50 +0000
bugs1335778
milestone55.0a1
Bug 1335778 - Synchronize navigate() for trigger methods using generators. In the case when the trigger callback inside navigate() uses a generator, the code has to be synchronized and needs to wait until the contained command has been completed. MozReview-Commit-ID: 8qKUMvH7HpS
testing/marionette/listener.js
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -268,29 +268,33 @@ var loadListener = {
       }
     }
 
     if (loadEventExpected) {
       let startTime = new Date().getTime();
       this.start(command_id, timeout, startTime, true);
     }
 
-    try {
-      trigger();
-    } catch (e) {
+    return Task.spawn(function* () {
+      yield trigger();
+
+    }).then(val => {
+      if (!loadEventExpected) {
+        sendOk(command_id);
+      }
+
+    }).catch(err => {
       if (loadEventExpected) {
         this.stop();
       }
-      sendError(new UnknownCommandError(e.message), command_id);
+
+      // Check why we do not raise an error if err is of type Event
+      sendError(err, command_id);
       return;
-    }
-
-    if (!loadEventExpected) {
-      sendOk(command_id);
-    }
+    });
   },
 }
 
 /**
  * Called when listener is first started up.
  * The listener sends its unique window ID and its current URI to the actor.
  * If the actor returns an ID, we start the listeners. Otherwise, nothing happens.
  */