Replace DOMException TYPE_MISMATCH_ERR with TypeError
[WebKit-https.git] / LayoutTests / media / encrypted-media / encrypted-media-syntax.html
1 <!doctype html>
2 <html lang="en">
3     <head>
4     </head>
5     <body>
6         <video></video>
7         <p>Tests invalid and valid syntaxes.</p>
8
9         <script src=../media-file.js></script>
10         <script src=../video-test.js></script>
11         <script>
12             var initData = new Uint8Array([0x51, 0x52, 0x53]);
13             var key = initData;
14     
15             function loadStarted()
16             {
17                 consoleWrite("Verify valid syntaxes do not throw.");
18                 testExpected("video.networkState", video.NETWORK_LOADING);
19                 testExpected("video.currentSrc", "", "!=");
20                 run("video.webkitGenerateKeyRequest('webkit-org.w3.clearkey')");
21                 run("video.webkitGenerateKeyRequest('webkit-org.w3.clearkey', initData)");
22                 run("video.webkitAddKey('webkit-org.w3.clearkey', key)");
23                 run("video.webkitAddKey('webkit-org.w3.clearkey', key, 'session')");
24                 run("video.webkitAddKey('webkit-org.w3.clearkey', key, initData)");
25                 run("video.webkitAddKey('webkit-org.w3.clearkey', key, initData, 'session')");
26                 run("video.webkitCancelKeyRequest('webkit-org.w3.clearkey')");
27                 run("video.webkitCancelKeyRequest('webkit-org.w3.clearkey', 'session')");
28
29                 consoleWrite("<br>Unsupported key systems result in NOT_SUPPORTED_ERR.");
30                 testException("video.webkitGenerateKeyRequest('com.example.invalid')", "DOMException.NOT_SUPPORTED_ERR");
31                 testException("video.webkitAddKey('com.example.invalid', key)", "DOMException.NOT_SUPPORTED_ERR");
32                 testException("video.webkitCancelKeyRequest('com.example.invalid')", "DOMException.NOT_SUPPORTED_ERR");
33
34                 endTest();
35             }
36         
37             consoleWrite("Test calling functions with too few parameters.");
38             testException("video.webkitGenerateKeyRequest()", "DOMException.TYPE_ERR");
39             testException("video.webkitAddKey()", "DOMException.TYPE_ERR");
40             testException("video.webkitAddKey('webkit-org.w3.clearkey')", "DOMException.TYPE_ERR");
41             testException("video.webkitCancelKeyRequest()", "DOMException.TYPE_ERR");
42
43             consoleWrite("<br>Verify invalid key system parameter is caught before checking whether loading has started.");
44             // If the above was not the case, all of these would be INVALID_STATE_ERR.
45             // Also tests "null" case for first parameter.
46             testExpected("video.networkState", video.NETWORK_EMPTY);
47             testExpected("video.currentSrc", "");
48             testException("video.webkitGenerateKeyRequest('')", "DOMException.SYNTAX_ERR");
49             testException("video.webkitGenerateKeyRequest(null)", "DOMException.SYNTAX_ERR");
50             testException("video.webkitGenerateKeyRequest(undefined)", "DOMException.SYNTAX_ERR");
51             testException("video.webkitAddKey('', key)", "DOMException.SYNTAX_ERR");
52             testException("video.webkitAddKey(null, key)", "DOMException.SYNTAX_ERR");
53             testException("video.webkitAddKey(undefined, key)", "DOMException.SYNTAX_ERR");
54             testException("video.webkitCancelKeyRequest('')", "DOMException.SYNTAX_ERR");
55             testException("video.webkitCancelKeyRequest(null)", "DOMException.SYNTAX_ERR");
56             testException("video.webkitCancelKeyRequest(undefined)", "DOMException.SYNTAX_ERR");
57
58             consoleWrite("<br>null key is caught before load state is checked.");
59             testException("video.webkitAddKey('webkit-org.w3.clearkey', '')", "DOMException.SYNTAX_ERR");
60             testException("video.webkitAddKey('webkit-org.w3.clearkey', null)", "DOMException.SYNTAX_ERR");
61             testException("video.webkitAddKey('webkit-org.w3.clearkey', undefined)", "DOMException.SYNTAX_ERR");
62
63             consoleWrite("<br>0-length key is caught before load state is checked.");
64             testError("video.webkitAddKey('webkit-org.w3.clearkey', new Uint8Array())", "'TypeError'");
65
66             consoleWrite("<br>Key system validity is not checked before loading.");
67             testException("video.webkitGenerateKeyRequest('com.example.invalid')", "DOMException.INVALID_STATE_ERR");
68             testException("video.webkitAddKey('com.example.invalid', key)", "DOMException.INVALID_STATE_ERR");
69             testException("video.webkitCancelKeyRequest('com.example.invalid')", "DOMException.INVALID_STATE_ERR");
70
71             // FIXME(82952): Add "test-encrypted" file.
72             video.setAttribute("src", findMediaFile("video", "../content/test"));
73             consoleWrite("");
74             waitForEvent('loadstart', loadStarted);
75         </script>
76     </body>
77 </html>