michael@0: package org.mozilla.gecko.tests; michael@0: import org.mozilla.gecko.Actions; michael@0: import org.mozilla.gecko.R; michael@0: michael@0: import android.view.View; michael@0: michael@0: /** michael@0: * This patch tests the clear private data options: michael@0: * - clear history option by: adding and checking that clear private michael@0: * data option removes the history items but not the users bookmarks michael@0: * - clear site settings and clear saved password by: checking michael@0: * each option present in the doorhanger and clearing the settings from michael@0: * the URL bar context menu and settings menu michael@0: */ michael@0: michael@0: public class testClearPrivateData extends PixelTest { michael@0: private final int TEST_WAIT_MS = 10000; michael@0: michael@0: public void testClearPrivateData() { michael@0: blockForGeckoReady(); michael@0: clearHistory(); michael@0: clearSiteSettings(); michael@0: clearPassword(); michael@0: } michael@0: michael@0: private void clearHistory() { michael@0: michael@0: // Loading a page and adding a second one as bookmark to have user made bookmarks and history michael@0: String blank1 = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL); michael@0: String blank2 = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL); michael@0: String title = StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE; michael@0: inputAndLoadUrl(blank1); michael@0: verifyPageTitle(title); michael@0: mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE, blank2); michael@0: michael@0: // Checking that the history list is not empty michael@0: verifyHistoryCount(1); michael@0: michael@0: //clear and check for device michael@0: checkDevice(title); michael@0: michael@0: // Checking that history list is empty michael@0: verifyHistoryCount(0); michael@0: michael@0: // Checking that the user made bookmark is not removed michael@0: mAsserter.ok(mDatabaseHelper.isBookmark(blank2), "Checking that bookmarks have not been removed", "User made bookmarks were not removed with private data"); michael@0: } michael@0: michael@0: private void verifyHistoryCount(final int expectedCount) { michael@0: boolean match = waitForTest( new BooleanTest() { michael@0: public boolean test() { michael@0: return (mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY).size() == expectedCount); michael@0: } michael@0: }, TEST_WAIT_MS); michael@0: mAsserter.ok(match, "Checking that the number of history items is correct", String.valueOf(expectedCount) + " history items present in the database"); michael@0: } michael@0: michael@0: public void clearSiteSettings() { michael@0: String shareStrings[] = {"Share your location with", "Share", "Don't share", "There are no settings to clear"}; michael@0: String titleGeolocation = StringHelper.ROBOCOP_GEOLOCATION_TITLE; michael@0: String url = getAbsoluteUrl(StringHelper.ROBOCOP_GEOLOCATION_URL); michael@0: loadCheckDismiss(shareStrings[1], url, shareStrings[0]); michael@0: checkOption(shareStrings[1], "Clear"); michael@0: checkOption(shareStrings[3], "Cancel"); michael@0: loadCheckDismiss(shareStrings[2], url, shareStrings[0]); michael@0: checkOption(shareStrings[2], "Cancel"); michael@0: checkDevice(titleGeolocation); michael@0: } michael@0: michael@0: public void clearPassword(){ michael@0: String passwordStrings[] = {"Save password", "Save", "Don't save"}; michael@0: String title = StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE; michael@0: String loginUrl = getAbsoluteUrl(StringHelper.ROBOCOP_LOGIN_URL); michael@0: loadCheckDismiss(passwordStrings[1], loginUrl, passwordStrings[0]); michael@0: checkOption(passwordStrings[1], "Clear"); michael@0: loadCheckDismiss(passwordStrings[2], loginUrl, passwordStrings[0]); michael@0: checkDevice(title); michael@0: } michael@0: michael@0: // clear private data and verify the device type because for phone there is an extra back action to exit the settings menu michael@0: public void checkDevice(String title) { michael@0: clearPrivateData(); michael@0: if (mDevice.type.equals("phone")) { michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK); michael@0: mAsserter.ok(waitForText(StringHelper.PRIVACY_SECTION_LABEL), "waiting to perform one back", "one back"); michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK); michael@0: verifyPageTitle(title); michael@0: } michael@0: else { michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK); michael@0: verifyPageTitle(title); michael@0: } michael@0: } michael@0: michael@0: // Load a URL, verify that the doorhanger appears and dismiss it michael@0: public void loadCheckDismiss(String option, String url, String message) { michael@0: inputAndLoadUrl(url); michael@0: waitForText(message); michael@0: mAsserter.is(mSolo.searchText(message), true, "Doorhanger:" + message + " has been displayed"); michael@0: mSolo.clickOnButton(option); michael@0: mAsserter.is(mSolo.searchText(message), false, "Doorhanger:" + message + " has been hidden"); michael@0: } michael@0: michael@0: //Verify if there are settings to be clear if so clear them from the URL bar context menu michael@0: public void checkOption(String option, String button) { michael@0: if (mDevice.version.equals("2.x")) { michael@0: // Use the context menu in pre-11 michael@0: final View toolbarView = mSolo.getView(R.id.browser_toolbar); michael@0: mSolo.clickLongOnView(toolbarView); michael@0: mAsserter.ok(waitForText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]), "Waiting for the pop-up to open", "Pop up was opened"); michael@0: } else { michael@0: // Use the Page menu in 11+ michael@0: selectMenuItem(StringHelper.PAGE_LABEL); michael@0: mAsserter.ok(waitForText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]), "Waiting for the submenu to open", "Submenu was opened"); michael@0: } michael@0: mSolo.clickOnText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]); michael@0: mAsserter.ok(waitForText(option), "Verify that the option: " + option + " is in the list", "The option is in the list. There are settings to clear"); michael@0: mSolo.clickOnButton(button); michael@0: } michael@0: }