Bug 942319 - Supply python script to convert some mochitests to standalone tests. r=bjacob
authorJeff Gilbert <jgilbert@mozilla.com>
Sun, 08 Dec 2013 21:56:40 -0500
changeset 175166 8dc4d9276c7a278aa6c537de680ed2ef40ce1d0e
parent 175165 9e1a644eb6f37daca96cdff84d1046bfe2d322ed
child 175167 97d17b777f684ce75022586c71a98bc8b178802e
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs942319
milestone28.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 942319 - Supply python script to convert some mochitests to standalone tests. r=bjacob
content/canvas/test/webgl/non-conf-tests/driver-info.js
content/canvas/test/webgl/non-conf-tests/mochi-to-testcase.py
--- a/content/canvas/test/webgl/non-conf-tests/driver-info.js
+++ b/content/canvas/test/webgl/non-conf-tests/driver-info.js
@@ -13,19 +13,25 @@ DriverInfo = (function() {
 
   function info(str) {
     gInfoFunc(str);
   }
 
   // ---------------------------------------------------------------------------
   // OS and driver identification
   //   Stolen from content/canvas/test/webgl/test_webgl_conformance_test_suite.html
-  const Cc = SpecialPowers.Cc;
-  const Ci = SpecialPowers.Ci;
   function detectDriverInfo() {
+    try {
+      var cc = SpecialPowers.Cc;
+    } catch (e) {
+      throw 'No SpecialPowers!';
+    }
+
+    const Cc = SpecialPowers.Cc;
+    const Ci = SpecialPowers.Ci;
     var doc = Cc["@mozilla.org/xmlextras/domparser;1"].createInstance(Ci.nsIDOMParser).parseFromString("<html/>", "text/html");
 
     var canvas = doc.createElement("canvas");
     canvas.width = 1;
     canvas.height = 1;
 
     var type = "";
     var gl = null;
@@ -41,16 +47,61 @@ DriverInfo = (function() {
     var ext = gl.getExtension("WEBGL_debug_renderer_info");
     // this extension is unconditionally available to chrome. No need to check.
 
     var webglRenderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
     var webglVendor = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
     return [webglVendor, webglRenderer];
   }
 
+  function detectOSInfo() {
+    try {
+      var cc = SpecialPowers.Cc;
+    } catch (e) {
+      throw 'No SpecialPowers!';
+    }
+
+    const Cc = SpecialPowers.Cc;
+    const Ci = SpecialPowers.Ci;
+
+    // From reftest.js:
+    var runtime = Cc['@mozilla.org/xre/app-info;1'].getService(Ci.nsIXULRuntime);
+
+    var os = null;
+    var version = null;
+    if (navigator.platform.indexOf('Win') == 0) {
+      os = OS.WINDOWS;
+
+      // code borrowed from browser/modules/test/browser_taskbar_preview.js
+      version = SpecialPowers.Services.sysinfo.getProperty('version');
+      version = parseFloat(version);
+      // Version 6.0 is Vista, 6.1 is 7.
+
+    } else if (navigator.platform.indexOf('Mac') == 0) {
+      os = OS.MAC;
+
+      var versionMatch = /Mac OS X (\d+.\d+)/.exec(navigator.userAgent);
+      version = versionMatch ? parseFloat(versionMatch[1]) : null;
+
+    } else if (runtime.widgetToolkit == 'gonk') {
+      os = OS.B2G;
+
+    } else if (navigator.appVersion.indexOf('Android') != -1) {
+      os = OS.ANDROID;
+      // From layout/tools/reftest/reftest.js:
+      version = SpecialPowers.Services.sysinfo.getProperty('version');
+
+    } else if (navigator.platform.indexOf('Linux') == 0) {
+      // Must be checked after android, as android also has a 'Linux' platform string.
+      os = OS.LINUX;
+    }
+
+    return [os, version];
+  }
+
   var OS = {
     WINDOWS: 'windows',
     MAC: 'mac',
     LINUX: 'linux',
     ANDROID: 'android',
     B2G: 'b2g',
   };
 
@@ -60,44 +111,20 @@ DriverInfo = (function() {
     ANDROID_X86_EMULATOR: 'android x86 emulator',
     ANGLE: 'angle',
   };
 
   var kOS = null;
   var kOSVersion = null;
   var kDriver = null;
 
-  // From reftest.js:
-  var runtime = Cc['@mozilla.org/xre/app-info;1'].getService(Ci.nsIXULRuntime);
-
-  if (navigator.platform.indexOf('Win') == 0) {
-    kOS = OS.WINDOWS;
-
-    // code borrowed from browser/modules/test/browser_taskbar_preview.js
-    var version = SpecialPowers.Services.sysinfo.getProperty('version');
-    kOSVersion = parseFloat(version);
-    // Version 6.0 is Vista, 6.1 is 7.
-
-  } else if (navigator.platform.indexOf('Mac') == 0) {
-    kOS = OS.MAC;
-
-    var versionMatch = /Mac OS X (\d+.\d+)/.exec(navigator.userAgent);
-    kOSVersion = versionMatch ? parseFloat(versionMatch[1]) : null;
-
-  } else if (runtime.widgetToolkit == 'gonk') {
-    kOS = OS.B2G;
-
-  } else if (navigator.appVersion.indexOf('Android') != -1) {
-    kOS = OS.ANDROID;
-    // From layout/tools/reftest/reftest.js:
-    kOSVersion = SpecialPowers.Services.sysinfo.getProperty('version');
-
-  } else if (navigator.platform.indexOf('Linux') == 0) {
-    // Must be checked after android, as android also has a 'Linux' platform string.
-    kOS = OS.LINUX;
+  try {
+    [kOS, kOSVersion] = detectOSInfo();
+  } catch (e) {
+    // Generally just fails when we don't have SpecialPowers.
   }
 
   try {
     var glVendor, glRenderer;
     [glVendor, glRenderer] = detectDriverInfo();
     info('GL vendor: ' + glVendor);
     info('GL renderer: ' + glRenderer);
 
new file mode 100644
--- /dev/null
+++ b/content/canvas/test/webgl/non-conf-tests/mochi-to-testcase.py
@@ -0,0 +1,86 @@
+import sys
+import os.path
+import re
+
+assert len(sys.argv) == 2
+mochiPath = sys.argv[1]
+
+extDotPos = mochiPath.find('.html')
+assert extDotPos != -1, 'mochitest target must be an html doc.'
+
+testPath = mochiPath[:extDotPos] + '.solo.html'
+    
+def ReadLocalFile(include):
+    incPath = os.path.dirname(mochiPath)
+    filePath = os.path.join(incPath, include)
+
+    data = None
+    try:
+        f = open(filePath, 'r')
+        data = f.read()
+    except:
+        pass
+
+    try:
+        f.close()
+    except:
+        pass
+
+    return data
+
+kSimpleTestReplacement = '''\n
+<script>
+// SimpleTest.js replacement
+function ok(val, text) {
+  var elem = document.getElementById('mochi-to-testcase-output');
+  var status = val ? 'Test <font color=\\'green\\'>passed</font>: '
+                   : 'Test <font color=\\'red\\'  >FAILED</font>: ';
+  elem.innerHTML += '\\n<br/>\\n' + status + text;
+}
+
+function todo(val, text) {
+  ok(!val, 'Todo: ' + text);
+}
+</script>
+<div id='mochi-to-testcase-output'></div>
+\n'''
+
+fin = open(mochiPath, 'r')
+fout = open(testPath, 'w')
+includePattern = re.compile('<script\\s*src=[\'"](.*)\\.js[\'"]>\\s*</script>')
+cssPattern = re.compile('<link\\s*rel=[\'"]stylesheet[\'"]\\s*href=[\'"]([^=>]*)[\'"]>')
+for line in fin:
+    skipLine = False
+    for css in cssPattern.findall(line):
+        skipLine = True
+        print('Ignoring stylesheet: ' + css)
+    
+    for inc in includePattern.findall(line):
+        skipLine = True
+        if inc == '/MochiKit/MochiKit':
+            continue
+
+        if inc == '/tests/SimpleTest/SimpleTest':
+            print('Injecting SimpleTest replacement')
+            fout.write(kSimpleTestReplacement);
+            continue
+            
+        incData = ReadLocalFile(inc + '.js')
+        if not incData:
+            print('Warning: Unknown JS file ignored: ' + inc + '.js')
+            continue
+
+        print('Injecting include: ' + inc + '.js')
+        fout.write('\n<script>\n// Imported from: ' + inc + '.js\n');
+        fout.write(incData);
+        fout.write('\n</script>\n');
+        continue
+
+    if skipLine:
+        continue
+    
+    fout.write(line)
+    continue
+
+fin.close()
+fout.close()