# Copyright (c) 2010 Philip Taylor
# Released under the BSD license and W3C Test Suite License: see LICENSE.txt

framed: |
    <!DOCTYPE html>
    <title>Canvas test: %(name)s</title>
    <script src="../tests.js"></script>
    <link rel="stylesheet" href="../tests.css">
    %(fonts)s<body class="framed show_output">
    <h1>
    <a href="%(name)s.html" target="_parent">%(name_wrapped)s</a>
    </h1>
    <p><a href="#" id="show_output" onclick="document.body.className += ' show_output'; return false">[show output]</a>
    %(fonthack)s<p class="output">Actual output:</p>
    <canvas id="c" class="output" %(canvas)s>%(fallback)s</canvas>
    %(expected)s
    <ul id="d"></ul>
    <script>
    _addTest(function(canvas, ctx) {

    %(code)s

    });
    </script>
    %(images)s

standalone: |
    <!DOCTYPE html>
    <title>Canvas test: %(name)s</title>
    <script src="../tests.js"></script>
    <link rel="stylesheet" href="../tests.css">
    <link rel="prev" href="%(prev)s.html" title="%(prev)s">
    <link rel="next" href="%(next)s.html" title="%(next)s">
    %(fonts)s<body class="show_output">
    <p>
     <a href="%(prev)s.html" accesskey="p" title="[p] %(prev)s">&lt;</a>
     <a href="index.html">[index]</a>
     <a href="%(next)s.html" accesskey="n" title="[n] %(next)s">&gt;</a>
    <h1>%(backrefs)s</h1>
    <p class="desc">%(desc)s</p>
    <div class="refs">References:
    <ul>
    %(refs)s
    </ul>
    </div>
    %(notes)s
    %(fonthack)s<p class="output">Actual output:</p>
    <canvas id="c" class="output" %(canvas)s>%(fallback)s</canvas>
    %(expected)s
    <ul id="d"></ul>
    <script>
    _addTest(function(canvas, ctx) {

    %(code)s

    });
    </script>
    %(images)s

minimal: |
    <!DOCTYPE html>
    <html class="minimal">
    <title>Canvas test: %(name)s</title>
    <script src="../tests.js"></script>
    <link rel="stylesheet" href="../tests.css">
    <link rel="prev" href="minimal.%(prev)s.html" title="%(prev)s">
    <link rel="next" href="minimal.%(next)s.html" title="%(next)s">
    %(fonts)s<body>
    <p id="passtext">Pass</p>
    <p id="failtext">Fail</p>
    <!-- TODO: handle "script did not run" case -->
    %(fonthack)s<p class="output">These images should be identical:</p>
    <canvas id="c" class="output" %(canvas)s>%(fallback)s</canvas>
    %(expected)s
    <ul id="d"></ul>
    <script>
    _addTest(function(canvas, ctx) {

    %(code)s

    });
    </script>
    %(images)s

w3c: |
    <!DOCTYPE html>
    <!-- DO NOT EDIT! This test has been generated by /2dcontext/tools/gentest.py. -->
    <title>Canvas test: %(name)s</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/2dcontext/resources/canvas-tests.js"></script>
    <link rel="stylesheet" href="/2dcontext/resources/canvas-tests.css">
    %(fonts)s<body class="show_output">

    <h1>%(name)s</h1>
    <p class="desc">%(desc)s</p>

    %(notes)s
    %(fonthack)s<p class="output">Actual output:</p>
    <canvas id="c" class="output" %(canvas)s>%(fallback)s</canvas>
    %(expected)s
    <ul id="d"></ul>
    <script>
    var t = async_test("%(escaped_desc)s");
    _addTest(function(canvas, ctx) {

    %(code)s

    });
    </script>
    %(scripts)s%(images)s

mochitest: |
    <!DOCTYPE HTML>
    <title>%(mochi_name_fn)s</title>
    %(mochi_desc)s<script src="/MochiKit/MochiKit.js"></script>
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" href="/tests/SimpleTest/test.css">
    %(fonts)s<body><!-- [[[ test_%(mochi_name)s.html ]]] -->

    <p>Canvas test: %(mochi_name)s</p>
    %(mochi_desc)s%(fonthack)s<canvas id="c" %(canvas)s>%(fallback)s</canvas>
    <script>

    function %(mochi_name_fn)s() {

    var canvas = document.getElementById('c');
    var ctx = canvas.getContext('2d');

    %(mochi_code)s

    }
    </script>
    %(mochi_images)s

