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) {
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, DeviceHandlerTest) {
RunTest(base::FilePath(
FILE_PATH_LITERAL("background/js/device_handler_unittest.html")));
RunGeneratedTest("/background/js/device_handler_unittest.html");
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationManagerTest) {
......
......@@ -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") {
testonly = true
deps = [
......@@ -451,6 +461,7 @@ js_library("volume_manager_util") {
js_unit_tests("unit_tests") {
deps = [
":crostini_unittest",
":device_handler_unittest",
":duplicate_finder_unittest",
":import_history_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 @@
// found in the LICENSE file.
'use strict';
/**
* Dummy private APIs.
*/
var chrome;
/**
* Callbacks registered by setTimeout.
* @type {Array<function>}
*/
var timeoutCallbacks;
/** @type {!MockVolumeManager} */
var volumeManager;
/** @type {DeviceHandler} */
var handler;
/** @type {!DeviceHandler} */
var deviceHandler;
/** Mock chrome APIs. */
var mockChrome;
// Set up the test components.
function setUp() {
// Set up string assets.
// Set up string assets.
window.loadTimeData.data = {
DEVICE_UNSUPPORTED_MESSAGE: 'DEVICE_UNSUPPORTED: $1',
DEVICE_UNKNOWN_MESSAGE: 'DEVICE_UNKNOWN: $1',
......@@ -31,21 +23,20 @@ function setUp() {
window.loadTimeData.getString = id => {
return window.loadTimeData.data_[id] || id;
};
new MockCommandLinePrivate();
volumeManager = new MockVolumeManager();
MockVolumeManager.installMockSingleton(volumeManager);
setupChromeApis();
volumeManager = new MockVolumeManager();
MockVolumeManager.installMockSingleton(volumeManager);
handler = new DeviceHandler();
deviceHandler = new DeviceHandler();
}
function setUpInIncognitoContext() {
chrome.extension.inIncognitoContext = true;
mockChrome.extension.inIncognitoContext = true;
}
function testGoodDevice(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'success',
volumeMetadata: {
......@@ -58,14 +49,12 @@ function testGoodDevice(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
assertEquals(1, Object.keys(notifications).length);
var options = notifications['deviceNavigation:/device/path'];
assertEquals(
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE', options.message);
assertTrue(options.isClickable);
}),
mockChrome.notifications.resolver.promise.then(function(notifications) {
assertEquals(1, Object.keys(notifications).length);
var options = notifications['deviceNavigation:/device/path'];
assertEquals('REMOVABLE_DEVICE_NAVIGATION_MESSAGE', options.message);
assertTrue(options.isClickable);
}),
callback);
}
......@@ -83,19 +72,15 @@ function testRemovableMediaDeviceWithImportEnabled(callback) {
var resolver = new importer.Resolver();
// Handle media device navigation requests.
handler.addEventListener(
DeviceHandler.VOLUME_NAVIGATION_REQUESTED,
function(event) {
deviceHandler.addEventListener(
DeviceHandler.VOLUME_NAVIGATION_REQUESTED, function(event) {
resolver.resolve(event);
});
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'success',
volumeMetadata: {
volumeId: 'blabbity',
deviceType: 'usb'
},
volumeMetadata: {volumeId: 'blabbity', deviceType: 'usb'},
shouldNotify: true
});
......@@ -121,19 +106,15 @@ function testMtpMediaDeviceWithImportEnabled(callback) {
var resolver = new importer.Resolver();
// Handle media device navigation requests.
handler.addEventListener(
DeviceHandler.VOLUME_NAVIGATION_REQUESTED,
function(event) {
deviceHandler.addEventListener(
DeviceHandler.VOLUME_NAVIGATION_REQUESTED, function(event) {
resolver.resolve(event);
});
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'success',
volumeMetadata: {
volumeId: 'blabbity',
deviceType: 'mtp'
},
volumeMetadata: {volumeId: 'blabbity', deviceType: 'mtp'},
shouldNotify: true
});
......@@ -146,9 +127,9 @@ function testMtpMediaDeviceWithImportEnabled(callback) {
}
function testMediaDeviceWithImportDisabled(callback) {
chrome.commandLinePrivate.cloudImportDisabled = true;
mockChrome.commandLinePrivate.cloudImportDisabled = true;
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'success',
volumeMetadata: {
......@@ -162,20 +143,18 @@ function testMediaDeviceWithImportDisabled(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
assertEquals(1, Object.keys(notifications).length);
assertEquals(
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE',
notifications[
'deviceNavigation:/device/path'].message,
'Device notification did not have the right message.');
}),
mockChrome.notifications.resolver.promise.then(function(notifications) {
assertEquals(1, Object.keys(notifications).length);
assertEquals(
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE',
notifications['deviceNavigation:/device/path'].message,
'Device notification did not have the right message.');
}),
callback);
}
function testGoodDeviceNotNavigated() {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'success',
volumeMetadata: {
......@@ -187,12 +166,12 @@ function testGoodDeviceNotNavigated() {
shouldNotify: false
});
assertEquals(0, Object.keys(chrome.notifications.items).length);
assertFalse(chrome.notifications.resolver.settled);
assertEquals(0, Object.keys(mockChrome.notifications.items).length);
assertFalse(mockChrome.notifications.resolver.settled);
}
function testGoodDeviceWithBadParent(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_internal',
volumeMetadata: {
......@@ -205,18 +184,17 @@ function testGoodDeviceWithBadParent(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
assertFalse(!!notifications['device:/device/path']);
assertEquals(
'DEVICE_UNKNOWN: label',
notifications['deviceFail:/device/path'].message);
}),
mockChrome.notifications.resolver.promise.then(function(notifications) {
assertFalse(!!notifications['device:/device/path']);
assertEquals(
'DEVICE_UNKNOWN: label',
notifications['deviceFail:/device/path'].message);
}),
callback);
}
function testGoodDeviceWithBadParent_DuplicateMount(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'success',
volumeMetadata: {
......@@ -230,7 +208,7 @@ function testGoodDeviceWithBadParent_DuplicateMount(callback) {
// Mounting the same device repeatedly should produce only
// a single notification.
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'success',
volumeMetadata: {
......@@ -243,18 +221,17 @@ function testGoodDeviceWithBadParent_DuplicateMount(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
assertEquals(1, Object.keys(notifications).length);
assertEquals(
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE',
notifications['deviceNavigation:/device/path'].message);
}),
mockChrome.notifications.resolver.promise.then(function(notifications) {
assertEquals(1, Object.keys(notifications).length);
assertEquals(
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE',
notifications['deviceNavigation:/device/path'].message);
}),
callback);
}
function testUnsupportedDevice(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_unsupported_filesystem',
volumeMetadata: {
......@@ -267,19 +244,18 @@ function testUnsupportedDevice(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
assertFalse(!!chrome.notifications.items['device:/device/path']);
assertEquals(
'DEVICE_UNSUPPORTED: label',
chrome.notifications.items['deviceFail:/device/path'].message);
}),
mockChrome.notifications.resolver.promise.then(function(notifications) {
assertFalse(!!mockChrome.notifications.items['device:/device/path']);
assertEquals(
'DEVICE_UNSUPPORTED: label',
mockChrome.notifications.items['deviceFail:/device/path'].message);
}),
callback);
}
function testUnknownDevice(callback) {
// Emulate adding a device which has unknown filesystem.
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_unknown_filesystem',
volumeMetadata: {
......@@ -292,20 +268,19 @@ function testUnknownDevice(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
assertFalse(!!chrome.notifications.items['device:/device/path']);
var item = chrome.notifications.items['deviceFail:/device/path'];
assertEquals('DEVICE_UNKNOWN_DEFAULT_MESSAGE', item.message);
// "Format device" button should appear.
assertEquals('DEVICE_UNKNOWN_BUTTON_LABEL', item.buttons[0].title);
}),
mockChrome.notifications.resolver.promise.then(function(notifications) {
assertFalse(!!mockChrome.notifications.items['device:/device/path']);
var item = mockChrome.notifications.items['deviceFail:/device/path'];
assertEquals('DEVICE_UNKNOWN_DEFAULT_MESSAGE', item.message);
// "Format device" button should appear.
assertEquals('DEVICE_UNKNOWN_BUTTON_LABEL', item.buttons[0].title);
}),
callback);
}
function testUnknownReadonlyDevice(callback) {
// Emulate adding a device which has unknown filesystem but is read-only.
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_unknown_filesystem',
volumeMetadata: {
......@@ -318,19 +293,18 @@ function testUnknownReadonlyDevice(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
assertFalse(!!chrome.notifications.items['device:/device/path']);
var item = chrome.notifications.items['deviceFail:/device/path'];
assertEquals('DEVICE_UNKNOWN_DEFAULT_MESSAGE', item.message);
// "Format device" button should not appear.
assertFalse(!!item.buttons);
}),
mockChrome.notifications.resolver.promise.then(function(notifications) {
assertFalse(!!mockChrome.notifications.items['device:/device/path']);
var item = mockChrome.notifications.items['deviceFail:/device/path'];
assertEquals('DEVICE_UNKNOWN_DEFAULT_MESSAGE', item.message);
// "Format device" button should not appear.
assertFalse(!!item.buttons);
}),
callback);
}
function testUnsupportedWithUnknownParentReplacesNotification() {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_internal',
volumeMetadata: {
......@@ -344,9 +318,9 @@ function testUnsupportedWithUnknownParentReplacesNotification() {
assertEquals(
'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',
status: 'error_unsupported_filesystem',
volumeMetadata: {
......@@ -358,14 +332,14 @@ function testUnsupportedWithUnknownParentReplacesNotification() {
shouldNotify: true
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'DEVICE_UNSUPPORTED: label',
chrome.notifications.items['deviceFail:/device/path'].message);
mockChrome.notifications.items['deviceFail:/device/path'].message);
}
function testMountPartialSuccess(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'success',
volumeMetadata: {
......@@ -378,14 +352,15 @@ function testMountPartialSuccess(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
mockChrome.notifications.resolver.promise
.then(function(notifications) {
assertEquals(1, Object.keys(notifications).length);
assertEquals(
'REMOVABLE_DEVICE_NAVIGATION_MESSAGE',
notifications['deviceNavigation:/device/path'].message);
}).then(function() {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
})
.then(function() {
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_unsupported_filesystem',
volumeMetadata: {
......@@ -396,8 +371,9 @@ function testMountPartialSuccess(callback) {
},
shouldNotify: true
});
}).then(function() {
var notifications = chrome.notifications.items;
})
.then(function() {
var notifications = mockChrome.notifications.items;
assertEquals(
2, Object.keys(notifications).length);
assertEquals(
......@@ -408,7 +384,7 @@ function testMountPartialSuccess(callback) {
}
function testUnknown(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_unknown',
volumeMetadata: {
......@@ -421,18 +397,17 @@ function testUnknown(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
assertEquals(1, Object.keys(notifications).length);
assertEquals(
'DEVICE_UNKNOWN: label',
notifications['deviceFail:/device/path'].message);
}),
mockChrome.notifications.resolver.promise.then(function(notifications) {
assertEquals(1, Object.keys(notifications).length);
assertEquals(
'DEVICE_UNKNOWN: label',
notifications['deviceFail:/device/path'].message);
}),
callback);
}
function testNonASCIILabel(callback) {
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_internal',
volumeMetadata: {
......@@ -446,19 +421,18 @@ function testNonASCIILabel(callback) {
});
reportPromise(
chrome.notifications.resolver.promise.then(
function(notifications) {
assertEquals(1, Object.keys(notifications).length);
assertEquals(
'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB',
notifications['deviceFail:/device/path'].message);
}),
mockChrome.notifications.resolver.promise.then(function(notifications) {
assertEquals(1, Object.keys(notifications).length);
assertEquals(
'DEVICE_UNKNOWN: \u30E9\u30D9\u30EB',
notifications['deviceFail:/device/path'].message);
}),
callback);
}
function testMulitpleFail() {
// The first parent error.
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_internal',
volumeMetadata: {
......@@ -469,13 +443,13 @@ function testMulitpleFail() {
},
shouldNotify: true
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'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.
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_internal',
volumeMetadata: {
......@@ -486,13 +460,13 @@ function testMulitpleFail() {
},
shouldNotify: true
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'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.
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_internal',
volumeMetadata: {
......@@ -503,14 +477,14 @@ function testMulitpleFail() {
},
shouldNotify: true
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'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
// not changed.
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'error_internal',
volumeMetadata: {
......@@ -521,97 +495,87 @@ function testMulitpleFail() {
},
shouldNotify: true
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'MULTIPART_DEVICE_UNSUPPORTED: label',
chrome.notifications.items['deviceFail:/device/path'].message);
mockChrome.notifications.items['deviceFail:/device/path'].message);
}
function testDisabledDevice() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch({
type: 'disabled',
devicePath: '/device/path'
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals('EXTERNAL_STORAGE_DISABLED_MESSAGE',
chrome.notifications.items['deviceFail:/device/path'].message);
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'disabled', devicePath: '/device/path'});
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'EXTERNAL_STORAGE_DISABLED_MESSAGE',
mockChrome.notifications.items['deviceFail:/device/path'].message);
chrome.fileManagerPrivate.onDeviceChanged.dispatch({
type: 'removed',
devicePath: '/device/path'
});
assertEquals(0, Object.keys(chrome.notifications.items).length);
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'removed', devicePath: '/device/path'});
assertEquals(0, Object.keys(mockChrome.notifications.items).length);
}
function testFormatSucceeded() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch({
type: 'format_start',
devicePath: '/device/path'
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals('FORMATTING_OF_DEVICE_PENDING_MESSAGE',
chrome.notifications.items['formatStart:/device/path'].message);
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'format_start', devicePath: '/device/path'});
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'FORMATTING_OF_DEVICE_PENDING_MESSAGE',
mockChrome.notifications.items['formatStart:/device/path'].message);
chrome.fileManagerPrivate.onDeviceChanged.dispatch({
type: 'format_success',
devicePath: '/device/path'
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals('FORMATTING_FINISHED_SUCCESS_MESSAGE',
chrome.notifications.items[
'formatSuccess:/device/path'].message);
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'format_success', devicePath: '/device/path'});
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'FORMATTING_FINISHED_SUCCESS_MESSAGE',
mockChrome.notifications.items['formatSuccess:/device/path'].message);
}
function testFormatFailed() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch({
type: 'format_start',
devicePath: '/device/path'
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals('FORMATTING_OF_DEVICE_PENDING_MESSAGE',
chrome.notifications.items['formatStart:/device/path'].message);
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'format_start', devicePath: '/device/path'});
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'FORMATTING_OF_DEVICE_PENDING_MESSAGE',
mockChrome.notifications.items['formatStart:/device/path'].message);
chrome.fileManagerPrivate.onDeviceChanged.dispatch({
type: 'format_fail',
devicePath: '/device/path'
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals('FORMATTING_FINISHED_FAILURE_MESSAGE',
chrome.notifications.items['formatFail:/device/path'].message);
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'format_fail', devicePath: '/device/path'});
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'FORMATTING_FINISHED_FAILURE_MESSAGE',
mockChrome.notifications.items['formatFail:/device/path'].message);
}
function testRenameSucceeded() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch(
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{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'});
assertEquals(0, Object.keys(chrome.notifications.items).length);
assertEquals(0, Object.keys(mockChrome.notifications.items).length);
}
function testRenameFailed() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch(
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{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'});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'RENAMING_OF_DEVICE_FINISHED_FAILURE_MESSAGE',
chrome.notifications.items['renameFail:/device/path'].message);
mockChrome.notifications.items['renameFail:/device/path'].message);
}
function testDeviceHardUnplugged() {
chrome.fileManagerPrivate.onDeviceChanged.dispatch({
type: 'hard_unplugged',
devicePath: '/device/path'
});
assertEquals(1, Object.keys(chrome.notifications.items).length);
assertEquals('DEVICE_HARD_UNPLUGGED_MESSAGE',
chrome.notifications.items[
'hardUnplugged:/device/path'].message);
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'hard_unplugged', devicePath: '/device/path'});
assertEquals(1, Object.keys(mockChrome.notifications.items).length);
assertEquals(
'DEVICE_HARD_UNPLUGGED_MESSAGE',
mockChrome.notifications.items['hardUnplugged:/device/path'].message);
}
function testNotificationClicked(callback) {
......@@ -620,15 +584,14 @@ function testNotificationClicked(callback) {
// Add a listener for navigation-requested events.
var resolver = new importer.Resolver();
handler.addEventListener(
DeviceHandler.VOLUME_NAVIGATION_REQUESTED,
function(event) {
deviceHandler.addEventListener(
DeviceHandler.VOLUME_NAVIGATION_REQUESTED, function(event) {
resolver.resolve(event);
});
// Call the notification-body-clicked handler and check that the
// navigation-requested event is dispatched.
chrome.notifications.onClicked.dispatch(notificationId);
mockChrome.notifications.onClicked.dispatch(notificationId);
reportPromise(
resolver.promise.then(
function(event) {
......@@ -641,16 +604,16 @@ function testNotificationClicked(callback) {
function testMiscMessagesInIncognito() {
setUpInIncognitoContext();
chrome.fileManagerPrivate.onDeviceChanged.dispatch(
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch(
{type: 'format_start', devicePath: '/device/path'});
// No notification sent by this instance in incognito context.
assertEquals(0, Object.keys(chrome.notifications.items).length);
assertFalse(chrome.notifications.resolver.settled);
assertEquals(0, Object.keys(mockChrome.notifications.items).length);
assertFalse(mockChrome.notifications.resolver.settled);
}
function testMountCompleteInIncognito() {
setUpInIncognitoContext();
chrome.fileManagerPrivate.onMountCompleted.dispatch({
mockChrome.fileManagerPrivate.onMountCompleted.dispatch({
eventType: 'mount',
status: 'success',
volumeMetadata: {
......@@ -662,11 +625,11 @@ function testMountCompleteInIncognito() {
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.
// This looks as if notification is not generated yet because the promise
// is not settled yet. Same for testGoodDeviceNotNavigated.
assertFalse(chrome.notifications.resolver.settled);
assertFalse(mockChrome.notifications.resolver.settled);
}
/**
......@@ -676,34 +639,42 @@ function testMountCompleteInIncognito() {
* @return {!VolumeInfo}
*/
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);
assertTrue(!!volumeInfo);
volumeInfo.fileSystem.populate(fileNames);
var mockFileSystem = /** @type {!MockFileSystem} */
(volumeInfo.fileSystem);
mockFileSystem.populate(fileNames);
return volumeInfo;
}
function setupChromeApis() {
// Make dummy APIs.
chrome = {
// Mock chrome APIs.
mockChrome = {
commandLinePrivate: {
hasSwitch: function(switchName, callback) {
if (switchName === 'disable-cloud-import') {
callback(chrome.commandLinePrivate.cloudImportDisabled);
callback(mockChrome.commandLinePrivate.cloudImportDisabled);
}
},
cloudImportDisabled: false
cloudImportDisabled: false,
},
extension: {
inIncognitoContext: false,
},
extension: {inIncognitoContext: false},
fileManagerPrivate: {
onDeviceChanged: {
dispatch: null,
addListener: function(listener) {
this.dispatch = listener;
mockChrome.fileManagerPrivate.onDeviceChanged.dispatch = listener;
}
},
onMountCompleted: {
dispatch: null,
addListener: function(listener) {
this.dispatch = listener;
mockChrome.fileManagerPrivate.onMountCompleted.dispatch = listener;
}
},
getProfiles: function(callback) {
......@@ -717,27 +688,32 @@ function setupChromeApis() {
},
notifications: {
resolver: new importer.Resolver(),
promise: null,
create: function(id, params, callback) {
this.promise = this.resolver.promise;
this.items[id] = params;
if (!this.resolver.settled) {
this.resolver.resolve(this.items);
mockChrome.notifications.promise =
mockChrome.notifications.resolver.promise;
mockChrome.notifications.items[id] = params;
if (!mockChrome.notifications.resolver.settled) {
mockChrome.notifications.resolver.resolve(
mockChrome.notifications.items);
}
callback();
},
clear: function(id, callback) {
delete this.items[id];
delete mockChrome.notifications.items[id];
callback();
},
items: {},
onButtonClicked: {
dispatch: null,
addListener: function(listener) {
this.dispatch = listener;
mockChrome.notifications.onButtonClicked.dispatch = listener;
}
},
onClicked: {
dispatch: null,
addListener: function(listener) {
this.dispatch = listener;
mockChrome.notifications.onClicked.dispatch = listener;
}
},
getAll: function(callback) {
......@@ -751,4 +727,6 @@ function setupChromeApis() {
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