try: -b o -p linux64-mulet,linux64_gecko,macosx64_gecko,win32_gecko -u all -t none
authorArmen Zambrano Gasparnian <armenzg@mozilla.com>
Mon, 27 Oct 2014 14:38:08 -0400
changeset 284949 07296ac81420
parent 284948 da125623d9cb
child 328342 4eb79bef003b
push id38738
push userarmenzg@mozilla.com
push dateMon, 27 Oct 2014 18:38:31 +0000
treeherdertry@07296ac81420 [default view] [failures only]
milestone36.0a1
try: -b o -p linux64-mulet,linux64_gecko,macosx64_gecko,win32_gecko -u all -t none
layout/tools/reftest/Makefile.in
layout/tools/reftest/b2g_desktop.py
layout/tools/reftest/gaia_lock_screen.js
layout/tools/reftest/runreftest.py
layout/tools/reftest/runreftestb2g.py
--- a/layout/tools/reftest/Makefile.in
+++ b/layout/tools/reftest/Makefile.in
@@ -7,16 +7,21 @@ ifdef XPI_NAME
 NO_JS_MANIFEST = 1
 DIST_FILES = install.rdf
 
 ifeq ($(MOZ_BUILD_APP),mobile/android)
 DEFINES += -DBOOTSTRAP
 DIST_FILES += bootstrap.js
 endif
 
+ifeq ($(MOZ_BUILD_APP),b2g/dev)
+DEFINES += -DBOOTSTRAP
+DEFINES += -DREFTEST_B2G
+endif
+
 ifeq ($(MOZ_BUILD_APP),b2g)
 DEFINES += -DBOOTSTRAP
 DEFINES += -DREFTEST_B2G
 endif
 
 # Used in install.rdf
 USE_EXTENSION_MANIFEST=1
 else
@@ -25,16 +30,17 @@ endif
 
 _DEST_DIR = $(DEPTH)/_tests/reftest
 
 _HARNESS_FILES = \
   $(srcdir)/runreftest.py \
   $(srcdir)/remotereftest.py \
   $(srcdir)/runreftestb2g.py \
   $(srcdir)/b2g_desktop.py \
+  $(srcdir)/gaia_lock_screen.js \
   automation.py \
   $(topsrcdir)/testing/mozbase/mozdevice/mozdevice/devicemanager.py \
   $(topsrcdir)/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py \
   $(topsrcdir)/testing/mozbase/mozdevice/mozdevice/devicemanagerSUT.py \
   $(topsrcdir)/testing/mozbase/mozdevice/mozdevice/droid.py \
   $(topsrcdir)/testing/mozbase/mozdevice/mozdevice/Zeroconf.py \
   $(topsrcdir)/testing/mozbase/moznetwork/moznetwork/moznetwork.py \
   $(topsrcdir)/build/mobile/b2gautomation.py \
--- a/layout/tools/reftest/b2g_desktop.py
+++ b/layout/tools/reftest/b2g_desktop.py
@@ -1,63 +1,80 @@
 # 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/.
 from __future__ import print_function, unicode_literals
 
-import json
 import os
 import signal
 import sys
-import threading
 
 here = os.path.abspath(os.path.dirname(__file__))
 
 from runreftest import RefTest, ReftestOptions
 
 from marionette import Marionette
 from mozprocess import ProcessHandler
 from mozrunner import FirefoxRunner
 import mozinfo
 import mozlog
 
 log = mozlog.getLogger('REFTEST')
 
 class B2GDesktopReftest(RefTest):
+    build_type = "desktop"
     marionette = None
 
     def __init__(self, marionette_args):
         RefTest.__init__(self)
         self.last_test = os.path.basename(__file__)
         self.marionette_args = marionette_args
         self.profile = None
         self.runner = None
         self.test_script = os.path.join(here, 'b2g_start_script.js')
         self.timeout = None
 
+    def _unlockScreen(self):
+        self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
+        self.marionette.import_script(os.path.abspath(
+            os.path.join(__file__, os.path.pardir, "gaia_lock_screen.js")))
+        self.marionette.switch_to_frame()
+        self.marionette.execute_async_script('GaiaLockScreen.unlock()')
+
     def run_marionette_script(self):
         self.marionette = Marionette(**self.marionette_args)
         assert(self.marionette.wait_for_port())
         self.marionette.start_session()
