<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body onload="runTest()">
<script>

description("Tests that the GeolocationClient only starts updating when the page becomes visible");
window.jsTestIsAsync = true;

function geolocationWatchFunction()
{
}

function checkNotUpdatingAndShowPage()
{
    shouldBeFalse("testRunner.isGeolocationProviderActive()");
    debug("Changing page visibility to 'visible'");
    testRunner.setPageVisibility("visible");
}

function onVisibilityChange() {
    debug("Page visibility changed to " + !document.hidden);
    if (document.hidden) {
        shouldBeFalse("testRunner.isGeolocationProviderActive()");
        debug("Adding Geolocation watcher");
        navigator.geolocation.watchPosition(geolocationWatchFunction);
        setTimeout(checkNotUpdatingAndShowPage, 50);
    } else
        shouldBecomeEqual("testRunner.isGeolocationProviderActive()", "true", finishJSTest);
}

document.addEventListener("visibilitychange", onVisibilityChange, false)

if (window.testRunner) {
    testRunner.setGeolocationPermission(true);
    testRunner.setMockGeolocationPosition(1, 2, 3);
}

function runTest()
{
    debug("Page is initially visible");
    shouldBeFalse("document.hidden");
    shouldBeFalse("testRunner.isGeolocationProviderActive()");

    debug("Changing page visibility to 'hidden'");
    if (window.testRunner)
        testRunner.setPageVisibility("hidden");
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
