Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 var kFileManagerExtensionId = 'hhaomjibdihmijegdhdafkllkbggdgoj'; | 16 var kFileManagerExtensionId = 'hhaomjibdihmijegdhdafkllkbggdgoj'; |
| 17 | 17 |
| 18 // Class specified by the client running the TestRunner. | 18 // Class specified by the client running the TestRunner. |
| 19 // |expectedTasks| should contain list of actions defined for abc files defined | 19 // |expectedTasks| should contain list of actions defined for abc files defined |
| 20 // by filesystem_handler part of the test. | 20 // by filesystem_handler part of the test. |
| 21 // |fileVerifierFunction| method that will verify test results received from the | 21 // |fileVerifierFunction| optional method that will verify test results received |
|
tbarzic
2012/09/19 15:45:13
you can revert changes in this file now
thorogood
2012/09/20 00:48:17
Done, thanks.
| |
| 22 // filesystem_handler part of the test. | 22 // from the filesystem_handler part of the test. |
| 23 // The method will be passed received fileEntry object, original file | 23 // The method will be passed received fileEntry object, original file |
| 24 // content, response received from filesystem_handler and callback | 24 // content, response received from filesystem_handler and callback |
| 25 // function that will expect error object as its argument (or undefined on | 25 // function that will expect error object as its argument (or undefined on |
| 26 // success). | 26 // success). |
| 27 // TODO(tbarzic): Rename this to TestParams, or something similar. | 27 // TODO(tbarzic): Rename this to TestParams, or something similar. |
| 28 var TestExpectations = function(fileExtension, expectedTasks, | 28 var TestExpectations = function(fileExtension, expectedTasks, |
| 29 fileVerifierFunction) { | 29 fileVerifierFunction) { |
| 30 this.fileText_ = undefined; | 30 this.fileText_ = undefined; |
| 31 this.file_ = undefined; | 31 this.file_ = undefined; |
| 32 | 32 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Class that is in charge for running the test. | 70 // Class that is in charge for running the test. |
| 71 var TestRunner = function(expectations) { | 71 var TestRunner = function(expectations) { |
| 72 this.expectations_ = expectations; | 72 this.expectations_ = expectations; |
| 73 this.fileCreator_ = new TestFileCreator("tmp", true /* shouldRandomize */); | 73 this.fileCreator_ = new TestFileCreator("tmp", true /* shouldRandomize */); |
| 74 this.listener_ = this.onHandlerRequest_.bind(this); | 74 if (expectations.fileVerifierFunction_) { |
| 75 this.listener_ = this.onHandlerRequest_.bind(this); | |
| 76 } | |
| 75 }; | 77 }; |
| 76 | 78 |
| 77 // Starts the test. | 79 // Starts the test. |
| 78 TestRunner.prototype.runTest = function() { | 80 TestRunner.prototype.runTest = function() { |
| 79 // Get local FS, create dir with a file in it. | 81 // Get local FS, create dir with a file in it. |
| 80 console.log('Requesting local file system...'); | 82 console.log('Requesting local file system...'); |
| 81 chrome.extension.onRequestExternal.addListener(this.listener_); | 83 if (this.listener_) { |
| 84 chrome.extension.onRequestExternal.addListener(this.listener_); | |
| 85 } | |
| 82 chrome.fileBrowserPrivate.requestLocalFileSystem( | 86 chrome.fileBrowserPrivate.requestLocalFileSystem( |
| 83 this.onFileSystemFetched_.bind(this)); | 87 this.onFileSystemFetched_.bind(this)); |
| 84 }; | 88 }; |
| 85 | 89 |
| 86 TestRunner.prototype.onFileSystemFetched_ = function(fs) { | 90 TestRunner.prototype.onFileSystemFetched_ = function(fs) { |
| 87 if (!fs) { | 91 if (!fs) { |
| 88 this.errorCallback_(chrome.extensions.lastError); | 92 this.errorCallback_(chrome.extensions.lastError); |
| 89 return; | 93 return; |
| 90 } | 94 } |
| 91 | 95 |
| 92 this.fileCreator_.init(fs, this.onFileCreatorInit_.bind(this), | 96 this.fileCreator_.init(fs, this.onFileCreatorInit_.bind(this), |
| 93 this.errorCallback_.bind(this)); | 97 this.errorCallback_.bind(this)); |
| 94 }; | 98 }; |
| 95 | 99 |
| 96 TestRunner.prototype.onFileCreatorInit_ = function() { | 100 TestRunner.prototype.onFileCreatorInit_ = function() { |
| 97 var ext = this.expectations_.getFileExtension(); | 101 var ext = this.expectations_.getFileExtension(); |
| 98 if (!ext) { | 102 if (!ext) { |
| 99 this.errorCallback_({message: "Test file extension not set."}); | 103 this.errorCallback_({message: "Test file extension not set."}); |
| 100 return; | 104 return; |
| 101 } | 105 } |
| 102 console.log(this.fileExtension); | |
| 103 var self = this; | 106 var self = this; |
| 104 this.fileCreator_.createFile('.log', | 107 this.fileCreator_.createFile('.log', |
| 105 function(file, text) { | 108 function(file, text) { |
| 106 self.fileCreator_.createFile(ext, | 109 self.fileCreator_.createFile(ext, |
| 107 self.onFileCreated_.bind(self), | 110 self.onFileCreated_.bind(self), |
| 108 self.errorCallback_.bind(self)); | 111 self.errorCallback_.bind(self)); |
| 109 }, | 112 }, |
| 110 this.errorCallback_.bind(this)); | 113 this.errorCallback_.bind(this)); |
| 111 }; | 114 }; |
| 112 | 115 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 123 TestRunner.prototype.onGetTasks_ = function(fileUrl, tasks) { | 126 TestRunner.prototype.onGetTasks_ = function(fileUrl, tasks) { |
| 124 console.log('Tasks: '); | 127 console.log('Tasks: '); |
| 125 console.log(tasks); | 128 console.log(tasks); |
| 126 if (!tasks || !tasks.length) { | 129 if (!tasks || !tasks.length) { |
| 127 this.errorCallback_({message: 'No tasks registered'}); | 130 this.errorCallback_({message: 'No tasks registered'}); |
| 128 return; | 131 return; |
| 129 } | 132 } |
| 130 | 133 |
| 131 console.log('DONE fetching ' + tasks.length + ' tasks'); | 134 console.log('DONE fetching ' + tasks.length + ' tasks'); |
| 132 | 135 |
| 133 tasks = this.filterTasks_(tasks); | 136 console.log('FILEURL: ' + fileUrl); |
| 137 console.log('TASKID: ' + tasks[0].taskId); | |
| 138 | |
| 134 chrome.fileBrowserPrivate.executeTask(tasks[0].taskId, [fileUrl]); | 139 chrome.fileBrowserPrivate.executeTask(tasks[0].taskId, [fileUrl]); |
| 135 }; | 140 }; |
| 136 | 141 |
| 137 TestRunner.prototype.filterTasks_ = function(tasks) { | 142 TestRunner.prototype.filterTasks_ = function(tasks) { |
| 138 var result = []; | 143 var result = []; |
| 139 for (var i = 0; i < tasks.length; i++) { | 144 for (var i = 0; i < tasks.length; i++) { |
| 140 if (tasks[i].taskId.split('|')[0] != kFileManagerExtensionId) { | 145 if (tasks[i].taskId.split('|')[0] != kFileManagerExtensionId) { |
| 141 result.push(tasks[i]); | 146 result.push(tasks[i]); |
| 142 } | 147 } |
| 143 } | 148 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 if (!error) { | 203 if (!error) { |
| 199 sendResponse({success: true}); | 204 sendResponse({success: true}); |
| 200 this.fileCreator_.cleanupAndEndTest(this.reportSuccess_.bind(this), | 205 this.fileCreator_.cleanupAndEndTest(this.reportSuccess_.bind(this), |
| 201 this.reportFail_.bind(this, | 206 this.reportFail_.bind(this, |
| 202 cleanupError)); | 207 cleanupError)); |
| 203 } else { | 208 } else { |
| 204 sendResponse({success: false}); | 209 sendResponse({success: false}); |
| 205 this.errorCallback_(error); | 210 this.errorCallback_(error); |
| 206 } | 211 } |
| 207 }; | 212 }; |
| OLD | NEW |