Commit 21fff260 authored by dpapad's avatar dpapad Committed by Commit Bot

Settings: Prep work for JS type checking of various privacy tests

Specifically:
 -  Fixing several type violations and adding JS type checking for
    - test_site_settings_prefs_browser_proxy.js
    - test_local_data_browser_proxy.js
    - test_util.js
 - Removing usage of mockMethods() from
   TestSiteSettingsPrefsBrowserProxy, as this pattern is incompatible
   with static type checking.
 - Updating various js_library() targets with missing dependencies as
   needed.

Bug: 1000989
Change-Id: I6b6924804ac96b048c6bde98e0101a7e90b4472a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2183015
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#766541}
parent 5f279cea
...@@ -191,6 +191,7 @@ js_type_check("closure_compile_local_module") { ...@@ -191,6 +191,7 @@ js_type_check("closure_compile_local_module") {
":global_scroll_target_behavior.m", ":global_scroll_target_behavior.m",
":hats_browser_proxy", ":hats_browser_proxy",
":i18n_setup", ":i18n_setup",
":lazy_load",
":lifetime_browser_proxy.m", ":lifetime_browser_proxy.m",
":metrics_browser_proxy", ":metrics_browser_proxy",
":open_window_proxy", ":open_window_proxy",
...@@ -238,6 +239,14 @@ js_library("hats_browser_proxy") { ...@@ -238,6 +239,14 @@ js_library("hats_browser_proxy") {
deps = [ "//ui/webui/resources/js:cr.m" ] deps = [ "//ui/webui/resources/js:cr.m" ]
} }
js_library("lazy_load") {
deps = [
"site_settings:local_data_browser_proxy",
"site_settings:protocol_handlers",
"site_settings:site_settings_prefs_browser_proxy",
]
}
js_library("lifetime_browser_proxy.m") { js_library("lifetime_browser_proxy.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/lifetime_browser_proxy.m.js" ] sources = [ "$root_gen_dir/chrome/browser/resources/settings/lifetime_browser_proxy.m.js" ]
deps = [ "//ui/webui/resources/js:cr.m" ] deps = [ "//ui/webui/resources/js:cr.m" ]
......
...@@ -20,7 +20,6 @@ import './site_settings/category_setting_exceptions.js'; ...@@ -20,7 +20,6 @@ import './site_settings/category_setting_exceptions.js';
import './site_settings/chooser_exception_list.js'; import './site_settings/chooser_exception_list.js';
import './site_settings/media_picker.js'; import './site_settings/media_picker.js';
import './site_settings/pdf_documents.js'; import './site_settings/pdf_documents.js';
import './site_settings/protocol_handlers.js';
import './site_settings/site_data.js'; import './site_settings/site_data.js';
import './site_settings/site_details.js'; import './site_settings/site_details.js';
import './site_settings/zoom_levels.js'; import './site_settings/zoom_levels.js';
...@@ -47,6 +46,7 @@ import './system_page/system_page.js'; ...@@ -47,6 +46,7 @@ import './system_page/system_page.js';
// <if expr="not is_macosx"> // <if expr="not is_macosx">
import './languages_page/edit_dictionary_page.js'; import './languages_page/edit_dictionary_page.js';
// </if> // </if>
export {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js'; export {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
...@@ -84,11 +84,13 @@ export {AndroidInfoBrowserProxyImpl} from './site_settings/android_info_browser_ ...@@ -84,11 +84,13 @@ export {AndroidInfoBrowserProxyImpl} from './site_settings/android_info_browser_
// </if> // </if>
export {ChooserType, ContentSetting, ContentSettingsTypes, CookieControlsMode, SITE_EXCEPTION_WILDCARD, SiteSettingSource, SortMethod} from './site_settings/constants.js'; export {ChooserType, ContentSetting, ContentSettingsTypes, CookieControlsMode, SITE_EXCEPTION_WILDCARD, SiteSettingSource, SortMethod} from './site_settings/constants.js';
export {cookieInfo} from './site_settings/cookie_info.js'; export {cookieInfo} from './site_settings/cookie_info.js';
export {LocalDataBrowserProxyImpl} from './site_settings/local_data_browser_proxy.js'; export {CookieList, LocalDataBrowserProxy, LocalDataBrowserProxyImpl, LocalDataItem} from './site_settings/local_data_browser_proxy.js';
export {HandlerEntry, ProtocolEntry} from './site_settings/protocol_handlers.js';
export {kControlledByLookup} from './site_settings/site_settings_behavior.js'; export {kControlledByLookup} from './site_settings/site_settings_behavior.js';
export {ContentSettingProvider, SiteSettingsPrefsBrowserProxyImpl} from './site_settings/site_settings_prefs_browser_proxy.js'; export {ContentSettingProvider, CookieControlsManagedState, DefaultContentSetting, RawChooserException, RawSiteException, RecentSitePermissions, SiteGroup, SiteSettingsPrefsBrowserProxy, SiteSettingsPrefsBrowserProxyImpl, ZoomLevelEntry} from './site_settings/site_settings_prefs_browser_proxy.js';
export {WebsiteUsageBrowserProxyImpl} from './site_settings/website_usage_browser_proxy.js'; export {WebsiteUsageBrowserProxyImpl} from './site_settings/website_usage_browser_proxy.js';
export {defaultSettingLabel} from './site_settings_page/site_settings_list.js'; export {defaultSettingLabel} from './site_settings_page/site_settings_list.js';
// <if expr="not chromeos"> // <if expr="not chromeos">
export {SystemPageBrowserProxyImpl} from './system_page/system_page_browser_proxy.js'; export {SystemPageBrowserProxyImpl} from './system_page/system_page_browser_proxy.js';
// </if> // </if>
...@@ -58,7 +58,10 @@ js_library("all_sites") { ...@@ -58,7 +58,10 @@ js_library("all_sites") {
":site_settings_prefs_browser_proxy", ":site_settings_prefs_browser_proxy",
"..:global_scroll_target_behavior.m", "..:global_scroll_target_behavior.m",
"..:router.m", "..:router.m",
"..:settings_routes",
"//third_party/polymer/v3_0/components-chromium/iron-list",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled", "//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/cr_elements/cr_action_menu:cr_action_menu.m",
"//ui/webui/resources/js:i18n_behavior.m", "//ui/webui/resources/js:i18n_behavior.m",
"//ui/webui/resources/js:load_time_data.m", "//ui/webui/resources/js:load_time_data.m",
"//ui/webui/resources/js:web_ui_listener_behavior.m", "//ui/webui/resources/js:web_ui_listener_behavior.m",
...@@ -295,6 +298,7 @@ js_library("site_settings_prefs_browser_proxy") { ...@@ -295,6 +298,7 @@ js_library("site_settings_prefs_browser_proxy") {
"//ui/webui/resources/cr_elements/policy:cr_policy_indicator_behavior.m", "//ui/webui/resources/cr_elements/policy:cr_policy_indicator_behavior.m",
"//ui/webui/resources/js:cr.m", "//ui/webui/resources/js:cr.m",
] ]
externs_list = [ "$externs_path/settings_private.js" ]
} }
js_library("website_usage_browser_proxy") { js_library("website_usage_browser_proxy") {
......
...@@ -44,14 +44,14 @@ const MenuActions = { ...@@ -44,14 +44,14 @@ const MenuActions = {
* protocol_display_name: string, * protocol_display_name: string,
* spec: string}} * spec: string}}
*/ */
let HandlerEntry; export let HandlerEntry;
/** /**
* @typedef {{handlers: !Array<!HandlerEntry>, * @typedef {{handlers: !Array<!HandlerEntry>,
* protocol: string, * protocol: string,
* protocol_display_name: string}} * protocol_display_name: string}}
*/ */
let ProtocolEntry; export let ProtocolEntry;
Polymer({ Polymer({
is: 'protocol-handlers', is: 'protocol-handlers',
......
...@@ -238,7 +238,8 @@ export class SiteSettingsPrefsBrowserProxy { ...@@ -238,7 +238,8 @@ export class SiteSettingsPrefsBrowserProxy {
/** /**
* Gets the exceptions (site list) for a particular category. * Gets the exceptions (site list) for a particular category.
* @param {string} contentType The name of the category to query. * @param {!ContentSettingsTypes} contentType The name of the category to
* query.
* @return {!Promise<!Array<!RawSiteException>>} * @return {!Promise<!Array<!RawSiteException>>}
*/ */
getExceptionList(contentType) {} getExceptionList(contentType) {}
...@@ -250,7 +251,7 @@ export class SiteSettingsPrefsBrowserProxy { ...@@ -250,7 +251,7 @@ export class SiteSettingsPrefsBrowserProxy {
* @param {string} origin The origin to look up permissions for. * @param {string} origin The origin to look up permissions for.
* @param {!Array<!ContentSettingsTypes>} contentTypes A list of * @param {!Array<!ContentSettingsTypes>} contentTypes A list of
* categories to retrieve the ContentSetting for. * categories to retrieve the ContentSetting for.
* @return {!Promise<!NodeList<!RawSiteException>>} * @return {!Promise<!Array<!RawSiteException>>}
*/ */
getOriginPermissions(origin, contentTypes) {} getOriginPermissions(origin, contentTypes) {}
......
...@@ -65,12 +65,37 @@ js_type_check("closure_compile") { ...@@ -65,12 +65,37 @@ js_type_check("closure_compile") {
":settings_page_test_util", ":settings_page_test_util",
":test_about_page_browser_proxy", ":test_about_page_browser_proxy",
":test_lifetime_browser_proxy.m", ":test_lifetime_browser_proxy.m",
":test_local_data_browser_proxy",
":test_search_engines_browser_proxy.m", ":test_search_engines_browser_proxy.m",
":test_site_settings_prefs_browser_proxy",
":test_util",
# TODO(crbug.com/1000989): Add targets for more files here. # TODO(crbug.com/1000989): Add targets for more files here.
] ]
} }
js_library("test_local_data_browser_proxy") {
deps = [
"..:test_browser_proxy.m",
"//chrome/browser/resources/settings:lazy_load",
]
}
js_library("test_site_settings_prefs_browser_proxy") {
deps = [
":test_util",
"..:test_browser_proxy.m",
"//chrome/browser/resources/settings:lazy_load",
]
}
js_library("test_util") {
deps = [
"//chrome/browser/resources/settings:lazy_load",
"//chrome/browser/resources/settings:settings",
]
}
js_library("about_page_tests") { js_library("about_page_tests") {
deps = [ deps = [
":test_about_page_browser_proxy", ":test_about_page_browser_proxy",
......
...@@ -325,8 +325,7 @@ suite('CrSettingsCookiesPageTest', function() { ...@@ -325,8 +325,7 @@ suite('CrSettingsCookiesPageTest', function() {
source: SiteSettingSource.POLICY source: SiteSettingSource.POLICY
}))], }))],
[]); []);
siteSettingsBrowserProxy.setResultFor( siteSettingsBrowserProxy.setCookieControlsManagedState(managedControlState);
'getCookieControlsManagedState', Promise.resolve(managedControlState));
siteSettingsBrowserProxy.setPrefs(managedPrefs); siteSettingsBrowserProxy.setPrefs(managedPrefs);
await siteSettingsBrowserProxy.whenCalled('getDefaultValueForContentType'); await siteSettingsBrowserProxy.whenCalled('getDefaultValueForContentType');
await siteSettingsBrowserProxy.whenCalled('getCookieControlsManagedState'); await siteSettingsBrowserProxy.whenCalled('getCookieControlsManagedState');
...@@ -365,9 +364,8 @@ suite('CrSettingsCookiesPageTest', function() { ...@@ -365,9 +364,8 @@ suite('CrSettingsCookiesPageTest', function() {
}))], }))],
[]); []);
siteSettingsBrowserProxy.reset(); siteSettingsBrowserProxy.reset();
siteSettingsBrowserProxy.setResultFor( siteSettingsBrowserProxy.setCookieControlsManagedState(
'getCookieControlsManagedState', unmanagedControlState);
Promise.resolve(unmanagedControlState));
siteSettingsBrowserProxy.setPrefs(unmanagedPrefs); siteSettingsBrowserProxy.setPrefs(unmanagedPrefs);
await siteSettingsBrowserProxy.whenCalled('getDefaultValueForContentType'); await siteSettingsBrowserProxy.whenCalled('getDefaultValueForContentType');
await siteSettingsBrowserProxy.whenCalled('getCookieControlsManagedState'); await siteSettingsBrowserProxy.whenCalled('getCookieControlsManagedState');
......
...@@ -268,8 +268,7 @@ suite('PrivacyPageRedesignEnabled', function() { ...@@ -268,8 +268,7 @@ suite('PrivacyPageRedesignEnabled', function() {
setup(function() { setup(function() {
siteSettingsBrowserProxy = new TestSiteSettingsPrefsBrowserProxy(); siteSettingsBrowserProxy = new TestSiteSettingsPrefsBrowserProxy();
SiteSettingsPrefsBrowserProxyImpl.instance_ = siteSettingsBrowserProxy; SiteSettingsPrefsBrowserProxyImpl.instance_ = siteSettingsBrowserProxy;
siteSettingsBrowserProxy.setResultFor( siteSettingsBrowserProxy.setCookieSettingDescription(testLabels[0]);
'getCookieSettingDescription', Promise.resolve(testLabels[0]));
PolymerTest.clearBody(); PolymerTest.clearBody();
page = document.createElement('settings-privacy-page'); page = document.createElement('settings-privacy-page');
document.body.appendChild(page); document.body.appendChild(page);
......
...@@ -36,7 +36,7 @@ suite('CrSettingsRecentSitePermissionsTest', function() { ...@@ -36,7 +36,7 @@ suite('CrSettingsRecentSitePermissionsTest', function() {
}); });
test('No recent permissions', async function() { test('No recent permissions', async function() {
browserProxy.setResultFor('getRecentSitePermissions', Promise.resolve([])); browserProxy.setRecentSitePermissions([]);
testElement.currentRouteChanged(routes.SITE_SETTINGS); testElement.currentRouteChanged(routes.SITE_SETTINGS);
await browserProxy.whenCalled('getRecentSitePermissions'); await browserProxy.whenCalled('getRecentSitePermissions');
flush(); flush();
...@@ -67,7 +67,7 @@ suite('CrSettingsRecentSitePermissionsTest', function() { ...@@ -67,7 +67,7 @@ suite('CrSettingsRecentSitePermissionsTest', function() {
] ]
}, },
]); ]);
browserProxy.setResultFor('getRecentSitePermissions', mockData); browserProxy.setRecentSitePermissions(mockData);
testElement.currentRouteChanged(routes.SITE_SETTINGS); testElement.currentRouteChanged(routes.SITE_SETTINGS);
await browserProxy.whenCalled('getRecentSitePermissions'); await browserProxy.whenCalled('getRecentSitePermissions');
flush(); flush();
......
...@@ -1016,8 +1016,9 @@ suite('EditExceptionDialog', function() { ...@@ -1016,8 +1016,9 @@ suite('EditExceptionDialog', function() {
input.value = expectedPattern; input.value = expectedPattern;
input.fire('input'); input.fire('input');
return browserProxy.whenCalled('isPatternValidForType') return browserProxy.whenCalled('isPatternValidForType').then(function([
.then(function(pattern, category) { pattern, category
]) {
assertEquals(expectedPattern, pattern); assertEquals(expectedPattern, pattern);
assertTrue(actionButton.disabled); assertTrue(actionButton.disabled);
assertTrue(input.invalid); assertTrue(input.invalid);
...@@ -1108,8 +1109,9 @@ suite('AddExceptionDialog', function() { ...@@ -1108,8 +1109,9 @@ suite('AddExceptionDialog', function() {
input.value = expectedPattern; input.value = expectedPattern;
input.fire('input'); input.fire('input');
return browserProxy.whenCalled('isPatternValidForType') return browserProxy.whenCalled('isPatternValidForType').then(function([
.then(function(pattern) { pattern, category
]) {
assertEquals(expectedPattern, pattern); assertEquals(expectedPattern, pattern);
assertTrue(actionButton.disabled); assertTrue(actionButton.disabled);
assertTrue(input.invalid); assertTrue(input.invalid);
......
...@@ -30,8 +30,7 @@ suite('SiteSettingsPage', function() { ...@@ -30,8 +30,7 @@ suite('SiteSettingsPage', function() {
function setupPage() { function setupPage() {
siteSettingsBrowserProxy = new TestSiteSettingsPrefsBrowserProxy(); siteSettingsBrowserProxy = new TestSiteSettingsPrefsBrowserProxy();
SiteSettingsPrefsBrowserProxyImpl.instance_ = siteSettingsBrowserProxy; SiteSettingsPrefsBrowserProxyImpl.instance_ = siteSettingsBrowserProxy;
siteSettingsBrowserProxy.setResultFor( siteSettingsBrowserProxy.setCookieSettingDescription(testLabels[0]);
'getCookieSettingDescription', Promise.resolve(testLabels[0]));
PolymerTest.clearBody(); PolymerTest.clearBody();
page = document.createElement('settings-site-settings-page'); page = document.createElement('settings-site-settings-page');
document.body.appendChild(page); document.body.appendChild(page);
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
// found in the LICENSE file. // found in the LICENSE file.
// clang-format off // clang-format off
import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js'; import { CookieList,LocalDataBrowserProxy, LocalDataItem} from 'chrome://settings/lazy_load.js';
import {TestBrowserProxy} from '../test_browser_proxy.m.js';
// clang-format on // clang-format on
/** /**
...@@ -24,7 +26,7 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy { ...@@ -24,7 +26,7 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy {
'getNumCookiesString', 'getNumCookiesString',
'reloadCookies', 'reloadCookies',
'removeCookie', 'removeCookie',
'removeThirdPartyCookies', 'removeAllThirdPartyCookies',
]); ]);
/** @private {?CookieList} */ /** @private {?CookieList} */
...@@ -32,6 +34,9 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy { ...@@ -32,6 +34,9 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy {
/** @private {Array<!LocalDataItem>} */ /** @private {Array<!LocalDataItem>} */
this.cookieList_ = []; this.cookieList_ = [];
/** @private {!Array<!LocalDataItem>} */
this.filteredCookieList_ = [];
} }
/** /**
...@@ -56,13 +61,14 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy { ...@@ -56,13 +61,14 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy {
if (filter === undefined) { if (filter === undefined) {
filter = ''; filter = '';
} }
/** @type {!Array<!LocalDataItem>} */
const output = []; const output = [];
for (let i = 0; i < this.cookieList_.length; ++i) { for (let i = 0; i < this.cookieList_.length; ++i) {
if (this.cookieList_[i].site.indexOf(filter) >= 0) { if (this.cookieList_[i].site.indexOf(filter) >= 0) {
output.push(this.filteredCookieList_[i]); output.push(this.filteredCookieList_[i]);
} }
} }
return Promise.resolve({items: output}); return Promise.resolve({items: output, total: output.length});
} }
/** @override */ /** @override */
...@@ -84,7 +90,8 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy { ...@@ -84,7 +90,8 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy {
/** @override */ /** @override */
getCookieDetails(site) { getCookieDetails(site) {
this.methodCalled('getCookieDetails', site); this.methodCalled('getCookieDetails', site);
return Promise.resolve(this.cookieDetails_ || {id: '', children: []}); return Promise.resolve(
this.cookieDetails_ || {id: '', children: [], start: 0});
} }
/** @override */ /** @override */
...@@ -106,7 +113,8 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy { ...@@ -106,7 +113,8 @@ export class TestLocalDataBrowserProxy extends TestBrowserProxy {
} }
/** @override */ /** @override */
removeThirdPartyCookies() { removeAllThirdPartyCookies() {
this.methodCalled('removeThirdPartyCookies'); this.methodCalled('removeAllThirdPartyCookies');
return Promise.resolve();
} }
} }
...@@ -5,22 +5,13 @@ ...@@ -5,22 +5,13 @@
// clang-format off // clang-format off
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {webUIListenerCallback} from 'chrome://resources/js/cr.m.js'; import {webUIListenerCallback} from 'chrome://resources/js/cr.m.js';
import {ContentSetting,SiteSettingSource} from 'chrome://settings/lazy_load.js'; import {ContentSetting, ContentSettingsTypes, CookieControlsManagedState, HandlerEntry, ProtocolEntry, RawChooserException, RawSiteException, RecentSitePermissions, SiteSettingSource, SiteSettingsPrefsBrowserProxy, ZoomLevelEntry} from 'chrome://settings/lazy_load.js';
import {createSiteGroup,createSiteSettingsPrefs, getContentSettingsTypeFromChooserType} from 'chrome://test/settings/test_util.js';
import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js'; import {TestBrowserProxy} from '../test_browser_proxy.m.js';
import {createOriginInfo, createSiteGroup,createSiteSettingsPrefs, getContentSettingsTypeFromChooserType, SiteSettingsPref} from './test_util.js';
// clang-format on // clang-format on
/**
* In the real (non-test) code, this data comes from the C++ handler.
* Only used for tests.
* @typedef {{defaults: !Object<ContentSettingsTypes,
* !DefaultContentSetting>,
* exceptions: !Object<ContentSettingsTypes,
* !Array<!RawSiteException>>,
* chooserExceptions: !Object<ContentSettingsTypes,
* !Array<!RawChooserException>>}}
*/
let SiteSettingsPref;
/** /**
* A test version of SiteSettingsPrefsBrowserProxy. Provides helper methods * A test version of SiteSettingsPrefsBrowserProxy. Provides helper methods
...@@ -58,6 +49,9 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy { ...@@ -58,6 +49,9 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy {
'clearEtldPlus1DataAndCookies', 'clearEtldPlus1DataAndCookies',
'clearOriginDataAndCookies', 'clearOriginDataAndCookies',
'recordAction', 'recordAction',
'getCookieControlsManagedState',
'getCookieSettingDescription',
'getRecentSitePermissions',
]); ]);
/** @private {boolean} */ /** @private {boolean} */
...@@ -81,11 +75,14 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy { ...@@ -81,11 +75,14 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy {
/** @private {boolean} */ /** @private {boolean} */
this.isPatternValidForType_ = true; this.isPatternValidForType_ = true;
this.mockMethods([ /** @private {!CookieControlsManagedState|undefined} */
'getCookieSettingDescription', this.cookieControlsManagedState_ = undefined;
'getCookieControlsManagedState',
'getRecentSitePermissions', /** @private {string} */
]); this.cookieSettingDesciption_ = '';
/** @private {!Array<!RecentSitePermissions>} */
this.recentSitePermissions_ = [];
} }
/** /**
...@@ -165,7 +162,7 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy { ...@@ -165,7 +162,7 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy {
/** /**
* Sets the prefs to use when testing. * Sets the prefs to use when testing.
* @param {!Array<!HandlerEntry>} * @param {!Array<!HandlerEntry>} list
*/ */
setIgnoredProtocols(list) { setIgnoredProtocols(list) {
// Shallow copy of the passed-in array so mutation won't impact the source // Shallow copy of the passed-in array so mutation won't impact the source
...@@ -297,8 +294,8 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy { ...@@ -297,8 +294,8 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy {
// Create a deep copy of the pref so that the chooser-exception-list element // Create a deep copy of the pref so that the chooser-exception-list element
// is able update the UI appropriately when incognito mode is toggled. // is able update the UI appropriately when incognito mode is toggled.
const pref = const pref = /** @type {!Array<!RawChooserException>} */ (
JSON.parse(JSON.stringify(this.prefs_.chooserExceptions[setting])); JSON.parse(JSON.stringify(this.prefs_.chooserExceptions[setting])));
assert(pref !== undefined, 'Pref is missing for ' + chooserType); assert(pref !== undefined, 'Pref is missing for ' + chooserType);
if (this.hasIncognito_) { if (this.hasIncognito_) {
...@@ -340,7 +337,7 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy { ...@@ -340,7 +337,7 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy {
/** @override */ /** @override */
isPatternValidForType(pattern, category) { isPatternValidForType(pattern, category) {
this.methodCalled('isPatternValidForType', pattern, category); this.methodCalled('isPatternValidForType', [pattern, category]);
return Promise.resolve({ return Promise.resolve({
isValid: this.isPatternValidForType_, isValid: this.isPatternValidForType_,
reason: this.isPatternValidForType_ ? '' : 'pattern is invalid', reason: this.isPatternValidForType_ ? '' : 'pattern is invalid',
...@@ -360,7 +357,6 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy { ...@@ -360,7 +357,6 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy {
this.methodCalled( this.methodCalled(
'resetCategoryPermissionForPattern', 'resetCategoryPermissionForPattern',
[primaryPattern, secondaryPattern, contentType, incognito]); [primaryPattern, secondaryPattern, contentType, incognito]);
return Promise.resolve();
} }
/** @override */ /** @override */
...@@ -369,7 +365,6 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy { ...@@ -369,7 +365,6 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy {
this.methodCalled( this.methodCalled(
'resetChooserExceptionForSite', 'resetChooserExceptionForSite',
[chooserType, origin, embeddingOrigin, exception]); [chooserType, origin, embeddingOrigin, exception]);
return Promise.resolve();
} }
/** @override */ /** @override */
...@@ -425,7 +420,6 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy { ...@@ -425,7 +420,6 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy {
this.methodCalled( this.methodCalled(
'setCategoryPermissionForPattern', 'setCategoryPermissionForPattern',
[primaryPattern, secondaryPattern, contentType, value, incognito]); [primaryPattern, secondaryPattern, contentType, value, incognito]);
return Promise.resolve();
} }
/** @override */ /** @override */
...@@ -487,4 +481,51 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy { ...@@ -487,4 +481,51 @@ export class TestSiteSettingsPrefsBrowserProxy extends TestBrowserProxy {
recordAction() { recordAction() {
this.methodCalled('recordAction'); this.methodCalled('recordAction');
} }
/** @param {!CookieControlsManagedState} state */
setCookieControlsManagedState(state) {
this.cookieControlsManagedState_ = state;
}
/** @override */
getCookieControlsManagedState() {
this.methodCalled('getCookieControlsManagedState');
return Promise.resolve(/** @type {!CookieControlsManagedState} */ (
this.cookieControlsManagedState_));
}
/** @param {string} label */
setCookieSettingDescription(label) {
this.cookieSettingDesciption_ = label;
}
/** @override */
getCookieSettingDescription() {
this.methodCalled('getCookieSettingDescription');
return Promise.resolve(this.cookieSettingDesciption_);
}
/** @param {!Array<!RecentSitePermissions>} permissions */
setRecentSitePermissions(permissions) {
this.recentSitePermissions_ = permissions;
}
/** @override */
getRecentSitePermissions() {
this.methodCalled('getRecentSitePermissions');
return Promise.resolve(this.recentSitePermissions_);
}
/** @override */
getDefaultCaptureDevices() {}
/** @override */
setDefaultCaptureDevice() {}
/** @override */
setProtocolHandlerDefault() {}
/** @override */
showAndroidManageAppLinks() {}
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// clang-format off // clang-format off
import {ChooserType, ContentSetting, ContentSettingsTypes, SiteSettingSource} from 'chrome://settings/lazy_load.js'; import {ChooserType, ContentSetting, ContentSettingsTypes, DefaultContentSetting, RawChooserException, RawSiteException, SiteGroup, SiteSettingSource} from 'chrome://settings/lazy_load.js';
import {Route, Router} from 'chrome://settings/settings.js'; import {Route, Router} from 'chrome://settings/settings.js';
// clang-format on // clang-format on
...@@ -15,7 +15,7 @@ import {Route, Router} from 'chrome://settings/settings.js'; ...@@ -15,7 +15,7 @@ import {Route, Router} from 'chrome://settings/settings.js';
* @param {ContentSettingsTypes} contentType The ContentSettingsType * @param {ContentSettingsTypes} contentType The ContentSettingsType
* to use as the key. * to use as the key.
* @param {Object} value The value to map to |contentType|. * @param {Object} value The value to map to |contentType|.
* @return {Object<setting: ContentSettingsTypes, value: Object>} * @return {Object<ContentSettingsTypes, Object>}
*/ */
export function createContentSettingTypeToValuePair(contentType, value) { export function createContentSettingTypeToValuePair(contentType, value) {
return {setting: contentType, value: value}; return {setting: contentType, value: value};
...@@ -26,18 +26,18 @@ export function createContentSettingTypeToValuePair(contentType, value) { ...@@ -26,18 +26,18 @@ export function createContentSettingTypeToValuePair(contentType, value) {
* @param {!Object=} override An object with a subset of the properties of * @param {!Object=} override An object with a subset of the properties of
* DefaultContentSetting. Properties defined in |override| will * DefaultContentSetting. Properties defined in |override| will
* overwrite the defaults in this function's return value. * overwrite the defaults in this function's return value.
* @return {DefaultContentSetting} * @return {!DefaultContentSetting}
*/ */
export function createDefaultContentSetting(override) { export function createDefaultContentSetting(override) {
if (override === undefined) { if (override === undefined) {
override = {}; override = {};
} }
return Object.assign( return /** @type {!DefaultContentSetting} */ (Object.assign(
{ {
setting: ContentSetting.ASK, setting: ContentSetting.ASK,
source: SiteSettingSource.PREFERENCE, source: SiteSettingSource.PREFERENCE,
}, },
override); override));
} }
/** /**
...@@ -46,13 +46,13 @@ export function createDefaultContentSetting(override) { ...@@ -46,13 +46,13 @@ export function createDefaultContentSetting(override) {
* @param {!Object=} override An object with a subset of the properties of * @param {!Object=} override An object with a subset of the properties of
* RawSiteException. Properties defined in |override| will overwrite the * RawSiteException. Properties defined in |override| will overwrite the
* defaults in this function's return value. * defaults in this function's return value.
* @return {RawSiteException} * @return {!RawSiteException}
*/ */
export function createRawSiteException(origin, override) { export function createRawSiteException(origin, override) {
if (override === undefined) { if (override === undefined) {
override = {}; override = {};
} }
return Object.assign( return /** @type {!RawSiteException} */ (Object.assign(
{ {
embeddingOrigin: origin, embeddingOrigin: origin,
incognito: false, incognito: false,
...@@ -61,7 +61,7 @@ export function createRawSiteException(origin, override) { ...@@ -61,7 +61,7 @@ export function createRawSiteException(origin, override) {
setting: ContentSetting.ALLOW, setting: ContentSetting.ALLOW,
source: SiteSettingSource.PREFERENCE, source: SiteSettingSource.PREFERENCE,
}, },
override); override));
} }
/** /**
...@@ -72,14 +72,31 @@ export function createRawSiteException(origin, override) { ...@@ -72,14 +72,31 @@ export function createRawSiteException(origin, override) {
* @param {!Object=} override An object with a subset of the properties of * @param {!Object=} override An object with a subset of the properties of
* RawChooserException. Properties defined in |override| will overwrite * RawChooserException. Properties defined in |override| will overwrite
* the defaults in this function's return value. * the defaults in this function's return value.
* @return {RawChooserException} * @return {!RawChooserException}
*/ */
export function createRawChooserException(chooserType, sites, override) { export function createRawChooserException(chooserType, sites, override) {
return Object.assign( return /** @type {!RawChooserException} */ (Object.assign(
{chooserType: chooserType, displayName: '', object: {}, sites: sites}, {
override || {}); chooserType: chooserType,
displayName: '',
object: {},
sites: sites,
},
override));
} }
/**
* In the real (non-test) code, this data comes from the C++ handler.
* Only used for tests.
* @typedef {{
* defaults: !Object<ContentSettingsTypes, !DefaultContentSetting>,
* exceptions: !Object<ContentSettingsTypes, !Array<!RawSiteException>>,
* chooserExceptions: !Object<ContentSettingsTypes,
* !Array<!RawChooserException>>
* }}
*/
export let SiteSettingsPref;
/** /**
* Helper to create a mock SiteSettingsPref. * Helper to create a mock SiteSettingsPref.
* @param {!Array<{setting: ContentSettingsTypes, * @param {!Array<{setting: ContentSettingsTypes,
...@@ -150,7 +167,7 @@ export function createSiteSettingsPrefs( ...@@ -150,7 +167,7 @@ export function createSiteSettingsPrefs(
* eTLD+1. * eTLD+1.
* @param {number=} mockUsage The override initial usage value for each origin * @param {number=} mockUsage The override initial usage value for each origin
* in the site group. * in the site group.
* @return {SiteGroup} * @return {!SiteGroup}
*/ */
export function createSiteGroup(eTLDPlus1Name, originList, mockUsage) { export function createSiteGroup(eTLDPlus1Name, originList, mockUsage) {
if (mockUsage === undefined) { if (mockUsage === undefined) {
...@@ -162,6 +179,7 @@ export function createSiteGroup(eTLDPlus1Name, originList, mockUsage) { ...@@ -162,6 +179,7 @@ export function createSiteGroup(eTLDPlus1Name, originList, mockUsage) {
etldPlus1: eTLDPlus1Name, etldPlus1: eTLDPlus1Name,
origins: originInfoList, origins: originInfoList,
numCookies: 0, numCookies: 0,
hasInstalledPWA: false,
}; };
} }
...@@ -185,7 +203,7 @@ export function createOriginInfo(origin, override) { ...@@ -185,7 +203,7 @@ export function createOriginInfo(origin, override) {
* |chooserType|. * |chooserType|.
* @param {ChooserType} chooserType The chooser type of the * @param {ChooserType} chooserType The chooser type of the
* permission. * permission.
* @return {?ContentSettingsType} * @return {?ContentSettingsTypes}
*/ */
export function getContentSettingsTypeFromChooserType(chooserType) { export function getContentSettingsTypeFromChooserType(chooserType) {
switch (chooserType) { switch (chooserType) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment