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

Side by Side Diff: chrome/test/data/extensions/api_test/filebrowser_component/main.js

Issue 10834383: Chrome OS "open with" picker allowing Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: sync to head, comment Created 8 years, 4 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
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 This component extension test does the following: 6 This component extension test does the following:
7 7
8 1. Creates an abc and log file on the local file system with some random text. 8 1. Creates an abc and log file on the local file system with some random text.
9 2. Finds a registered task (file item context menu) for abc file and invokes it 9 2. Finds a registered task (file item context menu) for abc file and invokes it
10 with url of the test file. 10 with url of the test file.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 if (!this.file_ || !this.fileText_ || !this.fileVerifierFunction_) { 58 if (!this.file_ || !this.fileText_ || !this.fileVerifierFunction_) {
59 callback({message: "Test expectations not set properly."}); 59 callback({message: "Test expectations not set properly."});
60 return; 60 return;
61 } 61 }
62 62
63 this.fileVerifierFunction_(this.file_, this.fileText_, request, 63 this.fileVerifierFunction_(this.file_, this.fileText_, request,
64 callback); 64 callback);
65 }; 65 };
66 66
67 TestExpectations.prototype.hasVerifyStep = function() {
68 return !!this.fileVerifierFunction_;
69 };
70
67 // Verifies that list of tasks |tasks| contains tasks specified in 71 // Verifies that list of tasks |tasks| contains tasks specified in
68 // expectedTasks_. |successCallback| expects to be passed |tasks|. 72 // expectedTasks_. |successCallback| expects to be passed |tasks|.
69 // |errorCallback| expects error object. 73 // |errorCallback| expects error object.
70 TestExpectations.prototype.verifyTasks = function(tasks, 74 TestExpectations.prototype.verifyTasks = function(tasks,
71 successCallback, 75 successCallback,
72 errorCallback) { 76 errorCallback) {
73 if (tasks.length != Object.keys(this.expectedTasks_).length) { 77 if (tasks.length != Object.keys(this.expectedTasks_).length) {
74 errorCallback({message: 'Wrong number of tasks found.'}); 78 errorCallback({message: 'Wrong number of tasks found.'});
75 return; 79 return;
76 } 80 }
77 81
78 for (var i = 0; i < tasks.length; ++i) { 82 for (var i = 0; i < tasks.length; ++i) {
79 var taskName = /^.*[|](\w+)$/.exec(tasks[i].taskId)[1]; 83 var taskName = /^.*[|](\S+)$/.exec(tasks[i].taskId)[1];
80 var patterns = tasks[i].patterns; 84 var patterns = tasks[i].patterns;
81 var expectedPatterns = this.expectedTasks_[taskName]; 85 var expectedPatterns = this.expectedTasks_[taskName];
82 if (!expectedPatterns) { 86 if (!expectedPatterns) {
83 errorCallback({message: 'Wrong task from getFileTasks(): ' + task_name}); 87 errorCallback({message: 'Wrong task from getFileTasks(): ' + taskName});
84 return; 88 return;
85 } 89 }
86 patterns = patterns.sort(); 90 patterns = patterns.sort();
87 expectedPatterns = expectedPatterns.sort(); 91 expectedPatterns = expectedPatterns.sort();
88 for (var j = 0; j < patterns.length; ++j) { 92 for (var j = 0; j < patterns.length; ++j) {
89 var translatedPattern = expectedPatterns[j].replace( 93 var translatedPattern = expectedPatterns[j].replace(
90 /^filesystem:/, "chrome-extension://*/"); 94 /^filesystem:/, "chrome-extension://*/");
91 if (patterns[j] != translatedPattern) { 95 if (patterns[j] != translatedPattern) {
92 errorCallback({message: 'Wrong patterns set for task ' + 96 errorCallback({message: 'Wrong patterns set for task ' +
93 taskName + '. ' + 97 taskName + '. ' +
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 this.fileCreator_.init(fs, this.onFileCreatorInit_.bind(this), 129 this.fileCreator_.init(fs, this.onFileCreatorInit_.bind(this),
126 this.errorCallback_.bind(this)); 130 this.errorCallback_.bind(this));
127 }; 131 };
128 132
129 TestRunner.prototype.onFileCreatorInit_ = function() { 133 TestRunner.prototype.onFileCreatorInit_ = function() {
130 var ext = this.expectations_.getFileExtension(); 134 var ext = this.expectations_.getFileExtension();
131 if (!ext) { 135 if (!ext) {
132 this.errorCallback_({message: "Test file extension not set."}); 136 this.errorCallback_({message: "Test file extension not set."});
133 return; 137 return;
134 } 138 }
135 console.log(this.fileExtension);
136 var self = this; 139 var self = this;
137 this.fileCreator_.createFile('.log', 140 this.fileCreator_.createFile('.log',
138 function(file, text) { 141 function(file, text) {
139 self.fileCreator_.createFile(ext, 142 self.fileCreator_.createFile(ext,
140 self.onFileCreated_.bind(self), 143 self.onFileCreated_.bind(self),
141 self.errorCallback_.bind(self)); 144 self.errorCallback_.bind(self));
142 }, 145 },
143 this.errorCallback_.bind(this)); 146 this.errorCallback_.bind(this));
144 }; 147 };
145 148
(...skipping 17 matching lines...) Expand all
163 166
164 console.log('DONE fetching ' + tasks.length + ' tasks'); 167 console.log('DONE fetching ' + tasks.length + ' tasks');
165 168
166 this.expectations_.verifyTasks(tasks, 169 this.expectations_.verifyTasks(tasks,
167 this.onTasksVerified_.bind(this, fileUrl), 170 this.onTasksVerified_.bind(this, fileUrl),
168 this.errorCallback_.bind(this)); 171 this.errorCallback_.bind(this));
169 } 172 }
170 173
171 TestRunner.prototype.onTasksVerified_ = function(fileUrl, tasks) { 174 TestRunner.prototype.onTasksVerified_ = function(fileUrl, tasks) {
172 chrome.fileBrowserPrivate.executeTask(tasks[0].taskId, [fileUrl]); 175 chrome.fileBrowserPrivate.executeTask(tasks[0].taskId, [fileUrl]);
176
177 if (!this.expectations_.hasVerifyStep()) {
178 console.log('Not verifying content, succeed immediately.');
179 this.reportSuccess_();
180 }
173 }; 181 };
174 182
175 TestRunner.prototype.errorCallback_ = function(error) { 183 TestRunner.prototype.errorCallback_ = function(error) {
176 var msg = ''; 184 var msg = '';
177 if (!error.code) { 185 if (!error.code) {
178 msg = error.message; 186 msg = error.message;
179 } else { 187 } else {
180 switch (error.code) { 188 switch (error.code) {
181 case FileError.QUOTA_EXCEEDED_ERR: 189 case FileError.QUOTA_EXCEEDED_ERR:
182 msg = 'QUOTA_EXCEEDED_ERR'; 190 msg = 'QUOTA_EXCEEDED_ERR';
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (!error) { 234 if (!error) {
227 sendResponse({success: true}); 235 sendResponse({success: true});
228 this.fileCreator_.cleanupAndEndTest(this.reportSuccess_.bind(this), 236 this.fileCreator_.cleanupAndEndTest(this.reportSuccess_.bind(this),
229 this.reportFail_.bind(this, 237 this.reportFail_.bind(this,
230 cleanupError)); 238 cleanupError));
231 } else { 239 } else {
232 sendResponse({success: false}); 240 sendResponse({success: false});
233 this.errorCallback_(error); 241 this.errorCallback_(error);
234 } 242 }
235 }; 243 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698