Bug 1502312 PlacesUtils.validatePageInfo isn't setting requiredIf for url/guid properly. r=mak

Differential Revision: https://phabricator.services.mozilla.com/D9902

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2018-10-26 12:03:12 +00:00
Родитель 9a4efbbdcc
Коммит f7a8f9e64f
2 изменённых файлов: 10 добавлений и 3 удалений

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

@ -1105,8 +1105,8 @@ var PlacesUtils = {
*/
validatePageInfo(pageInfo, validateVisits = true) {
return this.validateItemProperties("PageInfo", PAGEINFO_VALIDATORS, pageInfo,
{ url: { requiredIf: b => { typeof b.guid != "string"; } },
guid: { requiredIf: b => { typeof b.url != "string"; } },
{ url: { requiredIf: b => !b.guid },
guid: { requiredIf: b => !b.url },
visits: { requiredIf: b => validateVisits },
});
},

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

@ -18,6 +18,13 @@ add_task(async function test_error_cases() {
/Error: PageInfo: Input should be/,
"passing a null as pageInfo should throw an Error"
);
Assert.throws(
() => PlacesUtils.history.update({
description: "Test description",
}),
/Error: PageInfo: The following properties were expected: url, guid/,
"not included a url or a guid should throw"
);
Assert.throws(
() => PlacesUtils.history.update({url: "not a valid url string"}),
/Error: PageInfo: Invalid value for property/,
@ -155,7 +162,7 @@ add_task(async function test_previewImageURL_change_saved() {
let guid = await PlacesTestUtils.fieldInDB(TEST_URL, "guid");
previewImageURL = IMAGE_URL;
await PlacesUtils.history.update({ url: TEST_URL, guid, previewImageURL });
await PlacesUtils.history.update({ guid, previewImageURL });
previewImageURLInDB = await PlacesTestUtils.fieldInDB(TEST_URL, "preview_image_url");
Assert.equal(previewImageURL, previewImageURLInDB, "previewImageURL should be updated via GUID as expected");