Commit f45b8394 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Closure compile device_hander_unittest

 - remove device_handler_unittest.html
 - add BUILD rule to auto-generate this unit test
 - add BUILD rule to Closure compile this unit test
 - rename handler -> deviceHander, use mockChrome
   everywhere and also install it during Setup()
 - remove unused timeoutCallbacks var
 - fix Closure errors, js code auto-format

No change in test behavior, no new tests.

Bug: 908673
No-try: true
Change-Id: I46535df1c77a57c488e40f9c410ca4a62ad73ac5
Reviewed-on: https://chromium-review.googlesource.com/c/1351336
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611000}
parent 620e9b73
...@@ -35,8 +35,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ProgressCenterItemGroupTest) { ...@@ -35,8 +35,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ProgressCenterItemGroupTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, DeviceHandlerTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, DeviceHandlerTest) {
RunTest(base::FilePath( RunGeneratedTest("/background/js/device_handler_unittest.html");
FILE_PATH_LITERAL("background/js/device_handler_unittest.html")));
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationManagerTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationManagerTest) {
......
...@@ -167,6 +167,16 @@ js_library("device_handler") { ...@@ -167,6 +167,16 @@ js_library("device_handler") {
] ]
} }
js_unittest("device_handler_unittest") {
deps = [
":device_handler",
":mock_volume_manager",
"//ui/file_manager/base/js:mock_chrome",
"//ui/file_manager/base/js:test_error_reporting",
"//ui/file_manager/file_manager/common/js:test_importer_common",
]
}
js_library("mock_drive_sync_handler") { js_library("mock_drive_sync_handler") {
testonly = true testonly = true
deps = [ deps = [
...@@ -451,6 +461,7 @@ js_library("volume_manager_util") { ...@@ -451,6 +461,7 @@ js_library("volume_manager_util") {
js_unit_tests("unit_tests") { js_unit_tests("unit_tests") {
deps = [ deps = [
":crostini_unittest", ":crostini_unittest",
":device_handler_unittest",
":duplicate_finder_unittest", ":duplicate_finder_unittest",
":import_history_unittest", ":import_history_unittest",
":media_scanner_unittest", ":media_scanner_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="../../../../../ui/webui/resources/js/assert.js"></script>
<script src="../../../../../ui/webui/resources/js/cr.js"></script>
<script src="../../../../../ui/webui/resources/js/cr/event_target.js"></script>
<script src="../../../../../ui/webui/resources/js/cr/ui/array_data_model.js"></script>
<script src="../../../../../ui/webui/resources/js/load_time_data.js"></script>
<!-- Need to load async_util.js before device_handler.js -->
<script src="../../common/js/async_util.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../../base/js/mock_chrome.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../../base/js/volume_manager_types.js"></script>
<script src="../../common/js/importer_common.js"></script>
<script src="../../common/js/files_app_entry_types.js"></script>
<script src="../../common/js/util.js"></script>
<script src="device_handler.js"></script>
<script src="volume_info_impl.js"></script>
<script src="volume_info_list_impl.js"></script>
<script src="volume_manager_factory.js"></script>
<script src="volume_manager_impl.js"></script>
<script src="volume_manager_util.js"></script>
<script src="mock_volume_manager.js"></script>
<script src="device_handler_unittest.js"></script>
</body>
</html>
...@@ -3,26 +3,18 @@ ...@@ -3,26 +3,18 @@
// found in the LICENSE file. // found in the LICENSE file.
'use strict'; 'use strict';
/**
* Dummy private APIs.
*/
var chrome;
/**
* Callbacks registered by setTimeout.
* @type {Array<function>}
*/
var timeoutCallbacks;
/** @type {!MockVolumeManager} */ /** @type {!MockVolumeManager} */
var volumeManager; var volumeManager;
/** @type {DeviceHandler} */ /** @type {!DeviceHandler} */
var handler; var deviceHandler;
/** Mock chrome APIs. */
var mockChrome;
// Set up the test components. // Set up the test components.
function setUp() { function setUp() {
// Set up string assets. // Set up string assets.
window.loadTimeData.data = { window.loadTimeData.data = {
DEVICE_UNSUPPORTED_MESSAGE: 'DEVICE_UNSUPPORTED: $1', DEVICE_UNSUPPORTED_MESSAGE: 'DEVICE_UNSUPPORTED: $1',
DEVICE_UNKNOWN_MESSAGE: 'DEVICE_UNKNOWN: $1', DEVICE_UNKNOWN_MESSAGE: 'DEVICE_UNKNOWN: $1',
...@@ -31,21 +23,20 @@ function setUp() { ...@@ -31,21 +23,20 @@ function setUp() {
window.loadTimeData.getString = id => { window.loadTimeData.getString = id => {
return window.loadTimeData.data_[id] || id; return window.loadTimeData.data_[id] || id;
}; };
new MockCommandLinePrivate();
volumeManager = new MockVolumeManager();
MockVolumeManager.installMockSingleton(volumeManager);
setupChromeApis(); setupChromeApis();
volumeManager = new MockVolumeManager();
MockVolumeManager.installMockSingleton(volumeManager);
handler = new DeviceHandler(); deviceHandler = new DeviceHandler();
} }
function setUpInIncognitoContext() { function setUpInIncognitoContext() {
chrome.extension.inIncognitoContext = true; mockChrome.extension.inIncognitoContext = true;
} }
function testGoodDevice(callback) { function testGoodDevice(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'success', status: 'success',
volumeMetadata: { volumeMetadata: {
...@@ -58,14 +49,12 @@ function testGoodDevice(callback) { ...@@ -58,14 +49,12 @@ function testGoodDevice(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise.then(function(notifications) {
function(notifications) { assertEquals(1, Object.keys(notifications).length);
assertEquals(1, Object.keys(notifications).length); var options = notifications['deviceNavigation:/device/path'];
var options = notifications['deviceNavigation:/device/path']; assertEquals('REMOVABLE_DEVICE_NAVIGATION_MESSAGE', options.message);
assertEquals( assertTrue(options.isClickable);
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE', options.message); }),
assertTrue(options.isClickable);
}),
callback); callback);
} }
...@@ -83,19 +72,15 @@ function testRemovableMediaDeviceWithImportEnabled(callback) { ...@@ -83,19 +72,15 @@ function testRemovableMediaDeviceWithImportEnabled(callback) {
var resolver = new importer.Resolver(); var resolver = new importer.Resolver();
// Handle media device navigation requests. // Handle media device navigation requests.
handler.addEventListener( deviceHandler.addEventListener(
DeviceHandler.VOLUME_NAVIGATION_REQUESTED, DeviceHandler.VOLUME_NAVIGATION_REQUESTED, function(event) {
function(event) {
resolver.resolve(event); resolver.resolve(event);
}); });
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'success', status: 'success',
volumeMetadata: { volumeMetadata: {volumeId: 'blabbity', deviceType: 'usb'},
volumeId: 'blabbity',
deviceType: 'usb'
},
shouldNotify: true shouldNotify: true
}); });
...@@ -121,19 +106,15 @@ function testMtpMediaDeviceWithImportEnabled(callback) { ...@@ -121,19 +106,15 @@ function testMtpMediaDeviceWithImportEnabled(callback) {
var resolver = new importer.Resolver(); var resolver = new importer.Resolver();
// Handle media device navigation requests. // Handle media device navigation requests.
handler.addEventListener( deviceHandler.addEventListener(
DeviceHandler.VOLUME_NAVIGATION_REQUESTED, DeviceHandler.VOLUME_NAVIGATION_REQUESTED, function(event) {
function(event) {
resolver.resolve(event); resolver.resolve(event);
}); });
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'success', status: 'success',
volumeMetadata: { volumeMetadata: {volumeId: 'blabbity', deviceType: 'mtp'},
volumeId: 'blabbity',
deviceType: 'mtp'
},
shouldNotify: true shouldNotify: true
}); });
...@@ -146,9 +127,9 @@ function testMtpMediaDeviceWithImportEnabled(callback) { ...@@ -146,9 +127,9 @@ function testMtpMediaDeviceWithImportEnabled(callback) {
} }
function testMediaDeviceWithImportDisabled(callback) { function testMediaDeviceWithImportDisabled(callback) {
chrome.commandLinePrivate.cloudImportDisabled = true; mockChrome.commandLinePrivate.cloudImportDisabled = true;
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'success', status: 'success',
volumeMetadata: { volumeMetadata: {
...@@ -162,20 +143,18 @@ function testMediaDeviceWithImportDisabled(callback) { ...@@ -162,20 +143,18 @@ function testMediaDeviceWithImportDisabled(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise.then(function(notifications) {
function(notifications) { assertEquals(1, Object.keys(notifications).length);
assertEquals(1, Object.keys(notifications).length); assertEquals(
assertEquals( 'REMOVABLE_DEVICE_NAVIGATION_MESSAGE',
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE', notifications['deviceNavigation:/device/path'].message,
notifications[ 'Device notification did not have the right message.');
'deviceNavigation:/device/path'].message, }),
'Device notification did not have the right message.');
}),
callback); callback);
} }
function testGoodDeviceNotNavigated() { function testGoodDeviceNotNavigated() {
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'success', status: 'success',
volumeMetadata: { volumeMetadata: {
...@@ -187,12 +166,12 @@ function testGoodDeviceNotNavigated() { ...@@ -187,12 +166,12 @@ function testGoodDeviceNotNavigated() {
shouldNotify: false shouldNotify: false
}); });
assertEquals(0, Object.keys(chrome.notifications.items).length); assertEquals(0, Object.keys(mockChrome.notifications.items).length);
assertFalse(chrome.notifications.resolver.settled); assertFalse(mockChrome.notifications.resolver.settled);
} }
function testGoodDeviceWithBadParent(callback) { function testGoodDeviceWithBadParent(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_internal', status: 'error_internal',
volumeMetadata: { volumeMetadata: {
...@@ -205,18 +184,17 @@ function testGoodDeviceWithBadParent(callback) { ...@@ -205,18 +184,17 @@ function testGoodDeviceWithBadParent(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise.then(function(notifications) {
function(notifications) { assertFalse(!!notifications['device:/device/path']);
assertFalse(!!notifications['device:/device/path']); assertEquals(
assertEquals( 'DEVICE_UNKNOWN: label',
'DEVICE_UNKNOWN: label', notifications['deviceFail:/device/path'].message);
notifications['deviceFail:/device/path'].message); }),
}),
callback); callback);
} }
function testGoodDeviceWithBadParent_DuplicateMount(callback) { function testGoodDeviceWithBadParent_DuplicateMount(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'success', status: 'success',
volumeMetadata: { volumeMetadata: {
...@@ -230,7 +208,7 @@ function testGoodDeviceWithBadParent_DuplicateMount(callback) { ...@@ -230,7 +208,7 @@ function testGoodDeviceWithBadParent_DuplicateMount(callback) {
// Mounting the same device repeatedly should produce only // Mounting the same device repeatedly should produce only
// a single notification. // a single notification.
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'success', status: 'success',
volumeMetadata: { volumeMetadata: {
...@@ -243,18 +221,17 @@ function testGoodDeviceWithBadParent_DuplicateMount(callback) { ...@@ -243,18 +221,17 @@ function testGoodDeviceWithBadParent_DuplicateMount(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise.then(function(notifications) {
function(notifications) { assertEquals(1, Object.keys(notifications).length);
assertEquals(1, Object.keys(notifications).length); assertEquals(
assertEquals( 'REMOVABLE_DEVICE_NAVIGATION_MESSAGE',
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE', notifications['deviceNavigation:/device/path'].message);
notifications['deviceNavigation:/device/path'].message); }),
}),
callback); callback);
} }
function testUnsupportedDevice(callback) { function testUnsupportedDevice(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_unsupported_filesystem', status: 'error_unsupported_filesystem',
volumeMetadata: { volumeMetadata: {
...@@ -267,19 +244,18 @@ function testUnsupportedDevice(callback) { ...@@ -267,19 +244,18 @@ function testUnsupportedDevice(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise.then(function(notifications) {
function(notifications) { assertFalse(!!mockChrome.notifications.items['device:/device/path']);
assertFalse(!!chrome.notifications.items['device:/device/path']); assertEquals(
assertEquals( 'DEVICE_UNSUPPORTED: label',
'DEVICE_UNSUPPORTED: label', mockChrome.notifications.items['deviceFail:/device/path'].message);
chrome.notifications.items['deviceFail:/device/path'].message); }),
}),
callback); callback);
} }
function testUnknownDevice(callback) { function testUnknownDevice(callback) {
// Emulate adding a device which has unknown filesystem. // Emulate adding a device which has unknown filesystem.
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_unknown_filesystem', status: 'error_unknown_filesystem',
volumeMetadata: { volumeMetadata: {
...@@ -292,20 +268,19 @@ function testUnknownDevice(callback) { ...@@ -292,20 +268,19 @@ function testUnknownDevice(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise.then(function(notifications) {
function(notifications) { assertFalse(!!mockChrome.notifications.items['device:/device/path']);
assertFalse(!!chrome.notifications.items['device:/device/path']); var item = mockChrome.notifications.items['deviceFail:/device/path'];
var item = chrome.notifications.items['deviceFail:/device/path']; assertEquals('DEVICE_UNKNOWN_DEFAULT_MESSAGE', item.message);
assertEquals('DEVICE_UNKNOWN_DEFAULT_MESSAGE', item.message); // "Format device" button should appear.
// "Format device" button should appear. assertEquals('DEVICE_UNKNOWN_BUTTON_LABEL', item.buttons[0].title);
assertEquals('DEVICE_UNKNOWN_BUTTON_LABEL', item.buttons[0].title); }),
}),
callback); callback);
} }
function testUnknownReadonlyDevice(callback) { function testUnknownReadonlyDevice(callback) {
// Emulate adding a device which has unknown filesystem but is read-only. // Emulate adding a device which has unknown filesystem but is read-only.
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_unknown_filesystem', status: 'error_unknown_filesystem',
volumeMetadata: { volumeMetadata: {
...@@ -318,19 +293,18 @@ function testUnknownReadonlyDevice(callback) { ...@@ -318,19 +293,18 @@ function testUnknownReadonlyDevice(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise.then(function(notifications) {
function(notifications) { assertFalse(!!mockChrome.notifications.items['device:/device/path']);
assertFalse(!!chrome.notifications.items['device:/device/path']); var item = mockChrome.notifications.items['deviceFail:/device/path'];
var item = chrome.notifications.items['deviceFail:/device/path']; assertEquals('DEVICE_UNKNOWN_DEFAULT_MESSAGE', item.message);
assertEquals('DEVICE_UNKNOWN_DEFAULT_MESSAGE', item.message); // "Format device" button should not appear.
// "Format device" button should not appear. assertFalse(!!item.buttons);
assertFalse(!!item.buttons); }),
}),
callback); callback);
} }
function testUnsupportedWithUnknownParentReplacesNotification() { function testUnsupportedWithUnknownParentReplacesNotification() {
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_internal', status: 'error_internal',
volumeMetadata: { volumeMetadata: {
...@@ -344,9 +318,9 @@ function testUnsupportedWithUnknownParentReplacesNotification() { ...@@ -344,9 +318,9 @@ function testUnsupportedWithUnknownParentReplacesNotification() {
assertEquals( assertEquals(
'DEVICE_UNKNOWN: label', 'DEVICE_UNKNOWN: label',
chrome.notifications.items['deviceFail:/device/path'].message); mockChrome.notifications.items['deviceFail:/device/path'].message);
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_unsupported_filesystem', status: 'error_unsupported_filesystem',
volumeMetadata: { volumeMetadata: {
...@@ -358,14 +332,14 @@ function testUnsupportedWithUnknownParentReplacesNotification() { ...@@ -358,14 +332,14 @@ function testUnsupportedWithUnknownParentReplacesNotification() {
shouldNotify: true shouldNotify: true
}); });
assertEquals(1, Object.keys(chrome.notifications.items).length); assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals( assertEquals(
'DEVICE_UNSUPPORTED: label', 'DEVICE_UNSUPPORTED: label',
chrome.notifications.items['deviceFail:/device/path'].message); mockChrome.notifications.items['deviceFail:/device/path'].message);
} }
function testMountPartialSuccess(callback) { function testMountPartialSuccess(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'success', status: 'success',
volumeMetadata: { volumeMetadata: {
...@@ -378,14 +352,15 @@ function testMountPartialSuccess(callback) { ...@@ -378,14 +352,15 @@ function testMountPartialSuccess(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise
function(notifications) { .then(function(notifications) {
assertEquals(1, Object.keys(notifications).length); assertEquals(1, Object.keys(notifications).length);
assertEquals( assertEquals(
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE', 'REMOVABLE_DEVICE_NAVIGATION_MESSAGE',
notifications['deviceNavigation:/device/path'].message); notifications['deviceNavigation:/device/path'].message);
}).then(function() { })
chrome.fileManagerPrivate.onMountCompleted.dispatch({ .then(function() {
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_unsupported_filesystem', status: 'error_unsupported_filesystem',
volumeMetadata: { volumeMetadata: {
...@@ -396,8 +371,9 @@ function testMountPartialSuccess(callback) { ...@@ -396,8 +371,9 @@ function testMountPartialSuccess(callback) {
}, },
shouldNotify: true shouldNotify: true
}); });
}).then(function() { })
var notifications = chrome.notifications.items; .then(function() {
var notifications = mockChrome.notifications.items;
assertEquals( assertEquals(
2, Object.keys(notifications).length); 2, Object.keys(notifications).length);
assertEquals( assertEquals(
...@@ -408,7 +384,7 @@ function testMountPartialSuccess(callback) { ...@@ -408,7 +384,7 @@ function testMountPartialSuccess(callback) {
} }
function testUnknown(callback) { function testUnknown(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_unknown', status: 'error_unknown',
volumeMetadata: { volumeMetadata: {
...@@ -421,18 +397,17 @@ function testUnknown(callback) { ...@@ -421,18 +397,17 @@ function testUnknown(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise.then(function(notifications) {
function(notifications) { assertEquals(1, Object.keys(notifications).length);
assertEquals(1, Object.keys(notifications).length); assertEquals(
assertEquals( 'DEVICE_UNKNOWN: label',
'DEVICE_UNKNOWN: label', notifications['deviceFail:/device/path'].message);
notifications['deviceFail:/device/path'].message); }),
}),
callback); callback);
} }
function testNonASCIILabel(callback) { function testNonASCIILabel(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_internal', status: 'error_internal',
volumeMetadata: { volumeMetadata: {
...@@ -446,19 +421,18 @@ function testNonASCIILabel(callback) { ...@@ -446,19 +421,18 @@ function testNonASCIILabel(callback) {
}); });
reportPromise( reportPromise(
chrome.notifications.resolver.promise.then( mockChrome.notifications.resolver.promise.then(function(notifications) {
function(notifications) { assertEquals(1, Object.keys(notifications).length);
assertEquals(1, Object.keys(notifications).length); assertEquals(
assertEquals( 'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB',
'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB', notifications['deviceFail:/device/path'].message);
notifications['deviceFail:/device/path'].message); }),
}),
callback); callback);
} }
function testMulitpleFail() { function testMulitpleFail() {
// The first parent error. // The first parent error.
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_internal', status: 'error_internal',
volumeMetadata: { volumeMetadata: {
...@@ -469,13 +443,13 @@ function testMulitpleFail() { ...@@ -469,13 +443,13 @@ function testMulitpleFail() {
}, },
shouldNotify: true shouldNotify: true
}); });
assertEquals(1, Object.keys(chrome.notifications.items).length); assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals( assertEquals(
'DEVICE_UNKNOWN: label', 'DEVICE_UNKNOWN: label',
chrome.notifications.items['deviceFail:/device/path'].message); mockChrome.notifications.items['deviceFail:/device/path'].message);
// The first child error that replaces the parent error. // The first child error that replaces the parent error.
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_internal', status: 'error_internal',
volumeMetadata: { volumeMetadata: {
...@@ -486,13 +460,13 @@ function testMulitpleFail() { ...@@ -486,13 +460,13 @@ function testMulitpleFail() {
}, },
shouldNotify: true shouldNotify: true
}); });
assertEquals(1, Object.keys(chrome.notifications.items).length); assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals( assertEquals(
'DEVICE_UNKNOWN: label', 'DEVICE_UNKNOWN: label',
chrome.notifications.items['deviceFail:/device/path'].message); mockChrome.notifications.items['deviceFail:/device/path'].message);
// The second child error that turns to a multi-partition error. // The second child error that turns to a multi-partition error.
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_internal', status: 'error_internal',
volumeMetadata: { volumeMetadata: {
...@@ -503,14 +477,14 @@ function testMulitpleFail() { ...@@ -503,14 +477,14 @@ function testMulitpleFail() {
}, },
shouldNotify: true shouldNotify: true
}); });
assertEquals(1, Object.keys(chrome.notifications.items).length); assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals( assertEquals(
'MULTIPART_DEVICE_UNSUPPORTED: label', 'MULTIPART_DEVICE_UNSUPPORTED: label',
chrome.notifications.items['deviceFail:/device/path'].message); mockChrome.notifications.items['deviceFail:/device/path'].message);
// The third child error that should be ignored because the error message does // The third child error that should be ignored because the error message does
// not changed. // not changed.
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'error_internal', status: 'error_internal',
volumeMetadata: { volumeMetadata: {
...@@ -521,97 +495,87 @@ function testMulitpleFail() { ...@@ -521,97 +495,87 @@ function testMulitpleFail() {
}, },
shouldNotify: true shouldNotify: true
}); });
assertEquals(1, Object.keys(chrome.notifications.items).length); assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals( assertEquals(
'MULTIPART_DEVICE_UNSUPPORTED: label', 'MULTIPART_DEVICE_UNSUPPORTED: label',
chrome.notifications.items['deviceFail:/device/path'].message); mockChrome.notifications.items['deviceFail:/device/path'].message);
} }
function testDisabledDevice() { function testDisabledDevice() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch({ mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
type: 'disabled', {type: 'disabled', devicePath: '/device/path'});
devicePath: '/device/path' assertEquals(1, Object.keys(mockChrome.notifications.items).length);
}); assertEquals(
assertEquals(1, Object.keys(chrome.notifications.items).length); 'EXTERNAL_STORAGE_DISABLED_MESSAGE',
assertEquals('EXTERNAL_STORAGE_DISABLED_MESSAGE', mockChrome.notifications.items['deviceFail:/device/path'].message);
chrome.notifications.items['deviceFail:/device/path'].message);
chrome.fileManagerPrivate.onDeviceChanged.dispatch({ mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
type: 'removed', {type: 'removed', devicePath: '/device/path'});
devicePath: '/device/path' assertEquals(0, Object.keys(mockChrome.notifications.items).length);
});
assertEquals(0, Object.keys(chrome.notifications.items).length);
} }
function testFormatSucceeded() { function testFormatSucceeded() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch({ mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
type: 'format_start', {type: 'format_start', devicePath: '/device/path'});
devicePath: '/device/path' assertEquals(1, Object.keys(mockChrome.notifications.items).length);
}); assertEquals(
assertEquals(1, Object.keys(chrome.notifications.items).length); 'FORMATTING_OF_DEVICE_PENDING_MESSAGE',
assertEquals('FORMATTING_OF_DEVICE_PENDING_MESSAGE', mockChrome.notifications.items['formatStart:/device/path'].message);
chrome.notifications.items['formatStart:/device/path'].message);
chrome.fileManagerPrivate.onDeviceChanged.dispatch({ mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
type: 'format_success', {type: 'format_success', devicePath: '/device/path'});
devicePath: '/device/path' assertEquals(1, Object.keys(mockChrome.notifications.items).length);
}); assertEquals(
assertEquals(1, Object.keys(chrome.notifications.items).length); 'FORMATTING_FINISHED_SUCCESS_MESSAGE',
assertEquals('FORMATTING_FINISHED_SUCCESS_MESSAGE', mockChrome.notifications.items['formatSuccess:/device/path'].message);
chrome.notifications.items[
'formatSuccess:/device/path'].message);
} }
function testFormatFailed() { function testFormatFailed() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch({ mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
type: 'format_start', {type: 'format_start', devicePath: '/device/path'});
devicePath: '/device/path' assertEquals(1, Object.keys(mockChrome.notifications.items).length);
}); assertEquals(
assertEquals(1, Object.keys(chrome.notifications.items).length); 'FORMATTING_OF_DEVICE_PENDING_MESSAGE',
assertEquals('FORMATTING_OF_DEVICE_PENDING_MESSAGE', mockChrome.notifications.items['formatStart:/device/path'].message);
chrome.notifications.items['formatStart:/device/path'].message);
chrome.fileManagerPrivate.onDeviceChanged.dispatch({ mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
type: 'format_fail', {type: 'format_fail', devicePath: '/device/path'});
devicePath: '/device/path' assertEquals(1, Object.keys(mockChrome.notifications.items).length);
}); assertEquals(
assertEquals(1, Object.keys(chrome.notifications.items).length); 'FORMATTING_FINISHED_FAILURE_MESSAGE',
assertEquals('FORMATTING_FINISHED_FAILURE_MESSAGE', mockChrome.notifications.items['formatFail:/device/path'].message);
chrome.notifications.items['formatFail:/device/path'].message);
} }
function testRenameSucceeded() { function testRenameSucceeded() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch( mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'rename_start', devicePath: '/device/path'}); {type: 'rename_start', devicePath: '/device/path'});
assertEquals(0, Object.keys(chrome.notifications.items).length); assertEquals(0, Object.keys(mockChrome.notifications.items).length);
chrome.fileManagerPrivate.onDeviceChanged.dispatch( mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'rename_success', devicePath: '/device/path'}); {type: 'rename_success', devicePath: '/device/path'});
assertEquals(0, Object.keys(chrome.notifications.items).length); assertEquals(0, Object.keys(mockChrome.notifications.items).length);
} }
function testRenameFailed() { function testRenameFailed() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch( mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'rename_start', devicePath: '/device/path'}); {type: 'rename_start', devicePath: '/device/path'});
assertEquals(0, Object.keys(chrome.notifications.items).length); assertEquals(0, Object.keys(mockChrome.notifications.items).length);
chrome.fileManagerPrivate.onDeviceChanged.dispatch( mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'rename_fail', devicePath: '/device/path'}); {type: 'rename_fail', devicePath: '/device/path'});
assertEquals(1, Object.keys(chrome.notifications.items).length); assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals( assertEquals(
'RENAMING_OF_DEVICE_FINISHED_FAILURE_MESSAGE', 'RENAMING_OF_DEVICE_FINISHED_FAILURE_MESSAGE',
chrome.notifications.items['renameFail:/device/path'].message); mockChrome.notifications.items['renameFail:/device/path'].message);
} }
function testDeviceHardUnplugged() { function testDeviceHardUnplugged() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch({ mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
type: 'hard_unplugged', {type: 'hard_unplugged', devicePath: '/device/path'});
devicePath: '/device/path' assertEquals(1, Object.keys(mockChrome.notifications.items).length);
}); assertEquals(
assertEquals(1, Object.keys(chrome.notifications.items).length); 'DEVICE_HARD_UNPLUGGED_MESSAGE',
assertEquals('DEVICE_HARD_UNPLUGGED_MESSAGE', mockChrome.notifications.items['hardUnplugged:/device/path'].message);
chrome.notifications.items[
'hardUnplugged:/device/path'].message);
} }
function testNotificationClicked(callback) { function testNotificationClicked(callback) {
...@@ -620,15 +584,14 @@ function testNotificationClicked(callback) { ...@@ -620,15 +584,14 @@ function testNotificationClicked(callback) {
// Add a listener for navigation-requested events. // Add a listener for navigation-requested events.
var resolver = new importer.Resolver(); var resolver = new importer.Resolver();
handler.addEventListener( deviceHandler.addEventListener(
DeviceHandler.VOLUME_NAVIGATION_REQUESTED, DeviceHandler.VOLUME_NAVIGATION_REQUESTED, function(event) {
function(event) {
resolver.resolve(event); resolver.resolve(event);
}); });
// Call the notification-body-clicked handler and check that the // Call the notification-body-clicked handler and check that the
// navigation-requested event is dispatched. // navigation-requested event is dispatched.
chrome.notifications.onClicked.dispatch(notificationId); mockChrome.notifications.onClicked.dispatch(notificationId);
reportPromise( reportPromise(
resolver.promise.then( resolver.promise.then(
function(event) { function(event) {
...@@ -641,16 +604,16 @@ function testNotificationClicked(callback) { ...@@ -641,16 +604,16 @@ function testNotificationClicked(callback) {
function testMiscMessagesInIncognito() { function testMiscMessagesInIncognito() {
setUpInIncognitoContext(); setUpInIncognitoContext();
chrome.fileManagerPrivate.onDeviceChanged.dispatch( mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'format_start', devicePath: '/device/path'}); {type: 'format_start', devicePath: '/device/path'});
// No notification sent by this instance in incognito context. // No notification sent by this instance in incognito context.
assertEquals(0, Object.keys(chrome.notifications.items).length); assertEquals(0, Object.keys(mockChrome.notifications.items).length);
assertFalse(chrome.notifications.resolver.settled); assertFalse(mockChrome.notifications.resolver.settled);
} }
function testMountCompleteInIncognito() { function testMountCompleteInIncognito() {
setUpInIncognitoContext(); setUpInIncognitoContext();
chrome.fileManagerPrivate.onMountCompleted.dispatch({ mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount', eventType: 'mount',
status: 'success', status: 'success',
volumeMetadata: { volumeMetadata: {
...@@ -662,11 +625,11 @@ function testMountCompleteInIncognito() { ...@@ -662,11 +625,11 @@ function testMountCompleteInIncognito() {
shouldNotify: true shouldNotify: true
}); });
assertEquals(0, Object.keys(chrome.notifications.items).length); assertEquals(0, Object.keys(mockChrome.notifications.items).length);
// TODO(yamaguchi): I think this test is incomplete. // TODO(yamaguchi): I think this test is incomplete.
// This looks as if notification is not generated yet because the promise // This looks as if notification is not generated yet because the promise
// is not settled yet. Same for testGoodDeviceNotNavigated. // is not settled yet. Same for testGoodDeviceNotNavigated.
assertFalse(chrome.notifications.resolver.settled); assertFalse(mockChrome.notifications.resolver.settled);
} }
/** /**
...@@ -676,34 +639,42 @@ function testMountCompleteInIncognito() { ...@@ -676,34 +639,42 @@ function testMountCompleteInIncognito() {
* @return {!VolumeInfo} * @return {!VolumeInfo}
*/ */
function setupFileSystem(volumeType, volumeId, fileNames) { function setupFileSystem(volumeType, volumeId, fileNames) {
var volumeInfo = volumeManager.createVolumeInfo( /** @type {!MockVolumeManager}*/
var mockVolumeManager = volumeManager;
var volumeInfo = mockVolumeManager.createVolumeInfo(
volumeType, volumeId, 'A volume known as ' + volumeId); volumeType, volumeId, 'A volume known as ' + volumeId);
assertTrue(!!volumeInfo); assertTrue(!!volumeInfo);
volumeInfo.fileSystem.populate(fileNames); var mockFileSystem = /** @type {!MockFileSystem} */
(volumeInfo.fileSystem);
mockFileSystem.populate(fileNames);
return volumeInfo; return volumeInfo;
} }
function setupChromeApis() { function setupChromeApis() {
// Make dummy APIs. // Mock chrome APIs.
chrome = { mockChrome = {
commandLinePrivate: { commandLinePrivate: {
hasSwitch: function(switchName, callback) { hasSwitch: function(switchName, callback) {
if (switchName === 'disable-cloud-import') { if (switchName === 'disable-cloud-import') {
callback(chrome.commandLinePrivate.cloudImportDisabled); callback(mockChrome.commandLinePrivate.cloudImportDisabled);
} }
}, },
cloudImportDisabled: false cloudImportDisabled: false,
},
extension: {
inIncognitoContext: false,
}, },
extension: {inIncognitoContext: false},
fileManagerPrivate: { fileManagerPrivate: {
onDeviceChanged: { onDeviceChanged: {
dispatch: null,
addListener: function(listener) { addListener: function(listener) {
this.dispatch = listener; mockChrome.fileManagerPrivate.onDeviceChanged.dispatch = listener;
} }
}, },
onMountCompleted: { onMountCompleted: {
dispatch: null,
addListener: function(listener) { addListener: function(listener) {
this.dispatch = listener; mockChrome.fileManagerPrivate.onMountCompleted.dispatch = listener;
} }
}, },
getProfiles: function(callback) { getProfiles: function(callback) {
...@@ -717,27 +688,32 @@ function setupChromeApis() { ...@@ -717,27 +688,32 @@ function setupChromeApis() {
}, },
notifications: { notifications: {
resolver: new importer.Resolver(), resolver: new importer.Resolver(),
promise: null,
create: function(id, params, callback) { create: function(id, params, callback) {
this.promise = this.resolver.promise; mockChrome.notifications.promise =
this.items[id] = params; mockChrome.notifications.resolver.promise;
if (!this.resolver.settled) { mockChrome.notifications.items[id] = params;
this.resolver.resolve(this.items); if (!mockChrome.notifications.resolver.settled) {
mockChrome.notifications.resolver.resolve(
mockChrome.notifications.items);
} }
callback(); callback();
}, },
clear: function(id, callback) { clear: function(id, callback) {
delete this.items[id]; delete mockChrome.notifications.items[id];
callback(); callback();
}, },
items: {}, items: {},
onButtonClicked: { onButtonClicked: {
dispatch: null,
addListener: function(listener) { addListener: function(listener) {
this.dispatch = listener; mockChrome.notifications.onButtonClicked.dispatch = listener;
} }
}, },
onClicked: { onClicked: {
dispatch: null,
addListener: function(listener) { addListener: function(listener) {
this.dispatch = listener; mockChrome.notifications.onClicked.dispatch = listener;
} }
}, },
getAll: function(callback) { getAll: function(callback) {
...@@ -751,4 +727,6 @@ function setupChromeApis() { ...@@ -751,4 +727,6 @@ function setupChromeApis() {
onStartup: {addListener: function() {}} onStartup: {addListener: function() {}}
} }
}; };
installMockChrome(mockChrome);
} }
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