summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/resources/file_manager/js/file_manager.js13
-rw-r--r--chrome/browser/resources/file_manager/js/file_manager_pyauto.js51
-rw-r--r--chrome/test/functional/chromeos_file_browser.py15
-rw-r--r--chrome/test/pyautolib/chromeos/file_browser.py21
4 files changed, 81 insertions, 19 deletions
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index a7174a1..18c5dfe 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -2233,6 +2233,19 @@ FileManager.prototype = {
}
/**
+ * Get remaining and total size of selected directory in KB.
+ *
+ * @param {object} callback Function to call with stats string as the
+ * argument.
+ */
+ FileManager.prototype.getSelectedDirectorySizeStats = function(callback) {
+ directoryURL = fileManager.selection.entries[0].toURL();
+ chrome.fileBrowserPrivate.getSizeStats(directoryURL, function(stats) {
+ callback(stats);
+ });
+ }
+
+ /**
* Used by tests to wait before interacting with the file maanager
*/
FileManager.prototype.isInitialized = function() {
diff --git a/chrome/browser/resources/file_manager/js/file_manager_pyauto.js b/chrome/browser/resources/file_manager/js/file_manager_pyauto.js
index fd327fc..f2f8e4d 100644
--- a/chrome/browser/resources/file_manager/js/file_manager_pyauto.js
+++ b/chrome/browser/resources/file_manager/js/file_manager_pyauto.js
@@ -18,18 +18,18 @@ var pyautoAPI = {
*/
addItemToSelection: function(name) {
var itemExists = fileManager.addItemToSelection(name);
- window.domAutomationController.send(itemExists);
+ this.sendValue_(itemExists);
},
/**
* List all items in the current directory.
* We assume names do not contain '|' charecter.
*
- * @return {string} A delimeter seperated string of item names.
+ * @return {object} A a list of item names.
*/
listDirectory: function() {
var list = fileManager.listDirectory();
- window.domAutomationController.send(list.join('|'));
+ this.sendJSONValue_(list);
},
/**
@@ -39,7 +39,7 @@ var pyautoAPI = {
*/
saveItemAs: function(name) {
fileManager.doSaveAs(name);
- window.domAutomationController.send('done');
+ this.sendDone_();
},
/**
@@ -47,7 +47,7 @@ var pyautoAPI = {
*/
openItem: function() {
fileManager.doOpen();
- window.domAutomationController.send('done');
+ this.sendDone_();
},
/**
@@ -55,7 +55,7 @@ var pyautoAPI = {
*/
copyItems: function() {
fileManager.copySelectionToClipboard();
- window.domAutomationController.send('done');
+ this.sendDone_();
},
/**
@@ -63,7 +63,7 @@ var pyautoAPI = {
*/
cutItems: function() {
fileManager.cutSelectionToClipboard();
- window.domAutomationController.send('done');
+ this.sendDone_();
},
/**
@@ -110,7 +110,7 @@ var pyautoAPI = {
*/
changeDirectory: function(path) {
if (path.charAt(0) != '/')
- path = fileManager.getCurrentDirectory() + '/' + path
+ path = fileManager.getCurrentDirectory() + '/' + path;
fileManager.changeDirectory(path, undefined, undefined, this.sendDone_);
},
@@ -120,15 +120,17 @@ var pyautoAPI = {
* @return {string} Path to the current directory.
*/
currentDirectory: function() {
- path = fileManager.getCurrentDirectory()
+ path = fileManager.getCurrentDirectory();
window.domAutomationController.send(path);
},
/**
- * Callback function signalling completion of operation.
+ * Get remaining and total size of selected directory.
+ *
+ * @return {object} remaining and total size in KB.
*/
- sendDone_: function() {
- window.domAutomationController.send('done');
+ getSelectedDirectorySizeStats: function() {
+ fileManager.getSelectedDirectorySizeStats(this.sendJSONValue_);
},
/**
@@ -140,7 +142,28 @@ var pyautoAPI = {
* @return {boolean} Whether file manager is initialied.
*/
isInitialized: function() {
- var initialized = (fileManager != null) && fileManager.isInitialized()
- window.domAutomationController.send(initialized);
+ var initialized = (fileManager != null) && fileManager.isInitialized();
+ this.sendValue_(initialized);
+ },
+
+ /**
+ * Callback function for returning primitiv types (int, string, boolean)
+ */
+ sendValue_: function(value) {
+ window.domAutomationController.send(value);
+ },
+
+ /**
+ * Callback function for returning a JSON encoded value.
+ */
+ sendJSONValue_: function(value) {
+ window.domAutomationController.send(JSON.stringify(value));
+ },
+
+ /**
+ * Callback function signalling completion of operation.
+ */
+ sendDone_: function() {
+ window.domAutomationController.send('done');
},
};
diff --git a/chrome/test/functional/chromeos_file_browser.py b/chrome/test/functional/chromeos_file_browser.py
index 7ec3a68..7329ea2 100644
--- a/chrome/test/functional/chromeos_file_browser.py
+++ b/chrome/test/functional/chromeos_file_browser.py
@@ -239,6 +239,21 @@ class ChromeosFileBrowserTest(pyauto.PyUITest):
self.assertTrue(file_browser, msg='File browser failed to initialize.')
self._CutFolder(file_browser)
+ def testGetSelectedDirectorySizeStats(self):
+ """Test we can get remaining and total size of the file shelf."""
+ file_browser = self._GetFullPageFileBrowser()
+ self.assertTrue(file_browser, msg='File browser failed to initialize.')
+ file_browser.CreateDirectory('apples')
+ file_browser.Select('apples')
+ remaining, total = file_browser.GetSelectedDirectorySizeStats()
+ self.assertTrue(remaining > 0,
+ msg='Remaining disk space = %dKB.' % remaining)
+ self.assertTrue(total > 0,
+ msg='Total disk space = %dKB.' % total)
+ self.assertTrue(total > remaining,
+ msg='Total space(%dKB) <= remaining space(%dKB).' %
+ (total, remaining))
+
if __name__ == '__main__':
pyauto_functional.Main()
diff --git a/chrome/test/pyautolib/chromeos/file_browser.py b/chrome/test/pyautolib/chromeos/file_browser.py
index 112958a..f1892e4 100644
--- a/chrome/test/pyautolib/chromeos/file_browser.py
+++ b/chrome/test/pyautolib/chromeos/file_browser.py
@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import simplejson as json # found in third_party
+
class FileBrowser(object):
"""This class provides an API for automating the ChromeOS File Browser.
@@ -51,11 +53,8 @@ class FileBrowser(object):
script = """
pyautoAPI.listDirectory();
"""
- list = self.executor.Execute(script)
- if list:
- return set(list.split('|'))
- else:
- return None
+ list = json.loads(self.executor.Execute(script))
+ return set(list)
def Save(self, name):
"""Save the entry using the given name.
@@ -150,6 +149,18 @@ class FileBrowser(object):
"""
return self.executor.Execute(script)
+ def GetSelectedDirectorySizeStats(self):
+ """Get remaining and total size of selected directory.
+
+ Returns:
+ A tuple: (remaining size in KB, total size in KB)
+ """
+ script = """
+ pyautoAPI.getSelectedDirectorySizeStats();
+ """
+ stats = json.loads(self.executor.Execute(script))
+ return stats['remainingSizeKB'], stats['totalSizeKB']
+
def WaitUntilInitialized(self):
"""Returns whether the file manager is initialized.