Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | module("selector"); |
michael@0 | 2 | |
michael@0 | 3 | test("element", function() { |
michael@0 | 4 | expect(9); |
michael@0 | 5 | ok( $("*").size() >= 30, "Select all" ); |
michael@0 | 6 | var all = $("*"), good = true; |
michael@0 | 7 | for ( var i = 0; i < all.length; i++ ) |
michael@0 | 8 | if ( all[i].nodeType == 8 ) |
michael@0 | 9 | good = false; |
michael@0 | 10 | ok( good, "Select all elements, no comment nodes" ); |
michael@0 | 11 | t( "Element Selector", "p", ["firstp","ap","sndp","en","sap","first"] ); |
michael@0 | 12 | t( "Element Selector", "body", ["body"] ); |
michael@0 | 13 | t( "Element Selector", "html", ["html"] ); |
michael@0 | 14 | t( "Parent Element", "div p", ["firstp","ap","sndp","en","sap","first"] ); |
michael@0 | 15 | equals( $("param", "#object1").length, 2, "Object/param as context" ); |
michael@0 | 16 | |
michael@0 | 17 | ok( $("#length").length, '<input name="length"> cannot be found under IE, see #945' ); |
michael@0 | 18 | ok( $("#lengthtest input").length, '<input name="length"> cannot be found under IE, see #945' ); |
michael@0 | 19 | }); |
michael@0 | 20 | |
michael@0 | 21 | if ( location.protocol != "file:" ) { |
michael@0 | 22 | test("Element Selector with underscore", function() { |
michael@0 | 23 | expect(1); |
michael@0 | 24 | stop(); |
michael@0 | 25 | $.get("data/with_fries.xml", function(xml) { |
michael@0 | 26 | equals( $("foo_bar", xml).length, 1, "Element Selector with underscore" ); |
michael@0 | 27 | start(); |
michael@0 | 28 | }); |
michael@0 | 29 | }); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | test("broken", function() { |
michael@0 | 33 | expect(7); |
michael@0 | 34 | t( "Broken Selector", "[", [] ); |
michael@0 | 35 | t( "Broken Selector", "(", [] ); |
michael@0 | 36 | t( "Broken Selector", "{", [] ); |
michael@0 | 37 | t( "Broken Selector", "<", [] ); |
michael@0 | 38 | t( "Broken Selector", "()", [] ); |
michael@0 | 39 | t( "Broken Selector", "<>", [] ); |
michael@0 | 40 | t( "Broken Selector", "{}", [] ); |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | test("id", function() { |
michael@0 | 44 | expect(25); |
michael@0 | 45 | t( "ID Selector", "#body", ["body"] ); |
michael@0 | 46 | t( "ID Selector w/ Element", "body#body", ["body"] ); |
michael@0 | 47 | t( "ID Selector w/ Element", "ul#first", [] ); |
michael@0 | 48 | t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] ); |
michael@0 | 49 | t( "ID selector with non-existant descendant", "#firstp #foobar", [] ); |
michael@0 | 50 | t( "ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"] ); |
michael@0 | 51 | t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi","台北"] ); |
michael@0 | 52 | t( "Descendant ID selector using UTF8", "div #台北", ["台北"] ); |
michael@0 | 53 | t( "Child ID selector using UTF8", "form > #台北", ["台北"] ); |
michael@0 | 54 | |
michael@0 | 55 | t( "Escaped ID", "#foo\\:bar", ["foo:bar"] ); |
michael@0 | 56 | t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); |
michael@0 | 57 | t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] ); |
michael@0 | 58 | t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); |
michael@0 | 59 | t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] ); |
michael@0 | 60 | t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); |
michael@0 | 61 | |
michael@0 | 62 | t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267 |
michael@0 | 63 | t( "ID Selector, not an ancestor ID", "#form #first", [] ); |
michael@0 | 64 | t( "ID Selector, not a child ID", "#form > #option1a", [] ); |
michael@0 | 65 | |
michael@0 | 66 | t( "All Children of ID", "#foo > *", ["sndp", "en", "sap"] ); |
michael@0 | 67 | t( "All Children of ID with no children", "#firstUL/*", [] ); |
michael@0 | 68 | |
michael@0 | 69 | $('<a name="tName1">tName1 A</a><a name="tName2">tName2 A</a><div id="tName1">tName1 Div</div>').appendTo('#main'); |
michael@0 | 70 | equals( $("#tName1")[0].id, 'tName1', "ID selector with same value for a name attribute" ); |
michael@0 | 71 | equals( $("#tName2").length, 0, "ID selector non-existing but name attribute on an A tag" ); |
michael@0 | 72 | t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] ); |
michael@0 | 73 | |
michael@0 | 74 | t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986 |
michael@0 | 75 | |
michael@0 | 76 | isSet( $("body").find("div#form"), [], "ID selector within the context of another element" ); |
michael@0 | 77 | }); |
michael@0 | 78 | |
michael@0 | 79 | test("class", function() { |
michael@0 | 80 | expect(16); |
michael@0 | 81 | t( "Class Selector", ".blog", ["mark","simon"] ); |
michael@0 | 82 | t( "Class Selector", ".blog.link", ["simon"] ); |
michael@0 | 83 | t( "Class Selector w/ Element", "a.blog", ["mark","simon"] ); |
michael@0 | 84 | t( "Parent Class Selector", "p .blog", ["mark","simon"] ); |
michael@0 | 85 | |
michael@0 | 86 | t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] ); |
michael@0 | 87 | t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] ); |
michael@0 | 88 | t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] ); |
michael@0 | 89 | t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] ); |
michael@0 | 90 | t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] ); |
michael@0 | 91 | t( "Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"] ); |
michael@0 | 92 | |
michael@0 | 93 | t( "Escaped Class", ".foo\\:bar", ["foo:bar"] ); |
michael@0 | 94 | t( "Escaped Class", ".test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); |
michael@0 | 95 | t( "Descendant scaped Class", "div .foo\\:bar", ["foo:bar"] ); |
michael@0 | 96 | t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); |
michael@0 | 97 | t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] ); |
michael@0 | 98 | t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); |
michael@0 | 99 | }); |
michael@0 | 100 | |
michael@0 | 101 | test("multiple", function() { |
michael@0 | 102 | expect(4); |
michael@0 | 103 | t( "Comma Support", "a.blog, p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); |
michael@0 | 104 | t( "Comma Support", "a.blog , p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); |
michael@0 | 105 | t( "Comma Support", "a.blog ,p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); |
michael@0 | 106 | t( "Comma Support", "a.blog,p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); |
michael@0 | 107 | }); |
michael@0 | 108 | |
michael@0 | 109 | test("child and adjacent", function() { |
michael@0 | 110 | expect(37); |
michael@0 | 111 | t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] ); |
michael@0 | 112 | t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] ); |
michael@0 | 113 | t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] ); |
michael@0 | 114 | t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] ); |
michael@0 | 115 | t( "Child w/ Class", "p > a.blog", ["mark","simon"] ); |
michael@0 | 116 | t( "All Children", "code > *", ["anchor1","anchor2"] ); |
michael@0 | 117 | t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] ); |
michael@0 | 118 | t( "Adjacent", "a + a", ["groups"] ); |
michael@0 | 119 | t( "Adjacent", "a +a", ["groups"] ); |
michael@0 | 120 | t( "Adjacent", "a+ a", ["groups"] ); |
michael@0 | 121 | t( "Adjacent", "a+a", ["groups"] ); |
michael@0 | 122 | t( "Adjacent", "p + p", ["ap","en","sap"] ); |
michael@0 | 123 | t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] ); |
michael@0 | 124 | |
michael@0 | 125 | t( "First Child", "p:first-child", ["firstp","sndp"] ); |
michael@0 | 126 | t( "Nth Child", "p:nth-child(1)", ["firstp","sndp"] ); |
michael@0 | 127 | |
michael@0 | 128 | t( "Last Child", "p:last-child", ["sap"] ); |
michael@0 | 129 | t( "Last Child", "a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon"] ); |
michael@0 | 130 | |
michael@0 | 131 | t( "Nth-child", "#main form#form > *:nth-child(2)", ["text2"] ); |
michael@0 | 132 | t( "Nth-child", "#main form#form > :nth-child(2)", ["text2"] ); |
michael@0 | 133 | |
michael@0 | 134 | t( "Nth-child", "#form select:first option:nth-child(3)", ["option1c"] ); |
michael@0 | 135 | t( "Nth-child", "#form select:first option:nth-child(0n+3)", ["option1c"] ); |
michael@0 | 136 | t( "Nth-child", "#form select:first option:nth-child(1n+0)", ["option1a", "option1b", "option1c", "option1d"] ); |
michael@0 | 137 | t( "Nth-child", "#form select:first option:nth-child(1n)", ["option1a", "option1b", "option1c", "option1d"] ); |
michael@0 | 138 | t( "Nth-child", "#form select:first option:nth-child(n)", ["option1a", "option1b", "option1c", "option1d"] ); |
michael@0 | 139 | t( "Nth-child", "#form select:first option:nth-child(even)", ["option1b", "option1d"] ); |
michael@0 | 140 | t( "Nth-child", "#form select:first option:nth-child(odd)", ["option1a", "option1c"] ); |
michael@0 | 141 | t( "Nth-child", "#form select:first option:nth-child(2n)", ["option1b", "option1d"] ); |
michael@0 | 142 | t( "Nth-child", "#form select:first option:nth-child(2n+1)", ["option1a", "option1c"] ); |
michael@0 | 143 | t( "Nth-child", "#form select:first option:nth-child(3n)", ["option1c"] ); |
michael@0 | 144 | t( "Nth-child", "#form select:first option:nth-child(3n+1)", ["option1a", "option1d"] ); |
michael@0 | 145 | t( "Nth-child", "#form select:first option:nth-child(3n+2)", ["option1b"] ); |
michael@0 | 146 | t( "Nth-child", "#form select:first option:nth-child(3n+3)", ["option1c"] ); |
michael@0 | 147 | t( "Nth-child", "#form select:first option:nth-child(3n-1)", ["option1b"] ); |
michael@0 | 148 | t( "Nth-child", "#form select:first option:nth-child(3n-2)", ["option1a", "option1d"] ); |
michael@0 | 149 | t( "Nth-child", "#form select:first option:nth-child(3n-3)", ["option1c"] ); |
michael@0 | 150 | t( "Nth-child", "#form select:first option:nth-child(3n+0)", ["option1c"] ); |
michael@0 | 151 | t( "Nth-child", "#form select:first option:nth-child(-n+3)", ["option1a", "option1b", "option1c"] ); |
michael@0 | 152 | }); |
michael@0 | 153 | |
michael@0 | 154 | test("attributes", function() { |
michael@0 | 155 | expect(20); |
michael@0 | 156 | t( "Attribute Exists", "a[title]", ["google"] ); |
michael@0 | 157 | t( "Attribute Exists", "*[title]", ["google"] ); |
michael@0 | 158 | t( "Attribute Exists", "[title]", ["google"] ); |
michael@0 | 159 | |
michael@0 | 160 | t( "Attribute Equals", "a[rel='bookmark']", ["simon1"] ); |
michael@0 | 161 | t( "Attribute Equals", 'a[rel="bookmark"]', ["simon1"] ); |
michael@0 | 162 | t( "Attribute Equals", "a[rel=bookmark]", ["simon1"] ); |
michael@0 | 163 | t( "Multiple Attribute Equals", "#form input[type='hidden'],#form input[type='radio']", ["hidden1","radio1","radio2"] ); |
michael@0 | 164 | t( "Multiple Attribute Equals", "#form input[type=\"hidden\"],#form input[type='radio']", ["hidden1","radio1","radio2"] ); |
michael@0 | 165 | t( "Multiple Attribute Equals", "#form input[type=hidden],#form input[type=radio]", ["hidden1","radio1","radio2"] ); |
michael@0 | 166 | |
michael@0 | 167 | t( "Attribute selector using UTF8", "span[lang=中文]", ["台北"] ); |
michael@0 | 168 | |
michael@0 | 169 | t( "Attribute Begins With", "a[href ^= 'http://www']", ["google","yahoo"] ); |
michael@0 | 170 | t( "Attribute Ends With", "a[href $= 'org/']", ["mark"] ); |
michael@0 | 171 | t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] ); |
michael@0 | 172 | |
michael@0 | 173 | t("Select options via [selected]", "#select1 option[selected]", ["option1a"] ); |
michael@0 | 174 | t("Select options via [selected]", "#select2 option[selected]", ["option2d"] ); |
michael@0 | 175 | t("Select options via [selected]", "#select3 option[selected]", ["option3b", "option3c"] ); |
michael@0 | 176 | |
michael@0 | 177 | t( "Grouped Form Elements", "input[name='foo[bar]']", ["hidden2"] ); |
michael@0 | 178 | |
michael@0 | 179 | t( ":not() Existing attribute", "#form select:not([multiple])", ["select1", "select2"]); |
michael@0 | 180 | t( ":not() Equals attribute", "#form select:not([name=select1])", ["select2", "select3"]); |
michael@0 | 181 | t( ":not() Equals quoted attribute", "#form select:not([name='select1'])", ["select2", "select3"]); |
michael@0 | 182 | }); |
michael@0 | 183 | |
michael@0 | 184 | test("pseudo (:) selectors", function() { |
michael@0 | 185 | expect(35); |
michael@0 | 186 | t( "First Child", "p:first-child", ["firstp","sndp"] ); |
michael@0 | 187 | t( "Last Child", "p:last-child", ["sap"] ); |
michael@0 | 188 | t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] ); |
michael@0 | 189 | t( "Empty", "ul:empty", ["firstUL"] ); |
michael@0 | 190 | t( "Enabled UI Element", "#form input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] ); |
michael@0 | 191 | t( "Disabled UI Element", "#form input:disabled", ["text2"] ); |
michael@0 | 192 | t( "Checked UI Element", "#form input:checked", ["radio2","check1"] ); |
michael@0 | 193 | t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c"] ); |
michael@0 | 194 | t( "Text Contains", "a:contains('Google')", ["google","groups"] ); |
michael@0 | 195 | t( "Text Contains", "a:contains('Google Groups')", ["groups"] ); |
michael@0 | 196 | t( "Element Preceded By", "p ~ div", ["foo","fx-queue","fx-tests", "moretests"] ); |
michael@0 | 197 | t( "Not", "a.blog:not(.link)", ["mark"] ); |
michael@0 | 198 | t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d"] ); |
michael@0 | 199 | t( "Not - complex", "#form option:not([id^='opt']:gt(0):nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d"] ); |
michael@0 | 200 | t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] ); |
michael@0 | 201 | |
michael@0 | 202 | t( "nth Element", "p:nth(1)", ["ap"] ); |
michael@0 | 203 | t( "First Element", "p:first", ["firstp"] ); |
michael@0 | 204 | t( "Last Element", "p:last", ["first"] ); |
michael@0 | 205 | t( "Even Elements", "p:even", ["firstp","sndp","sap"] ); |
michael@0 | 206 | t( "Odd Elements", "p:odd", ["ap","en","first"] ); |
michael@0 | 207 | t( "Position Equals", "p:eq(1)", ["ap"] ); |
michael@0 | 208 | t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] ); |
michael@0 | 209 | t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] ); |
michael@0 | 210 | t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] ); |
michael@0 | 211 | t( "Is Visible", "#form input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] ); |
michael@0 | 212 | t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] ); |
michael@0 | 213 | |
michael@0 | 214 | t( "Form element :input", "#form :input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] ); |
michael@0 | 215 | t( "Form element :radio", "#form :radio", ["radio1", "radio2"] ); |
michael@0 | 216 | t( "Form element :checkbox", "#form :checkbox", ["check1", "check2"] ); |
michael@0 | 217 | t( "Form element :text", "#form :text", ["text1", "text2", "hidden2", "name"] ); |
michael@0 | 218 | t( "Form element :radio:checked", "#form :radio:checked", ["radio2"] ); |
michael@0 | 219 | t( "Form element :checkbox:checked", "#form :checkbox:checked", ["check1"] ); |
michael@0 | 220 | t( "Form element :checkbox:checked, :radio:checked", "#form :checkbox:checked, #form :radio:checked", ["check1", "radio2"] ); |
michael@0 | 221 | |
michael@0 | 222 | t( "Headers", ":header", ["header", "banner", "userAgent"] ); |
michael@0 | 223 | t( "Has Children - :has()", "p:has(a)", ["firstp","ap","en","sap"] ); |
michael@0 | 224 | }); |