Can now choose multiple configurations within a set eg Toolbars[foo,bar]. r?jaws draft
authorRand Mustafa <rndmustafa@gmail.com>
Thu, 21 Sep 2017 21:49:42 -0400
changeset 669214 5dbc375879fdcf1b85be0a70f3d29896130832fa
parent 669213 76f7126ca3e1baffb530d5419a17e8d6d7507de5
child 670179 7f7c4e2ff9eb60c46edee4ef4a5ecf855beaad7f
push id81256
push userbmo:rndmustafa@gmail.com
push dateFri, 22 Sep 2017 18:13:11 +0000
reviewersjaws
milestone57.0a1
Can now choose multiple configurations within a set eg Toolbars[foo,bar]. r?jaws MozReview-Commit-ID: GbNctrucFHw
browser/tools/mozscreenshots/browser_screenshots.js
--- a/browser/tools/mozscreenshots/browser_screenshots.js
+++ b/browser/tools/mozscreenshots/browser_screenshots.js
@@ -1,16 +1,56 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+/**
+ * Finds the index of the first comma that is not enclosed within square brackets.
+ * @param {String} env - the string that needs to be searched
+ * @return {Integer} index of valid comma or -1 if not found.
+ */
+function findComma(env){
+  let ignore = false;
+  for(let i = 0; i < env.length; i++){
+    if(env[i] === '[') 
+      ignore = true;
+    else if(env[i] === ']') 
+      ignore = false;
+    else if(env[i] === ',' && ignore === false){
+      return i;
+    }
+  }
+  
+  return -1;
+}
+
+/**
+ * Splits the environment variable around commas not enclosed in brackets.
+ * @param {String} env - The environment variable
+ * @return {String[]} Array of strings containing the configurations 
+ * e.g. ["Toolbars[onlyNavBar,allToolbars]","DevTools[jsdebugger,webconsole]","Tabs"] 
+ */
+function splitEnv(env){
+  let result = [];
+  
+  let commaIndex = findComma(env);
+  while( commaIndex != -1 ){
+    result.push( env.slice(0, commaIndex).trim() );
+    env = env.slice(commaIndex+1);
+    commaIndex = findComma(env);
+  }
+  result.push( env.trim() );
+  
+  return result;
+}
+
 add_task(async function capture() {
   let setsEnv = env.get("MOZSCREENSHOTS_SETS");
   if (!setsEnv) {
     ok(true, "MOZSCREENSHOTS_SETS wasn't specified so there's nothing to capture");
     return;
   }
 
-  let sets = setsEnv.trim().split(",");
+  let sets = splitEnv(setsEnv);
   await TestRunner.start(sets);
 });