mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 14:45:29 +00:00
210 lines
10 KiB
Java
210 lines
10 KiB
Java
#filter substitution
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
import android.util.DisplayMetrics;
|
|
|
|
/* Test the context menu on web content: Long click on a link,
|
|
* verify that the context menu is shown and verify that some
|
|
* of the menu actions work.
|
|
*/
|
|
|
|
public class testWebContentContextMenu extends PixelTest {
|
|
|
|
@Override
|
|
protected int getTestType() {
|
|
return TEST_MOCHITEST;
|
|
|
|
}
|
|
|
|
public void testWebContentContextMenu() {
|
|
blockForGeckoReady();
|
|
|
|
String urls [] = { "/robocop/robocop_big_link.html", "/robocop/robocop_big_mailto.html", "/robocop/robocop_picture_link.html"};
|
|
String linkMenuItems [] = { "Open Link in New Tab", "Open Link in Private Tab", "Copy Link", "Share Link", "Bookmark Link"};
|
|
String mailtoMenuItems [] = { "Open With an App", "Copy Email Address", "Share Email Address"};
|
|
String photoMenuItems [] = { "Copy Image Location", "Share Image", "Set as Wallpaper", "Save Image"};
|
|
|
|
verfyLinkContextMenu(linkMenuItems, urls);
|
|
verfyMailtoContextMenu(mailtoMenuItems, urls);
|
|
verfyPhotoContextMenu(photoMenuItems, urls);
|
|
|
|
}
|
|
|
|
public void openContextMenu(int i, String urls []) {
|
|
DisplayMetrics dm = new DisplayMetrics();
|
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
|
|
|
// The link has a 60px height, so let's try to hit the middle
|
|
float top = mDriver.getGeckoTop() + 30 * dm.density;
|
|
float left = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() / 2;
|
|
|
|
String url = getAbsoluteUrl(urls [i]);
|
|
getInstrumentation().waitForIdleSync();
|
|
loadAndPaint(url);
|
|
mAsserter.dumpLog("long-clicking at "+left+", "+top);
|
|
mSolo.clickLongOnScreen(left, top);
|
|
}
|
|
|
|
public void accessSection(int i, String opt, String urls []) {
|
|
openContextMenu(i, urls);
|
|
mAsserter.ok(mSolo.waitForText(opt), "Waiting for " + opt + " option", "The " + opt + " option is present");
|
|
mSolo.clickOnText(opt);
|
|
}
|
|
|
|
public void verfyLinkContextMenu(String items [], String urls []) {
|
|
for (String opt:items) {
|
|
if (opt.equals("Open Link in New Tab")) {
|
|
openContextMenu(0, urls);
|
|
mAsserter.ok(mSolo.waitForText(opt), "Waiting for " + opt + " option", "The " + opt + " option is present");
|
|
Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
|
|
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
|
mSolo.clickOnText(opt);
|
|
|
|
// Wait for the new tab and page to load
|
|
tabEventExpecter.blockForEvent();
|
|
contentEventExpecter.blockForEvent();
|
|
|
|
// See tab count
|
|
Element tabCount = mDriver.findElement(getActivity(), "tabs_count");
|
|
String tabCountText = null;
|
|
if (tabCount != null) {
|
|
tabCountText = tabCount.getText();
|
|
}
|
|
mAsserter.is(tabCountText, "2", "Number of tabs has increased");
|
|
}
|
|
else {
|
|
if (opt.equals("Open Link in Private Tab")) {
|
|
accessSection(2, opt, urls);
|
|
mAsserter.ok(mSolo.waitForText("New private tab opened"), "Waiting for private tab to open", "The private tab is opened");
|
|
|
|
// Verifying if the private data is not listed in Awesomescreen
|
|
clickOnAwesomeBar();
|
|
mSolo.clickOnText("History");
|
|
mAsserter.ok(mSolo.waitForText("Browser Blank Page 01"), "Looking in History for the page loaded in the normal tab", "Fount it");
|
|
mAsserter.ok(mSolo.waitForText("Browser Blank Page 02") == false, "Looking in History for the page loaded in the private tab", "Page is not present in History");
|
|
}
|
|
else {
|
|
if (opt.equals("Copy Link")) {
|
|
accessSection(0, opt, urls);
|
|
|
|
// Verifying if the link was copied
|
|
mSolo.clickLongOnText("Big Link");
|
|
mAsserter.ok(mSolo.waitForText("^Paste$"), "Verify if the 'Paste' option is present", "The 'Paste' option is present");
|
|
mSolo.clickOnText("^Paste$");
|
|
mAsserter.ok(mSolo.waitForText("robocop_blank_01.html"), "Verify link", "The link was properly copied");
|
|
}
|
|
else {
|
|
if (opt.equals("Share Link")) {
|
|
accessSection(0, opt, urls);
|
|
|
|
// Verifying if the Share Link option menu is opened
|
|
mAsserter.ok(mSolo.waitForText("Share via"), "Waiting for the Share Link option menu to open", "The Share Link option menu is opened");
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK);// Close the Share Link option menu
|
|
mSolo.waitForText("Big Link");
|
|
}
|
|
else {
|
|
if (opt.equals("Bookmark Link")) {
|
|
Device mDevice = new Device();
|
|
Navigation nav = new Navigation(mDevice);
|
|
|
|
accessSection(0, opt, urls);
|
|
mAsserter.is(mSolo.waitForText("Bookmark added"), true, "Bookmark added verified");
|
|
|
|
// This waitForIdleSync improves reliability of the following loadUrl.
|
|
// TODO: understand why!
|
|
getInstrumentation().waitForIdleSync();
|
|
|
|
// We know that the link test page points to robocop_blank_01.html, so lets
|
|
// load it and see if the page is bookmarked
|
|
String url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
|
|
loadAndPaint(url);
|
|
|
|
// Pause briefly, to ensure that the bookmark addition, above, updates database tables and
|
|
// completes before checking that the bookmark exists.
|
|
// TODO: Find a better way to wait for completion of bookmark operations.
|
|
try { Thread.sleep(2000); } catch(Exception e) {}
|
|
|
|
// TODO: This doesn't work for some reason. We got a 'Bookmark added' and
|
|
// will check for 'Bookmark removed'
|
|
mAsserter.todo_is(mSolo.isTextChecked("Bookmark"), true, "Page is bookmarked");
|
|
|
|
nav.bookmark();
|
|
mAsserter.is(mSolo.waitForText("Bookmark removed"), true, "Bookmark removal verified");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void verfyMailtoContextMenu(String items [], String urls []) {
|
|
for (String opt:items) {
|
|
if (opt.equals("Copy Email Address")) {
|
|
openContextMenu(1, urls);
|
|
mAsserter.ok(mSolo.waitForText(opt), "Waiting for " + opt + " option", "The " + opt + " option is present");
|
|
mSolo.clickOnText(opt);
|
|
|
|
// Verifying if the email address was copied
|
|
mSolo.clickLongOnText("Big Mailto");
|
|
mAsserter.ok(mSolo.waitForText("^Paste$"), "Verify if the 'Paste' option is present", "The 'Paste' option is present");
|
|
mSolo.clickOnText("^Paste$");
|
|
mAsserter.ok(mSolo.waitForText("foo.bar@example.com"), "Verify email address", "The email address was properly copied");
|
|
}
|
|
else {
|
|
if (opt.equals("Share Email Address")) {
|
|
accessSection(1, opt, urls);
|
|
|
|
// Verifying if the Share email address option menu is opened
|
|
mAsserter.ok(mSolo.waitForText("Share via"), "Waiting for the Share email address option menu to open", "The Share email address option menu is opened");
|
|
}
|
|
}
|
|
}
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Close the Share email address option menu
|
|
mSolo.waitForText("Big Mailto");
|
|
}
|
|
|
|
// Load a picture test page and test for allowed menu actions
|
|
public void verfyPhotoContextMenu(String items [], String urls []) {
|
|
for (String opt:items) {
|
|
if (opt.equals("Copy Image Location")) {
|
|
|
|
// This waitForIdleSync improves reliability of the following loadUrl.
|
|
// TODO: understand why!
|
|
getInstrumentation().waitForIdleSync();
|
|
accessSection(2, opt, urls);
|
|
|
|
// Verifying if the photo's link was copied
|
|
mSolo.clickLongOnText("Picture Link");
|
|
mAsserter.ok(mSolo.waitForText("^Paste$"), "Verify if the 'Paste' option is present", "The 'Paste' option is present");
|
|
mSolo.clickOnText("^Paste$");
|
|
mAsserter.ok(mSolo.waitForText("Firefox.jpg"), "Verify link", "The photo's link was properly copied");
|
|
}
|
|
else {
|
|
if (opt.equals("Share Image")) {
|
|
accessSection(2, opt, urls);
|
|
|
|
// Verifying if the Share Image option menu is opened
|
|
mAsserter.ok(mSolo.waitForText("Share via"), "Waiting for the Share Image option menu to open", "The Share Image option menu is opened");
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Close the Share Image option menu
|
|
mSolo.waitForText("Picture Link");
|
|
}
|
|
else {
|
|
if (opt.equals("Set as Wallpaper")) {
|
|
openContextMenu(2, urls);
|
|
mAsserter.ok(mSolo.waitForText(opt), "Waiting for " + opt + " option", "The " + opt + " option is present");
|
|
}
|
|
else {
|
|
if (opt.equals("Save Image")) {
|
|
mSolo.clickOnText(opt);
|
|
mAsserter.ok(mSolo.waitForText("Download started"), "Verify that the download started", "The download started");
|
|
mSolo.waitForText("Picture Link");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|