chromium/third_party/blink/web_tests/fast/canvas/canvas-font-cache.html

<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<canvas id='c'></canvas>
<script>
test(function(t) {

    // The reason this is implemented as a layout test instead of a unit test (see CanvasFontCacheTest.cpp)
    // is to exercise interactions with animation frames.    
    var cacheLimit = 0;
    cacheLimit = internals.canvasFontCacheMaxFonts();
    requestAnimationFrame(step1);
    
    var ctx = document.getElementById('c').getContext('2d');
    
    function step1()
    {
        for (var i = 0; i < cacheLimit + 1; i ++) {
            ctx.font = (1 + i) + 'px sans-serif';
            ctx.fillText('a', 0, 50);
        }
        assert_true(internals.isInCanvasFontCache(document, "1px sans-serif"));
        requestAnimationFrame(step2);
    }
    
    function step2()
    {
        // Pruning of the cache is expected to happen between tasks
        assert_false(internals.isInCanvasFontCache(document, "1px sans-serif"));
        assert_true(internals.isInCanvasFontCache(document, "2px sans-serif")); 
    }
    
}, 'Test that createImageBitmap from a bitmaprenderer canvas produces correct result');
</script>