mobile/android/base/tests/testClearPrivateData.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testClearPrivateData.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +import org.mozilla.gecko.Actions;
     1.6 +import org.mozilla.gecko.R;
     1.7 +
     1.8 +import android.view.View;
     1.9 +
    1.10 +/**
    1.11 + * This patch tests the clear private data options:
    1.12 + * - clear history option by: adding and checking that clear private
    1.13 + * data option removes the history items but not the users bookmarks
    1.14 + * - clear site settings and clear saved password by: checking
    1.15 + * each option present in the doorhanger and clearing the settings from
    1.16 + * the URL bar context menu and settings menu
    1.17 + */
    1.18 +
    1.19 +public class testClearPrivateData extends PixelTest {
    1.20 +    private final int TEST_WAIT_MS = 10000;
    1.21 +
    1.22 +    public void testClearPrivateData() {
    1.23 +        blockForGeckoReady();
    1.24 +        clearHistory();
    1.25 +        clearSiteSettings();
    1.26 +        clearPassword();
    1.27 +    }
    1.28 +
    1.29 +    private void clearHistory() {
    1.30 +
    1.31 +        // Loading a page and adding a second one as bookmark to have user made bookmarks and history
    1.32 +        String blank1 = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
    1.33 +        String blank2 = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL);
    1.34 +        String title = StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE;
    1.35 +        inputAndLoadUrl(blank1);
    1.36 +        verifyPageTitle(title);
    1.37 +        mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE, blank2);
    1.38 +
    1.39 +        // Checking that the history list is not empty
    1.40 +        verifyHistoryCount(1);
    1.41 +
    1.42 +        //clear and check for device
    1.43 +        checkDevice(title);
    1.44 +
    1.45 +        // Checking that history list is empty
    1.46 +        verifyHistoryCount(0);
    1.47 +
    1.48 +        // Checking that the user made bookmark is not removed
    1.49 +        mAsserter.ok(mDatabaseHelper.isBookmark(blank2), "Checking that bookmarks have not been removed", "User made bookmarks were not removed with private data");
    1.50 +    }
    1.51 +
    1.52 +    private void verifyHistoryCount(final int expectedCount) {
    1.53 +        boolean match = waitForTest( new BooleanTest() {
    1.54 +            public boolean test() {
    1.55 +                return (mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY).size() == expectedCount);
    1.56 +            }
    1.57 +        }, TEST_WAIT_MS);
    1.58 +        mAsserter.ok(match, "Checking that the number of history items is correct", String.valueOf(expectedCount) + " history items present in the database");
    1.59 +    }
    1.60 +
    1.61 +    public void clearSiteSettings() {
    1.62 +        String shareStrings[] = {"Share your location with", "Share", "Don't share", "There are no settings to clear"};
    1.63 +        String titleGeolocation = StringHelper.ROBOCOP_GEOLOCATION_TITLE;
    1.64 +        String url = getAbsoluteUrl(StringHelper.ROBOCOP_GEOLOCATION_URL);
    1.65 +        loadCheckDismiss(shareStrings[1], url, shareStrings[0]);
    1.66 +        checkOption(shareStrings[1], "Clear");
    1.67 +        checkOption(shareStrings[3], "Cancel");
    1.68 +        loadCheckDismiss(shareStrings[2], url, shareStrings[0]);
    1.69 +        checkOption(shareStrings[2], "Cancel");
    1.70 +        checkDevice(titleGeolocation);
    1.71 +    }
    1.72 +
    1.73 +    public void clearPassword(){
    1.74 +        String passwordStrings[] = {"Save password", "Save", "Don't save"};
    1.75 +        String title = StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE;
    1.76 +        String loginUrl = getAbsoluteUrl(StringHelper.ROBOCOP_LOGIN_URL);
    1.77 +        loadCheckDismiss(passwordStrings[1], loginUrl, passwordStrings[0]);
    1.78 +        checkOption(passwordStrings[1], "Clear");
    1.79 +        loadCheckDismiss(passwordStrings[2], loginUrl, passwordStrings[0]);
    1.80 +        checkDevice(title);
    1.81 +    }
    1.82 +
    1.83 +    // clear private data and verify the device type because for phone there is an extra back action to exit the settings menu
    1.84 +    public void checkDevice(String title) {
    1.85 +        clearPrivateData();
    1.86 +        if (mDevice.type.equals("phone")) {
    1.87 +            mActions.sendSpecialKey(Actions.SpecialKey.BACK);
    1.88 +            mAsserter.ok(waitForText(StringHelper.PRIVACY_SECTION_LABEL), "waiting to perform one back", "one back");
    1.89 +            mActions.sendSpecialKey(Actions.SpecialKey.BACK);
    1.90 +            verifyPageTitle(title);
    1.91 +        }
    1.92 +        else {
    1.93 +            mActions.sendSpecialKey(Actions.SpecialKey.BACK);
    1.94 +            verifyPageTitle(title);
    1.95 +        }
    1.96 +    }
    1.97 +   
    1.98 +    // Load a URL, verify that the doorhanger appears and dismiss it
    1.99 +    public void loadCheckDismiss(String option, String url, String message) {
   1.100 +        inputAndLoadUrl(url);
   1.101 +        waitForText(message);
   1.102 +        mAsserter.is(mSolo.searchText(message), true, "Doorhanger:" + message + " has been displayed");
   1.103 +        mSolo.clickOnButton(option);
   1.104 +        mAsserter.is(mSolo.searchText(message), false, "Doorhanger:" + message + " has been hidden");
   1.105 +    }
   1.106 +
   1.107 +    //Verify if there are settings to be clear if so clear them from the URL bar context menu
   1.108 +    public void checkOption(String option, String button) {
   1.109 +        if (mDevice.version.equals("2.x")) {
   1.110 +            // Use the context menu in pre-11
   1.111 +            final View toolbarView = mSolo.getView(R.id.browser_toolbar);
   1.112 +            mSolo.clickLongOnView(toolbarView);
   1.113 +            mAsserter.ok(waitForText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]), "Waiting for the pop-up to open", "Pop up was opened");
   1.114 +        } else {
   1.115 +            // Use the Page menu in 11+
   1.116 +            selectMenuItem(StringHelper.PAGE_LABEL);
   1.117 +            mAsserter.ok(waitForText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]), "Waiting for the submenu to open", "Submenu was opened");
   1.118 +        }
   1.119 +        mSolo.clickOnText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]);
   1.120 +        mAsserter.ok(waitForText(option), "Verify that the option: " + option + " is in the list", "The option is in the list. There are settings to clear");
   1.121 +        mSolo.clickOnButton(button);
   1.122 +    }
   1.123 +}

mercurial