mirror of https://github.com/AMT-Cheif/drift.git
Add test
This commit is contained in:
parent
3e6cf51eea
commit
0de1e43409
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue