mobile/android/base/tests/testClearPrivateData.java.in
author Adrian Tamas <adrian.tamas@softvision.ro>
Mon, 26 Aug 2013 11:55:59 +0300
changeset 144942 8e79adf22902fdb3e6bdc6e8c46a95c97c6054c1
parent 144088 617b9050b5ed0d4c9d814038cbb99dd6f17e0099
child 146802 c24ba14732cd31279a1941680870a28c16773e68
permissions -rw-r--r--
Bug 908795 - Add a wait for test in testClearPrivateData to the history list check to give time to the database operations to happen. r=mleibovic

#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;

import @ANDROID_PACKAGE_NAME@.*;
import java.util.ArrayList;

public class testClearPrivateData extends AboutHomeTest {
    private final String BLANK1_TITLE = "Browser Blank Page 01";
    private final String BLANK2_TITLE = "Browser Blank Page 02";
    private final int TEST_WAIT_MS = 10000;

    @Override
    protected int getTestType() {
        return TEST_MOCHITEST;
    }

    public void testClearPrivateData() {
        blockForGeckoReady();
        clearHistory();
    }

    private void clearHistory() {
        // Loading a page and adding a second one as bookmark to have user made bookmarks and history
        String blank1 = getAbsoluteUrl("/robocop/robocop_blank_01.html");
        String blank2 = getAbsoluteUrl("/robocop/robocop_blank_02.html");

        inputAndLoadUrl(blank1);
        waitForText(BLANK1_TITLE);

        addOrUpdateMobileBookmark(BLANK2_TITLE, blank2);

        // Checking that the history list is not empty
        verifyHistoryCount(1);
        clearPrivateData();

        // Checking that history list is empty
        verifyHistoryCount(0);

        // Checking that the user made bookmark is not removed
        mAsserter.ok(isBookmark(blank2), "Checking that bookmarks have not been removed", "User made bookmarks were not removed with private data");
    }

    private void verifyHistoryCount(final int expectedCount) {
        boolean match = waitForTest( new BooleanTest() {
            public boolean test() {
                return (getBrowserDBUrls(BrowserDataType.HISTORY).size() == expectedCount);
            }
        }, TEST_WAIT_MS);
        mAsserter.ok(match, "Checking that the number of history items is correct", String.valueOf(expectedCount) + " history items present in the database");
    }
}