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

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: tiny 80 chars fix Created 8 years, 3 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 if (!this.file_ || !this.fileText_ || !this.fileVerifierFunction_) { 61 if (!this.file_ || !this.fileText_ || !this.fileVerifierFunction_) {
62 callback({message: "Test expectations not set properly."}); 62 callback({message: "Test expectations not set properly."});
63 return; 63 return;
64 } 64 }
65 65
66 this.fileVerifierFunction_(this.file_, this.fileText_, request, 66 this.fileVerifierFunction_(this.file_, this.fileText_, request,
67 callback); 67 callback);
68 }; 68 };
69 69
70 TestExpectations.prototype.hasVerifyStep = function() {
71 return !!this.fileVerifierFunction_;
72 };
73
74 // Verifies that list of tasks |tasks| contains tasks specified in
75 // expectedTasks_. |successCallback| expects to be passed |tasks|.
76 // |errorCallback| expects error object.
77 TestExpectations.prototype.verifyTasks = function(tasks,
78 successCallback,
79 errorCallback) {
80 if (tasks.length != Object.keys(this.expectedTasks_).length) {
81 errorCallback({message: 'Wrong number of tasks found.'});
82 return;
83 }
84
85 for (var i = 0; i < tasks.length; ++i) {
86 var taskName = /^.*[|]\d+[|](\S+)$/.exec(tasks[i].taskId)[1];
87 var patterns = tasks[i].patterns;
88 var expectedPatterns = this.expectedTasks_[taskName];
89 if (!expectedPatterns) {
90 errorCallback({message: 'Wrong task from getFileTasks(): ' + taskName});
tbarzic 2012/09/11 02:01:40 this function has been removed when "patterns" wer
thorogood 2012/09/13 02:34:49 Cool, that makes sense. Yeah - I wondered about "p
91 return;
92 }
93 patterns = patterns.sort();
94 expectedPatterns = expectedPatterns.sort();
95 for (var j = 0; j < patterns.length; ++j) {
96 var translatedPattern = expectedPatterns[j].replace(
97 /^filesystem:/, "chrome-extension://*/");
98 if (patterns[j] != translatedPattern) {
99 errorCallback({message: 'Wrong patterns set for task ' +
100 taskName + '. ' +
101 'Got: ' + patterns +
102 ' expected: ' + expectedPatterns});
103 return;
104 }
105 }
106 }
107 successCallback(tasks);
108 };
109
70 // Class that is in charge for running the test. 110 // Class that is in charge for running the test.
71 var TestRunner = function(expectations) { 111 var TestRunner = function(expectations) {
72 this.expectations_ = expectations; 112 this.expectations_ = expectations;
73 this.fileCreator_ = new TestFileCreator("tmp", true /* shouldRandomize */); 113 this.fileCreator_ = new TestFileCreator("tmp", true /* shouldRandomize */);
tbarzic 2012/09/13 04:29:16 Do if (expectations.fileVerifierFunction_) this.
thorogood 2012/09/13 08:14:04 Done, although I never make a request like this fr
74 this.listener_ = this.onHandlerRequest_.bind(this); 114 this.listener_ = this.onHandlerRequest_.bind(this);
75 }; 115 };
76 116
77 // Starts the test. 117 // Starts the test.
78 TestRunner.prototype.runTest = function() { 118 TestRunner.prototype.runTest = function() {
79 // Get local FS, create dir with a file in it. 119 // Get local FS, create dir with a file in it.
80 console.log('Requesting local file system...'); 120 console.log('Requesting local file system...');
tbarzic 2012/09/13 04:29:16 if (this.listener_)
thorogood 2012/09/13 08:14:04 Done.
81 chrome.extension.onRequestExternal.addListener(this.listener_); 121 chrome.extension.onRequestExternal.addListener(this.listener_);
82 chrome.fileBrowserPrivate.requestLocalFileSystem( 122 chrome.fileBrowserPrivate.requestLocalFileSystem(
83 this.onFileSystemFetched_.bind(this)); 123 this.onFileSystemFetched_.bind(this));
84 }; 124 };
85 125
86 TestRunner.prototype.onFileSystemFetched_ = function(fs) { 126 TestRunner.prototype.onFileSystemFetched_ = function(fs) {
87 if (!fs) { 127 if (!fs) {
88 this.errorCallback_(chrome.extensions.lastError); 128 this.errorCallback_(chrome.extensions.lastError);
89 return; 129 return;
90 } 130 }
91 131
92 this.fileCreator_.init(fs, this.onFileCreatorInit_.bind(this), 132 this.fileCreator_.init(fs, this.onFileCreatorInit_.bind(this),
93 this.errorCallback_.bind(this)); 133 this.errorCallback_.bind(this));
94 }; 134 };
95 135
96 TestRunner.prototype.onFileCreatorInit_ = function() { 136 TestRunner.prototype.onFileCreatorInit_ = function() {
97 var ext = this.expectations_.getFileExtension(); 137 var ext = this.expectations_.getFileExtension();
98 if (!ext) { 138 if (!ext) {
99 this.errorCallback_({message: "Test file extension not set."}); 139 this.errorCallback_({message: "Test file extension not set."});
100 return; 140 return;
101 } 141 }
102 console.log(this.fileExtension);
103 var self = this; 142 var self = this;
104 this.fileCreator_.createFile('.log', 143 this.fileCreator_.createFile('.log',
105 function(file, text) { 144 function(file, text) {
106 self.fileCreator_.createFile(ext, 145 self.fileCreator_.createFile(ext,
107 self.onFileCreated_.bind(self), 146 self.onFileCreated_.bind(self),
108 self.errorCallback_.bind(self)); 147 self.errorCallback_.bind(self));
109 }, 148 },
110 this.errorCallback_.bind(this)); 149 this.errorCallback_.bind(this));
111 }; 150 };
112 151
(...skipping 12 matching lines...) Expand all
125 console.log(tasks); 164 console.log(tasks);
126 if (!tasks || !tasks.length) { 165 if (!tasks || !tasks.length) {
127 this.errorCallback_({message: 'No tasks registered'}); 166 this.errorCallback_({message: 'No tasks registered'});
128 return; 167 return;
129 } 168 }
130 169
131 console.log('DONE fetching ' + tasks.length + ' tasks'); 170 console.log('DONE fetching ' + tasks.length + ' tasks');
132 171
133 tasks = this.filterTasks_(tasks); 172 tasks = this.filterTasks_(tasks);
134 chrome.fileBrowserPrivate.executeTask(tasks[0].taskId, [fileUrl]); 173 chrome.fileBrowserPrivate.executeTask(tasks[0].taskId, [fileUrl]);
174
175 if (!this.expectations_.hasVerifyStep()) {
tbarzic 2012/09/13 04:29:16 I think you still need something like this (TestRu
thorogood 2012/09/13 08:14:04 I'm not sure - my test intent handler does in fact
tbarzic 2012/09/13 18:44:45 yeah, but the problem is files created during the
176 console.log('Not verifying content, succeed immediately.');
177 this.reportSuccess_();
178 }
135 }; 179 };
136 180
137 TestRunner.prototype.filterTasks_ = function(tasks) { 181 TestRunner.prototype.filterTasks_ = function(tasks) {
138 var result = []; 182 var result = [];
139 for (var i = 0; i < tasks.length; i++) { 183 for (var i = 0; i < tasks.length; i++) {
140 if (tasks[i].taskId.split('|')[0] != kFileManagerExtensionId) { 184 if (tasks[i].taskId.split('|')[0] != kFileManagerExtensionId) {
141 result.push(tasks[i]); 185 result.push(tasks[i]);
142 } 186 }
143 } 187 }
144 return result; 188 return result;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 if (!error) { 242 if (!error) {
199 sendResponse({success: true}); 243 sendResponse({success: true});
200 this.fileCreator_.cleanupAndEndTest(this.reportSuccess_.bind(this), 244 this.fileCreator_.cleanupAndEndTest(this.reportSuccess_.bind(this),
201 this.reportFail_.bind(this, 245 this.reportFail_.bind(this,
202 cleanupError)); 246 cleanupError));
203 } else { 247 } else {
204 sendResponse({success: false}); 248 sendResponse({success: false});
205 this.errorCallback_(error); 249 this.errorCallback_(error);
206 } 250 }
207 }; 251 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698