browser_sync_settings_ui.js (9689B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 let { UIState } = ChromeUtils.importESModule( 7 "resource://services-sync/UIState.sys.mjs" 8 ); 9 10 add_setup(async function () { 11 await SpecialPowers.pushPrefEnv({ 12 set: [["browser.settings-redesign.enabled", true]], 13 }); 14 }); 15 16 async function runSyncTest(uiStateData, testCallback) { 17 const oldUIState = UIState.get; 18 UIState.get = () => uiStateData; 19 20 await openPreferencesViaOpenPreferencesAPI("paneSync", { 21 leaveOpen: true, 22 }); 23 let doc = gBrowser.contentDocument; 24 25 try { 26 await testCallback(doc); 27 } finally { 28 UIState.get = oldUIState; 29 BrowserTestUtils.removeTab(gBrowser.selectedTab); 30 } 31 } 32 33 add_task(async function testSyncNoFxaSignIn() { 34 await runSyncTest( 35 { 36 status: UIState.STATUS_NOT_CONFIGURED, 37 email: "foo@bar.com", 38 }, 39 async doc => { 40 let syncSettingGroup = doc.querySelector('setting-group[groupid="sync"]'); 41 ok( 42 !BrowserTestUtils.isHidden(syncSettingGroup), 43 "Sync setting group is displayed." 44 ); 45 46 let syncNoFxaSignIn = syncSettingGroup.querySelector("#noFxaSignIn"); 47 ok( 48 !BrowserTestUtils.isHidden(syncNoFxaSignIn), 49 "Link to sign in is displayed when status is not confirmed." 50 ); 51 52 let syncConfigured = syncSettingGroup.querySelector("#syncConfigured"); 53 let syncNotConfigured = 54 syncSettingGroup.querySelector("#syncNotConfigured"); 55 let fxaDeviceNameSection = syncSettingGroup.querySelector( 56 "#fxaDeviceNameSection" 57 ); 58 ok( 59 BrowserTestUtils.isHidden(syncConfigured) && 60 BrowserTestUtils.isHidden(syncNotConfigured) && 61 BrowserTestUtils.isHidden(fxaDeviceNameSection), 62 "All other sync sections are hidden." 63 ); 64 } 65 ); 66 }); 67 68 add_task(async function testSyncFxaNotVerified() { 69 await runSyncTest( 70 { 71 status: UIState.STATUS_NOT_VERIFIED, 72 email: "foo@bar.com", 73 }, 74 async doc => { 75 let syncSettingGroup = doc.querySelector('setting-group[groupid="sync"]'); 76 ok( 77 !BrowserTestUtils.isHidden(syncSettingGroup), 78 "Sync setting group is displayed." 79 ); 80 81 let fxaDeviceNameSection = syncSettingGroup.querySelector( 82 "#fxaDeviceNameSection" 83 ); 84 ok( 85 !BrowserTestUtils.isHidden(fxaDeviceNameSection), 86 "Device name section is displayed when status is not confirmed." 87 ); 88 89 let fxaDeviceName = fxaDeviceNameSection.querySelector("#fxaDeviceName"); 90 ok( 91 fxaDeviceName.disabled, 92 "Change device name is disabled when status is not confirmed." 93 ); 94 95 let syncNoFxaSignIn = syncSettingGroup.querySelector("#noFxaSignIn"); 96 let syncConfigured = syncSettingGroup.querySelector("#syncConfigured"); 97 let syncNotConfigured = 98 syncSettingGroup.querySelector("#syncNotConfigured"); 99 ok( 100 BrowserTestUtils.isHidden(syncConfigured) && 101 BrowserTestUtils.isHidden(syncNotConfigured) && 102 BrowserTestUtils.isHidden(syncNoFxaSignIn), 103 "All other sync sections are hidden." 104 ); 105 } 106 ); 107 }); 108 109 add_task(async function testSyncFxaLoginFailed() { 110 await runSyncTest( 111 { 112 status: UIState.STATUS_LOGIN_FAILED, 113 email: "foo@bar.com", 114 }, 115 async doc => { 116 let syncSettingGroup = doc.querySelector('setting-group[groupid="sync"]'); 117 ok( 118 !BrowserTestUtils.isHidden(syncSettingGroup), 119 "Sync setting group is displayed." 120 ); 121 122 let fxaDeviceNameSection = syncSettingGroup.querySelector( 123 "#fxaDeviceNameSection" 124 ); 125 ok( 126 !BrowserTestUtils.isHidden(fxaDeviceNameSection), 127 "Device name section is displayed when login failed." 128 ); 129 130 let fxaDeviceName = fxaDeviceNameSection.querySelector("#fxaDeviceName"); 131 ok( 132 fxaDeviceName.disabled, 133 "Change device name is disabled when login failed." 134 ); 135 136 let syncNoFxaSignIn = syncSettingGroup.querySelector("#noFxaSignIn"); 137 let syncConfigured = syncSettingGroup.querySelector("#syncConfigured"); 138 let syncNotConfigured = 139 syncSettingGroup.querySelector("#syncNotConfigured"); 140 ok( 141 BrowserTestUtils.isHidden(syncConfigured) && 142 BrowserTestUtils.isHidden(syncNotConfigured) && 143 BrowserTestUtils.isHidden(syncNoFxaSignIn), 144 "All other sync sections are hidden." 145 ); 146 } 147 ); 148 }); 149 150 add_task(async function testSyncFxaSignedInSyncingOff() { 151 await runSyncTest( 152 { 153 status: UIState.STATUS_SIGNED_IN, 154 email: "foo@bar.com", 155 syncEnabled: false, 156 }, 157 async doc => { 158 let syncSettingGroup = doc.querySelector('setting-group[groupid="sync"]'); 159 ok( 160 !BrowserTestUtils.isHidden(syncSettingGroup), 161 "Sync setting group is displayed." 162 ); 163 164 let fxaDeviceNameSection = syncSettingGroup.querySelector( 165 "#fxaDeviceNameSection" 166 ); 167 ok( 168 !BrowserTestUtils.isHidden(fxaDeviceNameSection), 169 "Device name section is displayed when user is signed in." 170 ); 171 172 let fxaDeviceName = fxaDeviceNameSection.querySelector("#fxaDeviceName"); 173 ok( 174 !fxaDeviceName.disabled, 175 "Change device name is enabled when user is signed in." 176 ); 177 178 let syncNotConfigured = 179 syncSettingGroup.querySelector("#syncNotConfigured"); 180 ok( 181 !BrowserTestUtils.isHidden(syncNotConfigured), 182 "Syncing is off section is displayed when user is signed in but sync is disabled." 183 ); 184 185 let syncNoFxaSignIn = syncSettingGroup.querySelector("#noFxaSignIn"); 186 let syncConfigured = syncSettingGroup.querySelector("#syncConfigured"); 187 ok( 188 BrowserTestUtils.isHidden(syncConfigured) && 189 BrowserTestUtils.isHidden(syncNoFxaSignIn), 190 "All other sync sections are hidden." 191 ); 192 } 193 ); 194 }); 195 196 add_task(async function testSyncFxaSignedInSyncingOn() { 197 await SpecialPowers.pushPrefEnv({ 198 set: [ 199 ["services.sync.engine.bookmarks", true], 200 ["services.sync.engine.history", true], 201 ["services.sync.engine.tabs", true], 202 ["services.sync.engine.addons", true], 203 ["services.sync.engine.prefs", true], 204 ["services.sync.engine.passwords", true], 205 ["services.sync.engine.addresses", true], 206 ["services.sync.engine.creditcards", true], 207 ], 208 }); 209 210 await runSyncTest( 211 { 212 status: UIState.STATUS_SIGNED_IN, 213 email: "foo@bar.com", 214 syncEnabled: true, 215 }, 216 async doc => { 217 let syncSettingGroup = doc.querySelector('setting-group[groupid="sync"]'); 218 ok( 219 !BrowserTestUtils.isHidden(syncSettingGroup), 220 "Sync setting group is displayed." 221 ); 222 223 let fxaDeviceNameSection = syncSettingGroup.querySelector( 224 "#fxaDeviceNameSection" 225 ); 226 ok( 227 !BrowserTestUtils.isHidden(fxaDeviceNameSection), 228 "Device name section is displayed when user is signed in." 229 ); 230 231 let fxaDeviceName = fxaDeviceNameSection.querySelector("#fxaDeviceName"); 232 ok( 233 !fxaDeviceName.disabled, 234 "Change device name is enabled when user is signed in." 235 ); 236 237 let syncConfigured = syncSettingGroup.querySelector("#syncConfigured"); 238 ok( 239 !BrowserTestUtils.isHidden(syncConfigured), 240 "Syncing is on section is displayed when user is signed in and sync is enabled." 241 ); 242 243 let syncEnginesList = syncConfigured.querySelector("sync-engines-list"); 244 ok(syncEnginesList, "sync-engines-list component is displayed."); 245 246 let engines = syncEnginesList.shadowRoot.querySelector( 247 ".engines-list-wrapper" 248 ); 249 ok( 250 engines, 251 "The list of synced engines is displayed when syncing is on." 252 ); 253 254 let syncNoFxaSignIn = syncSettingGroup.querySelector("#noFxaSignIn"); 255 let syncNotConfigured = 256 syncSettingGroup.querySelector("#syncNotConfigured"); 257 ok( 258 BrowserTestUtils.isHidden(syncNotConfigured) && 259 BrowserTestUtils.isHidden(syncNoFxaSignIn), 260 "All other sync sections are hidden." 261 ); 262 } 263 ); 264 }); 265 266 add_task(async function testSyncedEnginesEmptyState() { 267 await SpecialPowers.pushPrefEnv({ 268 set: [ 269 ["services.sync.engine.bookmarks", false], 270 ["services.sync.engine.history", false], 271 ["services.sync.engine.tabs", false], 272 ["services.sync.engine.addons", false], 273 ["services.sync.engine.prefs", false], 274 ["services.sync.engine.passwords", false], 275 ["services.sync.engine.addresses", false], 276 ["services.sync.engine.creditcards", false], 277 ], 278 }); 279 280 await runSyncTest( 281 { 282 status: UIState.STATUS_SIGNED_IN, 283 email: "foo@bar.com", 284 syncEnabled: true, 285 }, 286 async doc => { 287 let syncSettingGroup = doc.querySelector('setting-group[groupid="sync"]'); 288 ok( 289 !BrowserTestUtils.isHidden(syncSettingGroup), 290 "Sync setting group is displayed." 291 ); 292 293 let syncConfigured = syncSettingGroup.querySelector("#syncConfigured"); 294 ok( 295 !BrowserTestUtils.isHidden(syncConfigured), 296 "Syncing is on section is displayed when user is signed in and sync is enabled." 297 ); 298 299 let syncEnginesList = syncConfigured.querySelector("sync-engines-list"); 300 ok(syncEnginesList, "sync-engines-list component is displayed."); 301 302 let engineListEmptyState = syncEnginesList.shadowRoot.querySelector( 303 "placeholder-message" 304 ); 305 ok( 306 engineListEmptyState, 307 "Empty state message is displayed when syncing is on but non of the engines is synced." 308 ); 309 } 310 ); 311 });