https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 952bda327c9bc8efae043de3071d0421efe702d1 authored by Boris Zbarsky on 26 March 2018, 18:16:29 UTC
part 3. Add testing for what mutation observers happen when doing DOMTokenList.replace.
Tip revision: 952bda3
eventTestHarness.js
iframe = document.createElement("IFRAME");
iframe.src = "about:blank";
document.body.appendChild(iframe);
iframe.contentWindow.document.body.textContent = "Nothing to see here.";

storageEventList = new Array();
iframe.contentWindow.onstorage = function(e) {
    window.parent.storageEventList.push(e);
};

function runAfterNStorageEvents(callback, expectedNumEvents)
{
    countStorageEvents(callback, expectedNumEvents, 0)
}

function countStorageEvents(callback, expectedNumEvents, times)
{
    function onTimeout()
    {
        var currentCount = storageEventList.length;
        if (currentCount == expectedNumEvents) {
            callback();
        } else if (currentCount > expectedNumEvents) {
            msg = "got at least " + currentCount + ", expected only " + expectedNumEvents + " events";
            callback(msg);
        } else if (times > 50) {
            msg = "Timeout: only got " + currentCount + ", expected " + expectedNumEvents + " events";
            callback(msg);
        } else {
            countStorageEvents(callback, expectedNumEvents, times+1);
        }
    }
    setTimeout(onTimeout, 20);
}

function clearStorage(storageName, callback)
{
    if (window[storageName].length === 0) {
        storageEventList = [];
        setTimeout(callback, 0);
    } else {
        window[storageName].clear();
        runAfterNStorageEvents(function() {
            storageEventList = [];
            callback();
        }, 1);
    }
}

function testStorages(testCallback)
{
    testCallback("sessionStorage");
    var hit = false;
    add_result_callback(function() {
        if (!hit) {
            hit = true;
            testCallback("localStorage");
        }
    });
}
back to top