|
| 1 | +/* |
| 2 | +Copyright 2023-2024 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import path from "path"; |
| 18 | +import { readFile } from "node:fs/promises"; |
| 19 | + |
| 20 | +import { expect, test as base } from "../../element-web-test"; |
| 21 | + |
| 22 | +const test = base.extend({ |
| 23 | + // Replace the `user` fixture with one which populates the indexeddb data before starting the app. |
| 24 | + user: async ({ context, pageWithCredentials: page, credentials }, use) => { |
| 25 | + await page.route(`/test_indexeddb_cryptostore_dump/*`, async (route, request) => { |
| 26 | + const resourcePath = path.join(__dirname, new URL(request.url()).pathname); |
| 27 | + const body = await readFile(resourcePath, { encoding: "utf-8" }); |
| 28 | + await route.fulfill({ body }); |
| 29 | + }); |
| 30 | + await page.goto("/test_indexeddb_cryptostore_dump/index.html"); |
| 31 | + |
| 32 | + await use(credentials); |
| 33 | + }, |
| 34 | +}); |
| 35 | + |
| 36 | +test.describe("migration", function () { |
| 37 | + test.use({ displayName: "Alice" }); |
| 38 | + |
| 39 | + test("Should support migration from legacy crypto", async ({ context, user, page }, workerInfo) => { |
| 40 | + test.skip(workerInfo.project.name === "Legacy Crypto", "This test only works with Rust crypto."); |
| 41 | + test.slow(); |
| 42 | + |
| 43 | + // We should see a migration progress bar |
| 44 | + await page.getByText("Hang tight.").waitFor({ timeout: 60000 }); |
| 45 | + |
| 46 | + // When the progress bar first loads, it should have a high max (one per megolm session to import), and |
| 47 | + // a relatively low value. |
| 48 | + const progressBar = page.getByRole("progressbar"); |
| 49 | + const initialProgress = parseFloat(await progressBar.getAttribute("value")); |
| 50 | + const initialMax = parseFloat(await progressBar.getAttribute("max")); |
| 51 | + expect(initialMax).toBeGreaterThan(4000); |
| 52 | + expect(initialProgress).toBeGreaterThanOrEqual(0); |
| 53 | + expect(initialProgress).toBeLessThanOrEqual(500); |
| 54 | + |
| 55 | + // Later, the progress should pass 50% |
| 56 | + await expect |
| 57 | + .poll( |
| 58 | + async () => { |
| 59 | + const progressBar = page.getByRole("progressbar"); |
| 60 | + return ( |
| 61 | + (parseFloat(await progressBar.getAttribute("value")) * 100.0) / |
| 62 | + parseFloat(await progressBar.getAttribute("max")) |
| 63 | + ); |
| 64 | + }, |
| 65 | + { timeout: 60000 }, |
| 66 | + ) |
| 67 | + .toBeGreaterThan(50); |
| 68 | + |
| 69 | + // Eventually, we should get a normal matrix chat |
| 70 | + await page.waitForSelector(".mx_MatrixChat", { timeout: 120000 }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments