Bug 846340 - Robocop: Add test for 'Clear Site settings', 'Clear Saved passwords' and 'Clear history' options. r=gbrown
authorteodora vermesan <teodora.vermesan@softvision.ro>
Thu, 21 Nov 2013 12:17:48 +0200
changeset 173990 0aeb846dc2e7b458651a11df052415cb57eb301a
parent 173989 f2a84fb7a14e154f71f799aa0d85b3bb9a49744e
child 173991 1b339f171b0af353ca4f0153f5b0404a46873554
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs846340
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 846340 - Robocop: Add test for 'Clear Site settings', 'Clear Saved passwords' and 'Clear history' options. r=gbrown
mobile/android/base/tests/StringHelper.java
mobile/android/base/tests/testClearPrivateData.java
--- a/mobile/android/base/tests/StringHelper.java
+++ b/mobile/android/base/tests/StringHelper.java
@@ -43,16 +43,23 @@ class StringHelper {
         "Open in New Tab",
         "Open in Private Tab",
         "Edit",
         "Remove",
         "Share",
         "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
     // Note: please use getAbsoluteUrl(String url) on each robocop url to get the correct url
     public static final String ROBOCOP_BIG_LINK_URL = "/robocop/robocop_big_link.html";
     public static final String ROBOCOP_BIG_MAILTO_URL = "/robocop/robocop_big_mailto.html";
     public static final String ROBOCOP_BLANK_PAGE_01_URL = "/robocop/robocop_blank_01.html";
     public static final String ROBOCOP_BLANK_PAGE_02_URL = "/robocop/robocop_blank_02.html";
--- a/mobile/android/base/tests/testClearPrivateData.java
+++ b/mobile/android/base/tests/testClearPrivateData.java
@@ -1,48 +1,117 @@
 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;
 
     @Override
     protected int getTestType() {
         return TEST_MOCHITEST;
     }
 
     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);
 
         // Checking that the user made bookmark is not removed
         mAsserter.ok(mDatabaseHelper.isBookmark(blank2), "Checking that bookmarks have not been removed", "User made bookmarks were not removed with private data");
     }
 
     private void verifyHistoryCount(final int expectedCount) {
         boolean match = waitForTest( new BooleanTest() {
             public boolean test() {
                 return (mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY).size() == expectedCount);
             }
         }, 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);
+    }
 }