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 5// Helper routines for generating bad load tests. 6// Webpage must have an 'embeds' div for injecting NaCl modules. 7// Depends on nacltest.js. 8 9function createModule(id, src, type) { 10 return createNaClEmbed({ 11 id: id, 12 src: src, 13 width: 100, 14 height: 20, 15 type: type 16 }); 17} 18 19 20function addModule(module) { 21 $('embeds').appendChild(module); 22} 23 24 25function removeModule(module) { 26 $('embeds').removeChild(module); 27} 28 29 30function badLoadTest(tester, id, src, type, error_string) { 31 tester.addAsyncTest(id, function(test){ 32 var module = createModule(id, src, type); 33 34 test.expectEvent(module, 'load', function(e) { 35 removeModule(module); 36 test.fail('Module loaded successfully.'); 37 }); 38 test.expectEvent(module, 'error', function(e) { 39 test.assertEqual(module.readyState, 4); 40 test.assertEqual(module.lastError, error_string); 41 test.expectEvent(module, 'loadend', function(e) { 42 removeModule(module); 43 test.pass(); 44 }); 45 }); 46 addModule(module); 47 }); 48} 49