Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/wasm/wasm_indexeddb_test.js

Issue 2749503002: [wasm] enable wasm structured cloning in specific cases (Closed)
Patch Set: fix negative test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var db_name = 'db'; 5 var db_name = 'db';
6 var obj_store = 'store'; 6 var obj_store = 'store';
7 var module_key = 'my_module'; 7 var module_key = 'my_module';
8 8
9 function createAndSaveToIndexedDB() { 9 function createAndSaveToIndexedDB() {
10 return new Promise( (resolve, reject) => { 10 return new Promise((resolve, reject) => {
11 createWasmModule() 11 createWasmModule()
12 .then (mod => { 12 .then(mod => {
13 var delete_request = indexedDB.deleteDatabase(db_name); 13 var delete_request = indexedDB.deleteDatabase(db_name);
14 delete_request.onsuccess = function() { 14 delete_request.onsuccess = function() {
15 var open_request = indexedDB.open(db_name); 15 var open_request = indexedDB.open(db_name);
16 open_request.onupgradeneeded = function() { 16 open_request.onupgradeneeded = function() {
17 var db = open_request.result; 17 var db = open_request.result;
18 db.createObjectStore(obj_store); 18 db.createObjectStore(obj_store);
19 }; 19 };
20 open_request.onsuccess = function() { 20 open_request.onsuccess = function() {
21 var db = open_request.result; 21 var db = open_request.result;
22 var tx = db.transaction(obj_store, 'readwrite'); 22 var tx = db.transaction(obj_store, 'readwrite');
23 var store = tx.objectStore(obj_store); 23 var store = tx.objectStore(obj_store);
24 store.put(mod, module_key); 24 store.put(mod, module_key);
25 tx.oncomplete = function() { 25 tx.oncomplete = function() {
26 resolve(); 26 resolve();
27 }; 27 };
28 tx.onabort = function() {
29 reject(transaction.error);
30 };
28 }; 31 };
29 }; 32 };
30 }) 33 })
31 .catch(error => reject(error)); 34 .catch(error => reject(error));
32 }); 35 });
33 } 36 }
34 37
38 var kErrorMsg = "failed to retrieve object";
39
35 function loadFromIndexedDB(prev) { 40 function loadFromIndexedDB(prev) {
36 return new Promise(resolve => { 41 return new Promise((resolve, reject) => {
37 prev.then(() => { 42 prev.then(() => {
38 var open_request = indexedDB.open(db_name); 43 var open_request = indexedDB.open(db_name);
39 open_request.onsuccess = function() { 44 open_request.onsuccess = function() {
40 var db = open_request.result; 45 var db = open_request.result;
41 var tx = db.transaction(obj_store); 46 var tx = db.transaction(obj_store);
42 var store = tx.objectStore(obj_store); 47 var store = tx.objectStore(obj_store);
43 var get_request = store.get(module_key); 48 var get_request = store.get(module_key);
44 get_request.onsuccess = function() { 49 get_request.onsuccess = function() {
45 var mod = get_request.result; 50 var mod = get_request.result;
46 var instance = new WebAssembly.Instance(get_request.result); 51 if (mod instanceof WebAssembly.Module) {
47 resolve(instance.exports.increment(1)); 52 try {
53 var instance = new WebAssembly.Instance(mod);
54 } catch(e) {
55 reject(e);
jsbell 2017/03/24 16:51:13 Should return here, or move the resolve into the t
Mircea Trofin 2017/03/24 22:52:07 Done.
56 }
57 resolve(instance.exports.increment(1));
58 } else {
59 assert_equals(mod, null);
60 reject(new Error(kErrorMsg));
61 }
48 }; 62 };
49 }; 63 };
50 }); 64 });
51 }); 65 });
52 } 66 }
53 67
54 function TestIndexedDBLoadStore() { 68 function TestIndexedDBLoadStoreSecure() {
55 return loadFromIndexedDB(createAndSaveToIndexedDB()) 69 if (window.location.origin != get_host_info().AUTHENTICATED_ORIGIN) {
56 .then((res) => assert_equals(res, 2)) 70 window.location = get_host_info().AUTHENTICATED_ORIGIN + window.location.pat hname;
57 .catch(error => assert_unreached(error)); 71 } else {
72 return loadFromIndexedDB(createAndSaveToIndexedDB())
73 .then(res => assert_equals(res, 2),
74 error => assert_unreached(error));
75 }
58 } 76 }
77
78 function TestIndexedDBLoadStoreInsecure() {
79 if (window.location.origin != get_host_info().UNAUTHENTICATED_ORIGIN) {
80 window.location = get_host_info().UNAUTHENTICATED_ORIGIN + window.location.p athname;
81 } else {
82 return loadFromIndexedDB(createAndSaveToIndexedDB())
83 .then(assert_unreached,
84 error => assert_equals(error.message, kErrorMsg));
85 }
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698