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

Side by Side Diff: chrome/test/data/extensions/api_test/local_filesystem/tab.js

Issue 8763008: Move yet another block of tests to manifest_version 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var fileSystem = null;
6 var testDirName = null;
7 var testFileName = null;
8 var watchfileUrl = null;
9
10 function errorCallback(e) {
11 var msg = '';
12 switch (e.code) {
13 case FileError.QUOTA_EXCEEDED_ERR:
14 msg = 'QUOTA_EXCEEDED_ERR';
15 break;
16 case FileError.NOT_FOUND_ERR:
17 msg = 'NOT_FOUND_ERR';
18 break;
19 case FileError.SECURITY_ERR:
20 msg = 'SECURITY_ERR';
21 break;
22 case FileError.INVALID_MODIFICATION_ERR:
23 msg = 'INVALID_MODIFICATION_ERR';
24 break;
25 case FileError.INVALID_STATE_ERR:
26 msg = 'INVALID_STATE_ERR';
27 break;
28 default:
29 msg = 'Unknown Error';
30 break;
31 };
32 chrome.test.fail("Got unexpected error: " + msg);
33 console.log('Error: ' + msg);
34 alert('Error: ' + msg);
35 }
36
37 function successCallbackFinal(entry) {
38 chrome.test.succeed();
39 }
40
41 function onGetFileEntry(entry) {
42 chrome.test.succeed();
43 }
44
45 function deleteDirectory() {
46 console.log("Deleting dir : " + testDirName);
47 fileSystem.root.getDirectory(testDirName, {create:false},
48 function(directory) {
49 // Do clean-up. (Assume the tab won't be reloaded in testing.)
50 directory.removeRecursively(successCallbackFinal, errorCallback);
51 }, errorCallback);
52 }
53
54
55 // Sets up directory watch, kicks of file removal from the directory.
56 function setupDirectoryWatch(dirEntry) {
57 watchfileUrl = dirEntry.toURL();
58 chrome.fileBrowserPrivate.addFileWatch(
59 watchfileUrl,
60 function(success) {
61 if (!success) {
62 chrome.test.fail("File watch setup failed.");
63 } else {
64 console.log("Added new file watch: " + watchfileUrl);
65 fileSystem.root.getFile(testDirName+'/'+testFileName, {create: false},
66 triggerFolderChange, errorCallback);
67 }
68 });
69 }
70
71 function triggerFolderChange(fileEntry) {
72 // Just delete test file, this should trigger onFolderChanged call below.
73 fileEntry.remove(function() {}, errorCallback);
74 }
75
76 function onFolderChanged(info) {
77 if (info && info.eventType == 'changed' &&
78 info.fileUrl == watchfileUrl) {
79 // Remove file watch.
80 console.log("Removing file watch: " + info.fileUrl);
81 chrome.fileBrowserPrivate.removeFileWatch(info.fileUrl,
82 function(success) {
83 if (success) {
84 chrome.test.succeed();
85 } else {
86 chrome.test.fail("Failed to remove file watch.");
87 }
88 });
89 } else {
90 var msg = "ERROR: Unexpected watch event info";
91 console.log(msg);
92 console.log(info);
93 chrome.test.fail(msg);
94 }
95 }
96
97 function onLocalFS(fs, error) {
98 if (!fs) {
99 errorCallback(error);
100 return;
101 }
102 fileSystem = fs;
103 console.log("DONE requesting filesystem: " + fileSystem.name);
104 // Read directory content.
105 console.log("Opening file : " + testDirName+'/'+testFileName);
106 fileSystem.root.getDirectory(testDirName, {create: false},
107 function(dirEntry) {
108 console.log('DONE opening directory: ' + dirEntry.fullPath);
109 fileSystem.root.getFile(testDirName+'/'+testFileName, {create:false},
110 onGetFileEntry, errorCallback);
111 }, errorCallback);
112 }
113
114 // Initialize tests - get test dir, file name.
115 function start() {
116 var loc = window.location.href;
117 console.log("Opening tab " + loc);
118 if (loc.indexOf("#") == -1 ) {
119 chrome.test.fail("Missing params");
120 return;
121 }
122 loc = unescape(loc.substr(loc.indexOf("#") + 1));
123 if (loc.lastIndexOf("/") == -1 ) {
124 chrome.test.fail("Bad params");
125 return;
126 }
127 testDirName = loc.substr(0, loc.lastIndexOf("/"));
128 testFileName = loc.substr(loc.lastIndexOf("/") + 1);
129
130 chrome.test.runTests([
131 function basic_operations() {
132 console.log("Requesting local file system...");
133 chrome.fileBrowserPrivate.requestLocalFileSystem(onLocalFS);
134 },
135
136 function file_watcher() {
137 chrome.fileBrowserPrivate.onFileChanged.addListener(onFolderChanged);
138 console.log("Setting up watch of : " + testDirName);
139 fileSystem.root.getDirectory(testDirName, {create: false},
140 setupDirectoryWatch, errorCallback);
141 },
142
143 function cleanup() {
144 deleteDirectory();
145 }
146 ]);
147 }
148
149 start();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698