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

Unified Diff: ui/file_manager/gallery/js/background.js

Issue 304683002: Add the browser test for the new gallery. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 7 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
« no previous file with comments | « ui/file_manager/file_manager/background/js/volume_manager.js ('k') | ui/file_manager/gallery/manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/gallery/js/background.js
diff --git a/ui/file_manager/gallery/js/background.js b/ui/file_manager/gallery/js/background.js
index 4c5d2582339c57ffbe9390652f5bf01a7c7dec34..0051dba88d3c5a2c25f2e37c06d794afc1b58bb3 100644
--- a/ui/file_manager/gallery/js/background.js
+++ b/ui/file_manager/gallery/js/background.js
@@ -103,45 +103,14 @@ var appWindowPromise = Promise.resolve(null);
*/
var closingPromise = Promise.resolve(null);
-chrome.app.runtime.onLaunched.addListener(function(launchData) {
- // Skip if files are not selected.
- if (!launchData || !launchData.items || launchData.items.length == 0)
- return;
-
- // Obtains entries in non-isolated file systems.
- // The entries in launchData are stored in the isolated file system.
- // We need to map the isolated entries to the normal entries to retrieve their
- // parent directory.
- var isolatedEntries = launchData.items.map(function(item) {
- return item.entry;
- });
- var selectedEntriesPromise = backgroundComponentsPromise.then(function() {
- return resolveEntries(isolatedEntries);
- });
-
- // If only 1 entry is selected, retrieve entries in the same directory.
- // Otherwise, just use the selectedEntries as an entry set.
- var allEntriesPromise = selectedEntriesPromise.then(function(entries) {
- if (entries.length === 1) {
- var parent = new Promise(entries[0].getParent.bind(entries[0]));
- return parent.then(getChildren).then(function(entries) {
- return entries.filter(FileType.isImageOrVideo);
- });
- } else {
- return entries;
- }
- });
-
- // Store the selected and all entries to the launchData.
- launchData.entriesPromise = Promise.all([selectedEntriesPromise,
- allEntriesPromise]).then(
- function(args) {
- return Object.freeze({
- selectedEntries: args[0],
- allEntries: args[1]
- });
- });
-
+/**
+ * Launches the application with entries.
+ *
+ * @param {Promise} selectedEntriesPromise Promise to be fulfilled with the
+ * entries that are stored in the exteranl file system (not in the isolated
+ * file system).
+ */
+function launch(selectedEntriesPromise) {
// If there is the previous window, close the window.
appWindowPromise = appWindowPromise.then(function(appWindow) {
if (appWindow) {
@@ -180,14 +149,61 @@ chrome.app.runtime.onLaunched.addListener(function(launchData) {
return args[0];
});
+
+ // If only 1 entry is selected, retrieve entries in the same directory.
+ // Otherwise, just use the selectedEntries as an entry set.
+ var allEntriesPromise = selectedEntriesPromise.then(function(entries) {
+ if (entries.length === 1) {
+ var parentPromise = new Promise(entries[0].getParent.bind(entries[0]));
+ return parentPromise.then(getChildren).then(function(entries) {
+ return entries.filter(FileType.isImageOrVideo);
+ });
+ } else {
+ return entries;
+ }
+ });
+
// Open entries.
- Promise.all([
+ return Promise.all([
appWindowPromise,
allEntriesPromise,
selectedEntriesPromise
]).then(function(args) {
args[0].contentWindow.loadEntries(args[1], args[2]);
- }).catch(function(error) {
+ });
+}
+
+chrome.app.runtime.onLaunched.addListener(function(launchData) {
+ // Skip if files are not selected.
+ if (!launchData || !launchData.items || launchData.items.length === 0)
+ return;
+
+ // Obtains entries in non-isolated file systems.
+ // The entries in launchData are stored in the isolated file system.
+ // We need to map the isolated entries to the normal entries to retrieve their
+ // parent directory.
+ var isolatedEntries = launchData.items.map(function(item) {
+ return item.entry;
+ });
+ var selectedEntriesPromise = backgroundComponentsPromise.then(function() {
+ return resolveEntries(isolatedEntries);
+ });
+
+ launch(selectedEntriesPromise).catch(function(error) {
console.error(error.stack || error);
});
});
+
+// If is is run in the browser test, wait for the test resources are installed
+// as a component extension, and then load the test resources.
+if (chrome.test) {
+ chrome.runtime.onMessageExternal.addListener(function(message) {
+ if (message.name !== 'testResourceLoaded')
+ return;
+ var script = document.createElement('script');
+ script.src =
+ 'chrome-extension://ejhcmmdhhpdhhgmifplfmjobgegbibkn' +
+ '/gallery/test_loader.js';
+ document.documentElement.appendChild(script);
+ });
+}
« no previous file with comments | « ui/file_manager/file_manager/background/js/volume_manager.js ('k') | ui/file_manager/gallery/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698