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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Opens a file dialog and waits for closing it. | |
9 * | |
10 * @param {string} volumeName Volume name passed to the selectVolume remote | |
11 * funciton. | |
12 * @param {Array.<TestEntryInfo>} expectedSet Expected set of the entries. | |
13 * @param {function(windowId:string):Promise} closeDialog Function to close the | |
14 * dialog. | |
15 * @return {Promise} Promise to be fulfilled with the result entry of the | |
16 * dialog. | |
17 */ | |
18 function openAndWaitForClosingDialog(volumeName, expectedSet, closeDialog) { | |
19 var resultPromise = new Promise(function(fulfill) { | |
20 chrome.fileSystem.chooseEntry( | |
21 {type: 'openFile'}, | |
22 function(entry) { fulfill(entry); }); | |
23 }); | |
24 | |
25 return remoteCall.waitForWindow('dialog#').then(function(windowId) { | |
26 return remoteCall.waitForElement(windowId, '#file-list'). | |
27 then(function() { | |
28 // Wait for initialization of Files.app. | |
29 return remoteCall.waitForFiles( | |
30 windowId, TestEntryInfo.getExpectedRows(BASIC_LOCAL_ENTRY_SET)); | |
31 }). | |
32 then(function() { | |
33 return remoteCall.callRemoteTestUtil( | |
34 'selectVolume', windowId, [volumeName]); | |
35 }). | |
36 then(function() { | |
37 var expectedRows = TestEntryInfo.getExpectedRows(expectedSet); | |
38 return remoteCall.waitForFiles(windowId, expectedRows); | |
39 }). | |
40 then(function() { | |
41 return remoteCall.callRemoteTestUtil( | |
42 'selectFile', windowId, ['hello.txt']); | |
43 }). | |
44 then(closeDialog.bind(null, windowId)). | |
45 then(function() { | |
46 return repeatUntil(function() { | |
47 return remoteCall.callRemoteTestUtil('getWindows', null, []). | |
48 then(function(windows) { | |
49 if (windows[windowId]) | |
50 return pending('Window %s does not hide.', windowId); | |
51 else | |
52 return resultPromise; | |
53 }); | |
54 }); | |
55 }); | |
56 }); | |
57 } | |
58 | |
59 /** | |
60 * Tests to open and cancel the file dialog. | 8 * Tests to open and cancel the file dialog. |
61 * | 9 * |
62 * @param {string} volumeName Volume name passed to the selectVolume remote | 10 * @param {string} volumeName Volume name passed to the selectVolume remote |
63 * funciton. | 11 * funciton. |
64 * @param {Array.<TestEntryInfo>} expectedSet Expected set of the entries. | 12 * @param {Array.<TestEntryInfo>} expectedSet Expected set of the entries. |
65 * @return {Promsie} Promise to be fulfilled/rejected depending on the test | 13 * @return {Promsie} Promise to be fulfilled/rejected depending on the test |
66 * result. | 14 * result. |
67 */ | 15 */ |
68 function openFileDialog(volumeName, expectedSet) { | 16 function openFileDialog(volumeName, expectedSet) { |
69 var localEntriesPromise = addEntries(['local'], BASIC_LOCAL_ENTRY_SET); | 17 var localEntriesPromise = addEntries(['local'], BASIC_LOCAL_ENTRY_SET); |
70 var driveEntriesPromise = addEntries(['drive'], BASIC_DRIVE_ENTRY_SET); | 18 var driveEntriesPromise = addEntries(['drive'], BASIC_DRIVE_ENTRY_SET); |
71 var setupPromise = Promise.all([localEntriesPromise, driveEntriesPromise]); | 19 var setupPromise = Promise.all([localEntriesPromise, driveEntriesPromise]); |
72 | 20 |
73 var closeByCancelButtonPromise = setupPromise.then(function() { | 21 var closeByCancelButtonPromise = setupPromise.then(function() { |
74 return openAndWaitForClosingDialog( | 22 return openAndWaitForClosingDialog( |
| 23 {type: 'openFile'}, |
75 volumeName, | 24 volumeName, |
76 expectedSet, | 25 expectedSet, |
77 function(windowId) { | 26 function(windowId) { |
78 return remoteCall.waitForElement(windowId, | 27 return remoteCall.callRemoteTestUtil( |
79 '.button-panel button.cancel'). | 28 'selectFile', windowId, ['hello.txt'] |
80 then(function() { | 29 ).then(function() { |
81 return remoteCall.callRemoteTestUtil( | 30 return remoteCall.waitForElement(windowId, |
82 'fakeEvent', | 31 '.button-panel button.cancel'); |
83 windowId, | 32 }).then(function() { |
84 ['.button-panel button.cancel', 'click']); | 33 return remoteCall.callRemoteTestUtil( |
85 }); | 34 'fakeEvent', |
| 35 windowId, |
| 36 ['.button-panel button.cancel', 'click']); |
| 37 }); |
86 }); | 38 }); |
87 }).then(function(result) { | 39 }).then(function(result) { |
88 // Undefined means the dialog is canceled. | 40 // Undefined means the dialog is canceled. |
89 chrome.test.assertEq(undefined, result); | 41 chrome.test.assertEq(undefined, result); |
90 }); | 42 }); |
91 | 43 |
92 var closeByEscKeyPromise = closeByCancelButtonPromise.then(function() { | 44 var closeByEscKeyPromise = closeByCancelButtonPromise.then(function() { |
93 return openAndWaitForClosingDialog( | 45 return openAndWaitForClosingDialog( |
| 46 {type: 'openFile'}, |
94 volumeName, | 47 volumeName, |
95 expectedSet, | 48 expectedSet, |
96 function(windowId) { | 49 function(windowId) { |
97 return remoteCall.callRemoteTestUtil( | 50 return remoteCall.callRemoteTestUtil( |
98 'fakeKeyDown', | 51 'selectFile', windowId, ['hello.txt'] |
99 windowId, | 52 ).then(function() { |
100 ['#file-list', 'U+001B', false]); | 53 return remoteCall.callRemoteTestUtil( |
| 54 'fakeKeyDown', |
| 55 windowId, |
| 56 ['#file-list', 'U+001B', false]); |
| 57 }); |
101 }); | 58 }); |
102 }).then(function(result) { | 59 }).then(function(result) { |
103 // Undefined means the dialog is canceled. | 60 // Undefined means the dialog is canceled. |
104 chrome.test.assertEq(undefined, result); | 61 chrome.test.assertEq(undefined, result); |
105 }); | 62 }); |
106 | 63 |
107 var closeByOkButtonPromise = closeByEscKeyPromise.then(function() { | 64 var closeByOkButtonPromise = closeByEscKeyPromise.then(function() { |
108 return openAndWaitForClosingDialog( | 65 return openAndWaitForClosingDialog( |
| 66 {type: 'openFile'}, |
109 volumeName, | 67 volumeName, |
110 expectedSet, | 68 expectedSet, |
111 function(windowId) { | 69 function(windowId) { |
112 return remoteCall.waitForElement(windowId, | 70 return remoteCall.callRemoteTestUtil( |
113 '.button-panel button.ok'). | 71 'selectFile', windowId, ['hello.txt'] |
114 then(function() { | 72 ).then(function() { |
115 return remoteCall.callRemoteTestUtil( | 73 return remoteCall.waitForElement(windowId, |
116 'fakeEvent', | 74 '.button-panel button.ok'); |
117 windowId, | 75 }).then(function() { |
118 ['.button-panel button.ok', 'click']); | 76 return remoteCall.callRemoteTestUtil( |
119 }); | 77 'fakeEvent', |
| 78 windowId, |
| 79 ['.button-panel button.ok', 'click']); |
| 80 }); |
120 }); | 81 }); |
121 }).then(function(result) { | 82 }).then(function(result) { |
122 chrome.test.assertEq('hello.txt', result.name); | 83 chrome.test.assertEq('hello.txt', result.name); |
123 }); | 84 }); |
124 | 85 |
125 return closeByOkButtonPromise; | 86 return closeByOkButtonPromise; |
126 } | 87 } |
127 | 88 |
128 testcase.openFileDialogOnDownloads = function() { | 89 testcase.openFileDialogOnDownloads = function() { |
129 testPromise(openFileDialog('downloads', BASIC_LOCAL_ENTRY_SET)); | 90 testPromise(openFileDialog('downloads', BASIC_LOCAL_ENTRY_SET)); |
130 }; | 91 }; |
131 | 92 |
132 testcase.openFileDialogOnDrive = function() { | 93 testcase.openFileDialogOnDrive = function() { |
133 testPromise(openFileDialog('drive', BASIC_DRIVE_ENTRY_SET)); | 94 testPromise(openFileDialog('drive', BASIC_DRIVE_ENTRY_SET)); |
134 }; | 95 }; |
135 | 96 |
136 testcase.unloadFileDialog = function() { | 97 testcase.unloadFileDialog = function() { |
137 chrome.fileSystem.chooseEntry({type: 'openFile'}, function(entry) {}); | 98 chrome.fileSystem.chooseEntry({type: 'openFile'}, function(entry) {}); |
138 | 99 |
139 testPromise(remoteCall.waitForWindow('dialog#').then(function(windowId) { | 100 testPromise(remoteCall.waitForWindow('dialog#').then(function(windowId) { |
140 return remoteCall.callRemoteTestUtil('unload', windowId, []). | 101 return remoteCall.callRemoteTestUtil('unload', windowId, []). |
141 then(function() { | 102 then(function() { |
142 return remoteCall.callRemoteTestUtil('getErrorCount', windowId, []); | 103 return remoteCall.callRemoteTestUtil('getErrorCount', windowId, []); |
143 }). | 104 }). |
144 then(function(num) { | 105 then(function(num) { |
145 chrome.test.assertEq(0, num); | 106 chrome.test.assertEq(0, num); |
146 }); | 107 }); |
147 })); | 108 })); |
148 }; | 109 }; |
OLD | NEW |