| 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-list. */ | 5 /** @fileoverview Suite of tests for site-list. */ |
| 6 cr.define('site_list', function() { | 6 cr.define('site_list', function() { |
| 7 /** | 7 /** |
| 8 * An example pref with 2 blocked location items and 2 allowed. This pref | 8 * An example pref with 2 blocked location items and 2 allowed. This pref |
| 9 * is also used for the All Sites category and therefore needs values for | 9 * is also used for the All Sites category and therefore needs values for |
| 10 * all types, even though some might be blank. | 10 * all types, even though some might be blank. |
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 args[0]); | 1049 args[0]); |
| 1050 assertEquals('', args[1]); | 1050 assertEquals('', args[1]); |
| 1051 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); | 1051 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); |
| 1052 assertEquals('allow', args[3]); | 1052 assertEquals('allow', args[3]); |
| 1053 }); | 1053 }); |
| 1054 }); | 1054 }); |
| 1055 }); | 1055 }); |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 suite('EditExceptionDialog', function() { | 1058 suite('EditExceptionDialog', function() { |
| 1059 var dialog; | 1059 /** @type {SettingsEditExceptionDialogElement} */ var dialog; |
| 1060 |
| 1060 /** | 1061 /** |
| 1061 * The dialog tests don't call |getExceptionList| so the exception needs to | 1062 * The dialog tests don't call |getExceptionList| so the exception needs to |
| 1062 * be processes as a |SiteSettingsPref|. | 1063 * be processes as a |SiteSettingsPref|. |
| 1063 * @type {SiteSettingsPref} | 1064 * @type {SiteSettingsPref} |
| 1064 */ | 1065 */ |
| 1065 var cookieException = { | 1066 var cookieException = { |
| 1066 category: 'cookies', | 1067 category: 'cookies', |
| 1067 embeddingOrigin: 'http://foo.com', | 1068 embeddingOrigin: 'http://foo.com', |
| 1068 incognito: false, | 1069 incognito: false, |
| 1069 origin: 'http://foo.com', | 1070 origin: 'http://foo.com', |
| 1070 setting: 'block', | 1071 setting: 'block', |
| 1071 enforcement: '', | 1072 enforcement: '', |
| 1072 controlledBy: 'USER_POLICY', | 1073 controlledBy: 'USER_POLICY', |
| 1073 }; | 1074 }; |
| 1074 | 1075 |
| 1075 setup(function() { | 1076 setup(function() { |
| 1076 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); | 1077 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); |
| 1077 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; | 1078 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; |
| 1078 PolymerTest.clearBody(); | 1079 PolymerTest.clearBody(); |
| 1079 dialog = document.createElement('settings-edit-exception-dialog'); | 1080 dialog = document.createElement('settings-edit-exception-dialog'); |
| 1080 dialog.model = cookieException; | 1081 dialog.model = cookieException; |
| 1081 document.body.appendChild(dialog); | 1082 document.body.appendChild(dialog); |
| 1082 }); | 1083 }); |
| 1083 | 1084 |
| 1084 teardown(function() { | 1085 teardown(function() { |
| 1085 dialog.remove(); | 1086 dialog.remove(); |
| 1086 }); | 1087 }); |
| 1087 | 1088 |
| 1088 test('action button disabled on invalid input', function() { | 1089 test('invalid input', function() { |
| 1089 var input = dialog.$$('paper-input'); | 1090 var input = dialog.$$('paper-input'); |
| 1090 assertTrue(!!input); | 1091 assertTrue(!!input); |
| 1092 assertFalse(input.invalid); |
| 1093 |
| 1091 var actionButton = dialog.$.actionButton; | 1094 var actionButton = dialog.$.actionButton; |
| 1092 assertTrue(!!actionButton); | 1095 assertTrue(!!actionButton); |
| 1093 assertFalse(actionButton.disabled); | 1096 assertFalse(actionButton.disabled); |
| 1094 | 1097 |
| 1098 // Simulate user input of whitespace only text. |
| 1099 input.value = ' '; |
| 1100 input.fire('input'); |
| 1101 Polymer.dom.flush(); |
| 1102 assertTrue(actionButton.disabled); |
| 1103 assertTrue(input.invalid); |
| 1104 |
| 1105 // Simulate user input of invalid text. |
| 1095 browserProxy.setIsPatternValid(false); | 1106 browserProxy.setIsPatternValid(false); |
| 1096 var expectedPattern = 'foobarbaz'; | 1107 var expectedPattern = 'foobarbaz'; |
| 1097 // Simulate user input. | |
| 1098 input.value = expectedPattern; | 1108 input.value = expectedPattern; |
| 1099 input.fire('input'); | 1109 input.fire('input'); |
| 1100 | 1110 |
| 1101 return browserProxy.whenCalled('isPatternValid').then(function(pattern) { | 1111 return browserProxy.whenCalled('isPatternValid').then(function(pattern) { |
| 1102 assertEquals(expectedPattern, pattern); | 1112 assertEquals(expectedPattern, pattern); |
| 1103 assertTrue(actionButton.disabled); | 1113 assertTrue(actionButton.disabled); |
| 1114 assertTrue(input.invalid); |
| 1104 }); | 1115 }); |
| 1105 }); | 1116 }); |
| 1106 | 1117 |
| 1107 test('action button calls proxy', function() { | 1118 test('action button calls proxy', function() { |
| 1108 var input = dialog.$$('paper-input'); | 1119 var input = dialog.$$('paper-input'); |
| 1109 assertTrue(!!input); | 1120 assertTrue(!!input); |
| 1110 // Simulate user edit. | 1121 // Simulate user edit. |
| 1111 var newValue = input.value + ':1234'; | 1122 var newValue = input.value + ':1234'; |
| 1112 input.value = newValue; | 1123 input.value = newValue; |
| 1113 | 1124 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1130 assertEquals(newValue, args[1]); | 1141 assertEquals(newValue, args[1]); |
| 1131 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); | 1142 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); |
| 1132 assertEquals(cookieException.setting, args[3]); | 1143 assertEquals(cookieException.setting, args[3]); |
| 1133 assertEquals(cookieException.incognito, args[4]); | 1144 assertEquals(cookieException.incognito, args[4]); |
| 1134 | 1145 |
| 1135 assertFalse(dialog.$.dialog.open); | 1146 assertFalse(dialog.$.dialog.open); |
| 1136 }); | 1147 }); |
| 1137 }); | 1148 }); |
| 1138 }); | 1149 }); |
| 1139 | 1150 |
| 1151 suite('AddExceptionDialog', function() { |
| 1152 /** @type {AddSiteDialogElement} */ var dialog; |
| 1153 |
| 1154 setup(function() { |
| 1155 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); |
| 1156 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; |
| 1157 PolymerTest.clearBody(); |
| 1158 dialog = document.createElement('add-site-dialog'); |
| 1159 dialog.category = settings.ContentSettingsTypes.GEOLOCATION; |
| 1160 dialog.contentSetting = settings.PermissionValues.ALLOW; |
| 1161 document.body.appendChild(dialog); |
| 1162 }); |
| 1163 |
| 1164 teardown(function() { |
| 1165 dialog.remove(); |
| 1166 }); |
| 1167 |
| 1168 test('invalid input', function() { |
| 1169 // Initially the action button should be disabled, but the error warning |
| 1170 // should not be shown for an empty input. |
| 1171 var input = dialog.$$('paper-input'); |
| 1172 assertTrue(!!input); |
| 1173 assertFalse(input.invalid); |
| 1174 |
| 1175 var actionButton = dialog.$.add; |
| 1176 assertTrue(!!actionButton); |
| 1177 assertTrue(actionButton.disabled); |
| 1178 |
| 1179 // Simulate user input of invalid text. |
| 1180 browserProxy.setIsPatternValid(false); |
| 1181 var expectedPattern = 'foobarbaz'; |
| 1182 input.value = expectedPattern; |
| 1183 input.fire('input'); |
| 1184 |
| 1185 return browserProxy.whenCalled('isPatternValid').then(function(pattern) { |
| 1186 assertEquals(expectedPattern, pattern); |
| 1187 assertTrue(actionButton.disabled); |
| 1188 assertTrue(input.invalid); |
| 1189 }); |
| 1190 }); |
| 1191 }); |
| 1192 |
| 1140 return { | 1193 return { |
| 1141 registerTests: registerTests, | 1194 registerTests: registerTests, |
| 1142 }; | 1195 }; |
| 1143 }); | 1196 }); |
| OLD | NEW |