1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/testReaderMode.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,196 @@ 1.4 +package org.mozilla.gecko.tests; 1.5 + 1.6 +import org.json.JSONException; 1.7 +import org.json.JSONObject; 1.8 +import org.mozilla.gecko.Actions; 1.9 +import org.mozilla.gecko.R; 1.10 + 1.11 +import android.view.View; 1.12 +import android.view.ViewGroup; 1.13 +import android.widget.ListView; 1.14 + 1.15 +import com.jayway.android.robotium.solo.Condition; 1.16 +import com.jayway.android.robotium.solo.Solo; 1.17 + 1.18 +/** 1.19 + * This patch tests the Reader Mode feature by adding and removing items in reading list 1.20 + * checks the reader toolbar functionality(share, add/remove to reading list, go to reading list) 1.21 + * accessing a page from reading list menu, checks that the reader icon is associated in History tab 1.22 + * and that the reading list is properly populated after adding or removing reader items 1.23 + */ 1.24 +public class testReaderMode extends AboutHomeTest { 1.25 + static final int EVENT_CLEAR_DELAY_MS = 3000; 1.26 + static final int READER_ICON_MAX_WAIT_MS = 15000; 1.27 + 1.28 + public void testReaderMode() { 1.29 + blockForGeckoReady(); 1.30 + 1.31 + Actions.EventExpecter contentEventExpecter; 1.32 + Actions.EventExpecter contentReaderAddedExpecter; 1.33 + Actions.EventExpecter faviconExpecter; 1.34 + Actions.EventExpecter contentPageShowExpecter; 1.35 + Actions.RepeatedEventExpecter paintExpecter; 1.36 + ListView list; 1.37 + View child; 1.38 + View readerIcon; 1.39 + String textUrl = getAbsoluteUrl(StringHelper.ROBOCOP_TEXT_PAGE_URL); 1.40 + String devType = mDevice.type; 1.41 + int childNo; 1.42 + int height; 1.43 + int width; 1.44 + 1.45 + loadAndPaint(textUrl); 1.46 + 1.47 + // Add the page to the Reading List using long click on the reader icon 1.48 + readerIcon = getReaderIcon(); 1.49 + contentReaderAddedExpecter = mActions.expectGeckoEvent("Reader:Added"); 1.50 + mSolo.clickLongOnView(readerIcon); 1.51 + String eventData = contentReaderAddedExpecter.blockForEventData(); 1.52 + isAdded(eventData); 1.53 + contentReaderAddedExpecter.unregisterListener(); 1.54 + 1.55 + // Try to add the page to the Reading List using long click on the reader icon a second time 1.56 + readerIcon = getReaderIcon(); 1.57 + contentReaderAddedExpecter = mActions.expectGeckoEvent("Reader:Added"); 1.58 + mSolo.clickLongOnView(readerIcon); 1.59 + eventData = contentReaderAddedExpecter.blockForEventData(); 1.60 + isAdded(eventData); 1.61 + contentReaderAddedExpecter.unregisterListener(); 1.62 + 1.63 + // Waiting for the favicon since is the last element loaded usually 1.64 + faviconExpecter = mActions.expectGeckoEvent("Reader:FaviconRequest"); 1.65 + contentPageShowExpecter = mActions.expectGeckoEvent("Content:PageShow"); 1.66 + readerIcon = getReaderIcon(); 1.67 + paintExpecter = mActions.expectPaint(); 1.68 + mSolo.clickOnView(readerIcon); 1.69 + 1.70 + // Changing devices orientation to be sure that all devices are in portrait when will access the reader toolbar 1.71 + mSolo.setActivityOrientation(Solo.PORTRAIT); 1.72 + faviconExpecter.blockForEvent(); 1.73 + faviconExpecter.unregisterListener(); 1.74 + contentPageShowExpecter.blockForEvent(); 1.75 + contentPageShowExpecter.unregisterListener(); 1.76 + paintExpecter.blockUntilClear(EVENT_CLEAR_DELAY_MS); 1.77 + paintExpecter.unregisterListener(); 1.78 + verifyPageTitle("Robocop Text Page"); 1.79 + 1.80 + // Open the share menu for the reader toolbar 1.81 + height = mDriver.getGeckoTop() + mDriver.getGeckoHeight() - 10; 1.82 + width = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() - 10; 1.83 + mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height)); 1.84 + mSolo.clickOnScreen(width,height); 1.85 + mAsserter.ok(mSolo.waitForText("Share via"), "Waiting for the share menu", "The share menu is present"); 1.86 + mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Close the share menu 1.87 + 1.88 + // Remove page from the Reading List using reader toolbar 1.89 + height = mDriver.getGeckoTop() + mDriver.getGeckoHeight() - 10; 1.90 + width = mDriver.getGeckoLeft() + 50; 1.91 + mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height)); 1.92 + mSolo.clickOnScreen(width,height); 1.93 + mAsserter.ok(mSolo.waitForText("Page removed from your Reading List"), "Waiting for the page to removed from your Reading List", "The page is removed from your Reading List"); 1.94 + 1.95 + //Add page to the Reading List using reader toolbar 1.96 + mSolo.clickOnScreen(width,height); 1.97 + mAsserter.ok(mSolo.waitForText("Page added to your Reading List"), "Waiting for the page to be added to your Reading List", "The page was added to your Reading List"); 1.98 + 1.99 + // Open the Reading List menu for the toolbar 1.100 + height = mDriver.getGeckoTop() + mDriver.getGeckoHeight() - 10; 1.101 + width = mDriver.getGeckoLeft() + mDriver.getGeckoWidth()/2 - 10; 1.102 + mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height)); 1.103 + contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded"); 1.104 + mSolo.clickOnScreen(width,height); 1.105 + contentEventExpecter.blockForEvent(); 1.106 + contentEventExpecter.unregisterListener(); 1.107 + 1.108 + // Check if the page is present in the Reading List 1.109 + mAsserter.ok(mSolo.waitForText("Robocop Text Page"), "Verify if the page is added to your Reading List", "The page is present in your Reading List"); 1.110 + 1.111 + // Check if the page is added in History tab like a Reading List item 1.112 + openAboutHomeTab(AboutHomeTabs.MOST_RECENT); 1.113 + list = findListViewWithTag("most_recent"); 1.114 + child = list.getChildAt(1); 1.115 + mAsserter.ok(child != null, "item can be retrieved", child != null ? child.toString() : "null!"); 1.116 + mSolo.clickLongOnView(child); 1.117 + mAsserter.ok(mSolo.waitForText("Open in Reader"), "Verify if the page is present in history as a Reading List item", "The page is present in history as a Reading List item"); 1.118 + mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Dismiss the context menu 1.119 + mSolo.waitForText("Robocop Text Page"); 1.120 + 1.121 + // Verify separately the Reading List entries for tablets and phone because for tablets there is an extra child in UI design 1.122 + if (devType.equals("phone")) { 1.123 + childNo = 1; 1.124 + } 1.125 + else { 1.126 + childNo = 2; 1.127 + } 1.128 + // Verify if the page is present to your Reading List 1.129 + openAboutHomeTab(AboutHomeTabs.READING_LIST); 1.130 + list = findListViewWithTag("reading_list"); 1.131 + child = list.getChildAt(childNo-1); 1.132 + mAsserter.ok(child != null, "Verify if the page is present to your Reading List", "The page is present in your Reading List"); 1.133 + contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded"); 1.134 + mSolo.clickOnView(child); 1.135 + contentEventExpecter.blockForEvent(); 1.136 + contentEventExpecter.unregisterListener(); 1.137 + verifyPageTitle("Robocop Text Page"); 1.138 + 1.139 + // Verify that we are in reader mode and remove the page from Reading List 1.140 + height = mDriver.getGeckoTop() + mDriver.getGeckoHeight() - 10; 1.141 + width = mDriver.getGeckoLeft() + 50; 1.142 + mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height)); 1.143 + mSolo.clickOnScreen(width,height); 1.144 + mAsserter.ok(mSolo.waitForText("Page removed from your Reading List"), "Waiting for the page to removed from your Reading List", "The page is removed from your Reading List"); 1.145 + verifyPageTitle("Robocop Text Page"); 1.146 + 1.147 + //Check if the Reading List is empty 1.148 + openAboutHomeTab(AboutHomeTabs.READING_LIST); 1.149 + list = findListViewWithTag("reading_list"); 1.150 + child = list.getChildAt(childNo-1); 1.151 + mAsserter.ok(child == null, "Verify if the Reading List is empty", "The Reading List is empty"); 1.152 + } 1.153 + 1.154 + // Get the reader icon method 1.155 + protected View getReaderIcon() { 1.156 + View pageActionLayout = mSolo.getView(R.id.page_action_layout); 1.157 + final ViewGroup actionLayoutEntry = (ViewGroup)pageActionLayout; 1.158 + View icon = actionLayoutEntry.getChildAt(1); 1.159 + if (icon == null || icon.getVisibility() != View.VISIBLE) { 1.160 + // wait for the view to be visible, otherwise it may not respond 1.161 + // to clicks -- see bug 927578 1.162 + mAsserter.dumpLog("reader icon not visible -- waiting for visibility"); 1.163 + Condition visibilityCondition = new Condition() { 1.164 + @Override 1.165 + public boolean isSatisfied() { 1.166 + View conditionIcon = actionLayoutEntry.getChildAt(1); 1.167 + if (conditionIcon == null || 1.168 + conditionIcon.getVisibility() != View.VISIBLE) 1.169 + return false; 1.170 + return true; 1.171 + } 1.172 + }; 1.173 + waitForCondition(visibilityCondition, READER_ICON_MAX_WAIT_MS); 1.174 + icon = actionLayoutEntry.getChildAt(1); 1.175 + mAsserter.ok(icon != null, "checking reader icon view", "reader icon view not null"); 1.176 + mAsserter.ok(icon.getVisibility() == View.VISIBLE, "checking reader icon visible", "reader icon visible"); 1.177 + } 1.178 + return icon; 1.179 + } 1.180 + 1.181 + // This method check to see if a reader item is added to the reader list 1.182 + private boolean isAdded(String eventData) { 1.183 + try { 1.184 + JSONObject data = new JSONObject(eventData); 1.185 + if (data.getInt("result") == 0) { 1.186 + mAsserter.ok(true, "Waiting for the page to be added to your Reading List", "The page was added to your Reading List"); 1.187 + } 1.188 + else { 1.189 + if (data.getInt("result") == 2) { 1.190 + mAsserter.ok(true, "Trying to add a second time the page in your Reading List", "The page is already in your Reading List"); 1.191 + } 1.192 + } 1.193 + } catch (JSONException e) { 1.194 + mAsserter.ok(false, "Error parsing the event data", e.toString()); 1.195 + return false; 1.196 + } 1.197 + return true; 1.198 + } 1.199 +}