mobile/android/base/tests/testClearPrivateData.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;
     2 import org.mozilla.gecko.Actions;
     3 import org.mozilla.gecko.R;
     5 import android.view.View;
     7 /**
     8  * This patch tests the clear private data options:
     9  * - clear history option by: adding and checking that clear private
    10  * data option removes the history items but not the users bookmarks
    11  * - clear site settings and clear saved password by: checking
    12  * each option present in the doorhanger and clearing the settings from
    13  * the URL bar context menu and settings menu
    14  */
    16 public class testClearPrivateData extends PixelTest {
    17     private final int TEST_WAIT_MS = 10000;
    19     public void testClearPrivateData() {
    20         blockForGeckoReady();
    21         clearHistory();
    22         clearSiteSettings();
    23         clearPassword();
    24     }
    26     private void clearHistory() {
    28         // Loading a page and adding a second one as bookmark to have user made bookmarks and history
    29         String blank1 = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
    30         String blank2 = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL);
    31         String title = StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE;
    32         inputAndLoadUrl(blank1);
    33         verifyPageTitle(title);
    34         mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE, blank2);
    36         // Checking that the history list is not empty
    37         verifyHistoryCount(1);
    39         //clear and check for device
    40         checkDevice(title);
    42         // Checking that history list is empty
    43         verifyHistoryCount(0);
    45         // Checking that the user made bookmark is not removed
    46         mAsserter.ok(mDatabaseHelper.isBookmark(blank2), "Checking that bookmarks have not been removed", "User made bookmarks were not removed with private data");
    47     }
    49     private void verifyHistoryCount(final int expectedCount) {
    50         boolean match = waitForTest( new BooleanTest() {
    51             public boolean test() {
    52                 return (mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY).size() == expectedCount);
    53             }
    54         }, TEST_WAIT_MS);
    55         mAsserter.ok(match, "Checking that the number of history items is correct", String.valueOf(expectedCount) + " history items present in the database");
    56     }
    58     public void clearSiteSettings() {
    59         String shareStrings[] = {"Share your location with", "Share", "Don't share", "There are no settings to clear"};
    60         String titleGeolocation = StringHelper.ROBOCOP_GEOLOCATION_TITLE;
    61         String url = getAbsoluteUrl(StringHelper.ROBOCOP_GEOLOCATION_URL);
    62         loadCheckDismiss(shareStrings[1], url, shareStrings[0]);
    63         checkOption(shareStrings[1], "Clear");
    64         checkOption(shareStrings[3], "Cancel");
    65         loadCheckDismiss(shareStrings[2], url, shareStrings[0]);
    66         checkOption(shareStrings[2], "Cancel");
    67         checkDevice(titleGeolocation);
    68     }
    70     public void clearPassword(){
    71         String passwordStrings[] = {"Save password", "Save", "Don't save"};
    72         String title = StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE;
    73         String loginUrl = getAbsoluteUrl(StringHelper.ROBOCOP_LOGIN_URL);
    74         loadCheckDismiss(passwordStrings[1], loginUrl, passwordStrings[0]);
    75         checkOption(passwordStrings[1], "Clear");
    76         loadCheckDismiss(passwordStrings[2], loginUrl, passwordStrings[0]);
    77         checkDevice(title);
    78     }
    80     // clear private data and verify the device type because for phone there is an extra back action to exit the settings menu
    81     public void checkDevice(String title) {
    82         clearPrivateData();
    83         if (mDevice.type.equals("phone")) {
    84             mActions.sendSpecialKey(Actions.SpecialKey.BACK);
    85             mAsserter.ok(waitForText(StringHelper.PRIVACY_SECTION_LABEL), "waiting to perform one back", "one back");
    86             mActions.sendSpecialKey(Actions.SpecialKey.BACK);
    87             verifyPageTitle(title);
    88         }
    89         else {
    90             mActions.sendSpecialKey(Actions.SpecialKey.BACK);
    91             verifyPageTitle(title);
    92         }
    93     }
    95     // Load a URL, verify that the doorhanger appears and dismiss it
    96     public void loadCheckDismiss(String option, String url, String message) {
    97         inputAndLoadUrl(url);
    98         waitForText(message);
    99         mAsserter.is(mSolo.searchText(message), true, "Doorhanger:" + message + " has been displayed");
   100         mSolo.clickOnButton(option);
   101         mAsserter.is(mSolo.searchText(message), false, "Doorhanger:" + message + " has been hidden");
   102     }
   104     //Verify if there are settings to be clear if so clear them from the URL bar context menu
   105     public void checkOption(String option, String button) {
   106         if (mDevice.version.equals("2.x")) {
   107             // Use the context menu in pre-11
   108             final View toolbarView = mSolo.getView(R.id.browser_toolbar);
   109             mSolo.clickLongOnView(toolbarView);
   110             mAsserter.ok(waitForText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]), "Waiting for the pop-up to open", "Pop up was opened");
   111         } else {
   112             // Use the Page menu in 11+
   113             selectMenuItem(StringHelper.PAGE_LABEL);
   114             mAsserter.ok(waitForText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]), "Waiting for the submenu to open", "Submenu was opened");
   115         }
   116         mSolo.clickOnText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]);
   117         mAsserter.ok(waitForText(option), "Verify that the option: " + option + " is in the list", "The option is in the list. There are settings to clear");
   118         mSolo.clickOnButton(button);
   119     }
   120 }

mercurial