browser_device_selector_items.js (2213B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests the device selector button and the menu items. 7 8 const MenuItem = require("resource://devtools/client/shared/components/menu/MenuItem.js"); 9 10 const FIREFOX_ICON = 11 'url("chrome://devtools/skin/images/browsers/firefox.svg")'; 12 const DUMMY_ICON = `url("${MenuItem.DUMMY_ICON}")`; 13 14 const FIREFOX_DEVICE = { 15 name: "Device of Firefox user-agent", 16 userAgent: "Mozilla/5.0 (Mobile; rv:39.0) Gecko/39.0 Firefox/39.0", 17 width: 320, 18 height: 570, 19 pixelRatio: 5.5, 20 touch: true, 21 firefoxOS: true, 22 os: "custom", 23 featured: true, 24 }; 25 26 const TEST_DEVICES = [ 27 { 28 name: FIREFOX_DEVICE.name, 29 hasIcon: true, 30 }, 31 { 32 name: "Laptop with MDPI screen", 33 hasIcon: false, 34 }, 35 ]; 36 37 addDeviceForTest(FIREFOX_DEVICE); 38 39 // Add the laptop to the device list 40 const { 41 updatePreferredDevices, 42 } = require("resource://devtools/client/responsive/actions/devices.js"); 43 updatePreferredDevices({ 44 added: ["Laptop with MDPI screen"], 45 removed: [], 46 }); 47 48 addRDMTask( 49 URL_ROOT, 50 async function ({ ui }) { 51 const deviceSelector = 52 ui.toolWindow.document.getElementById("device-selector"); 53 54 for (const testDevice of TEST_DEVICES) { 55 info(`Check "${name}" device`); 56 await testMenuItems(ui.toolWindow, deviceSelector, menuItems => { 57 const menuItem = findMenuItem(menuItems, testDevice.name); 58 ok(menuItem, "The menu item is on the list"); 59 const label = menuItem.querySelector(".iconic > .label"); 60 const backgroundImage = ui.toolWindow.getComputedStyle( 61 label, 62 "::before" 63 ).backgroundImage; 64 const icon = testDevice.hasIcon ? FIREFOX_ICON : DUMMY_ICON; 65 is(backgroundImage, icon, "The icon is correct"); 66 }); 67 68 info("Check device selector button"); 69 await selectDevice(ui, testDevice.name); 70 const backgroundImage = ui.toolWindow.getComputedStyle( 71 deviceSelector, 72 "::before" 73 ).backgroundImage; 74 const icon = testDevice.hasIcon ? FIREFOX_ICON : "none"; 75 is(backgroundImage, icon, "The icon is correct"); 76 } 77 }, 78 { waitForDeviceList: true } 79 );