Bug 1290944 - Part 4.2: Update a related gtest. r=bkelly

This commit is contained in:
Ho-Pang Hsu 2017-01-04 17:09:10 +08:00
Родитель 0f06d93ea7
Коммит 6311ff9492
1 изменённых файлов: 88 добавлений и 1 удалений

Просмотреть файл

@ -151,12 +151,16 @@ TEST(ServiceWorkerRegistrar, TestReadData)
buffer.Append("scope 0\ncurrentWorkerURL 0\n"); buffer.Append("scope 0\ncurrentWorkerURL 0\n");
buffer.Append(SERVICEWORKERREGISTRAR_TRUE "\n"); buffer.Append(SERVICEWORKERREGISTRAR_TRUE "\n");
buffer.Append("cacheName 0\n"); buffer.Append("cacheName 0\n");
buffer.AppendInt(nsIRequest::LOAD_NORMAL, 16);
buffer.Append("\n");
buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n"); buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.Append("\n"); buffer.Append("\n");
buffer.Append("scope 1\ncurrentWorkerURL 1\n"); buffer.Append("scope 1\ncurrentWorkerURL 1\n");
buffer.Append(SERVICEWORKERREGISTRAR_FALSE "\n"); buffer.Append(SERVICEWORKERREGISTRAR_FALSE "\n");
buffer.Append("cacheName 1\n"); buffer.Append("cacheName 1\n");
buffer.AppendInt(nsIRequest::VALIDATE_ALWAYS, 16);
buffer.Append("\n");
buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n"); buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
ASSERT_TRUE(CreateFile(buffer)) << "CreateFile should not fail"; ASSERT_TRUE(CreateFile(buffer)) << "CreateFile should not fail";
@ -182,6 +186,7 @@ TEST(ServiceWorkerRegistrar, TestReadData)
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_TRUE(data[0].currentWorkerHandlesFetch()); ASSERT_TRUE(data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get()); ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
ASSERT_EQ(nsIRequest::LOAD_NORMAL, data[0].loadFlags());
const mozilla::ipc::PrincipalInfo& info1 = data[1].principal(); const mozilla::ipc::PrincipalInfo& info1 = data[1].principal();
ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content"; ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
@ -196,6 +201,7 @@ TEST(ServiceWorkerRegistrar, TestReadData)
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_FALSE(data[1].currentWorkerHandlesFetch()); ASSERT_FALSE(data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get()); ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[1].loadFlags());
} }
TEST(ServiceWorkerRegistrar, TestDeleteData) TEST(ServiceWorkerRegistrar, TestDeleteData)
@ -225,8 +231,10 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
reg.scope() = nsPrintfCString("scope write %d", i); reg.scope() = nsPrintfCString("scope write %d", i);
reg.currentWorkerURL() = nsPrintfCString("currentWorkerURL write %d", i); reg.currentWorkerURL() = nsPrintfCString("currentWorkerURL write %d", i);
reg.currentWorkerHandlesFetch() = true;
reg.cacheName() = reg.cacheName() =
NS_ConvertUTF8toUTF16(nsPrintfCString("cacheName write %d", i)); NS_ConvertUTF8toUTF16(nsPrintfCString("cacheName write %d", i));
reg.loadFlags() = nsIRequest::VALIDATE_ALWAYS;
nsAutoCString spec; nsAutoCString spec;
spec.AppendPrintf("spec write %d", i); spec.AppendPrintf("spec write %d", i);
@ -272,9 +280,13 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
test.AppendPrintf("currentWorkerURL write %d", i); test.AppendPrintf("currentWorkerURL write %d", i);
ASSERT_STREQ(test.get(), data[i].currentWorkerURL().get()); ASSERT_STREQ(test.get(), data[i].currentWorkerURL().get());
ASSERT_EQ(true, data[i].currentWorkerHandlesFetch());
test.Truncate(); test.Truncate();
test.AppendPrintf("cacheName write %d", i); test.AppendPrintf("cacheName write %d", i);
ASSERT_STREQ(test.get(), NS_ConvertUTF16toUTF8(data[i].cacheName()).get()); ASSERT_STREQ(test.get(), NS_ConvertUTF16toUTF8(data[i].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[i].loadFlags());
} }
} }
@ -311,7 +323,9 @@ TEST(ServiceWorkerRegistrar, TestVersion2Migration)
ASSERT_STREQ("scope 0", cInfo0.spec().get()); ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get()); ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("activeCache 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get()); ASSERT_STREQ("activeCache 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[0].loadFlags());
const mozilla::ipc::PrincipalInfo& info1 = data[1].principal(); const mozilla::ipc::PrincipalInfo& info1 = data[1].principal();
ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content"; ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
@ -324,7 +338,9 @@ TEST(ServiceWorkerRegistrar, TestVersion2Migration)
ASSERT_STREQ("scope 1", cInfo1.spec().get()); ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get()); ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_EQ(true, data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("activeCache 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get()); ASSERT_STREQ("activeCache 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[1].loadFlags());
} }
TEST(ServiceWorkerRegistrar, TestVersion3Migration) TEST(ServiceWorkerRegistrar, TestVersion3Migration)
@ -360,7 +376,9 @@ TEST(ServiceWorkerRegistrar, TestVersion3Migration)
ASSERT_STREQ("scope 0", cInfo0.spec().get()); ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get()); ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get()); ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[0].loadFlags());
const mozilla::ipc::PrincipalInfo& info1 = data[1].principal(); const mozilla::ipc::PrincipalInfo& info1 = data[1].principal();
ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content"; ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
@ -373,7 +391,9 @@ TEST(ServiceWorkerRegistrar, TestVersion3Migration)
ASSERT_STREQ("scope 1", cInfo1.spec().get()); ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get()); ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_EQ(true, data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get()); ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[1].loadFlags());
} }
TEST(ServiceWorkerRegistrar, TestVersion4Migration) TEST(ServiceWorkerRegistrar, TestVersion4Migration)
@ -410,8 +430,9 @@ TEST(ServiceWorkerRegistrar, TestVersion4Migration)
ASSERT_STREQ("scope 0", data[0].scope().get()); ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
// default is true // default is true
ASSERT_EQ(true, data[1].currentWorkerHandlesFetch()); ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get()); ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[0].loadFlags());
const mozilla::ipc::PrincipalInfo& info1 = data[1].principal(); const mozilla::ipc::PrincipalInfo& info1 = data[1].principal();
ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content"; ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
@ -427,6 +448,64 @@ TEST(ServiceWorkerRegistrar, TestVersion4Migration)
// default is true // default is true
ASSERT_EQ(true, data[1].currentWorkerHandlesFetch()); ASSERT_EQ(true, data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get()); ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[1].loadFlags());
}
TEST(ServiceWorkerRegistrar, TestVersion5Migration)
{
nsAutoCString buffer("5" "\n");
buffer.Append("^appId=123&inBrowser=1\n");
buffer.Append("scope 0\ncurrentWorkerURL 0\n");
buffer.Append(SERVICEWORKERREGISTRAR_TRUE "\n");
buffer.Append("cacheName 0\n");
buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.Append("\n");
buffer.Append("scope 1\ncurrentWorkerURL 1\n");
buffer.Append(SERVICEWORKERREGISTRAR_FALSE "\n");
buffer.Append("cacheName 1\n");
buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
ASSERT_TRUE(CreateFile(buffer)) << "CreateFile should not fail";
RefPtr<ServiceWorkerRegistrarTest> swr = new ServiceWorkerRegistrarTest;
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";
const mozilla::ipc::PrincipalInfo& info0 = data[0].principal();
ASSERT_EQ(info0.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
const mozilla::ipc::ContentPrincipalInfo& cInfo0 = data[0].principal();
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_TRUE(data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[0].loadFlags());
const mozilla::ipc::PrincipalInfo& info1 = data[1].principal();
ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
const mozilla::ipc::ContentPrincipalInfo& cInfo1 = data[1].principal();
nsAutoCString suffix1;
cInfo1.attrs().CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_FALSE(data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[1].loadFlags());
} }
TEST(ServiceWorkerRegistrar, TestDedupeRead) TEST(ServiceWorkerRegistrar, TestDedupeRead)
@ -476,7 +555,9 @@ TEST(ServiceWorkerRegistrar, TestDedupeRead)
ASSERT_STREQ("scope 0", cInfo0.spec().get()); ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get()); ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get()); ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[0].loadFlags());
const mozilla::ipc::PrincipalInfo& info1 = data[1].principal(); const mozilla::ipc::PrincipalInfo& info1 = data[1].principal();
ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content"; ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
@ -489,7 +570,9 @@ TEST(ServiceWorkerRegistrar, TestDedupeRead)
ASSERT_STREQ("scope 1", cInfo1.spec().get()); ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get()); ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_EQ(true, data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get()); ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[1].loadFlags());
} }
TEST(ServiceWorkerRegistrar, TestDedupeWrite) TEST(ServiceWorkerRegistrar, TestDedupeWrite)
@ -502,8 +585,10 @@ TEST(ServiceWorkerRegistrar, TestDedupeWrite)
reg.scope() = NS_LITERAL_CSTRING("scope write dedupe"); reg.scope() = NS_LITERAL_CSTRING("scope write dedupe");
reg.currentWorkerURL() = nsPrintfCString("currentWorkerURL write %d", i); reg.currentWorkerURL() = nsPrintfCString("currentWorkerURL write %d", i);
reg.currentWorkerHandlesFetch() = true;
reg.cacheName() = reg.cacheName() =
NS_ConvertUTF8toUTF16(nsPrintfCString("cacheName write %d", i)); NS_ConvertUTF8toUTF16(nsPrintfCString("cacheName write %d", i));
reg.loadFlags() = nsIRequest::VALIDATE_ALWAYS;
nsAutoCString spec; nsAutoCString spec;
spec.AppendPrintf("spec write dedupe/%d", i); spec.AppendPrintf("spec write dedupe/%d", i);
@ -540,8 +625,10 @@ TEST(ServiceWorkerRegistrar, TestDedupeWrite)
ASSERT_STREQ("scope write dedupe", cInfo.spec().get()); ASSERT_STREQ("scope write dedupe", cInfo.spec().get());
ASSERT_STREQ("scope write dedupe", data[0].scope().get()); ASSERT_STREQ("scope write dedupe", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL write 9", data[0].currentWorkerURL().get()); ASSERT_STREQ("currentWorkerURL write 9", data[0].currentWorkerURL().get());
ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName write 9", ASSERT_STREQ("cacheName write 9",
NS_ConvertUTF16toUTF8(data[0].cacheName()).get()); NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
ASSERT_EQ(nsIRequest::VALIDATE_ALWAYS, data[0].loadFlags());
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {