mobile/android/base/tests/testReaderMode.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 package org.mozilla.gecko.tests;
     3 import org.json.JSONException;
     4 import org.json.JSONObject;
     5 import org.mozilla.gecko.Actions;
     6 import org.mozilla.gecko.R;
     8 import android.view.View;
     9 import android.view.ViewGroup;
    10 import android.widget.ListView;
    12 import com.jayway.android.robotium.solo.Condition;
    13 import com.jayway.android.robotium.solo.Solo;
    15 /**
    16  * This patch tests the Reader Mode feature by adding and removing items in reading list
    17  * checks the reader toolbar functionality(share, add/remove to reading list, go to reading list)
    18  * accessing a page from reading list menu, checks that the reader icon is associated in History tab
    19  * and that the reading list is properly populated after adding or removing reader items
    20  */
    21 public class testReaderMode extends AboutHomeTest {
    22     static final int EVENT_CLEAR_DELAY_MS = 3000;
    23     static final int READER_ICON_MAX_WAIT_MS = 15000;
    25     public void testReaderMode() {
    26         blockForGeckoReady();
    28         Actions.EventExpecter contentEventExpecter;
    29         Actions.EventExpecter contentReaderAddedExpecter;
    30         Actions.EventExpecter faviconExpecter;
    31         Actions.EventExpecter contentPageShowExpecter;
    32         Actions.RepeatedEventExpecter paintExpecter;
    33         ListView list;
    34         View child;
    35         View readerIcon;
    36         String textUrl = getAbsoluteUrl(StringHelper.ROBOCOP_TEXT_PAGE_URL);
    37         String devType = mDevice.type;
    38         int childNo;
    39         int height;
    40         int width;
    42         loadAndPaint(textUrl);
    44         // Add the page to the Reading List using long click on the reader icon
    45         readerIcon = getReaderIcon();
    46         contentReaderAddedExpecter = mActions.expectGeckoEvent("Reader:Added");
    47         mSolo.clickLongOnView(readerIcon);
    48         String eventData = contentReaderAddedExpecter.blockForEventData();
    49         isAdded(eventData);
    50         contentReaderAddedExpecter.unregisterListener();
    52         // Try to add the page to the Reading List using long click on the reader icon a second time
    53         readerIcon = getReaderIcon();
    54         contentReaderAddedExpecter = mActions.expectGeckoEvent("Reader:Added");
    55         mSolo.clickLongOnView(readerIcon);
    56         eventData = contentReaderAddedExpecter.blockForEventData();
    57         isAdded(eventData);
    58         contentReaderAddedExpecter.unregisterListener();
    60         // Waiting for the favicon since is the last element loaded usually
    61         faviconExpecter = mActions.expectGeckoEvent("Reader:FaviconRequest");
    62         contentPageShowExpecter = mActions.expectGeckoEvent("Content:PageShow");
    63         readerIcon = getReaderIcon();
    64         paintExpecter = mActions.expectPaint();
    65         mSolo.clickOnView(readerIcon);
    67         // Changing devices orientation to be sure that all devices are in portrait when will access the reader toolbar
    68         mSolo.setActivityOrientation(Solo.PORTRAIT);
    69         faviconExpecter.blockForEvent();
    70         faviconExpecter.unregisterListener();
    71         contentPageShowExpecter.blockForEvent();
    72         contentPageShowExpecter.unregisterListener();
    73         paintExpecter.blockUntilClear(EVENT_CLEAR_DELAY_MS);
    74         paintExpecter.unregisterListener();
    75         verifyPageTitle("Robocop Text Page");
    77         // Open the share menu for the reader toolbar
    78         height = mDriver.getGeckoTop() + mDriver.getGeckoHeight() - 10;
    79         width = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() - 10;
    80         mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height));
    81         mSolo.clickOnScreen(width,height);
    82         mAsserter.ok(mSolo.waitForText("Share via"), "Waiting for the share menu", "The share menu is present");
    83         mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Close the share menu
    85         // Remove page from the Reading List using reader toolbar
    86         height = mDriver.getGeckoTop() + mDriver.getGeckoHeight() - 10;
    87         width = mDriver.getGeckoLeft() + 50;
    88         mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height));
    89         mSolo.clickOnScreen(width,height);
    90         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");
    92         //Add page to the Reading List using reader toolbar
    93         mSolo.clickOnScreen(width,height);
    94         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");
    96         // Open the Reading List menu for the toolbar
    97         height = mDriver.getGeckoTop() + mDriver.getGeckoHeight() - 10;
    98         width = mDriver.getGeckoLeft() + mDriver.getGeckoWidth()/2 - 10;
    99         mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height));
   100         contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
   101         mSolo.clickOnScreen(width,height);
   102         contentEventExpecter.blockForEvent();
   103         contentEventExpecter.unregisterListener();
   105         // Check if the page is present in the Reading List
   106         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");
   108         // Check if the page is added in History tab like a Reading List item
   109         openAboutHomeTab(AboutHomeTabs.MOST_RECENT);
   110         list = findListViewWithTag("most_recent");
   111         child = list.getChildAt(1);
   112         mAsserter.ok(child != null, "item can be retrieved", child != null ? child.toString() : "null!");
   113         mSolo.clickLongOnView(child);
   114         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");
   115         mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Dismiss the context menu
   116         mSolo.waitForText("Robocop Text Page");
   118         // Verify separately the Reading List entries for tablets and phone because for tablets there is an extra child in UI design
   119         if (devType.equals("phone")) {
   120             childNo = 1;
   121         }
   122         else {
   123             childNo = 2;
   124         }
   125         // Verify if the page is present to your Reading List
   126         openAboutHomeTab(AboutHomeTabs.READING_LIST);
   127         list = findListViewWithTag("reading_list");
   128         child = list.getChildAt(childNo-1);
   129         mAsserter.ok(child != null, "Verify if the page is present to your Reading List", "The page is present in your Reading List");
   130         contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
   131         mSolo.clickOnView(child);
   132         contentEventExpecter.blockForEvent();
   133         contentEventExpecter.unregisterListener();
   134         verifyPageTitle("Robocop Text Page");
   136         // Verify that we are in reader mode and remove the page from Reading List
   137         height = mDriver.getGeckoTop() + mDriver.getGeckoHeight() - 10;
   138         width = mDriver.getGeckoLeft() + 50;
   139         mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height));
   140         mSolo.clickOnScreen(width,height);
   141         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");
   142         verifyPageTitle("Robocop Text Page");
   144         //Check if the Reading List is empty
   145         openAboutHomeTab(AboutHomeTabs.READING_LIST);
   146         list = findListViewWithTag("reading_list");
   147         child = list.getChildAt(childNo-1);
   148         mAsserter.ok(child == null, "Verify if the Reading List is empty", "The Reading List is empty");
   149     }
   151     // Get the reader icon method
   152     protected View getReaderIcon() {
   153         View pageActionLayout = mSolo.getView(R.id.page_action_layout);
   154         final ViewGroup actionLayoutEntry = (ViewGroup)pageActionLayout;
   155         View icon = actionLayoutEntry.getChildAt(1);
   156         if (icon == null || icon.getVisibility() != View.VISIBLE) {
   157             // wait for the view to be visible, otherwise it may not respond
   158             // to clicks -- see bug 927578
   159             mAsserter.dumpLog("reader icon not visible -- waiting for visibility");
   160             Condition visibilityCondition = new Condition() {
   161                 @Override
   162                 public boolean isSatisfied() {
   163                     View conditionIcon = actionLayoutEntry.getChildAt(1);
   164                     if (conditionIcon == null || 
   165                         conditionIcon.getVisibility() != View.VISIBLE)
   166                         return false;
   167                     return true;
   168                 }
   169             };
   170             waitForCondition(visibilityCondition, READER_ICON_MAX_WAIT_MS);
   171             icon = actionLayoutEntry.getChildAt(1);
   172             mAsserter.ok(icon != null, "checking reader icon view", "reader icon view not null");
   173             mAsserter.ok(icon.getVisibility() == View.VISIBLE, "checking reader icon visible", "reader icon visible");
   174         }
   175         return icon;
   176     }
   178     // This method check to see if a reader item is added to the reader list
   179     private boolean isAdded(String eventData) {
   180         try {
   181             JSONObject data = new JSONObject(eventData);
   182                 if (data.getInt("result") == 0) {
   183                     mAsserter.ok(true, "Waiting for the page to be added to your Reading List", "The page was added to your Reading List");
   184                 }
   185                 else {
   186                     if (data.getInt("result") == 2) {
   187                         mAsserter.ok(true, "Trying to add a second time the page in your Reading List", "The page is already in your Reading List");
   188                     }
   189                 }
   190         } catch (JSONException e) {
   191             mAsserter.ok(false, "Error parsing the event data", e.toString());
   192             return false;
   193         }
   194         return true;
   195     }
   196 }

mercurial