| 1 |
// Copyright 2008 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
goog.provide('goog.dom.iterTest'); |
| 16 |
goog.setTestOnly('goog.dom.iterTest'); |
| 17 |
|
| 18 |
goog.require('goog.dom'); |
| 19 |
goog.require('goog.dom.NodeType'); |
| 20 |
goog.require('goog.dom.iter.AncestorIterator'); |
| 21 |
goog.require('goog.dom.iter.ChildIterator'); |
| 22 |
goog.require('goog.dom.iter.SiblingIterator'); |
| 23 |
goog.require('goog.testing.dom'); |
| 24 |
goog.require('goog.testing.jsunit'); |
| 25 |
|
| 26 |
var test; |
| 27 |
var br; |
| 28 |
|
| 29 |
function setUpPage() { |
| 30 |
test = goog.dom.getElement('test'); |
| 31 |
br = goog.dom.getElement('br'); |
| 32 |
} |
| 33 |
|
| 34 |
function testNextSibling() { |
| 35 |
goog.testing.dom.assertNodesMatch( |
| 36 |
new goog.dom.iter.SiblingIterator(test.firstChild), ['#br', 'def']); |
| 37 |
} |
| 38 |
|
| 39 |
function testNextSiblingInclusive() { |
| 40 |
goog.testing.dom.assertNodesMatch( |
| 41 |
new goog.dom.iter.SiblingIterator(test.firstChild, true), |
| 42 |
['abc', '#br', 'def']); |
| 43 |
} |
| 44 |
|
| 45 |
function testPreviousSibling() { |
| 46 |
goog.testing.dom.assertNodesMatch( |
| 47 |
new goog.dom.iter.SiblingIterator(test.lastChild, false, true), |
| 48 |
['#br', 'abc']); |
| 49 |
} |
| 50 |
|
| 51 |
function testPreviousSiblingInclusive() { |
| 52 |
goog.testing.dom.assertNodesMatch( |
| 53 |
new goog.dom.iter.SiblingIterator(test.lastChild, true, true), |
| 54 |
['def', '#br', 'abc']); |
| 55 |
} |
| 56 |
|
| 57 |
function testChildIterator() { |
| 58 |
goog.testing.dom.assertNodesMatch( |
| 59 |
new goog.dom.iter.ChildIterator(test), ['abc', '#br', 'def']); |
| 60 |
} |
| 61 |
|
| 62 |
function testChildIteratorIndex() { |
| 63 |
goog.testing.dom.assertNodesMatch( |
| 64 |
new goog.dom.iter.ChildIterator(test, false, 1), ['#br', 'def']); |
| 65 |
} |
| 66 |
|
| 67 |
function testChildIteratorReverse() { |
| 68 |
goog.testing.dom.assertNodesMatch( |
| 69 |
new goog.dom.iter.ChildIterator(test, true), ['def', '#br', 'abc']); |
| 70 |
} |
| 71 |
|
| 72 |
function testEmptyChildIteratorReverse() { |
| 73 |
goog.testing.dom.assertNodesMatch( |
| 74 |
new goog.dom.iter.ChildIterator(br, true), []); |
| 75 |
} |
| 76 |
|
| 77 |
function testChildIteratorIndexReverse() { |
| 78 |
goog.testing.dom.assertNodesMatch( |
| 79 |
new goog.dom.iter.ChildIterator(test, true, 1), ['#br', 'abc']); |
| 80 |
} |
| 81 |
|
| 82 |
function testAncestorIterator() { |
| 83 |
goog.testing.dom.assertNodesMatch( |
| 84 |
new goog.dom.iter.AncestorIterator(br), |
| 85 |
['#test', '#body', '#html', goog.dom.NodeType.DOCUMENT]); |
| 86 |
} |
| 87 |
|
| 88 |
function testAncestorIteratorInclusive() { |
| 89 |
goog.testing.dom.assertNodesMatch( |
| 90 |
new goog.dom.iter.AncestorIterator(br, true), |
| 91 |
['#br', '#test', '#body', '#html', goog.dom.NodeType.DOCUMENT]); |
| 92 |
} |