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