diff options
Diffstat (limited to 'devtools/client/responsive/test/xpcshell')
16 files changed, 551 insertions, 0 deletions
diff --git a/devtools/client/responsive/test/xpcshell/.eslintrc.js b/devtools/client/responsive/test/xpcshell/.eslintrc.js new file mode 100644 index 0000000000..c447323956 --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the shared list of defined globals for xpcshell. + extends: "../../../../.eslintrc.xpcshell.js", +}; diff --git a/devtools/client/responsive/test/xpcshell/head.js b/devtools/client/responsive/test/xpcshell/head.js new file mode 100644 index 0000000000..ee4933416c --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/head.js @@ -0,0 +1,19 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/* eslint no-unused-vars: [2, {"vars": "local"}] */ + +const { require } = ChromeUtils.importESModule( + "resource://devtools/shared/loader/Loader.sys.mjs" +); + +const Store = require("resource://devtools/client/responsive/store.js"); + +const DevToolsUtils = require("resource://devtools/shared/DevToolsUtils.js"); + +Services.prefs.setBoolPref("devtools.testing", true); +registerCleanupFunction(() => { + Services.prefs.clearUserPref("devtools.testing"); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_add_device.js b/devtools/client/responsive/test/xpcshell/test_add_device.js new file mode 100644 index 0000000000..cea6e30989 --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_add_device.js @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test adding a new device. + +const { + addDevice, + addDeviceType, +} = require("resource://devtools/client/responsive/actions/devices.js"); + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + const device = { + name: "Firefox OS Flame", + width: 320, + height: 570, + pixelRatio: 1.5, + userAgent: "Mozilla/5.0 (Mobile; rv:39.0) Gecko/39.0 Firefox/39.0", + touch: true, + firefoxOS: true, + os: "fxos", + }; + + dispatch(addDeviceType("phones")); + dispatch(addDevice(device, "phones")); + + equal(getState().devices.phones.length, 1, "Correct number of phones"); + ok( + getState().devices.phones.includes(device), + "Device phone list contains Firefox OS Flame" + ); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_add_device_type.js b/devtools/client/responsive/test/xpcshell/test_add_device_type.js new file mode 100644 index 0000000000..e824574380 --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_add_device_type.js @@ -0,0 +1,28 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test adding a new device type. + +const { + addDeviceType, +} = require("resource://devtools/client/responsive/actions/devices.js"); + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + dispatch(addDeviceType("phones")); + + equal(getState().devices.types.length, 1, "Correct number of device types"); + equal( + getState().devices.phones.length, + 0, + "Defaults to an empty array of phones" + ); + ok( + getState().devices.types.includes("phones"), + "Device types contain phones" + ); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_add_viewport.js b/devtools/client/responsive/test/xpcshell/test_add_viewport.js new file mode 100644 index 0000000000..c9a6d9500b --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_add_viewport.js @@ -0,0 +1,24 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test adding viewports to the page. + +const { + addViewport, +} = require("resource://devtools/client/responsive/actions/viewports.js"); + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + equal(getState().viewports.length, 0, "Defaults to no viewpots at startup"); + + dispatch(addViewport()); + equal(getState().viewports.length, 1, "One viewport total"); + + // For the moment, there can be at most one viewport. + dispatch(addViewport()); + equal(getState().viewports.length, 1, "One viewport total, again"); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_change_device.js b/devtools/client/responsive/test/xpcshell/test_change_device.js new file mode 100644 index 0000000000..f5e3ab7f73 --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_change_device.js @@ -0,0 +1,50 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test changing the viewport device. + +const { + addDevice, + addDeviceType, +} = require("resource://devtools/client/responsive/actions/devices.js"); +const { + addViewport, + changeDevice, +} = require("resource://devtools/client/responsive/actions/viewports.js"); + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + dispatch(addDeviceType("phones")); + dispatch( + addDevice( + { + name: "Firefox OS Flame", + width: 320, + height: 570, + pixelRatio: 1.5, + userAgent: "Mozilla/5.0 (Mobile; rv:39.0) Gecko/39.0 Firefox/39.0", + touch: true, + firefoxOS: true, + os: "fxos", + }, + "phones" + ) + ); + dispatch(addViewport()); + + let viewport = getState().viewports[0]; + equal(viewport.device, "", "Default device is unselected"); + + dispatch(changeDevice(0, "Firefox OS Flame", "phones")); + + viewport = getState().viewports[0]; + equal( + viewport.device, + "Firefox OS Flame", + "Changed to Firefox OS Flame device" + ); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_change_display_pixel_ratio.js b/devtools/client/responsive/test/xpcshell/test_change_display_pixel_ratio.js new file mode 100644 index 0000000000..7cc2604b7b --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_change_display_pixel_ratio.js @@ -0,0 +1,26 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test changing the display pixel ratio. + +const { + changeDisplayPixelRatio, +} = require("resource://devtools/client/responsive/actions/ui.js"); + +const NEW_PIXEL_RATIO = 5.5; + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + equal(getState().ui.displayPixelRatio, 0, "Defaults to 0 at startup"); + + dispatch(changeDisplayPixelRatio(NEW_PIXEL_RATIO)); + equal( + getState().ui.displayPixelRatio, + NEW_PIXEL_RATIO, + `Display Pixel Ratio changed to ${NEW_PIXEL_RATIO}` + ); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_change_network_throttling.js b/devtools/client/responsive/test/xpcshell/test_change_network_throttling.js new file mode 100644 index 0000000000..eb762682d8 --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_change_network_throttling.js @@ -0,0 +1,34 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test changing the network throttling state + +const { + changeNetworkThrottling, +} = require("resource://devtools/client/shared/components/throttling/actions.js"); + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + ok( + !getState().networkThrottling.enabled, + "Network throttling is disabled by default." + ); + equal( + getState().networkThrottling.profile, + "", + "Network throttling profile is empty by default." + ); + + dispatch(changeNetworkThrottling(true, "Bob")); + + ok(getState().networkThrottling.enabled, "Network throttling is enabled."); + equal( + getState().networkThrottling.profile, + "Bob", + "Network throttling profile is set." + ); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_change_pixel_ratio.js b/devtools/client/responsive/test/xpcshell/test_change_pixel_ratio.js new file mode 100644 index 0000000000..d462cf39cc --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_change_pixel_ratio.js @@ -0,0 +1,27 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test changing the viewport pixel ratio. + +const { + addViewport, + changePixelRatio, +} = require("resource://devtools/client/responsive/actions/viewports.js"); +const NEW_PIXEL_RATIO = 5.5; + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + dispatch(addViewport()); + dispatch(changePixelRatio(0, NEW_PIXEL_RATIO)); + + const viewport = getState().viewports[0]; + equal( + viewport.pixelRatio, + NEW_PIXEL_RATIO, + `Viewport's pixel ratio changed to ${NEW_PIXEL_RATIO}` + ); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_change_user_agent.js b/devtools/client/responsive/test/xpcshell/test_change_user_agent.js new file mode 100644 index 0000000000..e92d3f110f --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_change_user_agent.js @@ -0,0 +1,28 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test changing the user agent. + +const { + changeUserAgent, +} = require("resource://devtools/client/responsive/actions/ui.js"); + +const NEW_USER_AGENT = + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) " + + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"; + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + equal(getState().ui.userAgent, "", "User agent is empty by default."); + + dispatch(changeUserAgent(NEW_USER_AGENT)); + equal( + getState().ui.userAgent, + NEW_USER_AGENT, + `User Agent changed to ${NEW_USER_AGENT}` + ); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_resize_viewport.js b/devtools/client/responsive/test/xpcshell/test_resize_viewport.js new file mode 100644 index 0000000000..83780ad195 --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_resize_viewport.js @@ -0,0 +1,37 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test resizing the viewport. + +const { + addViewport, + resizeViewport, +} = require("resource://devtools/client/responsive/actions/viewports.js"); +const { + toggleTouchSimulation, +} = require("resource://devtools/client/responsive/actions/ui.js"); + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + dispatch(addViewport()); + dispatch(resizeViewport(0, 500, 500)); + + let viewport = getState().viewports[0]; + equal(viewport.width, 500, "Resized width of 500"); + equal(viewport.height, 500, "Resized height of 500"); + + dispatch(toggleTouchSimulation(true)); + dispatch(resizeViewport(0, 400, 400)); + + viewport = getState().viewports[0]; + equal(viewport.width, 400, "Resized width of 400 (with touch simulation on)"); + equal( + viewport.height, + 400, + "Resized height of 400 (with touch simulation on)" + ); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_rotate_viewport.js b/devtools/client/responsive/test/xpcshell/test_rotate_viewport.js new file mode 100644 index 0000000000..7d34daa39f --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_rotate_viewport.js @@ -0,0 +1,27 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test rotating the viewport. + +const { + addViewport, + rotateViewport, +} = require("resource://devtools/client/responsive/actions/viewports.js"); + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + dispatch(addViewport()); + + let viewport = getState().viewports[0]; + equal(viewport.width, 320, "Default width of 320"); + equal(viewport.height, 480, "Default height of 480"); + + dispatch(rotateViewport(0)); + viewport = getState().viewports[0]; + equal(viewport.width, 480, "Rotated width of 480"); + equal(viewport.height, 320, "Rotated height of 320"); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_ua_parser.js b/devtools/client/responsive/test/xpcshell/test_ua_parser.js new file mode 100644 index 0000000000..152a504498 --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_ua_parser.js @@ -0,0 +1,129 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test for user agent parser. + +const { + parseUserAgent, +} = require("resource://devtools/client/responsive/utils/ua.js"); + +const TEST_DATA = [ + { + userAgent: + "Mozilla/5.0 (Android 4.4.3; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0", + expectedBrowser: { name: "Firefox", version: "41" }, + expectedOS: { name: "Android", version: "4.4.3" }, + }, + { + userAgent: + "Mozilla/5.0 (Android 8.0.0; Mobile; rv:70.0) Gecko/70.0 Firefox/70.0", + expectedBrowser: { name: "Firefox", version: "70" }, + expectedOS: { name: "Android", version: "8" }, + }, + { + userAgent: + "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/70.1", + expectedBrowser: { name: "Firefox", version: "70.1" }, + expectedOS: { name: "Windows NT", version: "6.1" }, + }, + { + userAgent: + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/70.0", + expectedBrowser: { name: "Firefox", version: "70" }, + expectedOS: { name: "Mac OSX", version: "10.13" }, + }, + { + userAgent: + "Mozilla/5.0 (X11; Linux i586; rv:31.0) Gecko/20100101 Firefox/70.0", + expectedBrowser: { name: "Firefox", version: "70" }, + expectedOS: { name: "Linux", version: null }, + }, + { + userAgent: + "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/13.2b11866 Mobile/16A366 Safari/605.1.15", + expectedBrowser: { name: "Firefox", version: "13.2b11866" }, + expectedOS: { name: "iOS", version: "12" }, + }, + { + userAgent: + "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/12.0 Mobile/15A372 Safari/604.1", + expectedBrowser: { name: "Safari", version: "12" }, + expectedOS: { name: "iOS", version: "12" }, + }, + { + userAgent: + "Mozilla/5.0 (iPad; CPU OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1", + expectedBrowser: { name: "Safari", version: "14.1" }, + expectedOS: { name: "iPadOS", version: "14.7.1" }, + }, + { + userAgent: + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.8 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7", + expectedBrowser: { name: "Safari", version: "9.1" }, + expectedOS: { name: "Mac OSX", version: "10.11.6" }, + }, + { + userAgent: + "Mozilla/5.0 (Linux; Android 8.0.0; Nexus 6P Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Mobile Safari/537.36", + expectedBrowser: { name: "Chrome", version: "67" }, + expectedOS: { name: "Android", version: "8" }, + }, + { + userAgent: + "Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile Safari/537.36", + expectedBrowser: { name: "Chrome", version: "87" }, + expectedOS: { name: "Android", version: "11" }, + }, + { + userAgent: + "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/69.0.3497.105 Mobile/15E148 Safari/605.1", + expectedBrowser: { name: "Chrome", version: "69" }, + expectedOS: { name: "iOS", version: "12" }, + }, + { + userAgent: + "Mozilla/5.0 (X11; CrOS x86_64 11895.118.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.159 Safari/537.36", + expectedBrowser: { name: "Chrome", version: "74" }, + expectedOS: { name: "Chrome OS", version: "11895.118" }, + }, + { + userAgent: + "Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263", + expectedBrowser: { name: "Edge", version: "14.14263" }, + expectedOS: { name: "Windows Phone", version: "10.0" }, + }, + { + userAgent: + "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 OPR/43.0.2442.991", + expectedBrowser: { name: "Opera", version: "43" }, + expectedOS: { name: "Windows NT", version: "10.0" }, + }, + { + userAgent: + "Opera/9.80 (Linux armv7l) Presto/2.12.407 Version/12.51 , D50u-D1-UHD/V1.5.16-UHD (Vizio, D50u-D1, Wireless)", + expectedBrowser: { name: "Opera", version: "9.80" }, + expectedOS: { name: "Linux", version: null }, + }, + { + userAgent: + "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)", + expectedBrowser: { name: "IE", version: "6" }, + expectedOS: { name: "Windows NT", version: "5.1" }, + }, + { + userAgent: "1080p Full HD Television", + expectedBrowser: null, + expectedOS: null, + }, +]; + +add_task(async function () { + for (const { userAgent, expectedBrowser, expectedOS } of TEST_DATA) { + info(`Test for ${userAgent}`); + const { browser, os } = parseUserAgent(userAgent); + deepEqual(browser, expectedBrowser, "Parsed browser is correct"); + deepEqual(os, expectedOS, "Parsed OS is correct"); + } +}); diff --git a/devtools/client/responsive/test/xpcshell/test_update_device_displayed.js b/devtools/client/responsive/test/xpcshell/test_update_device_displayed.js new file mode 100644 index 0000000000..2d04b546ba --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_update_device_displayed.js @@ -0,0 +1,38 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test updating the device `displayed` property + +const { + addDevice, + addDeviceType, + updateDeviceDisplayed, +} = require("resource://devtools/client/responsive/actions/devices.js"); + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + const device = { + name: "Firefox OS Flame", + width: 320, + height: 570, + pixelRatio: 1.5, + userAgent: "Mozilla/5.0 (Mobile; rv:39.0) Gecko/39.0 Firefox/39.0", + touch: true, + firefoxOS: true, + os: "fxos", + }; + + dispatch(addDeviceType("phones")); + dispatch(addDevice(device, "phones")); + dispatch(updateDeviceDisplayed(device, "phones", true)); + + equal(getState().devices.phones.length, 1, "Correct number of phones"); + ok( + getState().devices.phones[0].displayed, + "Device phone list contains enabled Firefox OS Flame" + ); +}); diff --git a/devtools/client/responsive/test/xpcshell/test_update_touch_simulation_enabled.js b/devtools/client/responsive/test/xpcshell/test_update_touch_simulation_enabled.js new file mode 100644 index 0000000000..e96c4b3a86 --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/test_update_touch_simulation_enabled.js @@ -0,0 +1,24 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test updating the touch simulation `enabled` property + +const { + toggleTouchSimulation, +} = require("resource://devtools/client/responsive/actions/ui.js"); + +add_task(async function () { + const store = Store(); + const { getState, dispatch } = store; + + ok( + !getState().ui.touchSimulationEnabled, + "Touch simulation is disabled by default." + ); + + dispatch(toggleTouchSimulation(true)); + + ok(getState().ui.touchSimulationEnabled, "Touch simulation is enabled."); +}); diff --git a/devtools/client/responsive/test/xpcshell/xpcshell.ini b/devtools/client/responsive/test/xpcshell/xpcshell.ini new file mode 100644 index 0000000000..9c5573b418 --- /dev/null +++ b/devtools/client/responsive/test/xpcshell/xpcshell.ini @@ -0,0 +1,18 @@ +[DEFAULT] +tags = devtools +head = head.js +firefox-appdir = browser + +[test_add_device.js] +[test_add_device_type.js] +[test_add_viewport.js] +[test_change_device.js] +[test_change_display_pixel_ratio.js] +[test_change_network_throttling.js] +[test_change_pixel_ratio.js] +[test_change_user_agent.js] +[test_resize_viewport.js] +[test_rotate_viewport.js] +[test_ua_parser.js] +[test_update_device_displayed.js] +[test_update_touch_simulation_enabled.js] |