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

Unified 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: Address review comments and flesh out error and edge case handling Created 6 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/automation/tests/tabs/queryselector.js
diff --git a/chrome/test/data/extensions/api_test/automation/tests/tabs/queryselector.js b/chrome/test/data/extensions/api_test/automation/tests/tabs/queryselector.js
new file mode 100644
index 0000000000000000000000000000000000000000..b9078f132f7c527ef67b49cce1a72c7f860e82e6
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/automation/tests/tabs/queryselector.js
@@ -0,0 +1,55 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var allTests = [
dmazzoni 2014/10/30 23:32:42 How about a test where the query string doesn't re
aboxhall 2014/10/31 20:32:22 Good idea, done.
+ // Basic query from root node.
+ function testQuerySelector() {
+ var cancelButton = rootNode.lastChild().lastChild();
+ function assertCorrectResult(queryResult) {
Devlin 2014/10/30 23:26:53 I'm not too passionate about it, but is there a re
aboxhall 2014/10/31 20:32:22 No real reason here, but I'm in the habit of doing
+ assertEq(queryResult, cancelButton);
+ chrome.test.succeed();
+ }
+ rootNode.querySelector('body > button:nth-of-type(2)',
+ assertCorrectResult);
+ },
+
+ // Demonstrates that a query from a non-root element queries inside that
+ // element.
+ function testQuerySelectorFromMain() {
+ var main = rootNode.children()[1];
+ console.log('main: ' + main.toString());
+ // paragraph inside "main" element - not the first <p> on the page
+ var p = main.firstChild();
+ function assertCorrectResult(queryResult) {
+ assertEq(queryResult, p);
+ chrome.test.succeed();
+ }
+ main.querySelector('p', assertCorrectResult);
+ },
+
+ // Demonstrates that a query for an element which is ignored for accessibility
+ // returns its nearest ancestor.
+ function testQuerySelectorForSpanInsideButtonReturnsButton() {
+ var okButton = rootNode.lastChild().firstChild();
+ function assertCorrectResult(queryResult) {
+ assertEq(queryResult, okButton);
+ chrome.test.succeed();
+ }
+ rootNode.querySelector('#span-in-button', assertCorrectResult);
+ },
+
+ // Demonstrates that querying from an anonymous node may have unexpected
+ // results.
+ function testQuerySelectorFromAnonymousGroup() {
+ var h1 = rootNode.firstChild().firstChild();
+ var group = rootNode.lastChild();
+ function assertCorrectResult(queryResult) {
+ assertEq(queryResult, h1);
+ chrome.test.succeed();
+ }
+ group.querySelector('h1', assertCorrectResult);
+ }
+];
+
+setUpAndRunTests(allTests, 'complex.html');

Powered by Google App Engine
This is Rietveld 408576698