- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / nacl / pnacl_error_handling / pnacl_error_handling.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html>
4 <!--
5   Copyright (c) 2012 The Chromium Authors. All rights reserved.
6   Use of this source code is governed by a BSD-style license that can be
7   found in the LICENSE file.
8 -->
9 <head>
10   <META HTTP-EQUIV="Pragma" CONTENT="no-cache" />
11   <META HTTP-EQUIV="Expires" CONTENT="-1" />
12   <script type="text/javascript" src="nacltest.js"></script>
13   <script type="text/javascript" src="ppapi_bad.js"></script>
14   <title>PNaCl Error Handling Test</title>
15   <style type="text/css">
16   .naclModule { background-color: gray; margin: 2px 2px; }
17   </style>
18 </head>
19 <body id="body">
20 <script type="text/javascript">
21 //<![CDATA[
22
23 function declareTests(tester) {
24   // 'bad_pexe' loads a manifest, then loads a pexe that is invalid.
25   badLoadTest(
26       tester,
27       'bad_pexe',
28       'pnacl_bad_pexe.nmf',
29       'application/x-pnacl',
30       'NaCl module load failed: PnaclCoordinator: PNaCl Translator Error: ' +
31       'Invalid PNaCl bitcode header');
32
33   // 'nonexistent_pexe' loads a manifest, then tries to to load a nonexistent
34   // pexe and fails.
35   badLoadTest(
36       tester,
37       'nonexistent_pexe',
38       'pnacl_bad_doesnotexist.nmf',
39       'application/x-pnacl',
40       'NaCl module load failed: PnaclCoordinator: ' +
41       'pexe load failed (pp_error=-2).');
42
43   // 'illformed_manifest' loads a manifest that isn't quite right for pexes
44   // (looks like the format for NaCl portable data files).
45   badLoadTest(
46       tester,
47       'illformed_manifest',
48       'pnacl_illformed_manifest.nmf',
49       'application/x-pnacl',
50       'NaCl module load failed: manifest: program property \'portable\' does ' +
51       'not have required key: \'pnacl-translate\'.');
52
53   // 'wrong_mimetype' loads an okay manifest, but with the wrong mimetype
54   // (the NaCl mimetype instead of PNaCl mimetype).
55   badLoadTest(
56       tester,
57       'wrong_mimetype',
58       'pnacl_bad_pexe.nmf',
59       'application/x-nacl',
60       'NaCl module load failed: manifest: PNaCl-like NMF with ' +
61       'application/x-nacl mimetype instead of x-pnacl mimetype ' +
62       '(has pnacl-translate).');
63 }
64
65 // Test that when a surfaway causes the plugin to be destroyed, the PnaclHost
66 // receives a TranslationFinished message and clears its state so subsequent
67 // translations do not get blocked.
68 function surfawayTest(tester) {
69   tester.addAsyncTest('surfaway', function(test) {
70     var progress_event_count = 0;
71     var module = createModule('surfaway', 'simple.nmf', 'application/x-pnacl');
72     var f = function(e) {
73       progress_event_count += 1;
74       if (progress_event_count < 2) {
75         // The first 'progress' event indicates that we read the manifest and
76         // got a nexe URL. The actual translation has not started until the
77         // second event. On the first call, just re-hook to catch the next event
78         test.expectEvent(module, 'progress', f);
79       } else {
80         // Removing the embed will shutdown the plugin, and adding it will
81         // re-create it and start a new translation
82         removeModule(module);
83         addModule(module);
84       }
85     }
86     test.expectEvent(module, 'progress', f);
87     test.expectEvent(module, 'load', function(e) {
88       test.assertEqual(progress_event_count, 2);
89       removeModule(module);
90       test.pass();
91     });
92     addModule(module);
93   });
94 }
95
96 // The driver invoked when the body has finished loading.
97 function runTests() {
98   var tester = new Tester($('body'));
99   tester.loadErrorsAreOK();
100   declareTests(tester);
101   surfawayTest(tester);
102   tester.run();
103 }
104 //]]>
105 </script>
106
107 <!-- The tests will create and remove embeds from this div. -->
108 <div id="embeds"></div>
109
110 <script type="text/javascript">
111 //<![CDATA[
112 runTests();
113 //]]>
114 </script>
115 </body>
116 </html>