|
| 1 | +<!DOCTYPE html> |
| 2 | +<meta charset="utf-8"> |
| 3 | +<title>Cloning of input elements</title> |
| 4 | +<link rel="help" href="https://dom.spec.whatwg.org/#dom-node-clonenode"> |
| 5 | +<link rel="help" href="https://dom.spec.whatwg.org/#concept-node-clone"> |
| 6 | +<link rel="help" href="https://dom.spec.whatwg.org/#concept-node-clone-ext"> |
| 7 | +<link rel="help" href="https://html.spec.whatwg.org/multipage/forms.html#the-input-element:concept-node-clone-ext"> |
| 8 | + |
| 9 | +<script src="/resources/testharness.js"></script> |
| 10 | +<script src="/resources/testharnessreport.js"></script> |
| 11 | + |
| 12 | +<script> |
| 13 | +"use strict"; |
| 14 | + |
| 15 | +test(() => { |
| 16 | + const input = document.createElement("input"); |
| 17 | + input.value = "foo bar"; |
| 18 | + |
| 19 | + const copy = input.cloneNode(); |
| 20 | + assert_equals(copy.value, "foo bar"); |
| 21 | +}, "input element's value should be cloned"); |
| 22 | + |
| 23 | +test(() => { |
| 24 | + const input = document.createElement("input"); |
| 25 | + input.value = "foo bar"; |
| 26 | + |
| 27 | + const copy = input.cloneNode(); |
| 28 | + copy.setAttribute("value", "something else"); |
| 29 | + |
| 30 | + assert_equals(copy.value, "foo bar"); |
| 31 | +}, "input element's dirty value flag should be cloned, so setAttribute doesn't affect the cloned input's value"); |
| 32 | + |
| 33 | +test(() => { |
| 34 | + const input = document.createElement("input"); |
| 35 | + input.setAttribute("type", "radio"); |
| 36 | + input.checked = true; |
| 37 | + |
| 38 | + const copy = input.cloneNode(); |
| 39 | + assert_equals(copy.checked, true); |
| 40 | +}, "input element's checkedness should be cloned"); |
| 41 | + |
| 42 | +test(() => { |
| 43 | + const input = document.createElement("input"); |
| 44 | + input.setAttribute("type", "radio"); |
| 45 | + input.checked = false; |
| 46 | + |
| 47 | + const copy = input.cloneNode(); |
| 48 | + copy.setAttribute("checked", "checked"); |
| 49 | + |
| 50 | + assert_equals(copy.checked, false); |
| 51 | +}, "input element's dirty checkedness should be cloned, so setAttribute doesn't affect the cloned input's checkedness"); |
| 52 | +</script> |
0 commit comments