Bug 1084412 - marionette.findElements returns immediately when searchTimeout is set, r=AutomatedTester
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 21 Oct 2014 08:40:24 -0400
changeset 211418 56e2d9aff6370256db891961724dea070b89d2ff
parent 211417 949644ee3fdd697d976e99b5866ed45df4196daf
child 211419 b468088751c1ac8fe1dbff9a55a1f6da8b670bd9
push id50707
push userahalberstadt@mozilla.com
push dateTue, 21 Oct 2014 13:01:43 +0000
treeherdermozilla-inbound@56e2d9aff637 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersAutomatedTester
bugs1084412
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1084412 - marionette.findElements returns immediately when searchTimeout is set, r=AutomatedTester
testing/marionette/client/marionette/tests/unit/test_findelement.py
testing/marionette/marionette-elements.js
--- a/testing/marionette/client/marionette/tests/unit/test_findelement.py
+++ b/testing/marionette/client/marionette/tests/unit/test_findelement.py
@@ -117,25 +117,34 @@ class TestElements(MarionetteTestCase):
     def test_not_found(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         self.marionette.set_search_timeout(1000)
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
         self.marionette.set_search_timeout(0)
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
 
-    def test_timeout(self):
+    def test_timeout_element(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         button = self.marionette.find_element("id", "createDivButton")
         button.click()
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "newDiv")
         self.assertTrue(True, self.marionette.set_search_timeout(8000))
         self.assertEqual(HTMLElement, type(self.marionette.find_element(By.ID, "newDiv")))
 
+    def test_timeout_elements(self):
+        test_html = self.marionette.absolute_url("test.html")
+        self.marionette.navigate(test_html)
+        button = self.marionette.find_element("id", "createDivButton")
+        button.click()
+        self.assertEqual(len(self.marionette.find_elements(By.ID, "newDiv")), 0)
+        self.assertTrue(True, self.marionette.set_search_timeout(8000))
+        self.assertEqual(len(self.marionette.find_elements(By.ID, "newDiv")), 1)
+
     def test_css_selector_scope_doesnt_start_at_rootnode(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         el = self.marionette.find_element(By.ID, "mozLink")
         nav_el = self.marionette.find_element(By.ID, "testDiv")
         found_els = nav_el.find_elements(By.CSS_SELECTOR, "a")
         self.assertFalse(el.id in [found_el.id for found_el in found_els])
 
--- a/testing/marionette/marionette-elements.js
+++ b/testing/marionette/marionette-elements.js
@@ -288,42 +288,46 @@ ElementManager.prototype = {
     let startTime = values.time ? values.time : new Date().getTime();
     let startNode = (values.element != undefined) ?
                     this.getKnownElement(values.element, win) : win.document;
     if (this.elementStrategies.indexOf(values.using) < 0) {
       throw new ElementException("No such strategy.", 17, null);
     }
     let found = all ? this.findElements(values.using, values.value, win.document, startNode) :
                       this.findElement(values.using, values.value, win.document, startNode);
-    if (found) {
+    if (found == null || found.length <= 0) {
+      if (!searchTimeout || new Date().getTime() - startTime > searchTimeout) {
+        if (all) {
+          on_success([], command_id); // findElements should return empty list
+        } else {
+          on_error("Unable to locate element: " + values.value, 7, null, command_id);
+        }
+      } else {
+        values.time = startTime;
+        this.timer.initWithCallback(this.find.bind(this, win, values,
+                                                   searchTimeout,
+                                                   on_success, on_error, all,
+                                                   command_id),
+                                    100,
+                                    Components.interfaces.nsITimer.TYPE_ONE_SHOT);
+      }
+    } else {
       let type = Object.prototype.toString.call(found);
       if ((type == '[object Array]') || (type == '[object HTMLCollection]') || (type == '[object NodeList]')) {
         let ids = []
         for (let i = 0 ; i < found.length ; i++) {
           ids.push(this.addToKnownElements(found[i]));
         }
         on_success(ids, command_id);
       }
       else {
         let id = this.addToKnownElements(found);
         on_success({'ELEMENT':id}, command_id);
       }
       return;
-    } else {
-      if (!searchTimeout || new Date().getTime() - startTime > searchTimeout) {
-        on_error("Unable to locate element: " + values.value, 7, null, command_id);
-      } else {
-        values.time = startTime;
-        this.timer.initWithCallback(this.find.bind(this, win, values,
-                                                   searchTimeout,
-                                                   on_success, on_error, all,
-                                                   command_id),
-                                    100,
-                                    Components.interfaces.nsITimer.TYPE_ONE_SHOT);
-      }
     }
   },
 
   /**
    * Find a value by XPATH
    *
    * @param nsIDOMElement root
    *        Document root