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

Side by Side Diff: chrome/browser/resources/file_manager/js/photo/gallery_testapi.js

Issue 12261004: [Cleanup] Files.app: Remove 'this' from class methods. #2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/file_manager/js/media/player_testapi.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Test API for Chrome OS Image Editor. 6 * Test API for Chrome OS Image Editor.
7 * 7 *
8 * There are two ways to load Image Editor before testing: 8 * There are two ways to load Image Editor before testing:
9 * - open File Manager, and then click on an image file to open Image Editor; 9 * - open File Manager, and then click on an image file to open Image Editor;
10 * or 10 * or
11 * - open tab with URL: 11 * - open tab with URL:
12 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/gallery.html 12 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/gallery.html
13 * and then call |galleryTestAPI.load('/Downloads/path/to/file.jpg')|. 13 * and then call |galleryTestAPI.load('/Downloads/path/to/file.jpg')|.
14 * 14 *
15 * After Image Editor is loaded, you can call methods from |galleryTestAPI| to 15 * After Image Editor is loaded, you can call methods from |galleryTestAPI| to
16 * emulate user actions and get feedback. 16 * emulate user actions and get feedback.
17 */ 17 */
18 var galleryTestAPI = { 18 var galleryTestAPI = {
19 /** 19 /**
20 * Open the Photo Editor. 20 * Open the Photo Editor.
21 * @param {string} path Path to the directory or an image file. 21 * @param {string} path Path to the directory or an image file.
22 */ 22 */
23 load: function(path) { 23 load: function(path) {
24 Gallery.openStandalone(path, null, function() { 24 Gallery.openStandalone(path, null, function() {
25 this.waitFor_('loaded'); 25 galleryTestAPI.waitFor_('loaded');
26 }.bind(this)); 26 });
27 }, 27 },
28 28
29 /** 29 /**
30 * Responds with the selected file name. 30 * Responds with the selected file name.
31 */ 31 */
32 getSelectedFileName: function() { 32 getSelectedFileName: function() {
33 this.respond_(document.querySelector('.namebox').value); 33 galleryTestAPI.respond_(document.querySelector('.namebox').value);
34 }, 34 },
35 35
36 /** 36 /**
37 * Toggles edit mode. 37 * Toggles edit mode.
38 */ 38 */
39 clickEditToggle: function() { 39 clickEditToggle: function() {
40 this.click('.edit'); 40 galleryTestAPI.click('.edit');
41 setTimeout(this.respond_.bind(this, true), 0); 41 setTimeout(galleryTestAPI.respond_.bind(null, true), 0);
42 }, 42 },
43 43
44 /** 44 /**
45 * Clicks arrow to select next image. 45 * Clicks arrow to select next image.
46 */ 46 */
47 clickNextImageArrow: function() { 47 clickNextImageArrow: function() {
48 this.click('.arrow.right'); 48 galleryTestAPI.click('.arrow.right');
49 this.waitFor_('image-displayed'); 49 galleryTestAPI.waitFor_('image-displayed');
50 }, 50 },
51 51
52 /** 52 /**
53 * Clicks arrow to select previous image. 53 * Clicks arrow to select previous image.
54 */ 54 */
55 clickPreviousImageArrow: function() { 55 clickPreviousImageArrow: function() {
56 this.click('.arrow.left'); 56 galleryTestAPI.click('.arrow.left');
57 this.waitFor_('image-displayed'); 57 galleryTestAPI.waitFor_('image-displayed');
58 }, 58 },
59 59
60 /** 60 /**
61 * Clicks last thumbnail in ribbon to select an image. 61 * Clicks last thumbnail in ribbon to select an image.
62 */ 62 */
63 clickLastRibbonThumbnail: function() { 63 clickLastRibbonThumbnail: function() {
64 this.clickRibbonThumbnail(true); 64 galleryTestAPI.clickRibbonThumbnail(true);
65 }, 65 },
66 66
67 /** 67 /**
68 * Clicks first thumbnail in ribbon to select an image. 68 * Clicks first thumbnail in ribbon to select an image.
69 */ 69 */
70 clickFirstRibbonThumbnail: function() { 70 clickFirstRibbonThumbnail: function() {
71 this.clickRibbonThumbnail(false); 71 galleryTestAPI.clickRibbonThumbnail(false);
72 }, 72 },
73 73
74 /** 74 /**
75 * Clicks thumbnail in ribbon. 75 * Clicks thumbnail in ribbon.
76 * @param {boolean} last Whether to click on last vs first. 76 * @param {boolean} last Whether to click on last vs first.
77 */ 77 */
78 clickRibbonThumbnail: function(last) { 78 clickRibbonThumbnail: function(last) {
79 // TODO(dgozman): investigate why this timeout is required sometimes. 79 // TODO(dgozman): investigate why this timeout is required sometimes.
80 setTimeout(function() { 80 setTimeout(function() {
81 var nodes = document.querySelectorAll('.ribbon > :not([vanishing])'); 81 var nodes = document.querySelectorAll('.ribbon > :not([vanishing])');
82 if (nodes.length == 0) { 82 if (nodes.length == 0) {
83 this.respond_(false); 83 galleryTestAPI.respond_(false);
84 return; 84 return;
85 } 85 }
86 nodes[last ? nodes.length - 1 : 0].click(); 86 nodes[last ? nodes.length - 1 : 0].click();
87 this.waitFor_('image-displayed'); 87 galleryTestAPI.waitFor_('image-displayed');
88 }.bind(this), 0); 88 }, 0);
89 }, 89 },
90 90
91 /** 91 /**
92 * Clicks 'rotate left' tool. 92 * Clicks 'rotate left' tool.
93 */ 93 */
94 clickRotateLeft: function() { 94 clickRotateLeft: function() {
95 this.editAndRespond_(this.click.bind(this, '.rotate_left')); 95 galleryTestAPI.editAndRespond_(
96 galleryTestAPI.click.bind(null, '.rotate_left'));
96 }, 97 },
97 98
98 /** 99 /**
99 * Clicks 'rotate right' tool. 100 * Clicks 'rotate right' tool.
100 */ 101 */
101 clickRotateRight: function() { 102 clickRotateRight: function() {
102 this.editAndRespond_(this.click.bind(this, '.rotate_right')); 103 galleryTestAPI.editAndRespond_(
104 galleryTestAPI.click.bind(null, '.rotate_right'));
103 }, 105 },
104 106
105 /** 107 /**
106 * Clicks 'undo' tool. 108 * Clicks 'undo' tool.
107 */ 109 */
108 clickUndo: function() { 110 clickUndo: function() {
109 this.editAndRespond_(this.click.bind(this, '.undo')); 111 galleryTestAPI.editAndRespond_(galleryTestAPI.click.bind(null, '.undo'));
110 }, 112 },
111 113
112 /** 114 /**
113 * Clicks 'redo' tool. 115 * Clicks 'redo' tool.
114 */ 116 */
115 clickRedo: function() { 117 clickRedo: function() {
116 this.editAndRespond_(this.click.bind(this, '.redo')); 118 galleryTestAPI.editAndRespond_(galleryTestAPI.click.bind(null, '.redo'));
117 }, 119 },
118 120
119 /** 121 /**
120 * Clicks 'autofix' tool. 122 * Clicks 'autofix' tool.
121 */ 123 */
122 clickAutofix: function() { 124 clickAutofix: function() {
123 this.editAndRespond_(this.click.bind(this, '.autofix')); 125 galleryTestAPI.editAndRespond_(galleryTestAPI.click.bind(null, '.autofix'));
124 }, 126 },
125 127
126 /** 128 /**
127 * Responds whether autofix tool is available. 129 * Responds whether autofix tool is available.
128 */ 130 */
129 isAutofixAvailable: function() { 131 isAutofixAvailable: function() {
130 this.respond_(!document.querySelector('.autofix').hasAttribute('disabled')); 132 galleryTestAPI.respond_(
133 !document.querySelector('.autofix').hasAttribute('disabled'));
131 }, 134 },
132 135
133 /** 136 /**
134 * Performs a click on the element with specififc selector. 137 * Performs a click on the element with specififc selector.
135 * @param {string} selector CSS selector. 138 * @param {string} selector CSS selector.
136 */ 139 */
137 click: function(selector) { 140 click: function(selector) {
138 document.querySelector(selector).click(); 141 document.querySelector(selector).click();
139 }, 142 },
140 143
141 /** 144 /**
142 * Waits until editor is ready, performs action and then responds. 145 * Waits until editor is ready, performs action and then responds.
143 * @param {function} action The action to perform. 146 * @param {function} action The action to perform.
144 * @private 147 * @private
145 */ 148 */
146 editAndRespond_: function(action) { 149 editAndRespond_: function(action) {
147 // TODO(dgozman): investigate why this is required sometimes. 150 // TODO(dgozman): investigate why this is required sometimes.
148 setTimeout(function() { 151 setTimeout(function() {
149 action(); 152 action();
150 this.waitFor_('image-saved'); 153 galleryTestAPI.waitFor_('image-saved');
151 }.bind(this), 0); 154 }, 0);
152 }, 155 },
153 156
154 /** 157 /**
155 * Waits for event fired and then calls a function. 158 * Waits for event fired and then calls a function.
156 * @param {string} event Event name. 159 * @param {string} event Event name.
157 * @param {function=} opt_callback Callback. If not passed, 160 * @param {function=} opt_callback Callback. If not passed,
158 * |this.respond_(true)| is called. 161 * |galleryTestAPI.respond_(true)| is called.
159 * @private 162 * @private
160 */ 163 */
161 waitFor_: function(event, opt_callback) { 164 waitFor_: function(event, opt_callback) {
162 var callback = opt_callback || this.respond_.bind(this, true); 165 var callback = opt_callback || galleryTestAPI.respond_.bind(null, true);
163 var listener = function() { 166 var listener = function() {
164 Gallery.instance.removeEventListener(event, listener); 167 Gallery.instance.removeEventListener(event, listener);
165 callback(); 168 callback();
166 }; 169 };
167 Gallery.instance.addEventListener(event, listener); 170 Gallery.instance.addEventListener(event, listener);
168 }, 171 },
169 172
170 /** 173 /**
171 * @param {string|boolean|number} value Value to send back. 174 * @param {string|boolean|number} value Value to send back.
172 * @private 175 * @private
173 */ 176 */
174 respond_: function(value) { 177 respond_: function(value) {
175 if (window.domAutomationController) { 178 if (window.domAutomationController) {
176 window.domAutomationController.send(value); 179 window.domAutomationController.send(value);
177 } else if (this.respondCallback) { 180 } else if (galleryTestAPI.respondCallback) {
178 this.respondCallback(value); 181 galleryTestAPI.respondCallback(value);
179 } else { 182 } else {
180 console.log('playerTestAPI response: ' + value); 183 console.log('playerTestAPI response: ' + value);
181 } 184 }
182 } 185 }
183 }; 186 };
184 187
185 /** 188 /**
186 * Test example. 189 * Test example.
187 */ 190 */
188 galleryTestAPI.testExample = function() { 191 galleryTestAPI.testExample = function() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 235
233 function nextStep() { 236 function nextStep() {
234 ++step; 237 ++step;
235 console.log('nextStep calls: ' + steps[step - 1].name); 238 console.log('nextStep calls: ' + steps[step - 1].name);
236 steps[step - 1].apply(null, arguments); 239 steps[step - 1].apply(null, arguments);
237 } 240 }
238 241
239 api.respondCallback = nextStep; 242 api.respondCallback = nextStep;
240 nextStep(); 243 nextStep();
241 }; 244 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/media/player_testapi.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698