content/test/unit/test_normalize.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 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 function run_test()
michael@0 7 {
michael@0 8 /*
michael@0 9 * NOTE: [i] is not allowed in this test, since it's done via classinfo and
michael@0 10 * we don't have that in xpcshell; the workaround is item(i). Suck.
michael@0 11 */
michael@0 12 init();
michael@0 13
michael@0 14 test_element();
michael@0 15
michael@0 16 // more tests would be nice here (such as for documents), but the primary
michael@0 17 // uses of Node.normalize() are in test_element; stuff beyond this is either
michael@0 18 // unimplemented or is unlikely to be used all that much within a browser
michael@0 19 // DOM implementation
michael@0 20 }
michael@0 21
michael@0 22 // TEST CODE
michael@0 23
michael@0 24 var doc; // cache for use in all tests
michael@0 25
michael@0 26 function init()
michael@0 27 {
michael@0 28 doc = ParseFile("empty_document.xml");
michael@0 29 }
michael@0 30
michael@0 31 function test_element()
michael@0 32 {
michael@0 33 var x = doc.createElement("funk");
michael@0 34
michael@0 35 // one empty Text node
michael@0 36 x.appendChild(doc.createTextNode(""));
michael@0 37 do_check_eq(x.childNodes.length, 1);
michael@0 38
michael@0 39 x.normalize();
michael@0 40 do_check_eq(x.childNodes.length, 0);
michael@0 41
michael@0 42
michael@0 43 // multiple empty Text nodes
michael@0 44 x.appendChild(doc.createTextNode(""));
michael@0 45 x.appendChild(doc.createTextNode(""));
michael@0 46 do_check_eq(x.childNodes.length, 2);
michael@0 47
michael@0 48 x.normalize();
michael@0 49 do_check_eq(x.childNodes.length, 0);
michael@0 50
michael@0 51
michael@0 52 // empty Text node followed by other Text node
michael@0 53 x.appendChild(doc.createTextNode(""));
michael@0 54 x.appendChild(doc.createTextNode("Guaraldi"));
michael@0 55 do_check_eq(x.childNodes.length, 2);
michael@0 56
michael@0 57 x.normalize();
michael@0 58 do_check_eq(x.childNodes.length, 1);
michael@0 59 do_check_eq(x.childNodes.item(0).nodeValue, "Guaraldi");
michael@0 60
michael@0 61
michael@0 62 // Text node followed by empty Text node
michael@0 63 clearKids(x);
michael@0 64 x.appendChild(doc.createTextNode("Guaraldi"));
michael@0 65 x.appendChild(doc.createTextNode(""));
michael@0 66 do_check_eq(x.childNodes.length, 2);
michael@0 67
michael@0 68 x.normalize();
michael@0 69 do_check_eq(x.childNodes.item(0).nodeValue, "Guaraldi");
michael@0 70
michael@0 71
michael@0 72 // Text node followed by empty Text node followed by other Node
michael@0 73 clearKids(x);
michael@0 74 x.appendChild(doc.createTextNode("Guaraldi"));
michael@0 75 x.appendChild(doc.createTextNode(""));
michael@0 76 x.appendChild(doc.createElement("jazzy"));
michael@0 77 do_check_eq(x.childNodes.length, 3);
michael@0 78
michael@0 79 x.normalize();
michael@0 80 do_check_eq(x.childNodes.length, 2);
michael@0 81 do_check_eq(x.childNodes.item(0).nodeValue, "Guaraldi");
michael@0 82 do_check_eq(x.childNodes.item(1).nodeName, "jazzy");
michael@0 83
michael@0 84
michael@0 85 // Nodes are recursively normalized
michael@0 86 clearKids(x);
michael@0 87 var kid = doc.createElement("eit");
michael@0 88 kid.appendChild(doc.createTextNode(""));
michael@0 89
michael@0 90 x.appendChild(doc.createTextNode("Guaraldi"));
michael@0 91 x.appendChild(doc.createTextNode(""));
michael@0 92 x.appendChild(kid);
michael@0 93 do_check_eq(x.childNodes.length, 3);
michael@0 94 do_check_eq(x.childNodes.item(2).childNodes.length, 1);
michael@0 95
michael@0 96 x.normalize();
michael@0 97 do_check_eq(x.childNodes.length, 2);
michael@0 98 do_check_eq(x.childNodes.item(0).nodeValue, "Guaraldi");
michael@0 99 do_check_eq(x.childNodes.item(1).childNodes.length, 0);
michael@0 100 }
michael@0 101
michael@0 102
michael@0 103 // UTILITY FUNCTIONS
michael@0 104
michael@0 105 function clearKids(node)
michael@0 106 {
michael@0 107 while (node.hasChildNodes())
michael@0 108 node.removeChild(node.childNodes.item(0));
michael@0 109 }

mercurial