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.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Modal Prompts Test</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="prompt_common.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | Prompter tests: modal prompts |
michael@0 | 11 | <p id="display"></p> |
michael@0 | 12 | |
michael@0 | 13 | <div id="content" style="display: none"> |
michael@0 | 14 | <iframe id="iframe"></iframe> |
michael@0 | 15 | </div> |
michael@0 | 16 | |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript;version=1.8"> |
michael@0 | 19 | |
michael@0 | 20 | let prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"]. |
michael@0 | 21 | getService(Ci.nsIPromptService2); |
michael@0 | 22 | let ioService = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 23 | getService(Ci.nsIIOService); |
michael@0 | 24 | let pollTimer; |
michael@0 | 25 | |
michael@0 | 26 | function pollDialog(dialog) { |
michael@0 | 27 | if (dialog.getButton("accept").disabled) |
michael@0 | 28 | return; |
michael@0 | 29 | |
michael@0 | 30 | ok(true, "dialog button is enabled now"); |
michael@0 | 31 | pollTimer.cancel(); |
michael@0 | 32 | pollTimer = null; |
michael@0 | 33 | dialog.acceptDialog(); |
michael@0 | 34 | didDialog = true; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function checkExpectedSelectState(doc, state) { |
michael@0 | 38 | let msg = doc.getElementById("info.txt").value; |
michael@0 | 39 | // XXX check title? OS X has title in content |
michael@0 | 40 | let listbox = doc.getElementById("list"); |
michael@0 | 41 | |
michael@0 | 42 | is(msg, state.msg, "Checking expected message"); |
michael@0 | 43 | // XXX check title? OS X has title in content |
michael@0 | 44 | // Compare listbox contents |
michael@0 | 45 | let count = listbox.itemCount; |
michael@0 | 46 | is(count, state.items.length, "Checking listbox length"); |
michael@0 | 47 | if (count) |
michael@0 | 48 | is(listbox.selectedIndex, 0, "Checking selected index"); |
michael@0 | 49 | |
michael@0 | 50 | for (let i = 0; i < count; i++) { |
michael@0 | 51 | let item = listbox.getItemAtIndex(i).label; |
michael@0 | 52 | is(item, items[i], "Checking item #" + i + " label"); |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | /* |
michael@0 | 57 | * handleDialog |
michael@0 | 58 | * |
michael@0 | 59 | * Invoked a short period of time after calling startCallbackTimer(), and |
michael@0 | 60 | * allows testing the actual prompt dialog while it's being displayed. Tests |
michael@0 | 61 | * should call startCallbackTimer() each time the auth dialog is expected (the |
michael@0 | 62 | * timer is a one-shot). |
michael@0 | 63 | */ |
michael@0 | 64 | function handleDialog(doc, testNum) { |
michael@0 | 65 | ok(true, "--- handleDialog for test " + testNum + " ---"); |
michael@0 | 66 | |
michael@0 | 67 | let dialog = doc.getElementsByTagName("dialog")[0]; |
michael@0 | 68 | let listbox = doc.getElementById("list"); |
michael@0 | 69 | let clickOK = true; |
michael@0 | 70 | let state; |
michael@0 | 71 | |
michael@0 | 72 | // XXX check focused element |
michael@0 | 73 | // XXX check text/passbox labels? |
michael@0 | 74 | // XXX check button labels? |
michael@0 | 75 | |
michael@0 | 76 | switch(testNum) { |
michael@0 | 77 | case 1: |
michael@0 | 78 | // Select (0 items) |
michael@0 | 79 | state = { |
michael@0 | 80 | msg : "This is the select text.", |
michael@0 | 81 | title : "TestTitle", |
michael@0 | 82 | items : [], |
michael@0 | 83 | }; |
michael@0 | 84 | checkExpectedSelectState(doc, state); |
michael@0 | 85 | break; |
michael@0 | 86 | |
michael@0 | 87 | case 2: |
michael@0 | 88 | // Select (3 items, default ok) |
michael@0 | 89 | state = { |
michael@0 | 90 | msg : "This is the select text.", |
michael@0 | 91 | title : "TestTitle", |
michael@0 | 92 | items : ["one", "two", "three"], |
michael@0 | 93 | }; |
michael@0 | 94 | checkExpectedSelectState(doc, state); |
michael@0 | 95 | break; |
michael@0 | 96 | |
michael@0 | 97 | case 3: |
michael@0 | 98 | // Select (3 items, change selection, ok) |
michael@0 | 99 | state = { |
michael@0 | 100 | msg : "This is the select text.", |
michael@0 | 101 | title : "TestTitle", |
michael@0 | 102 | items : ["one", "two", "three"], |
michael@0 | 103 | }; |
michael@0 | 104 | checkExpectedSelectState(doc, state); |
michael@0 | 105 | // XXX need to trigger old code's click listener |
michael@0 | 106 | listbox.selectedIndex = 1; |
michael@0 | 107 | //listbox.getItemAtIndex(1).click(); |
michael@0 | 108 | break; |
michael@0 | 109 | |
michael@0 | 110 | case 4: |
michael@0 | 111 | // Select (3 items, cancel) |
michael@0 | 112 | state = { |
michael@0 | 113 | msg : "This is the select text.", |
michael@0 | 114 | title : "TestTitle", |
michael@0 | 115 | items : ["one", "two", "three"], |
michael@0 | 116 | }; |
michael@0 | 117 | checkExpectedSelectState(doc, state); |
michael@0 | 118 | clickOK = false; |
michael@0 | 119 | break; |
michael@0 | 120 | |
michael@0 | 121 | default: |
michael@0 | 122 | ok(false, "Uhh, unhandled switch for testNum #" + testNum); |
michael@0 | 123 | break; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | |
michael@0 | 127 | if (clickOK) |
michael@0 | 128 | dialog.acceptDialog(); |
michael@0 | 129 | else |
michael@0 | 130 | dialog.cancelDialog(); |
michael@0 | 131 | |
michael@0 | 132 | ok(true, "handleDialog done"); |
michael@0 | 133 | didDialog = true; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | let testNum = 0; |
michael@0 | 137 | let selectVal = {}; |
michael@0 | 138 | let isOK; |
michael@0 | 139 | |
michael@0 | 140 | isSelectDialog = true; |
michael@0 | 141 | isTabModal = false; |
michael@0 | 142 | usePromptService = true; |
michael@0 | 143 | |
michael@0 | 144 | // ===== test 1 ===== |
michael@0 | 145 | // Select (0 items, ok) |
michael@0 | 146 | testNum++; |
michael@0 | 147 | startCallbackTimer(); |
michael@0 | 148 | items = []; |
michael@0 | 149 | selectVal.value = null; // outparam, just making sure. |
michael@0 | 150 | isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal); |
michael@0 | 151 | is(isOK, true, "checked expected retval"); |
michael@0 | 152 | is(selectVal.value, -1, "checking selected index"); |
michael@0 | 153 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 154 | |
michael@0 | 155 | // ===== test 2 ===== |
michael@0 | 156 | // Select (3 items, ok) |
michael@0 | 157 | testNum++; |
michael@0 | 158 | startCallbackTimer(); |
michael@0 | 159 | items = ["one", "two", "three"]; |
michael@0 | 160 | selectVal.value = null; // outparam, just making sure. |
michael@0 | 161 | isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal); |
michael@0 | 162 | is(isOK, true, "checked expected retval"); |
michael@0 | 163 | is(selectVal.value, 0, "checking selected index"); |
michael@0 | 164 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 165 | |
michael@0 | 166 | // ===== test 3 ===== |
michael@0 | 167 | // Select (3 items, selection changed, ok) |
michael@0 | 168 | testNum++; |
michael@0 | 169 | startCallbackTimer(); |
michael@0 | 170 | items = ["one", "two", "three"]; |
michael@0 | 171 | selectVal.value = null; // outparam, just making sure. |
michael@0 | 172 | isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal); |
michael@0 | 173 | is(isOK, true, "checked expected retval"); |
michael@0 | 174 | is(selectVal.value, 1, "checking selected index"); |
michael@0 | 175 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 176 | |
michael@0 | 177 | // ===== test 4 ===== |
michael@0 | 178 | // Select (3 items, cancel) |
michael@0 | 179 | testNum++; |
michael@0 | 180 | startCallbackTimer(); |
michael@0 | 181 | items = ["one", "two", "three"]; |
michael@0 | 182 | selectVal.value = null; // outparam, just making sure. |
michael@0 | 183 | isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal); |
michael@0 | 184 | is(isOK, false, "checked expected retval"); |
michael@0 | 185 | is(selectVal.value, 0, "checking selected index"); |
michael@0 | 186 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 187 | |
michael@0 | 188 | |
michael@0 | 189 | </script> |
michael@0 | 190 | </pre> |
michael@0 | 191 | </body> |
michael@0 | 192 | </html> |