1 // Copyright 2014 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.
8 * Prepares the photo editor.
10 * @param {string} testVolumeName Test volume name passed to the addEntries
11 * function. Either 'drive' or 'local'.
12 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
13 * @return {Promise} Promise to be fulfilled with on success.
15 function setupPhotoEditor(testVolumeName
, volumeType
) {
17 var launchedPromise
= launch(
21 return launchedPromise
.then(function(args
) {
22 var appId
= args
.appId
;
24 // Show the slide image.
25 var slideImagePromise
= gallery
.waitForSlideImage(
29 'My Desktop Background');
31 // Lauch the photo editor.
32 var photoEditorPromise
= slideImagePromise
.then(function() {
33 return gallery
.waitAndClickElement(appId
, 'button.edit');
36 return photoEditorPromise
.then(function() {
43 * Tests to rotate an image.
45 * @param {string} testVolumeName Test volume name passed to the addEntries
46 * function. Either 'drive' or 'local'.
47 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
48 * @return {Promise} Promise to be fulfilled with on success.
50 function rotateImage(testVolumeName
, volumeType
) {
51 var launchedPromise
= setupPhotoEditor(testVolumeName
, volumeType
);
52 return launchedPromise
.then(function(args
) {
53 var appId
= args
.appId
;
54 return gallery
.waitAndClickElement(
55 appId
, '.gallery:not([locked]) button.rotate_right').then(function() {
56 return gallery
.waitForSlideImage(
60 'My Desktop Background');
63 return gallery
.waitAndClickElement(
64 appId
, '.gallery:not([locked]) button.rotate_left');
67 return gallery
.waitForSlideImage(
71 'My Desktop Background');
77 * Tests to crop an image and undoes it.
79 * @param {string} testVolumeName Test volume name passed to the addEntries
80 * function. Either 'drive' or 'local'.
81 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
82 * @return {Promise} Promise to be fulfilled with on success.
84 function cropImage(testVolumeName
, volumeType
) {
85 var launchedPromise
= setupPhotoEditor(testVolumeName
, volumeType
);
86 return launchedPromise
.then(function(args
) {
87 var appId
= args
.appId
;
88 return gallery
.waitAndClickElement(appId
,
89 '.gallery:not([locked]) button.crop').
92 gallery
.waitForElement(appId
, '.crop-overlay')
96 return gallery
.fakeKeyDown(appId
, 'body', 'Enter', false);
99 chrome
.test
.assertTrue(ret
);
101 gallery
.waitForElementLost(appId
, '.crop-overlay')
105 return gallery
.waitForSlideImage(
109 'My Desktop Background');
112 return gallery
.waitAndClickElement(
113 appId
, '.gallery:not([locked]) button.undo');
116 return gallery
.waitForSlideImage(
120 'My Desktop Background');
126 * Tests to exposure an image.
128 * @param {string} testVolumeName Test volume name passed to the addEntries
129 * function. Either 'drive' or 'local'.
130 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
131 * @return {Promise} Promise to be fulfilled with on success.
133 function exposureImage(testVolumeName
, volumeType
) {
134 var launchedPromise
= setupPhotoEditor(testVolumeName
, volumeType
);
135 return launchedPromise
.then(function(args
) {
136 var appId
= args
.appId
;
137 var url
= args
.urls
[0];
138 var buttonQuery
= '.gallery:not([locked]) button.exposure';
140 var origMetadata
= null;
142 // Click the exposure button.
143 return gallery
.waitAndClickElement(appId
, buttonQuery
).then(function() {
144 // Wait until the edit controls appear.
146 gallery
.waitForElement(appId
, '.brightness > paper-slider'),
147 gallery
.waitForElement(appId
, '.contrast > paper-slider'),
150 return gallery
.callRemoteTestUtil(
151 'changeValue', appId
, ['.brightness > paper-slider', 20]);
153 return gallery
.callRemoteTestUtil(
154 'changeValue', appId
, ['.contrast > paper-slider', -20]);
156 return gallery
.callRemoteTestUtil('getMetadata', null, [url
]);
157 }).then(function(metadata
) {
158 origMetadata
= metadata
;
160 // Push the Enter key.
161 return gallery
.fakeKeyDown(appId
, 'body', 'Enter', false);
163 // Wait until the image is updated.
164 return repeatUntil(function() {
165 return gallery
.callRemoteTestUtil('getMetadata', null, [url
])
166 .then(function(metadata
) {
167 if (origMetadata
.modificationTime
!= metadata
.modificationTime
) {
171 '%s is not updated. ' +
172 'First last modified: %s, Second last modified: %s.',
174 origMetadata
.modificationTime
,
175 metadata
.modificationTime
);
184 * Tests whether overwrite original checkbox is enabled or disabled properly.
186 * @param {string} testVolumeName Test volume name passed to the addEntries
187 * function. Either 'drive' or 'local'.
188 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
189 * @return {Promise} Promise to be fulfilled with on success.
191 function enableDisableOverwriteOriginalCheckbox(testVolumeName
, volumeType
) {
193 var launchedPromise
= setupPhotoEditor(testVolumeName
, volumeType
);
194 return launchedPromise
.then(function(result
) {
195 appId
= result
.appId
;
197 // Confirm overwrite original checkbox is enabled and checked.
198 return gallery
.waitForElement(appId
,
199 '.overwrite-original[checked]:not([disabled])');
201 // Uncheck overwrite original.
202 return gallery
.waitAndClickElement(appId
, '.overwrite-original');
205 return gallery
.waitAndClickElement(appId
, '.rotate_right');
207 // Confirm that edited image has been saved.
208 return gallery
.waitForAFile(volumeType
,
209 'My Desktop Background - Edited.png');
211 // Confirm overwrite original checkbox is disabled and not checked.
212 return gallery
.waitForElement(appId
,
213 '.overwrite-original[disabled]:not([checked])');
215 // Go back to the slide mode.
216 return gallery
.waitAndClickElement(appId
, 'button.edit');
218 // Confirm current image is My Desktop Background - Edited.png.
219 return gallery
.waitForSlideImage(appId
, 600, 800,
220 'My Desktop Background - Edited');
222 // Move to My Desktop Background.png. Switching to other image is required
223 // to end edit session of the edited image.
224 return gallery
.waitAndClickElement(appId
, '.arrow.right');
226 // Confirm current image has changed to another image.
227 return gallery
.waitForSlideImage(appId
, 800, 600, 'My Desktop Background');
229 // Back to the edited image.
230 return gallery
.waitAndClickElement(appId
, '.arrow.left');
232 // Confirm current image is switched to My Desktop Background - Edited.png.
233 return gallery
.waitForSlideImage(appId
, 600, 800,
234 'My Desktop Background - Edited');
236 // Click edit button again.
237 return gallery
.waitAndClickElement(appId
, 'button.edit');
239 // Confirm overwrite original checkbox is enabled and not checked.
240 return gallery
.waitForElement(appId
,
241 '.overwrite-original:not([checked]):not([disabled])');
246 * The rotateImage test for Downloads.
247 * @return {Promise} Promise to be fulfilled with on success.
249 testcase
.rotateImageOnDownloads = function() {
250 return rotateImage('local', 'downloads');
254 * The rotateImage test for Google Drive.
255 * @return {Promise} Promise to be fulfilled with on success.
257 testcase
.rotateImageOnDrive = function() {
258 return rotateImage('drive', 'drive');
262 * The cropImage test for Downloads.
263 * @return {Promise} Promise to be fulfilled with on success.
265 testcase
.cropImageOnDownloads = function() {
266 return cropImage('local', 'downloads');
270 * The cropImage test for Google Drive.
271 * @return {Promise} Promise to be fulfilled with on success.
273 testcase
.cropImageOnDrive = function() {
274 return cropImage('drive', 'drive');
278 * The exposureImage test for Downloads.
279 * @return {Promise} Promise to be fulfilled with on success.
281 testcase
.exposureImageOnDownloads = function() {
282 return exposureImage('local', 'downloads');
286 * The exposureImage test for Google Drive.
287 * @return {Promise} Promise to be fulfilled with on success.
289 testcase
.exposureImageOnDrive = function() {
290 return exposureImage('drive', 'drive');
294 * The enableDisableOverwriteOriginalCheckbox test for Downloads.
295 * @return {Promise} Promise to be fulfilled with on success.
297 testcase
.enableDisableOverwriteOriginalCheckboxOnDownloads = function() {
298 return enableDisableOverwriteOriginalCheckbox('local', 'downloads');
302 * The enableDisableOverwriteOriginalCheckbox test for Drive.
303 * @return {Promise} Promise to be fulfilled with on success.
305 testcase
.enableDisableOverwriteOriginalCheckboxOnDrive = function() {
306 return enableDisableOverwriteOriginalCheckbox('drive', 'drive');