mobile/android/base/tests/testPrivateBrowsing.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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

mercurial