From 4d94a6680a999ed995203a46c8cb905f14bd716a Mon Sep 17 00:00:00 2001 From: "hirono@chromium.org" Date: Tue, 5 Aug 2014 08:20:41 +0000 Subject: Files.app: Add the MockDirectoryEntry class. BUG=315439 TEST=run the js tests. Review URL: https://codereview.chromium.org/439753002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287496 0039d316-1c4b-4281-b951-d872f2087c98 --- .../unit_tests/metadata_cache_unittest.html | 2 +- .../file_manager/unit_tests/mocks/mock_entry.js | 73 ++++++++++++++++++++++ .../unit_tests/mocks/mock_file_entry.js | 24 ------- .../unit_tests/navigation_list_model_unittest.html | 4 +- 4 files changed, 76 insertions(+), 27 deletions(-) create mode 100644 chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js delete mode 100644 chrome/test/data/file_manager/unit_tests/mocks/mock_file_entry.js (limited to 'chrome/test') diff --git a/chrome/test/data/file_manager/unit_tests/metadata_cache_unittest.html b/chrome/test/data/file_manager/unit_tests/metadata_cache_unittest.html index 0732456..97f8fea 100644 --- a/chrome/test/data/file_manager/unit_tests/metadata_cache_unittest.html +++ b/chrome/test/data/file_manager/unit_tests/metadata_cache_unittest.html @@ -8,7 +8,7 @@ - + diff --git a/chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js b/chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js new file mode 100644 index 0000000..5110334 --- /dev/null +++ b/chrome/test/data/file_manager/unit_tests/mocks/mock_entry.js @@ -0,0 +1,73 @@ +// 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. + +/** + * Mock class for FileEntry. + * + * @param {string} volumeId Id of the volume containing the entry. + * @param {string} fullPath Full path for the entry. + * @constructor + */ +function MockFileEntry(volumeId, fullPath) { + this.volumeId = volumeId; + this.fullPath = fullPath; +} + +/** + * Returns fake URL. + * + * @return {string} Fake URL. + */ +MockFileEntry.prototype.toURL = function() { + return 'filesystem:' + this.volumeId + this.fullPath; +}; + +/** + * Mock class for DirectoryEntry. + * + * @param {string} volumeId Id of the volume containing the entry. + * @param {string} fullPath Full path for the entry. + * @param {Object.} contents Map of + * path and MockEntry contained in the directory. + * @constructor + */ +function MockDirectoryEntry(volumeId, fullPath, contents) { + this.contents_ = contents; +} + +/** + * Returns a file under the directory. + * + * @param {string} path Path. + * @param {Object} option Option. + * @param {callback(MockFileEntry)} successCallback Success callback. + * @param {callback(Object)} failureCallback Failure callback; + */ +MockDirectoryEntry.prototype.getFile = function( + path, option, successCallback, failureCallback) { + if (!this.contents_[path]) + failureCallback({name: util.FileError.NOT_FOUND_ERR}); + else if (!(this.contents_[path] instanceof MockFileEntry)) + failureCallback({name: util.FileError.TYPE_MISMATCH_ERR}); + else + successCallback(this.contents_[path]); +}; + +/** + * Returns a directory under the directory. + * + * @param {string} path Path. + * @param {Object} option Option. + * @param {callback(MockDirectoryEntry)} successCallback Success callback. + * @param {callback(Object)} failureCallback Failure callback; + */ +MockDirectoryEntry.prototype.getDirectory = + function(path, option, successCallback, failureCallback) { + if (!this.contents_[path]) + failureCallback({name: util.FileError.NOT_FOUND_ERR}); + else if (!(this.contents_[path] instanceof MockDirectoryEntry)) + failureCallback({name: util.FileError.TYPE_MISMATCH_ERR}); + else + successCallback(this.contents_[path]); +}; diff --git a/chrome/test/data/file_manager/unit_tests/mocks/mock_file_entry.js b/chrome/test/data/file_manager/unit_tests/mocks/mock_file_entry.js deleted file mode 100644 index c16a63d..0000000 --- a/chrome/test/data/file_manager/unit_tests/mocks/mock_file_entry.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2013 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. - -/** - * Mock class for FileEntry. - * - * @param {string} volumeId Id of the volume containing the entry. - * @param {string} fullPath Full path for the entry. - * @constructor - */ -function MockFileEntry(volumeId, fullPath) { - this.volumeId = volumeId; - this.fullPath = fullPath; -} - -/** - * Returns fake URL. - * - * @return {string} Fake URL. - */ -MockFileEntry.prototype.toURL = function() { - return 'filesystem:' + this.volumeId + this.fullPath; -}; diff --git a/chrome/test/data/file_manager/unit_tests/navigation_list_model_unittest.html b/chrome/test/data/file_manager/unit_tests/navigation_list_model_unittest.html index 5b980a8..2cedd98 100644 --- a/chrome/test/data/file_manager/unit_tests/navigation_list_model_unittest.html +++ b/chrome/test/data/file_manager/unit_tests/navigation_list_model_unittest.html @@ -1,5 +1,5 @@ - @@ -20,7 +20,7 @@ - + -- cgit v1.1