| 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 // Checks that filesystem_handler read the file correctly (original and received | 5 // Checks that filesystem_handler read the file correctly (original and received |
| 6 // text match) and changed its content in expected way (file should contain | 6 // text match) and changed its content in expected way (file should contain |
| 7 // originalText + originalText). | 7 // originalText + originalText). |
| 8 function verifyFileContent(file, originalText, receivedText, callback) { | 8 function verifyFileContent(file, originalText, request, callback) { |
| 9 if (receivedText != originalText) { | 9 if (request.fileContent != originalText) { |
| 10 callback({message:'Received content does not match. ' + | 10 callback({message:'Received content does not match. ' + |
| 11 'Expected: "' + originalText + '", ' + | 11 'Expected: "' + originalText + '", ' + |
| 12 'Got "' + receivedText + '".'}); | 12 'Got "' + request.fileContent + '".'}); |
| 13 return; | 13 return; |
| 14 } | 14 } |
| 15 | 15 |
| 16 readFile(file, | 16 readFile(file, |
| 17 function(text) { | 17 function(text) { |
| 18 var error = undefined; | 18 var error = undefined; |
| 19 var expectedText = originalText + originalText; | 19 var expectedText = originalText + originalText; |
| 20 if (text != expectedText) { | 20 if (text != expectedText) { |
| 21 error = {message: 'File content not as expected. ' + | 21 error = {message: 'File content not as expected. ' + |
| 22 'Expected: "' + expectedText + '", ' + | 22 'Expected: "' + expectedText + '", ' + |
| 23 'Read: ' + text + '".'}; | 23 'Read: ' + text + '".'}; |
| 24 } | 24 } |
| 25 callback(error); | 25 callback(error); |
| 26 }, | 26 }, |
| 27 callback); | 27 callback); |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 function getFileExtensionFromLocationHref() { |
| 31 var loc = window.location.href; |
| 32 console.log("Opening tab " + loc); |
| 33 if (loc.indexOf("#") == -1 ) { |
| 34 console.log("No params in url, faling back to default."); |
| 35 return undefined; |
| 36 } |
| 37 |
| 38 loc = unescape(loc.substr(loc.indexOf("#") + 1)); |
| 39 return loc; |
| 40 } |
| 41 |
| 42 function createTestExpectations(defaultFileExtension) { |
| 43 var fileExtension = getFileExtensionFromLocationHref(); |
| 44 if (!fileExtension) |
| 45 fileExtension = defaultFileExtension; |
| 46 |
| 47 var fileActionName = 'TestAction_' + fileExtension; |
| 48 var fileActionFilter = ['filesystem:*.' + fileExtension.toLowerCase()]; |
| 49 var expectedTasks = {}; |
| 50 expectedTasks[fileActionName] = fileActionFilter; |
| 51 fileExtension = '.' + fileExtension; |
| 52 |
| 53 return new TestExpectations(fileExtension, expectedTasks, verifyFileContent); |
| 54 } |
| 55 |
| 30 chrome.test.runTests([function tab() { | 56 chrome.test.runTests([function tab() { |
| 31 var expectedTasks = {'AbcAction': ['filesystem:*.abc'], | 57 var expectations = createTestExpectations('aBc'); |
| 32 'BaseAction': ['filesystem:*', 'filesystem:*.*']}; | |
| 33 var expectations = new TestExpectations(expectedTasks, verifyFileContent); | |
| 34 | 58 |
| 35 var testRunner = new TestRunner(expectations); | 59 var testRunner = new TestRunner(expectations); |
| 36 testRunner.runTest(); | 60 testRunner.runTest(); |
| 37 }]); | 61 }]); |
| OLD | NEW |