dom/camera/test/camera_common.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 var CameraTest = (function() {
michael@0 2 'use strict';
michael@0 3
michael@0 4 /**
michael@0 5 * 'camera.control.test.enabled' is queried in Gecko to enable different
michael@0 6 * test modes in the camera stack. The only currently-supported setting
michael@0 7 * is 'hardware', which wraps the Gonk camera abstraction class in a
michael@0 8 * shim class that supports injecting hardware camera API failures into
michael@0 9 * the execution path.
michael@0 10 *
michael@0 11 * The affected API is specified by the 'camera.control.test.hardware'
michael@0 12 * pref. Currently supported values should be determined by inspecting
michael@0 13 * TestGonkCameraHardware.cpp.
michael@0 14 *
michael@0 15 * Some API calls are simple: e.g. 'start-recording-failure' will cause
michael@0 16 * the DOM-facing startRecording() call to fail. More complex tests like
michael@0 17 * 'take-picture-failure' will cause the takePicture() API to fail, while
michael@0 18 * 'take-picture-process-failure' will simulate a failure of the
michael@0 19 * asynchronous picture-taking process, even if the initial API call
michael@0 20 * path seems to have succeeded.
michael@0 21 *
michael@0 22 * If 'camera.control.test.hardware.gonk.parameters' is set, it will cause
michael@0 23 * the contents of that string to be appended to the string of parameters
michael@0 24 * pulled from the Gonk camera library. This allows tests to inject fake
michael@0 25 * settings/capabilities for features not supported by the emulator. These
michael@0 26 * parameters are one or more semicolon-delimited key=value pairs, e.g. to
michael@0 27 * pretend the emulator supports zoom:
michael@0 28 *
michael@0 29 * zoom-ratios=100,150,200,300,400;max-zoom=4
michael@0 30 *
michael@0 31 * This means (of course) that neither the key not the value tokens can
michael@0 32 * contain either equals signs or semicolons. The test shim doesn't enforce
michael@0 33 * this so that we can test getting junk from the camera library as well.
michael@0 34 */
michael@0 35 const PREF_TEST_ENABLED = "camera.control.test.enabled";
michael@0 36 const PREF_TEST_HARDWARE = "camera.control.test.hardware";
michael@0 37 const PREF_TEST_EXTRA_PARAMETERS = "camera.control.test.hardware.gonk.parameters";
michael@0 38 var oldTestEnabled;
michael@0 39 var oldTestHw;
michael@0 40 var testMode;
michael@0 41
michael@0 42 function testHardwareSetFakeParameters(parameters, callback) {
michael@0 43 SpecialPowers.pushPrefEnv({'set': [[PREF_TEST_EXTRA_PARAMETERS, parameters]]}, function() {
michael@0 44 var setParams = SpecialPowers.getCharPref(PREF_TEST_EXTRA_PARAMETERS);
michael@0 45 ise(setParams, parameters, "Extra test parameters '" + setParams + "'");
michael@0 46 if (callback) {
michael@0 47 callback(setParams);
michael@0 48 }
michael@0 49 });
michael@0 50 }
michael@0 51
michael@0 52 function testHardwareClearFakeParameters(callback) {
michael@0 53 SpecialPowers.pushPrefEnv({'clear': [[PREF_TEST_EXTRA_PARAMETERS]]}, callback);
michael@0 54 }
michael@0 55
michael@0 56 function testHardwareSet(test, callback) {
michael@0 57 SpecialPowers.pushPrefEnv({'set': [[PREF_TEST_HARDWARE, test]]}, function() {
michael@0 58 var setTest = SpecialPowers.getCharPref(PREF_TEST_HARDWARE);
michael@0 59 ise(setTest, test, "Test subtype set to " + setTest);
michael@0 60 if (callback) {
michael@0 61 callback(setTest);
michael@0 62 }
michael@0 63 });
michael@0 64 }
michael@0 65
michael@0 66 function testHardwareDone(callback) {
michael@0 67 testMode = null;
michael@0 68 if (oldTestHw) {
michael@0 69 SpecialPowers.pushPrefEnv({'set': [[PREF_TEST_HARDWARE, oldTestHw]]}, callback);
michael@0 70 } else {
michael@0 71 SpecialPowers.pushPrefEnv({'clear': [[PREF_TEST_HARDWARE]]}, callback);
michael@0 72 }
michael@0 73 }
michael@0 74
michael@0 75 function testBegin(mode, callback) {
michael@0 76 SimpleTest.waitForExplicitFinish();
michael@0 77 try {
michael@0 78 oldTestEnabled = SpecialPowers.getCharPref(PREF_TEST_ENABLED);
michael@0 79 } catch(e) { }
michael@0 80 SpecialPowers.pushPrefEnv({'set': [[PREF_TEST_ENABLED, mode]]}, function() {
michael@0 81 var setMode = SpecialPowers.getCharPref(PREF_TEST_ENABLED);
michael@0 82 ise(setMode, mode, "Test mode set to " + setMode);
michael@0 83 if (setMode === "hardware") {
michael@0 84 try {
michael@0 85 oldTestHw = SpecialPowers.getCharPref(PREF_TEST_HARDWARE);
michael@0 86 } catch(e) { }
michael@0 87 testMode = {
michael@0 88 set: testHardwareSet,
michael@0 89 setFakeParameters: testHardwareSetFakeParameters,
michael@0 90 clearFakeParameters: testHardwareClearFakeParameters,
michael@0 91 done: testHardwareDone
michael@0 92 };
michael@0 93 if (callback) {
michael@0 94 callback(testMode);
michael@0 95 }
michael@0 96 }
michael@0 97 });
michael@0 98 }
michael@0 99
michael@0 100 function testEnd(callback) {
michael@0 101 // A chain of clean-up functions....
michael@0 102 function allCleanedUp() {
michael@0 103 SimpleTest.finish();
michael@0 104 if (callback) {
michael@0 105 callback();
michael@0 106 }
michael@0 107 }
michael@0 108 function cleanUpTestEnabled() {
michael@0 109 var next = allCleanedUp;
michael@0 110 if (oldTestEnabled) {
michael@0 111 SpecialPowers.pushPrefEnv({'set': [[PREF_TEST_ENABLED, oldTestEnabled]]}, next);
michael@0 112 } else {
michael@0 113 SpecialPowers.pushPrefEnv({'clear': [[PREF_TEST_ENABLED]]}, next);
michael@0 114 }
michael@0 115 }
michael@0 116 function cleanUpTest() {
michael@0 117 var next = cleanUpTestEnabled;
michael@0 118 if (testMode) {
michael@0 119 testMode.done(next);
michael@0 120 testMode = null;
michael@0 121 } else {
michael@0 122 next();
michael@0 123 }
michael@0 124 }
michael@0 125 function cleanUpExtraParameters() {
michael@0 126 var next = cleanUpTest;
michael@0 127 if (testMode) {
michael@0 128 testMode.clearFakeParameters(next);
michael@0 129 } else {
michael@0 130 next();
michael@0 131 }
michael@0 132 }
michael@0 133
michael@0 134 cleanUpExtraParameters();
michael@0 135 }
michael@0 136
michael@0 137 ise(SpecialPowers.sanityCheck(), "foo", "SpecialPowers passed sanity check");
michael@0 138 return {
michael@0 139 begin: testBegin,
michael@0 140 end: testEnd
michael@0 141 };
michael@0 142
michael@0 143 })();

mercurial