Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
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 | } |