1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * Renames an image in thumbnail mode and confirms that thumbnail of renamed
7 * image is successfully updated.
8 * @param {string} testVolumeName Test volume name.
9 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
10 * @return {!Promise} Promise to be fulfilled with on success.
12 function renameImageInThumbnailMode(testVolumeName, volumeType) {
13 var launchedPromise = launch(testVolumeName, volumeType,
14 [ENTRIES.desktop, ENTRIES.image3], [ENTRIES.desktop]);
16 return launchedPromise.then(function(result) {
17 // Confirm initial state after the launch.
19 return gallery.waitForSlideImage(appId, 800, 600, 'My Desktop Background');
21 // Goes to thumbnail mode.
22 return gallery.waitAndClickElement(appId, 'button.mode');
24 return gallery.selectImageInThumbnailMode(appId, 'image3.jpg');
25 }).then(function(result) {
26 chrome.test.assertTrue(result);
27 return gallery.callRemoteTestUtil('changeName', appId, ['New Image Name']);
29 // Assert that rename had done successfully.
30 return gallery.waitForAFile(volumeType, 'New Image Name.jpg');
32 return gallery.selectImageInThumbnailMode(
33 appId, 'My Desktop Background.png');
34 }).then(function(result) {
35 chrome.test.assertTrue(result);
36 return gallery.callRemoteTestUtil('queryAllElements', appId,
37 ['.thumbnail-view > ul > li.selected']);
38 }).then(function(result) {
39 // Only My Desktop Background.png is selected.
40 chrome.test.assertEq(1, result.length);
42 chrome.test.assertEq('My Desktop Background.png',
43 result[0].attributes['title']);
44 return gallery.callRemoteTestUtil('queryAllElements', appId,
45 ['.thumbnail-view > ul > li:not(.selected)']);
46 }).then(function(result) {
47 // Confirm that thumbnail of renamed image has updated.
48 chrome.test.assertEq(1, result.length);
49 chrome.test.assertEq('New Image Name.jpg',
50 result[0].attributes['title']);
55 * Delete all images in thumbnail mode and confirm that no-images error banner
57 * @param {string} testVolumeName Test volume name.
58 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
59 * @return {!Promise} Promise to be fulfilled with on success.
61 function deleteAllImagesInThumbnailMode(testVolumeName, volumeType) {
62 var launchedPromise = launch(testVolumeName, volumeType,
63 [ENTRIES.desktop, ENTRIES.image3]);
65 return launchedPromise.then(function(result) {
67 // Click delete button.
68 return gallery.waitAndClickElement(appId, 'paper-button.delete');
69 }).then(function(result) {
70 chrome.test.assertTrue(!!result);
71 // Wait and click delete button of confirmation dialog.
72 return gallery.waitAndClickElement(appId, '.cr-dialog-ok');
73 }).then(function(result) {
74 chrome.test.assertTrue(!!result);
75 // Wait until error banner is shown.
76 return gallery.waitForElement(appId, '.gallery[error] .error-banner');
81 * Clicks an empty space in thumbnail view and confirms that current selection
83 * @param {string} testVolumeName Test volume name.
84 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
85 * @return {!Promise} Promise to be fulfilled with on success.
87 function emptySpaceClickUnselectsInThumbnailMode(testVolumeName, volumeType) {
88 var launchedPromise = launch(testVolumeName, volumeType,
89 [ENTRIES.desktop, ENTRIES.image3], [ENTRIES.desktop]);
91 return launchedPromise.then(function(result) {
92 // Confirm initial state after the launch.
94 return gallery.waitForSlideImage(appId, 800, 600, 'My Desktop Background');
95 }).then(function(result) {
96 // Switch to thumbnail mode.
97 return gallery.waitAndClickElement(appId, 'button.mode');
98 }).then(function(result) {
99 // Confirm My Desktop Background.png is selected in thumbnail view.
100 return gallery.callRemoteTestUtil('queryAllElements', appId,
101 ['.thumbnail-view > ul > li.selected']);
102 }).then(function(results) {
103 chrome.test.assertEq(1, results.length);
104 chrome.test.assertEq('My Desktop Background.png',
105 results[0].attributes['title']);
106 // Click empty space of thumbnail view.
107 return gallery.waitAndClickElement(appId, '.thumbnail-view > ul');
108 }).then(function(result) {
109 // Confirm no image is selected.
110 return gallery.callRemoteTestUtil('queryAllElements', appId,
111 ['.thumbnail-view > ul > li.selected']);
112 }).then(function(results) {
113 chrome.test.assertEq(0, results.length);
114 // Confirm delete button is disabled.
115 return gallery.waitForElement(appId, 'paper-button.delete[disabled]');
116 }).then(function(result) {
117 // Confirm slideshow button is disabled.
118 return gallery.waitForElement(appId, 'paper-button.slideshow[disabled]');
120 // Switch back to slide mode by clicking mode button.
121 return gallery.waitAndClickElement(appId, 'button.mode:not([disabled])');
122 }).then(function(result) {
123 // First image in the image set (image3) should be shown.
124 return gallery.waitForSlideImage(appId, 640, 480, 'image3');
129 * Rename test in thumbnail mode for Downloads.
130 * @return {!Promise} Promise to be fulfilled with on success.
132 testcase.renameImageInThumbnailModeOnDownloads = function() {
133 return renameImageInThumbnailMode('local', 'downloads');
137 * Rename test in thumbnail mode for Drive.
138 * @return {!Promise} Promise to be fulfilled with on success.
140 testcase.renameImageInThumbnailModeOnDrive = function() {
141 return renameImageInThumbnailMode('drive', 'drive');
145 * Delete all images test in thumbnail mode for Downloads.
146 * @return {!Promise} Promise to be fulfilled with on success.
148 testcase.deleteAllImagesInThumbnailModeOnDownloads = function() {
149 return deleteAllImagesInThumbnailMode('local', 'downloads');
153 * Delete all images test in thumbnail mode for Drive.
154 * @return {!Promise} Promise to be fulfilled with on success.
156 testcase.deleteAllImagesInThumbnailModeOnDrive = function() {
157 return deleteAllImagesInThumbnailMode('drive', 'drive');
161 * Empty space click unselects current selection in thumbnail mode for
163 * @return {!Promise} Promise to be fulfilled with on success.
165 testcase.emptySpaceClickUnselectsInThumbnailModeOnDownloads = function() {
166 return emptySpaceClickUnselectsInThumbnailMode('local', 'downloads');
170 * Empty space click unselects current selection in thumbnail mode for Drive.
171 * @return {!Promise} Promise to be fulfilled with on success.
173 testcase.emptySpaceClickUnselectsInThumbnailModeOnDrive = function() {
174 return emptySpaceClickUnselectsInThumbnailMode('drive', 'drive');