summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/gtest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /dom/serviceworkers/test/gtest
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-upstream/125.0.1.tar.xz
firefox-upstream/125.0.1.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/serviceworkers/test/gtest')
-rw-r--r--dom/serviceworkers/test/gtest/TestReadWrite.cpp109
1 files changed, 46 insertions, 63 deletions
diff --git a/dom/serviceworkers/test/gtest/TestReadWrite.cpp b/dom/serviceworkers/test/gtest/TestReadWrite.cpp
index 823647d22e..66b966f9e2 100644
--- a/dom/serviceworkers/test/gtest/TestReadWrite.cpp
+++ b/dom/serviceworkers/test/gtest/TestReadWrite.cpp
@@ -219,7 +219,7 @@ TEST(ServiceWorkerRegistrar, TestReadData)
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
- ASSERT_STREQ("^inBrowser=1", suffix0.get());
+ ASSERT_STREQ("", suffix0.get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
@@ -280,30 +280,24 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
{
RefPtr<ServiceWorkerRegistrarTest> swr = new ServiceWorkerRegistrarTest;
- for (int i = 0; i < 2; ++i) {
- ServiceWorkerRegistrationData reg;
-
- reg.scope() = nsPrintfCString("https://scope_write_%d.org", i);
- reg.currentWorkerURL() = nsPrintfCString("currentWorkerURL write %d", i);
- reg.currentWorkerHandlesFetch() = true;
- reg.cacheName() =
- NS_ConvertUTF8toUTF16(nsPrintfCString("cacheName write %d", i));
- reg.updateViaCache() =
- nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_IMPORTS;
+ ServiceWorkerRegistrationData reg;
- reg.currentWorkerInstalledTime() = PR_Now();
- reg.currentWorkerActivatedTime() = PR_Now();
- reg.lastUpdateTime() = PR_Now();
+ reg.scope() = "https://scope_write_0.org"_ns;
+ reg.currentWorkerURL() = "currentWorkerURL write 0"_ns;
+ reg.currentWorkerHandlesFetch() = true;
+ reg.cacheName() = u"cacheName write 0"_ns;
+ reg.updateViaCache() =
+ nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_IMPORTS;
- nsAutoCString spec;
- spec.AppendPrintf("spec write %d", i);
+ reg.currentWorkerInstalledTime() = PR_Now();
+ reg.currentWorkerActivatedTime() = PR_Now();
+ reg.lastUpdateTime() = PR_Now();
- reg.principal() = mozilla::ipc::ContentPrincipalInfo(
- mozilla::OriginAttributes(i % 2), spec, spec, mozilla::Nothing(),
- spec);
+ const auto spec = "spec write 0"_ns;
+ reg.principal() = mozilla::ipc::ContentPrincipalInfo(
+ mozilla::OriginAttributes(), spec, spec, mozilla::Nothing(), spec);
- swr->TestRegisterServiceWorker(reg);
- }
+ swr->TestRegisterServiceWorker(reg);
nsresult rv = swr->TestWriteData();
ASSERT_EQ(NS_OK, rv) << "WriteData() should not fail";
@@ -314,47 +308,37 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
nsresult rv = swr->TestReadData();
ASSERT_EQ(NS_OK, rv) << "ReadData() should not fail";
- const nsTArray<ServiceWorkerRegistrationData>& data = swr->TestGetData();
- ASSERT_EQ((uint32_t)2, data.Length()) << "2 entries should be found";
-
- for (int i = 0; i < 2; ++i) {
- nsAutoCString test;
-
- ASSERT_EQ(data[i].principal().type(),
- mozilla::ipc::PrincipalInfo::TContentPrincipalInfo);
- const mozilla::ipc::ContentPrincipalInfo& cInfo = data[i].principal();
+ const nsTArray<ServiceWorkerRegistrationData>& dataArr = swr->TestGetData();
+ ASSERT_EQ((uint32_t)1, dataArr.Length()) << "1 entries should be found";
- mozilla::OriginAttributes attrs(i % 2);
- nsAutoCString suffix, expectSuffix;
- attrs.CreateSuffix(expectSuffix);
- cInfo.attrs().CreateSuffix(suffix);
+ const auto& data = dataArr[0];
- ASSERT_STREQ(expectSuffix.get(), suffix.get());
+ ASSERT_EQ(data.principal().type(),
+ mozilla::ipc::PrincipalInfo::TContentPrincipalInfo);
+ const mozilla::ipc::ContentPrincipalInfo& cInfo = data.principal();
- test.AppendPrintf("https://scope_write_%d.org", i);
- ASSERT_STREQ(test.get(), cInfo.spec().get());
+ mozilla::OriginAttributes attrs;
+ nsAutoCString suffix, expectSuffix;
+ attrs.CreateSuffix(expectSuffix);
+ cInfo.attrs().CreateSuffix(suffix);
- test.Truncate();
- test.AppendPrintf("https://scope_write_%d.org", i);
- ASSERT_STREQ(test.get(), data[i].scope().get());
+ ASSERT_STREQ(expectSuffix.get(), suffix.get());
- test.Truncate();
- test.AppendPrintf("currentWorkerURL write %d", i);
- ASSERT_STREQ(test.get(), data[i].currentWorkerURL().get());
+ ASSERT_STREQ("https://scope_write_0.org", cInfo.spec().get());
+ ASSERT_STREQ("https://scope_write_0.org", data.scope().get());
+ ASSERT_STREQ("currentWorkerURL write 0", data.currentWorkerURL().get());
- ASSERT_EQ(true, data[i].currentWorkerHandlesFetch());
+ ASSERT_EQ(true, data.currentWorkerHandlesFetch());
- test.Truncate();
- test.AppendPrintf("cacheName write %d", i);
- ASSERT_STREQ(test.get(), NS_ConvertUTF16toUTF8(data[i].cacheName()).get());
+ ASSERT_STREQ("cacheName write 0",
+ NS_ConvertUTF16toUTF8(data.cacheName()).get());
- ASSERT_EQ(nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_IMPORTS,
- data[i].updateViaCache());
+ ASSERT_EQ(nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_IMPORTS,
+ data.updateViaCache());
- ASSERT_NE((int64_t)0, data[i].currentWorkerInstalledTime());
- ASSERT_NE((int64_t)0, data[i].currentWorkerActivatedTime());
- ASSERT_NE((int64_t)0, data[i].lastUpdateTime());
- }
+ ASSERT_NE((int64_t)0, data.currentWorkerInstalledTime());
+ ASSERT_NE((int64_t)0, data.currentWorkerActivatedTime());
+ ASSERT_NE((int64_t)0, data.lastUpdateTime());
}
TEST(ServiceWorkerRegistrar, TestVersion2Migration)
@@ -394,7 +378,7 @@ TEST(ServiceWorkerRegistrar, TestVersion2Migration)
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
- ASSERT_STREQ("^inBrowser=1", suffix0.get());
+ ASSERT_STREQ("", suffix0.get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
@@ -464,7 +448,7 @@ TEST(ServiceWorkerRegistrar, TestVersion3Migration)
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
- ASSERT_STREQ("^inBrowser=1", suffix0.get());
+ ASSERT_STREQ("", suffix0.get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
@@ -532,7 +516,7 @@ TEST(ServiceWorkerRegistrar, TestVersion4Migration)
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
- ASSERT_STREQ("^inBrowser=1", suffix0.get());
+ ASSERT_STREQ("", suffix0.get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
@@ -604,7 +588,7 @@ TEST(ServiceWorkerRegistrar, TestVersion5Migration)
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
- ASSERT_STREQ("^inBrowser=1", suffix0.get());
+ ASSERT_STREQ("", suffix0.get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
@@ -678,7 +662,7 @@ TEST(ServiceWorkerRegistrar, TestVersion6Migration)
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
- ASSERT_STREQ("^inBrowser=1", suffix0.get());
+ ASSERT_STREQ("", suffix0.get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
@@ -765,7 +749,7 @@ TEST(ServiceWorkerRegistrar, TestVersion7Migration)
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
- ASSERT_STREQ("^inBrowser=1", suffix0.get());
+ ASSERT_STREQ("", suffix0.get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
@@ -850,7 +834,7 @@ TEST(ServiceWorkerRegistrar, TestDedupeRead)
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
- ASSERT_STREQ("^inBrowser=1", suffix0.get());
+ ASSERT_STREQ("", suffix0.get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
@@ -903,8 +887,7 @@ TEST(ServiceWorkerRegistrar, TestDedupeWrite)
spec.AppendPrintf("spec write dedupe/%d", i);
reg.principal() = mozilla::ipc::ContentPrincipalInfo(
- mozilla::OriginAttributes(false), spec, spec, mozilla::Nothing(),
- spec);
+ mozilla::OriginAttributes(), spec, spec, mozilla::Nothing(), spec);
swr->TestRegisterServiceWorker(reg);
}
@@ -926,7 +909,7 @@ TEST(ServiceWorkerRegistrar, TestDedupeWrite)
mozilla::ipc::PrincipalInfo::TContentPrincipalInfo);
const mozilla::ipc::ContentPrincipalInfo& cInfo = data[0].principal();
- mozilla::OriginAttributes attrs(false);
+ mozilla::OriginAttributes attrs;
nsAutoCString suffix, expectSuffix;
attrs.CreateSuffix(expectSuffix);
cInfo.attrs().CreateSuffix(suffix);