Bug 1043699 - Add Mulet reftests support. r=jgriffin
authorArmen Zambrano Gasparnian <armenzg@mozilla.com>
Tue, 04 Nov 2014 09:18:27 -0500
changeset 213885 dfd2eb97d840
parent 213884 0650c4edb139
child 213886 81998c889766
push id51354
push userarmenzg@mozilla.com
push dateTue, 04 Nov 2014 14:18:38 +0000
treeherdermozilla-inbound@dfd2eb97d840 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs1043699
milestone36.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 1043699 - Add Mulet reftests support. r=jgriffin
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
testing/config/mozharness/linux_mulet_config.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,47 +1,51 @@
 # 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 marionette import Marionette, expected
+from marionette.wait import Wait
+from marionette.by import By
 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 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":
+            self._wait_for_homescreen(timeout=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)
 
@@ -103,18 +107,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 +139,60 @@ 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 _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 _wait_for_homescreen(self, timeout):
+        log.info("Waiting for home screen to load")
+        Wait(self.marionette, timeout).until(expected.element_present(
+            By.CSS_SELECTOR, '#homescreen[loading-state=false]'))
 
 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())
 
--- a/testing/config/mozharness/linux_mulet_config.py
+++ b/testing/config/mozharness/linux_mulet_config.py
@@ -1,11 +1,11 @@
 # This is used by mozharness' mulet_unittest.py
 config = {
     # testsuite options
     "reftest_options": [
-        "--desktop", "--profile=%(gaia_profile)s",
+        "--mulet", "--profile=%(gaia_profile)s",
         "--appname=%(application)s", "%(test_manifest)s"
     ],
     "run_file_names": {
         "reftest": "runreftestb2g.py",
     },
 }