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

Unified Diff: chrome/test/data/file_manager/unit_tests/import_history_unittest.js

Issue 677213002: Add ImportHistory class and RecordStorage class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address an outstanding TODO Created 6 years, 2 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
Index: chrome/test/data/file_manager/unit_tests/import_history_unittest.js
diff --git a/chrome/test/data/file_manager/unit_tests/import_history_unittest.js b/chrome/test/data/file_manager/unit_tests/import_history_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..b0fece8ee9984c2e014f0fec1fc97d7df8572e96
--- /dev/null
+++ b/chrome/test/data/file_manager/unit_tests/import_history_unittest.js
@@ -0,0 +1,161 @@
+// Copyright 2014 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.
+'use strict';
+
+/** @const {string} */
+var GOOGLE_DRIVE = 'Google Drive';
+
+/**
+ * Space Cloud: Your source for interstellar cloud storage.
+ * @const {string}
+ */
+var SPACE_CLOUD = 'Space Cloud';
+
+/** @type {!TestFileSystem|undefined} */
+var testFileSystem;
+
+/** @type {!MockFileEntry|undefined} */
+var testFileEntry;
+
+/** @type {!RecordStorage|undefined} */
+var storage;
+
+/** @type {!Promise.<ImportHistory>|undefined} */
+var historyLoader;
+
+// Set up the test components.
+function setUp() {
+ testFileSystem = new TestFileSystem('abc-123');
+ testFileEntry = new MockFileEntry(
+ testFileSystem,
+ 'hey/there', {
+ size: 1234,
+ modificationTime: 'Thursday, very late'
mtomasz 2014/10/29 01:10:40 nit: Can we use a Date object?
Steve McKay 2014/10/29 16:57:21 Done (in a const), but the type is still string.
+ });
+
+ storage = new TestRecordStorage();
+ historyLoader = ImportHistory.load(storage);
+}
+
+/**
+ * In-memory test implementation of {@code RecordStorage}.
+ *
+ * @constructor
+ * @implements {RecordStorage}
+ */
+var TestRecordStorage = function() {
+
+ // Pre-populate the store with some "previously written" data <wink>.
+ /** @private {!Array.<!Array.<string>>} */
+ this.records_ = [
+ ['Thursday, very late_1234', GOOGLE_DRIVE],
+ ['99999_99999', SPACE_CLOUD]
+ ];
+
+ /**
+ * @override
+ * @this {TestRecordStorage}
+ */
+ this.readAll = function() {
+ return Promise.resolve(this.records_);
+ };
+
+ /**
+ * @override
+ * @this {TestRecordStorage}
+ */
+ this.write = function(record) {
+ this.records_.push(record);
+ return Promise.resolve();
+ };
+};
+
+/**
+ * @return {!Promise.<RecordStorage>}
+ */
+function createRealStorage() {
+ return new Promise(
+ function(resolve, reject) {
+ var onFilesystemReady = function(fileSystem) {
+ fileSystem.root.getFile(
+ 'test.data',
+ {
+ create: true,
+ exclusive: false
+ },
+ function(fileEntry) {
+ resolve(new FileEntryRecordStorage(fileEntry));
+ },
+ reject);
+ };
+
+ window.webkitRequestFileSystem(
+ TEMPORARY,
+ 1024 * 1024,
+ onFilesystemReady,
+ reject);
+ });
+}
+
+function testRecordStorage(callback) {
mtomasz 2014/10/29 01:10:40 nit: Shall we add jsdoc to these functions?
Steve McKay 2014/10/29 16:57:21 I've always been of the opinion that tests should
+ createRealStorage()
+ .then(
+ function(storage) {
+ storage.write(['abc', '123']).then(
+ function() {
+ storage.readAll().then(
+ function(records) {
+ callback(/* error */ records.length != 1);
+ },
+ callback);
+ });
+ },
+ callback)
+ .catch(handleError_.bind(callback));
+}
+
+function testHistoryNotImported(callback) {
+ // TestRecordWriter is pre-configured with a Space Cloud entry
+ // but not for this file.
+ historyLoader.then(
+ function(testHistory) {
+ testHistory.wasImported(testFileEntry, SPACE_CLOUD).then(
+ function(result) {
+ callback(/* error */ result);
+ });
+ })
+ .catch(handleError_.bind(callback));
+}
+
+function testHistoryLoadsStoredRecords(callback) {
+ // TestRecordWriter is pre-configured with this entry.
+ historyLoader.then(
+ function(testHistory) {
+ testHistory.wasImported(testFileEntry, GOOGLE_DRIVE).then(
+ function(result) {
+ callback(/* error */ !result);
+ });
+ })
+ .catch(handleError_.bind(callback));
+}
+
+function testHistoryUpdates(callback) {
+ historyLoader.then(
+ function(testHistory) {
+ testHistory.markImported(testFileEntry, SPACE_CLOUD).then(
+ function() {
+ testHistory.wasImported(testFileEntry, SPACE_CLOUD).then(
+ function(result) {
+ callback(/* error */ !result);
+ });
+ });
+ })
+ .catch(handleError_.bind(callback));
+}
+
mtomasz 2014/10/29 01:10:40 nit: \n\n -> \n
Steve McKay 2014/10/29 16:57:21 Done.
+
+function handleError_(callback, error) {
mtomasz 2014/10/29 01:10:40 nit: Private in what scope? Maybe no need for _ at
Steve McKay 2014/10/29 16:57:21 Hmmm. Good point. It would be file scoped if such
+ console.error(error.stack || error);
+ callback(/* error */ true);
+};

Powered by Google App Engine
This is Rietveld 408576698