+        if self.build_type == "mulet":
+            # XXX: bug 1043699 - unlocking takes too long on EC2
+            import time
+            time.sleep(15)
+            self._unlockScreen()
         self.marionette.set_context(self.marionette.CONTEXT_CHROME)
 
         if os.path.isfile(self.test_script):
             f = open(self.test_script, 'r')
             self.test_script = f.read()
             f.close()
         self.marionette.execute_script(self.test_script)
 
     def run_tests(self, test_path, options):
         reftestlist = self.getManifestPath(test_path)
         if not reftestlist.startswith('file://'):
             reftestlist = 'file://%s' % reftestlist
 
         self.profile = self.create_profile(options, reftestlist,
                                            profile_to_clone=options.profile)
         env = self.buildBrowserEnv(options, self.profile.profile)
+
+        if self.build_type == "mulet":
+            # FIXME
+            if "MOZ_DISABLE_NONLOCAL_CONNECTIONS" in env:
+                del env["MOZ_DISABLE_NONLOCAL_CONNECTIONS"]
+
         kp_kwargs = { 'processOutputLine': [self._on_output],
                       'onTimeout': [self._on_timeout],
                       'kill_on_timeout': False }
 
         if not options.debugger:
             if not options.timeout:
                 if mozinfo.info['debug']:
                     options.timeout = 420
@@ -103,18 +120,22 @@ class B2GDesktopReftest(RefTest):
 
     def create_profile(self, options, reftestlist, profile_to_clone=None):
         profile = RefTest.createReftestProfile(self, options, reftestlist,
                                                profile_to_clone=profile_to_clone)
 
         prefs = {}
         # Turn off the locale picker screen
         prefs["browser.firstrun.show.localepicker"] = False
-        prefs["b2g.system_startup_url"] = "app://test-container.gaiamobile.org/index.html"
-        prefs["b2g.system_manifest_url"] = "app://test-container.gaiamobile.org/manifest.webapp"
+        if not self.build_type == "mulet":
+            # FIXME: With Mulet we can't set this values since Gaia won't launch
+            prefs["b2g.system_startup_url"] = \
+                    "app://test-container.gaiamobile.org/index.html"
+            prefs["b2g.system_manifest_url"] = \
+                    "app://test-container.gaiamobile.org/manifest.webapp"
         prefs["dom.ipc.tabs.disabled"] = False
         prefs["dom.mozBrowserFramesEnabled"] = True
         prefs["font.size.inflation.emPerLine"] = 0
         prefs["font.size.inflation.minTwips"] = 0
         prefs["network.dns.localDomains"] = "app://test-container.gaiamobile.org"
         prefs["reftest.browser.iframe.enabled"] = False
         prefs["reftest.remote"] = False
         prefs["reftest.uri"] = "%s" % reftestlist
@@ -131,40 +152,48 @@ class B2GDesktopReftest(RefTest):
         cmd = os.path.abspath(app)
         args = ['-marionette']
 
         if browser_arg:
             args += [browser_arg]
 
         if not ignore_window_size:
             args.extend(['--screen', '800x1000'])
+
+        if self.build_type == "mulet":
+            args += ['-chrome', 'chrome://b2g/content/shell.html']
         return cmd, args
 
     def _on_output(self, line):
         print(line)
         # TODO use structured logging
         if "TEST-START" in line and "|" in line:
             self.last_test = line.split("|")[1].strip()
 
     def _on_timeout(self):
         msg = "%s | application timed out after %s seconds with no output"
         log.testFail(msg % (self.last_test, self.timeout))
 
         # kill process to get a stack
         self.runner.stop(sig=signal.SIGABRT)
 
+class MuletReftest(B2GDesktopReftest):
+    build_type = "mulet"
 
 def run_desktop_reftests(parser, options, args):
     marionette_args = {}
     if options.marionette:
         host, port = options.marionette.split(':')
         marionette_args['host'] = host
         marionette_args['port'] = int(port)
 
-    reftest = B2GDesktopReftest(marionette_args)
+    if options.mulet:
+        reftest = MuletReftest(marionette_args)
+    else:
+        reftest = B2GDesktopReftest(marionette_args)
 
     options = ReftestOptions.verifyCommonOptions(parser, options, reftest)
     if options == None:
         sys.exit(1)
 
     # add a -bin suffix if b2g-bin exists, but just b2g was specified
     if options.app[-4:] != '-bin':
         if os.path.isfile("%s-bin" % options.app):
