Bug 1128287 - Intermittent testFindInPage | testFindInPage.js r=margaret

Rely on multiple ends of find in page promises (Repaint and Java callback)

--HG--
extra : rebase_source : c79fe8b9eb9ca5608e99d9a0f82f981a8a9bec19
This commit is contained in:
Robin Ricard 2015-02-12 09:21:33 -08:00
parent 6f4b98405d
commit 22c04d675b
2 changed files with 21 additions and 13 deletions

View File

@ -11,11 +11,12 @@ import org.mozilla.gecko.Element;
import org.mozilla.gecko.R;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.util.GeckoEventListener;
import org.json.JSONObject;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.NativeEventListener;
import org.mozilla.gecko.util.NativeJSObject;
public class testFindInPage extends JavascriptTest implements GeckoEventListener {
public class testFindInPage extends JavascriptTest implements NativeEventListener {
private static final int WAIT_FOR_TEST = 3000;
protected Element next, close;
@ -24,14 +25,15 @@ public class testFindInPage extends JavascriptTest implements GeckoEventListener
}
@Override
public void handleMessage(String event, final JSONObject message) {
public void handleMessage(final String event, final NativeJSObject message,
final EventCallback callback) {
if (event.equals("Test:FindInPage")) {
try {
final String text = message.getString("text");
final int nrOfMatches = Integer.parseInt(message.getString("nrOfMatches"));
final int nrOfMatches = message.getInt("nrOfMatches");
findText(text, nrOfMatches);
} catch (Exception e) {
fFail("Can't extract find query from JSON");
callback.sendError("Can't extract find query from JSON :" + e.toString());
}
}
@ -39,9 +41,11 @@ public class testFindInPage extends JavascriptTest implements GeckoEventListener
try {
close.click();
} catch (Exception e) {
fFail("FindInPage prompt not opened");
callback.sendError("FindInPage prompt not opened");
}
}
callback.sendSuccess("done");
}
@Override

View File

@ -35,17 +35,21 @@ function openTabWithUrl(url) {
}
function findInPage(browser, text, nrOfMatches) {
let repaintPromise = promiseBrowserEvent(browser, "MozAfterPaint");
do_print("Send findInPageMessage: " + text + " nth: " + nrOfMatches);
Messaging.sendRequest({ type: "Test:FindInPage", text: text, nrOfMatches: nrOfMatches });
return repaintPromise;
let messagePromise = Messaging.sendRequestForResult({
type: "Test:FindInPage",
text: text,
nrOfMatches: nrOfMatches
});
let repaintPromise = promiseBrowserEvent(browser, "MozAfterPaint");
return Promise.all([messagePromise, repaintPromise]);
}
function closeFindInPage(browser) {
let repaintPromise = promiseBrowserEvent(browser, "MozAfterPaint");
do_print("Send closeFindInPageMessage");
Messaging.sendRequest({ type: "Test:CloseFindInPage" });
return repaintPromise;
let messagePromise = Messaging.sendRequestForResult({ type: "Test:CloseFindInPage" });
let repaintPromise = promiseBrowserEvent(browser, "MozAfterPaint");
return Promise.all([messagePromise, repaintPromise]);
}
function assertSelection(document, expectedSelection = false, expectedAnchorText = false) {