Bug 729485 - Test for content permissions prompts. r=mbrubeck,kats
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 16 May 2012 12:00:45 -0700
changeset 95597 023c65a66288e5d828647bb81a0cc2954d027eb3
parent 95596 62b0be6431ad638ed3c5267d1871de918818e259
child 95598 a8f13db7bff96dc165ce56afbcd7871af5e1cc4b
push idunknown
push userunknown
push dateunknown
reviewersmbrubeck, kats
bugs729485
milestone15.0a1
Bug 729485 - Test for content permissions prompts. r=mbrubeck,kats
mobile/android/base/tests/PixelTest.java.in
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/robocop_geolocation.html
mobile/android/base/tests/testPermissions.java.in
--- a/mobile/android/base/tests/PixelTest.java.in
+++ b/mobile/android/base/tests/PixelTest.java.in
@@ -13,16 +13,32 @@ class PixelTest extends BaseTest {
         PaintedSurface p = mDriver.getPaintedSurface();
         if (p == null) {
             mAsserter.ok(p != null, "checking that painted surface loaded", 
                  "painted surface loaded");
         }
         return p;
     }
 
+    protected final PaintedSurface reloadAndPaint() {
+        Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
+
+        mActions.sendSpecialKey(Actions.SpecialKey.MENU);
+        mSolo.waitForText("Reload");
+        mSolo.clickOnText("Reload");
+
+        paintExpecter.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;
+    }
+
     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/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -9,16 +9,17 @@
 [testOverscroll]
 [testAxisLocking]
 [testAboutPage]
 [testWebContentContextMenu]
 [testPasswordProvider]
 [testPasswordEncrypt]
 [testFormHistory]
 [testBrowserProvider]
+[testPermissions]
 # [testJarReader] # see bug 738890
 
 # Used for Talos, please don't use in mochitest
 #[testPan]
 #[testCheck]
 #[testCheck2]
 #[testCheck3]
 #[testBrowserProviderPerf]
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/robocop_geolocation.html
@@ -0,0 +1,17 @@
+<html>
+<title>Geolocation Test Page</title>
+<body>
+<script>
+  function clb(position) {
+    // Show a green background if permission is granted
+    document.body.style.background = "#008000";
+  }
+  function err(error) {
+    // Show a red background if permission is denied
+    if (error.code == error.PERMISSION_DENIED)
+      document.body.style.background = "#FF0000";
+  }
+  navigator.geolocation.getCurrentPosition(clb, err, {timeout: 0});
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testPermissions.java.in
@@ -0,0 +1,55 @@
+#filter substitution
+package @ANDROID_PACKAGE_NAME@.tests;
+
+import @ANDROID_PACKAGE_NAME@.*;
+
+import android.widget.CheckBox;
+import java.util.ArrayList;
+
+public class testPermissions extends PixelTest {
+    private PaintedSurface mPaintedSurface;
+    private Actions.RepeatedEventExpecter mPaintExpecter;
+
+    public void testPermissions() {
+        setTestType("mochitest");
+        mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
+
+        geolocationTest();
+    }
+
+    private void geolocationTest() {
+        // Test geolocation notification
+        mPaintedSurface = loadAndPaint(getAbsoluteUrl("/robocop/robocop_geolocation.html"));
+        mSolo.waitForText("wants your location");
+
+        // Uncheck the "Don't ask again for this site" checkbox
+        ArrayList<CheckBox> checkBoxes = mSolo.getCurrentCheckBoxes();
+        mAsserter.ok(checkBoxes.size() == 1, "checkbox count", "only one checkbox visible");
+        mAsserter.ok(mSolo.isCheckBoxChecked(0), "checkbox checked", "checkbox is checked");
+        mSolo.clickOnCheckBox(0);
+        mAsserter.ok(!mSolo.isCheckBoxChecked(0), "checkbox not checked", "checkbox is not checked");
+
+        // Test "Share" button functionality with unchecked checkbox
+        mPaintExpecter = mActions.expectPaint();
+        mSolo.clickOnText("Share");
+        mPaintedSurface = waitForPaint(mPaintExpecter);
+        mAsserter.ispixel(mPaintedSurface.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
+
+        // Re-trigger geolocation notification
+        reloadAndPaint();
+        mSolo.waitForText("wants your location");
+
+        // Make sure the checkbox is checked this time
+        mAsserter.ok(mSolo.isCheckBoxChecked(0), "checkbox checked", "checkbox is checked");
+
+        // Test "Share" button functionality with checked checkbox
+        mPaintExpecter = mActions.expectPaint();
+        mSolo.clickOnText("Share");
+        mPaintedSurface = waitForPaint(mPaintExpecter);
+        mAsserter.ispixel(mPaintedSurface.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
+
+        // When we reload the page, location should be automatically shared
+        mPaintedSurface = reloadAndPaint();
+        mAsserter.ispixel(mPaintedSurface.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
+    }
+}