| 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 during teardown in PolymerTest.testIronIcons. | 
|  | 54     // In practice, this is done from the parent. | 
|  | 55     testElement.icon = 'settings:videocam'; | 
| 51     document.body.appendChild(testElement); | 56     document.body.appendChild(testElement); | 
| 52   }); | 57   }); | 
| 53 | 58 | 
| 54   // Tests that the given value is converted to the expected value, for a | 59   // Tests that the given value is converted to the expected value, for a | 
| 55   // given prefType. | 60   // given prefType. | 
| 56   function isAllowed(origin, exceptionList) { | 61   function isAllowed(origin, exceptionList) { | 
| 57     for (var i = 0; i < exceptionList.length; ++i) { | 62     for (var i = 0; i < exceptionList.length; ++i) { | 
| 58       if (exceptionList[i].origin == origin) | 63       if (exceptionList[i].origin == origin) | 
| 59         return exceptionList[i].setting == 'allow'; | 64         return exceptionList[i].setting == 'allow'; | 
| 60     } | 65     } | 
| 61     return false; | 66     return false; | 
| 62   }; | 67   }; | 
| 63 | 68 | 
| 64   function validatePermissionFlipWorks(origin, expectedPermissionValue) { | 69   function validatePermissionFlipWorks(origin, expectedPermissionValue) { | 
| 65     browserProxy.resetResolver('setCategoryPermissionForOrigin'); | 70     browserProxy.resetResolver('setCategoryPermissionForOrigin'); | 
| 66 | 71 | 
| 67     // Simulate permission change initiated by the user. | 72     // Simulate permission change initiated by the user. | 
| 68     testElement.$.permission.value = expectedPermissionValue; | 73     testElement.$.permission.value = expectedPermissionValue; | 
| 69     testElement.$.permission.dispatchEvent(new CustomEvent('change')); | 74     testElement.$.permission.dispatchEvent(new CustomEvent('change')); | 
| 70 | 75 | 
| 71     return browserProxy.whenCalled('setCategoryPermissionForOrigin') | 76     return browserProxy.whenCalled('setCategoryPermissionForOrigin') | 
| 72         .then(function(args) { | 77         .then(function(args) { | 
| 73           assertEquals(origin, args[0]); | 78           assertEquals(origin, args[0]); | 
| 74           assertEquals('', args[1]); | 79           assertEquals('', args[1]); | 
| 75           assertEquals(testElement.category, args[2]); | 80           assertEquals(testElement.category, args[2]); | 
| 76           assertEquals(expectedPermissionValue, args[3]); | 81           assertEquals(expectedPermissionValue, args[3]); | 
| 77         }); | 82         }); | 
| 78   }; | 83   }; | 
| 79 | 84 | 
| 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() { | 85   test('camera category', function() { | 
| 94     var origin = 'https://www.example.com'; | 86     var origin = 'https://www.example.com'; | 
| 95     browserProxy.setPrefs(prefs); | 87     browserProxy.setPrefs(prefs); | 
| 96     testElement.category = settings.ContentSettingsTypes.CAMERA; | 88     testElement.category = settings.ContentSettingsTypes.CAMERA; | 
| 97     testElement.label = 'Camera'; | 89     testElement.label = 'Camera'; | 
| 98     testElement.site = { | 90     testElement.site = { | 
| 99       origin: origin, | 91       origin: origin, | 
| 100       embeddingOrigin: '', | 92       embeddingOrigin: '', | 
| 101     }; | 93     }; | 
| 102 | 94 | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 148         .then(function() { | 140         .then(function() { | 
| 149           // Flip the permission and validate that prefs stay in sync. | 141           // Flip the permission and validate that prefs stay in sync. | 
| 150           return validatePermissionFlipWorks( | 142           return validatePermissionFlipWorks( | 
| 151               origin, settings.PermissionValues.ALLOW); | 143               origin, settings.PermissionValues.ALLOW); | 
| 152         }) | 144         }) | 
| 153         .then(function() { | 145         .then(function() { | 
| 154           return validatePermissionFlipWorks( | 146           return validatePermissionFlipWorks( | 
| 155               origin, settings.PermissionValues.BLOCK); | 147               origin, settings.PermissionValues.BLOCK); | 
| 156         }); | 148         }); | 
| 157   }); | 149   }); | 
| 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 }); | 150 }); | 
| OLD | NEW | 
|---|