Bug 885806 - Add automatic regex creation to GCLI appcache command tests r=pbrosset
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Fri, 02 May 2014 16:59:38 +0100
changeset 206023 365fc5eb11697b1f6cbbfcd2f2f867b43c2d0556
parent 206022 ede61596f87281d1a912769c851af428abbe698f
child 206024 219b3ed1b9968ea9d6eea0bfc21dc73107821b1a
child 206176 eddaac20ab8579256ff1cb4e845b6611bfaed47e
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbrosset
bugs885806
milestone32.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 885806 - Add automatic regex creation to GCLI appcache command tests r=pbrosset
browser/devtools/commandline/test/browser_cmd_appcache_invalid.js
browser/devtools/commandline/test/head.js
--- a/browser/devtools/commandline/test/browser_cmd_appcache_invalid.js
+++ b/browser/devtools/commandline/test/browser_cmd_appcache_invalid.js
@@ -7,30 +7,95 @@
 const TEST_URI = "http://sub1.test1.example.com/browser/browser/devtools/commandline/" +
                  "test/browser_cmd_appcache_invalid_index.html";
 
 function test() {
   return Task.spawn(spawnTest).then(finish, helpers.handleError);
 }
 
 function spawnTest() {
+  let lines = [
+    'Manifest has a character encoding of ISO-8859-1. Manifests must have the ' +
+      'utf-8 character encoding.',
+    'The first line of the manifest must be "CACHE MANIFEST" at line 1.',
+    '"CACHE MANIFEST" is only valid on the first line but was found at line 3.',
+    'images/sound-icon.png points to a resource that is not available at line 9.',
+    'images/background.png points to a resource that is not available at line 10.',
+    '/checking.cgi points to a resource that is not available at line 13.',
+    'Asterisk (*) incorrectly used in the NETWORK section at line 14. If a line ' +
+      'in the NETWORK section contains only a single asterisk character, then any ' +
+      'URI not listed in the manifest will be treated as if the URI was listed in ' +
+      'the NETWORK section. Otherwise such URIs will be treated as unavailable. ' +
+    'Other uses of the * character are prohibited',
+    '../rel.html points to a resource that is not available at line 17.',
+    '../../rel.html points to a resource that is not available at line 18.',
+    '../../../rel.html points to a resource that is not available at line 19.',
+    '../../../../rel.html points to a resource that is not available at line 20.',
+    '../../../../../rel.html points to a resource that is not available at line 21.',
+    '/../ is not a valid URI prefix at line 22.',
+    '/test.css points to a resource that is not available at line 23.',
+    '/test.js points to a resource that is not available at line 24.',
+    'test.png points to a resource that is not available at line 25.',
+    '/main/features.js points to a resource that is not available at line 27.',
+    '/main/settings/index.css points to a resource that is not available at line 28.',
+    'http://example.com/scene.jpg points to a resource that is not available at line 29.',
+    '/section1/blockedbyfallback.html points to a resource that is not available at line 30.',
+    'http://example.com/images/world.jpg points to a resource that is not available at line 31.',
+    '/section2/blockedbyfallback.html points to a resource that is not available at line 32.',
+    '/main/home points to a resource that is not available at line 34.',
+    'main/app.js points to a resource that is not available at line 35.',
+    '/settings/home points to a resource that is not available at line 37.',
+    '/settings/app.js points to a resource that is not available at line 38.',
+    'The file http://sub1.test1.example.com/browser/browser/devtools/' +
+      'commandline/test/browser_cmd_appcache_invalid_page3.html was modified ' +
+      'after http://sub1.test1.example.com/browser/browser/devtools/' +
+      'commandline/test/browser_cmd_appcache_invalid_appcache.appcache. Unless ' +
+      'the text in the manifest file is changed the cached version will be used ' +
+      'instead at line 39.',
+    'browser_cmd_appcache_invalid_page3.html has cache-control set to no-store. ' +
+      'This will prevent the application cache from storing the file at line 39.',
+    'http://example.com/logo.png points to a resource that is not available at line 40.',
+    'http://example.com/check.png points to a resource that is not available at line 41.',
+    'Spaces in URIs need to be replaced with % at line 42.',
+    'http://example.com/cr oss.png points to a resource that is not available at line 42.',
+    'Asterisk (*) incorrectly used in the CACHE section at line 43. If a line ' +
+      'in the NETWORK section contains only a single asterisk character, then ' +
+      'any URI not listed in the manifest will be treated as if the URI was ' +
+      'listed in the NETWORK section. Otherwise such URIs will be treated as ' +
+      'unavailable. Other uses of the * character are prohibited',
+    'The SETTINGS section may only contain a single value, "prefer-online" or "fast" at line 47.',
+    'FALLBACK section line 50 (/section1/ /offline1.html) prevents caching of ' +
+      'line 30 (/section1/blockedbyfallback.html) in the CACHE section.',
+    '/offline1.html points to a resource that is not available at line 50.',
+    'FALLBACK section line 51 (/section2/ offline2.html) prevents caching of ' +
+      'line 32 (/section2/blockedbyfallback.html) in the CACHE section.',
+    'offline2.html points to a resource that is not available at line 51.',
+    'Only two URIs separated by spaces are allowed in the FALLBACK section at line 52.',
+    'Asterisk (*) incorrectly used in the FALLBACK section at line 53. URIs ' +
+      'in the FALLBACK section simply need to match a prefix of the request URI.',
+    'offline3.html points to a resource that is not available at line 53.',
+    'Invalid section name (BLAH) at line 55.',
+    'Only two URIs separated by spaces are allowed in the FALLBACK section at line 55.'
+  ];
+
   let options = yield helpers.openTab(TEST_URI);
   info("window open");
 
   // Wait for site to be cached.
   yield helpers.listenOnce(gBrowser.contentWindow.applicationCache, 'error');
   info("applicationCache error happened");
 
   yield helpers.openToolbar(options);
   info("toolbar open");
 
   // Pages containing an appcache the notification bar gives options to allow
   // or deny permission for the app to save data offline. Let's click Allow.
   let notificationID = "offline-app-requested-sub1.test1.example.com";
-  let notification = PopupNotifications.getNotification(notificationID, gBrowser.selectedBrowser);
+  let notification =
+    PopupNotifications.getNotification(notificationID, gBrowser.selectedBrowser);
 
   if (notification) {
     info("Authorizing offline storage.");
     notification.mainAction.callback();
   } else {
     info("No notification box is available.");
   }
 
@@ -40,60 +105,16 @@ function spawnTest() {
       setup: 'appcache validate',
       check: {
         input:  'appcache validate',
         markup: 'VVVVVVVVVVVVVVVVV',
         status: 'VALID',
         args: {}
       },
       exec: {
-        output: [
-          /Manifest has a character encoding of ISO-8859-1\. Manifests must have the utf-8 character encoding\./,
-          /The first line of the manifest must be "CACHE MANIFEST" at line 1\./,
-          /"CACHE MANIFEST" is only valid on the first line but was found at line 3\./,
-          /images\/sound-icon\.png points to a resource that is not available at line 9\./,
-          /images\/background\.png points to a resource that is not available at line 10\./,
-          /\/checking\.cgi points to a resource that is not available at line 13\./,
-          /Asterisk \(\*\) incorrectly used in the NETWORK section at line 14\. If a line in the NETWORK section contains only a single asterisk character, then any URI not listed in the manifest will be treated as if the URI was listed in the NETWORK section\. Otherwise such URIs will be treated as unavailable\. Other uses of the \* character are prohibited/,
-          /\.\.\/rel\.html points to a resource that is not available at line 17\./,
-          /\.\.\/\.\.\/rel\.html points to a resource that is not available at line 18\./,
-          /\.\.\/\.\.\/\.\.\/rel\.html points to a resource that is not available at line 19\./,
-          /\.\.\/\.\.\/\.\.\/\.\.\/rel\.html points to a resource that is not available at line 20\./,
-          /\.\.\/\.\.\/\.\.\/\.\.\/\.\.\/rel\.html points to a resource that is not available at line 21\./,
-          /\/\.\.\/ is not a valid URI prefix at line 22\./,
-          /\/test\.css points to a resource that is not available at line 23\./,
-          /\/test\.js points to a resource that is not available at line 24\./,
-          /test\.png points to a resource that is not available at line 25\./,
-          /\/main\/features\.js points to a resource that is not available at line 27\./,
-          /\/main\/settings\/index\.css points to a resource that is not available at line 28\./,
-          /http:\/\/example\.com\/scene\.jpg points to a resource that is not available at line 29\./,
-          /\/section1\/blockedbyfallback\.html points to a resource that is not available at line 30\./,
-          /http:\/\/example\.com\/images\/world\.jpg points to a resource that is not available at line 31\./,
-          /\/section2\/blockedbyfallback\.html points to a resource that is not available at line 32\./,
-          /\/main\/home points to a resource that is not available at line 34\./,
-          /main\/app\.js points to a resource that is not available at line 35\./,
-          /\/settings\/home points to a resource that is not available at line 37\./,
-          /\/settings\/app\.js points to a resource that is not available at line 38\./,
-          /The file http:\/\/sub1\.test1\.example\.com\/browser\/browser\/devtools\/commandline\/test\/browser_cmd_appcache_invalid_page3\.html was modified after http:\/\/sub1\.test1\.example\.com\/browser\/browser\/devtools\/commandline\/test\/browser_cmd_appcache_invalid_appcache\.appcache\. Unless the text in the manifest file is changed the cached version will be used instead at line 39\./,
-          /browser_cmd_appcache_invalid_page3\.html has cache-control set to no-store\. This will prevent the application cache from storing the file at line 39\./,
-          /http:\/\/example\.com\/logo\.png points to a resource that is not available at line 40\./,
-          /http:\/\/example\.com\/check\.png points to a resource that is not available at line 41\./,
-          /Spaces in URIs need to be replaced with % at line 42\./,
-          /http:\/\/example\.com\/cr oss\.png points to a resource that is not available at line 42\./,
-          /Asterisk \(\*\) incorrectly used in the CACHE section at line 43\. If a line in the NETWORK section contains only a single asterisk character, then any URI not listed in the manifest will be treated as if the URI was listed in the NETWORK section\. Otherwise such URIs will be treated as unavailable\. Other uses of the \* character are prohibited/,
-          /The SETTINGS section may only contain a single value, "prefer-online" or "fast" at line 47\./,
-          /FALLBACK section line 50 \(\/section1\/ \/offline1\.html\) prevents caching of line 30 \(\/section1\/blockedbyfallback\.html\) in the CACHE section\./,
-          /\/offline1\.html points to a resource that is not available at line 50\./,
-          /FALLBACK section line 51 \(\/section2\/ offline2\.html\) prevents caching of line 32 \(\/section2\/blockedbyfallback\.html\) in the CACHE section\./,
-          /offline2\.html points to a resource that is not available at line 51\./,
-          /Only two URIs separated by spaces are allowed in the FALLBACK section at line 52\./,
-          /Asterisk \(\*\) incorrectly used in the FALLBACK section at line 53\. URIs in the FALLBACK section simply need to match a prefix of the request URI\./,
-          /offline3\.html points to a resource that is not available at line 53\./,
-          /Invalid section name \(BLAH\) at line 55\./,
-          /Only two URIs separated by spaces are allowed in the FALLBACK section at line 55\./
-        ]
+        output: lines.map(getRegexForString)
       },
     },
   ]);
 
   yield helpers.closeToolbar(options);
   yield helpers.closeTab(options);
 }
--- a/browser/devtools/commandline/test/head.js
+++ b/browser/devtools/commandline/test/head.js
@@ -23,16 +23,30 @@ function whenDelayedStartupFinished(aWin
     if (aWindow == aSubject) {
       Services.obs.removeObserver(observer, aTopic);
       executeSoon(aCallback);
     }
   }, "browser-delayed-startup-finished", false);
 }
 
 /**
+ * Creates a regular expression that matches a string. This greatly simplifies
+ * matching and debugging long strings.
+ *
+ * @param {String} text
+ *        Text to convert
+ * @return {RegExp}
+ *         Regular expression matching text
+ */
+function getRegexForString(str) {
+  str = str.replace(/(\.|\\|\/|\(|\)|\[|\]|\*|\+|\?|\$|\^|\|)/g, "\\$1");
+  return new RegExp(str);
+}
+
+/**
  * Force GC on shutdown, because it seems that GCLI can outrun the garbage
  * collector in some situations, which causes test failures in later tests
  * Bug 774619 is an example.
  */
 registerCleanupFunction(function tearDown() {
   window.QueryInterface(Ci.nsIInterfaceRequestor)
       .getInterface(Ci.nsIDOMWindowUtils)
       .garbageCollect();