Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1588)

Side by Side Diff: chrome/test/data/extensions/api_test/automation/tests/tabs/queryselector.js

Issue 655273005: Implement AutomationNode.querySelector(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fix heap-use-after-free issue by not keeping a scoped_ptr to automation_api_helper in extension_hel… Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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(null, queryResult);
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 // paragraph inside "main" element - not the first <p> on the page
31 var p = main.firstChild();
32 function assertCorrectResult(queryResult) {
33 assertEq(queryResult, p);
34 chrome.test.succeed();
35 }
36 main.querySelector('p', assertCorrectResult);
37 },
38
39 // Demonstrates that a query for an element which is ignored for accessibility
40 // returns its nearest ancestor.
41 function testQuerySelectorForSpanInsideButtonReturnsButton() {
42 var okButton = rootNode.lastChild().firstChild();
43 function assertCorrectResult(queryResult) {
44 assertEq(queryResult, okButton);
45 chrome.test.succeed();
46 }
47 rootNode.querySelector('#span-in-button', assertCorrectResult);
48 },
49
50 // Demonstrates that querying from an anonymous node may have unexpected
51 // results.
52 function testQuerySelectorFromAnonymousGroup() {
53 var h1 = rootNode.firstChild().firstChild();
54 var group = rootNode.lastChild();
55 function assertCorrectResult(queryResult) {
56 assertEq(h1, queryResult);
57 chrome.test.succeed();
58 }
59 group.querySelector('h1', assertCorrectResult);
60 },
61
62 function testQuerySelectorFromRemovedNode() {
63 var group = rootNode.firstChild();
64 function assertCorrectResult(queryResult) {
65 assertEq(null, queryResult);
66 var errorMsg =
67 'querySelector sent on node which is no longer in the tree.';
68 assertEq(errorMsg, chrome.extension.lastError.message);
69 assertEq(errorMsg, chrome.runtime.lastError.message);
70
71 chrome.test.succeed();
72 }
73 function afterRemoveChild() {
74 group.querySelector('h1', assertCorrectResult);
75 }
76 chrome.tabs.executeScript(
77 { code: 'document.body.removeChild(document.body.firstElementChild)' },
78 afterRemoveChild);
79 }
80 ];
81
82 setUpAndRunTests(allTests, 'complex.html');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698