// Bug 1617611: Fix all the tests broken by "cookies SameSite=lax by default"
Services.prefs.setBoolPref("network.cookie.sameSite.laxByDefault", false);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("network.cookie.sameSite.laxByDefault");
});
add_task(async function noCookiesWhenNoneAreSet({ client }) { const { Network } = client; const { cookies } = await Network.getCookies({ urls: [DEFAULT_HOST] });
is(cookies.length, 0, "No cookies have been found");
});
try { const { cookies } = await Network.getCookies();
is(cookies.length, 0, "No cookies have been found");
} finally {
Services.cookies.removeAll();
}
});
try { const { cookies } = await Network.getCookies();
is(cookies.length, 1, "All cookies have been found");
assertCookie(cookies[0], cookie);
} finally {
Services.cookies.removeAll();
}
});
try { const { cookies } = await Network.getCookies();
cookies.sort((a, b) => a.name.localeCompare(b.name));
is(cookies.length, 2, "All cookies have been found");
assertCookie(cookies[0], cookie1);
assertCookie(cookies[1], cookie2);
} finally {
Services.cookies.removeAll();
}
});
add_task(async function allCookiesIncludingSubFrames({ client }) { const GET_COOKIES_PAGE_URL = `${DEFAULT_HOST}${BASE_PATH}/doc_get_cookies_page.html`;
try { const { cookies } = await Network.getCookies();
cookies.sort((a, b) => a.name.localeCompare(b.name));
is(cookies.length, 2, "All cookies have been found including subframe");
assertCookie(cookies[0], cookie_frame);
assertCookie(cookies[1], cookie_page);
} finally {
Services.cookies.removeAll();
}
});
try { // Cookie returned for secure protocols
let result = await Network.getCookies();
is(result.cookies.length, 1, "The secure cookie has been found");
assertCookie(result.cookies[0], cookie);
// For unsecure protocols no secure cookies are returned
await loadURL(DEFAULT_URL);
result = await Network.getCookies();
is(result.cookies.length, 0, "No secure cookies have been found");
} finally {
Services.cookies.removeAll();
}
});
add_task(async function expiry({ client }) { const { Network } = client; const date = new Date();
date.setDate(date.getDate() + 3);
try { const { cookies } = await Network.getCookies();
is(cookies.length, 1, "A single cookie has been found");
assertCookie(cookies[0], cookie);
} finally {
Services.cookies.removeAll();
}
});
try { const { cookies } = await Network.getCookies();
is(cookies.length, 1, "A single cookie has been found");
assertCookie(cookies[0], cookie);
} finally {
Services.cookies.removeAll();
}
});
try {
console.log("Check exact path");
await loadURL(`${DEFAULT_HOST}${PATH}`);
let result = await Network.getCookies();
is(result.cookies.length, 1, "A single cookie has been found");
assertCookie(result.cookies[0], cookie);
console.log("Check sub path");
await loadURL(`${DEFAULT_HOST}${SJS_PATH}`);
result = await Network.getCookies();
is(result.cookies.length, 1, "A single cookie has been found");
assertCookie(result.cookies[0], cookie);
console.log("Check parent path");
await loadURL(`${DEFAULT_HOST}${PARENT_PATH}`);
result = await Network.getCookies();
is(result.cookies.length, 0, "No cookies have been found");
console.log("Check non matching path");
await loadURL(`${DEFAULT_HOST}/foo/bar`);
result = await Network.getCookies();
is(result.cookies.length, 0, "No cookies have been found");
} finally {
Services.cookies.removeAll();
}
});
try { const { cookies } = await Network.getCookies();
is(cookies.length, 1, "A single cookie has been found");
assertCookie(cookies[0], cookie);
} finally {
Services.cookies.removeAll();
}
});
add_task(async function sameSite({ client }) { const { Network } = client; for (const value of ["Lax", "Strict"]) {
console.log(`Test cookie with SameSite=${value}`);
await loadURL(`${DEFAULT_URL}?name=foo&value=bar&sameSite=${value}`);
try { const { cookies } = await Network.getCookies();
is(cookies.length, 1, "A single cookie has been found");
assertCookie(cookies[0], cookie);
} finally {
Services.cookies.removeAll();
}
});
for (const testCase of testTable) {
await Assert.rejects(
Network.getCookies({ urls: testCase }),
/urls: array expected/,
`Fails the argument type for urls`
);
}
});
for (const testCase of testTable) {
await Assert.rejects(
Network.getCookies({ urls: testCase }),
/urls: string value expected at index 0/,
`Fails the argument type for urls`
);
}
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.