mobile/android/base/tests/testPrivateBrowsing.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 package org.mozilla.gecko.tests;
     3 import java.util.ArrayList;
     5 import org.json.JSONException;
     6 import org.json.JSONObject;
     7 import org.mozilla.gecko.Actions;
     9 /**
    10  * The test loads a new private tab and loads a page with a big link on it
    11  * Opens the link in a new private tab and checks that it is private
    12  * Adds a new normal tab and loads a 3rd URL
    13  * 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
    14  */
    15 public class testPrivateBrowsing extends ContentContextMenuTest {
    17     public void testPrivateBrowsing() {
    18         String bigLinkUrl = getAbsoluteUrl(StringHelper.ROBOCOP_BIG_LINK_URL);
    19         String blank1Url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
    20         String blank2Url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL);
    22         blockForGeckoReady();
    24         inputAndLoadUrl(StringHelper.ABOUT_BLANK_URL);
    26         addTab(bigLinkUrl, StringHelper.ROBOCOP_BIG_LINK_TITLE, true);
    28         verifyTabCount(1);
    30         // Open the link context menu and verify the options
    31         verifyContextMenuItems(StringHelper.CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB);
    33         // Check that "Open Link in New Tab" is not in the menu
    34         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");
    36         // Open the link in a new private tab and check that it is private
    37         Actions.EventExpecter privateTabEventExpector = mActions.expectGeckoEvent("Tab:Added");
    38         mSolo.clickOnText(StringHelper.CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB[0]);
    39         String eventData = privateTabEventExpector.blockForEventData();
    40         privateTabEventExpector.unregisterListener();
    42         mAsserter.ok(isTabPrivate(eventData), "Checking if the new tab opened from the context menu was a private tab", "The tab was a private tab");
    43         verifyTabCount(2);
    45         // Open a normal tab to check later that it was registered in the Firefox Browser History
    46         addTab(blank2Url, StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE, false);
    47         verifyTabCount(2);
    49         // Get the history list and check that the links open in private browsing are not saved
    50         ArrayList<String> firefoxHistory = mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY);
    51         mAsserter.ok(!firefoxHistory.contains(bigLinkUrl), "Check that the link opened in the first private tab was not saved", bigLinkUrl + " was not added to history");
    52         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");
    53         mAsserter.ok(firefoxHistory.contains(blank2Url), "Check that the link opened in the normal tab was saved", blank2Url + " was added to history");
    54     }
    56     private boolean isTabPrivate(String eventData) {
    57         try {
    58             JSONObject data = new JSONObject(eventData);
    59             return data.getBoolean("isPrivate");
    60         } catch (JSONException e) {
    61             mAsserter.ok(false, "Error parsing the event data", e.toString());
    62             return false;
    63         }
    64     }
    65 }

mercurial