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

Unified Diff: chrome/test/data/webrtc/indexeddb.js

Issue 1909923002: Making RTCCertificate cloneable (WIP). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Derp! Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/test/data/webrtc/peerconnection.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webrtc/indexeddb.js
diff --git a/chrome/test/data/webrtc/indexeddb.js b/chrome/test/data/webrtc/indexeddb.js
new file mode 100644
index 0000000000000000000000000000000000000000..ef15c05b26260b4afe47c7d9537a538e5a11da14
--- /dev/null
+++ b/chrome/test/data/webrtc/indexeddb.js
@@ -0,0 +1,146 @@
+/**
+ * Copyright 2016 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+var kDatabaseName = 'WebRTC-Database';
+
+/**
+ * The one and only |IDBDatabase| in this page.
+ * @private
+ */
+var gDatabase = null;
+
+var gCertificate = null;
+var gCertificateClone = null;
+
+// Public interface to tests. These are expected to be called with
+// ExecuteJavascript invocations from the browser tests and will return answers
+// through the DOM automation controller.
+
+function openDatabase() {
+ if (gDatabase !== null)
+ throw failTest('The database is already open.');
+ var reqOpen = indexedDB.open(kDatabaseName);
+ reqOpen.onupgradeneeded = function() {
+ // This happens before |onsuccess| if the database is new or its version is
+ // updated. Create object stores.
+ var db = reqOpen.result;
+ var certStore = db.createObjectStore('certificates', { keyPath: 'id' });
+ certStore.createIndex('by_id', 'id');
+ };
+ reqOpen.onsuccess = function() {
+ if (gDatabase !== null)
+ throw failTest('The database is already open.');
+ gDatabase = reqOpen.result;
+ returnToTest('ok-database-opened');
+ }
+ reqOpen.onerror = function() {
+ throw failTest('The database could not be opened. Error: ' + reqOpen.error);
+ }
+}
+
+function closeDatabase() {
+ if (gDatabase === null)
+ throw failTest('The database is already closed.');
+ gDatabase.close();
+ gDatabase = null;
+ returnToTest('ok-database-closed');
+}
+
+function deleteDatabase() {
+ if (gDatabase !== null)
+ throw failTest('The database should be closed before deleting.');
+ var reqDelete = indexedDB.deleteDatabase(kDatabaseName);
+ reqDelete.onsuccess = function () {
+ returnToTest('ok-database-deleted');
+ };
+ reqDelete.onerror = function () {
+ throw failTest(
+ 'The database could not be deleted. Error: ' + reqDelete.error);
+ };
+}
+
+function generateAndCloneCertificate(keygenAlgorithm) {
+ RTCPeerConnection.generateCertificate(keygenAlgorithm).then(
+ function(certificate) {
+ gCertificate = certificate;
+ cloneCertificate(gCertificate,
+ function(clone) {
+ gCertificateClone = clone;
+ if (!gCertificate.equals(gCertificateClone)) {
+ throw failTest(
+ 'The cloned certificate is not equal to its original.');
+ }
+ returnToTest('ok-generated-and-cloned');
+ },
+ function() {
+ throw failTest('Error cloning certificate.');
+ });
+ },
+ function() {
+ failTest('Certificate generation failed. keygenAlgorithm: ' +
+ JSON.stringify(keygenAlgorithm));
+ });
+}
+
+// Public helper functions to test functions. Expected to indirectly be called
+// with ExecuteJavascript from browser tests, but does not do |returnToTest|.
+
+function saveCertificate(certificate, onsuccess, onerror) {
+ if (gDatabase === null)
+ throw failTest('The database is not open.');
+
+ var certTrans = gDatabase.transaction('certificates', 'readwrite');
+ var certStore = certTrans.objectStore('certificates');
+ var certPut = certStore.put({
+ id:0,
+ cert:certificate
+ });
+
+ certPut.onsuccess = function() {
+ onsuccess();
+ };
+ certPut.onerror = function() {
+ onerror(certPut.error);
+ };
+}
+
+function loadCertificate(onsuccess, onerror) {
+ if (gDatabase === null)
+ throw failTest('The database is not open.');
+
+ var certTrans = gDatabase.transaction('certificates', 'readonly');
+ var certStore = certTrans.objectStore('certificates');
+ var certById = certStore.index('by_id');
+
+ var reqGet = certById.get(0);
+ reqGet.onsuccess = function() {
+ var match = reqGet.result;
+ if (match !== undefined) {
+ onsuccess(match.cert);
+ } else {
+ onsuccess(null);
+ }
+ };
+ reqGet.onerror = function() {
+ onerror(reqGet.error);
+ };
+}
+
+function cloneCertificate(certificate, onsuccess, onerror) {
+ saveCertificate(certificate,
+ function() {
+ // Certificate saved successfully, now load it.
+ loadCertificate(
+ function(clone) {
+ // Load successful.
+ if (clone === null)
+ throw failTest('loadCertificate returned a null certificate.');
+ onsuccess(clone);
+ },
+ onerror);
+ },
+ onerror);
+}
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/test/data/webrtc/peerconnection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698