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

Unified Diff: chrome/test/pyautolib/dom_mutation_observer.js

Issue 10095018: Added a new PyAuto method WaitForDomNode() which allows tests to block until a specified node exist… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created a new exception class JavascriptRuntimeException in place of RuntimeException. Created 8 years, 8 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
« no previous file with comments | « chrome/test/functional/apptest.py ('k') | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/pyautolib/dom_mutation_observer.js
diff --git a/chrome/test/pyautolib/dom_mutation_observer.js b/chrome/test/pyautolib/dom_mutation_observer.js
index 45a4b3d524780c5f6fec4ac76a001e147c17eaa7..4588487c602c23732fab82e44ededdaa3992c089 100644
--- a/chrome/test/pyautolib/dom_mutation_observer.js
+++ b/chrome/test/pyautolib/dom_mutation_observer.js
@@ -11,7 +11,7 @@
* Args:
* automation_id: Automation id used to route DomAutomationController messages.
* observer_id: Id of the observer who will be receiving the messages.
- * observer_type: One of 'add', 'remove', or 'change'.
+ * observer_type: One of 'add', 'remove', 'change', or 'exists'.
* pattern: Pattern used to select the DOM node of interest.
* ptype: Type of |pattern|, either 'xpath' or 'css'.
* expected_value: If not null, regular expression matching text contents
@@ -102,6 +102,22 @@ function(automation_id, observer_id, observer_type, pattern, ptype,
}
}
+ /* Calls raiseEvent if the expected node exists in the DOM.
+ *
+ * Args:
+ * mutations: A list of mutation objects.
+ * observer: The mutation observer object associated with this callback.
+ */
+ function existsNodeCallback(mutations, observer) {
+ var node = firstMatchingNode(pattern, ptype);
+ if (node && nodeValueTextEquals(node, expected_value)) {
+ raiseEvent();
+ observer.disconnect();
+ delete observer;
+ return;
+ }
+ }
+
/* Return true if the xpath matches the given node.
*
* Args:
@@ -184,7 +200,8 @@ function(automation_id, observer_id, observer_type, pattern, ptype,
*/
function observeAdd(pattern, ptype) {
window.domAutomationController.send("success");
- if (firstMatchingNode(pattern, ptype)) {
+ var node = firstMatchingNode(pattern, ptype);
+ if (node && nodeValueTextEquals(node, expected_value)) {
raiseEvent();
console.log("Matching node in DOM, assuming it was previously added.");
return;
@@ -243,6 +260,27 @@ function(automation_id, observer_id, observer_type, pattern, ptype,
subtree: true});
}
+ /* Watch for a node matching pattern to exist in the DOM.
+ *
+ * Args:
+ * pattern: A string in the format of either an XPath or CSS Selector.
+ * ptype: Either 'xpath' or 'css'.
+ */
+ function observeExists(pattern, ptype) {
+ window.domAutomationController.send("success");
+ var node = firstMatchingNode(pattern, ptype);
+ if (node && nodeValueTextEquals(node, expected_value)) {
+ raiseEvent();
+ console.log("Node already exists in DOM.");
+ return;
+ }
+
+ var obs = new WebKitMutationObserver(existsNodeCallback);
+ obs.observe(document,
+ { childList: true,
+ attributes: true,
+ subtree: true});
+ }
/* Interpret arguments and launch the requested observer function. */
var observer;
@@ -256,6 +294,9 @@ function(automation_id, observer_id, observer_type, pattern, ptype,
case "change":
observeChange(pattern, ptype);
break;
+ case "exists":
+ observeExists(pattern, ptype);
+ break;
}
console.log("MutationObserver javscript injection completed.")
« no previous file with comments | « chrome/test/functional/apptest.py ('k') | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698