OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 var allTests = [ | |
6 // Basic query from root node. | |
7 function testQuerySelector() { | |
8 var cancelButton = rootNode.lastChild().lastChild(); | |
9 function assertCorrectResult(queryResult) { | |
10 assertEq(queryResult, cancelButton); | |
11 chrome.test.succeed(); | |
12 } | |
13 rootNode.querySelector('body > button:nth-of-type(2)', | |
14 assertCorrectResult); | |
15 }, | |
16 | |
17 function testQuerySelectorNoMatch() { | |
18 function assertCorrectResult(queryResult) { | |
19 assertEq(queryResult, null); | |
20 chrome.test.succeed(); | |
21 } | |
22 rootNode.querySelector('#nonexistent', | |
23 assertCorrectResult); | |
24 }, | |
25 | |
26 // Demonstrates that a query from a non-root element queries inside that | |
27 // element. | |
28 function testQuerySelectorFromMain() { | |
29 var main = rootNode.children()[1]; | |
30 console.log('main: ' + main.toString()); | |
Devlin
2014/10/31 22:11:28
reminder: Remove these logs.
aboxhall
2014/10/31 23:06:48
Done.
| |
31 // paragraph inside "main" element - not the first <p> on the page | |
32 var p = main.firstChild(); | |
33 function assertCorrectResult(queryResult) { | |
34 assertEq(queryResult, p); | |
35 chrome.test.succeed(); | |
36 } | |
37 main.querySelector('p', assertCorrectResult); | |
38 }, | |
39 | |
40 // Demonstrates that a query for an element which is ignored for accessibility | |
41 // returns its nearest ancestor. | |
42 function testQuerySelectorForSpanInsideButtonReturnsButton() { | |
43 var okButton = rootNode.lastChild().firstChild(); | |
44 function assertCorrectResult(queryResult) { | |
45 assertEq(queryResult, okButton); | |
46 chrome.test.succeed(); | |
47 } | |
48 rootNode.querySelector('#span-in-button', assertCorrectResult); | |
49 }, | |
50 | |
51 // Demonstrates that querying from an anonymous node may have unexpected | |
52 // results. | |
53 function testQuerySelectorFromAnonymousGroup() { | |
54 var h1 = rootNode.firstChild().firstChild(); | |
55 var group = rootNode.lastChild(); | |
56 function assertCorrectResult(queryResult) { | |
57 assertEq(h1, queryResult); | |
58 chrome.test.succeed(); | |
59 } | |
60 group.querySelector('h1', assertCorrectResult); | |
61 }, | |
62 | |
63 function testQuerySelectorFromRemovedNode() { | |
64 var group = rootNode.firstChild(); | |
65 function assertCorrectResult(queryResult) { | |
66 assertEq(null, queryResult); | |
67 var errorMsg = | |
68 'querySelector sent on node which is no longer in the tree'; | |
69 assertEq(errorMsg, chrome.extension.lastError.message); | |
70 assertEq(errorMsg, chrome.runtime.lastError.message); | |
71 | |
72 chrome.test.succeed(); | |
73 } | |
74 function afterRemoveChild() { | |
75 group.querySelector('h1', assertCorrectResult); | |
76 } | |
77 chrome.tabs.executeScript( | |
78 { code: 'document.body.removeChild(document.body.firstElementChild)' }, | |
79 afterRemoveChild); | |
80 } | |
81 ]; | |
82 | |
83 setUpAndRunTests(allTests, 'complex.html'); | |
OLD | NEW |