dom/plugins/test/mochitest/test_npruntime_npninvoke.html

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 <html>
michael@0 2 <head>
michael@0 3 <title>NPN_Invoke Tests</title>
michael@0 4 <script type="text/javascript"
michael@0 5 src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="utils.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css"
michael@0 8 href="/tests/SimpleTest/test.css" />
michael@0 9 </head>
michael@0 10 <body onload="runTests()">
michael@0 11
michael@0 12 <script class="testbody" type="application/javascript">
michael@0 13 ////
michael@0 14 // This test exercises NPN_Invoke by calling the plugin's npnInvokeTest
michael@0 15 // method, which in turn invokes a script method with 1 or more parameters,
michael@0 16 // and then compares the return vale with an expected value. This is good
michael@0 17 // for verifying various NPVariant values and types moving between
michael@0 18 // the browser and the plugin.
michael@0 19 //
michael@0 20
michael@0 21 SimpleTest.waitForExplicitFinish();
michael@0 22 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
michael@0 23
michael@0 24 // This function returns all the arguments passed to it, either as a
michael@0 25 // single variable (in the caes of 1 argument), or as an array.
michael@0 26 function returnArgs() {
michael@0 27 if (arguments.length == 1)
michael@0 28 return arguments[0];
michael@0 29 var arr = new Array();
michael@0 30 for (i = 0; i < arguments.length; i++) {
michael@0 31 arr.push(arguments[i]);
michael@0 32 }
michael@0 33 return arr;
michael@0 34 }
michael@0 35
michael@0 36 // Same as above but explicitly expects two arguments.
michael@0 37 function returnTwoArgs(arg1, arg2) {
michael@0 38 return [arg1, arg2];
michael@0 39 }
michael@0 40
michael@0 41 // some objects and arrays used in the tests...
michael@0 42 var obj = {"key1": "string", "key2": 0, "key3": true, "key4": undefined,
michael@0 43 "key5": null, "key6": -551235.12552, "key7": false};
michael@0 44 var arr = ["string", 0, true, false, undefined, null, -1, 55512.1252];
michael@0 45 var obj2 = {"key1": "string", "key2": 0, "key3": true, "key4": undefined,
michael@0 46 "key5": null, "key6": -551235.12552, "key7": false, "array": arr};
michael@0 47 var arr2 = ["string", false, undefined, null, -1, 55512.1252,
michael@0 48 {"a": "apple", "b": true, "c": undefined}];
michael@0 49
michael@0 50 ////
michael@0 51 // A list of tests to run. Each member of the main array contains
michael@0 52 // two members: the first contains the arguments passed to npnInvokeTest,
michael@0 53 // and the second is the expected result.
michael@0 54 //
michael@0 55 var tests = [
michael@0 56 // numeric values
michael@0 57 [["returnArgs", 0, 0], true],
michael@0 58 [["returnArgs", 1, 1], true],
michael@0 59 [["returnArgs", 32768, 32768], true],
michael@0 60 [["returnArgs", -32768, -32768], true],
michael@0 61 [["returnArgs", 2147483648, 2147483648], true],
michael@0 62 [["returnArgs", -2147483648, -2147483648], true],
michael@0 63 [["returnArgs", 1.0, 1.0], true],
michael@0 64 [["returnArgs", 1.592786, 1.592786], true],
michael@0 65 [["returnArgs", 1.592786837, 1.592786837], true],
michael@0 66 [["returnArgs", -1.592786, -1.592786], true],
michael@0 67 [["returnArgs", -1.592786837, -1.592786837], true],
michael@0 68 [["returnArgs", 15235.592786, 15235.592786], true],
michael@0 69 // null, void, bool
michael@0 70 [["returnArgs", null, null], true],
michael@0 71 [["returnArgs", undefined, undefined], true],
michael@0 72 [["returnArgs", undefined, null], false],
michael@0 73 [["returnArgs", null, undefined], false],
michael@0 74 [["returnArgs", 0, undefined], false],
michael@0 75 [["returnArgs", 0, null], false],
michael@0 76 [["returnArgs", 0, false], false],
michael@0 77 [["returnArgs", 1, true], false],
michael@0 78 [["returnArgs", true, true], true],
michael@0 79 [["returnArgs", false, false], true],
michael@0 80 // strings
michael@0 81 [["returnArgs", "", ""], true],
michael@0 82 [["returnArgs", "test", "test"], true],
michael@0 83 [["returnArgs", "test", "testing"], false],
michael@0 84 [["returnArgs", "test\n", "test\n"], true],
michael@0 85 [["returnArgs", "test\nline2", "test\nline2"], true],
michael@0 86 [["returnArgs", "test\nline2", "testline2"], false],
michael@0 87 [["returnArgs", "test\u000aline2", "test\u000aline2"], true],
michael@0 88 [["returnArgs", "test\u0020line2", "test line2"], true],
michael@0 89 [["returnArgs", "test line2", "test\u0020line2"], true],
michael@0 90 // objects and arrays
michael@0 91 [["returnArgs", obj, obj], true],
michael@0 92 [["returnArgs", arr, arr], true],
michael@0 93 [["returnArgs", obj2, obj2], true],
michael@0 94 [["returnArgs", arr2, arr2], true],
michael@0 95 // multiple arguments
michael@0 96 [["returnArgs", [0, 1, 2], 0, 1, 2], true],
michael@0 97 [["returnArgs", [5, "a", true, false, null],
michael@0 98 5, "a", true, false, null], true],
michael@0 99 [["returnArgs", [-1500.583, "test string\n",
michael@0 100 [5, 10, 15, 20], {"a": 1, "b": 2}],
michael@0 101 -1500.583, "test string\n", [5, 10, 15, 20], {"a": 1, "b": 2}], true],
michael@0 102 [["returnArgs", [undefined, 0, null, "yes"],
michael@0 103 undefined, 0, null, "yes"], true],
michael@0 104 [["returnArgs", [0, undefined, null, "yes"],
michael@0 105 0, undefined, null, "yes"], true],
michael@0 106 // too many/too few args
michael@0 107 [["returnTwoArgs", ["a", "b"], "a", "b", "c"], true],
michael@0 108 [["returnTwoArgs", ["a", undefined], "a"], true],
michael@0 109 [["returnTwoArgs", [undefined, undefined]], true],
michael@0 110 ];
michael@0 111
michael@0 112 function runTests() {
michael@0 113 var plugin = document.getElementById("plugin1");
michael@0 114
michael@0 115 var result;
michael@0 116 for (var test of tests) {
michael@0 117 switch (test[0].length) {
michael@0 118 case 2:
michael@0 119 result = plugin.npnInvokeTest(test[0][0], test[0][1]);
michael@0 120 break;
michael@0 121 case 3:
michael@0 122 result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2]);
michael@0 123 break;
michael@0 124 case 4:
michael@0 125 result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2],
michael@0 126 test[0][3]);
michael@0 127 break;
michael@0 128 case 5:
michael@0 129 result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2],
michael@0 130 test[0][3], test[0][4]);
michael@0 131 case 6:
michael@0 132 result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2],
michael@0 133 test[0][3], test[0][4], test[0][5]);
michael@0 134 break;
michael@0 135 case 7:
michael@0 136 result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2],
michael@0 137 test[0][3], test[0][4], test[0][5], test[0][6]);
michael@0 138 break;
michael@0 139 default:
michael@0 140 is(false, "bad number of test arguments");
michael@0 141 }
michael@0 142 is(result, test[1], "npnInvokeTestFailed: " + plugin.getError());
michael@0 143 $("verbose").appendChild(
michael@0 144 createEl('span', null, ((result == test[1] ? "pass" : "fail") + ": " + test[0])));
michael@0 145 if (result != test[1])
michael@0 146 $("verbose").appendChild(createEl("span", null, (" " + plugin.getError())));
michael@0 147 $("verbose").appendChild(createEl('br'));
michael@0 148 }
michael@0 149
michael@0 150 SimpleTest.finish();
michael@0 151 }
michael@0 152 </script>
michael@0 153
michael@0 154 <p id="display"></p>
michael@0 155
michael@0 156 <embed id="plugin1" type="application/x-test" width="400" height="100">
michael@0 157 </embed>
michael@0 158
michael@0 159 <div id="verbose">
michael@0 160 </div>
michael@0 161 </body>
michael@0 162 </html>

mercurial