language-model-destroy.tentative.https.window.js (1388B)
1 // META: title=Language Model Destroy 2 // META: script=/resources/testdriver.js 3 // META: script=../resources/util.js 4 // META: timeout=long 5 6 'use strict'; 7 8 promise_test(async t => { 9 await ensureLanguageModel(); 10 11 // Start a new session. 12 const session = await createLanguageModel(); 13 14 // Calling `session.destroy()` immediately after `session.prompt()` will 15 // trigger the "The model execution session has been destroyed." exception. 16 let result = session.prompt(kTestPrompt); 17 session.destroy(); 18 await promise_rejects_dom( 19 t, "InvalidStateError", result, 20 "The model execution session has been destroyed." 21 ); 22 23 // Calling `session.prompt()` after `session.destroy()` will trigger the 24 // "The model execution session has been destroyed." exception. 25 await promise_rejects_dom( 26 t, "InvalidStateError", session.prompt(kTestPrompt), 27 "The model execution session has been destroyed." 28 ); 29 30 // After destroying the session, the properties should be still accessible. 31 assert_equals( 32 typeof session.inputQuota, "number", 33 "inputQuota must be accessible." 34 ); 35 assert_equals( 36 typeof session.inputUsage, "number", 37 "inputUsage must be accessible." 38 ); 39 assert_equals( 40 typeof session.temperature, "number", 41 "temperature must be accessible." 42 ); 43 assert_equals( 44 typeof session.topK, "number", 45 "topK must be accessible." 46 ); 47 });