2 <script src="../resources/magnitude-perf.js"></script>
6 var doc, node, expected;
8 function appendDeepTree(magnitude)
10 for (var i = 0; i < magnitude; i++) {
11 node = node.appendChild(doc.createElement('div'));
16 // Tests that contains is O(1) for document where the test |node| is in the document.
18 function setup1(magnitude)
23 appendDeepTree(magnitude);
26 // Tests that contains is O(1) for document when the test |node| is not in the document.
28 function setup2(magnitude)
30 node = document.createElement('div'); // Not added to the document
33 appendDeepTree(magnitude);
36 // Tests that contains is O(1) for document when the test |node| is in a different document.
38 function setup3(magnitude)
40 var iframe = document.body.appendChild(document.createElement('iframe'));
41 doc = iframe.contentDocument;
42 node = doc.body; // Different document.
44 appendDeepTree(magnitude);
47 function test(magnitude)
49 var actual = document.contains(node);
50 if (actual !== expected)
51 throw 'Unexpected return value: ' + actual + ', expected: ' + expected;
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);