<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test.js"></script>
<iframe id="testFrame" src="about:blank"></iframe>
<script>
description("Tests that Navigator properties do not get GC'd before their Navigator object.");
jsTestIsAsync = true;

var navigatorProperties = [ "geolocation", "mimeTypes", "plugins" ];
if (navigator.serviceWorker)
    navigatorProperties.push("serviceWorker");

onload = function() {
    frameNavigator = document.getElementById("testFrame").contentWindow.navigator;
    for (let navigatorProperty of navigatorProperties)
        eval("frameNavigator." + navigatorProperty + ".foo = 1;");
    document.getElementById("testFrame").remove();
    for (let navigatorProperty of navigatorProperties)
        shouldBe("frameNavigator." + navigatorProperty + ".foo", "1");
    debug("");
    gc();
    for (let navigatorProperty of navigatorProperties)
        shouldBe("frameNavigator." + navigatorProperty + ".foo", "1");
    debug("");
    setTimeout(() => {
        gc();
        for (let navigatorProperty of navigatorProperties)
            shouldBe("frameNavigator." + navigatorProperty + ".foo", "1");
        finishJSTest();
    }, 10);
}
</script>
</body>
