https://github.com/web-platform-tests/wpt
Raw File
Tip revision: f938471bc4c12d502a04dd46191d9629bd38f8f1 authored by Michael[tm] Smith on 22 April 2014, 08:39:34 UTC
Updated document.lastModified test.
Tip revision: f938471
link-import.html
<!DOCTYPE html>.
<html>
<head>  
<title>HTML Imports</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="author" title="Hajime Morrita" href="mailto:morrita@google.com">
<link rel="help" href="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/imports/index.html#loading-imports">
<link id="linkImport" rel="import" href="resources/hello.html">
</head>
<body>
<div id="log">Running test...</div>
<script>

test(function() {
  var linkImport = document.getElementById("linkImport");
  assert_true(linkImport.import instanceof DocumentFragment);
  assert_true(linkImport.import.querySelector("#target") instanceof DocumentFragment);
}, 
"Check on loaded import. It must return the imported fragment for the import, represented by the link element."
);

test(function() {
  var linkImport = document.getElementById("linkImport");
  assert_equals(linkImport.import, linkImport.import);
}, 
"Check on object identity. The same object must be returned each time."
);

var frameTest = async_test(
  "Check on blocking script import on parent. Imports in the parent frame should block scripts in chlid documents."
);

function checkFromFrame() {
   frameTest.step(function() {
     var linkImportBlockingParent = document.getElementById("linkImportBlockingParent");
     assert_true(linkImportBlockingParent.import instanceof DocumentFragment);
   });

   frameTest.done();
   // This is just for cleanup.
   document.getElementById("testingFrame").style.display = "none";
}

</script>
<link id="linkImportBlockingParent" rel="import" href="resources/another.html" />
<iframe id="testingFrame" srcdoc="<script>parent.checkFromFrame();</script>"></iframe>
<script>

var insertionTest = async_test(
  "Check on dynamically inserted element. The import should be loaded even for dynamically added links."
);

insertionTest.step(function() {
  var retries = 50;
  var linkToBeInserted = document.createElement("link");
  linkToBeInserted.setAttribute("rel", "import");
  linkToBeInserted.setAttribute("href", "resources/another.html");
  function checkAndDoneOncePassed() {
    insertionTest.step(function() {
      var loaded = linkToBeInserted.import instanceof DocumentFragment;
      if (loaded) {
        assert_true(loaded);
        insertionTest.done();
        return;
      }

      retries--;
      if (retries <= 0) {
        assert_unreached("Too many retries.");
        insertionTest.done();
        return;
      }

      window.setTimeout(checkAndDoneOncePassed, 0);
    });
  };

  window.setTimeout(checkAndDoneOncePassed, 0);
});

</script>
</body>
</html>
back to top