Closed Bug 1732473 Opened 3 years ago Closed 3 years ago

Refactor ext-cookies.js: consolidate duplicate logic

Categories

(WebExtensions :: General, task, P3)

task

Tracking

(firefox96 fixed)

RESOLVED FIXED
96 Branch
Tracking Status
firefox96 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

Details

(Whiteboard: [addons-jira])

Attachments

(3 files)

ext-cookies.js has some duplication of logic. To improve maintainability, the logic should be consolidated. In bug 1669716 I am introducing a new method to derive origin attributes from the received details, that method can be expanded to resolve this bug.

Duplicate logic (only difference is to return early vs throwing error):

Redundant private browsing check:

Changing severity to N/A because this is a task.

Severity: -- → N/A
Priority: -- → P3

The cookies API implementation emits a bunch of errors in some cases,
but these are not covered by unit tests. I'm going to refactor some
logic involving these checks, and before doing so I'd like to start
with unit tests with the current behavior as expectations.

Move the duplicate logic of parsing the storeId to a common place.

This patch has the following observable changes in behavior:

  • Invalid storeId (whether with the "firefox-container-" prefix or with
    something else) have the same error message instead of distinct ones.
    Instead of "Illegal storeId: Xor "Unknown storeId", the message is nowInvalid cookie store id: "X"`, which is also what Chromium uses.

  • Invalid storeId in remove, get and getAll now result in an error,
    instead of being ignored silently. This is now consistent with the
    existing behavior for the cookies.set method, and also consistent with
    how Chromium rejects invalid storeId values.

The query method already validates whether access to private cookies is
allowed. It cannot yield private cookies if not allowed, so checking it
again in the loop of getAll is redundant..

Attachment #9244520 - Attachment description: Bug 1732473 - Consistent storeId validation/errors in cookies API → Bug 1732473 - Deduplicate storeId parsing in cookies API
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/ee872b2362bb Add test coverage for errors in the cookies API r=zombie https://hg.mozilla.org/integration/autoland/rev/d2a20c79f52b Deduplicate storeId parsing in cookies API r=zombie https://hg.mozilla.org/integration/autoland/rev/a219f44c0135 Remove redundant privateBrowsingAllowed check r=zombie

Filed bug 1743616, updated test and will reland.

Flags: needinfo?(rob)
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/8a37f510e7d4 Add test coverage for errors in the cookies API r=zombie https://hg.mozilla.org/integration/autoland/rev/1a7011d80f7a Deduplicate storeId parsing in cookies API r=zombie https://hg.mozilla.org/integration/autoland/rev/cfa39c8b2830 Remove redundant privateBrowsingAllowed check r=zombie
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 96 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: