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

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

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

Powered by Google App Engine
This is Rietveld 408576698