| Index: chrome/test/data/webui/inspect_ui_test.js
|
| diff --git a/chrome/test/data/webui/inspect_ui_test.js b/chrome/test/data/webui/inspect_ui_test.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0b7d92748f01374feb9d3fd012c66bcb84616fc4
|
| --- /dev/null
|
| +++ b/chrome/test/data/webui/inspect_ui_test.js
|
| @@ -0,0 +1,75 @@
|
| +// 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.
|
| +
|
| +function waitForElements(selector, populateFunctionName, callback) {
|
| + var elements = document.querySelectorAll(selector);
|
| + if (elements.length) {
|
| + callback(elements);
|
| + return;
|
| + }
|
| + var originalFunction = window[populateFunctionName];
|
| + expectNotEquals(undefined, originalFunction);
|
| + expectEquals(undefined, originalFunction.__isSniffer);
|
| + var interceptFunction = function() {
|
| + originalFunction.apply(window, arguments);
|
| + var elements = document.querySelectorAll(selector);
|
| + if (elements.length) {
|
| + window[populateFunctionName] = originalFunction;
|
| + callback(elements);
|
| + }
|
| + };
|
| + interceptFunction.__isSniffer = true;
|
| + window[populateFunctionName] = interceptFunction;
|
| +}
|
| +
|
| +function findByContentSubstring(elements, content, childSelector) {
|
| + return Array.prototype.filter.call(elements, function(element) {
|
| + if (childSelector)
|
| + element = element.querySelector(childSelector);
|
| + return element && element.textContent.indexOf(content) >= 0;
|
| + })[0];
|
| +}
|
| +
|
| +function testTargetListed(sectionSelector, populateFunctionName, url) {
|
| + waitForElements(
|
| + sectionSelector + ' .row',
|
| + populateFunctionName,
|
| + function(elements) {
|
| + var urlElement = findByContentSubstring(elements, url, '.url');
|
| + expectNotEquals(undefined, urlElement);
|
| + testDone();
|
| + });
|
| +}
|
| +
|
| +function testAdbTargetsListed() {
|
| + waitForElements('.device', 'populateRemoteTargets', function(devices) {
|
| + expectEquals(2, devices.length);
|
| +
|
| + var offlineDevice = findByContentSubstring(
|
| + devices, 'Offline', '.device-name');
|
| + expectNotEquals(undefined, offlineDevice);
|
| +
|
| + var onlineDevice = findByContentSubstring(
|
| + devices, 'Nexus 6', '.device-name');
|
| + expectNotEquals(undefined, onlineDevice);
|
| +
|
| + var browsers = onlineDevice.querySelectorAll('.browser');
|
| + expectEquals(4, browsers.length);
|
| +
|
| + var chromeBrowser = findByContentSubstring(
|
| + browsers, 'Chrome (32.0.1679.0)', '.browser-name');
|
| + expectNotEquals(undefined, chromeBrowser);
|
| +
|
| + var chromePages = chromeBrowser.querySelectorAll('.pages');
|
| + var chromiumPage = findByContentSubstring(
|
| + chromePages, 'http://www.chromium.org/', '.url');
|
| + expectNotEquals(undefined, chromiumPage);
|
| +
|
| + var webView = findByContentSubstring(
|
| + browsers, 'WebView in com.sample.feed (4.0)', '.browser-name');
|
| + expectNotEquals(undefined, webView);
|
| +
|
| + testDone();
|
| + });
|
| +}
|
|
|