How to use updateDevice method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

test_accounts_device_registration.js

Source:test_accounts_device_registration.js Github

copy

Full Screen

1/* Any copyright is dedicated to the Public Domain.2 * http://creativecommons.org/publicdomain/zero/1.0/ */3"use strict";4const { FxAccounts } = ChromeUtils.import(5 "resource://gre/modules/FxAccounts.jsm"6);7const { FxAccountsClient } = ChromeUtils.import(8 "resource://gre/modules/FxAccountsClient.jsm"9);10const { FxAccountsDevice } = ChromeUtils.import(11 "resource://gre/modules/FxAccountsDevice.jsm"12);13const {14 ERRNO_DEVICE_SESSION_CONFLICT,15 ERRNO_TOO_MANY_CLIENT_REQUESTS,16 ERRNO_UNKNOWN_DEVICE,17 ON_DEVICE_CONNECTED_NOTIFICATION,18 ON_DEVICE_DISCONNECTED_NOTIFICATION,19} = ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js");20var { AccountState } = ChromeUtils.import(21 "resource://gre/modules/FxAccounts.jsm",22 null23);24initTestLogging("Trace");25var log = Log.repository.getLogger("Services.FxAccounts.test");26log.level = Log.Level.Debug;27const BOGUS_PUBLICKEY =28 "BBXOKjUb84pzws1wionFpfCBjDuCh4-s_1b52WA46K5wYL2gCWEOmFKWn_NkS5nmJwTBuO8qxxdjAIDtNeklvQc";29const BOGUS_AUTHKEY = "GSsIiaD2Mr83iPqwFNK4rw";30Services.prefs.setCharPref("identity.fxaccounts.loglevel", "Trace");31const DEVICE_REGISTRATION_VERSION = 42;32function MockStorageManager() {}33MockStorageManager.prototype = {34 initialize(accountData) {35 this.accountData = accountData;36 },37 finalize() {38 return Promise.resolve();39 },40 getAccountData() {41 return Promise.resolve(this.accountData);42 },43 updateAccountData(updatedFields) {44 for (let [name, value] of Object.entries(updatedFields)) {45 if (value == null) {46 delete this.accountData[name];47 } else {48 this.accountData[name] = value;49 }50 }51 return Promise.resolve();52 },53 deleteAccountData() {54 this.accountData = null;55 return Promise.resolve();56 },57};58function MockFxAccountsClient(device) {59 this._email = "nobody@example.com";60 // Be careful relying on `this._verified` as it doesn't change if the user's61 // state does via setting the `verified` flag in the user data.62 this._verified = false;63 this._deletedOnServer = false; // for testing accountStatus64 // mock calls up to the auth server to determine whether the65 // user account has been verified66 this.recoveryEmailStatus = function(sessionToken) {67 // simulate a call to /recovery_email/status68 return Promise.resolve({69 email: this._email,70 verified: this._verified,71 });72 };73 this.accountKeys = function(keyFetchToken) {74 Assert.ok(keyFetchToken, "must be called with a key-fetch-token");75 // ideally we'd check the verification status here to more closely simulate76 // the server, but `this._verified` is a test-only construct and doesn't77 // update when the user changes verification status.78 Assert.ok(!this._deletedOnServer, "this test thinks the acct is deleted!");79 return {80 kA: "test-ka",81 wrapKB: "X".repeat(32),82 };83 };84 this.accountStatus = function(uid) {85 return Promise.resolve(!!uid && !this._deletedOnServer);86 };87 const {88 id: deviceId,89 name: deviceName,90 type: deviceType,91 sessionToken,92 } = device;93 this.registerDevice = (st, name, type) =>94 Promise.resolve({ id: deviceId, name });95 this.updateDevice = (st, id, name) => Promise.resolve({ id, name });96 this.signOut = () => Promise.resolve({});97 this.getDeviceList = st =>98 Promise.resolve([99 {100 id: deviceId,101 name: deviceName,102 type: deviceType,103 isCurrentDevice: st === sessionToken,104 },105 ]);106 FxAccountsClient.apply(this);107}108MockFxAccountsClient.prototype = {109 __proto__: FxAccountsClient.prototype,110};111async function MockFxAccounts(credentials, device = {}) {112 let fxa = new FxAccounts({113 newAccountState(creds) {114 // we use a real accountState but mocked storage.115 let storage = new MockStorageManager();116 storage.initialize(creds);117 return new AccountState(storage);118 },119 fxAccountsClient: new MockFxAccountsClient(device, credentials),120 fxaPushService: {121 registerPushEndpoint() {122 return new Promise(resolve => {123 resolve({124 endpoint: "http://mochi.test:8888",125 getKey(type) {126 return ChromeUtils.base64URLDecode(127 type === "auth" ? BOGUS_AUTHKEY : BOGUS_PUBLICKEY,128 { padding: "ignore" }129 );130 },131 });132 });133 },134 unsubscribe() {135 return Promise.resolve();136 },137 },138 commands: {139 async availableCommands() {140 return {};141 },142 },143 device: {144 DEVICE_REGISTRATION_VERSION,145 },146 VERIFICATION_POLL_TIMEOUT_INITIAL: 1,147 });148 await fxa._internal.setSignedInUser(credentials);149 Services.prefs.setStringPref(150 "identity.fxaccounts.account.device.name",151 device.name || "mock device name"152 );153 return fxa;154}155function updateUserAccountData(fxa, data) {156 return fxa._internal.updateUserAccountData(data);157}158add_task(async function test_updateDeviceRegistration_with_new_device() {159 const deviceName = "foo";160 const deviceType = "bar";161 const credentials = getTestUser("baz");162 const fxa = await MockFxAccounts(credentials, { name: deviceName });163 // Remove the current device registration (setSignedInUser does one!).164 await updateUserAccountData(fxa, { uid: credentials.uid, device: null });165 const spy = {166 registerDevice: { count: 0, args: [] },167 updateDevice: { count: 0, args: [] },168 getDeviceList: { count: 0, args: [] },169 };170 const client = fxa._internal.fxAccountsClient;171 client.registerDevice = function() {172 spy.registerDevice.count += 1;173 spy.registerDevice.args.push(arguments);174 return Promise.resolve({175 id: "newly-generated device id",176 createdAt: Date.now(),177 name: deviceName,178 type: deviceType,179 });180 };181 client.updateDevice = function() {182 spy.updateDevice.count += 1;183 spy.updateDevice.args.push(arguments);184 return Promise.resolve({});185 };186 client.getDeviceList = function() {187 spy.getDeviceList.count += 1;188 spy.getDeviceList.args.push(arguments);189 return Promise.resolve([]);190 };191 await fxa.updateDeviceRegistration();192 Assert.equal(spy.updateDevice.count, 0);193 Assert.equal(spy.getDeviceList.count, 0);194 Assert.equal(spy.registerDevice.count, 1);195 Assert.equal(spy.registerDevice.args[0].length, 4);196 Assert.equal(spy.registerDevice.args[0][0], credentials.sessionToken);197 Assert.equal(spy.registerDevice.args[0][1], deviceName);198 Assert.equal(spy.registerDevice.args[0][2], "desktop");199 Assert.equal(200 spy.registerDevice.args[0][3].pushCallback,201 "http://mochi.test:8888"202 );203 Assert.equal(spy.registerDevice.args[0][3].pushPublicKey, BOGUS_PUBLICKEY);204 Assert.equal(spy.registerDevice.args[0][3].pushAuthKey, BOGUS_AUTHKEY);205 const state = fxa._internal.currentAccountState;206 const data = await state.getUserAccountData();207 Assert.equal(data.device.id, "newly-generated device id");208 Assert.equal(data.device.registrationVersion, DEVICE_REGISTRATION_VERSION);209 await fxa.signOut(true);210});211add_task(async function test_updateDeviceRegistration_with_existing_device() {212 const deviceId = "my device id";213 const deviceName = "phil's device";214 const credentials = getTestUser("pb");215 const fxa = await MockFxAccounts(credentials, { name: deviceName });216 await updateUserAccountData(fxa, {217 uid: credentials.uid,218 device: {219 id: deviceId,220 registeredCommandsKeys: [],221 registrationVersion: 1, // < 42222 },223 });224 const spy = {225 registerDevice: { count: 0, args: [] },226 updateDevice: { count: 0, args: [] },227 getDeviceList: { count: 0, args: [] },228 };229 const client = fxa._internal.fxAccountsClient;230 client.registerDevice = function() {231 spy.registerDevice.count += 1;232 spy.registerDevice.args.push(arguments);233 return Promise.resolve({});234 };235 client.updateDevice = function() {236 spy.updateDevice.count += 1;237 spy.updateDevice.args.push(arguments);238 return Promise.resolve({239 id: deviceId,240 name: deviceName,241 });242 };243 client.getDeviceList = function() {244 spy.getDeviceList.count += 1;245 spy.getDeviceList.args.push(arguments);246 return Promise.resolve([]);247 };248 await fxa.updateDeviceRegistration();249 Assert.equal(spy.registerDevice.count, 0);250 Assert.equal(spy.getDeviceList.count, 0);251 Assert.equal(spy.updateDevice.count, 1);252 Assert.equal(spy.updateDevice.args[0].length, 4);253 Assert.equal(spy.updateDevice.args[0][0], credentials.sessionToken);254 Assert.equal(spy.updateDevice.args[0][1], deviceId);255 Assert.equal(spy.updateDevice.args[0][2], deviceName);256 Assert.equal(257 spy.updateDevice.args[0][3].pushCallback,258 "http://mochi.test:8888"259 );260 Assert.equal(spy.updateDevice.args[0][3].pushPublicKey, BOGUS_PUBLICKEY);261 Assert.equal(spy.updateDevice.args[0][3].pushAuthKey, BOGUS_AUTHKEY);262 const state = fxa._internal.currentAccountState;263 const data = await state.getUserAccountData();264 Assert.equal(data.device.id, deviceId);265 Assert.equal(data.device.registrationVersion, DEVICE_REGISTRATION_VERSION);266 await fxa.signOut(true);267});268add_task(269 async function test_updateDeviceRegistration_with_unknown_device_error() {270 const deviceName = "foo";271 const deviceType = "bar";272 const currentDeviceId = "my device id";273 const credentials = getTestUser("baz");274 const fxa = await MockFxAccounts(credentials, { name: deviceName });275 await updateUserAccountData(fxa, {276 uid: credentials.uid,277 device: {278 id: currentDeviceId,279 registeredCommandsKeys: [],280 registrationVersion: 1, // < 42281 },282 });283 const spy = {284 registerDevice: { count: 0, args: [] },285 updateDevice: { count: 0, args: [] },286 getDeviceList: { count: 0, args: [] },287 };288 const client = fxa._internal.fxAccountsClient;289 client.registerDevice = function() {290 spy.registerDevice.count += 1;291 spy.registerDevice.args.push(arguments);292 return Promise.resolve({293 id: "a different newly-generated device id",294 createdAt: Date.now(),295 name: deviceName,296 type: deviceType,297 });298 };299 client.updateDevice = function() {300 spy.updateDevice.count += 1;301 spy.updateDevice.args.push(arguments);302 return Promise.reject({303 code: 400,304 errno: ERRNO_UNKNOWN_DEVICE,305 });306 };307 client.getDeviceList = function() {308 spy.getDeviceList.count += 1;309 spy.getDeviceList.args.push(arguments);310 return Promise.resolve([]);311 };312 await fxa.updateDeviceRegistration();313 Assert.equal(spy.getDeviceList.count, 0);314 Assert.equal(spy.registerDevice.count, 0);315 Assert.equal(spy.updateDevice.count, 1);316 Assert.equal(spy.updateDevice.args[0].length, 4);317 Assert.equal(spy.updateDevice.args[0][0], credentials.sessionToken);318 Assert.equal(spy.updateDevice.args[0][1], currentDeviceId);319 Assert.equal(spy.updateDevice.args[0][2], deviceName);320 Assert.equal(321 spy.updateDevice.args[0][3].pushCallback,322 "http://mochi.test:8888"323 );324 Assert.equal(spy.updateDevice.args[0][3].pushPublicKey, BOGUS_PUBLICKEY);325 Assert.equal(spy.updateDevice.args[0][3].pushAuthKey, BOGUS_AUTHKEY);326 const state = fxa._internal.currentAccountState;327 const data = await state.getUserAccountData();328 Assert.equal(null, data.device);329 await fxa.signOut(true);330 }331);332add_task(333 async function test_updateDeviceRegistration_with_device_session_conflict_error() {334 const deviceName = "foo";335 const deviceType = "bar";336 const currentDeviceId = "my device id";337 const conflictingDeviceId = "conflicting device id";338 const credentials = getTestUser("baz");339 const fxa = await MockFxAccounts(credentials, { name: deviceName });340 await updateUserAccountData(fxa, {341 uid: credentials.uid,342 device: {343 id: currentDeviceId,344 registeredCommandsKeys: [],345 registrationVersion: 1, // < 42346 },347 });348 const spy = {349 registerDevice: { count: 0, args: [] },350 updateDevice: { count: 0, args: [], times: [] },351 getDeviceList: { count: 0, args: [] },352 };353 const client = fxa._internal.fxAccountsClient;354 client.registerDevice = function() {355 spy.registerDevice.count += 1;356 spy.registerDevice.args.push(arguments);357 return Promise.resolve({});358 };359 client.updateDevice = function() {360 spy.updateDevice.count += 1;361 spy.updateDevice.args.push(arguments);362 spy.updateDevice.time = Date.now();363 if (spy.updateDevice.count === 1) {364 return Promise.reject({365 code: 400,366 errno: ERRNO_DEVICE_SESSION_CONFLICT,367 });368 }369 return Promise.resolve({370 id: conflictingDeviceId,371 name: deviceName,372 });373 };374 client.getDeviceList = function() {375 spy.getDeviceList.count += 1;376 spy.getDeviceList.args.push(arguments);377 spy.getDeviceList.time = Date.now();378 return Promise.resolve([379 {380 id: "ignore",381 name: "ignore",382 type: "ignore",383 isCurrentDevice: false,384 },385 {386 id: conflictingDeviceId,387 name: deviceName,388 type: deviceType,389 isCurrentDevice: true,390 },391 ]);392 };393 await fxa.updateDeviceRegistration();394 Assert.equal(spy.registerDevice.count, 0);395 Assert.equal(spy.updateDevice.count, 1);396 Assert.equal(spy.updateDevice.args[0].length, 4);397 Assert.equal(spy.updateDevice.args[0][0], credentials.sessionToken);398 Assert.equal(spy.updateDevice.args[0][1], currentDeviceId);399 Assert.equal(spy.updateDevice.args[0][2], deviceName);400 Assert.equal(401 spy.updateDevice.args[0][3].pushCallback,402 "http://mochi.test:8888"403 );404 Assert.equal(spy.updateDevice.args[0][3].pushPublicKey, BOGUS_PUBLICKEY);405 Assert.equal(spy.updateDevice.args[0][3].pushAuthKey, BOGUS_AUTHKEY);406 Assert.equal(spy.getDeviceList.count, 1);407 Assert.equal(spy.getDeviceList.args[0].length, 1);408 Assert.equal(spy.getDeviceList.args[0][0], credentials.sessionToken);409 Assert.ok(spy.getDeviceList.time >= spy.updateDevice.time);410 const state = fxa._internal.currentAccountState;411 const data = await state.getUserAccountData();412 Assert.equal(data.device.id, conflictingDeviceId);413 Assert.equal(data.device.registrationVersion, null);414 await fxa.signOut(true);415 }416);417add_task(418 async function test_updateDeviceRegistration_with_unrecoverable_error() {419 const deviceName = "foo";420 const credentials = getTestUser("baz");421 const fxa = await MockFxAccounts(credentials, { name: deviceName });422 await updateUserAccountData(fxa, { uid: credentials.uid, device: null });423 const spy = {424 registerDevice: { count: 0, args: [] },425 updateDevice: { count: 0, args: [] },426 getDeviceList: { count: 0, args: [] },427 };428 const client = fxa._internal.fxAccountsClient;429 client.registerDevice = function() {430 spy.registerDevice.count += 1;431 spy.registerDevice.args.push(arguments);432 return Promise.reject({433 code: 400,434 errno: ERRNO_TOO_MANY_CLIENT_REQUESTS,435 });436 };437 client.updateDevice = function() {438 spy.updateDevice.count += 1;439 spy.updateDevice.args.push(arguments);440 return Promise.resolve({});441 };442 client.getDeviceList = function() {443 spy.getDeviceList.count += 1;444 spy.getDeviceList.args.push(arguments);445 return Promise.resolve([]);446 };447 await fxa.updateDeviceRegistration();448 Assert.equal(spy.getDeviceList.count, 0);449 Assert.equal(spy.updateDevice.count, 0);450 Assert.equal(spy.registerDevice.count, 1);451 Assert.equal(spy.registerDevice.args[0].length, 4);452 const state = fxa._internal.currentAccountState;453 const data = await state.getUserAccountData();454 Assert.equal(null, data.device);455 await fxa.signOut(true);456 }457);458add_task(459 async function test_getDeviceId_with_no_device_id_invokes_device_registration() {460 const credentials = getTestUser("foo");461 credentials.verified = true;462 const fxa = await MockFxAccounts(credentials);463 await updateUserAccountData(fxa, { uid: credentials.uid, device: null });464 const spy = { count: 0, args: [] };465 fxa._internal.currentAccountState.getUserAccountData = () =>466 Promise.resolve({467 email: credentials.email,468 registrationVersion: DEVICE_REGISTRATION_VERSION,469 });470 fxa._internal.device._registerOrUpdateDevice = function() {471 spy.count += 1;472 spy.args.push(arguments);473 return Promise.resolve("bar");474 };475 const result = await fxa.device.getLocalId();476 Assert.equal(spy.count, 1);477 Assert.equal(spy.args[0].length, 2);478 Assert.equal(spy.args[0][1].email, credentials.email);479 Assert.equal(null, spy.args[0][1].device);480 Assert.equal(result, "bar");481 await fxa.signOut(true);482 }483);484add_task(485 async function test_getDeviceId_with_registration_version_outdated_invokes_device_registration() {486 const credentials = getTestUser("foo");487 credentials.verified = true;488 const fxa = await MockFxAccounts(credentials);489 const spy = { count: 0, args: [] };490 fxa._internal.currentAccountState.getUserAccountData = () =>491 Promise.resolve({492 device: {493 id: "my id",494 registrationVersion: 0,495 registeredCommandsKeys: [],496 },497 });498 fxa._internal.device._registerOrUpdateDevice = function() {499 spy.count += 1;500 spy.args.push(arguments);501 return Promise.resolve("wibble");502 };503 const result = await fxa.device.getLocalId();504 Assert.equal(spy.count, 1);505 Assert.equal(spy.args[0].length, 2);506 Assert.equal(spy.args[0][1].device.id, "my id");507 Assert.equal(result, "wibble");508 await fxa.signOut(true);509 }510);511add_task(512 async function test_getDeviceId_with_device_id_and_uptodate_registration_version_doesnt_invoke_device_registration() {513 const credentials = getTestUser("foo");514 credentials.verified = true;515 const fxa = await MockFxAccounts(credentials);516 const spy = { count: 0 };517 fxa._internal.currentAccountState.getUserAccountData = async () => ({518 device: {519 id: "foo's device id",520 registrationVersion: DEVICE_REGISTRATION_VERSION,521 registeredCommandsKeys: [],522 },523 });524 fxa._internal.device._registerOrUpdateDevice = function() {525 spy.count += 1;526 return Promise.resolve("bar");527 };528 const result = await fxa.device.getLocalId();529 Assert.equal(spy.count, 0);530 Assert.equal(result, "foo's device id");531 await fxa.signOut(true);532 }533);534add_task(535 async function test_getDeviceId_with_device_id_and_with_no_registration_version_invokes_device_registration() {536 const credentials = getTestUser("foo");537 credentials.verified = true;538 const fxa = await MockFxAccounts(credentials);539 const spy = { count: 0, args: [] };540 fxa._internal.currentAccountState.getUserAccountData = () =>541 Promise.resolve({ device: { id: "wibble" } });542 fxa._internal.device._registerOrUpdateDevice = function() {543 spy.count += 1;544 spy.args.push(arguments);545 return Promise.resolve("wibble");546 };547 const result = await fxa.device.getLocalId();548 Assert.equal(spy.count, 1);549 Assert.equal(spy.args[0].length, 2);550 Assert.equal(spy.args[0][1].device.id, "wibble");551 Assert.equal(result, "wibble");552 await fxa.signOut(true);553 }554);555add_task(async function test_verification_updates_registration() {556 const deviceName = "foo";557 const credentials = getTestUser("baz");558 const fxa = await MockFxAccounts(credentials, {559 id: "device-id",560 name: deviceName,561 });562 // We should already have a device registration, but without send-tab due to563 // our inability to fetch keys for an unverified users.564 const state = fxa._internal.currentAccountState;565 const { device } = await state.getUserAccountData();566 Assert.equal(device.registeredCommandsKeys.length, 0);567 let updatePromise = new Promise(resolve => {568 const old_registerOrUpdateDevice = fxa.device._registerOrUpdateDevice.bind(569 fxa.device570 );571 fxa.device._registerOrUpdateDevice = async function(572 currentState,573 signedInUser574 ) {575 await old_registerOrUpdateDevice(currentState, signedInUser);576 fxa.device._registerOrUpdateDevice = old_registerOrUpdateDevice;577 resolve();578 };579 });580 fxa._internal.checkEmailStatus = async function(sessionToken) {581 credentials.verified = true;582 return credentials;583 };584 await updatePromise;585 const { device: newDevice } = await state.getUserAccountData();586 Assert.equal(newDevice.registeredCommandsKeys.length, 1);587 await fxa.signOut(true);588});589add_task(async function test_devicelist_pushendpointexpired() {590 const deviceId = "mydeviceid";591 const credentials = getTestUser("baz");592 credentials.verified = true;593 const fxa = await MockFxAccounts(credentials);594 await updateUserAccountData(fxa, {595 uid: credentials.uid,596 device: {597 id: deviceId,598 registeredCommandsKeys: [],599 registrationVersion: 1, // < 42600 },601 });602 const spy = {603 updateDevice: { count: 0, args: [] },604 getDeviceList: { count: 0, args: [] },605 };606 const client = fxa._internal.fxAccountsClient;607 client.updateDevice = function() {608 spy.updateDevice.count += 1;609 spy.updateDevice.args.push(arguments);610 return Promise.resolve({});611 };612 client.getDeviceList = function() {613 spy.getDeviceList.count += 1;614 spy.getDeviceList.args.push(arguments);615 return Promise.resolve([616 {617 id: "mydeviceid",618 name: "foo",619 type: "desktop",620 isCurrentDevice: true,621 pushEndpointExpired: true,622 pushCallback: "https://example.com",623 },624 ]);625 };626 await fxa.device.refreshDeviceList();627 Assert.equal(spy.getDeviceList.count, 1);628 Assert.equal(spy.updateDevice.count, 1);629 await fxa.signOut(true);630});631add_task(async function test_devicelist_nopushcallback() {632 const deviceId = "mydeviceid";633 const credentials = getTestUser("baz");634 credentials.verified = true;635 const fxa = await MockFxAccounts(credentials);636 await updateUserAccountData(fxa, {637 uid: credentials.uid,638 device: {639 id: deviceId,640 registeredCommandsKeys: [],641 registrationVersion: 1,642 },643 });644 const spy = {645 updateDevice: { count: 0, args: [] },646 getDeviceList: { count: 0, args: [] },647 };648 const client = fxa._internal.fxAccountsClient;649 client.updateDevice = function() {650 spy.updateDevice.count += 1;651 spy.updateDevice.args.push(arguments);652 return Promise.resolve({});653 };654 client.getDeviceList = function() {655 spy.getDeviceList.count += 1;656 spy.getDeviceList.args.push(arguments);657 return Promise.resolve([658 {659 id: "mydeviceid",660 name: "foo",661 type: "desktop",662 isCurrentDevice: true,663 pushEndpointExpired: false,664 pushCallback: null,665 },666 ]);667 };668 await fxa.device.refreshDeviceList();669 Assert.equal(spy.getDeviceList.count, 1);670 Assert.equal(spy.updateDevice.count, 1);671 await fxa.signOut(true);672});673add_task(async function test_refreshDeviceList() {674 let credentials = getTestUser("baz");675 let storage = new MockStorageManager();676 storage.initialize(credentials);677 let state = new AccountState(storage);678 let fxAccountsClient = new MockFxAccountsClient({679 id: "deviceAAAAAA",680 name: "iPhone",681 type: "phone",682 sessionToken: credentials.sessionToken,683 });684 let spy = {685 getDeviceList: { count: 0 },686 };687 fxAccountsClient.getDeviceList = (function(old) {688 return function getDeviceList() {689 spy.getDeviceList.count += 1;690 return old.apply(this, arguments);691 };692 })(fxAccountsClient.getDeviceList);693 let fxai = {694 _now: Date.now(),695 _generation: 0,696 fxAccountsClient,697 now() {698 return this._now;699 },700 withVerifiedAccountState(func) {701 // Ensure `func` is called asynchronously, and simulate the possibility702 // of a different user signng in while the promise is in-flight.703 const currentGeneration = this._generation;704 return Promise.resolve()705 .then(_ => func(state))706 .then(result => {707 if (currentGeneration < this._generation) {708 throw new Error("Another user has signed in");709 }710 return result;711 });712 },713 fxaPushService: null,714 };715 let device = new FxAccountsDevice(fxai);716 Assert.equal(717 device.recentDeviceList,718 null,719 "Should not have device list initially"720 );721 Assert.ok(await device.refreshDeviceList(), "Should refresh list");722 Assert.deepEqual(723 device.recentDeviceList,724 [725 {726 id: "deviceAAAAAA",727 name: "iPhone",728 type: "phone",729 isCurrentDevice: true,730 },731 ],732 "Should fetch device list"733 );734 Assert.equal(735 spy.getDeviceList.count,736 1,737 "Should make request to refresh list"738 );739 Assert.ok(740 !(await device.refreshDeviceList()),741 "Should not refresh device list if fresh"742 );743 fxai._now += device.TIME_BETWEEN_FXA_DEVICES_FETCH_MS;744 let refreshPromise = device.refreshDeviceList();745 let secondRefreshPromise = device.refreshDeviceList();746 Assert.ok(747 await Promise.all([refreshPromise, secondRefreshPromise]),748 "Should refresh list if stale"749 );750 Assert.equal(751 spy.getDeviceList.count,752 2,753 "Should only make one request if called with pending request"754 );755 device.observe(null, ON_DEVICE_CONNECTED_NOTIFICATION);756 await device.refreshDeviceList();757 Assert.equal(758 spy.getDeviceList.count,759 3,760 "Should refresh device list after connecting new device"761 );762 device.observe(763 null,764 ON_DEVICE_DISCONNECTED_NOTIFICATION,765 JSON.stringify({ isLocalDevice: false })766 );767 await device.refreshDeviceList();768 Assert.equal(769 spy.getDeviceList.count,770 4,771 "Should refresh device list after disconnecting device"772 );773 device.observe(774 null,775 ON_DEVICE_DISCONNECTED_NOTIFICATION,776 JSON.stringify({ isLocalDevice: true })777 );778 await device.refreshDeviceList();779 Assert.equal(780 spy.getDeviceList.count,781 4,782 "Should not refresh device list after disconnecting this device"783 );784 let refreshBeforeResetPromise = device.refreshDeviceList({785 ignoreCached: true,786 });787 fxai._generation++;788 await Assert.rejects(refreshBeforeResetPromise, /Another user has signed in/);789 device.reset();790 Assert.equal(791 device.recentDeviceList,792 null,793 "Should clear device list after resetting"794 );795 Assert.ok(796 await device.refreshDeviceList(),797 "Should fetch new list after resetting"798 );799});800function expandHex(two_hex) {801 // Return a 64-character hex string, encoding 32 identical bytes.802 let eight_hex = two_hex + two_hex + two_hex + two_hex;803 let thirtytwo_hex = eight_hex + eight_hex + eight_hex + eight_hex;804 return thirtytwo_hex + thirtytwo_hex;805}806function expandBytes(two_hex) {807 return CommonUtils.hexToBytes(expandHex(two_hex));808}809function getTestUser(name) {810 return {811 email: name + "@example.com",812 uid: "1ad7f502-4cc7-4ec1-a209-071fd2fae348",813 sessionToken: name + "'s session token",814 keyFetchToken: name + "'s keyfetch token",815 unwrapBKey: expandHex("44"),816 verified: false,817 };...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import updatedevice_style from "./Updatedevice.module.css"2import Listitem from '../../Listitem'3import Levelgoto from "../../image/gotoright.svg";4import Bellactive from "../../Bellactive";5import Dropdown from 'react-dropdown';6import 'react-dropdown/style.css';7import delefi from '../../image/delefi.svg'8import star from '../../image/star.svg'9import {Link} from 'react-router-dom';10function Updatedevice(){11 const optionsdevice = [12 'Chọn loại thiết bị','Kiosk ','Display counter'13 ];14 const sumitdevice =(e)=>{15 console.log(e.value)16 }17 const defaultOptiondevice = optionsdevice[0];18 return(19 <div className={updatedevice_style.listdevice}>20 <Listitem/>21 <div className={updatedevice_style.listlevelright}>22 <div className={updatedevice_style.update}>23 <div className={updatedevice_style.updateinfo}>24 <div className={updatedevice_style.updateinfolist}>25 <p className={updatedevice_style.updatetitle}>26 Thiết bị27 </p>28 <img src={Levelgoto} alt="levelgoto" className={updatedevice_style.levelgoto}></img>29 <Link to='/device'>30 <p className={updatedevice_style.updatetitle }>31 Danh sách thiết bị32 </p>33 </Link>34 <img src={Levelgoto} alt="levelgoto" className={updatedevice_style.levelgoto}></img>35 <p className={updatedevice_style.updatelist }>36 Cập nhật thiết bị37 </p>38 </div>39 <div className={updatedevice_style.bell}>40 <Bellactive/>41 </div>42 </div>43 <div className={updatedevice_style.updatecontainer}>44 <div className={updatedevice_style.updatelisttitle}>45 Quản lý thiết bị46 </div>47 <div className={updatedevice_style.updatelistitem}>48 <div className={updatedevice_style.listitem}>49 <div className={updatedevice_style.updatelistinformation}>50 Thông tin thiết bị51 </div>52 <div className={updatedevice_style.listinformation}>53 <div className={updatedevice_style.updatename}>54 <p className={updatedevice_style.updateid}>Mã thiết bị:55 <img src={star} alt='star' className={updatedevice_style.starid}></img>56 </p>57 58 <input className={updatedevice_style.titlecontnet} type="text" name="" placeholder="KIO_01"/>59 </div>60 <div className={updatedevice_style.updatename}>61 <p className={updatedevice_style.updateid}>Loại thiết bị:62 <img src={star} alt='star' className={updatedevice_style.starid}></img>63 </p>64 <div className={updatedevice_style.updatedrow}>65 <Dropdown options={optionsdevice} 66 onChange={(e)=>sumitdevice(e)} 67 value={defaultOptiondevice} placeholder="Select an option" />68 </div>69 </div>70 <div className={updatedevice_style.updatename}>71 <p className={updatedevice_style.updateid}>Tên thiết bị:72 <img src={star} alt='star' className={updatedevice_style.starid}></img>73 </p>74 75 <input className={updatedevice_style.titlecontnet} type="text" name="" placeholder="Kiosk"/>76 </div>77 <div className={updatedevice_style.updatename}>78 <p className={updatedevice_style.updateid}>Tên đăng nhập:79 <img src={star} alt='star' className={updatedevice_style.starid}></img>80 </p>81 82 <input className={updatedevice_style.titlecontnet} type="text" name="" placeholder="Linhkyo011"/>83 </div>84 <div className={updatedevice_style.updatename}>85 <p className={updatedevice_style.updateid}> Địa chỉ IP:86 <img src={star} alt='star' className={updatedevice_style.starid}></img>87 </p>88 89 <input className={updatedevice_style.titlecontnet} type="text" name="" placeholder="128.172.308"/>90 </div>91 <div className={updatedevice_style.updatename}>92 <p className={updatedevice_style.updateid}>Mật khẩu:93 <img src={star} alt='star' className={updatedevice_style.starid}></img>94 </p>95 96 <input className={updatedevice_style.titlecontnet} type="text" name="" placeholder="CMS"/>97 </div>98 <div className={updatedevice_style.updatename}>99 <p className={updatedevice_style.updateid}>Dịch vụ sử dụng:100 <img src={star} alt='star' className={updatedevice_style.starid}></img>101 </p>102 <div className={updatedevice_style.list}>103 <div className={updatedevice_style.item}>104 <p className={updatedevice_style.updatetitle__item}>105 106 Khám tim mạch107 </p>108 <img src={delefi} alt='star' className={updatedevice_style.delefi}></img>109 </div>110 <div className={updatedevice_style.item}>111 <p className={updatedevice_style.updatetitle__item}>112 113 Khám sản phụ khoa114 </p>115 <img src={delefi} alt='star' className={updatedevice_style.delefi}></img>116 </div>117 <div className={updatedevice_style.item}>118 <p className={updatedevice_style.updatetitle__item}>119 120 Khám răng hàm mặt121 </p>122 <img src={delefi} alt='star' className={updatedevice_style.delefi}></img>123 </div>124 <div className={updatedevice_style.item}>125 <p className={updatedevice_style.updatetitle__item}>126 127 Khám tai mũi họng128 </p>129 <img src={delefi} alt='star' className={updatedevice_style.delefi}></img>130 </div>131 <div className={updatedevice_style.item}>132 <p className={updatedevice_style.updatetitle__item}>133 134 Khám hô hấp135 </p>136 <img src={delefi} alt='star' className={updatedevice_style.delefi}></img>137 </div>138 <div className={updatedevice_style.item}>139 <p className={updatedevice_style.updatetitle__item}>140 141 Khám tổng quát142 </p>143 <img src={delefi} alt='star' className={updatedevice_style.delefi}></img>144 </div>145 </div>146 </div>147 </div>148 </div>149 <div className={updatedevice_style.updatenameitem}>150 <img src={star} alt='star' className={updatedevice_style.star}></img>151 <p> Là trường thông tin bắt buộc</p>152 </div>153 </div>154 <div className={updatedevice_style.userbutton}>155 <Link to ='/device'>156 <div className={updatedevice_style.cannel}>157 <div className={updatedevice_style.canneltitle}>Hủy bỏ</div>158 </div>159 </Link>160 <Link to='/device'>161 <div className={updatedevice_style.more}>162 <div className={updatedevice_style.moretitle}>Cập nhật</div>163 </div>164 </Link>165 166 </div>167 </div>168 </div>169 </div>170 </div> 171 )172}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = client.getDevice('123456789012345678');3device.updateDevice({ status: 'using' });4var stf = require('devicefarmer-stf-client');5var device = client.getDevice('123456789012345678');6device.updateDevice({ status: 'using' });7var stf = require('devicefarmer-stf-client');8var device = client.getDevice('123456789012345678');9device.updateDevice({ status: 'using' });10var stf = require('devicefarmer-stf-client');11var device = client.getDevice('123456789012345678');12device.updateDevice({ status: 'using' });13var stf = require('devicefarmer-stf-client');14var device = client.getDevice('123456789012345678');15device.updateDevice({ status: 'using' });16var stf = require('devicefarmer-stf-client');17var device = client.getDevice('123456789012345678');18device.updateDevice({ status: 'using' });19var stf = require('devicefarmer-stf-client');20var device = client.getDevice('123456789012345678');21device.updateDevice({ status: 'using' });

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var client = new stf.Client({3});4client.updateDevice({5}).then(function() {6 console.log('Device updated!');7}).catch(function(err) {8 console.error('Error:', err);9});10var stf = require('devicefarmer-stf-client');11var client = new stf.Client({12});13client.updateDevice({14}).then(function() {15 console.log('Device updated!');16}).catch(function(err) {17 console.error('Error:', err);18});19var stf = require('devicefarmer-stf-client');20var client = new stf.Client({21});22client.getDevices().then(function(devices) {23 console.log(devices);24}).catch(function(err) {25 console.error('Error:', err);26});27client.on('deviceAdd', function(device) {28 console.log('Device added:', device);29});30client.on('deviceUpdate', function(device) {31 console.log('Device updated:', device);32});33client.on('deviceRemove', function(device) {34 console.log('Device removed:', device);35});36client.on('deviceAdd', function(device) {37 console.log('Device added:', device);38});39client.on('deviceUpdate',

Full Screen

Using AI Code Generation

copy

Full Screen

1var deviceFarmerClient = require('devicefarmer-stf-client');2var device = client.updateDevice('device id', {status: 'broken'});3device.then(function(device){4 console.log(device);5}, function(err){6 console.log(err);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = new stf.Device(client);3device.updateDevice('f4c0d7b6', {present: false}, function(err, res) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(res);9 }10});11var stf = require('devicefarmer-stf-client');12var device = new stf.Device(client);13device.getDevice('f4c0d7b6', function(err, res) {14 if (err) {15 console.log(err);16 }17 else {18 console.log(res);19 }20});21var stf = require('devicefarmer-stf-client');22var device = new stf.Device(client);23device.getDevices(function(err, res) {24 if (err) {25 console.log(err);26 }27 else {28 console.log(res);29 }30});31var stf = require('devicefarmer-stf-client');32var device = new stf.Device(client);33device.getDevicesByOwner('someUser', function(err, res) {34 if (err) {35 console.log(err);36 }37 else {38 console.log(res);39 }40});41var stf = require('devicefarmer-stf-client');42var device = new stf.Device(client);43device.getDevicesByGroup('someGroup', function(err, res) {44 if (err) {45 console.log(err);46 }47 else {48 console.log(res);49 }50});

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2var client = new devicefarmer.Client();3var deviceId = "your device id";4var status = "using";5client.updateDevice(deviceId, status, function(error, response, body) {6 if (!error && response.statusCode == 200) {7 console.log(body);8 } else {9 console.log(response.statusCode);10 }11});12{13}14var devicefarmer = require('devicefarmer-stf');15var client = new devicefarmer.Client();16var deviceId = "your device id";17client.getDevice(deviceId, function(error, response, body) {18 if (!error && response.statusCode == 200) {19 console.log(body);20 } else {21 console.log(response.statusCode);22 }23});24{25 "device": {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful