Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved test content out of DOM0 window.onload handler because Caja doe…

…sn't support this method of onload subscription. This may be filed as a bug.
  • Loading branch information...
commit 549d2149db56bd25e91b0ca532b0f969b5d4cc19 1 parent f604446
@lsmith lsmith authored
Showing with 256 additions and 258 deletions.
  1. +256 −258 yui2.8/tests/selector/tests/selector_caja.html
View
514 yui2.8/tests/selector/tests/selector_caja.html
@@ -15,264 +15,6 @@
<script type="text/javascript" src="yui/yuitest/yuitest.js"></script>
<script id="foo-script" type="text/javascript" src="#"></script>
-<script>
-onload = function() {
- var Y = YAHOO.util;
- var logger = new YAHOO.tool.TestLogger(null, {height:'2000px'});
- var suite = new YAHOO.tool.TestSuite("Selector Suite");
- var Selector = Y.Selector;
-
- var $ = Selector.query;
- var demo = Y.Dom.get('demo');
- children = Y.Dom.getChildren(demo);
- var demoFirstChild = children[0];
- var demoLastChild = children[children.length - 1];
-
- var selectorQueryAll = new YAHOO.tool.TestCase({
- name: 'Query All',
-
- testTest: function() {
- Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), '[type=checkbox], button'), '[type=checkbox], button');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('test-lang-en-us'), '[lang|=en]'), '[lang|=en] (lang="en-us")');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('test-lang-en'), '[lang|=en]'), '[lang|=en] (lang="en")');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('test-lang-english'), '[lang|=en]'), '[lang|=en] (lang="en")');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('test-lang-none'), '[lang|=en]'), '[lang|=en] false pos');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('checkbox-unchecked'), 'for [type=checkbox]'), 'for [type=checkbox] false pos');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), 'form [type=checkbox]'), 'form [type=checkbox]');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('checkbox-unchecked'), 'for [type=checkbox]'), 'for [type=checkbox] false pos');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), '[type=checkbox], button'), '[type=checkbox], button');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), 'button, [type=checkbox]'), 'button, [type=checkbox]');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('checkbox-unchecked'), 'foo, button'), 'foo, button');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-checked'), '[type=checkbox]:checked'), 'type=checkbox:checked');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('radio-checked'), ':checked'), ':checked (radio)');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('radio-unchecked'), ':checked'), ':checked (radio) false pos');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('checkbox-unchecked'), '[type=checkbox]:checked'), 'type=checkbox:checked false pos');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), '[type=checkbox]:not(:checked)'), 'type=checkbox:not(:checked)');
- },
-
- testRootQuery: function() {
- var all = Y.Dom.get('nth-test').getElementsByTagName('li');
- Y.ArrayAssert.itemsAreEqual(all, $('li', 'nth-test'), 'id as root');
- Y.ArrayAssert.itemsAreEqual([], $('li', 'nth-tes'), 'id as root false pos');
- Y.ArrayAssert.itemsAreEqual(all, $('li', Y.Dom.get('nth-test')), 'node as root');
- Y.ArrayAssert.itemsAreEqual(all, $('#nth-test li', Y.Dom.get('root-test')), 'id selector w/root');
- Y.ArrayAssert.itemsAreEqual([], $('#root-test li', Y.Dom.get('nth-test')), 'id selector w/root false pos');
- Y.ArrayAssert.itemsAreEqual([], $('#root-test li', Y.Dom.get('nth-test')), 'id selector w/root false pos');
- Y.ArrayAssert.itemsAreEqual([Y.Dom.get('nth-test')], $('> ol', 'root-test'), "$('> ol', 'root-test')");
- Y.ArrayAssert.itemsAreEqual([Y.Dom.get('root-test')], $('+ div', 'empty'), "$('+ div', 'empty')");
- },
- testNthLastChild: function() {
- var all = Y.Dom.get('nth-test').getElementsByTagName('li');
- var odd = Y.Dom.getElementsByClassName('even', 'li', 'nth-test');
- var even = Y.Dom.getElementsByClassName('odd', 'li', 'nth-test');
- var four1 = Y.Dom.getElementsByClassName('last-four-1', 'li', 'nth-test');
-
- Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-last-child(2n+1)'), '2n+1');
- Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-last-child(odd)'), 'odd');
- Y.ArrayAssert.itemsAreEqual(even, $('li:nth-last-child(2n+0)'), '2n+0');
- Y.ArrayAssert.itemsAreEqual(even, $('li:nth-last-child(2n)'), '2n');
- Y.ArrayAssert.itemsAreEqual(even, $('li:nth-last-child(even)'), 'even');
- Y.ArrayAssert.itemsAreEqual(four1, $('li:nth-last-child(4n+1)'), '4n+1');
- },
- testNthType: function() {
- var all = Y.Dom.get('nth-test').getElementsByTagName('li');
- var odd = Y.Dom.getElementsByClassName('odd', 'li', 'nth-test');
- var even = Y.Dom.getElementsByClassName('even', 'li', 'nth-test');
- var three1 = Y.Dom.getElementsByClassName('three-1', 'li', 'nth-test');
- var four1 = Y.Dom.getElementsByClassName('four-1', 'li', 'nth-test');
- var four2 = Y.Dom.getElementsByClassName('four-2', 'li', 'nth-test');
- var four3 = Y.Dom.getElementsByClassName('four-3', 'li', 'nth-test');
- var four4 = Y.Dom.getElementsByClassName('four-4', 'li', 'nth-test');
- Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-of-type(odd)'), 'odd');
- },
- testNthChild: function() {
- var all = Y.Dom.get('nth-test').getElementsByTagName('li');
- var odd = Y.Dom.getElementsByClassName('odd', 'li', 'nth-test');
- var even = Y.Dom.getElementsByClassName('even', 'li', 'nth-test');
- var three1 = Y.Dom.getElementsByClassName('three-1', 'li', 'nth-test');
- var four1 = Y.Dom.getElementsByClassName('four-1', 'li', 'nth-test');
- var four2 = Y.Dom.getElementsByClassName('four-2', 'li', 'nth-test');
- var four3 = Y.Dom.getElementsByClassName('four-3', 'li', 'nth-test');
- var four4 = Y.Dom.getElementsByClassName('four-4', 'li', 'nth-test');
-
- Y.ArrayAssert.itemsAreEqual(even[1], $('li:nth-child(2)'), '2');
- Y.ArrayAssert.itemsAreEqual(even[1], $('li:nth-child(0n+2)'), '0n+2');
- Y.ArrayAssert.itemsAreEqual(three1, $('li:nth-child(3n+1)'), '3n+1');
- Y.ArrayAssert.itemsAreEqual(all, $('li:nth-child(n+1)'), 'n+1');
-
- // from http://www.w3.org/TR/css3-selectors/#nth-child-pseudo examples
- Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-child(2n+1)'), '2n+1');
- Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-child(odd)'), 'odd');
- Y.ArrayAssert.itemsAreEqual(even, $('li:nth-child(2n+0)'), '2n+0');
- Y.ArrayAssert.itemsAreEqual(even, $('li:nth-child(2n)'), '2n');
- Y.ArrayAssert.itemsAreEqual(even, $('li:nth-child(even)'), 'even');
- Y.ArrayAssert.itemsAreEqual(four1, $('li:nth-child(4n+1)'), '4n+1');
- Y.ArrayAssert.itemsAreEqual(four2, $('li:nth-child(4n+2)'), '4n+2');
- Y.ArrayAssert.itemsAreEqual(four3, $('li:nth-child(4n+3)'), '4n+3');
- Y.ArrayAssert.itemsAreEqual(four4, $('li:nth-child(4n+4)'), '4n+4');
- Y.ArrayAssert.itemsAreEqual(even[0], $('li:nth-child(0n+1)'), '0n+1');
- Y.ArrayAssert.itemsAreEqual(even[0], $('li:nth-child(1)'), '1');
- Y.ArrayAssert.itemsAreEqual(all, $('li:nth-child(1n+0)'), '1n+0');
- Y.ArrayAssert.itemsAreEqual(all, $('li:nth-child(n+0)'), 'n+0');
-
- },
-
- testSelector: function() {
- Y.ArrayAssert.itemsAreEqual($('.not-button', 'test-inputs'), $('input:not([type=button])', 'test-inputs'), 'input[type=radio], input[type=checkbox] = input:not([type=button])');
- Y.ArrayAssert.itemsAreEqual($('p, p'), document.getElementsByTagName('p'), 'p, p');
- Y.ArrayAssert.itemsAreEqual($('p', null, true), document.getElementsByTagName('p')[0], 'p (firstOnly)');
- Y.ArrayAssert.itemsAreEqual($('.Foo'), [], '.Foo');
- Y.ArrayAssert.itemsAreEqual($('p ~ p'), [children[1], children[2]], 'p ~ p');
- Y.ArrayAssert.itemsAreEqual([], $('#demo.bar p'), '#demo.bar p');
- Y.ArrayAssert.itemsAreEqual(Y.Dom.get('demo').getElementsByTagName('p'), $('#demo.foo p'), '#demo.foo p');
- Y.ArrayAssert.itemsAreEqual(Y.Dom.get('demo').getElementsByTagName('p'), $('.foo p'), '.foo p');
- Y.ArrayAssert.itemsAreEqual(Y.Dom.get('demo').getElementsByTagName('p'), $('#demo p'), '#demo p');
- Y.ArrayAssert.itemsAreEqual($('p > em'), [Y.Dom.getFirstChild('demo-first-child')], 'p > em');
- Y.ArrayAssert.itemsAreEqual(Y.Dom.getElementsByClassName('para'), $('[class~=para]'), '[class=~para]');
- Y.ArrayAssert.itemsAreEqual(document.body.getElementsByTagName('p'), $('body div p'), 'body div p');
- Y.ArrayAssert.itemsAreEqual([], $('#demo .madeup'), '#demo .madeup');
- Y.ArrayAssert.itemsAreEqual(Y.Dom.getElementsByClassName('para', 'p'), $('div .para'), 'div .para');
- Y.ArrayAssert.itemsAreEqual(Y.Dom.getElementsByClassName('first', null, 'demo'), $('#demo .first'), '#demo .first');
- Y.ArrayAssert.itemsAreEqual(document.getElementsByTagName('div'), $('div'), 'div');
- Y.ArrayAssert.itemsAreEqual(document.body.getElementsByTagName('div'), $('body div'), 'body div');
- Y.ArrayAssert.itemsAreEqual([demoFirstChild, Y.Dom.getNextSibling(demoFirstChild)], $('#demo p:not(.last)'), '#demo p:not(.last)');
- Y.ArrayAssert.itemsAreEqual(Y.Dom.get('demo2').getElementsByTagName('div'), $('div:contains(child of demo2)', 'demo2'), 'div:contains:(child of demo2) ');
- Y.ArrayAssert.itemsAreEqual([Y.Dom.get('class-bar')], $('.Bar'), '.Bar');
- Y.ArrayAssert.itemsAreEqual([Y.Dom.get('root-test')], $('#empty + div'), "$('#empty + div')");
- Y.Assert.areEqual(Y.Dom.get('empty'), $('div[custom]', null, true), "$('div[custom]', null, true)");
- Y.ArrayAssert.itemsAreEqual([Y.Dom.get('test-obj')], $('object[custom]'), "$('object[custom]')");
-
- Y.Assert.areEqual(Y.Dom.get('empty'), $('div[customAttr]', null, true), "$('div[customAttr]', null, true)");
- Y.ArrayAssert.itemsAreEqual([Y.Dom.get('test-obj')], $('object[customAttr]'), "$('object[customAttr]')");
-
- Y.Assert.areEqual(Y.Dom.get('href-test'), $('[href=foo.html]', null, true), '[href=foo.html]');
- Y.Assert.areEqual(Y.Dom.get('href-test'), $('a[href=foo.html]', null, true), 'a[href=foo.html]');
- Y.Assert.areEqual(Y.Dom.get('href-test2'), $('[href=http://foo.com/foo.html]', null, true), 'href=http://foo.com/foo.html');
- Y.Assert.areEqual(Y.Dom.get('href-test3'), $('[href=http://foo.com/foo.html?foo=foo&bar=bar]', null, true), 'href=http://foo.com/foo.html?foo=foo&bar=baz');
- Y.Assert.areEqual(Y.Dom.get('selector-script'), $('head > script[src=yui/selector/selector.js]', null, true), 'head > script[src=yui/selector/selector.js]');
- Y.Assert.areEqual(Y.Dom.get('href-test'), $('a[href]', null, true), 'a[href]');
- Y.Assert.areEqual(Y.Dom.get('href-test'), $('body [href]', null, true), 'body [href]');
-
- Y.Assert.areEqual(Y.Dom.get('foo-script'), $('head > script[src=http://foo.com/bar.js]', null, true), 'head > script[src=http://foo.com/bar.js]');
- }
- });
-
- var simpleTest = new YAHOO.tool.TestCase({
- name: 'Simple Node Test',
-
- testPseudo: function() {
- //Y.Assert.isTrue(Selector.test(Y.Dom.get('empty'), ':empty'), 'empty');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo2'), ':empty'), 'empty false pos');
- Y.Assert.isTrue(Selector.test(Y.Dom.getLastChild('demo'), ':last-child'), 'last-child');
- Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), 'p:first-child'), 'first-child tag');
- Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), ':first-child'), 'first-child');
- Y.Assert.isFalse(Selector.test(Y.Dom.getFirstChild('demo'), ':only-of-type'), 'only-of-type false pos');
- Y.Assert.isFalse(Selector.test(Y.Dom.getFirstChild('demo'), ':first-child.last'), 'first-child class false pos');
- Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), ':first-child.first'), 'first-child class');
- Y.Assert.isFalse(Selector.test(Y.Dom.getFirstChild('demo'), ':only-child'), 'only-child');
- Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), ':first-of-type'), 'first-of-type');
- Y.Assert.isTrue(Selector.test(Y.Dom.getLastChild('demo'), ':last-of-type'), 'last-of-type');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), ':not(.foo)'), 'not(.foo)');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), ':not(p)'), 'not(p)');
- Y.Assert.isTrue(Selector.test(demoFirstChild, ':not(.last)'), 'not(.last)');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), ':contains(demo2)'), 'contains(demo2)');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo2'), ':not(:contains(demo2))'), ':not(:contains(demo2))');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), ':not(:contains(demo1))'), ':not(:contains(demo1))');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), ':contains(child of demo2)'), 'contains(child of demo2)');
- },
-
- testAttr: function() {
- Y.Assert.isTrue(Selector.test(Y.Dom.get('href-test'), '[href=foo.html]'), 'href=foo.html');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('href-test2'), '[href=http://foo.com/foo.html]'), 'href=http://foo.com/foo.html');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[title]'), 'title exists');
- Y.Assert.isFalse(Selector.test(Y.Dom.getFirstChild('demo'), '[title]'), 'title exists false pos');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id=demo]'), 'id equality');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id|=de]'), '[id|=de]');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id|=me]'), 'id starts with false pos');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id~=demo]'), 'id includes');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[title~=demo]'), 'title includes');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id!=demo]'), 'id negation');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id!=bar]'), 'id negation');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id^=de]'), 'id starts with');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id$=mo]'), 'id ends with');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id$=m]'), 'id ends with false pos');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id*=em]'), 'id substr');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id*=ex]'), 'id substr false pos');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id=demo][title~=demo]'), 'multiple attributes');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div[id=demo][title~=demo]'), 'tag & multiple attributes');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div[title=this is a demo]'), 'attribute with spaces');
-
- var img = document.createElement('img');
- img.className = 'testing';
- img.src = 'http://upload.wikimedia.org/wikipedia/en/3/3b/Gokukidadult.jpg';
- Y.Assert.isTrue(Selector.test(img, 'img[src=' + img.src + ']'), 'img[src=');
- Y.Assert.isTrue(Selector.test(img, 'img[src=' + img.src + '].testing'), 'img[src=...][class=testing]');
-
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), '[title="this is a \[demo\]"]'), '[title="this is a [demo]"]');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), '[id=demo2][title="this is a [demo]"]'), '[id=demo2][title="this is a [demo]"]');
- },
-
- testClass: function() {
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '.foo'), 'class match');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div.foo'), 'tag match');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), 'span.foo'), 'tag false positive');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '#demo.foo'), 'id match');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '.baz'), 'class false positive');
- Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), '.first.para'), 'multiple class match');
- Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), 'p.first.para'), 'tag & multiple class match');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '.foo.bar'), 'multiple class false pos');
- },
-
- testId: function() {
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '#demo'), 'id match');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div#demo'), 'tag match');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), 'div#dmo'), 'id false positive');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), 'span#demo'), 'tag false positive');
- },
-
- testTag: function() {
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div'), 'tag match');
- Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), 'span'), 'tag false positive');
- Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '*'), 'universal tag');
- },
-
- testOffDom: function() {
- var html = '<div class="foo"><p id="foo-p">i am <em class="em1">foo</em>, who are <em class="em2">you</em>?</p></div>';
- var node = document.createElement('div');
- node.innerHTML = html;
-
- Y.Assert.areEqual('foo', $('[class]', node, true).className, "$('[class]', node, true)");
- Y.Assert.areEqual('foo', $('.foo', node, true).className, "$('.foo', node, true)");
- Y.Assert.areEqual('foo', $('div.foo', node, true).className, "$('div.foo', node, true)");
- Y.Assert.areEqual('foo', $('> div', node, true).className, "$('> div', node, true)");
-
- Y.Assert.areEqual('P', $('> div > p', node, true).tagName, "$('> div > p', node, true)");
- Y.Assert.areEqual('P', $('#foo-p', node, true).tagName, "$('#foo-p', node, true)");
- Y.Assert.areEqual('P', $('div #foo-p', node, true).tagName, "$('div #foo-p', node, true)");
- Y.Assert.areEqual('P', $('div > #foo-p', node, true).tagName, "$('div > #foo-p', node, true)");
-
- Y.Assert.areEqual('em1', $('em', node, true).className, "$('em', node, true)");
- Y.Assert.areEqual('em1', $('.em1', node, true).className, "$('.em1', node, true)");
- Y.Assert.areEqual('em1', $('em[class]', node, true).className, "$('em[class]', node, true)");
- Y.Assert.areEqual('em1', $('.em1', node, true).className, "$('.em1', node, true)");
-
- Y.Assert.areEqual('em2', $('> div p > em + em', node, true).className, "$('> div p > em + em', node, true)");
- Y.Assert.areEqual('em2', $('> div > p > em + em', node, true).className, "$('> div > p > em + em', node, true)");
- Y.Assert.areEqual('em2', $('em + em', node, true).className, "$('em + em', node, true)");
- Y.Assert.areEqual('em2', $('em ~ em', node, true).className, "$('em ~ em', node, true)");
-
- Y.Assert.isNull($('+ em', node, true), "($('+ em', node, true)");
- Y.Assert.isNull($('~ em', node, true), "($('~ em', node, true)");
- }
-
- });
-
- suite.add(selectorQueryAll);
- suite.add(simpleTest);
- YAHOO.tool.TestRunner.add(suite);
- YAHOO.tool.TestRunner.run();
-};
-</script>
<style type="text/css">
#root-test > ol > li > ol li {
color: red;
@@ -325,5 +67,261 @@
<input type="button" value="foo">
</form>
<div class="Bar" id="class-bar"></div>
+<script>
+var Y = YAHOO.util;
+var logger = new YAHOO.tool.TestLogger(null, {height:'2000px'});
+var suite = new YAHOO.tool.TestSuite("Selector Suite");
+var Selector = Y.Selector;
+
+var $ = Selector.query;
+var demo = Y.Dom.get('demo');
+children = Y.Dom.getChildren(demo);
+var demoFirstChild = children[0];
+var demoLastChild = children[children.length - 1];
+
+var selectorQueryAll = new YAHOO.tool.TestCase({
+ name: 'Query All',
+
+ testTest: function() {
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), '[type=checkbox], button'), '[type=checkbox], button');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('test-lang-en-us'), '[lang|=en]'), '[lang|=en] (lang="en-us")');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('test-lang-en'), '[lang|=en]'), '[lang|=en] (lang="en")');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('test-lang-english'), '[lang|=en]'), '[lang|=en] (lang="en")');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('test-lang-none'), '[lang|=en]'), '[lang|=en] false pos');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('checkbox-unchecked'), 'for [type=checkbox]'), 'for [type=checkbox] false pos');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), 'form [type=checkbox]'), 'form [type=checkbox]');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('checkbox-unchecked'), 'for [type=checkbox]'), 'for [type=checkbox] false pos');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), '[type=checkbox], button'), '[type=checkbox], button');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), 'button, [type=checkbox]'), 'button, [type=checkbox]');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('checkbox-unchecked'), 'foo, button'), 'foo, button');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-checked'), '[type=checkbox]:checked'), 'type=checkbox:checked');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('radio-checked'), ':checked'), ':checked (radio)');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('radio-unchecked'), ':checked'), ':checked (radio) false pos');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('checkbox-unchecked'), '[type=checkbox]:checked'), 'type=checkbox:checked false pos');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('checkbox-unchecked'), '[type=checkbox]:not(:checked)'), 'type=checkbox:not(:checked)');
+ },
+
+ testRootQuery: function() {
+ var all = Y.Dom.get('nth-test').getElementsByTagName('li');
+ Y.ArrayAssert.itemsAreEqual(all, $('li', 'nth-test'), 'id as root');
+ Y.ArrayAssert.itemsAreEqual([], $('li', 'nth-tes'), 'id as root false pos');
+ Y.ArrayAssert.itemsAreEqual(all, $('li', Y.Dom.get('nth-test')), 'node as root');
+ Y.ArrayAssert.itemsAreEqual(all, $('#nth-test li', Y.Dom.get('root-test')), 'id selector w/root');
+ Y.ArrayAssert.itemsAreEqual([], $('#root-test li', Y.Dom.get('nth-test')), 'id selector w/root false pos');
+ Y.ArrayAssert.itemsAreEqual([], $('#root-test li', Y.Dom.get('nth-test')), 'id selector w/root false pos');
+ Y.ArrayAssert.itemsAreEqual([Y.Dom.get('nth-test')], $('> ol', 'root-test'), "$('> ol', 'root-test')");
+ Y.ArrayAssert.itemsAreEqual([Y.Dom.get('root-test')], $('+ div', 'empty'), "$('+ div', 'empty')");
+ },
+ testNthLastChild: function() {
+ var all = Y.Dom.get('nth-test').getElementsByTagName('li');
+ var odd = Y.Dom.getElementsByClassName('even', 'li', 'nth-test');
+ var even = Y.Dom.getElementsByClassName('odd', 'li', 'nth-test');
+ var four1 = Y.Dom.getElementsByClassName('last-four-1', 'li', 'nth-test');
+
+ Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-last-child(2n+1)'), '2n+1');
+ Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-last-child(odd)'), 'odd');
+ Y.ArrayAssert.itemsAreEqual(even, $('li:nth-last-child(2n+0)'), '2n+0');
+ Y.ArrayAssert.itemsAreEqual(even, $('li:nth-last-child(2n)'), '2n');
+ Y.ArrayAssert.itemsAreEqual(even, $('li:nth-last-child(even)'), 'even');
+ Y.ArrayAssert.itemsAreEqual(four1, $('li:nth-last-child(4n+1)'), '4n+1');
+ },
+ testNthType: function() {
+ var all = Y.Dom.get('nth-test').getElementsByTagName('li');
+ var odd = Y.Dom.getElementsByClassName('odd', 'li', 'nth-test');
+ var even = Y.Dom.getElementsByClassName('even', 'li', 'nth-test');
+ var three1 = Y.Dom.getElementsByClassName('three-1', 'li', 'nth-test');
+ var four1 = Y.Dom.getElementsByClassName('four-1', 'li', 'nth-test');
+ var four2 = Y.Dom.getElementsByClassName('four-2', 'li', 'nth-test');
+ var four3 = Y.Dom.getElementsByClassName('four-3', 'li', 'nth-test');
+ var four4 = Y.Dom.getElementsByClassName('four-4', 'li', 'nth-test');
+ Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-of-type(odd)'), 'odd');
+ },
+ testNthChild: function() {
+ var all = Y.Dom.get('nth-test').getElementsByTagName('li');
+ var odd = Y.Dom.getElementsByClassName('odd', 'li', 'nth-test');
+ var even = Y.Dom.getElementsByClassName('even', 'li', 'nth-test');
+ var three1 = Y.Dom.getElementsByClassName('three-1', 'li', 'nth-test');
+ var four1 = Y.Dom.getElementsByClassName('four-1', 'li', 'nth-test');
+ var four2 = Y.Dom.getElementsByClassName('four-2', 'li', 'nth-test');
+ var four3 = Y.Dom.getElementsByClassName('four-3', 'li', 'nth-test');
+ var four4 = Y.Dom.getElementsByClassName('four-4', 'li', 'nth-test');
+
+ Y.ArrayAssert.itemsAreEqual(even[1], $('li:nth-child(2)'), '2');
+ Y.ArrayAssert.itemsAreEqual(even[1], $('li:nth-child(0n+2)'), '0n+2');
+ Y.ArrayAssert.itemsAreEqual(three1, $('li:nth-child(3n+1)'), '3n+1');
+ Y.ArrayAssert.itemsAreEqual(all, $('li:nth-child(n+1)'), 'n+1');
+
+ // from http://www.w3.org/TR/css3-selectors/#nth-child-pseudo examples
+ Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-child(2n+1)'), '2n+1');
+ Y.ArrayAssert.itemsAreEqual(odd, $('li:nth-child(odd)'), 'odd');
+ Y.ArrayAssert.itemsAreEqual(even, $('li:nth-child(2n+0)'), '2n+0');
+ Y.ArrayAssert.itemsAreEqual(even, $('li:nth-child(2n)'), '2n');
+ Y.ArrayAssert.itemsAreEqual(even, $('li:nth-child(even)'), 'even');
+ Y.ArrayAssert.itemsAreEqual(four1, $('li:nth-child(4n+1)'), '4n+1');
+ Y.ArrayAssert.itemsAreEqual(four2, $('li:nth-child(4n+2)'), '4n+2');
+ Y.ArrayAssert.itemsAreEqual(four3, $('li:nth-child(4n+3)'), '4n+3');
+ Y.ArrayAssert.itemsAreEqual(four4, $('li:nth-child(4n+4)'), '4n+4');
+ Y.ArrayAssert.itemsAreEqual(even[0], $('li:nth-child(0n+1)'), '0n+1');
+ Y.ArrayAssert.itemsAreEqual(even[0], $('li:nth-child(1)'), '1');
+ Y.ArrayAssert.itemsAreEqual(all, $('li:nth-child(1n+0)'), '1n+0');
+ Y.ArrayAssert.itemsAreEqual(all, $('li:nth-child(n+0)'), 'n+0');
+
+ },
+
+ testSelector: function() {
+ Y.ArrayAssert.itemsAreEqual($('.not-button', 'test-inputs'), $('input:not([type=button])', 'test-inputs'), 'input[type=radio], input[type=checkbox] = input:not([type=button])');
+ Y.ArrayAssert.itemsAreEqual($('p, p'), document.getElementsByTagName('p'), 'p, p');
+ Y.ArrayAssert.itemsAreEqual($('p', null, true), document.getElementsByTagName('p')[0], 'p (firstOnly)');
+ Y.ArrayAssert.itemsAreEqual($('.Foo'), [], '.Foo');
+ Y.ArrayAssert.itemsAreEqual($('p ~ p'), [children[1], children[2]], 'p ~ p');
+ Y.ArrayAssert.itemsAreEqual([], $('#demo.bar p'), '#demo.bar p');
+ Y.ArrayAssert.itemsAreEqual(Y.Dom.get('demo').getElementsByTagName('p'), $('#demo.foo p'), '#demo.foo p');
+ Y.ArrayAssert.itemsAreEqual(Y.Dom.get('demo').getElementsByTagName('p'), $('.foo p'), '.foo p');
+ Y.ArrayAssert.itemsAreEqual(Y.Dom.get('demo').getElementsByTagName('p'), $('#demo p'), '#demo p');
+ Y.ArrayAssert.itemsAreEqual($('p > em'), [Y.Dom.getFirstChild('demo-first-child')], 'p > em');
+ Y.ArrayAssert.itemsAreEqual(Y.Dom.getElementsByClassName('para'), $('[class~=para]'), '[class=~para]');
+ Y.ArrayAssert.itemsAreEqual(document.body.getElementsByTagName('p'), $('body div p'), 'body div p');
+ Y.ArrayAssert.itemsAreEqual([], $('#demo .madeup'), '#demo .madeup');
+ Y.ArrayAssert.itemsAreEqual(Y.Dom.getElementsByClassName('para', 'p'), $('div .para'), 'div .para');
+ Y.ArrayAssert.itemsAreEqual(Y.Dom.getElementsByClassName('first', null, 'demo'), $('#demo .first'), '#demo .first');
+ Y.ArrayAssert.itemsAreEqual(document.getElementsByTagName('div'), $('div'), 'div');
+ Y.ArrayAssert.itemsAreEqual(document.body.getElementsByTagName('div'), $('body div'), 'body div');
+ Y.ArrayAssert.itemsAreEqual([demoFirstChild, Y.Dom.getNextSibling(demoFirstChild)], $('#demo p:not(.last)'), '#demo p:not(.last)');
+ Y.ArrayAssert.itemsAreEqual(Y.Dom.get('demo2').getElementsByTagName('div'), $('div:contains(child of demo2)', 'demo2'), 'div:contains:(child of demo2) ');
+ Y.ArrayAssert.itemsAreEqual([Y.Dom.get('class-bar')], $('.Bar'), '.Bar');
+ Y.ArrayAssert.itemsAreEqual([Y.Dom.get('root-test')], $('#empty + div'), "$('#empty + div')");
+ Y.Assert.areEqual(Y.Dom.get('empty'), $('div[custom]', null, true), "$('div[custom]', null, true)");
+ Y.ArrayAssert.itemsAreEqual([Y.Dom.get('test-obj')], $('object[custom]'), "$('object[custom]')");
+
+ Y.Assert.areEqual(Y.Dom.get('empty'), $('div[customAttr]', null, true), "$('div[customAttr]', null, true)");
+ Y.ArrayAssert.itemsAreEqual([Y.Dom.get('test-obj')], $('object[customAttr]'), "$('object[customAttr]')");
+
+ Y.Assert.areEqual(Y.Dom.get('href-test'), $('[href=foo.html]', null, true), '[href=foo.html]');
+ Y.Assert.areEqual(Y.Dom.get('href-test'), $('a[href=foo.html]', null, true), 'a[href=foo.html]');
+ Y.Assert.areEqual(Y.Dom.get('href-test2'), $('[href=http://foo.com/foo.html]', null, true), 'href=http://foo.com/foo.html');
+ Y.Assert.areEqual(Y.Dom.get('href-test3'), $('[href=http://foo.com/foo.html?foo=foo&bar=bar]', null, true), 'href=http://foo.com/foo.html?foo=foo&bar=baz');
+ Y.Assert.areEqual(Y.Dom.get('selector-script'), $('head > script[src=yui/selector/selector.js]', null, true), 'head > script[src=yui/selector/selector.js]');
+ Y.Assert.areEqual(Y.Dom.get('href-test'), $('a[href]', null, true), 'a[href]');
+ Y.Assert.areEqual(Y.Dom.get('href-test'), $('body [href]', null, true), 'body [href]');
+
+ Y.Assert.areEqual(Y.Dom.get('foo-script'), $('head > script[src=http://foo.com/bar.js]', null, true), 'head > script[src=http://foo.com/bar.js]');
+ }
+});
+
+var simpleTest = new YAHOO.tool.TestCase({
+ name: 'Simple Node Test',
+
+ testPseudo: function() {
+ //Y.Assert.isTrue(Selector.test(Y.Dom.get('empty'), ':empty'), 'empty');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo2'), ':empty'), 'empty false pos');
+ Y.Assert.isTrue(Selector.test(Y.Dom.getLastChild('demo'), ':last-child'), 'last-child');
+ Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), 'p:first-child'), 'first-child tag');
+ Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), ':first-child'), 'first-child');
+ Y.Assert.isFalse(Selector.test(Y.Dom.getFirstChild('demo'), ':only-of-type'), 'only-of-type false pos');
+ Y.Assert.isFalse(Selector.test(Y.Dom.getFirstChild('demo'), ':first-child.last'), 'first-child class false pos');
+ Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), ':first-child.first'), 'first-child class');
+ Y.Assert.isFalse(Selector.test(Y.Dom.getFirstChild('demo'), ':only-child'), 'only-child');
+ Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), ':first-of-type'), 'first-of-type');
+ Y.Assert.isTrue(Selector.test(Y.Dom.getLastChild('demo'), ':last-of-type'), 'last-of-type');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), ':not(.foo)'), 'not(.foo)');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), ':not(p)'), 'not(p)');
+ Y.Assert.isTrue(Selector.test(demoFirstChild, ':not(.last)'), 'not(.last)');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), ':contains(demo2)'), 'contains(demo2)');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo2'), ':not(:contains(demo2))'), ':not(:contains(demo2))');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), ':not(:contains(demo1))'), ':not(:contains(demo1))');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), ':contains(child of demo2)'), 'contains(child of demo2)');
+ },
+
+ testAttr: function() {
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('href-test'), '[href=foo.html]'), 'href=foo.html');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('href-test2'), '[href=http://foo.com/foo.html]'), 'href=http://foo.com/foo.html');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[title]'), 'title exists');
+ Y.Assert.isFalse(Selector.test(Y.Dom.getFirstChild('demo'), '[title]'), 'title exists false pos');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id=demo]'), 'id equality');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id|=de]'), '[id|=de]');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id|=me]'), 'id starts with false pos');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id~=demo]'), 'id includes');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[title~=demo]'), 'title includes');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id!=demo]'), 'id negation');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id!=bar]'), 'id negation');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id^=de]'), 'id starts with');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id$=mo]'), 'id ends with');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id$=m]'), 'id ends with false pos');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id*=em]'), 'id substr');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '[id*=ex]'), 'id substr false pos');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '[id=demo][title~=demo]'), 'multiple attributes');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div[id=demo][title~=demo]'), 'tag & multiple attributes');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div[title=this is a demo]'), 'attribute with spaces');
+
+ var img = document.createElement('img');
+ img.className = 'testing';
+ img.src = 'http://upload.wikimedia.org/wikipedia/en/3/3b/Gokukidadult.jpg';
+ Y.Assert.isTrue(Selector.test(img, 'img[src=' + img.src + ']'), 'img[src=');
+ Y.Assert.isTrue(Selector.test(img, 'img[src=' + img.src + '].testing'), 'img[src=...][class=testing]');
+
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), '[title="this is a \[demo\]"]'), '[title="this is a [demo]"]');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo2'), '[id=demo2][title="this is a [demo]"]'), '[id=demo2][title="this is a [demo]"]');
+ },
+
+ testClass: function() {
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '.foo'), 'class match');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div.foo'), 'tag match');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), 'span.foo'), 'tag false positive');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '#demo.foo'), 'id match');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '.baz'), 'class false positive');
+ Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), '.first.para'), 'multiple class match');
+ Y.Assert.isTrue(Selector.test(Y.Dom.getFirstChild('demo'), 'p.first.para'), 'tag & multiple class match');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), '.foo.bar'), 'multiple class false pos');
+ },
+
+ testId: function() {
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '#demo'), 'id match');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div#demo'), 'tag match');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), 'div#dmo'), 'id false positive');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), 'span#demo'), 'tag false positive');
+ },
+
+ testTag: function() {
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), 'div'), 'tag match');
+ Y.Assert.isFalse(Selector.test(Y.Dom.get('demo'), 'span'), 'tag false positive');
+ Y.Assert.isTrue(Selector.test(Y.Dom.get('demo'), '*'), 'universal tag');
+ },
+
+ testOffDom: function() {
+ var html = '<div class="foo"><p id="foo-p">i am <em class="em1">foo</em>, who are <em class="em2">you</em>?</p></div>';
+ var node = document.createElement('div');
+ node.innerHTML = html;
+
+ Y.Assert.areEqual('foo', $('[class]', node, true).className, "$('[class]', node, true)");
+ Y.Assert.areEqual('foo', $('.foo', node, true).className, "$('.foo', node, true)");
+ Y.Assert.areEqual('foo', $('div.foo', node, true).className, "$('div.foo', node, true)");
+ Y.Assert.areEqual('foo', $('> div', node, true).className, "$('> div', node, true)");
+
+ Y.Assert.areEqual('P', $('> div > p', node, true).tagName, "$('> div > p', node, true)");
+ Y.Assert.areEqual('P', $('#foo-p', node, true).tagName, "$('#foo-p', node, true)");
+ Y.Assert.areEqual('P', $('div #foo-p', node, true).tagName, "$('div #foo-p', node, true)");
+ Y.Assert.areEqual('P', $('div > #foo-p', node, true).tagName, "$('div > #foo-p', node, true)");
+
+ Y.Assert.areEqual('em1', $('em', node, true).className, "$('em', node, true)");
+ Y.Assert.areEqual('em1', $('.em1', node, true).className, "$('.em1', node, true)");
+ Y.Assert.areEqual('em1', $('em[class]', node, true).className, "$('em[class]', node, true)");
+ Y.Assert.areEqual('em1', $('.em1', node, true).className, "$('.em1', node, true)");
+
+ Y.Assert.areEqual('em2', $('> div p > em + em', node, true).className, "$('> div p > em + em', node, true)");
+ Y.Assert.areEqual('em2', $('> div > p > em + em', node, true).className, "$('> div > p > em + em', node, true)");
+ Y.Assert.areEqual('em2', $('em + em', node, true).className, "$('em + em', node, true)");
+ Y.Assert.areEqual('em2', $('em ~ em', node, true).className, "$('em ~ em', node, true)");
+
+ Y.Assert.isNull($('+ em', node, true), "($('+ em', node, true)");
+ Y.Assert.isNull($('~ em', node, true), "($('~ em', node, true)");
+ }
+
+});
+
+suite.add(selectorQueryAll);
+suite.add(simpleTest);
+YAHOO.tool.TestRunner.add(suite);
+YAHOO.tool.TestRunner.run();
+</script>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.