| 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 /** |
| 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 |
| 10 * all types, even though some might be blank. |
| 11 * @type {SiteSettingsPref} |
| 12 */ |
| 13 var prefs = { |
| 14 exceptions: { |
| 15 auto_downloads: [], |
| 16 background_sync: [], |
| 17 camera: [], |
| 18 cookies: [], |
| 19 geolocation: [ |
| 20 { |
| 21 embeddingOrigin: 'https://bar-allow.com:443', |
| 22 origin: 'https://bar-allow.com:443', |
| 23 setting: 'allow', |
| 24 source: 'preference', |
| 25 }, |
| 26 { |
| 27 embeddingOrigin: 'https://foo-allow.com:443', |
| 28 origin: 'https://foo-allow.com:443', |
| 29 setting: 'allow', |
| 30 source: 'preference', |
| 31 }, |
| 32 { |
| 33 embeddingOrigin: 'https://bar-block.com:443', |
| 34 origin: 'https://bar-block.com:443', |
| 35 setting: 'block', |
| 36 source: 'preference', |
| 37 }, |
| 38 { |
| 39 embeddingOrigin: 'https://foo-block.com:443', |
| 40 origin: 'https://foo-block.com:443', |
| 41 setting: 'block', |
| 42 source: 'preference', |
| 43 }, |
| 44 ], |
| 45 images: [], |
| 46 javascript: [], |
| 47 mic: [], |
| 48 midiDevices: [], |
| 49 notifications: [], |
| 50 plugins: [], |
| 51 protectedContent: [], |
| 52 popups: [], |
| 53 unsandboxed_plugins: [], |
| 54 } |
| 55 }; |
| 56 |
| 57 /** |
| 58 * An example pref with mixed schemes (present and absent). |
| 59 * @type {SiteSettingsPref} |
| 60 */ |
| 61 var prefsMixedSchemes = { |
| 62 exceptions: { |
| 63 geolocation: [ |
| 64 { |
| 65 embeddingOrigin: 'https://foo-allow.com', |
| 66 origin: 'https://foo-allow.com', |
| 67 setting: 'allow', |
| 68 source: 'preference', |
| 69 }, |
| 70 { |
| 71 embeddingOrigin: 'bar-allow.com', |
| 72 origin: 'bar-allow.com', |
| 73 setting: 'allow', |
| 74 source: 'preference', |
| 75 }, |
| 76 ] |
| 77 } |
| 78 }; |
| 79 |
| 80 |
| 81 /** |
| 82 * An example pref with exceptions with origins and patterns from |
| 83 * different providers. |
| 84 * @type {SiteSettingsPref} |
| 85 */ |
| 86 var prefsMixedProvider = { |
| 87 exceptions: { |
| 88 geolocation: [ |
| 89 { |
| 90 embeddingOrigin: 'https://[*.]foo.com', |
| 91 origin: 'https://[*.]foo.com', |
| 92 setting: 'block', |
| 93 source: 'policy', |
| 94 }, |
| 95 { |
| 96 embeddingOrigin: 'https://bar.foo.com', |
| 97 origin: 'https://bar.foo.com', |
| 98 setting: 'block', |
| 99 source: 'preference', |
| 100 }, |
| 101 { |
| 102 embeddingOrigin: 'https://[*.]foo.com', |
| 103 origin: 'https://[*.]foo.com', |
| 104 setting: 'block', |
| 105 source: 'preference', |
| 106 }, |
| 107 ] |
| 108 } |
| 109 }; |
| 110 |
| 111 /** |
| 112 * An example pref with mixed origin and pattern. |
| 113 * @type {SiteSettingsPref} |
| 114 */ |
| 115 var prefsMixedOriginAndPattern = { |
| 116 exceptions: { |
| 117 auto_downloads: [], |
| 118 background_sync: [], |
| 119 camera: [], |
| 120 cookies: [], |
| 121 geolocation: [ |
| 122 { |
| 123 origin: 'https://foo.com', |
| 124 embeddingOrigin: '*', |
| 125 setting: 'allow', |
| 126 source: 'preference', |
| 127 }, |
| 128 ], |
| 129 images: [], |
| 130 javascript: [ |
| 131 { |
| 132 origin: 'https://[*.]foo.com', |
| 133 embeddingOrigin: '*', |
| 134 setting: 'allow', |
| 135 source: 'preference', |
| 136 }, |
| 137 ], |
| 138 mic: [], |
| 139 notifications: [], |
| 140 plugins: [], |
| 141 midiDevices: [], |
| 142 protectedContent: [], |
| 143 popups: [], |
| 144 unsandboxed_plugins: [], |
| 145 } |
| 146 }; |
| 147 |
| 148 /** |
| 149 * An example pref with multiple categories and multiple allow/block |
| 150 * state. |
| 151 * @type {SiteSettingsPref} |
| 152 */ |
| 153 var prefsVarious = { |
| 154 exceptions: { |
| 155 auto_downloads: [], |
| 156 background_sync: [], |
| 157 camera: [], |
| 158 cookies: [], |
| 159 geolocation: [ |
| 160 { |
| 161 embeddingOrigin: 'https://foo.com', |
| 162 origin: 'https://foo.com', |
| 163 setting: 'allow', |
| 164 source: 'preference', |
| 165 }, |
| 166 { |
| 167 embeddingOrigin: 'https://bar.com', |
| 168 origin: 'https://bar.com', |
| 169 setting: 'block', |
| 170 source: 'preference', |
| 171 }, |
| 172 ], |
| 173 images: [], |
| 174 javascript: [], |
| 175 mic: [], |
| 176 midiDevices: [], |
| 177 notifications: [ |
| 178 { |
| 179 embeddingOrigin: 'https://google.com', |
| 180 origin: 'https://google.com', |
| 181 setting: 'block', |
| 182 source: 'preference', |
| 183 }, |
| 184 { |
| 185 embeddingOrigin: 'https://bar.com', |
| 186 origin: 'https://bar.com', |
| 187 setting: 'block', |
| 188 source: 'preference', |
| 189 }, |
| 190 { |
| 191 embeddingOrigin: 'https://foo.com', |
| 192 origin: 'https://foo.com', |
| 193 setting: 'block', |
| 194 source: 'preference', |
| 195 }, |
| 196 ], |
| 197 plugins: [], |
| 198 protectedContent: [], |
| 199 popups: [], |
| 200 unsandboxed_plugins: [], |
| 201 } |
| 202 }; |
| 203 |
| 204 /** |
| 205 * An example pref with 1 allowed location item. |
| 206 * @type {SiteSettingsPref} |
| 207 */ |
| 208 var prefsOneEnabled = { |
| 209 exceptions: { |
| 210 geolocation: [ |
| 211 { |
| 212 embeddingOrigin: 'https://foo-allow.com:443', |
| 213 origin: 'https://foo-allow.com:443', |
| 214 setting: 'allow', |
| 215 source: 'preference', |
| 216 }, |
| 217 ] |
| 218 } |
| 219 }; |
| 220 |
| 221 /** |
| 222 * An example pref with 1 blocked location item. |
| 223 * @type {SiteSettingsPref} |
| 224 */ |
| 225 var prefsOneDisabled = { |
| 226 exceptions: { |
| 227 geolocation: [ |
| 228 { |
| 229 embeddingOrigin: 'https://foo-block.com:443', |
| 230 origin: 'https://foo-block.com:443', |
| 231 setting: 'block', |
| 232 source: 'preference', |
| 233 }, |
| 234 ] |
| 235 } |
| 236 }; |
| 237 |
| 238 /** |
| 239 * An example Cookies pref with 1 in each of the three categories. |
| 240 * @type {SiteSettingsPref} |
| 241 */ |
| 242 var prefsSessionOnly = { |
| 243 exceptions: { |
| 244 cookies: [ |
| 245 { |
| 246 embeddingOrigin: 'http://foo-block.com', |
| 247 origin: 'http://foo-block.com', |
| 248 setting: 'block', |
| 249 source: 'preference', |
| 250 }, |
| 251 { |
| 252 embeddingOrigin: 'http://foo-allow.com', |
| 253 origin: 'http://foo-allow.com', |
| 254 setting: 'allow', |
| 255 source: 'preference', |
| 256 }, |
| 257 { |
| 258 embeddingOrigin: 'http://foo-session.com', |
| 259 origin: 'http://foo-session.com', |
| 260 setting: 'session_only', |
| 261 source: 'preference', |
| 262 }, |
| 263 ] |
| 264 } |
| 265 }; |
| 266 |
| 267 /** |
| 268 * An example Cookies pref with mixed incognito and regular settings. |
| 269 * @type {SiteSettingsPref} |
| 270 */ |
| 271 var prefsIncognito = { |
| 272 exceptions: { |
| 273 cookies: [ |
| 274 // foo.com is blocked for regular sessions. |
| 275 { |
| 276 embeddingOrigin: 'http://foo.com', |
| 277 incognito: false, |
| 278 origin: 'http://foo.com', |
| 279 setting: 'block', |
| 280 source: 'preference', |
| 281 }, |
| 282 // bar.com is an allowed incognito item without an embedder. |
| 283 { |
| 284 embeddingOrigin: '', |
| 285 incognito: true, |
| 286 origin: 'http://bar.com', |
| 287 setting: 'allow', |
| 288 source: 'preference', |
| 289 }, |
| 290 // foo.com is allowed in incognito (overridden). |
| 291 { |
| 292 embeddingOrigin: 'http://foo.com', |
| 293 incognito: true, |
| 294 origin: 'http://foo.com', |
| 295 setting: 'allow', |
| 296 source: 'preference', |
| 297 }, |
| 298 |
| 299 ] |
| 300 } |
| 301 }; |
| 302 |
| 303 /** |
| 304 * An example Javascript pref with a chrome-extension:// scheme. |
| 305 * @type {SiteSettingsPref} |
| 306 */ |
| 307 var prefsChromeExtension = { |
| 308 exceptions: { |
| 309 javascript: [ |
| 310 { |
| 311 embeddingOrigin: '', |
| 312 origin: 'chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', |
| 313 setting: 'block', |
| 314 source: 'preference', |
| 315 }, |
| 316 ] |
| 317 } |
| 318 }; |
| 319 |
| 7 function registerTests() { | 320 function registerTests() { |
| 8 suite('SiteList', function() { | 321 suite('SiteList', function() { |
| 9 /** | 322 /** |
| 10 * A site list element created before each test. | 323 * A site list element created before each test. |
| 11 * @type {SiteList} | 324 * @type {SiteList} |
| 12 */ | 325 */ |
| 13 var testElement; | 326 var testElement; |
| 14 | 327 |
| 15 /** | 328 /** |
| 16 * The mock proxy object to use during test. | 329 * The mock proxy object to use during test. |
| 17 * @type {TestSiteSettingsPrefsBrowserProxy} | 330 * @type {TestSiteSettingsPrefsBrowserProxy} |
| 18 */ | 331 */ |
| 19 var browserProxy = null; | 332 var browserProxy = null; |
| 20 | 333 |
| 21 /** | |
| 22 * An example pref with 2 blocked location items and 2 allowed. This pref | |
| 23 * is also used for the All Sites category and therefore needs values for | |
| 24 * all types, even though some might be blank. | |
| 25 * @type {SiteSettingsPref} | |
| 26 */ | |
| 27 var prefs = { | |
| 28 exceptions: { | |
| 29 auto_downloads: [], | |
| 30 background_sync: [], | |
| 31 camera: [], | |
| 32 cookies: [], | |
| 33 geolocation: [ | |
| 34 { | |
| 35 embeddingOrigin: 'https://bar-allow.com:443', | |
| 36 origin: 'https://bar-allow.com:443', | |
| 37 setting: 'allow', | |
| 38 source: 'preference', | |
| 39 }, | |
| 40 { | |
| 41 embeddingOrigin: 'https://foo-allow.com:443', | |
| 42 origin: 'https://foo-allow.com:443', | |
| 43 setting: 'allow', | |
| 44 source: 'preference', | |
| 45 }, | |
| 46 { | |
| 47 embeddingOrigin: 'https://bar-block.com:443', | |
| 48 origin: 'https://bar-block.com:443', | |
| 49 setting: 'block', | |
| 50 source: 'preference', | |
| 51 }, | |
| 52 { | |
| 53 embeddingOrigin: 'https://foo-block.com:443', | |
| 54 origin: 'https://foo-block.com:443', | |
| 55 setting: 'block', | |
| 56 source: 'preference', | |
| 57 }, | |
| 58 ], | |
| 59 images: [], | |
| 60 javascript: [], | |
| 61 mic: [], | |
| 62 midiDevices: [], | |
| 63 notifications: [], | |
| 64 plugins: [], | |
| 65 protectedContent: [], | |
| 66 popups: [], | |
| 67 unsandboxed_plugins: [], | |
| 68 } | |
| 69 }; | |
| 70 | |
| 71 /** | |
| 72 * An example pref with mixed schemes (present and absent). | |
| 73 * @type {SiteSettingsPref} | |
| 74 */ | |
| 75 var prefsMixedSchemes = { | |
| 76 exceptions: { | |
| 77 geolocation: [ | |
| 78 { | |
| 79 embeddingOrigin: 'https://foo-allow.com', | |
| 80 origin: 'https://foo-allow.com', | |
| 81 setting: 'allow', | |
| 82 source: 'preference', | |
| 83 }, | |
| 84 { | |
| 85 embeddingOrigin: 'bar-allow.com', | |
| 86 origin: 'bar-allow.com', | |
| 87 setting: 'allow', | |
| 88 source: 'preference', | |
| 89 }, | |
| 90 ] | |
| 91 } | |
| 92 }; | |
| 93 | |
| 94 | |
| 95 /** | |
| 96 * An example pref with exceptions with origins and patterns from | |
| 97 * different providers. | |
| 98 * @type {SiteSettingsPref} | |
| 99 */ | |
| 100 var prefsMixedProvider = { | |
| 101 exceptions: { | |
| 102 geolocation: [ | |
| 103 { | |
| 104 embeddingOrigin: 'https://[*.]foo.com', | |
| 105 origin: 'https://[*.]foo.com', | |
| 106 setting: 'block', | |
| 107 source: 'policy', | |
| 108 }, | |
| 109 { | |
| 110 embeddingOrigin: 'https://bar.foo.com', | |
| 111 origin: 'https://bar.foo.com', | |
| 112 setting: 'block', | |
| 113 source: 'preference', | |
| 114 }, | |
| 115 { | |
| 116 embeddingOrigin: 'https://[*.]foo.com', | |
| 117 origin: 'https://[*.]foo.com', | |
| 118 setting: 'block', | |
| 119 source: 'preference', | |
| 120 }, | |
| 121 ] | |
| 122 } | |
| 123 }; | |
| 124 | |
| 125 /** | |
| 126 * An example pref with mixed origin and pattern. | |
| 127 * @type {SiteSettingsPref} | |
| 128 */ | |
| 129 var prefsMixedOriginAndPattern = { | |
| 130 exceptions: { | |
| 131 auto_downloads: [], | |
| 132 background_sync: [], | |
| 133 camera: [], | |
| 134 cookies: [], | |
| 135 geolocation: [ | |
| 136 { | |
| 137 origin: 'https://foo.com', | |
| 138 embeddingOrigin: '*', | |
| 139 setting: 'allow', | |
| 140 source: 'preference', | |
| 141 }, | |
| 142 ], | |
| 143 images: [], | |
| 144 javascript: [ | |
| 145 { | |
| 146 origin: 'https://[*.]foo.com', | |
| 147 embeddingOrigin: '*', | |
| 148 setting: 'allow', | |
| 149 source: 'preference', | |
| 150 }, | |
| 151 ], | |
| 152 mic: [], | |
| 153 notifications: [], | |
| 154 plugins: [], | |
| 155 midiDevices: [], | |
| 156 protectedContent: [], | |
| 157 popups: [], | |
| 158 unsandboxed_plugins: [], | |
| 159 } | |
| 160 }; | |
| 161 | |
| 162 /** | |
| 163 * An example pref with multiple categories and multiple allow/block | |
| 164 * state. | |
| 165 * @type {SiteSettingsPref} | |
| 166 */ | |
| 167 var prefsVarious = { | |
| 168 exceptions: { | |
| 169 auto_downloads: [], | |
| 170 background_sync: [], | |
| 171 camera: [], | |
| 172 cookies: [], | |
| 173 geolocation: [ | |
| 174 { | |
| 175 embeddingOrigin: 'https://foo.com', | |
| 176 origin: 'https://foo.com', | |
| 177 setting: 'allow', | |
| 178 source: 'preference', | |
| 179 }, | |
| 180 { | |
| 181 embeddingOrigin: 'https://bar.com', | |
| 182 origin: 'https://bar.com', | |
| 183 setting: 'block', | |
| 184 source: 'preference', | |
| 185 }, | |
| 186 ], | |
| 187 images: [], | |
| 188 javascript: [], | |
| 189 mic: [], | |
| 190 midiDevices: [], | |
| 191 notifications: [ | |
| 192 { | |
| 193 embeddingOrigin: 'https://google.com', | |
| 194 origin: 'https://google.com', | |
| 195 setting: 'block', | |
| 196 source: 'preference', | |
| 197 }, | |
| 198 { | |
| 199 embeddingOrigin: 'https://bar.com', | |
| 200 origin: 'https://bar.com', | |
| 201 setting: 'block', | |
| 202 source: 'preference', | |
| 203 }, | |
| 204 { | |
| 205 embeddingOrigin: 'https://foo.com', | |
| 206 origin: 'https://foo.com', | |
| 207 setting: 'block', | |
| 208 source: 'preference', | |
| 209 }, | |
| 210 ], | |
| 211 plugins: [], | |
| 212 protectedContent: [], | |
| 213 popups: [], | |
| 214 unsandboxed_plugins: [], | |
| 215 } | |
| 216 }; | |
| 217 | |
| 218 /** | |
| 219 * An example pref with 1 allowed location item. | |
| 220 * @type {SiteSettingsPref} | |
| 221 */ | |
| 222 var prefsOneEnabled = { | |
| 223 exceptions: { | |
| 224 geolocation: [ | |
| 225 { | |
| 226 embeddingOrigin: 'https://foo-allow.com:443', | |
| 227 origin: 'https://foo-allow.com:443', | |
| 228 setting: 'allow', | |
| 229 source: 'preference', | |
| 230 }, | |
| 231 ] | |
| 232 } | |
| 233 }; | |
| 234 | |
| 235 /** | |
| 236 * An example pref with 1 blocked location item. | |
| 237 * @type {SiteSettingsPref} | |
| 238 */ | |
| 239 var prefsOneDisabled = { | |
| 240 exceptions: { | |
| 241 geolocation: [ | |
| 242 { | |
| 243 embeddingOrigin: 'https://foo-block.com:443', | |
| 244 origin: 'https://foo-block.com:443', | |
| 245 setting: 'block', | |
| 246 source: 'preference', | |
| 247 }, | |
| 248 ] | |
| 249 } | |
| 250 }; | |
| 251 | |
| 252 /** | |
| 253 * An example Cookies pref with 1 in each of the three categories. | |
| 254 * @type {SiteSettingsPref} | |
| 255 */ | |
| 256 var prefsSessionOnly = { | |
| 257 exceptions: { | |
| 258 cookies: [ | |
| 259 { | |
| 260 embeddingOrigin: 'http://foo-block.com', | |
| 261 origin: 'http://foo-block.com', | |
| 262 setting: 'block', | |
| 263 source: 'preference', | |
| 264 }, | |
| 265 { | |
| 266 embeddingOrigin: 'http://foo-allow.com', | |
| 267 origin: 'http://foo-allow.com', | |
| 268 setting: 'allow', | |
| 269 source: 'preference', | |
| 270 }, | |
| 271 { | |
| 272 embeddingOrigin: 'http://foo-session.com', | |
| 273 origin: 'http://foo-session.com', | |
| 274 setting: 'session_only', | |
| 275 source: 'preference', | |
| 276 }, | |
| 277 ] | |
| 278 } | |
| 279 }; | |
| 280 | |
| 281 /** | |
| 282 * An example Cookies pref with mixed incognito and regular settings. | |
| 283 * @type {SiteSettingsPref} | |
| 284 */ | |
| 285 var prefsIncognito = { | |
| 286 exceptions: { | |
| 287 cookies: [ | |
| 288 // foo.com is blocked for regular sessions. | |
| 289 { | |
| 290 embeddingOrigin: 'http://foo.com', | |
| 291 incognito: false, | |
| 292 origin: 'http://foo.com', | |
| 293 setting: 'block', | |
| 294 source: 'preference', | |
| 295 }, | |
| 296 // bar.com is an allowed incognito item without an embedder. | |
| 297 { | |
| 298 embeddingOrigin: '', | |
| 299 incognito: true, | |
| 300 origin: 'http://bar.com', | |
| 301 setting: 'allow', | |
| 302 source: 'preference', | |
| 303 }, | |
| 304 // foo.com is allowed in incognito (overridden). | |
| 305 { | |
| 306 embeddingOrigin: 'http://foo.com', | |
| 307 incognito: true, | |
| 308 origin: 'http://foo.com', | |
| 309 setting: 'allow', | |
| 310 source: 'preference', | |
| 311 }, | |
| 312 | |
| 313 ] | |
| 314 } | |
| 315 }; | |
| 316 | |
| 317 /** | |
| 318 * An example Javascript pref with a chrome-extension:// scheme. | |
| 319 * @type {SiteSettingsPref} | |
| 320 */ | |
| 321 var prefsChromeExtension = { | |
| 322 exceptions: { | |
| 323 javascript: [ | |
| 324 { | |
| 325 embeddingOrigin: '', | |
| 326 origin: 'chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', | |
| 327 setting: 'block', | |
| 328 source: 'preference', | |
| 329 }, | |
| 330 ] | |
| 331 } | |
| 332 }; | |
| 333 | 334 |
| 334 suiteSetup(function() { | 335 suiteSetup(function() { |
| 335 CrSettingsPrefs.setInitialized(); | 336 CrSettingsPrefs.setInitialized(); |
| 336 }); | 337 }); |
| 337 | 338 |
| 338 suiteTeardown(function() { | 339 suiteTeardown(function() { |
| 339 CrSettingsPrefs.resetForTesting(); | 340 CrSettingsPrefs.resetForTesting(); |
| 340 }); | 341 }); |
| 341 | 342 |
| 342 // Initialize a site-list before each test. | 343 // Initialize a site-list before each test. |
| 343 setup(function() { | 344 setup(function() { |
| 344 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); | 345 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); |
| 345 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; | 346 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; |
| 346 PolymerTest.clearBody(); | 347 PolymerTest.clearBody(); |
| 347 testElement = document.createElement('site-list'); | 348 testElement = document.createElement('site-list'); |
| 348 document.body.appendChild(testElement); | 349 document.body.appendChild(testElement); |
| 349 }); | 350 }); |
| 350 | 351 |
| 351 teardown(function() { | 352 teardown(function() { |
| 352 closeActionMenu(); | 353 closeActionMenu(); |
| 353 // The code being tested changes the Route. Reset so that state is not | 354 // The code being tested changes the Route. Reset so that state is not |
| 354 // leaked across tests. | 355 // leaked across tests. |
| 355 settings.resetRouteForTesting(); | 356 settings.resetRouteForTesting(); |
| 356 }); | 357 }); |
| 357 | 358 |
| 358 /** | 359 /** |
| 359 * Fetch the non-hidden menu items from the action menu. | |
| 360 */ | |
| 361 function getMenuItems() { | |
| 362 var menu = testElement.$$('dialog[is=cr-action-menu]'); | |
| 363 assertTrue(!!menu); | |
| 364 return menu.querySelectorAll('button:not([hidden])'); | |
| 365 } | |
| 366 | |
| 367 /** | |
| 368 * Opens the action menu for a particular element in the list. | 360 * Opens the action menu for a particular element in the list. |
| 369 * @param {number} index The index of the child element (which site) to | 361 * @param {number} index The index of the child element (which site) to |
| 370 * open the action menu for. | 362 * open the action menu for. |
| 371 */ | 363 */ |
| 372 function openActionMenu(index) { | 364 function openActionMenu(index) { |
| 373 var item = testElement.$.listContainer.children[index]; | 365 var item = testElement.$.listContainer.children[index]; |
| 374 var dots = item.querySelector('paper-icon-button'); | 366 var dots = item.querySelector('paper-icon-button'); |
| 375 MockInteractions.tap(dots); | 367 MockInteractions.tap(dots); |
| 376 Polymer.dom.flush(); | 368 Polymer.dom.flush(); |
| 377 } | 369 } |
| 378 | 370 |
| 379 /** Closes the action menu. */ | 371 /** Closes the action menu. */ |
| 380 function closeActionMenu() { | 372 function closeActionMenu() { |
| 381 var menu = testElement.$$('dialog[is=cr-action-menu]'); | 373 var menu = testElement.$$('dialog[is=cr-action-menu]'); |
| 382 if (menu.open) | 374 if (menu.open) |
| 383 menu.close(); | 375 menu.close(); |
| 384 } | 376 } |
| 385 | 377 |
| 386 /** | 378 /** |
| 387 * Asserts the menu looks as expected. | 379 * Asserts the menu looks as expected. |
| 388 * @param {Array<string>} items The items expected to show in the menu. | 380 * @param {Array<string>} items The items expected to show in the menu. |
| 389 */ | 381 */ |
| 390 function assertMenu(items) { | 382 function assertMenu(items) { |
| 391 var menuItems = getMenuItems(); | 383 var menu = testElement.$$('dialog[is=cr-action-menu]'); |
| 384 assertTrue(!!menu); |
| 385 var menuItems = menu.querySelectorAll('button:not([hidden])'); |
| 392 assertEquals(items.length, menuItems.length); | 386 assertEquals(items.length, menuItems.length); |
| 393 for (var i = 0; i < items.length; i++) | 387 for (var i = 0; i < items.length; i++) |
| 394 assertEquals(items[i], menuItems[i].textContent.trim()); | 388 assertEquals(items[i], menuItems[i].textContent.trim()); |
| 395 } | 389 } |
| 396 | 390 |
| 397 /** | 391 /** |
| 398 * Configures the test element for a particular category. | 392 * Configures the test element for a particular category. |
| 399 * @param {settings.ContentSettingsTypes} category The category to set up. | 393 * @param {settings.ContentSettingsTypes} category The category to set up. |
| 400 * @param {settings.PermissionValues} subtype Type of list to use. | 394 * @param {settings.PermissionValues} subtype Type of list to use. |
| 401 * @param {Array<dictionary>} prefs The prefs to use. | 395 * @param {Array<dictionary>} prefs The prefs to use. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 prefsMixedProvider.exceptions.geolocation[0].origin, | 498 prefsMixedProvider.exceptions.geolocation[0].origin, |
| 505 testElement.sites[0].origin); | 499 testElement.sites[0].origin); |
| 506 assertEquals( | 500 assertEquals( |
| 507 prefsMixedProvider.exceptions.geolocation[0].source, | 501 prefsMixedProvider.exceptions.geolocation[0].source, |
| 508 testElement.sites[0].source); | 502 testElement.sites[0].source); |
| 509 } | 503 } |
| 510 }); | 504 }); |
| 511 }); | 505 }); |
| 512 | 506 |
| 513 test('initial BLOCK state is correct', function() { | 507 test('initial BLOCK state is correct', function() { |
| 514 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, | 508 var contentType = settings.ContentSettingsTypes.GEOLOCATION; |
| 515 settings.PermissionValues.BLOCK, prefs); | 509 var categorySubtype = settings.PermissionValues.BLOCK; |
| 510 setUpCategory(contentType, categorySubtype, prefs); |
| 516 return browserProxy.whenCalled('getExceptionList').then( | 511 return browserProxy.whenCalled('getExceptionList').then( |
| 517 function(contentType) { | 512 function(actualContentType) { |
| 518 assertEquals( | 513 assertEquals(contentType, actualContentType); |
| 519 settings.ContentSettingsTypes.GEOLOCATION, contentType); | 514 assertEquals(categorySubtype, testElement.categorySubtype); |
| 520 | 515 |
| 521 assertEquals(2, testElement.sites.length); | 516 assertEquals(2, testElement.sites.length); |
| 522 assertEquals(prefs.exceptions.geolocation[2].origin, | 517 assertEquals( |
| 518 prefs.exceptions.geolocation[2].origin, |
| 523 testElement.sites[0].origin); | 519 testElement.sites[0].origin); |
| 524 assertEquals(prefs.exceptions.geolocation[3].origin, | 520 assertEquals( |
| 521 prefs.exceptions.geolocation[3].origin, |
| 525 testElement.sites[1].origin); | 522 testElement.sites[1].origin); |
| 526 assertEquals( | |
| 527 settings.PermissionValues.BLOCK, testElement.categorySubtype); | |
| 528 Polymer.dom.flush(); // Populates action menu. | 523 Polymer.dom.flush(); // Populates action menu. |
| 529 openActionMenu(0); | 524 openActionMenu(0); |
| 530 assertMenu(['Allow', 'Remove'], testElement); | 525 assertMenu(['Allow', 'Remove'], testElement); |
| 531 | 526 |
| 532 assertFalse(testElement.$.category.hidden); | 527 assertFalse(testElement.$.category.hidden); |
| 533 }); | 528 }); |
| 534 }); | 529 }); |
| 535 | 530 |
| 536 test('initial SESSION ONLY state is correct', function() { | 531 test('initial SESSION ONLY state is correct', function() { |
| 537 setUpCategory(settings.ContentSettingsTypes.COOKIES, | 532 var contentType = settings.ContentSettingsTypes.COOKIES; |
| 538 settings.PermissionValues.SESSION_ONLY, prefsSessionOnly); | 533 var categorySubtype = settings.PermissionValues.SESSION_ONLY; |
| 534 setUpCategory(contentType, categorySubtype, prefsSessionOnly); |
| 539 return browserProxy.whenCalled('getExceptionList').then( | 535 return browserProxy.whenCalled('getExceptionList').then( |
| 540 function(contentType) { | 536 function(actualContentType) { |
| 541 assertEquals( | 537 assertEquals(contentType, actualContentType); |
| 542 settings.ContentSettingsTypes.COOKIES, contentType); | 538 assertEquals(categorySubtype, testElement.categorySubtype); |
| 543 | 539 |
| 544 assertEquals(1, testElement.sites.length); | 540 assertEquals(1, testElement.sites.length); |
| 545 assertEquals(prefsSessionOnly.exceptions.cookies[2].origin, | 541 assertEquals( |
| 542 prefsSessionOnly.exceptions.cookies[2].origin, |
| 546 testElement.sites[0].origin); | 543 testElement.sites[0].origin); |
| 547 | 544 |
| 548 assertEquals(settings.PermissionValues.SESSION_ONLY, | |
| 549 testElement.categorySubtype); | |
| 550 Polymer.dom.flush(); // Populates action menu. | 545 Polymer.dom.flush(); // Populates action menu. |
| 551 openActionMenu(0); | 546 openActionMenu(0); |
| 552 assertMenu(['Allow', 'Block', 'Remove'], testElement); | 547 assertMenu(['Allow', 'Block', 'Edit', 'Remove'], testElement); |
| 553 | 548 |
| 554 assertFalse(testElement.$.category.hidden); | 549 assertFalse(testElement.$.category.hidden); |
| 555 }); | 550 }); |
| 556 }); | 551 }); |
| 557 | 552 |
| 558 test('initial INCOGNITO BLOCK state is correct', function() { | 553 test('initial INCOGNITO BLOCK state is correct', function() { |
| 559 setUpCategory(settings.ContentSettingsTypes.COOKIES, | 554 var contentType = settings.ContentSettingsTypes.COOKIES; |
| 560 settings.PermissionValues.BLOCK, prefsIncognito); | 555 var categorySubtype = settings.PermissionValues.BLOCK; |
| 556 setUpCategory(contentType, categorySubtype, prefsIncognito); |
| 561 return browserProxy.whenCalled('getExceptionList').then( | 557 return browserProxy.whenCalled('getExceptionList').then( |
| 562 function(contentType) { | 558 function(actualContentType) { |
| 563 assertEquals(settings.ContentSettingsTypes.COOKIES, contentType); | 559 assertEquals(contentType, actualContentType); |
| 560 assertEquals(categorySubtype, testElement.categorySubtype); |
| 564 | 561 |
| 565 assertEquals(1, testElement.sites.length); | 562 assertEquals(1, testElement.sites.length); |
| 566 assertEquals(prefsIncognito.exceptions.cookies[0].origin, | 563 assertEquals( |
| 564 prefsIncognito.exceptions.cookies[0].origin, |
| 567 testElement.sites[0].origin); | 565 testElement.sites[0].origin); |
| 568 | 566 |
| 569 assertEquals(settings.PermissionValues.BLOCK, | |
| 570 testElement.categorySubtype); | |
| 571 Polymer.dom.flush(); // Populates action menu. | 567 Polymer.dom.flush(); // Populates action menu. |
| 572 openActionMenu(0); | 568 openActionMenu(0); |
| 573 // 'Clear on exit' is visible as this is not an incognito item. | 569 // 'Clear on exit' is visible as this is not an incognito item. |
| 574 assertMenu(['Allow', 'Clear on exit', 'Remove'], testElement); | 570 assertMenu( |
| 571 ['Allow', 'Clear on exit', 'Edit', 'Remove'], testElement); |
| 575 | 572 |
| 576 // Select 'Remove from menu'. | 573 // Select 'Remove' from menu. |
| 577 var menuItems = getMenuItems(); | 574 var remove = testElement.$.reset; |
| 578 assertTrue(!!menuItems); | 575 assertTrue(!!remove); |
| 579 MockInteractions.tap(menuItems[2]); | 576 MockInteractions.tap(remove); |
| 580 return browserProxy.whenCalled( | 577 return browserProxy.whenCalled( |
| 581 'resetCategoryPermissionForOrigin'); | 578 'resetCategoryPermissionForOrigin'); |
| 582 }).then(function(args) { | 579 }).then(function(args) { |
| 583 assertEquals('http://foo.com', args[0]); | 580 assertEquals('http://foo.com', args[0]); |
| 584 assertEquals('http://foo.com', args[1]); | 581 assertEquals('http://foo.com', args[1]); |
| 585 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); | 582 assertEquals(contentType, args[2]); |
| 586 assertFalse(args[3]); // Incognito. | 583 assertFalse(args[3]); // Incognito. |
| 587 }); | 584 }); |
| 588 }); | 585 }); |
| 589 | 586 |
| 590 test('initial INCOGNITO ALLOW state is correct', function() { | 587 test('initial INCOGNITO ALLOW state is correct', function() { |
| 591 setUpCategory(settings.ContentSettingsTypes.COOKIES, | 588 var contentType = settings.ContentSettingsTypes.COOKIES; |
| 592 settings.PermissionValues.ALLOW, prefsIncognito); | 589 var categorySubtype = settings.PermissionValues.ALLOW; |
| 590 setUpCategory(contentType, categorySubtype, prefsIncognito); |
| 593 return browserProxy.whenCalled('getExceptionList').then( | 591 return browserProxy.whenCalled('getExceptionList').then( |
| 594 function(contentType) { | 592 function(actualContentType) { |
| 595 assertEquals( | 593 assertEquals(contentType, actualContentType); |
| 596 settings.ContentSettingsTypes.COOKIES, contentType); | 594 assertEquals(categorySubtype, testElement.categorySubtype); |
| 597 | 595 |
| 598 assertEquals(2, testElement.sites.length); | 596 assertEquals(2, testElement.sites.length); |
| 599 assertEquals(prefsIncognito.exceptions.cookies[1].origin, | 597 assertEquals( |
| 598 prefsIncognito.exceptions.cookies[1].origin, |
| 600 testElement.sites[0].origin); | 599 testElement.sites[0].origin); |
| 601 assertEquals(prefsIncognito.exceptions.cookies[2].origin, | 600 assertEquals( |
| 601 prefsIncognito.exceptions.cookies[2].origin, |
| 602 testElement.sites[1].origin); | 602 testElement.sites[1].origin); |
| 603 | 603 |
| 604 assertEquals(settings.PermissionValues.ALLOW, | |
| 605 testElement.categorySubtype); | |
| 606 Polymer.dom.flush(); // Populates action menu. | 604 Polymer.dom.flush(); // Populates action menu. |
| 607 openActionMenu(0); | 605 openActionMenu(0); |
| 608 // 'Clear on exit' is hidden for incognito items. | 606 // 'Clear on exit' is hidden for incognito items. |
| 609 assertMenu(['Block', 'Remove'], testElement); | 607 assertMenu(['Block', 'Edit', 'Remove'], testElement); |
| 610 closeActionMenu(); | 608 closeActionMenu(); |
| 611 | 609 |
| 612 // Select 'Remove' from menu on 'foo.com'. | 610 // Select 'Remove' from menu on 'foo.com'. |
| 613 openActionMenu(1); | 611 openActionMenu(1); |
| 614 var menuItems = getMenuItems(); | 612 var remove = testElement.$.reset; |
| 615 assertTrue(!!menuItems); | 613 assertTrue(!!remove); |
| 616 MockInteractions.tap(menuItems[1]); | 614 MockInteractions.tap(remove); |
| 617 return browserProxy.whenCalled( | 615 return browserProxy.whenCalled( |
| 618 'resetCategoryPermissionForOrigin'); | 616 'resetCategoryPermissionForOrigin'); |
| 619 }).then(function(args) { | 617 }).then(function(args) { |
| 620 assertEquals('http://foo.com', args[0]); | 618 assertEquals('http://foo.com', args[0]); |
| 621 assertEquals('http://foo.com', args[1]); | 619 assertEquals('http://foo.com', args[1]); |
| 622 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); | 620 assertEquals(contentType, args[2]); |
| 623 assertTrue(args[3]); // Incognito. | 621 assertTrue(args[3]); // Incognito. |
| 624 }); | 622 }); |
| 625 }); | 623 }); |
| 626 | 624 |
| 625 test('edit action menu opens edit exception dialog', function() { |
| 626 setUpCategory( |
| 627 settings.ContentSettingsTypes.COOKIES, |
| 628 settings.PermissionValues.SESSION_ONLY, |
| 629 prefsSessionOnly); |
| 630 |
| 631 return browserProxy.whenCalled('getExceptionList').then(function() { |
| 632 Polymer.dom.flush(); // Populates action menu. |
| 633 |
| 634 openActionMenu(0); |
| 635 assertMenu(['Allow', 'Block', 'Edit', 'Remove'], testElement); |
| 636 var edit = testElement.$.edit; |
| 637 assertTrue(!!edit); |
| 638 MockInteractions.tap(edit); |
| 639 Polymer.dom.flush(); |
| 640 |
| 641 assertTrue(!!testElement.$$('settings-edit-exception-dialog')); |
| 642 }); |
| 643 }); |
| 644 |
| 627 test('list items shown and clickable when data is present', function() { | 645 test('list items shown and clickable when data is present', function() { |
| 628 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, | 646 var contentType = settings.ContentSettingsTypes.GEOLOCATION; |
| 629 settings.PermissionValues.ALLOW, prefs); | 647 setUpCategory(contentType, settings.PermissionValues.ALLOW, prefs); |
| 630 return browserProxy.whenCalled('getExceptionList').then( | 648 return browserProxy.whenCalled('getExceptionList').then( |
| 631 function(contentType) { | 649 function(actualContentType) { |
| 632 testElement.enableSiteSettings_ = true; | 650 testElement.enableSiteSettings_ = true; |
| 633 assertEquals( | 651 assertEquals(contentType, actualContentType); |
| 634 settings.ContentSettingsTypes.GEOLOCATION, contentType); | |
| 635 | 652 |
| 636 // Required for firstItem to be found below. | 653 // Required for firstItem to be found below. |
| 637 Polymer.dom.flush(); | 654 Polymer.dom.flush(); |
| 638 | 655 |
| 639 // Validate that the sites gets populated from pre-canned prefs. | 656 // Validate that the sites gets populated from pre-canned prefs. |
| 640 assertEquals(2, testElement.sites.length); | 657 assertEquals(2, testElement.sites.length); |
| 641 assertEquals(prefs.exceptions.geolocation[0].origin, | 658 assertEquals( |
| 659 prefs.exceptions.geolocation[0].origin, |
| 642 testElement.sites[0].origin); | 660 testElement.sites[0].origin); |
| 643 assertEquals(prefs.exceptions.geolocation[1].origin, | 661 assertEquals( |
| 662 prefs.exceptions.geolocation[1].origin, |
| 644 testElement.sites[1].origin); | 663 testElement.sites[1].origin); |
| 645 assertEquals(undefined, testElement.selectedOrigin); | 664 assertFalse(!!testElement.selectedOrigin); |
| 646 | 665 |
| 647 // Validate that the sites are shown in UI and can be selected. | 666 // Validate that the sites are shown in UI and can be selected. |
| 648 var firstItem = testElement.$.listContainer.children[0]; | 667 var firstItem = testElement.$.listContainer.children[0]; |
| 649 var clickable = firstItem.querySelector('.middle'); | 668 var clickable = firstItem.querySelector('.middle'); |
| 650 assertNotEquals(undefined, clickable); | 669 assertTrue(!!clickable); |
| 651 MockInteractions.tap(clickable); | 670 MockInteractions.tap(clickable); |
| 652 assertEquals(prefs.exceptions.geolocation[0].origin, | 671 assertEquals( |
| 672 prefs.exceptions.geolocation[0].origin, |
| 653 settings.getQueryParameters().get('site')); | 673 settings.getQueryParameters().get('site')); |
| 654 }); | 674 }); |
| 655 }); | 675 }); |
| 656 | 676 |
| 657 test('Block list open when Allow list is empty', function() { | 677 test('Block list open when Allow list is empty', function() { |
| 658 // Prefs: One item in Block list, nothing in Allow list. | 678 // Prefs: One item in Block list, nothing in Allow list. |
| 659 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, | 679 var contentType = settings.ContentSettingsTypes.GEOLOCATION; |
| 660 settings.PermissionValues.BLOCK, prefsOneDisabled); | 680 setUpCategory( |
| 681 contentType, settings.PermissionValues.BLOCK, prefsOneDisabled); |
| 661 return browserProxy.whenCalled('getExceptionList').then( | 682 return browserProxy.whenCalled('getExceptionList').then( |
| 662 function(contentType) { | 683 function(actualContentType) { |
| 663 assertEquals( | 684 assertEquals(contentType, actualContentType); |
| 664 settings.ContentSettingsTypes.GEOLOCATION, contentType); | |
| 665 assertFalse(testElement.$.category.hidden); | 685 assertFalse(testElement.$.category.hidden); |
| 666 }).then(function() { | 686 }).then(function() { |
| 667 assertNotEquals(0, testElement.$.listContainer.offsetHeight); | 687 assertNotEquals(0, testElement.$.listContainer.offsetHeight); |
| 668 }); | 688 }); |
| 669 }); | 689 }); |
| 670 | 690 |
| 671 test('Block list closed when Allow list is not empty', function() { | 691 test('Block list closed when Allow list is not empty', function() { |
| 672 // Prefs: Items in both Block and Allow list. | 692 // Prefs: Items in both Block and Allow list. |
| 673 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, | 693 var contentType = settings.ContentSettingsTypes.GEOLOCATION; |
| 674 settings.PermissionValues.BLOCK, prefs); | 694 setUpCategory(contentType, settings.PermissionValues.BLOCK, prefs); |
| 675 return browserProxy.whenCalled('getExceptionList').then( | 695 return browserProxy.whenCalled('getExceptionList').then( |
| 676 function(contentType) { | 696 function(actualContentType) { |
| 677 assertEquals( | 697 assertEquals(contentType, actualContentType); |
| 678 settings.ContentSettingsTypes.GEOLOCATION, contentType); | |
| 679 assertFalse(testElement.$.category.hidden); | 698 assertFalse(testElement.$.category.hidden); |
| 680 assertEquals(0, testElement.$.listContainer.offsetHeight); | 699 assertEquals(0, testElement.$.listContainer.offsetHeight); |
| 681 }); | 700 }); |
| 682 }); | 701 }); |
| 683 | 702 |
| 684 test('Allow list is always open (Block list empty)', function() { | 703 test('Allow list is always open (Block list empty)', function() { |
| 685 // Prefs: One item in Allow list, nothing in Block list. | 704 // Prefs: One item in Allow list, nothing in Block list. |
| 686 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, | 705 var contentType = settings.ContentSettingsTypes.GEOLOCATION; |
| 687 settings.PermissionValues.ALLOW, prefsOneEnabled); | 706 setUpCategory( |
| 707 contentType, settings.PermissionValues.ALLOW, prefsOneEnabled); |
| 688 return browserProxy.whenCalled('getExceptionList').then( | 708 return browserProxy.whenCalled('getExceptionList').then( |
| 689 function(contentType) { | 709 function(actualContentType) { |
| 690 assertEquals( | 710 assertEquals(contentType, actualContentType); |
| 691 settings.ContentSettingsTypes.GEOLOCATION, contentType); | |
| 692 | |
| 693 assertFalse(testElement.$.category.hidden); | 711 assertFalse(testElement.$.category.hidden); |
| 694 }).then(function() { | 712 }).then(function() { |
| 695 assertNotEquals(0, testElement.$.listContainer.offsetHeight); | 713 assertNotEquals(0, testElement.$.listContainer.offsetHeight); |
| 696 }); | 714 }); |
| 697 }); | 715 }); |
| 698 | 716 |
| 699 test('Allow list is always open (Block list non-empty)', function() { | 717 test('Allow list is always open (Block list non-empty)', function() { |
| 700 // Prefs: Items in both Block and Allow list. | 718 // Prefs: Items in both Block and Allow list. |
| 701 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, | 719 var contentType = settings.ContentSettingsTypes.GEOLOCATION; |
| 702 settings.PermissionValues.ALLOW, prefs); | 720 setUpCategory(contentType, settings.PermissionValues.ALLOW, prefs); |
| 703 return browserProxy.whenCalled('getExceptionList').then( | 721 return browserProxy.whenCalled('getExceptionList').then( |
| 704 function(contentType) { | 722 function(actualContentType) { |
| 705 assertEquals( | 723 assertEquals(contentType, actualContentType); |
| 706 settings.ContentSettingsTypes.GEOLOCATION, contentType); | |
| 707 assertFalse(testElement.$.category.hidden); | 724 assertFalse(testElement.$.category.hidden); |
| 708 }).then(function() { | 725 }).then(function() { |
| 709 assertNotEquals(0, testElement.$.listContainer.offsetHeight); | 726 assertNotEquals(0, testElement.$.listContainer.offsetHeight); |
| 710 }); | 727 }); |
| 711 }); | 728 }); |
| 712 | 729 |
| 713 test('Block list not hidden when empty', function() { | 730 test('Block list not hidden when empty', function() { |
| 714 // Prefs: One item in Allow list, nothing in Block list. | 731 // Prefs: One item in Allow list, nothing in Block list. |
| 715 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, | 732 var contentType = settings.ContentSettingsTypes.GEOLOCATION; |
| 716 settings.PermissionValues.BLOCK, prefsOneEnabled); | 733 setUpCategory( |
| 734 contentType, settings.PermissionValues.BLOCK, prefsOneEnabled); |
| 717 return browserProxy.whenCalled('getExceptionList').then( | 735 return browserProxy.whenCalled('getExceptionList').then( |
| 718 function(contentType) { | 736 function(actualContentType) { |
| 719 assertEquals( | 737 assertEquals(contentType, actualContentType); |
| 720 settings.ContentSettingsTypes.GEOLOCATION, contentType); | |
| 721 assertFalse(testElement.$.category.hidden); | 738 assertFalse(testElement.$.category.hidden); |
| 722 }); | 739 }); |
| 723 }); | 740 }); |
| 724 | 741 |
| 725 test('Allow list not hidden when empty', function() { | 742 test('Allow list not hidden when empty', function() { |
| 726 // Prefs: One item in Block list, nothing in Allow list. | 743 // Prefs: One item in Block list, nothing in Allow list. |
| 727 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, | 744 var contentType = settings.ContentSettingsTypes.GEOLOCATION; |
| 728 settings.PermissionValues.ALLOW, prefsOneDisabled); | 745 setUpCategory( |
| 746 contentType, settings.PermissionValues.ALLOW, prefsOneDisabled); |
| 729 return browserProxy.whenCalled('getExceptionList').then( | 747 return browserProxy.whenCalled('getExceptionList').then( |
| 730 function(contentType) { | 748 function(actualContentType) { |
| 731 assertEquals( | 749 assertEquals(contentType, actualContentType); |
| 732 settings.ContentSettingsTypes.GEOLOCATION, contentType); | |
| 733 assertFalse(testElement.$.category.hidden); | 750 assertFalse(testElement.$.category.hidden); |
| 734 }); | 751 }); |
| 735 }); | 752 }); |
| 736 | 753 |
| 737 test('All sites category no action menu', function() { | 754 test('All sites category no action menu', function() { |
| 738 setUpCategory(settings.ALL_SITES, '', prefsVarious); | 755 setUpCategory(settings.ALL_SITES, '', prefsVarious); |
| 739 return browserProxy.whenCalled('getExceptionList').then( | 756 return browserProxy.whenCalled('getExceptionList').then( |
| 740 function(contentType) { | 757 function(contentType) { |
| 741 // Use resolver to ensure that the list container is populated. | 758 // Use resolver to ensure that the list container is populated. |
| 742 var resolver = new PromiseResolver(); | 759 var resolver = new PromiseResolver(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 }); | 875 }); |
| 859 | 876 |
| 860 test('Select menu item', function() { | 877 test('Select menu item', function() { |
| 861 // Test for error: "Cannot read property 'origin' of undefined". | 878 // Test for error: "Cannot read property 'origin' of undefined". |
| 862 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, | 879 setUpCategory(settings.ContentSettingsTypes.GEOLOCATION, |
| 863 settings.PermissionValues.ALLOW, prefs); | 880 settings.PermissionValues.ALLOW, prefs); |
| 864 return browserProxy.whenCalled('getExceptionList').then(function( | 881 return browserProxy.whenCalled('getExceptionList').then(function( |
| 865 contentType) { | 882 contentType) { |
| 866 Polymer.dom.flush(); | 883 Polymer.dom.flush(); |
| 867 openActionMenu(0); | 884 openActionMenu(0); |
| 868 var menuItems = getMenuItems(); | 885 var allow = testElement.$.allow; |
| 869 assertTrue(!!menuItems); | 886 assertTrue(!!allow); |
| 870 MockInteractions.tap(menuItems[0]); | 887 MockInteractions.tap(allow); |
| 871 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); | 888 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); |
| 872 }); | 889 }); |
| 873 }); | 890 }); |
| 874 | 891 |
| 875 test('Chrome Extension scheme', function() { | 892 test('Chrome Extension scheme', function() { |
| 876 setUpCategory(settings.ContentSettingsTypes.JAVASCRIPT, | 893 setUpCategory(settings.ContentSettingsTypes.JAVASCRIPT, |
| 877 settings.PermissionValues.BLOCK, prefsChromeExtension); | 894 settings.PermissionValues.BLOCK, prefsChromeExtension); |
| 878 return browserProxy.whenCalled('getExceptionList').then(function( | 895 return browserProxy.whenCalled('getExceptionList').then(function( |
| 879 contentType) { | 896 contentType) { |
| 880 Polymer.dom.flush(); | 897 Polymer.dom.flush(); |
| 881 openActionMenu(0); | 898 openActionMenu(0); |
| 882 assertMenu(['Allow', 'Remove'], testElement); | 899 assertMenu(['Allow', 'Remove'], testElement); |
| 883 | 900 |
| 884 var menuItems = getMenuItems(); | 901 var allow = testElement.$.allow; |
| 885 assertTrue(!!menuItems); | 902 assertTrue(!!allow); |
| 886 MockInteractions.tap(menuItems[0]); // Action: Allow. | 903 MockInteractions.tap(allow); |
| 887 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); | 904 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); |
| 888 }).then(function(args) { | 905 }).then(function(args) { |
| 889 assertEquals('chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', | 906 assertEquals('chrome-extension://cfhgfbfpcbnnbibfphagcjmgjfjmojfa/', |
| 890 args[0]); | 907 args[0]); |
| 891 assertEquals('', args[1]); | 908 assertEquals('', args[1]); |
| 892 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); | 909 assertEquals(settings.ContentSettingsTypes.JAVASCRIPT, args[2]); |
| 893 assertEquals('allow', args[3]); | 910 assertEquals('allow', args[3]); |
| 894 }); | 911 }); |
| 895 }); | 912 }); |
| 896 }); | 913 }); |
| 897 } | 914 } |
| 915 |
| 916 suite('EditExceptionDialog', function() { |
| 917 var dialog; |
| 918 var cookieException = prefsIncognito.exceptions.cookies[0]; |
| 919 |
| 920 setup(function() { |
| 921 browserProxy = new TestSiteSettingsPrefsBrowserProxy(); |
| 922 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; |
| 923 PolymerTest.clearBody(); |
| 924 dialog = document.createElement('settings-edit-exception-dialog'); |
| 925 dialog.model = cookieException; |
| 926 document.body.appendChild(dialog); |
| 927 }); |
| 928 |
| 929 teardown(function() { |
| 930 dialog.remove(); |
| 931 }); |
| 932 |
| 933 test('action button disabled on invalid input', function() { |
| 934 var input = dialog.$$('paper-input'); |
| 935 assertTrue(!!input); |
| 936 var actionButton = dialog.$.actionButton; |
| 937 assertTrue(!!actionButton); |
| 938 assertFalse(actionButton.disabled); |
| 939 |
| 940 browserProxy.setIsPatternValid(false); |
| 941 var expectedPattern = 'foobarbaz'; |
| 942 // Simulate user input. |
| 943 input.value = expectedPattern; |
| 944 input.fire('input'); |
| 945 |
| 946 return browserProxy.whenCalled('isPatternValid').then(function(pattern) { |
| 947 assertEquals(expectedPattern, pattern); |
| 948 assertTrue(actionButton.disabled); |
| 949 }); |
| 950 }); |
| 951 |
| 952 test('action button calls proxy', function() { |
| 953 var input = dialog.$$('paper-input'); |
| 954 assertTrue(!!input); |
| 955 // Simulate user edit. |
| 956 var newValue = input.value + ':1234'; |
| 957 input.value = newValue; |
| 958 |
| 959 var actionButton = dialog.$.actionButton; |
| 960 assertTrue(!!actionButton); |
| 961 assertFalse(actionButton.disabled); |
| 962 |
| 963 MockInteractions.tap(actionButton); |
| 964 |
| 965 return browserProxy.whenCalled('resetCategoryPermissionForOrigin').then( |
| 966 function(args) { |
| 967 assertEquals(cookieException.origin, args[0]); |
| 968 assertEquals(cookieException.embeddingOrigin, args[1]); |
| 969 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); |
| 970 assertEquals(cookieException.incognito, args[3]); |
| 971 |
| 972 return browserProxy.whenCalled('setCategoryPermissionForOrigin'); |
| 973 }).then(function(args) { |
| 974 assertEquals(newValue, args[0]); |
| 975 assertEquals(newValue, args[1]); |
| 976 assertEquals(settings.ContentSettingsTypes.COOKIES, args[2]); |
| 977 assertEquals(cookieException.setting, args[3]); |
| 978 assertEquals(cookieException.incognito, args[4]); |
| 979 |
| 980 assertFalse(dialog.$.dialog.open); |
| 981 }); |
| 982 }); |
| 983 }); |
| 984 |
| 898 return { | 985 return { |
| 899 registerTests: registerTests, | 986 registerTests: registerTests, |
| 900 }; | 987 }; |
| 901 }); | 988 }); |
| OLD | NEW |