Bug 888277 - Create a new Robocop test to test private browsing. r=gbrown
authorAdrian Tamas <adrian.tamas@softvision.ro>
Tue, 25 Jun 2013 08:45:14 +0300
changeset 164300 093a5e2b407c66b568aa147b5d1c93719db71d52
parent 164299 fe160ec1e0ad4de44050fffdb6f187f885da085c
child 164301 855adbbb86046e0252d957a28cb0d4218df1146c
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs888277
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 888277 - Create a new Robocop test to test private browsing. r=gbrown
mobile/android/base/tests/ContentContextMenuTest.java.in
mobile/android/base/tests/PixelTest.java.in
mobile/android/base/tests/StringHelper.java.in
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/testPrivateBrowsing.java.in
--- a/mobile/android/base/tests/ContentContextMenuTest.java.in
+++ b/mobile/android/base/tests/ContentContextMenuTest.java.in
@@ -5,17 +5,17 @@ import @ANDROID_PACKAGE_NAME@.*;
 import android.content.ContentResolver;
 import android.util.DisplayMetrics;
 
 import java.lang.reflect.Method;
 
 /**
  * This class covers interactions with the context menu opened from web content
  */
-abstract class ContentContextMenuTest extends BaseTest {
+abstract class ContentContextMenuTest extends PixelTest {
     private static final int MAX_TEST_TIMEOUT = 10000;
 
     // This method opens the context menu of any web content. It assumes that the page is already loaded
     protected void openWebContentContextMenu(String waitText) {
         DisplayMetrics dm = new DisplayMetrics();
         getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
 
         // The web content we are trying to open the context menu for should be positioned at the top of the page, at least 60px heigh and aligned to the middle
--- a/mobile/android/base/tests/PixelTest.java.in
+++ b/mobile/android/base/tests/PixelTest.java.in
@@ -42,16 +42,32 @@ abstract class PixelTest extends BaseTes
         return p;
     }
 
     protected final void reloadAndPaint() {
         PaintedSurface painted = reloadAndGetPainted();
         painted.close();
     }
 
+    public void addTab(String url, String title, boolean isPrivate) {
+        Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
+        Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
+        if (isPrivate) {
+            selectMenuItem(StringHelper.NEW_PRIVATE_TAB_LABEL);
+        } else {
+            selectMenuItem(StringHelper.NEW_TAB_LABEL);
+        }
+        tabEventExpecter.blockForEvent();
+        contentEventExpecter.blockForEvent();
+        loadAndPaint(url);
+        tabEventExpecter.unregisterListener();
+        contentEventExpecter.unregisterListener();
+        mAsserter.ok(waitForText(title), "Checking that the page has loaded", "The page has loaded");
+    }
+
     protected final PaintedSurface waitForPaint(Actions.RepeatedEventExpecter expecter) {
         expecter.blockUntilClear(PAINT_CLEAR_DELAY);
         PaintedSurface p = mDriver.getPaintedSurface();
         if (p == null) {
             mAsserter.ok(p != null, "checking that painted surface loaded", 
                  "painted surface loaded");
         }
         return p;
--- a/mobile/android/base/tests/StringHelper.java.in
+++ b/mobile/android/base/tests/StringHelper.java.in
@@ -12,16 +12,44 @@ class StringHelper {
     };
     public static final String[] DEFAULT_BOOKMARKS_URLS = new String[] {
         "about:firefox",
         "http://support.mozilla.org/en-US/products/mobile",
         "https://addons.mozilla.org/en-US/android/"
     };
     public static final int DEFAULT_BOOKMARKS_COUNT = DEFAULT_BOOKMARKS_TITLES.length;
 
+    // About pages
+    public static final String ABOUT_BLANK_URL = "about:blank";
+    public static final String ABOUT_FIREFOX_URL = "about:firefox";
+    public static final String ABOUT_DOWNLOADS_URL = "about:downloads";
+    public static final String ABOUT_ADDONS_URL = "about:addons";
+    public static final String ABOUT_APPS_URL = "about:apps";
+
+    // Context Menu menu items
+    public static final String[] CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB = new String[] {
+        "Open Link in Private Tab", 
+        "Copy Link", 
+        "Share Link", 
+        "Bookmark Link"
+    };
+
+    public static final String[] CONTEXT_MENU_ITEMS_IN_NORMAL_TAB = new String[] {
+        "Open Link in New Tab",
+        "Open Link in Private Tab", 
+        "Copy Link", 
+        "Share Link", 
+        "Bookmark Link"
+    };
+
+    public static final String[] BOOKMARKS_OPTIONS_CONTEXTMENU_ITEMS = new String[] {
+        "Edit",
+        "Add to Home Screen"
+    };
+
     // Robocop page urls
     // Note: please use getAbsoluteUrl(String url) on each robocop url to get the correct url
     public static final String ROBOCOP_BIG_LINK_URL = "/robocop/robocop_big_link.html";
     public static final String ROBOCOP_BIG_MAILTO_URL = "/robocop/robocop_big_mailto.html";
     public static final String ROBOCOP_BLANK_PAGE_01_URL = "/robocop/robocop_blank_01.html";
     public static final String ROBOCOP_BLANK_PAGE_02_URL = "/robocop/robocop_blank_02.html";
     public static final String ROBOCOP_BLANK_PAGE_03_URL = "/robocop/robocop_blank_03.html";
     public static final String ROBOCOP_BOXES_URL = "/robocop/robocop_boxes.html";
@@ -124,15 +152,9 @@ class StringHelper {
     public static final String FORWARD_LABEL = "Forward";
     public static final String BOOKMARK_LABEL = "Bookmark";
 
     // Bookmark Toast Notification
     public static final String BOOKMARK_ADDED_LABEL = "Bookmark added";
     public static final String BOOKMARK_REMOVED_LABEL = "Bookmark removed";
     public static final String BOOKMARK_UPDATED_LABEL = "Bookmark updated";
     public static final String BOOKMARK_OPTIONS_LABEL = "Options";
-
-    // Bookmark Options Context Menu items
-    public static final String[] BOOKMARKS_OPTIONS_CONTEXTMENU_ITEMS = new String[] {
-    "Edit",
-    "Add to Home Screen"
-    };
 }
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -38,14 +38,15 @@
 [testJarReader]
 [testDistribution]
 [testFindInPage]
 [testInputUrlBar]
 [testAddSearchEngine]
 [testImportFromAndroid]
 [testMasterPassword]
 [testDeviceSearchEngine]
+[testPrivateBrowsing]
 
 # Used for Talos, please don't use in mochitest
 #[testPan]
 #[testCheck]
 #[testCheck2]
 #[testBrowserProviderPerf]
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testPrivateBrowsing.java.in
@@ -0,0 +1,72 @@
+#filter substitution
+package @ANDROID_PACKAGE_NAME@.tests;
+
+import @ANDROID_PACKAGE_NAME@.*;
+
+import java.util.ArrayList;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * The test loads a new private tab and loads a page with a big link on it
+ * Opens the link in a new private tab and checks that it is private
+ * Adds a new normal tab and loads a 3rd URL
+ * 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
+ */
+public class testPrivateBrowsing extends ContentContextMenuTest {
+
+    @Override
+    protected int getTestType() {
+        return TEST_MOCHITEST;
+    }
+
+    public void testPrivateBrowsing() {
+        String bigLinkUrl = getAbsoluteUrl(StringHelper.ROBOCOP_BIG_LINK_URL);
+        String blank1Url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
+        String blank2Url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL);
+
+        blockForGeckoReady();
+
+        inputAndLoadUrl(StringHelper.ABOUT_BLANK_URL);
+
+        addTab(bigLinkUrl, StringHelper.ROBOCOP_BIG_LINK_TITLE, true);
+
+        verifyTabCount(1);
+
+        // Open the link context menu and verify the options
+        verifyContextMenuItems(StringHelper.CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB);
+
+        // Check that "Open Link in New Tab" is not in the menu
+        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");
+
+        // Open the link in a new private tab and check that it is private
+        Actions.EventExpecter privateTabEventExpector = mActions.expectGeckoEvent("Tab:Added");
+        mSolo.clickOnText(StringHelper.CONTEXT_MENU_ITEMS_IN_PRIVATE_TAB[0]);
+        String eventData = privateTabEventExpector.blockForEventData();
+        privateTabEventExpector.unregisterListener();
+
+        mAsserter.ok(isTabPrivate(eventData), "Checking if the new tab opened from the context menu was a private tab", "The tab was a private tab");
+        verifyTabCount(2);
+
+        // Open a normal tab to check later that it was registered in the Firefox Browser History
+        addTab(blank2Url, StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE, false);
+        verifyTabCount(2);
+
+        // Get the history list and check that the links open in private browsing are not saved
+        ArrayList<String> firefoxHistory = mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY);
+        mAsserter.ok(!firefoxHistory.contains(bigLinkUrl), "Check that the link opened in the first private tab was not saved", bigLinkUrl + " was not added to history");
+        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");
+        mAsserter.ok(firefoxHistory.contains(blank2Url), "Check that the link opened in the normal tab was saved", blank2Url + " was added to history");
+    }
+
+    private boolean isTabPrivate(String eventData) {
+        try {
+            JSONObject data = new JSONObject(eventData);
+            return data.getBoolean("isPrivate");
+        } catch (JSONException e) {
+            mAsserter.ok(false, "Error parsing the event data", e.toString());
+            return false;
+        }
+    }
+}