test_storage_ext.js (2063B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 // This file tests basics of loading SQLite extension. 6 7 const VALID_EXTENSION_NAME = "fts5"; 8 9 add_setup(async function () { 10 cleanup(); 11 }); 12 13 add_task(async function test_valid_call() { 14 info("Testing valid call"); 15 let conn = getOpenedUnsharedDatabase(); 16 17 await new Promise((resolve, reject) => { 18 conn.loadExtension(VALID_EXTENSION_NAME, status => { 19 if (Components.isSuccessCode(status)) { 20 resolve(); 21 } else { 22 reject(status); 23 } 24 }); 25 }); 26 27 cleanup(); 28 }); 29 30 add_task(async function test_invalid_calls() { 31 info("Testing invalid calls"); 32 let conn = getOpenedUnsharedDatabase(); 33 34 await Assert.rejects( 35 new Promise((resolve, reject) => { 36 conn.loadExtension("unknown", status => { 37 if (Components.isSuccessCode(status)) { 38 resolve(); 39 } else { 40 reject(status); 41 } 42 }); 43 }), 44 /NS_ERROR_ILLEGAL_VALUE/, 45 "Should fail loading unknown extension" 46 ); 47 48 cleanup(); 49 50 await Assert.rejects( 51 new Promise((resolve, reject) => { 52 conn.loadExtension(VALID_EXTENSION_NAME, status => { 53 if (Components.isSuccessCode(status)) { 54 resolve(); 55 } else { 56 reject(status); 57 } 58 }); 59 }), 60 /NS_ERROR_NOT_INITIALIZED/, 61 "Should fail loading extension on a closed connection" 62 ); 63 }); 64 65 add_task(async function test_more_invalid_calls() { 66 let conn = getOpenedUnsharedDatabase(); 67 let promiseClosed = asyncClose(conn); 68 69 await Assert.rejects( 70 new Promise((resolve, reject) => { 71 conn.loadExtension(VALID_EXTENSION_NAME, status => { 72 if (Components.isSuccessCode(status)) { 73 resolve(); 74 } else { 75 reject(status); 76 } 77 }); 78 }), 79 /NS_ERROR_NOT_INITIALIZED/, 80 "Should fail loading extension on a closing connection" 81 ); 82 83 await promiseClosed; 84 });