Revision control

1
<!DOCTYPE html>
2
<script src="../resources/magnitude-perf.js"></script>
3
<body>
4
<script>
5
6
var doc, node, expected;
7
8
function appendDeepTree(magnitude)
9
{
10
for (var i = 0; i < magnitude; i++) {
11
node = node.appendChild(doc.createElement('div'));
12
}
13
}
14
15
16
// Tests that contains is O(1) for document where the test |node| is in the document.
17
18
function setup1(magnitude)
19
{
20
node = document.body;
21
doc = document;
22
expected = true;
23
appendDeepTree(magnitude);
24
}
25
26
// Tests that contains is O(1) for document when the test |node| is not in the document.
27
28
function setup2(magnitude)
29
{
30
node = document.createElement('div'); // Not added to the document
31
doc = document;
32
expected = false;
33
appendDeepTree(magnitude);
34
}
35
36
// Tests that contains is O(1) for document when the test |node| is in a different document.
37
38
function setup3(magnitude)
39
{
40
var iframe = document.body.appendChild(document.createElement('iframe'));
41
doc = iframe.contentDocument;
42
node = doc.body; // Different document.
43
expected = false;
44
appendDeepTree(magnitude);
45
}
46
47
function test(magnitude)
48
{
49
var actual = document.contains(node);
50
if (actual !== expected)
51
throw 'Unexpected return value: ' + actual + ', expected: ' + expected;
52
}
53
54
Magnitude.description('Tests that document.contains is O(1).');
55
Magnitude.run(setup1, test, Magnitude.CONSTANT);
56
Magnitude.run(setup2, test, Magnitude.CONSTANT);
57
Magnitude.run(setup3, test, Magnitude.CONSTANT);
58
59
</script>
60
</body>