Bug 1431306 - Return the MDN status list URL in getHTTPStatusCodeURL when statusCode does not have a dedicated page; r=nchevobbe draft
authorabhinav <abhinav.koppula@gmail.com>
Sat, 20 Jan 2018 23:31:44 +0530
changeset 747687 a23168b7f92c5de6b717b1ce2a3e8ff540943c0a
parent 724404 32b850fa28ae1c29039cb7ddcdfd71b324762c05
push id96982
push userbmo:abhinav.koppula@gmail.com
push dateFri, 26 Jan 2018 17:35:28 +0000
reviewersnchevobbe
bugs1431306
milestone60.0a1
Bug 1431306 - Return the MDN status list URL in getHTTPStatusCodeURL when statusCode does not have a dedicated page; r=nchevobbe MozReview-Commit-ID: 5FWYgChM5le
devtools/client/netmonitor/moz.build
devtools/client/netmonitor/src/utils/mdn-utils.js
devtools/client/netmonitor/test/unit/.eslintrc.js
devtools/client/netmonitor/test/unit/test_mdn-utils.js
devtools/client/netmonitor/test/unit/xpcshell.ini
--- a/devtools/client/netmonitor/moz.build
+++ b/devtools/client/netmonitor/moz.build
@@ -5,12 +5,14 @@
 DIRS += [
     'src'
 ]
 
 DevToolsModules(
     'panel.js'
 )
 
+XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
+
 BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
 
 with Files('**'):
     BUG_COMPONENT = ('Firefox', 'Developer Tools: Netmonitor')
--- a/devtools/client/netmonitor/src/utils/mdn-utils.js
+++ b/devtools/client/netmonitor/src/utils/mdn-utils.js
@@ -121,31 +121,33 @@ const SUPPORTED_HTTP_CODES = [
     "410",
     "411",
     "412",
     "413",
     "414",
     "415",
     "416",
     "417",
+    "418",
     "426",
     "428",
     "429",
     "431",
     "451",
     "500",
     "501",
     "502",
     "503",
     "504",
     "505",
     "511"
 ];
 
 const MDN_URL = "https://developer.mozilla.org/docs/";
+const MDN_STATUS_CODES_LIST_URL = `${MDN_URL}Web/HTTP/Status`;
 const getGAParams = (panelId = "netmonitor") => {
   return `?utm_source=mozilla&utm_medium=devtools-${panelId}&utm_campaign=default`;
 };
 
 /**
  * Get the MDN URL for the specified header.
  *
  * @param {string} header Name of the header for the baseURL to use.
@@ -163,20 +165,21 @@ function getHeadersURL(header) {
 /**
  * Get the MDN URL for the specified HTTP status code.
  *
  * @param {string} HTTP status code for the baseURL to use.
  *
  * @return {string} The MDN URL for the HTTP status code, or null if not available.
  */
 function getHTTPStatusCodeURL(statusCode, panelId) {
-  let idx = SUPPORTED_HTTP_CODES.indexOf(statusCode);
-  return idx > -1 ?
-    `${MDN_URL}Web/HTTP/Status/${SUPPORTED_HTTP_CODES[idx] + getGAParams(panelId)}`
-      : null;
+  return (
+    SUPPORTED_HTTP_CODES.includes(statusCode)
+      ? `${MDN_URL}Web/HTTP/Status/${statusCode}`
+      : MDN_STATUS_CODES_LIST_URL
+    ) + getGAParams(panelId);
 }
 
 /**
  * Get the MDN URL of the Timings tag for Network Monitor.
  *
  * @return {string} the MDN URL of the Timings tag for Network Monitor.
  */
 function getNetMonitorTimingsURL() {
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/unit/.eslintrc.js
@@ -0,0 +1,6 @@
+"use strict";
+
+module.exports = {
+  // Extend from the common devtools xpcshell eslintrc config.
+  "extends": "../../../../.eslintrc.xpcshell.js"
+};
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/unit/test_mdn-utils.js
@@ -0,0 +1,41 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test for mdn-utils
+
+"use strict";
+
+function run_test() {
+  let Cu = Components.utils;
+  const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+  const MDN_URL = "https://developer.mozilla.org/docs/";
+  const GTM_PARAMS_NM = "?utm_source=mozilla" +
+    "&utm_medium=devtools-netmonitor&utm_campaign=default";
+  const GTM_PARAMS_WC = "?utm_source=mozilla" +
+    "&utm_medium=devtools-webconsole&utm_campaign=default";
+
+  const {
+    getHeadersURL,
+    getHTTPStatusCodeURL,
+    getNetMonitorTimingsURL,
+    getPerformanceAnalysisURL
+  } = require("devtools/client/netmonitor/src/utils/mdn-utils");
+
+  info("Checking for supported headers");
+  equal(getHeadersURL("Accept"), `${MDN_URL}Web/HTTP/Headers/Accept${GTM_PARAMS_NM}`);
+  info("Checking for unsupported headers");
+  equal(getHeadersURL("Width"), null);
+
+  info("Checking for supported status code");
+  equal(getHTTPStatusCodeURL("200", "webconsole"),
+    `${MDN_URL}Web/HTTP/Status/200${GTM_PARAMS_WC}`);
+  info("Checking for unsupported status code");
+  equal(getHTTPStatusCodeURL("999", "webconsole"),
+    `${MDN_URL}Web/HTTP/Status${GTM_PARAMS_WC}`);
+
+  equal(getNetMonitorTimingsURL(),
+    `${MDN_URL}Tools/Network_Monitor${GTM_PARAMS_NM}#Timings`);
+
+  equal(getPerformanceAnalysisURL(),
+    `${MDN_URL}Tools/Network_Monitor${GTM_PARAMS_NM}#Performance_analysis`);
+}
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/unit/xpcshell.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+tags = devtools
+head =
+firefox-appdir = browser
+skip-if = toolkit == 'android'
+
+[test_mdn-utils.js]
\ No newline at end of file