Bug 1083879 - Add robocop test for popup blocker. r=rnewman, a=lsblakk
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 17 Oct 2014 15:42:43 -0700
changeset 233538 16b3bd0d5ebf2d85eb3eb24a73d3a33f988e98fb
parent 233537 e40a9b0757b742f948fd87143190258d38b1aa58
child 233539 547fe9ee7948becf5171d888f1211a7ee672ca88
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lsblakk
bugs1083879
milestone35.0a2
Bug 1083879 - Add robocop test for popup blocker. r=rnewman, a=lsblakk
mobile/android/base/tests/StringHelper.java
mobile/android/base/tests/robocop_popup.html
mobile/android/base/tests/testDoorHanger.java
--- a/mobile/android/base/tests/StringHelper.java
+++ b/mobile/android/base/tests/StringHelper.java
@@ -93,16 +93,17 @@ public class StringHelper {
     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_BLANK_PAGE_04_URL = "/robocop/robocop_blank_04.html";
     public static final String ROBOCOP_BLANK_PAGE_05_URL = "/robocop/robocop_blank_05.html";
     public static final String ROBOCOP_BOXES_URL = "/robocop/robocop_boxes.html";
     public static final String ROBOCOP_GEOLOCATION_URL = "/robocop/robocop_geolocation.html";
     public static final String ROBOCOP_LOGIN_URL = "/robocop/robocop_login.html";
+    public static final String ROBOCOP_POPUP_URL = "/robocop/robocop_popup.html";
     public static final String ROBOCOP_OFFLINE_STORAGE_URL = "/robocop/robocop_offline_storage.html";
     public static final String ROBOCOP_PICTURE_LINK_URL = "/robocop/robocop_picture_link.html";
     public static final String ROBOCOP_SEARCH_URL = "/robocop/robocop_search.html";
     public static final String ROBOCOP_TEXT_PAGE_URL = "/robocop/robocop_text_page.html";
     public static final String ROBOCOP_ADOBE_FLASH_URL = "/robocop/robocop_adobe_flash.html";
     public static final String ROBOCOP_INPUT_URL = "/robocop/robocop_input.html";
 
     private static final String ROBOCOP_JS_HARNESS_URL = "/robocop/robocop_javascript.html";
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/robocop_popup.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="UTF-8">
+    <title>Page creating a popup</title>
+  </head>
+  <body>
+    <script type="text/javascript">
+      window.open("data:text/plain;charset=utf-8,a", "a");
+    </script>
+  </body>
+</html>
--- a/mobile/android/base/tests/testDoorHanger.java
+++ b/mobile/android/base/tests/testDoorHanger.java
@@ -152,16 +152,87 @@ public class testDoorHanger extends Base
         // Load login page
         inputAndLoadUrl(LOGIN_URL);
         waitForText(LOGIN_MESSAGE);
 
         // Test doorhanger is dismissed when tapping "Save" and is no longer triggered
         mSolo.clickOnButton(LOGIN_ALLOW);
         waitForTextDismissed(LOGIN_MESSAGE);
         mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger notification is hidden when allowing saving password");
+
+        testPopupBlocking();
+    }
+
+    private void testPopupBlocking() {
+        String POPUP_URL = getAbsoluteUrl(StringHelper.ROBOCOP_POPUP_URL);
+        String POPUP_MESSAGE = "prevented this site from opening";
+        String POPUP_ALLOW = "Show";
+        String POPUP_DENY = "Don't show";
+
+        try {
+            JSONObject jsonPref = new JSONObject();
+            jsonPref.put("name", "dom.disable_open_during_load");
+            jsonPref.put("type", "bool");
+            jsonPref.put("value", true);
+            setPreferenceAndWaitForChange(jsonPref);
+        } catch (JSONException e) {
+            mAsserter.ok(false, "exception setting preference", e.toString());
+        }
+
+        // Load page with popup
+        inputAndLoadUrl(POPUP_URL);
+        waitForText(POPUP_MESSAGE);
+        mAsserter.is(mSolo.searchText(POPUP_MESSAGE), true, "Popup blocker is displayed");
+
+        // Wait for the popup to be shown.
+        Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
+
+        waitForCheckBox();
+        mSolo.clickOnCheckBox(0);
+        mSolo.clickOnButton(POPUP_ALLOW);
+        waitForTextDismissed(POPUP_MESSAGE);
+        mAsserter.is(mSolo.searchText(POPUP_MESSAGE), false, "Popup blocker is hidden when popup allowed");
+
+        try {
+            final JSONObject data = new JSONObject(tabEventExpecter.blockForEventData());
+
+            // Check to make sure the popup window was opened.
+            mAsserter.is("data:text/plain;charset=utf-8,a", data.getString("uri"), "Checking popup URL");
+
+            // Close the popup window.
+            closeTab(data.getInt("tabID"));
+
+        } catch (JSONException e) {
+            mAsserter.ok(false, "exception getting event data", e.toString());
+        }
+        tabEventExpecter.unregisterListener();
+
+        // Load page with popup
+        inputAndLoadUrl(POPUP_URL);
+        waitForText(POPUP_MESSAGE);
+        mAsserter.is(mSolo.searchText(POPUP_MESSAGE), true, "Popup blocker is displayed");
+
+        waitForCheckBox();
+        mSolo.clickOnCheckBox(0);
+        mSolo.clickOnButton(POPUP_DENY);
+        waitForTextDismissed(POPUP_MESSAGE);
+        mAsserter.is(mSolo.searchText(POPUP_MESSAGE), false, "Popup blocker is hidden when popup denied");
+
+        // Check that we're on the same page to verify that the popup was not shown.
+        verifyUrl(POPUP_URL);
+
+        try {
+            JSONObject jsonPref = new JSONObject();
+            jsonPref.put("name", "dom.disable_open_during_load");
+            jsonPref.put("type", "bool");
+            jsonPref.put("value", false);
+            setPreferenceAndWaitForChange(jsonPref);
+        } catch (JSONException e) {
+            mAsserter.ok(false, "exception setting preference", e.toString());
+        }
     }
 
     // wait for a CheckBox view that is clickable
     private void waitForCheckBox() {
         waitForCondition(new Condition() {
             @Override
             public boolean isSatisfied() {
                 for (CheckBox view : mSolo.getCurrentViews(CheckBox.class)) {