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