Repository: puppeteer/puppeteer
File: test/src/cookies.spec.ts (TypeScript)

Code before:
        url: COOKIE_DESTINATION_URL,
        name: COOKIE_NAME,
      });

      // Verify the cookie is deleted for specified URL.
      expect(await page.cookies(COOKIE_DESTINATION_URL)).toHaveLength(0);

      // Verify the cookie is not deleted for the current page.
      await expectCookieEquals(await page.cookies(), [
        {
          name: COOKIE_NAME,
          value: 'some_cookie_value',
          domain: 'localhost',
          path: '/',
          sameParty: false,
          expires: -1,
          size: 33,
          httpOnly: false,
          secure: false,
          session: true,
          sourceScheme: 'NonSecure',
        },
      ]);
    });
    it('should delete cookie for specified URL regardless of the current page', async () => {
      // Tentative test case. Depending on the cookie partitioning implementation, this
      // test case may not pass.
      // This test verifies the page.deleteCookie method deletes cookies for the custom
      // destination URL, even if it was set from another page.

      const {page, server} = await getTestState();
      const COOKIE_DESTINATION_URL = 'https://example.com';
      const COOKIE_NAME = 'some_cookie_name';
      const URL_1 = server.EMPTY_PAGE;
      const URL_2 = server.CROSS_PROCESS_PREFIX + '/empty.html';

      await page.goto(URL_1);
      // Set a cookie for the COOKIE_DESTINATION from URL_1.
      await page.setCookie({
        url: COOKIE_DESTINATION_URL,
        name: COOKIE_NAME,
        value: 'Cookie from URL_1',
      });
      expect(await page.cookies(COOKIE_DESTINATION_URL)).toHaveLength(1);

      await page.goto(URL_2);
      // Set a cookie for the COOKIE_DESTINATION from URL_2.
      await page.setCookie({
        url: COOKIE_DESTINATION_URL,
        name: COOKIE_NAME,
        value: 'Cookie from URL_2',

Review comment (bug):
This is an edge case where firefox and chrome can have observable different behavior. In ff all the cookies are partitioned, while in chrome they are not. In ff if context partition is used, delete command scoped to the cookies set by the current page. In chrome it is scoped only for the user context. As discussed offline, this is an expected to have different behavior for different implementations.

Code after:
        url: COOKIE_DESTINATION_URL,
        name: COOKIE_NAME,
      });

      // Verify the cookie is deleted for specified URL.
      expect(await page.cookies(COOKIE_DESTINATION_URL)).toHaveLength(0);

      // Verify the cookie is not deleted for the current page.
      await expectCookieEquals(await page.cookies(), [
        {
          name: COOKIE_NAME,
          value: 'some_cookie_value',
          domain: 'localhost',
          path: '/',
          sameParty: false,
          expires: -1,
          size: 33,
          httpOnly: false,
          secure: false,
          session: true,
          sourceScheme: 'NonSecure',
        },
      ]);
    });
    it('should delete cookie for specified URL regardless of the current page', async () => {
      // This test verifies the page.deleteCookie method deletes cookies for the custom
      // destination URL, even if it was set from another page. Depending on the cookie
      // partitioning implementation, this test case does not pass, if source origin is in
      // the default cookie partition.

      const {page, server} = await getTestState();
      const COOKIE_DESTINATION_URL = 'https://example.com';
      const COOKIE_NAME = 'some_cookie_name';
      const URL_1 = server.EMPTY_PAGE;
      const URL_2 = server.CROSS_PROCESS_PREFIX + '/empty.html';

      await page.goto(URL_1);
      // Set a cookie for the COOKIE_DESTINATION from URL_1.
      await page.setCookie({
        url: COOKIE_DESTINATION_URL,
        name: COOKIE_NAME,
        value: 'Cookie from URL_1',
      });
      expect(await page.cookies(COOKIE_DESTINATION_URL)).toHaveLength(1);

      await page.goto(URL_2);
      // Set a cookie for the COOKIE_DESTINATION from URL_2.
      await page.setCookie({
        url: COOKIE_DESTINATION_URL,
        name: COOKIE_NAME,
        value: 'Cookie from URL_2',