OLD | NEW |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../../resources/js-test.js"></script> | 4 <script src="../../../resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <script type="text/javascript"> | 7 <script type="text/javascript"> |
8 description('Tests the basics of SpeechGrammar and SpeechGrammarList'); | 8 description('Tests the basics of SpeechGrammar and SpeechGrammarList'); |
9 | 9 |
10 function run() { | 10 function run() { |
11 window.base = document.baseURI.substring(0, document.baseURI.lastIndexOf('/'
) + 1); | 11 window.base = document.baseURI.substring(0, document.baseURI.lastIndexOf('/'
) + 1); |
12 | 12 |
13 // Check availability of constructors. | 13 // Check availability of constructors. |
14 shouldBeTrue("'webkitSpeechGrammar' in window"); | 14 shouldBeTrue("'webkitSpeechGrammar' in window"); |
15 shouldBeFalse("webkitSpeechGrammar == null"); | 15 shouldBeFalse("webkitSpeechGrammar == null"); |
16 shouldBeTrue("'webkitSpeechGrammarList' in window"); | 16 shouldBeTrue("'webkitSpeechGrammarList' in window"); |
17 shouldBeFalse("webkitSpeechGrammarList == null"); | 17 shouldBeFalse("webkitSpeechGrammarList == null"); |
18 | 18 |
19 // Test creating a grammar explicitly. | 19 // Test creating a grammar explicitly. |
20 evalAndLog("window.g = new webkitSpeechGrammar()"); | 20 evalAndLog("window.g = new webkitSpeechGrammar()"); |
21 shouldBeFalse("g == null"); | 21 shouldBeFalse("g == null"); |
22 shouldBe("g.weight", "1.0"); | 22 shouldBe("g.weight", "1.0"); |
23 shouldBe("g.src", "''"); | 23 shouldBe("g.src", "''"); |
24 | 24 |
25 // Test setting the attributes. | 25 // Test setting the attributes. |
26 evalAndLog("g.weight = 2"); | 26 evalAndLog("g.weight = 2"); |
27 shouldBe("g.weight", "2.0"); | 27 shouldBe("g.weight", "2.0"); |
| 28 shouldThrow("g.weight = NaN"); |
| 29 shouldThrow("g.weight = Infinity"); |
| 30 shouldBe("g.weight", "2.0"); |
28 evalAndLog("g.src = 'grammar.xml'"); | 31 evalAndLog("g.src = 'grammar.xml'"); |
29 shouldBe("g.src", "base + 'grammar.xml'"); | 32 shouldBe("g.src", "base + 'grammar.xml'"); |
30 evalAndLog("g.src = 'http://example.tld/grammar.xml'"); | 33 evalAndLog("g.src = 'http://example.tld/grammar.xml'"); |
31 shouldBe("g.src", "'http://example.tld/grammar.xml'"); | 34 shouldBe("g.src", "'http://example.tld/grammar.xml'"); |
32 evalAndLog("g.src = 'foo bar'"); | 35 evalAndLog("g.src = 'foo bar'"); |
33 shouldBe("g.src", "base + 'foo%20bar'"); | 36 shouldBe("g.src", "base + 'foo%20bar'"); |
34 | 37 |
35 // Test creating a grammar list. | 38 // Test creating a grammar list. |
36 evalAndLog("window.gs = new webkitSpeechGrammarList()"); | 39 evalAndLog("window.gs = new webkitSpeechGrammarList()"); |
37 shouldBeFalse("gs == null"); | 40 shouldBeFalse("gs == null"); |
(...skipping 19 matching lines...) Expand all Loading... |
57 shouldBe("gs.item(1).src", "'http://foo.tld/grammar.xml'"); | 60 shouldBe("gs.item(1).src", "'http://foo.tld/grammar.xml'"); |
58 shouldBe("gs.item(1).weight", "3"); | 61 shouldBe("gs.item(1).weight", "3"); |
59 | 62 |
60 evalAndLog("gs.addFromString('<grammar>foo</grammar>', 4)"); | 63 evalAndLog("gs.addFromString('<grammar>foo</grammar>', 4)"); |
61 shouldBe("gs.length", "3"); | 64 shouldBe("gs.length", "3"); |
62 shouldBe("gs[2]", "gs.item(2)"); | 65 shouldBe("gs[2]", "gs.item(2)"); |
63 shouldBe("gs.item(2).src", "'data:application/xml,%3Cgrammar%3Efoo%3C/gramma
r%3E'"); | 66 shouldBe("gs.item(2).src", "'data:application/xml,%3Cgrammar%3Efoo%3C/gramma
r%3E'"); |
64 shouldBe("gs.item(2).weight", "4"); | 67 shouldBe("gs.item(2).weight", "4"); |
65 shouldBe("gs[2].src", "'data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E'
"); | 68 shouldBe("gs[2].src", "'data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E'
"); |
66 shouldBe("gs[2].weight", "4"); | 69 shouldBe("gs[2].weight", "4"); |
| 70 |
| 71 shouldThrow("gs.addFromUri('http://foo.tld/grammar.xml', NaN)"); |
| 72 shouldThrow("gs.addFromUri('http://foo.tld/grammar.xml', Infinity)"); |
| 73 shouldThrow("gs.addFromString('foo', NaN)"); |
| 74 shouldThrow("gs.addFromString('foo', Infinity)"); |
| 75 |
67 finishJSTest(); | 76 finishJSTest(); |
68 } | 77 } |
69 | 78 |
70 window.onload = run; | 79 window.onload = run; |
71 window.jsTestIsAsync = true; | 80 window.jsTestIsAsync = true; |
72 </script> | 81 </script> |
73 </body> | 82 </body> |
74 </html> | 83 </html> |
OLD | NEW |