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

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: moved frame.html 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) => {
jsbell 2017/03/22 17:41:07 nit: remove space between ( ( (not new in this CL
Mircea Trofin 2017/03/22 23:31:15 Done.
11 createWasmModule() 11 createWasmModule()
12 .then (mod => { 12 .then (mod => {
jsbell 2017/03/22 17:41:07 nit: remove space between then ( (not new in this
Mircea Trofin 2017/03/22 23:31:15 Done.
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);
jsbell 2017/03/22 17:41:06 Hrm... I would have expected this to throw DataClo
Mircea Trofin 2017/03/22 23:31:15 Acknowledged. Will update once we get clarity over
25 tx.oncomplete = function() { 25 tx.oncomplete = function() {
jsbell 2017/03/22 17:41:07 not new in this CL, but maybe add: tx.onabort =
Mircea Trofin 2017/03/22 23:31:15 Done.
26 resolve(); 26 resolve();
27 }; 27 };
28 }; 28 };
29 }; 29 };
30 }) 30 })
31 .catch(error => reject(error)); 31 .catch(error => reject(error));
32 }); 32 });
33 } 33 }
34 34
35 var kErrorMsg = "failed to retrieve object";
36
35 function loadFromIndexedDB(prev) { 37 function loadFromIndexedDB(prev) {
36 return new Promise(resolve => { 38 return new Promise((resolve, reject) => {
37 prev.then(() => { 39 prev.then(() => {
38 var open_request = indexedDB.open(db_name); 40 var open_request = indexedDB.open(db_name);
39 open_request.onsuccess = function() { 41 open_request.onsuccess = function() {
40 var db = open_request.result; 42 var db = open_request.result;
41 var tx = db.transaction(obj_store); 43 var tx = db.transaction(obj_store);
42 var store = tx.objectStore(obj_store); 44 var store = tx.objectStore(obj_store);
43 var get_request = store.get(module_key); 45 var get_request = store.get(module_key);
44 get_request.onsuccess = function() { 46 get_request.onsuccess = function() {
45 var mod = get_request.result; 47 var mod = get_request.result;
46 var instance = new WebAssembly.Instance(get_request.result); 48 if (mod instanceof WebAssembly.Module) {
47 resolve(instance.exports.increment(1)); 49 var instance = new WebAssembly.Instance(mod);
jsbell 2017/03/22 17:41:06 Since the constructor may throw, maybe wrap in a t
Mircea Trofin 2017/03/22 23:31:15 Done.
50 resolve(instance.exports.increment(1));
51 } else {
52 reject(new Error(kErrorMsg));
jsbell 2017/03/22 17:41:07 We should be asserting something about what `mod`
Mircea Trofin 2017/03/22 23:31:15 Done.
53 }
48 }; 54 };
49 }; 55 };
50 }); 56 });
51 }); 57 });
52 } 58 }
53 59
54 function TestIndexedDBLoadStore() { 60 function TestIndexedDBLoadStoreSecure() {
55 return loadFromIndexedDB(createAndSaveToIndexedDB()) 61 if (window.location.origin != get_host_info().AUTHENTICATED_ORIGIN) {
56 .then((res) => assert_equals(res, 2)) 62 window.location = get_host_info().AUTHENTICATED_ORIGIN + window.location.pat hname;
57 .catch(error => assert_unreached(error)); 63 } else {
64 return loadFromIndexedDB(createAndSaveToIndexedDB())
65 .then((res) => assert_equals(res, 2))
jsbell 2017/03/22 17:41:07 I don't think you want to use .then().catch() here
Mircea Trofin 2017/03/22 23:31:15 Done.
66 .catch(error => assert_unreached(error));
67 }
58 } 68 }
69
70 function TestIndexedDBLoadStoreInsecure() {
71 if (window.location.origin != get_host_info().UNAUTHENTICATED_ORIGIN) {
72 window.location = get_host_info().UNAUTHENTICATED_ORIGIN + window.location.p athname;
73 } else {
74 return loadFromIndexedDB(createAndSaveToIndexedDB())
75 .then(assert_unreached)
jsbell 2017/03/22 17:41:07 same as above re: two argument form of then()
Mircea Trofin 2017/03/22 23:31:15 Done.
76 .catch(error => assert_equals(error.message, kErrorMsg));
77 }
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698