Index: tools/chrome_remote_control/chrome_remote_control/test_helpers.js |
diff --git a/tools/chrome_remote_control/chrome_remote_control/test_helpers.js b/tools/chrome_remote_control/chrome_remote_control/test_helpers.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0fb3e019b0085f9d37b0e15b8338879a17132f96 |
--- /dev/null |
+++ b/tools/chrome_remote_control/chrome_remote_control/test_helpers.js |
@@ -0,0 +1,37 @@ |
+// Copyright (c) 2012 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. |
+ |
+// Inject this script on any page to use test helpers, e.g., click a link which |
+// matches a given text. |
+ |
+(function() { |
+ function findElementWithText(element, text) { |
+ if (element.innerHTML == text) { |
+ return element; |
+ } |
+ for (var i in element.childNodes) { |
+ var found_element = findElementWithText(element.childNodes[i], text); |
+ if (found_element) { |
+ return found_element; |
+ } |
+ } |
+ return null; |
+ } |
+ |
+ function ClickLinkWithText(text) { |
+ var element = findElementWithText(document, text); |
+ if (element) { |
+ element.click(); |
+ return true; |
+ } |
+ return false; |
+ } |
+ |
+ function ReadyStateComplete() { |
+ return document.readyState == "complete"; |
+ } |
+ |
+ window.__ClickLinkWithText = ClickLinkWithText; |
+ window.__ReadyStateComplete = ReadyStateComplete; |
+})(); |