Bug 1516862 - Fix test_ext_webrequest_basic intermittency while testing onError events fired on hostname resolving error. r=mixedpuppy
authorLuca Greco <lgreco@mozilla.com>
Thu, 14 Mar 2019 18:06:33 +0000
changeset 524921 32112b7c202edccb5ec54ab18971e0a46af3ee58
parent 524920 495029aae21bbac7d75caafb3d67082715c6c63b
child 524922 8d51957df27ad95b830b8bb93c32ebc2727be918
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1516862
milestone67.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 1516862 - Fix test_ext_webrequest_basic intermittency while testing onError events fired on hostname resolving error. r=mixedpuppy When the dns resolution for an url's hostname fails, the webRequest API seems to be receiving (from time to time but more often on macos and windows) more then one call to the HttpObserverManager.observeActivity method for the activityType nsISocketTransport.STATUS_RESOLVING and nsISocketTransport.STATUS_RESOLVED while channel wrapper errorString property is still null. The observeActvity method goal seems to fire fallback WebRequest errors for error conditions that are not fired as ChannelWrapper error events, but the "NS_ERROR_UNKNOWN_HOST" error is also being fired right after the fallback webRequest error event fired as "NS_ERROR_NET_ON_RESOLVED" (or "NS_ERROR_NET_ON_RESOLVING"). This behavior consistently triggers the two intermittent failures on the test test_ext_webrequest_basic.html while executing the test_webRequest_frames task "expected error message received in onErrorOccurred - Expected: NS_ERROR_UNKNOWN_HOST, Actual: NS_ERROR_NET_ON_RESOLVED" (when the fallback NS_ERROR_NET_ON_RESOLVED is fired first) and then "received onErrorOccurred" (because the "NS_ERROR_UNKNOWN_HOST" error is also being fired right after the fallback error message). Differential Revision: https://phabricator.services.mozilla.com/D22587
toolkit/components/extensions/test/mochitest/head_webrequest.js
toolkit/components/extensions/test/mochitest/test_ext_webrequest_basic.html
--- a/toolkit/components/extensions/test/mochitest/head_webrequest.js
+++ b/toolkit/components/extensions/test/mochitest/head_webrequest.js
@@ -234,17 +234,23 @@ function background(events) {
         browser.test.assertEq(expectedIp, details.ip, `correct ip for ${details.url}`);
       }
       if (expected.headers && expected.headers.response) {
         checkHeaders("response", expected, details);
       }
     },
     onErrorOccurred(expected, details, result) {
       if (expected.error) {
-        browser.test.assertEq(expected.error, details.error, "expected error message received in onErrorOccurred");
+        if (Array.isArray(expected.error)) {
+          browser.test.assertTrue(
+            expected.error.includes(details.error),
+            "expected error message received in onErrorOccurred");
+        } else {
+          browser.test.assertEq(expected.error, details.error, "expected error message received in onErrorOccurred");
+        }
       }
     },
   };
 
   function getListener(name) {
     return details => {
       let result = {};
       browser.test.log(`${name} ${details.requestId} ${details.url}`);
--- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest_basic.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_basic.html
@@ -373,17 +373,21 @@ add_task(async function test_webRequest_
     "dummy_page.html": {
       type: "sub_frame",
       status: 404,
     },
     "badrobot": {
       type: "sub_frame",
       status: 404,
       events: ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", "onErrorOccurred"],
-      error: "NS_ERROR_UNKNOWN_HOST",
+      // When an url's hostname fails to be resolved, an NS_ERROR_NET_ON_RESOLVED/RESOLVING
+      // onError event may be fired right before the NS_ERROR_UNKNOWN_HOST
+      // (See Bug 1516862 for a rationale).
+      optional_events: ["onErrorOccurred"],
+      error: ["NS_ERROR_UNKNOWN_HOST", "NS_ERROR_NET_ON_RESOLVED", "NS_ERROR_NET_ON_RESOLVING"],
     },
   };
   extension.sendMessage("set-expected", {expect, origin: location.href});
   await extension.awaitMessage("continue");
   addFrame("data:text/plain,webRequestTest");
   addFrame("data:text/plain,webRequestTest_bad");
   await extension.awaitMessage("cancelled");
   addFrame("redirection.sjs");