Bug 1636172 [wpt PR 23463] - Improve error handling in iframe-related Generic Sensor tests., a=testonly
authorRaphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Wed, 13 May 2020 09:47:12 +0000
changeset 531142 e7e913365a0064b11b18c25fb0e97c8eb93bbdea
parent 531141 a44e5764ffe9c6c679afe024e68e88922b844f37
child 531143 8745c436c63c9bcc767b3bc90e6137824c2522cf
push id37435
push userapavel@mozilla.com
push dateWed, 20 May 2020 15:28:23 +0000
treeherdermozilla-central@5415da14ec9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1636172, 23463, 1073865, 2187318, 766578
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1636172 [wpt PR 23463] - Improve error handling in iframe-related Generic Sensor tests., a=testonly Automatic update from web-platform-tests Improve error handling in iframe-related Generic Sensor tests. AbsoluteOrientationSensor-iframe-access.https.html has been flaky on the Mac bots, but there is very little information when the error occurs. All we get so far is: FAIL AbsoluteOrientationSensor: sensor is not suspended when focus traverses from to same-origin frame promise_test: Unhandled rejection with value: undefined which probably means one of the `await` statements are call something that returns a rejected promise, and my first guess is send_message_to_iframe(). Try to make the errors more obvious when they occur again: - Make send_message_to_iframe() reject the promise when the iframe returns an invalid command. _ Make send_message_to_iframe() include a message with more information when it receives an unexpected reply. - Stop shadowing |e| with an exception when something goes wrong in iframe_sensor_handler.html. Bug: 1073865 Change-Id: Ib88edfc924e4b8b922a54a97f8ef2ee49b5d0e55 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2187318 Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com> Commit-Queue: Reilly Grant <reillyg@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com> Cr-Commit-Position: refs/heads/master@{#766578} -- wpt-commits: 1d14e74b0ed4d5a991b072a1f50b2f6fc4cc1622 wpt-pr: 23463
testing/web-platform/tests/generic-sensor/generic-sensor-iframe-tests.sub.js
testing/web-platform/tests/generic-sensor/resources/iframe_sensor_handler.html
--- a/testing/web-platform/tests/generic-sensor/generic-sensor-iframe-tests.sub.js
+++ b/testing/web-platform/tests/generic-sensor/generic-sensor-iframe-tests.sub.js
@@ -1,26 +1,25 @@
 async function send_message_to_iframe(iframe, message, reply) {
   if (reply === undefined) {
     reply = 'success';
   }
 
   return new Promise((resolve, reject) => {
-    let messageHandler = e => {
+    window.addEventListener('message', (e) => {
       if (e.data.command !== message.command) {
+        reject(`Expected reply with command '${message.command}', got '${e.data.command}' instead`);
         return;
       }
-      window.removeEventListener('message', messageHandler);
       if (e.data.result === reply) {
         resolve();
       } else {
-        reject();
+        reject(`Got unexpected reply '${e.data.result}' to command '${message.command}', expected '${reply}'`);
       }
-    }
-    window.addEventListener('message', messageHandler);
+    }, { once: true });
     iframe.contentWindow.postMessage(message, '*');
   });
 }
 
 function run_generic_sensor_iframe_tests(sensorName) {
   const sensorType = self[sensorName];
   const featurePolicies = get_feature_policies_for_sensor(sensorName);
 
--- a/testing/web-platform/tests/generic-sensor/resources/iframe_sensor_handler.html
+++ b/testing/web-platform/tests/generic-sensor/resources/iframe_sensor_handler.html
@@ -15,32 +15,32 @@
     if (e.data.command === 'create_sensor') {
       assert_equals(sensor, null);
       initialize_generic_sensor_tests().then((backend) => {
         mockBackend = backend;
         try {
           sensor = new self[e.data.type]();
           e.source.postMessage({command: e.data.command,
                                 result: 'success'}, '*');
-        } catch (e) {
-          e.source.postMessage({command: e.data.command, result: ''}, '*');
+        } catch (error) {
+          e.source.postMessage({command: e.data.command, result: error}, '*');
         }
       });
     } else if (e.data.command === 'start_sensor') {
       assert_not_equals(sensor, null);
       try {
         sensor.start();
         sensor.onreading = () => lastTimestamp = sensor.timestamp;
         let onReadingListener = () => {
           e.source.postMessage({command: e.data.command,
                                 result: 'success'}, '*');
         }
         sensor.addEventListener('reading', onReadingListener, {once: true});
-      } catch (e) {
-        e.source.postMessage({command: e.data.command, result: ''}, '*');
+      } catch (error) {
+        e.source.postMessage({command: e.data.command, result: error}, '*');
       }
     } else if (e.data.command === 'is_sensor_suspended') {
       let cachedTimestamp = lastTimestamp;
       let timeoutId = setTimeout(() => {
         e.source.postMessage({command: e.data.command,
                               result: cachedTimestamp === lastTimestamp}, '*');
       }, maxUpdatePeriod);