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

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

Issue 9741002: Adding file access permissions to fileBrowserHandler manifest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unit_tests Created 8 years, 8 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
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.
11 3. Listens for a message from context menu handler and makes sure its payload 11 3. Listens for a message from context menu handler and makes sure its payload
12 matches the random text from the test file. 12 matches the random text from the test file.
13 */ 13 */
14 14
15 var cleanupError = 'Got unexpected error while cleaning up test directory.'; 15 var cleanupError = 'Got unexpected error while cleaning up test directory.';
16 16
17 // Class specified by the client runnig the TestRunner. 17 // Class specified by the client runnig the TestRunner.
18 // |expectedTasks| should contain list of actions defined for abc files defined 18 // |expectedTasks| should contain list of actions defined for abc files defined
19 // by filesystem_handler part of the test. 19 // by filesystem_handler part of the test.
20 // |fileVerifierFunction| method that will verify test results received from the 20 // |fileVerifierFunction| method that will verify test results received from the
21 // filesystem_handler part of the test. 21 // filesystem_handler part of the test.
22 // The method will be passed received fileEntry object, original file 22 // The method will be passed received fileEntry object, original file
23 // content, file content received from filesystem_handler and callback 23 // content, response received from filesystem_handler and callback
24 // function that will expect error object as its argument (or undefined on 24 // function that will expect error object as its argument (or undefined on
25 // success). 25 // success).
26 var TestExpectations = function(expectedTasks, fileVerifierFunction) { 26 // TODO(tbarzic): Rename this to TestParams, or something similar.
27 var TestExpectations = function(fileExtension, expectedTasks,
28 fileVerifierFunction) {
27 this.fileText_ = undefined; 29 this.fileText_ = undefined;
28 this.file_ = undefined; 30 this.file_ = undefined;
29 this.expectedTasks_ = expectedTasks; 31 this.expectedTasks_ = expectedTasks;
32 this.fileExtension_ = fileExtension;
30 this.fileVerifierFunction_ = fileVerifierFunction; 33 this.fileVerifierFunction_ = fileVerifierFunction;
31 }; 34 };
32 35
33 // This has to be called before verifyHandlerRequest. 36 // This has to be called before verifyHandlerRequest.
34 TestExpectations.prototype.setFileAndFileText = function(file, fileText) { 37 TestExpectations.prototype.setFileAndFileText = function(file, fileText) {
35 this.file_ = file; 38 this.file_ = file;
36 this.fileText_ = fileText; 39 this.fileText_ = fileText;
37 }; 40 };
38 41
42 TestExpectations.prototype.getFileExtension = function() {
43 return this.fileExtension_;
44 };
45
39 TestExpectations.prototype.verifyHandlerRequest = function(request, callback) { 46 TestExpectations.prototype.verifyHandlerRequest = function(request, callback) {
40 if (!request) { 47 if (!request) {
41 callback({message: "Request from handler not defined."}); 48 callback({message: "Request from handler not defined."});
42 return; 49 return;
43 } 50 }
44 51
45 if (!request.fileContent) { 52 if (!request.fileContent) {
46 var error = request.error || {message: "Undefined error."}; 53 var error = request.error || {message: "Undefined error."};
47 callback(error); 54 callback(error);
48 return; 55 return;
49 } 56 }
50 57
51 if (!this.file_ || !this.fileText_ || !this.fileVerifierFunction_) { 58 if (!this.file_ || !this.fileText_ || !this.fileVerifierFunction_) {
52 callback({message: "Test expectations not set properly."}); 59 callback({message: "Test expectations not set properly."});
53 return; 60 return;
54 } 61 }
55 62
56 this.fileVerifierFunction_(this.file_, this.fileText_, request.fileContent, 63 this.fileVerifierFunction_(this.file_, this.fileText_, request,
57 callback); 64 callback);
58 }; 65 };
59 66
60 // Verifies that list of tasks |tasks| contains tasks specified in 67 // Verifies that list of tasks |tasks| contains tasks specified in
61 // expectedTasks_. |successCallback| expects to be passed |tasks|. 68 // expectedTasks_. |successCallback| expects to be passed |tasks|.
62 // |errorCallback| expects error object. 69 // |errorCallback| expects error object.
63 TestExpectations.prototype.verifyTasks = function(tasks, 70 TestExpectations.prototype.verifyTasks = function(tasks,
64 successCallback, 71 successCallback,
65 errorCallback) { 72 errorCallback) {
66 if (tasks.length != Object.keys(this.expectedTasks_).length) { 73 if (tasks.length != Object.keys(this.expectedTasks_).length) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (!fs) { 118 if (!fs) {
112 this.errorCallback_(chrome.extensions.lastError); 119 this.errorCallback_(chrome.extensions.lastError);
113 return; 120 return;
114 } 121 }
115 122
116 this.fileCreator_.init(fs, this.onFileCreatorInit_.bind(this), 123 this.fileCreator_.init(fs, this.onFileCreatorInit_.bind(this),
117 this.errorCallback_.bind(this)); 124 this.errorCallback_.bind(this));
118 }; 125 };
119 126
120 TestRunner.prototype.onFileCreatorInit_ = function() { 127 TestRunner.prototype.onFileCreatorInit_ = function() {
128 var ext = this.expectations_.getFileExtension();
129 if (!ext) {
130 this.errorCallback_({message: "Test file extension not set."});
131 return;
132 }
133 console.log(this.fileExtension);
121 var self = this; 134 var self = this;
122 this.fileCreator_.createFile('.log', 135 this.fileCreator_.createFile('.log',
123 function(file, text) { 136 function(file, text) {
124 self.fileCreator_.createFile('.aBc', 137 self.fileCreator_.createFile(ext,
125 self.onFileCreated_.bind(self), 138 self.onFileCreated_.bind(self),
126 self.errorCallback_.bind(self)); 139 self.errorCallback_.bind(self));
127 }, 140 },
128 this.errorCallback_.bind(this)); 141 this.errorCallback_.bind(this));
129 }; 142 };
130 143
131 TestRunner.prototype.onFileCreated_ = function(file, text) { 144 TestRunner.prototype.onFileCreated_ = function(file, text) {
132 // Start 145 // Start
133 console.log('Get registered tasks now...'); 146 console.log('Get registered tasks now...');
134 this.expectations_.setFileAndFileText(file, text); 147 this.expectations_.setFileAndFileText(file, text);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (!error) { 224 if (!error) {
212 sendResponse({success: true}); 225 sendResponse({success: true});
213 this.fileCreator_.cleanupAndEndTest(this.reportSuccess_.bind(this), 226 this.fileCreator_.cleanupAndEndTest(this.reportSuccess_.bind(this),
214 this.reportFail_.bind(this, 227 this.reportFail_.bind(this,
215 cleanupError)); 228 cleanupError));
216 } else { 229 } else {
217 sendResponse({success: false}); 230 sendResponse({success: false});
218 this.errorCallback_(error); 231 this.errorCallback_(error);
219 } 232 }
220 }; 233 };
OLDNEW
« no previous file with comments | « chrome/common/extensions/file_browser_handler.cc ('k') | chrome/test/data/extensions/api_test/filebrowser_component/read.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698