Index: chrome/test/data/file_manager/unit_tests/device_handler_unittest.js |
diff --git a/chrome/test/data/file_manager/unit_tests/device_handler_unittest.js b/chrome/test/data/file_manager/unit_tests/device_handler_unittest.js |
index 43769176e127b4d988d6338259bd55fcd0b9f590..758669d1eba6ecc3a9d109b740989ad2fb51fdf9 100644 |
--- a/chrome/test/data/file_manager/unit_tests/device_handler_unittest.js |
+++ b/chrome/test/data/file_manager/unit_tests/device_handler_unittest.js |
@@ -26,6 +26,8 @@ function setUp() { |
loadTimeData.data = { |
REMOVABLE_DEVICE_DETECTION_TITLE: 'Device detected', |
REMOVABLE_DEVICE_SCANNING_MESSAGE: 'Scanning...', |
+ REMOVABLE_DEVICE_NAVIGATION_MESSAGE: 'DEVICE_NAVIGATION', |
+ REMOVABLE_DEVICE_NAVIGATION_BUTTON_LABEL: '', |
DEVICE_UNKNOWN_MESSAGE: 'DEVICE_UNKNOWN: $1', |
DEVICE_UNSUPPORTED_MESSAGE: 'DEVICE_UNSUPPORTED: $1', |
DEVICE_HARD_UNPLUGGED_TITLE: 'DEVICE_HARD_UNPLUGGED_TITLE', |
@@ -75,65 +77,54 @@ function setUp() { |
} |
}; |
- // Reset timeout callbacks. |
- timeoutCallbacks = []; |
- |
// Make a device handler. |
handler = new DeviceHandler(); |
} |
-/** |
- * Overrided setTimoeut funciton. |
- */ |
-window.setTimeout = function(func) { |
- timeoutCallbacks.push(func); |
-}; |
- |
-/** |
- * Call all pending timeout functions. |
- */ |
-function callTimeoutCallbacks() { |
- while (timeoutCallbacks.length) { |
- timeoutCallbacks.shift()(); |
- } |
-} |
- |
-function registerTypicalDevice() { |
- chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ |
- type: 'added', |
- devicePath: '/device/path' |
+function testGoodDevice() { |
+ chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
+ status: 'success', |
+ volumeMetadata: { |
+ isParentDevice: true, |
+ deviceType: 'usb', |
+ devicePath: '/device/path', |
+ deviceLabel: 'label' |
+ }, |
+ shouldNotify: true |
}); |
- assertFalse('device:/device/path' in chrome.notifications.items); |
- callTimeoutCallbacks(); |
- assertEquals('Scanning...', |
- chrome.notifications.items['device:/device/path'].message); |
+ assertEquals(1, Object.keys(chrome.notifications.items).length); |
+ assertEquals( |
+ 'DEVICE_NAVIGATION', |
+ chrome.notifications.items['deviceNavigation:/device/path'].message); |
} |
-function testGoodDevice() { |
- registerTypicalDevice(); |
+function testGoodDeviceNotNavigated() { |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'success', |
volumeMetadata: { |
isParentDevice: true, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: false |
}); |
assertEquals(0, Object.keys(chrome.notifications.items).length); |
} |
function testGoodDeviceWithBadParent() { |
- registerTypicalDevice(); |
- |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_internal', |
volumeMetadata: { |
isParentDevice: true, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertFalse(!!chrome.notifications.items['device:/device/path']); |
assertEquals( |
@@ -141,40 +132,50 @@ function testGoodDeviceWithBadParent() { |
chrome.notifications.items['deviceFail:/device/path'].message); |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'success', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
- assertEquals(0, Object.keys(chrome.notifications.items).length); |
+ assertEquals(1, Object.keys(chrome.notifications.items).length); |
+ assertEquals( |
+ 'DEVICE_NAVIGATION', |
+ chrome.notifications.items['deviceNavigation:/device/path'].message); |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'success', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
// Should do nothing this time. |
- assertEquals(0, Object.keys(chrome.notifications.items).length); |
+ assertEquals(1, Object.keys(chrome.notifications.items).length); |
+ assertEquals( |
+ 'DEVICE_NAVIGATION', |
+ chrome.notifications.items['deviceNavigation:/device/path'].message); |
} |
function testUnsupportedDevice() { |
- registerTypicalDevice(); |
- |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_unsupported_filesystem', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertFalse(!!chrome.notifications.items['device:/device/path']); |
assertEquals( |
@@ -183,29 +184,31 @@ function testUnsupportedDevice() { |
} |
function testUnsupportedWithUnknownParent() { |
- registerTypicalDevice(); |
- |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_internal', |
volumeMetadata: { |
isParentDevice: true, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertEquals( |
'DEVICE_UNKNOWN: label', |
chrome.notifications.items['deviceFail:/device/path'].message); |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_unsupported_filesystem', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertEquals(1, Object.keys(chrome.notifications.items).length); |
assertEquals( |
@@ -214,45 +217,50 @@ function testUnsupportedWithUnknownParent() { |
} |
function testMountPartialSuccess() { |
- registerTypicalDevice(); |
- |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'success', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
- assertEquals(0, Object.keys(chrome.notifications.items).length); |
+ assertEquals(1, Object.keys(chrome.notifications.items).length); |
+ assertEquals( |
+ 'DEVICE_NAVIGATION', |
+ chrome.notifications.items['deviceNavigation:/device/path'].message); |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_unsupported_filesystem', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
- assertEquals(1, Object.keys(chrome.notifications.items).length); |
+ assertEquals(2, Object.keys(chrome.notifications.items).length); |
assertEquals( |
'MULTIPART_DEVICE_UNSUPPORTED: label', |
chrome.notifications.items['deviceFail:/device/path'].message); |
} |
function testUnknown() { |
- registerTypicalDevice(); |
- |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_unknown', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertEquals(1, Object.keys(chrome.notifications.items).length); |
assertEquals( |
@@ -261,9 +269,8 @@ function testUnknown() { |
} |
function testNonASCIILabel() { |
- registerTypicalDevice(); |
- |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_internal', |
volumeMetadata: { |
isParentDevice: false, |
@@ -271,7 +278,8 @@ function testNonASCIILabel() { |
devicePath: '/device/path', |
// "RA (U+30E9) BE (U+30D9) RU (U+30EB)" in Katakana letters. |
deviceLabel: '\u30E9\u30D9\u30EB' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertEquals(1, Object.keys(chrome.notifications.items).length); |
assertEquals( |
@@ -280,17 +288,17 @@ function testNonASCIILabel() { |
} |
function testMulitpleFail() { |
- registerTypicalDevice(); |
- |
// The first parent error. |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_internal', |
volumeMetadata: { |
isParentDevice: true, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertEquals(1, Object.keys(chrome.notifications.items).length); |
assertEquals( |
@@ -299,13 +307,15 @@ function testMulitpleFail() { |
// The first child error that replaces the parent error. |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_internal', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertEquals(1, Object.keys(chrome.notifications.items).length); |
assertEquals( |
@@ -314,13 +324,15 @@ function testMulitpleFail() { |
// The second child error that turns to a multi-partition error. |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_internal', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertEquals(1, Object.keys(chrome.notifications.items).length); |
assertEquals( |
@@ -330,13 +342,15 @@ function testMulitpleFail() { |
// The third child error that should be ignored because the error message does |
// not changed. |
chrome.fileBrowserPrivate.onMountCompleted.dispatch({ |
+ eventType: 'mount', |
status: 'error_internal', |
volumeMetadata: { |
isParentDevice: false, |
deviceType: 'usb', |
devicePath: '/device/path', |
deviceLabel: 'label' |
- } |
+ }, |
+ shouldNotify: true |
}); |
assertEquals(1, Object.keys(chrome.notifications.items).length); |
assertEquals( |
@@ -345,10 +359,16 @@ function testMulitpleFail() { |
} |
function testScanCanceled() { |
- registerTypicalDevice(); |
+ chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ |
+ type: 'scan_started', |
+ devicePath: '/device/path' |
+ }); |
+ assertTrue('device:/device/path' in chrome.notifications.items); |
+ assertEquals('Scanning...', |
+ chrome.notifications.items['device:/device/path'].message); |
chrome.fileBrowserPrivate.onDeviceChanged.dispatch({ |
- type: 'scan_canceled', |
+ type: 'scan_cancelled', |
devicePath: '/device/path' |
}); |
assertEquals(0, Object.keys(chrome.notifications.items).length); |