Bug 1603962 - Add comment explaining why addJsonViewTab races two load promises. r=Honza
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Mon, 16 Dec 2019 09:03:36 +0000
changeset 507054 c53f0a1c8a8ec23c017433b7bc247676a62b3809
parent 507053 51f016ea456e5d3d284944e93db88022328069fb
child 507055 572a5cc1d0b5779c434dda5cba78a8ad59304eff
push id36922
push userncsoregi@mozilla.com
push dateMon, 16 Dec 2019 17:21:47 +0000
treeherdermozilla-central@27d0d6cc2131 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1603962
milestone73.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 1603962 - Add comment explaining why addJsonViewTab races two load promises. r=Honza Differential Revision: https://phabricator.services.mozilla.com/D57204
devtools/client/jsonview/test/head.js
--- a/devtools/client/jsonview/test/head.js
+++ b/devtools/client/jsonview/test/head.js
@@ -48,16 +48,23 @@ registerCleanupFunction(() => {
  */
 async function addJsonViewTab(
   url,
   { appReadyState = "complete", docReadyState = "complete" } = {}
 ) {
   info("Adding a new JSON tab with URL: '" + url + "'");
   const tabAdded = BrowserTestUtils.waitForNewTab(gBrowser, url);
   const tabLoaded = addTab(url);
+
+  // The `tabAdded` promise resolves when the JSON Viewer starts loading.
+  // This is usually what we want, however, it never resolves for unrecognized
+  // content types that trigger a download, nor for symlink file URIs.
+  // On the other hand, `tabLoaded` always resolves, but not until the document
+  // is fully loaded, which is too late if `docReadyState !== "complete"`.
+  // Therefore, we race both promises.
   const tab = await Promise.race([tabAdded, tabLoaded]);
   const browser = tab.linkedBrowser;
 
   // Load devtools/shared/test/frame-script-utils.js
   loadFrameScriptUtils();
   const rootDir = getRootDirectory(gTestPath);
 
   // Catch RequireJS errors (usually timeouts)