/** * Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ /** * schema_31_profile.zip is generated by make_profile.js on a build using * schema version 31. It contains the cache "xpcshell-test" with the entry * http://example.com/index.html and the body "hello world". */ const { TestUtils } = ChromeUtils.importESModule( "resource://testing-common/TestUtils.sys.mjs" ); add_task(async function testSteps() { const url = "http://example.com/index.html"; create_test_profile("schema_31_profile.zip"); info("Opening a cache triggers the 32 -> 33 migration"); const cache = await caches.open("xpcshell-test"); const response = await cache.match(url); ok(response, "Migrated entry is visible"); info("Deleting the migrated entry while its body is still referenced"); ok(await cache.delete(url), "Entry was deleted"); Assert.equal((await cache.keys()).length, 0, "Entry is no longer visible"); Assert.equal(getBodyFiles().length, 1, "Body is kept while referenced"); Assert.equal( await response.text(), "hello world", "Body is still readable after the entry was deleted" ); await TestUtils.waitForCondition( () => !getBodyFiles().length, "Body is removed once no longer referenced" ); await requestFinished(reset()); info("Checking the migrated database"); const conn = await openCacheDatabase(); try { Assert.equal(await conn.getSchemaVersion(), 33, "Schema version is 33"); let [row] = await conn.execute( "SELECT COUNT(*) FROM pragma_table_info('entries') " + "WHERE name = 'pending_deletion'" ); Assert.equal( row.getResultByIndex(0), 1, "entries has a pending_deletion column" ); [row] = await conn.execute( "SELECT COUNT(*) FROM sqlite_master WHERE type = 'index' AND " + "name = 'entries_pending_deletion_index'" ); Assert.equal(row.getResultByIndex(0), 1, "New index exists"); [row] = await conn.execute("SELECT COUNT(*) FROM entries"); Assert.equal(row.getResultByIndex(0), 0, "Entry row was deleted"); Assert.equal( await getTrackedTotalDiskUsage(conn), 0, "Tracked disk usage is back to 0" ); } finally { await conn.close(); } });