Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect extension enforcement of ANTI_ABUSE content setting
The ANTI_ABUSE content setting can be controlled through the Extensions API. The UI of the ANTI_ABUSE settings page should indicate when the content setting is being enforced by an extension. Also, the Private State Token (fka Trust Token) blocking mechanism should be triggered when an extension sets the ANTI_ABUSE content setting. Bug: 1418746 Change-Id: If46d5a722a7d1487ad0274ee7693c8dd8c7dc3bd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4284902 Commit-Queue: Ryan Kalla <ryankalla@google.com> Reviewed-by: Matt Menke <mmenke@chromium.org> Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org> Cr-Commit-Position: refs/heads/main@{#1121330}
- Loading branch information
Showing
7 changed files
with
202 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
chrome/test/data/webui/settings/anti_abuse_page_test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// clang-format off | ||
import 'chrome://settings/lazy_load.js'; | ||
|
||
import {ContentSetting, ContentSettingProvider, ContentSettingsTypes, SettingsAntiAbusePageElement, SiteSettingsPrefsBrowserProxyImpl} from 'chrome://settings/lazy_load.js'; | ||
import {assertEquals, assertNotEquals, assertTrue, assertFalse} from 'chrome://webui-test/chai_assert.js'; | ||
import {flushTasks} from 'chrome://webui-test/polymer_test_util.js'; | ||
|
||
import {TestSiteSettingsPrefsBrowserProxy} from './test_site_settings_prefs_browser_proxy.js'; | ||
import {createContentSettingTypeToValuePair, createSiteSettingsPrefs, SiteSettingsPref} from './test_util.js'; | ||
// clang-format on | ||
|
||
/** @fileoverview Suite of tests for settings-anti-abuse-page. */ | ||
suite('SettingsAntiAbusePage', function() { | ||
/** | ||
* A settings-anti-abuse-page created before each test. | ||
*/ | ||
let testElement: SettingsAntiAbusePageElement; | ||
|
||
/** | ||
* The mock proxy object to use during test. | ||
*/ | ||
let browserProxy: TestSiteSettingsPrefsBrowserProxy; | ||
|
||
// Initialize a settings-anti-abuse-page before each test. | ||
setup(function() { | ||
browserProxy = new TestSiteSettingsPrefsBrowserProxy(); | ||
SiteSettingsPrefsBrowserProxyImpl.setInstance(browserProxy); | ||
document.body.innerHTML = window.trustedTypes!.emptyHTML; | ||
testElement = document.createElement('settings-anti-abuse-page'); | ||
document.body.appendChild(testElement); | ||
}); | ||
|
||
/** | ||
* @param contentSetting The preference content setting. | ||
* @return The created preference object. | ||
*/ | ||
function createAntiAbusePref(contentSetting: ContentSetting): | ||
SiteSettingsPref { | ||
return createSiteSettingsPrefs( | ||
[ | ||
createContentSettingTypeToValuePair( | ||
ContentSettingsTypes.ANTI_ABUSE, {setting: contentSetting}), | ||
], | ||
[]); | ||
} | ||
/** | ||
* Verifies that the widget works as expected for a given |category|, | ||
* initial |prefs|, and given expectations. | ||
*/ | ||
async function testCategoryEnabled( | ||
element: SettingsAntiAbusePageElement, | ||
proxy: TestSiteSettingsPrefsBrowserProxy, prefs: SiteSettingsPref, | ||
expectedEnabled: boolean) { | ||
proxy.reset(); | ||
proxy.setPrefs(prefs); | ||
|
||
const toggleElement = element.$.toggleButton; | ||
|
||
let category = await proxy.whenCalled('getDefaultValueForContentType'); | ||
let categoryEnabled = toggleElement.checked; | ||
assertEquals(category, ContentSettingsTypes.ANTI_ABUSE); | ||
assertEquals(expectedEnabled, categoryEnabled); | ||
assertFalse(toggleElement.disabled); | ||
|
||
|
||
// Click the toggle and verify that the preference value is | ||
// updated correctly. | ||
proxy.resetResolver('setDefaultValueForContentType'); | ||
toggleElement.click(); | ||
|
||
let setting; | ||
[category, setting] = | ||
await proxy.whenCalled('setDefaultValueForContentType'); | ||
|
||
const oppositeSetting = | ||
expectedEnabled ? ContentSetting.BLOCK : ContentSetting.ALLOW; | ||
categoryEnabled = toggleElement.checked; | ||
assertEquals(category, ContentSettingsTypes.ANTI_ABUSE); | ||
assertEquals(oppositeSetting, setting); | ||
assertNotEquals(expectedEnabled, categoryEnabled); | ||
|
||
// Click the toggle again and verify that the preference value | ||
// is set back to the initial state. | ||
proxy.resetResolver('setDefaultValueForContentType'); | ||
toggleElement.click(); | ||
|
||
[category, setting] = | ||
await proxy.whenCalled('setDefaultValueForContentType'); | ||
const initialSetting = | ||
expectedEnabled ? ContentSetting.ALLOW : ContentSetting.BLOCK; | ||
categoryEnabled = toggleElement.checked; | ||
assertEquals(category, ContentSettingsTypes.ANTI_ABUSE); | ||
assertEquals(initialSetting, setting); | ||
assertEquals(expectedEnabled, categoryEnabled); | ||
} | ||
|
||
test('allow anti_abuse disable click triggers update', async function() { | ||
const enabledPref = createAntiAbusePref(ContentSetting.ALLOW); | ||
await testCategoryEnabled(testElement, browserProxy, enabledPref, true); | ||
}); | ||
|
||
|
||
test('toggle is disabled when pref is enforced', async function() { | ||
const enforcedPrefs = createSiteSettingsPrefs( | ||
[createContentSettingTypeToValuePair(ContentSettingsTypes.ANTI_ABUSE, { | ||
setting: ContentSetting.BLOCK, | ||
source: ContentSettingProvider.EXTENSION, | ||
})], | ||
[]); | ||
browserProxy.reset(); | ||
browserProxy.setPrefs(enforcedPrefs); | ||
const toggleElement = testElement.$.toggleButton; | ||
|
||
await browserProxy.whenCalled('getDefaultValueForContentType'); | ||
assertFalse(toggleElement.checked); | ||
assertTrue(toggleElement.disabled); | ||
|
||
// Stop enforcement. | ||
const enabledPref = createAntiAbusePref(ContentSetting.ALLOW); | ||
browserProxy.reset(); | ||
browserProxy.setPrefs(enabledPref); | ||
|
||
await flushTasks(); | ||
assertTrue(toggleElement.checked); | ||
assertFalse(toggleElement.disabled); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters