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) { ...@@ -30,8 +30,7 @@ IN_PROC_BROWSER_TEST_F(GalleryJsTest, ImageViewTest) {
} }
IN_PROC_BROWSER_TEST_F(GalleryJsTest, EntryListWatcherTest) { IN_PROC_BROWSER_TEST_F(GalleryJsTest, EntryListWatcherTest) {
RunTest( RunGeneratedTest("/entry_list_watcher_unittest.html");
base::FilePath(FILE_PATH_LITERAL("entry_list_watcher_unittest.html")));
} }
IN_PROC_BROWSER_TEST_F(GalleryJsTest, GalleryUtilTest) { IN_PROC_BROWSER_TEST_F(GalleryJsTest, GalleryUtilTest) {
......
...@@ -55,7 +55,19 @@ js_library("entry_list_watcher") { ...@@ -55,7 +55,19 @@ js_library("entry_list_watcher") {
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert",
"//ui/webui/resources/js/cr/ui:array_data_model", "//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") { js_library("error_banner") {
...@@ -207,6 +219,7 @@ js_library("thumbnail_mode") { ...@@ -207,6 +219,7 @@ js_library("thumbnail_mode") {
js_unit_tests("unit_tests") { js_unit_tests("unit_tests") {
deps = [ deps = [
":dimmable_ui_controller_unittest", ":dimmable_ui_controller_unittest",
":entry_list_watcher_unittest",
":gallery_data_model_unittest", ":gallery_data_model_unittest",
":gallery_util_unittest", ":gallery_util_unittest",
":ribbon_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) { ...@@ -19,36 +19,59 @@ function webkitResolveLocalFileSystemURL(url, callback) {
name: 'Not found.' name: 'Not found.'
}; };
callback(null); callback(null);
}; }
function setUp() { /**
chrome = { * Use a map to track watched URLs in the test. This is not normally part of the
fileManagerPrivate: { * fileManagerPrivate API.
onDirectoryChanged: new MockAPIEvent(), *
addFileWatch: function(entry, callback) { * @typedef {Object<string, boolean>}
this.watchedURLs[entry.toURL()] = true; */
callback(); chrome.fileManagerPrivate.watchedURLs;
},
removeFileWatch: function(entry, callback) { /**
delete this.watchedURLs[entry.toURL()]; * Creates a mock for window.chrome. TODO(tapted): Make this an ES6 class to
callback(); * avoid the confusing use of |this| below.
}, * @constructor
watchedURLs: {} */
function MockChrome() {
this.fileManagerPrivate = {
onDirectoryChanged: new MockAPIEvent(),
addFileWatch: function(entry, callback) {
this.watchedURLs[entry.toURL()] = true;
callback();
}, },
runtime: { removeFileWatch: function(entry, callback) {
// For lastError. 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 = new MockFileSystem('volumeId', 'filesystem://rootURL');
mockFileSystem.entries['/'] = new MockDirectoryEntry(mockFileSystem, '/'); mockFileSystem.entries['/'] = new MockDirectoryEntry(mockFileSystem, '/');
mockFileSystem.entries['/A.txt'] = mockFileSystem.entries['/A.txt'] =
new MockFileEntry(mockFileSystem, '/A.txt', {}); new MockFileEntry(mockFileSystem, '/A.txt');
mockFileSystem.entries['/B.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/'] = new MockDirectoryEntry(mockFileSystem, '/C/');
mockFileSystem.entries['/C/D.txt'] = mockFileSystem.entries['/C/D.txt'] =
new MockFileEntry(mockFileSystem, '/C/D.txt', {}); new MockFileEntry(mockFileSystem, '/C/D.txt');
} }
function testAddWatcher() { function testAddWatcher() {
...@@ -97,8 +120,8 @@ function testEntryRemoved(callback) { ...@@ -97,8 +120,8 @@ function testEntryRemoved(callback) {
assertArrayEquals( assertArrayEquals(
['filesystem://rootURL/'], ['filesystem://rootURL/'],
Object.keys(chrome.fileManagerPrivate.watchedURLs)); Object.keys(chrome.fileManagerPrivate.watchedURLs));
chrome.fileManagerPrivate.onDirectoryChanged.dispatch( /** @type{MockAPIEvent} */ (chrome.fileManagerPrivate.onDirectoryChanged)
{entry: mockFileSystem.entries['/']}); .dispatch({entry: mockFileSystem.entries['/']});
reportPromise(splicedPromise.then(function(event) { reportPromise(splicedPromise.then(function(event) {
assertEquals(1, event.removed.length); 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