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

Unified Diff: chrome/test/data/extensions/api_test/media_galleries/common/common_injected.js

Issue 24420003: Media Galleries: Run API tests in a temp directory with an injected common.js file. Avoid the need … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make it more obvious there's a JS file being injected into the test cases (try 2) Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/media_galleries/common/common_injected.js
diff --git a/chrome/test/data/extensions/api_test/media_galleries/copy_to_access/no_access/copy_to_common.js b/chrome/test/data/extensions/api_test/media_galleries/common/common_injected.js
similarity index 51%
rename from chrome/test/data/extensions/api_test/media_galleries/copy_to_access/no_access/copy_to_common.js
rename to chrome/test/data/extensions/api_test/media_galleries/common/common_injected.js
index 8f0322786fd1906c84597f28925878d87ccc2262..4362b37e8e513abfe0073f8b03d1fce3d8e60572 100644
--- a/chrome/test/data/extensions/api_test/media_galleries/copy_to_access/no_access/copy_to_common.js
+++ b/chrome/test/data/extensions/api_test/media_galleries/common/common_injected.js
@@ -3,8 +3,6 @@
// found in the LICENSE file.
// Valid WEBP image.
-// TODO(thestig) Maybe copy these files to a media gallery in the C++ setup
-// phase to avoid having this and webkitRequestFileSystem() below.
var validWEBPImageCase = {
filename: "valid.webp",
blobString: "RIFF0\0\0\0WEBPVP8 $\0\0\0\xB2\x02\0\x9D\x01\x2A" +
@@ -80,6 +78,91 @@ function runCopyToTest(testCase, expectSucceed) {
}
}
+// The custom callback functions are options.
+// If they are undefined, the default callbacks and checks will be used.
+// If passed in, all 3 function arguments need to be valid.
+function runReadGalleriesTest(expectedGalleryCount, expectSucceed,
+ customReadDirectoryCallback,
+ customReadDirectoryErrorCallback,
+ customGotGalleriesCallback) {
+ var galleries;
+ var readEntriesResults = [];
+ var readDirectoryCallback;
+ var readDirectoryErrorCallback;
+ var gotGalleriesCallback;
+
+ if (customReadDirectoryCallback && customReadDirectoryErrorCallback &&
+ customGotGalleriesCallback) {
+ chrome.test.assertEq(typeof(customReadDirectoryCallback), 'function');
+ chrome.test.assertEq(typeof(customReadDirectoryErrorCallback), 'function');
+ chrome.test.assertEq(typeof(customGotGalleriesCallback), 'function');
+ readDirectoryCallback = customReadDirectoryCallback;
+ readDirectoryErrorCallback = customReadDirectoryErrorCallback;
+ gotGalleriesCallback = customGotGalleriesCallback;
+ } else {
+ chrome.test.assertTrue(!customReadDirectoryCallback &&
+ !customReadDirectoryErrorCallback &&
+ !customGotGalleriesCallback);
+ readDirectoryCallback = defaultReadDirectoryCallback;
+ readDirectoryErrorCallback = defaultReadDirectoryErrorCallback;
+ gotGalleriesCallback = defaultGotGalleriesCallback;
+ }
+ chrome.mediaGalleries.getMediaFileSystems(testGalleries);
+
+ function testGalleries(results) {
+ gotGalleriesCallback(results);
+ chrome.test.assertEq(expectedGalleryCount, results.length,
+ "Gallery count mismatch");
+ if (expectedGalleryCount == 0) {
+ chrome.test.succeed();
+ return;
+ }
+
+ for (var i = 0; i < results.length; i++) {
+ var dirReader = results[i].root.createReader();
+ dirReader.readEntries(readDirectoryCallback, readDirectoryErrorCallback);
+ }
+ }
+
+ function defaultGotGalleriesCallback(entries) {
+ galleries = entries;
+ }
+
+ function defaultReadDirectoryCallback(entries) {
+ var result = "";
+ if (!expectSucceed) {
+ result = "Unexpected readEntries success";
+ }
+ readEntriesResults.push(result);
+ checkReadEntriesFinished();
+ }
+
+ function defaultReadDirectoryErrorCallback(err) {
+ var result = "";
+ if (expectSucceed) {
+ result = "Unexpected readEntries failure: " + err;
+ }
+ readEntriesResults.push(result);
+ checkReadEntriesFinished();
+ }
+
+ function checkReadEntriesFinished() {
+ if (readEntriesResults.length != galleries.length)
+ return;
+ var success = true;
+ for (var i = 0; i < readEntriesResults.length; i++) {
+ if (readEntriesResults[i]) {
+ success = false;
+ }
+ }
+ if (success) {
+ chrome.test.succeed();
+ return;
+ }
+ chrome.test.fail(readEntriesResults);
+ }
+}
+
// Create a dummy window to prevent the ExtensionProcessManager from suspending
// the chrome-test app. Needed because the writer.onerror and writer.onwriteend
// events do not qualify as pending callbacks, so the app looks dormant.

Powered by Google App Engine
This is Rietveld 408576698