| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 1 // Helper routines for generating bad load tests. | 5 // Helper routines for generating bad load tests. |
| 2 // Webpage must have an 'embeds' div for injecting NaCl modules. | 6 // Webpage must have an 'embeds' div for injecting NaCl modules. |
| 3 // Depends on nacltest.js. | 7 // Depends on nacltest.js. |
| 4 | 8 |
| 5 function createModule(id, src) { | 9 function createModule(id, src, type) { |
| 6 return createNaClEmbed({ | 10 return createNaClEmbed({ |
| 7 id: id, | 11 id: id, |
| 8 src: src, | 12 src: src, |
| 9 width: 100, | 13 width: 100, |
| 10 height: 20 | 14 height: 20, |
| 15 type: type |
| 11 }); | 16 }); |
| 12 } | 17 } |
| 13 | 18 |
| 14 | 19 |
| 15 function addModule(module) { | 20 function addModule(module) { |
| 16 $('embeds').appendChild(module); | 21 $('embeds').appendChild(module); |
| 17 } | 22 } |
| 18 | 23 |
| 19 | 24 |
| 20 function removeModule(module) { | 25 function removeModule(module) { |
| 21 $('embeds').removeChild(module); | 26 $('embeds').removeChild(module); |
| 22 } | 27 } |
| 23 | 28 |
| 24 | 29 |
| 25 function badLoadTest(tester, id, src, error_string) { | 30 function badLoadTest(tester, id, src, type, error_string) { |
| 26 tester.addAsyncTest(id, function(test){ | 31 tester.addAsyncTest(id, function(test){ |
| 27 var module = createModule(id, src); | 32 var module = createModule(id, src, type); |
| 28 | 33 |
| 29 test.expectEvent(module, 'load', function(e) { | 34 test.expectEvent(module, 'load', function(e) { |
| 30 removeModule(module); | 35 removeModule(module); |
| 31 test.fail('Module loaded successfully.'); | 36 test.fail('Module loaded successfully.'); |
| 32 }); | 37 }); |
| 33 test.expectEvent(module, 'error', function(e) { | 38 test.expectEvent(module, 'error', function(e) { |
| 34 test.assertEqual(module.readyState, 4); | 39 test.assertEqual(module.readyState, 4); |
| 35 test.assertEqual(module.lastError, error_string); | 40 test.assertEqual(module.lastError, error_string); |
| 36 test.expectEvent(module, 'loadend', function(e) { | 41 test.expectEvent(module, 'loadend', function(e) { |
| 37 removeModule(module); | 42 removeModule(module); |
| 38 test.pass(); | 43 test.pass(); |
| 39 }); | 44 }); |
| 40 }); | 45 }); |
| 41 addModule(module); | 46 addModule(module); |
| 42 }); | 47 }); |
| 43 } | 48 } |
| OLD | NEW |