Bug 786032 - Make search timeouts fail successfully, r=mdas, DONTBUILD because NPOTB

This commit is contained in:
Jonathan Griffin 2012-08-27 13:50:34 -07:00
parent 4c2952b2f1
commit 81585f8e62
4 changed files with 28 additions and 19 deletions

View File

@ -116,6 +116,9 @@ 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, "id", "I'm not on the page")
self.marionette.set_search_timeout(0)
self.assertRaises(NoSuchElementException, self.marionette.find_element, "id", "I'm not on the page")
def test_timeout(self):
@ -177,8 +180,10 @@ class TestElementsChrome(MarionetteTestCase):
self.assertEqual(el, found_el)
def test_not_found(self):
self.marionette.set_search_timeout(1000)
self.assertRaises(NoSuchElementException, self.marionette.find_element, "id", "I'm not on the page")
self.marionette.set_search_timeout(0)
self.assertRaises(NoSuchElementException, self.marionette.find_element, "id", "I'm not on the page")
def test_timeout(self):
self.assertRaises(NoSuchElementException, self.marionette.find_element, "id", "myid")

View File

@ -981,8 +981,9 @@ MarionetteDriverActor.prototype = {
if (this.context == "chrome") {
let id;
try {
let notify = this.sendResponse.bind(this);
id = this.curBrowser.elementManager.find(this.getCurrentWindow(),aRequest, notify, false);
let on_success = this.sendResponse.bind(this);
let on_error = this.sendError.bind(this);
id = this.curBrowser.elementManager.find(this.getCurrentWindow(),aRequest, on_success, on_error, false);
}
catch (e) {
this.sendError(e.message, e.code, e.stack);
@ -1005,8 +1006,9 @@ MarionetteDriverActor.prototype = {
if (this.context == "chrome") {
let id;
try {
let notify = this.sendResponse.bind(this);
id = this.curBrowser.elementManager.find(this.getCurrentWindow(), aRequest, notify, true);
let on_success = this.sendResponse.bind(this);
let on_error = this.sendError.bind(this);
id = this.curBrowser.elementManager.find(this.getCurrentWindow(), aRequest, on_success, on_error, true);
}
catch (e) {
this.sendError(e.message, e.code, e.stack);

View File

@ -235,16 +235,18 @@ ElementManager.prototype = {
* as the start node instead of the document root
* If this object has a 'time' member, this number will be
* used to see if we have hit the search timelimit.
* @param function notify
* The notification callback used when we are returning
* @param function on_success
* The notification callback used when we are returning successfully.
* @param function on_error
The callback to invoke when an error occurs.
* @param boolean all
* If true, all found elements will be returned.
* If false, only the first element will be returned.
*
* @return nsIDOMElement or list of nsIDOMElements
* Returns the element(s) by calling the notify function.
* Returns the element(s) by calling the on_success function.
*/
find: function EM_find(win, values, notify, all) {
find: function EM_find(win, values, on_success, on_error, all) {
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) {
@ -258,19 +260,19 @@ ElementManager.prototype = {
for (let i = 0 ; i < found.length ; i++) {
ids.push(this.addToKnownElements(found[i]));
}
notify(ids);
on_success(ids);
}
else {
let id = this.addToKnownElements(found);
notify(id);
on_success(id);
}
return;
} else {
if (this.searchTimeout == 0 || new Date().getTime() - startTime > this.searchTimeout) {
throw new ElementException("Unable to locate element: " + values.value, 7, null);
on_error("Unable to locate element: " + values.value, 7, null);
} else {
values.time = startTime;
this.timer.initWithCallback(this.find.bind(this, win, values, notify, all), 100, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
this.timer.initWithCallback(this.find.bind(this, win, values, on_success, on_error, all), 100, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
}
}
},

View File

@ -562,10 +562,10 @@ function refresh(msg) {
* Find an element in the document using requested search strategy
*/
function findElementContent(msg) {
let id;
try {
let notify = function(id) { sendResponse({value:id});};
id = elementManager.find(curWindow, msg.json, notify, false);
let on_success = function(id) { sendResponse({value:id}); };
let on_error = sendError;
elementManager.find(curWindow, msg.json, on_success, on_error, false);
}
catch (e) {
sendError(e.message, e.code, e.stack);
@ -576,10 +576,10 @@ function findElementContent(msg) {
* Find elements in the document using requested search strategy
*/
function findElementsContent(msg) {
let id;
try {
let notify = function(id) { sendResponse({value:id});};
id = elementManager.find(curWindow, msg.json, notify, true);
let on_success = function(id) { sendResponse({value:id}); };
let on_error = sendError;
elementManager.find(curWindow, msg.json, on_success, on_error, true);
}
catch (e) {
sendError(e.message, e.code, e.stack);