summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/speech/scripted/speechgrammar-basics.html
blob: 81a39bf9418e33fd0881f87cbd4ba74bb9cc3bdc (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
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script type="text/javascript">
description('Tests the basics of SpeechGrammar and SpeechGrammarList');

function run() {
    window.base = document.baseURI.substring(0, document.baseURI.lastIndexOf('/') + 1);

    // Check availability of constructors.
    shouldBeTrue("'webkitSpeechGrammar' in window");
    shouldBeFalse("webkitSpeechGrammar == null");
    shouldBeTrue("'webkitSpeechGrammarList' in window");
    shouldBeFalse("webkitSpeechGrammarList == null");

    // Test creating a grammar explicitly.
    evalAndLog("window.g = new webkitSpeechGrammar()");
    shouldBeFalse("g == null");
    shouldBe("g.weight", "1.0");
    shouldBe("g.src", "''");

    // Test setting the attributes.
    evalAndLog("g.weight = 2");
    shouldBe("g.weight", "2.0");
    shouldThrow("g.weight = NaN");
    shouldThrow("g.weight = Infinity");
    shouldBe("g.weight", "2.0");
    evalAndLog("g.src = 'grammar.xml'");
    shouldBe("g.src", "base + 'grammar.xml'");
    evalAndLog("g.src = 'http://example.tld/grammar.xml'");
    shouldBe("g.src", "'http://example.tld/grammar.xml'");
    evalAndLog("g.src = 'foo bar'");
    shouldBe("g.src", "base + 'foo%20bar'");

    // Test creating a grammar list.
    evalAndLog("window.gs = new webkitSpeechGrammarList()");
    shouldBeFalse("gs == null");
    shouldBe("gs.length", "0");
    shouldBeTrue("gs.item(0) == null");
    shouldBeTrue("gs[0] == undefined");
    shouldBeNull("gs.item(-1)");
    shouldBeTrue("gs[-1] == undefined");

    evalAndLog("gs.addFromUri('grammar', 2)");
    shouldBe("gs.length", "1");
    shouldBeTrue("gs.item(1) == null");
    shouldBeTrue("gs[1] == undefined");
    shouldBeNull("gs.item(-1)");
    shouldBeTrue("gs[-1] == undefined");
    shouldBe("gs[0]", "gs.item(0)");
    shouldBe("gs.item(0).src", "base + 'grammar'");
    shouldBe("gs.item(0).weight", "2");

    evalAndLog("gs.addFromUri('http://foo.tld/grammar.xml', 3)");
    shouldBe("gs.length", "2");
    shouldBe("gs[1]", "gs.item(1)");
    shouldBe("gs.item(1).src", "'http://foo.tld/grammar.xml'");
    shouldBe("gs.item(1).weight", "3");

    evalAndLog("gs.addFromString('<grammar>foo</grammar>', 4)");
    shouldBe("gs.length", "3");
    shouldBe("gs[2]", "gs.item(2)");
    shouldBe("gs.item(2).src", "'data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E'");
    shouldBe("gs.item(2).weight", "4");
    shouldBe("gs[2].src", "'data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E'");
    shouldBe("gs[2].weight", "4");

    shouldThrow("gs.addFromUri('http://foo.tld/grammar.xml', NaN)");
    shouldThrow("gs.addFromUri('http://foo.tld/grammar.xml', Infinity)");
    shouldThrow("gs.addFromString('foo', NaN)");
    shouldThrow("gs.addFromString('foo', Infinity)");

    finishJSTest();
}

window.onload = run;
window.jsTestIsAsync = true;
</script>
</body>
</html>