blob: ad41545429cdf667cdfd9f667618df1e42f48589 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<!DOCTYPE HTML>
<html>
<head>
<title>Verify detectLangauge</title>
<meta charset="utf-8">
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="text/javascript">
"use strict";
add_task(async function testDetectLanguage() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["tabs"],
host_permissions: ["<all_urls>"],
granted_host_permissions: true
},
background: async function() {
const BASE_PATH = "tests/toolkit/components/extensions/test/mochitest";
function loadTab(url) {
return browser.tabs.create({ url });
}
try {
let tab = await loadTab(
`https://example.com/${BASE_PATH}/file_language_ja.html`
);
let lang = await browser.tabs.detectLanguage(tab.id);
browser.test.assertEq(
"ja",
lang,
"Japanese document should be detected as Japanese"
);
await browser.tabs.remove(tab.id);
tab = await loadTab(
`https://example.com/${BASE_PATH}/file_language_fr_en.html`
);
lang = await browser.tabs.detectLanguage(tab.id);
browser.test.assertEq(
"fr",
lang,
"French/English document should be detected as primarily French"
);
await browser.tabs.remove(tab.id);
tab = await loadTab(
`https://example.com/${BASE_PATH}/file_language_tlh.html`
);
lang = await browser.tabs.detectLanguage(tab.id);
browser.test.assertEq(
"und",
lang,
"Klingon document should not be detected, should return 'und'"
);
await browser.tabs.remove(tab.id);
browser.test.notifyPass("detectLanguage");
} catch (e) {
browser.test.fail(`Error: ${e} :: ${e.stack}`);
browser.test.notifyFail("detectLanguage");
}
},
});
await extension.startup();
await extension.awaitFinish("detectLanguage");
await extension.unload();
});
</script>
</body>
</html>
|