Upgrade gr-storage for use with editable content

New functionality will be utilized in a descendant change.

Bug: Issue 6309
Change-Id: I33e004f6637206b6710e3ee2b7e661bd5d803016
diff --git a/polygerrit-ui/app/elements/shared/gr-storage/gr-storage_test.html b/polygerrit-ui/app/elements/shared/gr-storage/gr-storage_test.html
index ce8ec20..b1a77c7 100644
--- a/polygerrit-ui/app/elements/shared/gr-storage/gr-storage_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-storage/gr-storage_test.html
@@ -33,6 +33,7 @@
 <script>
   suite('gr-storage tests', () => {
     let element;
+    let sandbox;
 
     function mockStorage(opt_quotaExceeded) {
       return {
@@ -48,9 +49,12 @@
 
     setup(() => {
       element = fixture('basic');
+      sandbox = sinon.sandbox.create();
       element._storage = mockStorage();
     });
 
+    teardown(() => sandbox.restore());
+
     test('storing, retrieving and erasing drafts', () => {
       const changeNum = 1234;
       const patchNum = 5;
@@ -100,7 +104,7 @@
       // Make sure that the call to cleanup doesn't get throttled.
       element._lastCleanup = 0;
 
-      const cleanupSpy = sinon.spy(element, '_cleanupDrafts');
+      const cleanupSpy = sandbox.spy(element, '_cleanupItems');
 
       // Create a message with a timestamp that is a second behind the max age.
       element._storage.setItem(key, JSON.stringify({
@@ -114,8 +118,6 @@
       assert.isTrue(cleanupSpy.called);
       assert.isNotOk(draft);
       assert.isNotOk(element._storage.getItem(key));
-
-      cleanupSpy.restore();
     });
 
     test('_getDraftKey', () => {
@@ -160,5 +162,28 @@
       assert.isTrue(element._exceededQuota);
       assert.isNotOk(element._storage.getItem(key));
     });
+
+    test('editable content items', () => {
+      const cleanupStub = sandbox.stub(element, '_cleanupItems');
+      const key = 'testKey';
+      const computedKey = element._getEditableContentKey(key);
+      // Key correctly computed.
+      assert.equal(computedKey, 'editablecontent:testKey');
+
+      element.setEditableContentItem(key, 'my content');
+
+      // Setting the draft stores it under the expected key.
+      let item = element._storage.getItem(computedKey);
+      assert.isOk(item);
+      assert.equal(JSON.parse(item).message, 'my content');
+      assert.isOk(JSON.parse(item).updated);
+
+      // getEditableContentItem performs as expected.
+      item = element.getEditableContentItem(key);
+      assert.isOk(item);
+      assert.equal(item.message, 'my content');
+      assert.isOk(item.updated);
+      assert.isTrue(cleanupStub.called);
+    });
   });
 </script>