Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2941)

Unified Diff: chrome/test/data/webui/settings/site_list_tests.js

Issue 2055823003: Site Settings Desktop: Implement the 'Clear on exit' menu for Cookies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Polish Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/settings/site_list_tests.js
diff --git a/chrome/test/data/webui/settings/site_list_tests.js b/chrome/test/data/webui/settings/site_list_tests.js
index 79fd14880e979e9580a2ace8983e77de540179c5..288c5f6036919dda144ceda3ca48156524b1c2ab 100644
--- a/chrome/test/data/webui/settings/site_list_tests.js
+++ b/chrome/test/data/webui/settings/site_list_tests.js
@@ -218,6 +218,35 @@ cr.define('site_list', function() {
}
};
+ /**
+ * An example Cookies pref with 1 in each of the three categories.
+ * @type {SiteSettingsPref}
+ */
+ var prefsSessionOnly = {
+ exceptions: {
+ cookies: [
+ {
+ embeddingOrigin: 'http://foo-block.com',
+ origin: 'http://foo-block.com',
+ setting: 'block',
+ source: 'preference',
+ },
+ {
+ embeddingOrigin: 'http://foo-allow.com',
+ origin: 'http://foo-allow.com',
+ setting: 'allow',
+ source: 'preference',
+ },
+ {
+ embeddingOrigin: 'http://foo-session.com',
+ origin: 'http://foo-session.com',
+ setting: 'session_only',
+ source: 'preference',
+ },
+ ]
+ }
+ };
+
// Import necessary html before running suite.
suiteSetup(function() {
CrSettingsPrefs.setInitialized();
@@ -239,67 +268,53 @@ cr.define('site_list', function() {
});
/**
- * Asserts if a menu action is incorrectly hidden.
+ * Asserts the menu looks as expected.
+ * @param {Array<string>} items The items expected to show in the menu.
* @param {!HTMLElement} parentElement The parent node to start looking
* in.
- * @param {string} textForHiddenAction Text content of the only node that
- * should be hidden.
*/
- function assertMenuActionHidden(parentElement, textForHiddenAction) {
+ function assertMenu(items, parentElement) {
var listItem = parentElement.$.listContainer.children[0];
var menuItems =
listItem.querySelectorAll('paper-menu-button paper-item');
michaelpg 2016/06/09 18:43:43 Use the platform, Luke! var menuItems = listItem.
Finnur 2016/06/10 14:20:46 Hey, neat. :)
- assertNotEquals(0, menuItems.length);
-
- var found = false;
+ var i = 0;
menuItems.forEach(function(item) {
var text = item.textContent.trim();
- if (text == textForHiddenAction)
- found = true;
- assertEquals(text == textForHiddenAction, item.hidden);
+ if (!item.hidden) {
+ assertEquals(items[i], text);
+ ++i;
+ }
});
- assertTrue(found);
- }
-
- /**
- * Configures the test element as a location category.
- * @param {settings.PermissionValues} subtype Type of list to use: ALLOW
- * or BLOCK.
- * @param Array<dictionary> prefs The prefs to use.
- */
- function setupLocationCategory(subtype, prefs) {
- browserProxy.setPrefs(prefs);
- testElement.categorySubtype = subtype;
- testElement.categoryEnabled = true;
- testElement.allSites = false;
- testElement.currentRoute = {
- page: 'dummy',
- section: 'privacy',
- subpage: ['site-settings', 'site-settings-category-location'],
- };
- testElement.category = settings.ContentSettingsTypes.GEOLOCATION;
+ assertEquals(items.length, i);
}
/**
- * Configures the test element as the all sites category.
- * @param {dictionary} prefs The prefs to use.
+ * Configures the test element for a particular category.
+ * @param {settings.ContentSettingsTypes} category The category to setup.
+ * @param {settings.PermissionValues} subtype Type of list to use.
+ * @param {Array<dictionary>} prefs The prefs to use.
*/
- function setupAllSitesCategory(prefs) {
+ function setupCategory(category, subtype, prefs) {
browserProxy.setPrefs(prefs);
- testElement.categorySubtype = settings.INVALID_CATEGORY_SUBTYPE;
- testElement.categoryEnabled = true;
- testElement.allSites = true;
- testElement.prefs = prefs;
+ if (category == settings.ALL_SITES) {
+ testElement.categorySubtype = settings.INVALID_CATEGORY_SUBTYPE;
+ testElement.allSites = true;
+ } else {
+ testElement.categorySubtype = subtype;
+ testElement.allSites = false;
+ }
+ // Some route is needed, but the actual route doesn't matter.
testElement.currentRoute = {
page: 'dummy',
section: 'privacy',
subpage: ['site-settings', 'site-settings-category-location'],
};
- testElement.category = settings.ALL_SITES;
+ testElement.category = category;
}
test('getExceptionList API used', function() {
- setupLocationCategory(settings.PermissionValues.ALLOW, prefsEmpty);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.ALLOW, prefsEmpty);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
assertEquals(
@@ -308,7 +323,8 @@ cr.define('site_list', function() {
});
test('Empty list', function() {
- setupLocationCategory(settings.PermissionValues.ALLOW, prefsEmpty);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.ALLOW, prefsEmpty);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
assertEquals(
@@ -335,7 +351,8 @@ cr.define('site_list', function() {
});
test('initial ALLOW state is correct', function() {
- setupLocationCategory(settings.PermissionValues.ALLOW, prefs);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.ALLOW, prefs);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
assertEquals(
@@ -347,7 +364,7 @@ cr.define('site_list', function() {
assertEquals(
settings.PermissionValues.ALLOW, testElement.categorySubtype);
Polymer.dom.flush(); // Populates action menu.
- assertMenuActionHidden(testElement, 'Allow');
+ assertMenu(['Block', 'Reset to ask'], testElement);
assertEquals('Allow - 2', testElement.$.header.innerText.trim());
// Site list should show, no matter what category default is set to.
@@ -363,7 +380,8 @@ cr.define('site_list', function() {
});
test('initial BLOCK state is correct', function() {
- setupLocationCategory(settings.PermissionValues.BLOCK, prefs);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.BLOCK, prefs);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
assertEquals(
@@ -376,7 +394,7 @@ cr.define('site_list', function() {
assertEquals(
settings.PermissionValues.BLOCK, testElement.categorySubtype);
Polymer.dom.flush(); // Populates action menu.
- assertMenuActionHidden(testElement, 'Block');
+ assertMenu(['Allow', 'Reset to ask'], testElement);
assertEquals('Block - 2', testElement.$.header.innerText.trim());
// Site list should only show when category default is enabled.
@@ -390,8 +408,41 @@ cr.define('site_list', function() {
});
});
+ test('initial SESSION ONLY state is correct', function() {
+ setupCategory(settings.ContentSettingsTypes.COOKIES,
+ settings.PermissionValues.SESSION_ONLY, prefsSessionOnly);
+ return browserProxy.whenCalled('getExceptionList').then(
+ function(contentType) {
+ assertEquals(
+ settings.ContentSettingsTypes.COOKIES, contentType);
+
+ assertEquals(1, testElement.sites.length);
+ assertEquals(prefsSessionOnly.exceptions.cookies[2].origin,
+ testElement.sites[0].origin);
+
+ assertEquals(settings.PermissionValues.SESSION_ONLY,
+ testElement.categorySubtype);
+ Polymer.dom.flush(); // Populates action menu.
+ assertMenu(['Allow', 'Block', 'Reset to ask'], testElement);
+ assertEquals('Clear on exit - 1',
+ testElement.$.header.innerText.trim());
+
+ // Site list should show, no matter what category default is set to.
+ assertFalse(testElement.$.category.hidden);
+ browserProxy.resetResolver('getExceptionList');
+ testElement.categoryEnabled = false;
+ return browserProxy.whenCalled('getExceptionList').then(
+ function(contentType) {
michaelpg 2016/06/09 18:43:43 nit: 4-space indent
Finnur 2016/06/10 14:20:46 Done.
+ assertFalse(testElement.$.category.hidden);
+ assertEquals('Clear on exit - 1',
+ testElement.$.header.innerText);
+ });
+ });
+ });
+
test('list items shown and clickable when data is present', function() {
- setupLocationCategory(settings.PermissionValues.ALLOW, prefs);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.ALLOW, prefs);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
assertEquals(
@@ -418,8 +469,8 @@ cr.define('site_list', function() {
test('Block list open when Allow list is empty', function() {
// Prefs: One item in Block list, nothing in Allow list.
- setupLocationCategory(settings.PermissionValues.BLOCK,
- prefsOneDisabled);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.BLOCK, prefsOneDisabled);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
assertEquals(
@@ -434,7 +485,8 @@ cr.define('site_list', function() {
test('Block list closed when Allow list is not empty', function() {
// Prefs: Items in both Block and Allow list.
- setupLocationCategory(settings.PermissionValues.BLOCK, prefs);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.BLOCK, prefs);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
assertEquals(
@@ -448,7 +500,7 @@ cr.define('site_list', function() {
test('Allow list is always open (Block list empty)', function() {
// Prefs: One item in Allow list, nothing in Block list.
- setupLocationCategory(
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
settings.PermissionValues.ALLOW, prefsOneEnabled);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
@@ -464,7 +516,8 @@ cr.define('site_list', function() {
test('Allow list is always open (Block list non-empty)', function() {
// Prefs: Items in both Block and Allow list.
- setupLocationCategory(settings.PermissionValues.ALLOW, prefs);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.ALLOW, prefs);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
assertEquals(
@@ -479,7 +532,7 @@ cr.define('site_list', function() {
test('Block list hidden when empty', function() {
// Prefs: One item in Allow list, nothing in Block list.
- setupLocationCategory(
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
settings.PermissionValues.BLOCK, prefsOneEnabled);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
@@ -492,8 +545,8 @@ cr.define('site_list', function() {
test('Allow list hidden when empty', function() {
// Prefs: One item in Block list, nothing in Allow list.
- setupLocationCategory(settings.PermissionValues.ALLOW,
- prefsOneDisabled);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.ALLOW, prefsOneDisabled);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
assertEquals(
@@ -505,7 +558,7 @@ cr.define('site_list', function() {
test('All sites category', function() {
// Prefs: Multiple and overlapping sites.
- setupAllSitesCategory(prefsVarious);
+ setupCategory(settings.ALL_SITES, '', prefsVarious);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
@@ -548,7 +601,7 @@ cr.define('site_list', function() {
test('All sites mixed pattern and origin', function() {
// Prefs: One site, represented as origin and pattern.
- setupAllSitesCategory(prefsMixedOriginAndPattern);
+ setupCategory(settings.ALL_SITES, '', prefsMixedOriginAndPattern);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
@@ -589,8 +642,8 @@ cr.define('site_list', function() {
test('Mixed schemes (present and absent)', function() {
// Prefs: One item with scheme and one without.
- setupLocationCategory(settings.PermissionValues.ALLOW,
- prefsMixedSchemes);
+ setupCategory(settings.ContentSettingsTypes.GEOLOCATION,
+ settings.PermissionValues.ALLOW, prefsMixedSchemes);
return browserProxy.whenCalled('getExceptionList').then(
function(contentType) {
// No further checks needed. If this fails, it will hang the test.

Powered by Google App Engine
This is Rietveld 408576698