OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 window.chrome = { | |
6 fileManagerPrivate: { | |
7 getFileTasks: function(entries, callback) { | |
8 setTimeout(callback.bind(null, [ | |
9 {taskId:'handler-extension-id|file|open', isDefault: false}, | |
10 {taskId:'handler-extension-id|file|play', isDefault: true} | |
11 ]), 0); | |
12 } | |
13 }, | |
14 runtime: {id: 'test-extension-id'} | |
15 }; | |
16 | |
17 window.metrics = { | 5 window.metrics = { |
18 recordEnum: function() {} | 6 recordEnum: function() {} |
19 }; | 7 }; |
20 | 8 |
| 9 function setUp() { |
| 10 // Behavior of window.chrome depends on each test case. window.chrome should |
| 11 // be initialized properly inside each test function. |
| 12 window.chrome = {}; |
| 13 |
| 14 cr.ui.decorate('command', cr.ui.Command); |
| 15 } |
| 16 |
21 function testDoEntryAction(callback) { | 17 function testDoEntryAction(callback) { |
22 cr.ui.decorate('command', cr.ui.Command); | 18 window.chrome = { |
| 19 fileManagerPrivate: { |
| 20 getFileTasks: function(entries, callback) { |
| 21 setTimeout(callback.bind(null, [ |
| 22 {taskId:'handler-extension-id|file|open', isDefault: false}, |
| 23 {taskId:'handler-extension-id|file|play', isDefault: true} |
| 24 ]), 0); |
| 25 } |
| 26 }, |
| 27 runtime: {id: 'test-extension-id'} |
| 28 }; |
| 29 |
23 var fileSystem = new MockFileSystem('volumeId'); | 30 var fileSystem = new MockFileSystem('volumeId'); |
24 fileSystem.entries['/test.png'] = | 31 fileSystem.entries['/test.png'] = |
25 new MockFileEntry(fileSystem, '/test.png', {}); | 32 new MockFileEntry(fileSystem, '/test.png', {}); |
26 var metadataCache = new MockMetadataCache(); | 33 var metadataCache = new MockMetadataCache(); |
27 metadataCache.setForTest(fileSystem.entries['/test.png'], 'external', {}); | 34 metadataCache.setForTest(fileSystem.entries['/test.png'], 'external', {}); |
28 var controller = new TaskController( | 35 var controller = new TaskController( |
29 DialogType.FULL_PAGE, | 36 DialogType.FULL_PAGE, |
30 { | 37 { |
31 taskMenuButton: document.createElement('button'), | 38 taskMenuButton: document.createElement('button'), |
32 fileContextMenu: { | 39 fileContextMenu: { |
(...skipping 16 matching lines...) Expand all Loading... |
49 }); | 56 }); |
50 }); | 57 }); |
51 | 58 |
52 controller.doEntryAction(fileSystem.entries['/test.png']); | 59 controller.doEntryAction(fileSystem.entries['/test.png']); |
53 reportPromise(new Promise(function(fulfill) { | 60 reportPromise(new Promise(function(fulfill) { |
54 chrome.fileManagerPrivate.executeTask = fulfill; | 61 chrome.fileManagerPrivate.executeTask = fulfill; |
55 }).then(function(info) { | 62 }).then(function(info) { |
56 assertEquals("handler-extension-id|file|play", info); | 63 assertEquals("handler-extension-id|file|play", info); |
57 }), callback); | 64 }), callback); |
58 } | 65 } |
| 66 |
| 67 /** |
| 68 * Test case for openSuggestAppsDialog with an entry which has external type of |
| 69 * metadata. |
| 70 */ |
| 71 function testOpenSuggestAppsDialogWithMetadata(callback) { |
| 72 var showByExtensionAndMimeIsCalled = new Promise(function(resolve, reject) { |
| 73 var fileSystem = new MockFileSystem('volumeId'); |
| 74 var entry = new MockFileEntry(fileSystem, '/test.rtf'); |
| 75 |
| 76 var controller = new TaskController( |
| 77 DialogType.FULL_PAGE, |
| 78 { |
| 79 taskMenuButton: document.createElement('button'), |
| 80 fileContextMenu: { |
| 81 defaultActionMenuItem: document.createElement('div') |
| 82 }, |
| 83 suggestAppsDialog: { |
| 84 showByExtensionAndMime: function( |
| 85 extension, mimeType, onDialogClosed) { |
| 86 assertEquals('.rtf', extension); |
| 87 assertEquals('application/rtf', mimeType); |
| 88 resolve(); |
| 89 } |
| 90 } |
| 91 }, |
| 92 { |
| 93 getOne: function(entry, type, callback) { |
| 94 assertEquals('external', type); |
| 95 callback({ |
| 96 contentMimeType: 'application/rtf' |
| 97 }); |
| 98 } |
| 99 }, |
| 100 new cr.EventTarget(), |
| 101 null, |
| 102 null); |
| 103 |
| 104 controller.openSuggestAppsDialog( |
| 105 entry, function() {}, function() {}, function() {}); |
| 106 }); |
| 107 |
| 108 reportPromise(showByExtensionAndMimeIsCalled, callback); |
| 109 } |
| 110 |
| 111 /** |
| 112 * Test case for openSuggestAppsDialog with an entry which doesn't have external |
| 113 * type of metadata. |
| 114 */ |
| 115 function testOpenSuggestAppsDialogWithoutMetadata(callback) { |
| 116 window.chrome = { |
| 117 fileManagerPrivate: { |
| 118 getMimeType: function(url, callback) { |
| 119 callback('application/rtf'); |
| 120 } |
| 121 } |
| 122 }; |
| 123 |
| 124 var showByExtensionAndMimeIsCalled = new Promise(function(resolve, reject) { |
| 125 var isGetOneCalled = false; |
| 126 var fileSystem = new MockFileSystem('volumeId'); |
| 127 var entry = new MockFileEntry(fileSystem, '/test.rtf'); |
| 128 |
| 129 var controller = new TaskController( |
| 130 DialogType.FULL_PAGE, |
| 131 { |
| 132 taskMenuButton: document.createElement('button'), |
| 133 fileContextMenu: { |
| 134 defaultActionMenuItem: document.createElement('div') |
| 135 }, |
| 136 suggestAppsDialog: { |
| 137 showByExtensionAndMime: function( |
| 138 extension, mimeType, onDialogClosed) { |
| 139 assertTrue(isGetOneCalled); |
| 140 assertEquals('.rtf', extension); |
| 141 assertEquals('application/rtf', mimeType); |
| 142 resolve(); |
| 143 } |
| 144 } |
| 145 }, |
| 146 { |
| 147 getOne: function(entry, type, callback) { |
| 148 isGetOneCalled = true; |
| 149 callback({}); |
| 150 } |
| 151 }, |
| 152 new cr.EventTarget(), |
| 153 null, |
| 154 null); |
| 155 |
| 156 controller.openSuggestAppsDialog( |
| 157 entry, function() {}, function() {}, function() {}); |
| 158 }); |
| 159 |
| 160 reportPromise(showByExtensionAndMimeIsCalled, callback); |
| 161 } |
| 162 |
| 163 /** |
| 164 * Test case for openSuggestAppsDialog with an entry which doesn't have |
| 165 * extensiion. Since both extension and MIME type are required for |
| 166 * openSuggestAppsDialogopen, onFalure should be called for this test case. |
| 167 */ |
| 168 function testOpenSuggestAppsDialogFailure(callback) { |
| 169 var onFailureIsCalled = new Promise(function(resolve, reject) { |
| 170 var fileSystem = new MockFileSystem('volumeId'); |
| 171 var entry = new MockFileEntry(fileSystem, '/test'); |
| 172 |
| 173 var controller = new TaskController( |
| 174 DialogType.FULL_PAGE, |
| 175 { |
| 176 taskMenuButton: document.createElement('button'), |
| 177 fileContextMenu: { |
| 178 defaultActionMenuItem: document.createElement('div') |
| 179 } |
| 180 }, |
| 181 { |
| 182 getOne: function(entry, type, callback) { |
| 183 assertEquals('external', type); |
| 184 callback({ |
| 185 contentMimeType: 'image/png' |
| 186 }); |
| 187 } |
| 188 }, |
| 189 new cr.EventTarget(), |
| 190 null, |
| 191 null); |
| 192 |
| 193 controller.openSuggestAppsDialog( |
| 194 entry, function() {}, function() {}, resolve); |
| 195 }); |
| 196 |
| 197 reportPromise(onFailureIsCalled, callback); |
| 198 } |
OLD | NEW |