<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test for canvas drawWindow</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
  <script type="application/javascript" src="file_drawWindow_common.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
  <script type="application/javascript">

  SimpleTest.waitForExplicitFinish();
  window.addEventListener("load", openSourceWindow);

  var sourceWindow;

  function openSourceWindow(event) {
    if (event.target != document) {
      return;
    }

    // Add a little bottom padding to the window so that we don't capture the
    // rounded corners at the bottom, which our GL drawing code on OS X draws
    // for regular windows.
    // (The reftest framework doesn't have this problem because it doesn't use
    // a regular window with a titlebar, so there are no rounded corners.)
    const WINDOW_INNER_WIDTH = CANVAS_WIDTH;
    const WINDOW_INNER_HEIGHT = CANVAS_HEIGHT + 10;

    // Need to open as a toplevel chrome window so that
    // DRAWWINDOW_USE_WIDGET_LAYERS is honored.
    sourceWindow = window.browsingContext.topChromeWindow.open("file_drawWindow_source.html", "",
                                                               `chrome,width=${WINDOW_INNER_WIDTH},height=${WINDOW_INNER_HEIGHT}`);
    SimpleTest.waitForFocus(runTests, sourceWindow);
  }

  async function runTests() {
    var cxInterfaceWrap = SpecialPowers.wrap(CanvasRenderingContext2D);
    
    let snapshot = function(context, x, y, width, height, bg) {
      var flags = cxInterfaceWrap.DRAWWINDOW_USE_WIDGET_LAYERS |
                  cxInterfaceWrap.DRAWWINDOW_DRAW_CARET |
                  cxInterfaceWrap.DRAWWINDOW_DRAW_VIEW;
      context.drawWindow(sourceWindow, x, y, width, height, bg, flags);
    }
    await runDrawWindowTests(snapshot, true);

    sourceWindow.close();

    SimpleTest.finish();
  }

  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
</body>
</html>
