 Chromium Code Reviews
 Chromium Code Reviews Issue 2912253003:
  MD Settings: Show all content settings in Site Details.  (Closed)
    
  
    Issue 2912253003:
  MD Settings: Show all content settings in Site Details.  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 /** @fileoverview Suite of tests for site-details. */ | 5 /** @fileoverview Suite of tests for site-details. */ | 
| 6 suite('SiteDetailsPermission', function() { | 6 suite('SiteDetailsPermission', function() { | 
| 7 /** | 7 /** | 
| 8 * A site list element created before each test. | 8 * A site list element created before each test. | 
| 9 * @type {SiteDetailsPermission} | 9 * @type {SiteDetailsPermission} | 
| 10 */ | 10 */ | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 ] | 41 ] | 
| 42 } | 42 } | 
| 43 }; | 43 }; | 
| 44 | 44 | 
| 45 // Initialize a site-details-permission before each test. | 45 // Initialize a site-details-permission before each test. | 
| 46 setup(function() { | 46 setup(function() { | 
| 47 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); | 47 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); | 
| 48 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; | 48 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; | 
| 49 PolymerTest.clearBody(); | 49 PolymerTest.clearBody(); | 
| 50 testElement = document.createElement('site-details-permission'); | 50 testElement = document.createElement('site-details-permission'); | 
| 51 | |
| 52 // Set the camera icon on <site-details-permission> manually to avoid | |
| 53 // failures on undefined icons. In practice, this is done from the parent. | |
| 
calamity
2017/06/01 03:46:56
nit: ...icons during teardown in PolymerTest.testI
 
Patti Lor
2017/06/01 04:52:01
Done.
 | |
| 54 testElement.icon = 'settings:videocam'; | |
| 51 document.body.appendChild(testElement); | 55 document.body.appendChild(testElement); | 
| 52 }); | 56 }); | 
| 53 | 57 | 
| 54 // Tests that the given value is converted to the expected value, for a | 58 // Tests that the given value is converted to the expected value, for a | 
| 55 // given prefType. | 59 // given prefType. | 
| 56 function isAllowed(origin, exceptionList) { | 60 function isAllowed(origin, exceptionList) { | 
| 57 for (var i = 0; i < exceptionList.length; ++i) { | 61 for (var i = 0; i < exceptionList.length; ++i) { | 
| 58 if (exceptionList[i].origin == origin) | 62 if (exceptionList[i].origin == origin) | 
| 59 return exceptionList[i].setting == 'allow'; | 63 return exceptionList[i].setting == 'allow'; | 
| 60 } | 64 } | 
| 61 return false; | 65 return false; | 
| 62 }; | 66 }; | 
| 63 | 67 | 
| 64 function validatePermissionFlipWorks(origin, expectedPermissionValue) { | 68 function validatePermissionFlipWorks(origin, expectedPermissionValue) { | 
| 65 browserProxy.resetResolver('setCategoryPermissionForOrigin'); | 69 browserProxy.resetResolver('setCategoryPermissionForOrigin'); | 
| 66 | 70 | 
| 67 // Simulate permission change initiated by the user. | 71 // Simulate permission change initiated by the user. | 
| 68 testElement.$.permission.value = expectedPermissionValue; | 72 testElement.$.permission.value = expectedPermissionValue; | 
| 69 testElement.$.permission.dispatchEvent(new CustomEvent('change')); | 73 testElement.$.permission.dispatchEvent(new CustomEvent('change')); | 
| 70 | 74 | 
| 71 return browserProxy.whenCalled('setCategoryPermissionForOrigin') | 75 return browserProxy.whenCalled('setCategoryPermissionForOrigin') | 
| 72 .then(function(args) { | 76 .then(function(args) { | 
| 73 assertEquals(origin, args[0]); | 77 assertEquals(origin, args[0]); | 
| 74 assertEquals('', args[1]); | 78 assertEquals('', args[1]); | 
| 75 assertEquals(testElement.category, args[2]); | 79 assertEquals(testElement.category, args[2]); | 
| 76 assertEquals(expectedPermissionValue, args[3]); | 80 assertEquals(expectedPermissionValue, args[3]); | 
| 77 }); | 81 }); | 
| 78 }; | 82 }; | 
| 79 | 83 | 
| 80 test('empty state', function() { | |
| 81 browserProxy.setPrefs(prefsEmpty); | |
| 82 testElement.category = settings.ContentSettingsTypes.CAMERA; | |
| 83 testElement.site = { | |
| 84 origin: 'http://www.google.com', | |
| 85 embeddingOrigin: '', | |
| 86 }; | |
| 87 | |
| 88 return browserProxy.whenCalled('getExceptionList').then(function() { | |
| 89 assertTrue(testElement.$.details.hidden); | |
| 90 }); | |
| 91 }); | |
| 92 | |
| 93 test('camera category', function() { | 84 test('camera category', function() { | 
| 94 var origin = 'https://www.example.com'; | 85 var origin = 'https://www.example.com'; | 
| 95 browserProxy.setPrefs(prefs); | 86 browserProxy.setPrefs(prefs); | 
| 96 testElement.category = settings.ContentSettingsTypes.CAMERA; | 87 testElement.category = settings.ContentSettingsTypes.CAMERA; | 
| 97 testElement.label = 'Camera'; | 88 testElement.label = 'Camera'; | 
| 98 testElement.site = { | 89 testElement.site = { | 
| 99 origin: origin, | 90 origin: origin, | 
| 100 embeddingOrigin: '', | 91 embeddingOrigin: '', | 
| 101 }; | 92 }; | 
| 102 | 93 | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 .then(function() { | 139 .then(function() { | 
| 149 // Flip the permission and validate that prefs stay in sync. | 140 // Flip the permission and validate that prefs stay in sync. | 
| 150 return validatePermissionFlipWorks( | 141 return validatePermissionFlipWorks( | 
| 151 origin, settings.PermissionValues.ALLOW); | 142 origin, settings.PermissionValues.ALLOW); | 
| 152 }) | 143 }) | 
| 153 .then(function() { | 144 .then(function() { | 
| 154 return validatePermissionFlipWorks( | 145 return validatePermissionFlipWorks( | 
| 155 origin, settings.PermissionValues.BLOCK); | 146 origin, settings.PermissionValues.BLOCK); | 
| 156 }); | 147 }); | 
| 157 }); | 148 }); | 
| 158 | |
| 159 test('disappear on empty', function() { | |
| 160 var origin = 'https://www.example.com'; | |
| 161 browserProxy.setPrefs(prefs); | |
| 162 testElement.category = settings.ContentSettingsTypes.CAMERA; | |
| 163 testElement.site = { | |
| 164 origin: origin, | |
| 165 embeddingOrigin: '', | |
| 166 }; | |
| 167 | |
| 168 return browserProxy.whenCalled('getExceptionList') | |
| 169 .then(function() { | |
| 170 assertFalse(testElement.$.details.hidden); | |
| 171 | |
| 172 browserProxy.setPrefs(prefsEmpty); | |
| 173 return browserProxy.whenCalled('getExceptionList'); | |
| 174 }) | |
| 175 .then(function() { | |
| 176 assertTrue(testElement.$.details.hidden); | |
| 177 }); | |
| 178 }); | |
| 179 }); | 149 }); | 
| OLD | NEW |