Commit cfc3286b authored by Sasha Morrissey's avatar Sasha Morrissey Committed by Commit Bot

Fix incorrect check in 'Manage with Drive' action, and add test

Fix check in 'Manage with Drive' action, and add test to ensure it
doesn't regress again. Also added getLastVisitedUrl() in util.js to get
the URL opened by the Manage in Drive button.

Bug: 831480
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I382a662607103d60a5c9a7c58643eff0f9f62106
Reviewed-on: https://chromium-review.googlesource.com/1058884
Commit-Queue: Sasha Morrissey <sashab@chromium.org>
Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#559441}
parent e695d4ed
......@@ -253,10 +253,12 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
TestCase("restoreGeometryMaximized")));
WRAPPED_INSTANTIATE_TEST_CASE_P(
ShareDialog, /* share_dialog.js */
ShareAndManageDialog, /* share_and_manage_dialog.js */
FileManagerBrowserTest,
::testing::Values(TestCase("shareFile"),
TestCase("shareDirectory")));
TestCase("shareDirectory"),
TestCase("manageHostedFile"),
TestCase("manageFile")));
WRAPPED_INSTANTIATE_TEST_CASE_P(
SuggestAppDialog, /* suggest_app_dialog.js */
......
......@@ -1735,9 +1735,16 @@ const FakeDriveService::EntryInfo* FakeDriveService::AddNewEntry(
// Set mime type.
new_file->set_mime_type(content_type);
// Set alternate link if needed.
if (content_type == util::kGoogleDocumentMimeType)
new_file->set_alternate_link(GURL("https://document_alternate_link"));
// Set alternate link.
if (content_type == util::kGoogleDocumentMimeType) {
new_file->set_alternate_link(
GURL("https://document_alternate_link/" + title));
} else if (content_type == util::kDriveFolderMimeType) {
new_file->set_alternate_link(
GURL("https://folder_alternate_link/" + title));
} else {
new_file->set_alternate_link(GURL("https://file_alternate_link/" + title));
}
// Set parents.
if (!parent_resource_id.empty()) {
......
......@@ -159,6 +159,16 @@ test.util.sync.getTreeItems = function(contentWindow) {
return result;
};
/**
* Returns the last URL visited with visitURL() (e.g. for "Manage in Drive").
*
* @param {Window} contentWindow The window where visitURL() was called.
* @return {!string} The URL of the last URL visited.
*/
test.util.sync.getLastVisitedURL = function(contentWindow) {
return contentWindow.util.getLastVisitedURL();
};
/**
* Executes Javascript code on a webview and returns the result.
*
......
......@@ -902,18 +902,37 @@ util.isDescendantEntry = function(ancestorEntry, childEntry) {
return childEntry.fullPath.indexOf(ancestorPath) === 0;
};
/**
* The last URL with visitURL().
*
* @type {string}
* @private
*/
util.lastVisitedURL;
/**
* Visit the URL.
*
* If the browser is opening, the url is opened in a new tag, otherwise the url
* is opened in a new window.
*
* @param {string} url URL to visit.
* @param {!string} url URL to visit.
*/
util.visitURL = function(url) {
util.lastVisitedURL = url;
window.open(url);
};
/**
* Return the last URL visited with visitURL().
*
* @return {string} The last URL visited.
*/
util.getLastVisitedURL = function() {
return util.lastVisitedURL;
};
/**
* Returns normalized current locale, or default locale - 'en'.
* @return {string} Current locale
......
......@@ -472,7 +472,7 @@ DriveManageAction.prototype.execute = function() {
console.error(chrome.runtime.lastError.message);
return;
}
if (results.length == 1) {
if (results.length != 1) {
console.error(
'getEntryProperties for alternateUrl should return 1 entry ' +
'(returned ' + results.length + ')');
......
......@@ -19,8 +19,7 @@ function share(path) {
// Select the source file.
function(results) {
appId = results.windowId;
remoteCall.callRemoteTestUtil(
'selectFile', appId, [path], this.next);
remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next);
},
// Wait for the share button.
function(result) {
......@@ -52,51 +51,50 @@ function share(path) {
// Wait until the share dialog's contents are shown.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, '.share-dialog-webview-wrapper.loaded').
then(this.next);
remoteCall.waitForElement(appId, '.share-dialog-webview-wrapper.loaded')
.then(this.next);
},
function(result) {
chrome.test.assertTrue(!!result);
repeatUntil(function() {
return remoteCall.callRemoteTestUtil(
'queryAllElements',
appId,
[
'.share-dialog-webview-wrapper.loaded',
null /* iframe */,
['width', 'height']
]).
then(function(elements) {
// TODO(mtomasz): Fix the wrong geometry of the share dialog.
// return elements[0] &&
// elements[0].styles.width === '350px' &&
// elements[0].styles.height === '250px' ?
// undefined :
// pending('Dialog wrapper is currently %j. ' +
// 'but should be: 350x250',
// elements[0]);
return elements[0] ?
undefined :
pending(caller, 'The share dialog is not found.');
});
}).
then(this.next);
return remoteCall
.callRemoteTestUtil(
'queryAllElements', appId,
[
'.share-dialog-webview-wrapper.loaded', null /* iframe */,
['width', 'height']
])
.then(function(elements) {
// TODO(mtomasz): Fix the wrong geometry of the share dialog.
// return elements[0] &&
// elements[0].styles.width === '350px' &&
// elements[0].styles.height === '250px' ?
// undefined :
// pending('Dialog wrapper is currently %j. ' +
// 'but should be: 350x250',
// elements[0]);
return elements[0] ?
undefined :
pending(caller, 'The share dialog is not found.');
});
}).then(this.next);
},
// Wait until the share dialog's contents are shown.
function(result) {
remoteCall.callRemoteTestUtil(
'executeScriptInWebView',
appId,
['.share-dialog-webview-wrapper.loaded webview',
'document.querySelector("button").click()'],
'executeScriptInWebView', appId,
[
'.share-dialog-webview-wrapper.loaded webview',
'document.querySelector("button").click()'
],
this.next);
},
// Wait until the share dialog's contents are hidden.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.waitForElementLost(
appId, '.share-dialog-webview-wrapper.loaded').
then(this.next);
remoteCall
.waitForElementLost(appId, '.share-dialog-webview-wrapper.loaded')
.then(this.next);
},
// Check for Javascript errros.
function() {
......@@ -105,6 +103,79 @@ function share(path) {
]);
}
/**
* Test clicking 'Manage in Drive' for a file or directory on Drive.
*
* @param {!string} path Path for a file or a directory to be shared.
* @param {!string} expected_manage_url Expected URL for the browser to visit.
*/
function manage(path, expected_manage_url) {
var appId;
var caller = getCaller();
StepsRunner.run([
// Set up File Manager.
function() {
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next);
},
// Select the source file.
function(results) {
appId = results.windowId;
remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next);
},
// Wait for the file to be selected.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, '.table-row[selected]').then(this.next);
},
// Right-click on the file.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]'], this.next);
},
// Wait for the context menu to appear.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])')
.then(this.next);
},
// Wait for the "Manage in Drive" option to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall
.waitForElement(
appId,
'[command="#manage-in-drive"]:not([hidden]):not([disabled])')
.then(this.next);
},
// Select "Manage in Drive".
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId,
['[command="#manage-in-drive"]:not([hidden]):not([disabled])'],
this.next);
},
// Wait for the context menu to disappear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.waitForElement(appId, '#file-context-menu[hidden]')
.then(this.next);
},
// Wait for the browser window to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil('getLastVisitedURL', appId, [], this.next);
},
// Check we went to the correct URL, and for Javascript errors.
function(visitedUrl) {
chrome.test.assertEq(expected_manage_url, visitedUrl);
checkIfNoErrorsOccured(this.next);
}
]);
}
/**
* Tests sharing a file on Drive.
*/
......@@ -118,3 +189,18 @@ testcase.shareFile = function() {
testcase.shareDirectory = function() {
share('photos');
};
/**
* Tests managing a hosted file (gdoc) on Drive.
*/
testcase.manageHostedFile = function() {
manage(
'Test Document.gdoc', 'https://document_alternate_link/Test%20Document');
};
/**
* Tests managing a hosted file on Drive.
*/
testcase.manageFile = function() {
manage('world.ogv', 'https://file_alternate_link/world.ogv');
};
......@@ -32,7 +32,7 @@
"file_manager/quick_view.js",
"file_manager/restore_geometry.js",
"file_manager/restore_prefs.js",
"file_manager/share_dialog.js",
"file_manager/share_and_manage_dialog.js",
"file_manager/sort_columns.js",
"file_manager/suggest_app_dialog.js",
"file_manager/tab_index.js",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment