Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/wasm/wasm_indexeddb_test.js |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/wasm/wasm_indexeddb_test.js b/third_party/WebKit/LayoutTests/http/tests/wasm/wasm_indexeddb_test.js |
| index 4b7cafe45ba38b5e3ee95bc5bb4fb6a20096819b..74bac3a8b905c688f1b1cb669bccf2f83a4476e7 100644 |
| --- a/third_party/WebKit/LayoutTests/http/tests/wasm/wasm_indexeddb_test.js |
| +++ b/third_party/WebKit/LayoutTests/http/tests/wasm/wasm_indexeddb_test.js |
| @@ -7,9 +7,9 @@ var obj_store = 'store'; |
| var module_key = 'my_module'; |
| function createAndSaveToIndexedDB() { |
| - return new Promise( (resolve, reject) => { |
| + return new Promise((resolve, reject) => { |
| createWasmModule() |
| - .then (mod => { |
| + .then(mod => { |
| var delete_request = indexedDB.deleteDatabase(db_name); |
| delete_request.onsuccess = function() { |
| var open_request = indexedDB.open(db_name); |
| @@ -25,6 +25,9 @@ function createAndSaveToIndexedDB() { |
| tx.oncomplete = function() { |
| resolve(); |
| }; |
| + tx.onabort = function() { |
| + reject(transaction.error); |
| + }; |
| }; |
| }; |
| }) |
| @@ -32,8 +35,10 @@ function createAndSaveToIndexedDB() { |
| }); |
| } |
| +var kErrorMsg = "failed to retrieve object"; |
| + |
| function loadFromIndexedDB(prev) { |
| - return new Promise(resolve => { |
| + return new Promise((resolve, reject) => { |
| prev.then(() => { |
| var open_request = indexedDB.open(db_name); |
| open_request.onsuccess = function() { |
| @@ -43,16 +48,40 @@ function loadFromIndexedDB(prev) { |
| var get_request = store.get(module_key); |
| get_request.onsuccess = function() { |
| var mod = get_request.result; |
| - var instance = new WebAssembly.Instance(get_request.result); |
| - resolve(instance.exports.increment(1)); |
| + if (mod instanceof WebAssembly.Module) { |
| + try { |
| + var instance = new WebAssembly.Instance(mod); |
| + } catch(e) { |
| + reject(e); |
| + return; |
| + } |
| + resolve(instance.exports.increment(1)); |
| + } else { |
| + assert_equals(mod, null); |
| + reject(new Error(kErrorMsg)); |
| + } |
| }; |
| }; |
| }); |
| }); |
| } |
| -function TestIndexedDBLoadStore() { |
| - return loadFromIndexedDB(createAndSaveToIndexedDB()) |
| - .then((res) => assert_equals(res, 2)) |
| - .catch(error => assert_unreached(error)); |
| +function TestIndexedDBLoadStoreSecure() { |
| + if (window.location.origin != get_host_info().AUTHENTICATED_ORIGIN) { |
| + window.location = get_host_info().AUTHENTICATED_ORIGIN + window.location.pathname; |
|
jbroman
2017/03/27 18:50:52
Doing this inside the test seems not to match what
Mircea Trofin
2017/03/27 20:52:32
Done.
|
| + } else { |
| + return loadFromIndexedDB(createAndSaveToIndexedDB()) |
| + .then(res => assert_equals(res, 2), |
| + error => assert_unreached(error)); |
| + } |
| +} |
| + |
| +function TestIndexedDBLoadStoreInsecure() { |
| + if (window.location.origin != get_host_info().UNAUTHENTICATED_ORIGIN) { |
| + window.location = get_host_info().UNAUTHENTICATED_ORIGIN + window.location.pathname; |
| + } else { |
| + return loadFromIndexedDB(createAndSaveToIndexedDB()) |
| + .then(assert_unreached, |
| + error => assert_equals(error.message, kErrorMsg)); |
| + } |
| } |