diff options
Diffstat (limited to 'browser/components/backup/tests/xpcshell')
4 files changed, 129 insertions, 0 deletions
diff --git a/browser/components/backup/tests/xpcshell/data/test_xulstore.json b/browser/components/backup/tests/xpcshell/data/test_xulstore.json new file mode 100644 index 0000000000..0d0890ab16 --- /dev/null +++ b/browser/components/backup/tests/xpcshell/data/test_xulstore.json @@ -0,0 +1,18 @@ +{ + "chrome://browser/content/browser.xhtml": { + "PersonalToolbar": { "collapsed": "false" }, + "main-window": { + "screenX": "852", + "screenY": "125", + "width": "1484", + "height": "1256", + "sizemode": "normal" + }, + "sidebar-box": { + "sidebarcommand": "viewBookmarksSidebar", + "width": "323", + "style": "width: 323px;" + }, + "sidebar-title": { "value": "Bookmarks" } + } +} diff --git a/browser/components/backup/tests/xpcshell/test_BrowserResource.js b/browser/components/backup/tests/xpcshell/test_BrowserResource.js new file mode 100644 index 0000000000..23c8e077a5 --- /dev/null +++ b/browser/components/backup/tests/xpcshell/test_BrowserResource.js @@ -0,0 +1,63 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { BackupResource } = ChromeUtils.importESModule( + "resource:///modules/backup/BackupResource.sys.mjs" +); + +const EXPECTED_KILOBYTES_FOR_XULSTORE = 1; + +add_setup(() => { + do_get_profile(); +}); + +/** + * Tests that BackupService.getFileSize will get the size of a file in kilobytes. + */ +add_task(async function test_getFileSize() { + let file = do_get_file("data/test_xulstore.json"); + + let testFilePath = PathUtils.join(PathUtils.profileDir, "test_xulstore.json"); + + await IOUtils.copy(file.path, PathUtils.profileDir); + + let size = await BackupResource.getFileSize(testFilePath); + + Assert.equal( + size, + EXPECTED_KILOBYTES_FOR_XULSTORE, + "Size of the test_xulstore.json is rounded up to the nearest kilobyte." + ); + + await IOUtils.remove(testFilePath); +}); + +/** + * Tests that BackupService.getFileSize will get the total size of all the files in a directory and it's children in kilobytes. + */ +add_task(async function test_getDirectorySize() { + let file = do_get_file("data/test_xulstore.json"); + + // Create a test directory with the test json file in it. + let testDir = PathUtils.join(PathUtils.profileDir, "testDir"); + await IOUtils.makeDirectory(testDir); + await IOUtils.copy(file.path, testDir); + + // Create another test directory inside of that one. + let nestedTestDir = PathUtils.join(testDir, "testDir"); + await IOUtils.makeDirectory(nestedTestDir); + await IOUtils.copy(file.path, nestedTestDir); + + let size = await BackupResource.getDirectorySize(testDir); + + Assert.equal( + size, + EXPECTED_KILOBYTES_FOR_XULSTORE * 2, + `Total size of the directory is rounded up to the nearest kilobyte + and is equal to twice the size of the test_xulstore.json file` + ); + + await IOUtils.remove(testDir, { recursive: true }); +}); diff --git a/browser/components/backup/tests/xpcshell/test_measurements.js b/browser/components/backup/tests/xpcshell/test_measurements.js new file mode 100644 index 0000000000..e5726126b2 --- /dev/null +++ b/browser/components/backup/tests/xpcshell/test_measurements.js @@ -0,0 +1,40 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { BackupService } = ChromeUtils.importESModule( + "resource:///modules/backup/BackupService.sys.mjs" +); + +const { TelemetryTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/TelemetryTestUtils.sys.mjs" +); + +add_setup(() => { + do_get_profile(); + // FOG needs to be initialized in order for data to flow. + Services.fog.initializeFOG(); + Services.telemetry.clearScalars(); +}); + +/** + * Tests that we can measure the disk space available in the profile directory. + */ +add_task(async function test_profDDiskSpace() { + let bs = new BackupService(); + await bs.takeMeasurements(); + let measurement = Glean.browserBackup.profDDiskSpace.testGetValue(); + TelemetryTestUtils.assertScalar( + TelemetryTestUtils.getProcessScalars("parent", false, true), + "browser.backup.prof_d_disk_space", + measurement + ); + + Assert.greater( + measurement, + 0, + "Should have collected a measurement for the profile directory storage " + + "device" + ); +}); diff --git a/browser/components/backup/tests/xpcshell/xpcshell.toml b/browser/components/backup/tests/xpcshell/xpcshell.toml new file mode 100644 index 0000000000..fb6dcd6846 --- /dev/null +++ b/browser/components/backup/tests/xpcshell/xpcshell.toml @@ -0,0 +1,8 @@ +[DEFAULT] +firefox-appdir = "browser" +skip-if = ["os == 'android'"] + +["test_BrowserResource.js"] +support-files = ["data/test_xulstore.json"] + +["test_measurements.js"] |