OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 window.chrome = { |
| 6 fileManagerPrivate: { |
| 7 getFileTasks: function(entries, callback) { |
| 8 setTimeout(callback.bind(null, [ |
| 9 { |
| 10 taskId: 'handler-extension-id|app|any', |
| 11 isDefault: false, |
| 12 isGenericFileHandler: true |
| 13 } |
| 14 ]), 0); |
| 15 }, |
| 16 executeTask: function(taskId, urls, onViewFiles) { |
| 17 onViewFiles('failed'); |
| 18 } |
| 19 }, |
| 20 runtime: {id: 'test-extension-id'} |
| 21 }; |
| 22 |
| 23 window.metrics = { |
| 24 recordEnum: function() {} |
| 25 }; |
| 26 |
| 27 loadTimeData.data = { |
| 28 NO_ACTION_FOR_EXECUTABLE: 'NO_ACTION_FOR_EXECUTABLE', |
| 29 NO_ACTION_FOR_FILE_URL: 'NO_ACTION_FOR_FILE_URL', |
| 30 NO_ACTION_FOR_DMG: 'NO_ACTION_FOR_DMG', |
| 31 NO_ACTION_FOR_CRX: 'NO_ACTION_FOR_CRX', |
| 32 NO_ACTION_FOR_CRX_TITLE: 'NO_ACTION_FOR_CRX_TITLE' |
| 33 }; |
| 34 |
| 35 /** |
| 36 * Returns a mock file manager. |
| 37 * @return {!FileManager} |
| 38 */ |
| 39 function getMockFileManager() { |
| 40 return { |
| 41 isOnDrive: function() { |
| 42 return false; |
| 43 }, |
| 44 volumeManager: { |
| 45 getDriveConnectionState: function() { |
| 46 return VolumeManagerCommon.DriveConnectionType.ONLINE; |
| 47 } |
| 48 }, |
| 49 ui: { |
| 50 alertDialog: { |
| 51 showHtml: function(title, text, onOk, onCancel, onShow) {} |
| 52 } |
| 53 }, |
| 54 taskController: { |
| 55 openSuggestAppsDialog: function( |
| 56 entry, onSuccess, onCancelled, onFailure) {} |
| 57 } |
| 58 }; |
| 59 } |
| 60 |
| 61 /** |
| 62 * Returns a promise which is resolved when showHtml of alert dialog is called |
| 63 * with expected title and text. |
| 64 * |
| 65 * @param {!Array.<!Entry>} entries Entries. |
| 66 * @param {string} expectedTitle An expected title. |
| 67 * @param {string} expectedText An expected text. |
| 68 * @return {!Promise} |
| 69 */ |
| 70 function showHtmlOfAlertDialogIsCalled( |
| 71 entries, expectedTitle, expectedText) { |
| 72 return new Promise(function(resolve, reject) { |
| 73 var fileManager = getMockFileManager(); |
| 74 fileManager.ui.alertDialog.showHtml = |
| 75 function(title, text, onOk, onCancel, onShow) { |
| 76 assertEquals(expectedTitle, title); |
| 77 assertEquals(expectedText, text); |
| 78 resolve(); |
| 79 }; |
| 80 |
| 81 var fileTasks = new FileTasks(fileManager); |
| 82 fileTasks.init(entries).then(function() { |
| 83 fileTasks.executeDefault(); |
| 84 }); |
| 85 }); |
| 86 } |
| 87 |
| 88 /** |
| 89 * Returns a promise which is resolved when openSuggestAppsDialog is called. |
| 90 * |
| 91 * @param {!Array.<!Entry>} entries Entries. |
| 92 * @return {!Promise} |
| 93 */ |
| 94 function openSuggestAppsDialogIsCalled(entries) { |
| 95 return new Promise(function(resolve, reject) { |
| 96 var fileManager = getMockFileManager(); |
| 97 fileManager.taskController.openSuggestAppsDialog = |
| 98 function(entry, onSuccess, onCancelled, onFailure) { |
| 99 resolve(); |
| 100 }; |
| 101 |
| 102 var fileTasks = new FileTasks(fileManager); |
| 103 fileTasks.init(entries).then(function() { |
| 104 fileTasks.executeDefault(); |
| 105 }); |
| 106 }); |
| 107 } |
| 108 |
| 109 function testToOpenExeFile(callback) { |
| 110 var mockFileSystem = new MockFileSystem('volumeId'); |
| 111 var mockEntry = new MockFileEntry(mockFileSystem, '/test.exe'); |
| 112 |
| 113 reportPromise(showHtmlOfAlertDialogIsCalled( |
| 114 [mockEntry], 'test.exe', 'NO_ACTION_FOR_EXECUTABLE'), callback); |
| 115 } |
| 116 |
| 117 function testToOpenDmgFile(callback) { |
| 118 var mockFileSystem = new MockFileSystem('volumeId'); |
| 119 var mockEntry = new MockFileEntry(mockFileSystem, '/test.dmg'); |
| 120 |
| 121 reportPromise(showHtmlOfAlertDialogIsCalled( |
| 122 [mockEntry], 'test.dmg', 'NO_ACTION_FOR_DMG'), callback); |
| 123 } |
| 124 |
| 125 function testToOpenCrxFile(callback) { |
| 126 var mockFileSystem = new MockFileSystem('volumeId'); |
| 127 var mockEntry = new MockFileEntry(mockFileSystem, '/test.crx'); |
| 128 |
| 129 reportPromise(showHtmlOfAlertDialogIsCalled( |
| 130 [mockEntry], 'NO_ACTION_FOR_CRX_TITLE', 'NO_ACTION_FOR_CRX'), callback); |
| 131 } |
| 132 |
| 133 function testToOpenRtfFile(callback) { |
| 134 var mockFileSystem = new MockFileSystem('volumeId'); |
| 135 var mockEntry = new MockFileEntry(mockFileSystem, '/test.rtf'); |
| 136 |
| 137 reportPromise(openSuggestAppsDialogIsCalled([mockEntry]), callback); |
| 138 } |
OLD | NEW |