From 3bc54353ff4b95e792a06e98838860522663c535 Mon Sep 17 00:00:00 2001 From: teodora vermesan Date: Thu, 21 Nov 2013 12:17:48 +0200 Subject: [PATCH] Bug 846340 - Robocop: Add test for 'Clear Site settings', 'Clear Saved passwords' and 'Clear history' options. r=gbrown --- mobile/android/base/tests/StringHelper.java | 7 ++ .../base/tests/testClearPrivateData.java | 81 +++++++++++++++++-- 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/mobile/android/base/tests/StringHelper.java b/mobile/android/base/tests/StringHelper.java index f24e8b155360..2727cc8d5da6 100644 --- a/mobile/android/base/tests/StringHelper.java +++ b/mobile/android/base/tests/StringHelper.java @@ -52,6 +52,13 @@ public class StringHelper { "Add to Home Screen" }; + public static final String[] CONTEXT_MENU_ITEMS_IN_URL_BAR = new String[] { + "Share", + "Copy Address", + "Edit Site Settings", + "Add to Home Screen" + }; + public static final String TITLE_PLACE_HOLDER = "Enter Search or Address"; // Robocop page urls diff --git a/mobile/android/base/tests/testClearPrivateData.java b/mobile/android/base/tests/testClearPrivateData.java index 573db9c05e52..edbb22f3cae3 100644 --- a/mobile/android/base/tests/testClearPrivateData.java +++ b/mobile/android/base/tests/testClearPrivateData.java @@ -1,8 +1,17 @@ package org.mozilla.gecko.tests; - +import android.view.View; import org.mozilla.gecko.*; import java.util.ArrayList; +/** + * This patch tests the clear private data options: + * - clear history option by: adding and checking that clear private + * data option removes the history items but not the users bookmarks + * - clear site settings and clear saved password by: checking + * each option present in the doorhanger and clearing the settings from + * the URL bar context menu and settings menu + */ + public class testClearPrivateData extends PixelTest { private final int TEST_WAIT_MS = 10000; @@ -14,21 +23,25 @@ public class testClearPrivateData extends PixelTest { public void testClearPrivateData() { blockForGeckoReady(); clearHistory(); + clearSiteSettings(); + clearPassword(); } private void clearHistory() { + // Loading a page and adding a second one as bookmark to have user made bookmarks and history String blank1 = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL); String blank2 = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL); - - loadAndPaint(blank1); - waitForText(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE); - + String title = StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE; + inputAndLoadUrl(blank1); + verifyPageTitle(title); mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE, blank2); // Checking that the history list is not empty verifyHistoryCount(1); - clearPrivateData(); + + //clear and check for device + checkDevice(title); // Checking that history list is empty verifyHistoryCount(0); @@ -45,4 +58,60 @@ public class testClearPrivateData extends PixelTest { }, TEST_WAIT_MS); mAsserter.ok(match, "Checking that the number of history items is correct", String.valueOf(expectedCount) + " history items present in the database"); } + + public void clearSiteSettings() { + String shareStrings[] = {"Share your location with", "Share", "Don't share", "There are no settings to clear"}; + String titleGeolocation = StringHelper.ROBOCOP_GEOLOCATION_TITLE; + String url = getAbsoluteUrl(StringHelper.ROBOCOP_GEOLOCATION_URL); + loadCheckDismiss(shareStrings[1], url, shareStrings[0]); + checkOption(shareStrings[1], "Clear"); + checkOption(shareStrings[3], "Cancel"); + loadCheckDismiss(shareStrings[2], url, shareStrings[0]); + checkOption(shareStrings[2], "Cancel"); + checkDevice(titleGeolocation); + } + + public void clearPassword(){ + String passwordStrings[] = {"Save password", "Save", "Don't save"}; + String title = StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE; + String loginUrl = getAbsoluteUrl(StringHelper.ROBOCOP_LOGIN_URL); + loadCheckDismiss(passwordStrings[1], loginUrl, passwordStrings[0]); + checkOption(passwordStrings[1], "Clear"); + loadCheckDismiss(passwordStrings[2], loginUrl, passwordStrings[0]); + checkDevice(title); + } + + // clear private data and verify the device type because for phone there is an extra back action to exit the settings menu + public void checkDevice(String title) { + clearPrivateData(); + if (mDevice.type.equals("phone")) { + mActions.sendSpecialKey(Actions.SpecialKey.BACK); + mAsserter.ok(waitForText(StringHelper.PRIVACY_SECTION_LABEL), "waiting to perform one back", "one back"); + mActions.sendSpecialKey(Actions.SpecialKey.BACK); + verifyPageTitle(title); + } + else { + mActions.sendSpecialKey(Actions.SpecialKey.BACK); + verifyPageTitle(title); + } + } + + // Load a URL, verify that the doorhanger appears and dismiss it + public void loadCheckDismiss(String option, String url, String message) { + inputAndLoadUrl(url); + waitForText(message); + mAsserter.is(mSolo.searchText(message), true, "Doorhanger:" + message + " has been displayed"); + mSolo.clickOnButton(option); + mAsserter.is(mSolo.searchText(message), false, "Doorhanger:" + message + " has been hidden"); + } + + //Verify if there are settings to be clear if so clear them from the URL bar context menu + public void checkOption(String option, String button) { + final View toolbarView = mSolo.getView("browser_toolbar"); + mSolo.clickLongOnView(toolbarView); + mAsserter.ok(waitForText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]), "Waiting for the pop-up to open", "Pop up was openend"); + mSolo.clickOnText(StringHelper.CONTEXT_MENU_ITEMS_IN_URL_BAR[2]); + mAsserter.ok(waitForText(option), "Verify that the option: " + option + " is in the list", "The option is in the list. There are settings to clear"); + mSolo.clickOnButton(button); + } }