|
1 package org.mozilla.gecko.tests; |
|
2 |
|
3 import java.util.ArrayList; |
|
4 |
|
5 import org.json.JSONException; |
|
6 import org.json.JSONObject; |
|
7 import org.mozilla.gecko.Actions; |
|
8 |
|
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 { |
|
16 |
|
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); |
|
21 |
|
22 blockForGeckoReady(); |
|
23 |
|
24 inputAndLoadUrl(StringHelper.ABOUT_BLANK_URL); |
|
25 |
|
26 addTab(bigLinkUrl, StringHelper.ROBOCOP_BIG_LINK_TITLE, true); |
|
27 |
|
28 verifyTabCount(1); |
|
29 |
|
30 // Open the link context menu and verify the options |
|
31 verifyContextMenuItems(StringHelper.CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB); |
|
32 |
|
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"); |
|
35 |
|
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(); |
|
41 |
|
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); |
|
44 |
|
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); |
|
48 |
|
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 } |
|
55 |
|
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 } |