michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import java.util.ArrayList; michael@0: michael@0: import org.json.JSONException; michael@0: import org.json.JSONObject; michael@0: import org.mozilla.gecko.Actions; michael@0: michael@0: /** michael@0: * The test loads a new private tab and loads a page with a big link on it michael@0: * Opens the link in a new private tab and checks that it is private michael@0: * Adds a new normal tab and loads a 3rd URL michael@0: * 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: */ michael@0: public class testPrivateBrowsing extends ContentContextMenuTest { michael@0: michael@0: public void testPrivateBrowsing() { michael@0: String bigLinkUrl = getAbsoluteUrl(StringHelper.ROBOCOP_BIG_LINK_URL); michael@0: String blank1Url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL); michael@0: String blank2Url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL); michael@0: michael@0: blockForGeckoReady(); michael@0: michael@0: inputAndLoadUrl(StringHelper.ABOUT_BLANK_URL); michael@0: michael@0: addTab(bigLinkUrl, StringHelper.ROBOCOP_BIG_LINK_TITLE, true); michael@0: michael@0: verifyTabCount(1); michael@0: michael@0: // Open the link context menu and verify the options michael@0: verifyContextMenuItems(StringHelper.CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB); michael@0: michael@0: // Check that "Open Link in New Tab" is not in the menu michael@0: 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: michael@0: // Open the link in a new private tab and check that it is private michael@0: Actions.EventExpecter privateTabEventExpector = mActions.expectGeckoEvent("Tab:Added"); michael@0: mSolo.clickOnText(StringHelper.CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB[0]); michael@0: String eventData = privateTabEventExpector.blockForEventData(); michael@0: privateTabEventExpector.unregisterListener(); michael@0: michael@0: 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: verifyTabCount(2); michael@0: michael@0: // Open a normal tab to check later that it was registered in the Firefox Browser History michael@0: addTab(blank2Url, StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE, false); michael@0: verifyTabCount(2); michael@0: michael@0: // Get the history list and check that the links open in private browsing are not saved michael@0: ArrayList firefoxHistory = mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY); michael@0: 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: 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: mAsserter.ok(firefoxHistory.contains(blank2Url), "Check that the link opened in the normal tab was saved", blank2Url + " was added to history"); michael@0: } michael@0: michael@0: private boolean isTabPrivate(String eventData) { michael@0: try { michael@0: JSONObject data = new JSONObject(eventData); michael@0: return data.getBoolean("isPrivate"); michael@0: } catch (JSONException e) { michael@0: mAsserter.ok(false, "Error parsing the event data", e.toString()); michael@0: return false; michael@0: } michael@0: } michael@0: }