-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathBrowserServerStorageIntegrationTests.cs
More file actions
134 lines (109 loc) · 7.03 KB
/
BrowserServerStorageIntegrationTests.cs
File metadata and controls
134 lines (109 loc) · 7.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Threading.Tasks;
using Shouldly;
using Xunit;
using static Microsoft.Playwright.Assertions;
namespace ManagedCode.Storage.Tests.Storages.Browser;
[Collection(nameof(BrowserServerHostCollection))]
public sealed class BrowserServerStorageIntegrationTests(BrowserServerHostFixture fixture)
{
[Fact]
public async Task BrowserStorage_ServerHost_TextFlow_ShouldPersistListAndDelete()
{
await using var context = await fixture.CreateContextAsync();
var page = await context.NewPageAsync();
var directory = "server-browser-storage-tests";
var fileName = $"text-{Guid.NewGuid():N}.txt";
var content = $"content-{Guid.NewGuid():N}";
var updatedContent = $"updated-{Guid.NewGuid():N}";
var blobKeyPrefix = $"{fixture.ContainerKey}::{directory}/{fileName}::payload::";
await BrowserStoragePage.OpenPlaygroundAsync(page);
await BrowserStoragePage.FillInputsAsync(page, directory, fileName, content);
await page.ClickAsync("#save-text-button");
await Expect(page.Locator("#status-output")).ToContainTextAsync($"saved:{directory}/{fileName}");
await page.ClickAsync("#exists-button");
await Expect(page.Locator("#exists-output")).ToContainTextAsync("True");
await page.ClickAsync("#list-button");
await Expect(page.Locator("#blob-list")).ToContainTextAsync(fileName);
await page.FillAsync("#content-input", updatedContent);
await page.ClickAsync("#save-text-button");
await Expect(page.Locator("#status-output")).ToContainTextAsync($"saved:{directory}/{fileName}");
await page.ClickAsync("#load-text-button");
await Expect(page.Locator("#loaded-output")).ToHaveTextAsync(updatedContent);
var payloadStore = await BrowserStoragePage.ReadPayloadStoreAsync(page, fixture, $"{directory}/{fileName}");
payloadStore.ShouldBe("opfs");
var payloadFileCount = await BrowserStoragePage.ReadOpfsPayloadFileCountAsync(page, fixture, blobKeyPrefix);
payloadFileCount.ShouldBe(1);
var indexedDbCount = await BrowserStoragePage.ReadIndexedDbCountAsync(page, fixture, directory);
indexedDbCount.ShouldBe(1);
await page.ClickAsync("#delete-button");
await Expect(page.Locator("#status-output")).ToContainTextAsync("deleted:True");
await page.ClickAsync("#exists-button");
await Expect(page.Locator("#exists-output")).ToContainTextAsync("False");
}
[Fact]
[Trait("Category", "LargeFile")]
[Trait("Category", "BrowserStress")]
public async Task BrowserStorage_ServerHost_LargeFlow_ShouldPersistAcrossPages()
{
const int chunkedPayloadSizeMiB = 1024;
const long expectedLengthBytes = 1024L * 1024L * 1024L;
const float largeTimeoutMs = 900000;
await using var context = await fixture.CreateContextAsync();
var firstPage = await context.NewPageAsync();
var directory = "server-browser-storage-large";
var fileName = $"large-{Guid.NewGuid():N}.bin";
await BrowserStoragePage.OpenPlaygroundAsync(firstPage);
await BrowserStoragePage.FillInputsAsync(firstPage, directory, fileName, "ignored");
await BrowserStoragePage.FillSizeAsync(firstPage, chunkedPayloadSizeMiB);
await firstPage.ClickAsync("#save-large-button");
await Expect(firstPage.Locator("#status-output")).ToContainTextAsync("large-saved:", new() { Timeout = largeTimeoutMs });
await Expect(firstPage.Locator("#large-output")).ToContainTextAsync($"expected:{expectedLengthBytes}:", new() { Timeout = largeTimeoutMs });
var expected = await BrowserStoragePage.ReadTextAsync(firstPage, "#large-output");
expected.StartsWith($"expected:{expectedLengthBytes}:", StringComparison.Ordinal).ShouldBeTrue();
var payloadStore = await BrowserStoragePage.ReadPayloadStoreAsync(firstPage, fixture, $"{directory}/{fileName}");
payloadStore.ShouldBe("opfs");
var secondPage = await context.NewPageAsync();
await BrowserStoragePage.OpenPlaygroundAsync(secondPage);
await BrowserStoragePage.FillInputsAsync(secondPage, directory, fileName, "ignored");
await BrowserStoragePage.FillSizeAsync(secondPage, chunkedPayloadSizeMiB);
await secondPage.ClickAsync("#load-large-button");
await Expect(secondPage.Locator("#status-output")).ToContainTextAsync("large-loading", new() { Timeout = 10000 });
await Expect(secondPage.Locator("#status-output")).ToContainTextAsync("large-loaded:", new() { Timeout = largeTimeoutMs });
await Expect(secondPage.Locator("#large-output")).ToContainTextAsync($"actual:{expectedLengthBytes}:", new() { Timeout = largeTimeoutMs });
var actual = await BrowserStoragePage.ReadTextAsync(secondPage, "#large-output");
actual.StartsWith($"actual:{expectedLengthBytes}:", StringComparison.Ordinal).ShouldBeTrue();
actual.ShouldBe(expected.Replace("expected:", "actual:", StringComparison.Ordinal));
var reloadedPayloadStore = await BrowserStoragePage.ReadPayloadStoreAsync(secondPage, fixture, $"{directory}/{fileName}");
reloadedPayloadStore.ShouldBe("opfs");
}
[Fact]
public async Task BrowserStorage_ServerHost_ConcurrentTabs_ShouldPersistAllFiles()
{
await using var context = await fixture.CreateContextAsync();
var firstPage = await context.NewPageAsync();
var secondPage = await context.NewPageAsync();
var verificationPage = await context.NewPageAsync();
var directory = $"server-browser-storage-concurrent-{Guid.NewGuid():N}";
var firstFileName = $"first-{Guid.NewGuid():N}.txt";
var secondFileName = $"second-{Guid.NewGuid():N}.txt";
var firstContent = $"content-{Guid.NewGuid():N}";
var secondContent = $"content-{Guid.NewGuid():N}";
await BrowserStoragePage.OpenPlaygroundAsync(firstPage);
await BrowserStoragePage.OpenPlaygroundAsync(secondPage);
await BrowserStoragePage.FillInputsAsync(firstPage, directory, firstFileName, firstContent);
await BrowserStoragePage.FillInputsAsync(secondPage, directory, secondFileName, secondContent);
await Task.WhenAll(
firstPage.ClickAsync("#save-text-button"),
secondPage.ClickAsync("#save-text-button"));
await Expect(firstPage.Locator("#status-output")).ToContainTextAsync($"saved:{directory}/{firstFileName}");
await Expect(secondPage.Locator("#status-output")).ToContainTextAsync($"saved:{directory}/{secondFileName}");
await BrowserStoragePage.OpenPlaygroundAsync(verificationPage);
await verificationPage.FillAsync("#directory-input", directory);
await verificationPage.ClickAsync("#list-button");
await Expect(verificationPage.Locator("#blob-list")).ToContainTextAsync(firstFileName);
await Expect(verificationPage.Locator("#blob-list")).ToContainTextAsync(secondFileName);
var indexedDbCount = await BrowserStoragePage.ReadIndexedDbCountAsync(verificationPage, fixture, directory);
indexedDbCount.ShouldBe(2);
}
}