Commit 0ec1336e authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Gallery: Closure compile entry_list_watcher_unittest.js.

Bug: 867700
Change-Id: I42172daa50afe7a88b4ae2913371884504d46763
Reviewed-on: https://chromium-review.googlesource.com/1179117
Commit-Queue: Trent Apted <tapted@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584009}
parent b6819a21
......@@ -30,8 +30,7 @@ IN_PROC_BROWSER_TEST_F(GalleryJsTest, ImageViewTest) {
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, EntryListWatcherTest) {
RunTest(
base::FilePath(FILE_PATH_LITERAL("entry_list_watcher_unittest.html")));
RunGeneratedTest("/entry_list_watcher_unittest.html");
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, GalleryUtilTest) {
......
......@@ -55,7 +55,19 @@ js_library("entry_list_watcher") {
"//ui/webui/resources/js:assert",
"//ui/webui/resources/js/cr/ui:array_data_model",
]
externs_list = [ "$externs_path/file_manager_private.js" ]
externs_list = [
"$externs_path/file_system_provider.js",
"$externs_path/file_manager_private.js",
]
}
js_library("entry_list_watcher_unittest") {
deps = [
":entry_list_watcher",
"../../file_manager/common/js:mock_entry",
"../../file_manager/common/js:unittest_util",
"//ui/webui/resources/js:webui_resource_test",
]
}
js_library("error_banner") {
......@@ -207,6 +219,7 @@ js_library("thumbnail_mode") {
js_unit_tests("unit_tests") {
deps = [
":dimmable_ui_controller_unittest",
":entry_list_watcher_unittest",
":gallery_data_model_unittest",
":gallery_util_unittest",
":ribbon_unittest",
......
<!DOCTYPE html>
<!-- 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.
-->
<html>
<body>
<script src="../../../webui/resources/js/cr.js"></script>
<script src="../../../webui/resources/js/cr/event_target.js"></script>
<script src="../../../webui/resources/js/cr/ui/array_data_model.js"></script>
<script src="../../file_manager/common/js/mock_entry.js"></script>
<script src="../../file_manager/common/js/unittest_util.js"></script>
<script src="entry_list_watcher.js"></script>
<script src="entry_list_watcher_unittest.js"></script>
</body>
</html>
......@@ -19,36 +19,59 @@ function webkitResolveLocalFileSystemURL(url, callback) {
name: 'Not found.'
};
callback(null);
};
}
function setUp() {
chrome = {
fileManagerPrivate: {
onDirectoryChanged: new MockAPIEvent(),
addFileWatch: function(entry, callback) {
this.watchedURLs[entry.toURL()] = true;
callback();
},
removeFileWatch: function(entry, callback) {
delete this.watchedURLs[entry.toURL()];
callback();
},
watchedURLs: {}
/**
* Use a map to track watched URLs in the test. This is not normally part of the
* fileManagerPrivate API.
*
* @typedef {Object<string, boolean>}
*/
chrome.fileManagerPrivate.watchedURLs;
/**
* Creates a mock for window.chrome. TODO(tapted): Make this an ES6 class to
* avoid the confusing use of |this| below.
* @constructor
*/
function MockChrome() {
this.fileManagerPrivate = {
onDirectoryChanged: new MockAPIEvent(),
addFileWatch: function(entry, callback) {
this.watchedURLs[entry.toURL()] = true;
callback();
},
runtime: {
// For lastError.
}
removeFileWatch: function(entry, callback) {
delete this.watchedURLs[entry.toURL()];
callback();
},
watchedURLs: {}
};
this.runtime = {}; // For lastError.
}
/**
* Replace the real chrome APIs with a mock while suppressing closure errors.
* This is in its own function to limit the scope of suppressions.
*
* @param {Object} mockChrome
* @suppress {checkTypes|const}
*/
function replaceChromeWithMock() {
chrome = new MockChrome();
}
function setUp() {
replaceChromeWithMock();
mockFileSystem = new MockFileSystem('volumeId', 'filesystem://rootURL');
mockFileSystem.entries['/'] = new MockDirectoryEntry(mockFileSystem, '/');
mockFileSystem.entries['/A.txt'] =
new MockFileEntry(mockFileSystem, '/A.txt', {});
new MockFileEntry(mockFileSystem, '/A.txt');
mockFileSystem.entries['/B.txt'] =
new MockFileEntry(mockFileSystem, '/B.txt', {});
new MockFileEntry(mockFileSystem, '/B.txt');
mockFileSystem.entries['/C/'] = new MockDirectoryEntry(mockFileSystem, '/C/');
mockFileSystem.entries['/C/D.txt'] =
new MockFileEntry(mockFileSystem, '/C/D.txt', {});
new MockFileEntry(mockFileSystem, '/C/D.txt');
}
function testAddWatcher() {
......@@ -97,8 +120,8 @@ function testEntryRemoved(callback) {
assertArrayEquals(
['filesystem://rootURL/'],
Object.keys(chrome.fileManagerPrivate.watchedURLs));
chrome.fileManagerPrivate.onDirectoryChanged.dispatch(
{entry: mockFileSystem.entries['/']});
/** @type{MockAPIEvent} */ (chrome.fileManagerPrivate.onDirectoryChanged)
.dispatch({entry: mockFileSystem.entries['/']});
reportPromise(splicedPromise.then(function(event) {
assertEquals(1, event.removed.length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment