diff --git a/b2g/chrome/content/test/mochitest/RecordingStatusChromeScript.js b/b2g/chrome/content/test/mochitest/RecordingStatusChromeScript.js new file mode 100644 index 000000000000..48f8bd550b19 --- /dev/null +++ b/b2g/chrome/content/test/mochitest/RecordingStatusChromeScript.js @@ -0,0 +1,40 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; +const { Services } = Cu.import('resource://gre/modules/Services.jsm'); + +var processId; + +function peekChildId(aSubject, aTopic, aData) { + Services.obs.removeObserver(peekChildId, 'recording-device-events'); + Services.obs.removeObserver(peekChildId, 'recording-device-ipc-events'); + let props = aSubject.QueryInterface(Ci.nsIPropertyBag2); + if (props.hasKey('childID')) { + processId = props.get('childID'); + } +} + +addMessageListener('init-chrome-event', function(message) { + // listen mozChromeEvent and forward to content process. + let browser = Services.wm.getMostRecentWindow('navigator:browser'); + let type = message.type; + browser.addEventListener('mozChromeEvent', function(event) { + let details = event.detail; + if (details.type === type) { + sendAsyncMessage('chrome-event', details); + } + }, true); + + Services.obs.addObserver(peekChildId, 'recording-device-events', false); + Services.obs.addObserver(peekChildId, 'recording-device-ipc-events', false); +}); + +addMessageListener('fake-content-shutdown', function(message) { + let props = Cc["@mozilla.org/hash-property-bag;1"] + .createInstance(Ci.nsIWritablePropertyBag2); + if (processId) { + props.setPropertyAsUint64('childID', processId); + } + Services.obs.notifyObservers(props, 'recording-device-ipc-events', 'content-shutdown'); +}); diff --git a/b2g/chrome/content/test/mochitest/RecordingStatusHelper.js b/b2g/chrome/content/test/mochitest/RecordingStatusHelper.js new file mode 100644 index 000000000000..5e3e6814e1fd --- /dev/null +++ b/b2g/chrome/content/test/mochitest/RecordingStatusHelper.js @@ -0,0 +1,82 @@ +'use strict'; + +// resolve multiple promise in parallel +function expectAll(aValue) { + let deferred = new Promise(function(resolve, reject) { + let countdown = aValue.length; + let resolutionValues = new Array(countdown); + + for (let i = 0; i < aValue.length; i++) { + let index = i; + aValue[i].then(function(val) { + resolutionValues[index] = val; + if (--countdown === 0) { + resolve(resolutionValues); + } + }, reject); + } + }); + + return deferred; +} + +function TestInit() { + let url = SimpleTest.getTestFileURL("RecordingStatusChromeScript.js") + let script = SpecialPowers.loadChromeScript(url); + + let helper = { + finish: function () { + script.destroy(); + }, + fakeShutdown: function () { + script.sendAsyncMessage('fake-content-shutdown', {}); + } + }; + + script.addMessageListener('chrome-event', function (message) { + if (helper.hasOwnProperty('onEvent')) { + helper.onEvent(message); + } else { + ok(false, 'unexpected message: ' + JSON.stringify(message)); + } + }); + + script.sendAsyncMessage("init-chrome-event", { + type: 'recording-status' + }); + + return Promise.resolve(helper); +} + +function expectEvent(expected, eventHelper) { + return new Promise(function(resolve, reject) { + eventHelper.onEvent = function(message) { + delete eventHelper.onEvent; + ok(message, JSON.stringify(message)); + is(message.type, 'recording-status', 'event type: ' + message.type); + is(message.active, expected.active, 'recording active: ' + message.active); + is(message.isAudio, expected.isAudio, 'audio recording active: ' + message.isAudio); + is(message.isVideo, expected.isVideo, 'video recording active: ' + message.isVideo); + resolve(eventHelper); + }; + info('waiting for recording-status'); + }); +} + +function expectStream(params, callback) { + return new Promise(function(resolve, reject) { + var req = navigator.mozGetUserMedia( + params, + function(stream) { + ok(true, 'create media stream'); + callback(stream); + resolve(); + }, + function(err) { + ok(false, 'fail to create media stream'); + reject(err); + } + ); + info('waiting for gUM result'); + }); +} diff --git a/b2g/chrome/content/test/mochitest/file_getusermedia_iframe.html b/b2g/chrome/content/test/mochitest/file_getusermedia_iframe.html new file mode 100644 index 000000000000..f2b18eab3f42 --- /dev/null +++ b/b2g/chrome/content/test/mochitest/file_getusermedia_iframe.html @@ -0,0 +1,36 @@ + + +
++ ++ + diff --git a/b2g/chrome/content/test/mochitest/mochitest.ini b/b2g/chrome/content/test/mochitest/mochitest.ini new file mode 100644 index 000000000000..a9160bca7c53 --- /dev/null +++ b/b2g/chrome/content/test/mochitest/mochitest.ini @@ -0,0 +1,10 @@ +[DEFAULT] +support-files = + RecordingStatusChromeScript.js + RecordingStatusHelper.js + file_getusermedia_iframe.html + +[test_recordingStatus_basic.html] +[test_recordingStatus_multiple_requests.html] +[test_recordingStatus_iframe.html] +[test_recordingStatus_kill_content_process.html] diff --git a/b2g/chrome/content/test/mochitest/moz.build b/b2g/chrome/content/test/mochitest/moz.build new file mode 100644 index 000000000000..8421b15157a7 --- /dev/null +++ b/b2g/chrome/content/test/mochitest/moz.build @@ -0,0 +1,7 @@ +# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +MOCHITEST_MANIFESTS += ['mochitest.ini'] diff --git a/b2g/chrome/content/test/mochitest/test_recordingStatus_basic.html b/b2g/chrome/content/test/mochitest/test_recordingStatus_basic.html new file mode 100644 index 000000000000..9bc6b18038f2 --- /dev/null +++ b/b2g/chrome/content/test/mochitest/test_recordingStatus_basic.html @@ -0,0 +1,121 @@ + + + +
+ ++ + diff --git a/b2g/chrome/content/test/mochitest/test_recordingStatus_iframe.html b/b2g/chrome/content/test/mochitest/test_recordingStatus_iframe.html new file mode 100644 index 000000000000..c7987eeae64e --- /dev/null +++ b/b2g/chrome/content/test/mochitest/test_recordingStatus_iframe.html @@ -0,0 +1,73 @@ + + + +
+ + ++ + diff --git a/b2g/chrome/content/test/mochitest/test_recordingStatus_kill_content_process.html b/b2g/chrome/content/test/mochitest/test_recordingStatus_kill_content_process.html new file mode 100644 index 000000000000..bef89159b719 --- /dev/null +++ b/b2g/chrome/content/test/mochitest/test_recordingStatus_kill_content_process.html @@ -0,0 +1,74 @@ + + + +
+ ++ + diff --git a/b2g/chrome/content/test/mochitest/test_recordingStatus_multiple_requests.html b/b2g/chrome/content/test/mochitest/test_recordingStatus_multiple_requests.html new file mode 100644 index 000000000000..b4367fa649e9 --- /dev/null +++ b/b2g/chrome/content/test/mochitest/test_recordingStatus_multiple_requests.html @@ -0,0 +1,110 @@ + + + +
+ ++ + diff --git a/b2g/chrome/moz.build b/b2g/chrome/moz.build index bea69e096ae5..9d39af7ef428 100644 --- a/b2g/chrome/moz.build +++ b/b2g/chrome/moz.build @@ -8,4 +8,6 @@ DEFINES['AB_CD'] = CONFIG['MOZ_UI_LOCALE'] DEFINES['PACKAGE'] = 'browser' DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION'] -JAR_MANIFESTS += ['jar.mn'] \ No newline at end of file +JAR_MANIFESTS += ['jar.mn'] + +TEST_DIRS += ['content/test/mochitest'] diff --git a/testing/mochitest/b2g-desktop.json b/testing/mochitest/b2g-desktop.json index a77ed2766075..f13dfaa5ee26 100644 --- a/testing/mochitest/b2g-desktop.json +++ b/testing/mochitest/b2g-desktop.json @@ -9,6 +9,7 @@ "toolkit/devtools/apps": "" }, "excludetests": { + "b2g/chrome/content/test/mochitest": "require OOP support for mochitest-b2g-desktop, Bug 957554", "content/xul":"tests that use xul", "layout/xul" : "", "dom/tests/mochitest/general/test_focusrings.xul":"",