mochitest.isPixel: |
    function isPixel(ctx, x,y, r,g,b,a, pos, colour, d) {
        var pixel = ctx.getImageData(x, y, 1, 1);
        var pr = pixel.data[0],
            pg = pixel.data[1],
            pb = pixel.data[2],
            pa = pixel.data[3];
        ok(r-d <= pr && pr <= r+d &&
           g-d <= pg && pg <= g+d &&
           b-d <= pb && pb <= b+d &&
           a-d <= pa && pa <= a+d,
           "pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d);
    }

mochitest.todo_isPixel: |
    function todo_isPixel(ctx, x,y, r,g,b,a, pos, colour, d) {
        var pixel = ctx.getImageData(x, y, 1, 1);
        var pr = pixel.data[0],
            pg = pixel.data[1],
            pb = pixel.data[2],
            pa = pixel.data[3];
        todo(r-d <= pr && pr <= r+d &&
           g-d <= pg && pg <= g+d &&
           b-d <= pb && pb <= b+d &&
           a-d <= pa && pa <= a+d,
           "pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d);
    }

mochitest.deferTest: |
    function deferTest() {
        _deferred = true;
    }

mochitest.wrapFunction: |
    function wrapFunction(f) {
        return function () {
            f.apply(null, arguments);
            SimpleTest.finish();
        }
    }

mochitest.exception: |
    var _thrown_outer = false;
    try {

    %s
    } catch (e) {
        _thrown_outer = true;
    }
    todo(!_thrown_outer, 'should not throw exception');

mochitest.Makefile: |
    #
    # ***** BEGIN LICENSE BLOCK *****
    # Version: MPL 1.1/GPL 2.0/LGPL 2.1
    #
    # The contents of this file are subject to the Mozilla Public License Version
    # 1.1 (the "License"); you may not use this file except in compliance with
    # the License. You may obtain a copy of the License at
    # http://www.mozilla.org/MPL/
    #
    # Software distributed under the License is distributed on an "AS IS" basis,
    # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    # for the specific language governing rights and limitations under the
    # License.
    #
    # The Original Code is mozilla.org code.
    #
    # The Initial Developer of the Original Code is
    # Mozilla Corporation.
    # Portions created by the Initial Developer are Copyright (C) 2007
    # the Initial Developer. All Rights Reserved.
    #
    # Contributor(s):
    #   Philip Taylor <philip.taylor@cl.cam.ac.uk>
    #
    # Alternatively, the contents of this file may be used under the terms of
    # either of the GNU General Public License Version 2 or later (the "GPL"),
    # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    # in which case the provisions of the GPL or the LGPL are applicable instead
    # of those above. If you wish to allow use of your version of this file only
    # under the terms of either the GPL or the LGPL, and not to allow others to
    # use your version of this file under the terms of the MPL, indicate your
    # decision by deleting the provisions above and replace them with the notice
    # and other provisions required by the GPL or the LGPL. If you do not delete
    # the provisions above, a recipient may use your version of this file under
    # the terms of any one of the MPL, the GPL or the LGPL.
    #
    # ***** END LICENSE BLOCK *****

    DEPTH		= ../../..
    topsrcdir	= @top_srcdir@
    srcdir		= @srcdir@
    VPATH		= @srcdir@
    relativesrcdir  = content/canvas/test

    include $(DEPTH)/config/autoconf.mk
    include $(topsrcdir)/config/rules.mk


index.frame: |
    <!DOCTYPE html>
    <title>Canvas tests - %(category)s.*</title>
    <link rel="stylesheet" href="../frame.css">
    <p><a href="index.html">[index]</a>
    <h1>%(backrefs)s.*</h1>
    <p>

# FF trunk doesn't do onload in object, so use iframe instead
#index.frame.item: |-
#    <object width="200" height="220" data="framed.%s.html">(object fallback)</object><!--
#    -->
index.frame.item: |-
    <iframe width="200" height="220" src="framed.%s.html">(iframe fallback)</iframe><!--
    -->

index.w3c.frame: |
    <!DOCTYPE html>
    <title>Canvas tests - %(category)s.*</title>
    <link rel="stylesheet" href="/2dcontext/resources/canvas-frame.css">
    <p><a href="index.html">[index]</a>
    <h1>%(backrefs)s.*</h1>
    <p>

index.w3c.frame.item: |-
    <iframe width="320" height="240" src="%s.html">(iframe fallback)</iframe><!--
    -->

index: |
    <!DOCTYPE html>
    <title>Canvas tests - index</title>
    <link rel="stylesheet" href="../index.css">
    <script>
    function expand(obj) {
        obj.parentNode.className = obj.parentNode.className ? "" : "expand";
        return false;
    }
    </script>

    <h1><code>&lt;canvas&gt;</code> tests</h1>

    <p>Developed by <a href="mailto:excors&#64;gmail.com">Philip Taylor</a>.
    Last updated %(updated)s.

    <p>Based on the <a
    href="http://www.whatwg.org/specs/web-apps/current-work/#the-canvas">HTML</a>
    Draft Standard &mdash; 22 February 2010. See also the <a
    href="spec.html">annotated specification</a>.

    <p>See <a href="results.html">test results</a> for some browsers.
    (Generated semi-automatically via the <a
    href="../reportgenentry.html">report generator</a>.)

    <p>You may want to <a href="../source.tar.bz2">download the source
    code/data</a> (e.g. to create an offline copy of the tests).

    <h2>Test cases</h2>

    <p>For each test, a green background indicates success, red indicates
    failure, blue indicates a need to manually confirm the output is as
    expected.

    <p>The versions in the report generator are the most visually minimalist.
    The category links below show the actual and expected renderings, and any
    error messages. The individual test pages have links to relevant parts of
    the specification and extra notes.

    <p>There may be many inaccuracies: tests that do not notice when part of
    the output is incorrect; tests that are too intolerant of acceptable
    renderings differences, or make other unreasonable assumptions; tests that
    were written for an outdated version of the specification, and tests that
    are just wrong. Also a number of features are not tested, most notably text
    rendering. Please contact me (<a
    href="mailto:excors&#64;gmail.com">email</a>, <a
    href="http://wiki.whatwg.org/wiki/IRC">IRC</a>, etc) if you find any
    problems.

index.w3c: |
    <!DOCTYPE html>
    <title>Canvas tests - index</title>
    <link rel="stylesheet" href="/2dcontext/resources/canvas-index.css">

    <h1><code>&lt;canvas&gt;</code> tests</h1>

index.category.item: |
    <li><h3><a href="index.%s.html">%s.*</a></h3><p>%d test%s <a href="#" onclick="return expand(this)">expand</a></p>

index.w3c.category.item: |
    <li><h3><a href="index.%s.html">%s.*</a></h3><p>%d test%s</p>

reportgen: |
    <!DOCTYPE html>
    <title>Canvas tests - report generator</title>
    <link rel="stylesheet" href="../reportgen.css">
    <script src="../reportgen.js"></script>
    <p>This is mainly for my own use, so it is not designed to be user-friendly.
    If anyone else wants to use it for some reason, just wait
    until "tests not yet loaded" and "tests not yet completed" get down to zero, then click the
    pass/fail button for any test it shows where it cannot work out the answer (or use the
    <kbd>y</kbd>/<kbd>n</kbd> keys to choose for the magenta-highlighted case), then use the
    buttons at the bottom to collect all the results.
    <form id="f">
    <p><label for="loading">Tests not yet loaded:</label> <input id="loading" value="0" readonly>
    <p><label for="waiting">Tests not yet completed:</label> <input id="waiting" value="0" readonly>
    <p><button type="button" onclick="showUnfinished()">Show uncompleted tests</button>
       <button type="button" onclick="showAll()">Show all tests</button>
       <button type="button" onclick="reloadAll()">Reload test cases serially</button>
       <!--<button type="button" onclick="avoidFrameLimit()">HACK: work around frame limit</button>
       <button type="button" onclick="makeObjects()">HACK: s/iframe/object/</button>-->
    <hr>
    <p><label for="passed">Detected passes:</label> <input id="passed" value="0" readonly>
    <p><label for="failed">Detected fails:</label> <input id="failed" value="0" readonly>
    <hr>
    <table>
    <tr>
    <th>Test name
    <th>Test case
    <th>Pass?
    <th>Fail?
    <th>Notes
    <script>
    createTable( [
    %(items)s
    ] );
    </script>
    </table>
    </form>
    <hr>
    <form method="post" action="../submitresults.cgi">
    <button type="button" onclick="document.getElementById('report').value = genreport()">Generate test report</button><br>
    <textarea name="report" id="report" cols="100" rows="10"></textarea><br>
    <input type="submit" value="Submit results"> (Submissions will tend to be ignored unless there
    is a good reason why they won't be, so don't use this form unless there is such a reason.)
    </form>

results: |
    <!DOCTYPE html>
    <title>Canvas tests - results</title>
    <link rel="stylesheet" href="../results.css">
    <table>
    <col id="col1">
    <tr>
    <th>Test
