libdot: storage: chrome: add write retries to removeItem(s)

These APIs count against the write quota too.

Bug: b/40874862
Change-Id: I82e17c3f359cf9717661b31e3eaf3b3d1766de34
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/7475471
Reviewed-by: Joel Hockey <joelhockey@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/libdot/js/lib_storage_chrome.js b/libdot/js/lib_storage_chrome.js
index 52d36e9..09f6fab 100644
--- a/libdot/js/lib_storage_chrome.js
+++ b/libdot/js/lib_storage_chrome.js
@@ -99,6 +99,8 @@
    * @override
    */
   async removeItems(keys) {
-    return this.storage_.remove(keys);
+    return retryQuotaErrors(
+        () => this.storage_.remove(keys),
+        this.quotaRetryDelay_);
   }
 };
diff --git a/libdot/js/lib_storage_chrome_tests.js b/libdot/js/lib_storage_chrome_tests.js
index cfe6803..0f6bf73 100644
--- a/libdot/js/lib_storage_chrome_tests.js
+++ b/libdot/js/lib_storage_chrome_tests.js
@@ -114,6 +114,8 @@
   async remove(keys) {
     assert.equal(arguments.length, 1);
 
+    this.maybeFakeQuotaWriteError_();
+
     if (!Array.isArray(keys)) {
       keys = [keys];
     }
@@ -169,3 +171,29 @@
   assert.isFalse(this.fake.quotaWriteError);
   assert.equal(await this.storage.getItem('foo'), 3);
 });
+
+/**
+ * Verify removeItem quota writes are retried.
+ */
+it('quota-write-retry removeItem', async function() {
+  await this.storage.setItem('foo', 1);
+  assert.equal(await this.storage.getItem('foo'), 1);
+
+  this.fake.quotaWriteError = true;
+  await this.storage.removeItem('foo');
+  assert.isFalse(this.fake.quotaWriteError);
+  assert.isUndefined(await this.storage.getItem('foo'));
+});
+
+/**
+ * Verify removeItems quota writes are retried.
+ */
+it('quota-write-retry removeItems', async function() {
+  await this.storage.setItem('foo', 1);
+  assert.equal(await this.storage.getItem('foo'), 1);
+
+  this.fake.quotaWriteError = true;
+  await this.storage.removeItems(['foo']);
+  assert.isFalse(this.fake.quotaWriteError);
+  assert.isUndefined(await this.storage.getItem('foo'));
+});