Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

3.2 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<input id="upload" type="file" style="display:block;width:200px;height:200px">
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<script>
const input = document.getElementById("upload");
const events = [];
let phase = "single";
let multipleChangeResolve = null;
let multipleDropFiles = null;

const multipleChanged = new Promise(function (resolve) {
  multipleChangeResolve = resolve;
});

window.__enableMultipleFileDropPhase = function () {
  input.multiple = true;
  phase = "multiple";
};

input.addEventListener("drop", function (event) {
  if (phase === "multiple") {
    multipleDropFiles = Array.from(event.dataTransfer.files);
  }
  events.push(
    phase +
      "-drop:" +
      event.dataTransfer.files.length +
      ":" +
      Array.from(event.dataTransfer.files).map(file => file.name).join(",") +
      ":" +
      input.files.length,
  );
});

input.addEventListener("input", function () {
  events.push(
    phase +
      "-input:" +
      input.files.length +
      ":" +
      Array.from(input.files).map(file => file.name).join(",") +
      ":" +
      input.value,
  );
});

input.addEventListener("change", function () {
  events.push(
    phase +
      "-change:" +
      input.files.length +
      ":" +
      Array.from(input.files).map(file => file.name).join(","),
  );
  if (phase === "multiple") {
    multipleChangeResolve();
  }
});

promise_test(async function () {
  await multipleChanged;
  assert_array_equals(
    events,
    [
      "single-drop:2:first.txt,second.txt:0",
      "single-input:1:first.txt:C:\\fakepath\\first.txt",
      "single-change:1:first.txt",
      "multiple-drop:2:alpha.txt,beta.txt:1",
      "multiple-input:2:alpha.txt,beta.txt:C:\\fakepath\\alpha.txt",
      "multiple-change:2:alpha.txt,beta.txt",
    ],
    "single file input should truncate drops, while multiple input should keep all dropped files",
  );
  assert_equals(input.files.length, 2, "multiple input keeps both dropped files");
  assert_equals(input.files[0].name, "alpha.txt", "first multiple file");
  assert_equals(input.files[1].name, "beta.txt", "second multiple file");
  assert_equals(input.files[0].type, "text/plain", "first multiple file type");
  assert_equals(input.files[1].type, "text/plain", "second multiple file type");
  assert_equals(input.files[0].size, 5, "first multiple file size");
  assert_equals(input.files[1].size, 4, "second multiple file size");
  assert_equals(input.files[0].lastModified, 3, "first multiple file lastModified");
  assert_equals(input.files[1].lastModified, 4, "second multiple file lastModified");
  assert_equals(await input.files[0].text(), "alpha", "first multiple file bytes");
  assert_equals(await input.files[1].text(), "beta", "second multiple file bytes");
  assert_equals(await multipleDropFiles[0].text(), "alpha", "drop DataTransfer first file bytes");
  assert_equals(await multipleDropFiles[1].text(), "beta", "drop DataTransfer second file bytes");
  assert_equals(input.value, "C:\\fakepath\\alpha.txt", "fakepath reflects first selected file");
}, "Input.dispatchDragEvent respects file input multiple selection semantics");
</script>