Commit 02db51d7 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

FilesApp inline and remove test.util.sync.getElement_

Initially I planned to make the error message in getElement_ consistent
for the case where contentWindow.document does not exist and
contentWindow.document.querySelector(targetQuery) returns null.
In the end it made more sense to inline this into the 2 callers
that exist.

Bug: 852324
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: Ia5741cbb9628ada0839faca8d9d108f5535ba9f1
Reviewed-on: https://chromium-review.googlesource.com/1108238Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568927}
parent 49c72d35
...@@ -123,25 +123,6 @@ test.util.sync.closeWindow = function(appId) { ...@@ -123,25 +123,6 @@ test.util.sync.closeWindow = function(appId) {
return false; return false;
}; };
/**
* Gets the element specified by |targetQuery|.
*
* @param {Window} contentWindow Window to be used.
* @param {string} targetQuery Query to specify the element.
* @return {Element} If the specified element is not found, null is returned.
* @private
*/
test.util.sync.getElement_ = function(contentWindow, targetQuery) {
if (!contentWindow.document)
return null;
var target = contentWindow.document.querySelector(targetQuery);
if (!target)
console.error('Target element for ' + targetQuery + ' not found.');
return target;
};
/** /**
* Gets total Javascript error count from background page and each app window. * Gets total Javascript error count from background page and each app window.
* @return {number} Error count. * @return {number} Error count.
...@@ -314,18 +295,19 @@ test.util.sync.inputText = function(contentWindow, query, text) { ...@@ -314,18 +295,19 @@ test.util.sync.inputText = function(contentWindow, query, text) {
* @return {boolean} True if the event is sent to the target, false otherwise. * @return {boolean} True if the event is sent to the target, false otherwise.
*/ */
test.util.sync.sendEvent = function(contentWindow, targetQuery, event) { test.util.sync.sendEvent = function(contentWindow, targetQuery, event) {
var target; if (!contentWindow.document)
return false;
let target;
if (targetQuery === null) { if (targetQuery === null) {
target = contentWindow.document.activeElement; target = contentWindow.document.activeElement;
} else if (typeof targetQuery === 'string') { } else if (typeof targetQuery === 'string') {
target = test.util.sync.getElement_(contentWindow, targetQuery); target = contentWindow.document.querySelector(targetQuery);
} else if (Array.isArray(targetQuery)) { } else if (Array.isArray(targetQuery)) {
if (contentWindow.document) { let elems = test.util.sync.deepQuerySelectorAll_(
var elems = test.util.sync.deepQuerySelectorAll_( contentWindow.document, targetQuery);
contentWindow.document, targetQuery); if (elems.length > 0)
if (elems.length > 0) target = elems[0];
target = elems[0];
}
} }
if (!target) if (!target)
...@@ -500,7 +482,9 @@ test.util.sync.fakeMouseUp = function(contentWindow, targetQuery) { ...@@ -500,7 +482,9 @@ test.util.sync.fakeMouseUp = function(contentWindow, targetQuery) {
* otherwise. * otherwise.
*/ */
test.util.sync.focus = function(contentWindow, targetQuery) { test.util.sync.focus = function(contentWindow, targetQuery) {
var target = test.util.sync.getElement_(contentWindow, targetQuery); var target = contentWindow.document &&
contentWindow.document.querySelector(targetQuery);
if (!target) if (!target)
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment