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

Side by Side Diff: chrome/test/data/extensions/api_test/file_browser/filehandler_create/test.js

Issue 10664002: Add support for drive files to chrome.fileBrowserHandler.selectFile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 5 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
« no previous file with comments | « chrome/common/extensions/api/file_browser_handler.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 var EXTENSION_ID = 'kidcpjlbjdmcnmccjhjdckhbngnhnepk'; 5 var EXTENSION_ID = 'kidcpjlbjdmcnmccjhjdckhbngnhnepk';
6 var FILE_CONTENTS = 'hello from test extension.'; 6 var FILE_CONTENTS = 'hello from test extension.';
7 7
8 function errorCallback(error) { 8 function errorCallback(error) {
9 var msg = ''; 9 var msg = '';
10 if (!error.code) { 10 if (!error.code) {
(...skipping 17 matching lines...) Expand all
28 break; 28 break;
29 default: 29 default:
30 msg = 'Unknown Error'; 30 msg = 'Unknown Error';
31 break; 31 break;
32 }; 32 };
33 } 33 }
34 console.log(msg); 34 console.log(msg);
35 chrome.test.fail(msg); 35 chrome.test.fail(msg);
36 } 36 }
37 37
38 function ensureFileExists(entry, successCallback, errorCallback) {
39 entry.filesystem.root.getFile(entry.fullPath,
40 {create: true},
41 successCallback,
42 errorCallback);
43 }
44
38 function writeToFile(entry) { 45 function writeToFile(entry) {
39 entry.createWriter(function(writer) { 46 entry.createWriter(function(writer) {
40 writer.onerror = function(e) { 47 writer.onerror = function(e) {
41 errorCallback(writer.error); 48 errorCallback(writer.error);
42 }; 49 };
43 writer.onwrite = chrome.test.succeed; 50 writer.onwrite = chrome.test.succeed;
44 51
45 var bb = new WebKitBlobBuilder(); 52 var bb = new WebKitBlobBuilder();
46 bb.append(FILE_CONTENTS); 53 bb.append(FILE_CONTENTS);
47 writer.write(bb.getBlob('text/plain')); 54 writer.write(bb.getBlob('text/plain'));
48 }, errorCallback); 55 }, errorCallback);
49 } 56 }
50 57
51 chrome.test.runTests([ 58 chrome.test.runTests([
52 function selectionSuccessful() { 59 function selectionSuccessful() {
53 // The test will call selectFile function and expect it to succeed. 60 // The test will call selectFile function and expect it to succeed.
54 // When it gets the file entry, it verifies that the permissions given in 61 // When it gets the file entry, it verifies that the permissions given in
55 // the method allow the extension to read/write to selected file. 62 // the method allow the extension to read/write to selected file.
56 chrome.fileBrowserHandler.selectFile({ suggestedName: 'some_file_name.txt'}, 63 chrome.fileBrowserHandler.selectFile({ suggestedName: 'some_file_name.txt'},
57 function(result) { 64 function(result) {
58 chrome.test.assertTrue(!!result); 65 chrome.test.assertTrue(!!result);
59 chrome.test.assertTrue(result.success); 66 chrome.test.assertTrue(result.success);
60 chrome.test.assertTrue(!!result.entry); 67 chrome.test.assertTrue(!!result.entry);
61 68
62 writeToFile(result.entry); 69 ensureFileExists(result.entry, writeToFile, errorCallback);
63 }); 70 });
64 }, 71 },
65 function selectionFails() { 72 function selectionFails() {
66 // The test expects that selectFile returns failure with an empty entry. 73 // The test expects that selectFile returns failure with an empty entry.
67 chrome.fileBrowserHandler.selectFile({ suggestedName: 'fail' }, 74 chrome.fileBrowserHandler.selectFile({ suggestedName: 'fail' },
68 function(result) { 75 function(result) {
69 chrome.test.assertTrue(!!result); 76 chrome.test.assertTrue(!!result);
70 // Entry should be set iff operation succeeded. 77 // Entry should be set iff operation succeeded.
71 chrome.test.assertEq(false, result.success); 78 chrome.test.assertEq(false, result.success);
72 chrome.test.assertTrue(result.entry == null); 79 chrome.test.assertTrue(result.entry == null);
73 chrome.test.succeed(); 80 chrome.test.succeed();
74 }); 81 });
75 }]); 82 }]);
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/file_browser_handler.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698