browser_viewport_resizing_scrollbar.js (3085B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test scrollbar appearance after viewport resizing, with and without 7 // meta viewport support. 8 9 Services.scriptloader.loadSubScript( 10 "chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js", 11 this 12 ); 13 14 // The quest for a TEST_ROOT: we have to choose a way of addressing the RDM document 15 // such that two things can happen: 16 // 1) addRDMTask can load it. 17 // 2) WindowSnapshot can take a picture of it. 18 19 // The WindowSnapshot does not work cross-origin. We can't use a data URI, because those 20 // are considered cross-origin. 21 22 // let TEST_ROOT = ""; 23 24 // We can't use a relative URL, because addRDMTask can't load local files. 25 // TEST_ROOT = ""; 26 27 // We can't use a mochi.test URL, because it's cross-origin. 28 // TEST_ROOT = 29 // "http://mochi.test:8888/browser/devtools/client/responsive/test/browser/"; 30 31 // We can't use a chrome URL, because it triggers an assertion: RDM only available for 32 // remote tabs. 33 // TEST_ROOT = 34 // "chrome://mochitests/content/browser/devtools/client/responsive/test/browser/"; 35 36 // So if we had an effective TEST_ROOT, we'd use it here and run our test. But we don't. 37 // The proposed "file_meta_1000_div.html" would just contain the html specified below as 38 // a data URI. 39 // const TEST_URL = TEST_ROOT + "file_meta_1000_div.html"; 40 41 // Instead we're going to mess with a security preference to allow a data URI to be 42 // treated as same-origin. This doesn't work either for reasons that I don't understand. 43 44 const TEST_URL = 45 "data:text/html;charset=utf-8," + 46 "<head>" + 47 '<meta name="viewport" content="width=device-width, initial-scale=1"/>' + 48 "</head>" + 49 '<body><div style="background:orange; width:1000px; height:1000px"></div></body>'; 50 51 addRDMTask(TEST_URL, async function ({ ui, manager }) { 52 // Turn on the prefs that force overlay scrollbars to always be visible. 53 await SpecialPowers.pushPrefEnv({ 54 set: [["layout.testing.overlay-scrollbars.always-visible", true]], 55 }); 56 57 info("--- Starting viewport test output ---"); 58 59 const browser = ui.getViewportBrowser(); 60 61 const expected = [false, true]; 62 for (const e of expected) { 63 const message = "Meta Viewport " + (e ? "ON" : "OFF"); 64 65 // Ensure meta viewport is set. 66 info(message + " setting meta viewport support."); 67 await setTouchAndMetaViewportSupport(ui, e.metaSupport); 68 69 // Get to the initial size and snapshot the window. 70 await setViewportSizeAndAwaitReflow(ui, manager, 300, 600); 71 const initialSnapshot = await snapshotWindow(browser); 72 73 // Move to the rotated size. 74 await setViewportSizeAndAwaitReflow(ui, manager, 600, 300); 75 76 // Reload the window. 77 await reloadBrowser(); 78 79 // Go back to the initial size and take another snapshot. 80 await setViewportSizeAndAwaitReflow(ui, manager, 300, 600); 81 const finalSnapshot = await snapshotWindow(browser); 82 83 const result = compareSnapshots(initialSnapshot, finalSnapshot, true); 84 is(result[2], result[1], "Window snapshots should match."); 85 } 86 });