mobile/android/base/tests/testPermissions.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testPermissions.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import java.util.ArrayList;
     1.7 +
     1.8 +import org.mozilla.gecko.Actions;
     1.9 +import org.mozilla.gecko.PaintedSurface;
    1.10 +
    1.11 +import android.widget.CheckBox;
    1.12 +
    1.13 +public class testPermissions extends PixelTest {
    1.14 +    public void testPermissions() {
    1.15 +        blockForGeckoReady();
    1.16 +
    1.17 +        geolocationTest();
    1.18 +    }
    1.19 +
    1.20 +    private void geolocationTest() {
    1.21 +        Actions.RepeatedEventExpecter paintExpecter;
    1.22 +
    1.23 +        // Test geolocation notification
    1.24 +        loadAndPaint(getAbsoluteUrl("/robocop/robocop_geolocation.html"));
    1.25 +        waitForText("wants your location");
    1.26 +
    1.27 +        // Uncheck the "Don't ask again for this site" checkbox
    1.28 +        ArrayList<CheckBox> checkBoxes = mSolo.getCurrentViews(CheckBox.class);
    1.29 +        mAsserter.ok(checkBoxes.size() == 1, "checkbox count", "only one checkbox visible");
    1.30 +        mAsserter.ok(mSolo.isCheckBoxChecked(0), "checkbox checked", "checkbox is checked");
    1.31 +        mSolo.clickOnCheckBox(0);
    1.32 +        mAsserter.ok(!mSolo.isCheckBoxChecked(0), "checkbox not checked", "checkbox is not checked");
    1.33 +
    1.34 +        // Test "Share" button functionality with unchecked checkbox
    1.35 +        paintExpecter = mActions.expectPaint();
    1.36 +        mSolo.clickOnText("Share");
    1.37 +        PaintedSurface painted = waitForPaint(paintExpecter);
    1.38 +        paintExpecter.unregisterListener();
    1.39 +        try {
    1.40 +            mAsserter.ispixel(painted.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
    1.41 +        } finally {
    1.42 +            painted.close();
    1.43 +        }
    1.44 +
    1.45 +        // Re-trigger geolocation notification
    1.46 +        reloadAndPaint();
    1.47 +        waitForText("wants your location");
    1.48 +
    1.49 +        // Make sure the checkbox is checked this time
    1.50 +        mAsserter.ok(mSolo.isCheckBoxChecked(0), "checkbox checked", "checkbox is checked");
    1.51 +
    1.52 +        // Test "Share" button functionality with checked checkbox
    1.53 +        paintExpecter = mActions.expectPaint();
    1.54 +        mSolo.clickOnText("Share");
    1.55 +        painted = waitForPaint(paintExpecter);
    1.56 +        paintExpecter.unregisterListener();
    1.57 +        try {
    1.58 +            mAsserter.ispixel(painted.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
    1.59 +        } finally {
    1.60 +            painted.close();
    1.61 +        }
    1.62 +
    1.63 +        // When we reload the page, location should be automatically shared
    1.64 +        painted = reloadAndGetPainted();
    1.65 +        try {
    1.66 +            mAsserter.ispixel(painted.getPixelAt(10, 10), 0, 0x80, 0, "checking page background is green");
    1.67 +        } finally {
    1.68 +            painted.close();
    1.69 +        }
    1.70 +    }
    1.71 +}

mercurial