Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7262)

Unified Diff: chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/file_dialog.js

Issue 331583003: Files.app: Add a test to open a file dialog box. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/file_dialog.js
diff --git a/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/file_dialog.js b/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/file_dialog.js
new file mode 100644
index 0000000000000000000000000000000000000000..4b2a5a80df3de82c03c898d8c91b7fa62cf870f2
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/file_dialog.js
@@ -0,0 +1,124 @@
+// 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.
+
+'use strict';
+
+/**
+ * Opens a file dialog and waits for closing it.
+ *
+ * @param {string} volumeName Volume name passed to the selectVolume remote
+ * funciton.
+ * @param {Array.<TestEntryInfo>} expectedSet Expected set of the entries.
+ * @param {function(windowId:string):Promise} closeDialog Function to close the
+ * dialog.
+ * @return {Promise} Promise to be fulfilled with the result entry of the
+ * dialog.
+ */
+function openAndWaitForClosingDialog(volumeName, expectedSet, closeDialog) {
+ var resultProimse = new Promise(function(fulfill) {
fukino 2014/06/17 05:59:10 nit: s/resultProimse/resultPromise/
hirono 2014/06/17 07:07:14 Done.
+ chrome.fileSystem.chooseEntry(
+ {type: 'openFile'},
+ function(entry) { fulfill(entry); });
+ });
+
+ return waitForWindow('dialog#').then(function(id) {
+ return waitForElement(id, '#file-list').then(function() {
+ return callRemoteTestUtil('selectVolume', id, [volumeName]);
fukino 2014/06/17 05:59:10 nit: I think this indent level should be 6 spaces
hirono 2014/06/17 07:07:14 When I started to use Promise, I and @mtomasz disc
+ }).
+ then(function() {
+ var expectedRows = TestEntryInfo.getExpectedRows(expectedSet);
+ return waitForFiles(id, expectedRows);
fukino 2014/06/17 05:59:10 In my workistation, OpenFileDialog/FileManagerBrow
hirono 2014/06/17 07:07:14 Good catch! It looks the test clicks the navigatio
+ }).
+ then(function() {
+ return callRemoteTestUtil('selectFile', id, ['hello.txt']);
+ }).
+ then(closeDialog.bind(null, id)).
+ then(function() {
+ return repeatUntil(function() {
+ return callRemoteTestUtil('getWindows', null, []).
+ then(function(windows) {
+ if (windows[id])
+ return pending('Window %s does not hide.', id);
+ else
+ return resultProimse;
+ });
fukino 2014/06/17 05:59:10 nit: indent level should be same as previous then.
+ });
+ });
+ });
+}
+
+/**
+ * Tests to open and cancel the file dialog.
+ *
+ * @param {string} volumeName Volume name passed to the selectVolume remote
+ * funciton.
+ * @param {Array.<TestEntryInfo>} expectedSet Expected set of the entries.
+ * @return {Promsie} Promise to be fulfilled/rejected depending on the test
+ * result.
+ */
+function openFileDialog(volumeName, expectedSet) {
+ var localEntriesPromise = addEntries(['local'], BASIC_LOCAL_ENTRY_SET);
+ var driveEntriesPromise = addEntries(['drive'], BASIC_DRIVE_ENTRY_SET);
+ var setupPromise = Promise.all([localEntriesPromise, driveEntriesPromise]);
+
+ var closeByCancelButtonPromise = setupPromise.then(function() {
+ return openAndWaitForClosingDialog(
+ volumeName,
+ expectedSet,
+ function(windowId) {
+ return waitForElement(windowId, '.button-panel button.cancel').then(
+ function() {
+ return callRemoteTestUtil(
+ 'fakeEvent',
+ windowId,
+ ['.button-panel button.cancel', 'click']);
+ });
+ });
+ }).then(function(result) {
+ // Undefined means the dialog is canceled.
+ chrome.test.assertEq(undefined, result);
+ });
+
+ var closeByEscKeyPromise = closeByCancelButtonPromise.then(function() {
+ return openAndWaitForClosingDialog(
+ volumeName,
+ expectedSet,
+ function(windowId) {
+ return callRemoteTestUtil(
+ 'fakeKeyDown',
+ windowId,
+ ['#file-list', 'U+001B', false]);
+ });
+ }).then(function(result) {
+ // Undefined means the dialog is canceled.
+ chrome.test.assertEq(undefined, result);
+ });
+
+ var closeByOkButtonPromise = closeByEscKeyPromise.then(function() {
+ return openAndWaitForClosingDialog(
+ volumeName,
+ expectedSet,
+ function(windowId) {
+ return waitForElement(windowId, '.button-panel button.ok').then(
+ function() {
+ return callRemoteTestUtil(
+ 'fakeEvent',
+ windowId,
+ ['.button-panel button.ok', 'click']);
+ });
+ });
+ }).then(function(result) {
+ chrome.test.assertEq('hello.txt', result.name);
+ });
+
+ return closeByOkButtonPromise;
+}
+
+testcase.openFileDialogOnDownloads = function() {
+ testPromise(openFileDialog('downloads', BASIC_LOCAL_ENTRY_SET));
+};
+
+testcase.openFileDialogOnDrive = function() {
+ testPromise(openFileDialog('drive', BASIC_DRIVE_ENTRY_SET));
+};

Powered by Google App Engine
This is Rietveld 408576698