CropTarget-fromElement.https.html (3253B)
1 <!doctype html> 2 <html> 3 4 <head> 5 <title>Test CropTarget.fromElement()</title> 6 <meta name='assert' content='Test CropTarget.fromElement().' /> 7 </head> 8 9 <body> 10 <h1 class="instructions">Description</h1> 11 <p class="instructions"> 12 This test checks for the behavior of <code>CropTarget.fromElement()</code>. 13 </p> 14 15 <div id='test-div'></div> 16 <iframe id='test-iframe' src="about:blank"></iframe> 17 <img id='test-img' alt='Alt text' width="500" height="600"> 18 <div id='log'></div> 19 20 <script src=/resources/testharness.js></script> 21 <script src=/resources/testharnessreport.js></script> 22 23 <script> 24 "use strict"; 25 26 promise_test(async () => { 27 assert_true(!!CropTarget.fromElement); 28 const crop_target = await CropTarget.fromElement( 29 document.getElementById('test-iframe')); 30 assert_equals(crop_target.constructor.name, 'CropTarget'); 31 }, "Produces a CropTarget for Elements of subtype iframe."); 32 33 promise_test(async () => { 34 assert_true(!!CropTarget.fromElement); 35 const crop_target = await CropTarget.fromElement( 36 document.getElementById('test-div')); 37 assert_equals(crop_target.constructor.name, 'CropTarget'); 38 }, "Produces a CropTarget for Elements of subtype div."); 39 40 // TODO(crbug.com/1247761): Re-enable after rolling out the 41 // experiment to allow any Element. 42 // promise_test(function (t) { 43 // assert_true(!!CropTarget.fromElement); 44 // 45 // return promise_rejects_dom(t, "NotSupportedError", 46 // CropTarget.fromElement(document.getElementById("test-img"))); 47 // }, "Produces a CropTarget for Elements of subtype img."); 48 49 promise_test(t => { 50 assert_true(!!CropTarget.fromElement); 51 return promise_rejects_js(t, TypeError, 52 CropTarget.fromElement(undefined)); 53 }, "Rejects undefined with a TypeError."); 54 55 promise_test(t => { 56 assert_true(!!CropTarget.fromElement); 57 return promise_rejects_js(t, TypeError, CropTarget.fromElement(123)); 58 }, "Rejects a non-Element with a TypeError."); 59 60 promise_test(async () => { 61 assert_true(!!CropTarget.fromElement); 62 63 const div_crop_target = await CropTarget.fromElement( 64 document.getElementById('test-div')); 65 assert_equals(div_crop_target.constructor.name, 'CropTarget'); 66 67 const iframe_crop_target = await CropTarget.fromElement( 68 document.getElementById('test-iframe')); 69 assert_equals(iframe_crop_target.constructor.name, 'CropTarget'); 70 71 assert_not_equals(div_crop_target, iframe_crop_target); 72 }, "Distinct Elements produce distinct CropTargets."); 73 74 promise_test(async () => { 75 assert_true(!!CropTarget.fromElement); 76 77 const div = document.getElementById('test-div'); 78 const div_crop_target = await CropTarget.fromElement(div); 79 assert_equals(div_crop_target.constructor.name, 'CropTarget'); 80 81 const clone = div.cloneNode(true); 82 document.querySelector('body').appendChild(clone); 83 const clone_crop_target = await CropTarget.fromElement(clone); 84 assert_equals(clone_crop_target.constructor.name, 'CropTarget'); 85 86 assert_not_equals(div_crop_target, clone_crop_target); 87 }, "Cloned Elements produce distinct CropTargets."); 88 89 </script> 90 </body> 91 92 </html>