Skip to content

Commit

Permalink
Invoke setCookieControls CDP before iframe network agent auto attach
Browse files Browse the repository at this point in the history
This makes sure the iframe network handler has the correct cookie
controls settings after reloading the page.

Bug: 375352611
Change-Id: Ia39df476823ed78d14db9e5493b3250474a19912
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6175282
Reviewed-by: Danil Somsikov <[email protected]>
Commit-Queue: Shuran Huang <[email protected]>
  • Loading branch information
shuranhuang authored and Devtools-frontend LUCI CQ committed Jan 17, 2025
1 parent de07efa commit 31f399b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions front_end/core/sdk/NetworkManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ const {urlString} = Platform.DevToolsPath;
const LONG_URL_PART =
'LoremIpsumDolorSitAmetConsecteturAdipiscingElitPhasellusVitaeOrciInAugueCondimentumTinciduntUtEgetDolorQuisqueEfficiturUltricesTinciduntVivamusVelitPurusCommodoQuisErosSitAmetTemporMalesuadaNislNullamTtempusVulputateAugueEgetScelerisqueLacusVestibulumNon/index.html';

describeWithMockConnection('NetworkManager', () => {
it('setCookieControls gets invoked when network agent auto attach', () => {
const enableThirdPartyCookieRestrictionSetting =
Common.Settings.Settings.instance().createSetting('cookie-control-override-enabled', true);
const disableThirdPartyCookieMetadataSetting =
Common.Settings.Settings.instance().createSetting('grace-period-mitigation-disabled', false);
const disableThirdPartyCookieHeuristicsSetting =
Common.Settings.Settings.instance().createSetting('heuristic-mitigation-disabled', false);
assert.isTrue(enableThirdPartyCookieRestrictionSetting.get());
assert.isFalse(disableThirdPartyCookieMetadataSetting.get());
assert.isFalse(disableThirdPartyCookieHeuristicsSetting.get());

const target = createTarget();
const expectedCall = sinon.spy(target.networkAgent(), 'invoke_setCookieControls');

new SDK.NetworkManager.NetworkManager(target);

assert.isTrue(expectedCall.calledOnceWith({
enableThirdPartyCookieRestriction: true,
disableThirdPartyCookieMetadata: false,
disableThirdPartyCookieHeuristics: false
}));
});
});

describeWithMockConnection('MultitargetNetworkManager', () => {
describe('Trust Token done event', () => {
it('is not lost when arriving before the corresponding requestWillBeSent event', () => {
Expand Down
5 changes: 5 additions & 0 deletions front_end/core/sdk/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ export class NetworkManager extends SDKModel<EventTypes> {
if (Common.Settings.Settings.instance().moduleSetting('cache-disabled').get()) {
void this.#networkAgent.invoke_setCacheDisabled({cacheDisabled: true});
}
if (Common.Settings.Settings.instance().createSetting('cookie-control-override-enabled', undefined).get() ||
Common.Settings.Settings.instance().createSetting('grace-period-mitigation-disabled', undefined).get() ||
Common.Settings.Settings.instance().createSetting('heuristic-mitigation-disabled', undefined).get()) {
this.cookieControlFlagsSettingChanged();
}

void this.#networkAgent.invoke_enable({maxPostDataSize: MAX_EAGER_POST_REQUEST_BODY_LENGTH});
void this.#networkAgent.invoke_setAttachDebugStack({enabled: true});
Expand Down

0 comments on commit 31f399b

Please sign in to comment.