Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | package org.mozilla.gecko.tests; |
michael@0 | 2 | |
michael@0 | 3 | import org.mozilla.gecko.Actions; |
michael@0 | 4 | import org.mozilla.gecko.util.Clipboard; |
michael@0 | 5 | |
michael@0 | 6 | import android.util.DisplayMetrics; |
michael@0 | 7 | |
michael@0 | 8 | |
michael@0 | 9 | /** |
michael@0 | 10 | * This class covers interactions with the context menu opened from web content |
michael@0 | 11 | */ |
michael@0 | 12 | abstract class ContentContextMenuTest extends PixelTest { |
michael@0 | 13 | private static final int MAX_TEST_TIMEOUT = 10000; |
michael@0 | 14 | |
michael@0 | 15 | // This method opens the context menu of any web content. It assumes that the page is already loaded |
michael@0 | 16 | protected void openWebContentContextMenu(String waitText) { |
michael@0 | 17 | DisplayMetrics dm = new DisplayMetrics(); |
michael@0 | 18 | getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); |
michael@0 | 19 | |
michael@0 | 20 | // The web content we are trying to open the context menu for should be positioned at the top of the page, at least 60px heigh and aligned to the middle |
michael@0 | 21 | float top = mDriver.getGeckoTop() + 30 * dm.density; |
michael@0 | 22 | float left = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() / 2; |
michael@0 | 23 | |
michael@0 | 24 | mAsserter.dumpLog("long-clicking at "+left+", "+top); |
michael@0 | 25 | mSolo.clickLongOnScreen(left, top); |
michael@0 | 26 | waitForText(waitText); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | protected void verifyContextMenuItems(String[] items) { |
michael@0 | 30 | // Test that the menu items are displayed |
michael@0 | 31 | if (!mSolo.searchText(items[0])) { |
michael@0 | 32 | openWebContentContextMenu(items[0]); // Open the context menu if it is not already |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | for (String option:items) { |
michael@0 | 36 | mAsserter.ok(mSolo.searchText(option), "Checking that the option: " + option + " is available", "The option is available"); |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | protected void openTabFromContextMenu(String contextMenuOption, int expectedTabCount) { |
michael@0 | 41 | if (!mSolo.searchText(contextMenuOption)) { |
michael@0 | 42 | openWebContentContextMenu(contextMenuOption); // Open the context menu if it is not already |
michael@0 | 43 | } |
michael@0 | 44 | Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added"); |
michael@0 | 45 | mSolo.clickOnText(contextMenuOption); |
michael@0 | 46 | tabEventExpecter.blockForEvent(); |
michael@0 | 47 | tabEventExpecter.unregisterListener(); |
michael@0 | 48 | verifyTabCount(expectedTabCount); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | protected void verifyTabs(String[] items) { |
michael@0 | 52 | if (!mSolo.searchText(items[0])) { |
michael@0 | 53 | openWebContentContextMenu(items[0]); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | for (String option:items) { |
michael@0 | 57 | mAsserter.ok(mSolo.searchText(option), "Checking that the option: " + option + " is available", "The option is available"); |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | protected void switchTabs(String tab) { |
michael@0 | 62 | if (!mSolo.searchText(tab)) { |
michael@0 | 63 | openWebContentContextMenu(tab); |
michael@0 | 64 | } |
michael@0 | 65 | mSolo.clickOnText(tab); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | |
michael@0 | 69 | protected void verifyCopyOption(String copyOption, final String copiedText) { |
michael@0 | 70 | if (!mSolo.searchText(copyOption)) { |
michael@0 | 71 | openWebContentContextMenu(copyOption); // Open the context menu if it is not already |
michael@0 | 72 | } |
michael@0 | 73 | mSolo.clickOnText(copyOption); |
michael@0 | 74 | boolean correctText = waitForTest(new BooleanTest() { |
michael@0 | 75 | @Override |
michael@0 | 76 | public boolean test() { |
michael@0 | 77 | final String clipboardText = Clipboard.getText(); |
michael@0 | 78 | mAsserter.dumpLog("Clipboard text = " + clipboardText + " , expected text = " + copiedText); |
michael@0 | 79 | return clipboardText.contains(copiedText); |
michael@0 | 80 | } |
michael@0 | 81 | }, MAX_TEST_TIMEOUT); |
michael@0 | 82 | mAsserter.ok(correctText, "Checking if the text is correctly copied", "The text was correctly copied"); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | |
michael@0 | 87 | protected void verifyShareOption(String shareOption, String pageTitle) { |
michael@0 | 88 | waitForText(pageTitle); // Even if this fails, it won't assert |
michael@0 | 89 | if (!mSolo.searchText(shareOption)) { |
michael@0 | 90 | openWebContentContextMenu(shareOption); // Open the context menu if it is not already |
michael@0 | 91 | } |
michael@0 | 92 | mSolo.clickOnText(shareOption); |
michael@0 | 93 | mAsserter.ok(waitForText(shareOption), "Checking that the share pop-up is displayed", "The pop-up has been displayed"); |
michael@0 | 94 | |
michael@0 | 95 | // Close the Share Link option menu and wait for the page to be focused again |
michael@0 | 96 | mActions.sendSpecialKey(Actions.SpecialKey.BACK); |
michael@0 | 97 | waitForText(pageTitle); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | protected void verifyBookmarkLinkOption(String bookmarkOption, String link) { |
michael@0 | 101 | if (!mSolo.searchText(bookmarkOption)) { |
michael@0 | 102 | openWebContentContextMenu(bookmarkOption); // Open the context menu if it is not already |
michael@0 | 103 | } |
michael@0 | 104 | mSolo.clickOnText(bookmarkOption); |
michael@0 | 105 | mAsserter.ok(waitForText("Bookmark added"), "Waiting for the Bookmark added toaster notification", "The notification has been displayed"); |
michael@0 | 106 | mAsserter.ok(mDatabaseHelper.isBookmark(link), "Checking if the link has been added as a bookmark", "The link has been bookmarked"); |
michael@0 | 107 | } |
michael@0 | 108 | } |