mobile/android/base/tests/testPrivateBrowsing.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testPrivateBrowsing.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import java.util.ArrayList;
     1.7 +
     1.8 +import org.json.JSONException;
     1.9 +import org.json.JSONObject;
    1.10 +import org.mozilla.gecko.Actions;
    1.11 +
    1.12 +/**
    1.13 + * The test loads a new private tab and loads a page with a big link on it
    1.14 + * Opens the link in a new private tab and checks that it is private
    1.15 + * Adds a new normal tab and loads a 3rd URL
    1.16 + * Checks that the bigLinkUrl loaded in the normal tab is present in the browsing history but the 2 urls opened in private tabs are not
    1.17 + */
    1.18 +public class testPrivateBrowsing extends ContentContextMenuTest {
    1.19 +
    1.20 +    public void testPrivateBrowsing() {
    1.21 +        String bigLinkUrl = getAbsoluteUrl(StringHelper.ROBOCOP_BIG_LINK_URL);
    1.22 +        String blank1Url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
    1.23 +        String blank2Url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL);
    1.24 +
    1.25 +        blockForGeckoReady();
    1.26 +
    1.27 +        inputAndLoadUrl(StringHelper.ABOUT_BLANK_URL);
    1.28 +
    1.29 +        addTab(bigLinkUrl, StringHelper.ROBOCOP_BIG_LINK_TITLE, true);
    1.30 +
    1.31 +        verifyTabCount(1);
    1.32 +
    1.33 +        // Open the link context menu and verify the options
    1.34 +        verifyContextMenuItems(StringHelper.CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB);
    1.35 +
    1.36 +        // Check that "Open Link in New Tab" is not in the menu
    1.37 +        mAsserter.ok(!mSolo.searchText(StringHelper.CONTEXT_MENU_ITEMS_IN_NORMAL_TAB[0]), "Checking that 'Open Link in New Tab' is not displayed in the context menu", "'Open Link in New Tab' is not displayed in the context menu");
    1.38 +
    1.39 +        // Open the link in a new private tab and check that it is private
    1.40 +        Actions.EventExpecter privateTabEventExpector = mActions.expectGeckoEvent("Tab:Added");
    1.41 +        mSolo.clickOnText(StringHelper.CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB[0]);
    1.42 +        String eventData = privateTabEventExpector.blockForEventData();
    1.43 +        privateTabEventExpector.unregisterListener();
    1.44 +
    1.45 +        mAsserter.ok(isTabPrivate(eventData), "Checking if the new tab opened from the context menu was a private tab", "The tab was a private tab");
    1.46 +        verifyTabCount(2);
    1.47 +
    1.48 +        // Open a normal tab to check later that it was registered in the Firefox Browser History
    1.49 +        addTab(blank2Url, StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE, false);
    1.50 +        verifyTabCount(2);
    1.51 +
    1.52 +        // Get the history list and check that the links open in private browsing are not saved
    1.53 +        ArrayList<String> firefoxHistory = mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY);
    1.54 +        mAsserter.ok(!firefoxHistory.contains(bigLinkUrl), "Check that the link opened in the first private tab was not saved", bigLinkUrl + " was not added to history");
    1.55 +        mAsserter.ok(!firefoxHistory.contains(blank1Url), "Check that the link opened in the private tab from the context menu was not saved", blank1Url + " was not added to history");
    1.56 +        mAsserter.ok(firefoxHistory.contains(blank2Url), "Check that the link opened in the normal tab was saved", blank2Url + " was added to history");
    1.57 +    }
    1.58 +
    1.59 +    private boolean isTabPrivate(String eventData) {
    1.60 +        try {
    1.61 +            JSONObject data = new JSONObject(eventData);
    1.62 +            return data.getBoolean("isPrivate");
    1.63 +        } catch (JSONException e) {
    1.64 +            mAsserter.ok(false, "Error parsing the event data", e.toString());
    1.65 +            return false;
    1.66 +        }
    1.67 +    }
    1.68 +}

mercurial