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