new file mode 100644
--- /dev/null
+++ b/layout/tools/reftest/gaia_lock_screen.js
@@ -0,0 +1,90 @@
+/* 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/. */
+
+// NOTE: This code was forked from:
+// https://github.com/mozilla-b2g/gaia/blob/master/tests/atoms/gaia_lock_screen.js
+
+'use strict';
+
+var GaiaLockScreen = {
+
+  unlock: function() {
+    let lockscreen = window.wrappedJSObject.lockScreen;
+    let setlock = window.wrappedJSObject.SettingsListener.getSettingsLock();
+    let system = window.wrappedJSObject.System;
+    let obj = {'screen.timeout': 0};
+    setlock.set(obj);
+
+    window.wrappedJSObject.ScreenManager.turnScreenOn();
+
+    waitFor(
+      function() {
+        window.wrappedJSObject.dispatchEvent(
+          new window.wrappedJSObject.CustomEvent(
+            'lockscreen-request-unlock', {
+              detail: {
+                forcibly: true
+              }
+            }));
+        waitFor(
+          function() {
+            finish(system.locked);
+          },
+          function() {
+            return !system.locked;
+          }
+        );
+      },
+      function() {
+        return !!lockscreen;
+      }
+    );
+  },
+
+  lock: function() {
+    let lwm = window.wrappedJSObject.lockScreenWindowManager;
+    let lockscreen = window.wrappedJSObject.lockScreen;
+    let system = window.wrappedJSObject.System;
+    let setlock = window.wrappedJSObject.SettingsListener.getSettingsLock();
+    let obj = {'screen.timeout': 0};
+    let waitLock = function() {
+      waitFor(
+        function() {
+        window.wrappedJSObject.dispatchEvent(
+          new window.wrappedJSObject.CustomEvent(
+            'lockscreen-request-lock', {
+              detail: {
+                forcibly: true
+              }
+            }));
+          waitFor(
+            function() {
+              finish(!system.locked);
+            },
+            function() {
+              return system.locked;
+            }
+          );
+        },
+        function() {
+          return !!lockscreen;
+        }
+      );
+    };
+
+    setlock.set(obj);
+    window.wrappedJSObject.ScreenManager.turnScreenOn();
+
+    // Need to open the window before we lock the lockscreen.
+    // This would only happen when someone directly call the lockscrene.lock.
+    // It's a bad pattern and would only for test.
+    lwm.openApp();
+    waitFor(function() {
+      waitLock();
+    }, function() {
+      return lwm.states.instance.isActive();
+    });
+  }
+};
+
--- a/layout/tools/reftest/runreftest.py
+++ b/layout/tools/reftest/runreftest.py
@@ -3,25 +3,23 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 """
 Runs the reftest test harness.
 """
 
 from optparse import OptionParser
 import collections
-import json
 import multiprocessing
 import os
 import re
 import shutil
 import signal
 import subprocess
 import sys
-import tempfile
 import threading
 
 SCRIPT_DIRECTORY = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0])))
 sys.path.insert(0, SCRIPT_DIRECTORY)
 
 from automationutils import (
     addCommonOptions,
     dumpScreen,
@@ -30,17 +28,16 @@ from automationutils import (
     processLeakLog
 )
 import mozcrash
 import mozdebug
 import mozinfo
 import mozprocess
 import mozprofile
 import mozrunner
-from mozrunner.utils import findInPath as which
 
 here = os.path.abspath(os.path.dirname(__file__))
 
 try:
     from mozbuild.base import MozbuildObject
     build_obj = MozbuildObject.from_environment(cwd=here)
 except ImportError:
     build_obj = None
--- a/layout/tools/reftest/runreftestb2g.py
+++ b/layout/tools/reftest/runreftestb2g.py
@@ -119,16 +119,20 @@ class B2GOptions(ReftestOptions):
                     type="string", dest="profile",
                     help="for desktop testing, the path to the "
                          "gaia profile to use")
         defaults["profile"] = None
         self.add_option("--desktop", action="store_true",
                         dest="desktop",
                         help="Run the tests on a B2G desktop build")
         defaults["desktop"] = False
+        self.add_option("--mulet", action="store_true",
+                        dest="mulet",
+                        help="Run the tests on a B2G desktop build")
+        defaults["mulet"] = False
         self.add_option("--enable-oop", action="store_true",
                         dest="oop",
                         help="Run the tests out of process")
         defaults["oop"] = False
         defaults["remoteTestRoot"] = None
         defaults["logFile"] = "reftest.log"
         defaults["autorun"] = True
         defaults["closeWhenDone"] = True
@@ -615,16 +619,16 @@ def run_remote_reftests(parser, options,
 
     reftest.stopWebServer(options)
     return retVal
 
 def main(args=sys.argv[1:]):
     parser = B2GOptions()
     options, args = parser.parse_args(args)
 
-    if options.desktop:
+    if options.desktop or options.mulet:
         return run_desktop_reftests(parser, options, args)
     return run_remote_reftests(parser, options, args)
 
 
 if __name__ == "__main__":
     sys.exit(main())