test_bug1322678.html (3194B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1322678 5 --> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Test for Bug 1322678</title> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <script src="/tests/SimpleTest/SimpleTest.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 12 </head> 13 <body> 14 <script type="text/javascript"> 15 16 const CUSTOM_TITLE = "Custom Title"; 17 18 async function openNewWindowForTest() { 19 let win = window.open("bug369370-popup.png", "bug1322678", 20 "width=400,height=300,scrollbars=no"); 21 ok(win, "opened child window"); 22 23 await new Promise(resolve => { 24 win.onload = function() { 25 ok(true, "window loaded"); 26 resolve(); 27 }; 28 }); 29 30 return win; 31 } 32 33 async function testCustomTitle(aWin, aTitle) { 34 let doc = aWin.document; 35 let elements = doc.getElementsByTagName("img"); 36 is(elements.length, 1, "looking for img in ImageDocument"); 37 let img = elements[0]; 38 39 // Click to zoom in 40 synthesizeMouse(img, 25, 25, { }, aWin); 41 is(doc.title, aTitle, "Checking title"); 42 43 // Click there again to zoom out 44 synthesizeMouse(img, 25, 25, { }, aWin); 45 is(doc.title, aTitle, "Checking title"); 46 47 // Now try resizing the window so the image fits vertically and horizontally. 48 await new Promise(resolve => { 49 aWin.addEventListener("resize", function() { 50 // Give the image document time to respond 51 SimpleTest.executeSoon(function() { 52 is(doc.title, aTitle, "Checking title"); 53 resolve(); 54 }); 55 }, {once: true}); 56 57 let decorationSize = aWin.outerHeight - aWin.innerHeight; 58 aWin.resizeTo(800 + 50 + decorationSize, 600 + 50 + decorationSize); 59 }); 60 61 // Now try resizing the window so the image no longer fits. 62 await new Promise(resolve => { 63 aWin.addEventListener("resize", function() { 64 // Give the image document time to respond 65 SimpleTest.executeSoon(function() { 66 is(doc.title, aTitle, "Checking title"); 67 resolve(); 68 }); 69 }, {once: true}); 70 71 aWin.resizeTo(400, 300); 72 }); 73 } 74 75 // eslint-disable-next-line mozilla/no-addtask-setup 76 add_task(async function setup() { 77 await SpecialPowers.pushPrefEnv({"set": [ 78 ["browser.enable_automatic_image_resizing", true], 79 ]}); 80 }); 81 82 add_task(async function testUpdateDocumentTitle() { 83 let win = await openNewWindowForTest(); 84 // Set custom title. 85 win.document.title = CUSTOM_TITLE; 86 await testCustomTitle(win, CUSTOM_TITLE); 87 win.close(); 88 }); 89 90 add_task(async function testUpdateTitleElement() { 91 let win = await openNewWindowForTest(); 92 // Set custom title. 93 let title = win.document.getElementsByTagName("title")[0]; 94 title.text = CUSTOM_TITLE; 95 await testCustomTitle(win, CUSTOM_TITLE); 96 win.close(); 97 }); 98 99 add_task(async function testAppendNewTitleElement() { 100 let win = await openNewWindowForTest(); 101 // Set custom title. 102 let doc = win.document; 103 doc.getElementsByTagName("title")[0].remove(); 104 let title = doc.createElement("title"); 105 title.text = CUSTOM_TITLE; 106 doc.head.appendChild(title); 107 await testCustomTitle(win, CUSTOM_TITLE); 108 win.close(); 109 }); 110 111 </script> 112 </body> 113 </html>