This commit is contained in:
Simon Binder 2023-07-06 21:45:38 +02:00
parent 3e6cf51eea
commit 0de1e43409
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 33 additions and 11 deletions

View File

@ -20,8 +20,6 @@ class TestAssetServer {
final BuildDaemonClient buildRunner;
late final HttpServer server;
bool addCoopAndCoepHeaders = true;
TestAssetServer(this.buildRunner);
Future<void> close() async {
@ -69,17 +67,25 @@ class TestAssetServer {
final proxy = proxyHandler('http://localhost:$assetServerPort/web/');
server.server = await serve(
(request) async {
final response = await proxy(request);
final pathSegments = request.url.pathSegments;
if (server.addCoopAndCoepHeaders) {
return response.change(headers: {
// Needed for shared array buffers to work
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp'
});
if (pathSegments.isNotEmpty && pathSegments[0] == 'no-coep') {
// Serve stuff under /no-coep like the regular website, but without
// adding the security headers.
return await proxy(request.change(path: 'no-coep'));
} else {
final response = await proxy(request);
if (!request.url.path.startsWith('/no-coep')) {
return response.change(headers: {
// Needed for shared array buffers to work
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp'
});
}
return response;
}
return response;
},
'localhost',
8080,

View File

@ -176,6 +176,22 @@ void main() {
expect(await driver.amountOfRows, 1);
},
);
if (!browser.supports(WasmStorageImplementation.opfsShared)) {
test('uses indexeddb after OPFS becomes unavailable', () async {
// This browser only supports OPFS with the right headers. If they
// are ever removed, data is lost (nothing we could do about that),
// but drift should continue to work.
await driver.openDatabase(WasmStorageImplementation.opfsLocks);
await driver.insertIntoDatabase();
expect(await driver.amountOfRows, 1);
await Future.delayed(const Duration(seconds: 2));
await driver.driver.get('http://localhost:8080/no-coep');
await driver.openDatabase();
expect(await driver.amountOfRows, isZero);
});
}
}
});
}