зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1015395 - Make testFindInPage more robust. r=margaret
Use a JS based test relying on document.getSelection Use promises+generators to wait during UI changes done by Java
This commit is contained in:
Родитель
f85f9479d2
Коммит
0f04c67997
|
@ -35,7 +35,9 @@ skip-if = android_version == "10" || processor == "x86"
|
|||
[testDistribution]
|
||||
[testDoorHanger]
|
||||
[testFilterOpenTab]
|
||||
# [testFindInPage] # see bug 975155, bug 1014708
|
||||
[testFindInPage]
|
||||
# disabled on 2.3
|
||||
skip-if = android_version == "10"
|
||||
[testFlingCorrectness]
|
||||
# disabled on x86 only; bug 927476
|
||||
skip-if = processor == "x86"
|
||||
|
|
|
@ -5,16 +5,14 @@
|
|||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<div style='float: left; width: 100%; height: 500px; margin: 0; padding: 0; border: none; background-color: rgb(250,0,0)'> </div>
|
||||
<div style='float: left; width: 10%; height: 500px; margin: 0; padding: 0; border: none; background-color: rgb(250,0,0)'> </div>
|
||||
<p>Text taken from Wikipedia.org</p>
|
||||
<p> <b>Will be searching for this string:</b> Robocop </p>
|
||||
<p> <b>Will be searching for this string:</b> Robocop 1 </p>
|
||||
<p>Mozilla is a free software community best known for producing the Firefox web browser. The Mozilla community uses, develops, spreads and supports Mozilla products and works to advance the goals of the Open Web described in the Mozilla Manifesto.[1] The community is supported institutionally by the Mozilla Foundation and its tax-paying subsidiary, the Mozilla Corporation.[2] </p>
|
||||
<div style='float: left; width: 100%; height: 500px; margin: 0; padding: 0; border: none'> </div>
|
||||
<p> <b>Will be searching for this string:</b> Robocop </p>
|
||||
<p> <b>Will be searching for this string:</b> Robocop 2 </p>
|
||||
<p>In addition to the Firefox browser, Mozilla also produces Firefox Mobile, the Firefox OS mobile operating system, the bug tracking system Bugzilla and a number of other projects.</p>
|
||||
<div style='float: left; width: 200%; height: 500px; margin: 0; padding: 0; border: none'> </div>
|
||||
<p> <b>Will be searching for this string:</b> Robocop </p>
|
||||
<p> <b>Will be searching for this string:</b> Robocop 3 </p>
|
||||
<p>On February 23, 1998, Netscape Communications Corporation created a project called Mozilla (after the original code name of the Netscape Navigator browser which — according to Pascal Finette — is a mashup of "Mosaic Killer") to co-ordinate the development of the Mozilla Application Suite, the open source version of Netscape's internet software, Netscape Communicator.[3][4] Jamie Zawinski says he came up with the name "Mozilla" at a Netscape staff meeting.[5][6] A small group of Netscape employees were tasked with coordination of the new community.<p>
|
||||
<div style='float: left; width: 100%; height: 500px; margin: 0; padding: 0; border: none'> </div>
|
||||
<p> <b>Will be searching for this string:</b> Robocop </p>
|
||||
|
|
|
@ -4,47 +4,64 @@
|
|||
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import static org.mozilla.gecko.tests.helpers.AssertionHelper.fFail;
|
||||
|
||||
import org.mozilla.gecko.Actions;
|
||||
import org.mozilla.gecko.Element;
|
||||
import org.mozilla.gecko.PaintedSurface;
|
||||
import org.mozilla.gecko.R;
|
||||
|
||||
public class testFindInPage extends PixelTest {
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class testFindInPage extends JavascriptTest implements GeckoEventListener {
|
||||
private static final int WAIT_FOR_TEST = 3000;
|
||||
protected Element next, close;
|
||||
int height,width;
|
||||
|
||||
public void testFindInPage() {
|
||||
blockForGeckoReady();
|
||||
String url = getAbsoluteUrl(StringHelper.ROBOCOP_TEXT_PAGE_URL);
|
||||
loadAndPaint(url);
|
||||
public testFindInPage() {
|
||||
super("testFindInPage.js");
|
||||
}
|
||||
|
||||
height = mDriver.getGeckoHeight()/8;
|
||||
width = mDriver.getGeckoWidth()/2;
|
||||
|
||||
// Search that does not find the term and therefor should not pan the page
|
||||
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
|
||||
findText("Robocoop", 3); // This will be close enough to existing text to test that search finds just what it should
|
||||
PaintedSurface painted = waitForPaint(paintExpecter);
|
||||
paintExpecter.unregisterListener();
|
||||
try {
|
||||
mAsserter.ispixel(painted.getPixelAt(width,height), 255, 0, 0, "Pixel at " + String.valueOf(width) + "," + String.valueOf(height));
|
||||
} finally {
|
||||
painted.close();
|
||||
@Override
|
||||
public void handleMessage(String event, final JSONObject message) {
|
||||
if (event.equals("Test:FindInPage")) {
|
||||
try {
|
||||
final String text = message.getString("text");
|
||||
final int nrOfMatches = Integer.parseInt(message.getString("nrOfMatches"));
|
||||
findText(text, nrOfMatches);
|
||||
} catch (Exception e) {
|
||||
fFail("Can't extract find query from JSON");
|
||||
}
|
||||
}
|
||||
|
||||
// Search that finds matches and therefor pans the page
|
||||
paintExpecter = mActions.expectPaint();
|
||||
findText("Robocop", 3);
|
||||
painted = waitForPaint(paintExpecter);
|
||||
paintExpecter.unregisterListener();
|
||||
try {
|
||||
mAsserter.isnotpixel(painted.getPixelAt(width,height), 255, 0, 0, "Pixel at " + String.valueOf(width) + "," + String.valueOf(height));
|
||||
} finally {
|
||||
painted.close();
|
||||
if (event.equals("Test:CloseFindInPage")) {
|
||||
try {
|
||||
close.click();
|
||||
} catch (Exception e) {
|
||||
fFail("FindInPage prompt not opened");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"Test:FindInPage",
|
||||
"Test:CloseFindInPage");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"Test:FindInPage",
|
||||
"Test:CloseFindInPage");
|
||||
}
|
||||
|
||||
public void findText(String text, int nrOfMatches){
|
||||
selectMenuItem(StringHelper.FIND_IN_PAGE_LABEL);
|
||||
close = mDriver.findElement(getActivity(), R.id.find_close);
|
||||
|
@ -83,6 +100,5 @@ public class testFindInPage extends PixelTest {
|
|||
mSolo.sleep(500); // TODO: Find a better way to wait here because waitForTest is not enough
|
||||
mAsserter.ok(success, "Checking if the next button was clicked", "button was clicked");
|
||||
}
|
||||
close.click(); // Close find in page bar
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/Messaging.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const TEST_URL = "http://mochi.test:8888/tests/robocop/robocop_text_page.html";
|
||||
|
||||
function promiseBrowserEvent(browser, eventType) {
|
||||
return new Promise((resolve) => {
|
||||
function handle(event) {
|
||||
do_print("Received event " + eventType + " from browser");
|
||||
browser.removeEventListener(eventType, handle, true);
|
||||
resolve(event);
|
||||
}
|
||||
|
||||
browser.addEventListener(eventType, handle, true);
|
||||
do_print("Now waiting for " + eventType + " event from browser");
|
||||
});
|
||||
}
|
||||
|
||||
function openTabWithUrl(url) {
|
||||
do_print("Going to open " + url);
|
||||
let browserApp = Services.wm.getMostRecentWindow("navigator:browser").BrowserApp;
|
||||
let browser = browserApp.addTab(url, { selected: true, parentId: browserApp.selectedTab.id }).browser;
|
||||
|
||||
return promiseBrowserEvent(browser, "load")
|
||||
.then(() => { return browser; });
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function closeFindInPage(browser) {
|
||||
let repaintPromise = promiseBrowserEvent(browser, "MozAfterPaint");
|
||||
do_print("Send closeFindInPageMessage");
|
||||
Messaging.sendRequest({ type: "Test:CloseFindInPage" });
|
||||
return repaintPromise;
|
||||
}
|
||||
|
||||
function assertSelection(document, expectedSelection = false, expectedAnchorText = false) {
|
||||
let sel = document.getSelection();
|
||||
if (!expectedSelection) {
|
||||
do_print("Assert empty selection");
|
||||
do_check_eq(sel.toString(), "");
|
||||
} else {
|
||||
do_print("Assert selection to be " + expectedSelection);
|
||||
do_check_eq(sel.toString(), expectedSelection);
|
||||
}
|
||||
if (expectedAnchorText) {
|
||||
do_print("Assert anchor text to be " + expectedAnchorText);
|
||||
do_check_eq(sel.anchorNode.textContent, expectedAnchorText);
|
||||
}
|
||||
}
|
||||
|
||||
add_task(function* testFindInPage() {
|
||||
let browser = yield openTabWithUrl(TEST_URL);
|
||||
let document = browser.contentDocument;
|
||||
|
||||
yield findInPage(browser, "Robocoop", 1);
|
||||
assertSelection(document);
|
||||
|
||||
yield closeFindInPage(browser);
|
||||
assertSelection(document);
|
||||
|
||||
yield findInPage(browser, "Robocop", 1);
|
||||
assertSelection(document, "Robocop", " Robocop 1 ");
|
||||
|
||||
yield closeFindInPage(browser);
|
||||
assertSelection(document);
|
||||
|
||||
yield findInPage(browser, "Robocop", 3);
|
||||
assertSelection(document, "Robocop", " Robocop 3 ");
|
||||
|
||||
yield closeFindInPage(browser);
|
||||
assertSelection(document);
|
||||
});
|
||||
|
||||
run_next_test();
|
Загрузка…
Ссылка в новой задаче