Skip to content

Commit

Permalink
Language Detector: Reject when called with aborted signal
Browse files Browse the repository at this point in the history
Rejects the promise returned by AILanguageDetector.detect() when the
signal passed in is already aborted.

Bug: 391713293
Change-Id: Icbeb5648458397e92fa7ec0ba8e14fd31ddd1754
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6210161
Commit-Queue: Nathan Memmott <[email protected]>
Reviewed-by: Jiacheng Guo <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1412982}
  • Loading branch information
Nathan Memmott authored and chromium-wpt-export-bot committed Jan 29, 2025
1 parent c6fad56 commit 344a03b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ai/language_detection/detector.https.tentative.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@

promise_test(async t => {
const detector = await ai.languageDetector.create();
const results = await detector.detect("this string is in English");
const results = await detector.detect('this string is in English');
// "en" should be highest confidence.
assert_equals(results[0].detectedLanguage, "en");
assert_equals(results[0].detectedLanguage, 'en');
// Results should be from high to low confidence.
for (let i = 0; i < results.length - 1; i++) {
assert_greater_than_equal(results[i].confidence, results[i + 1].confidence);
}
});
}, 'Simple AILanguageDetector.detect() call');

promise_test(async t => {
const controller = new AbortController();
controller.abort();

const detector = await ai.languageDetector.create();
const detectPromise = await detector.detect('this string is in English');

await promise_rejects_dom(t, 'AbortError', detectPromise);
}, 'AILanguageDetector.detect() call with an aborted signal.')

0 comments on commit 344a03b

Please sign in to comment.