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

Side by Side 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, 2 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // Valid WEBP image. 5 // Valid WEBP image.
6 // TODO(thestig) Maybe copy these files to a media gallery in the C++ setup
7 // phase to avoid having this and webkitRequestFileSystem() below.
8 var validWEBPImageCase = { 6 var validWEBPImageCase = {
9 filename: "valid.webp", 7 filename: "valid.webp",
10 blobString: "RIFF0\0\0\0WEBPVP8 $\0\0\0\xB2\x02\0\x9D\x01\x2A" + 8 blobString: "RIFF0\0\0\0WEBPVP8 $\0\0\0\xB2\x02\0\x9D\x01\x2A" +
11 "\x01\0\x01\0\x2F\x9D\xCE\xE7s\xA8((((\x01\x9CK(\0" + 9 "\x01\0\x01\0\x2F\x9D\xCE\xE7s\xA8((((\x01\x9CK(\0" +
12 "\x05\xCE\xB3l\0\0\xFE\xD8\x80\0\0" 10 "\x05\xCE\xB3l\0\0\xFE\xD8\x80\0\0"
13 } 11 }
14 12
15 // Write an invalid test image and expect failure. 13 // Write an invalid test image and expect failure.
16 var invalidWEBPImageCase = { 14 var invalidWEBPImageCase = {
17 filename: "invalid.webp", 15 filename: "invalid.webp",
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } else { 71 } else {
74 onSuccess = chrome.test.fail; 72 onSuccess = chrome.test.fail;
75 onFailure = chrome.test.succeed; 73 onFailure = chrome.test.succeed;
76 } 74 }
77 return function() { 75 return function() {
78 testImageFileEntry.copyTo(gallery.root, filename, onSuccess, onFailure); 76 testImageFileEntry.copyTo(gallery.root, filename, onSuccess, onFailure);
79 }; 77 };
80 } 78 }
81 } 79 }
82 80
81 // The custom callback functions are options.
82 // If they are undefined, the default callbacks and checks will be used.
83 // If passed in, all 3 function arguments need to be valid.
84 function runReadGalleriesTest(expectedGalleryCount, expectSucceed,
85 customReadDirectoryCallback,
86 customReadDirectoryErrorCallback,
87 customGotGalleriesCallback) {
88 var galleries;
89 var readEntriesResults = [];
90 var readDirectoryCallback;
91 var readDirectoryErrorCallback;
92 var gotGalleriesCallback;
93
94 if (customReadDirectoryCallback && customReadDirectoryErrorCallback &&
95 customGotGalleriesCallback) {
96 chrome.test.assertEq(typeof(customReadDirectoryCallback), 'function');
97 chrome.test.assertEq(typeof(customReadDirectoryErrorCallback), 'function');
98 chrome.test.assertEq(typeof(customGotGalleriesCallback), 'function');
99 readDirectoryCallback = customReadDirectoryCallback;
100 readDirectoryErrorCallback = customReadDirectoryErrorCallback;
101 gotGalleriesCallback = customGotGalleriesCallback;
102 } else {
103 chrome.test.assertTrue(!customReadDirectoryCallback &&
104 !customReadDirectoryErrorCallback &&
105 !customGotGalleriesCallback);
106 readDirectoryCallback = defaultReadDirectoryCallback;
107 readDirectoryErrorCallback = defaultReadDirectoryErrorCallback;
108 gotGalleriesCallback = defaultGotGalleriesCallback;
109 }
110 chrome.mediaGalleries.getMediaFileSystems(testGalleries);
111
112 function testGalleries(results) {
113 gotGalleriesCallback(results);
114 chrome.test.assertEq(expectedGalleryCount, results.length,
115 "Gallery count mismatch");
116 if (expectedGalleryCount == 0) {
117 chrome.test.succeed();
118 return;
119 }
120
121 for (var i = 0; i < results.length; i++) {
122 var dirReader = results[i].root.createReader();
123 dirReader.readEntries(readDirectoryCallback, readDirectoryErrorCallback);
124 }
125 }
126
127 function defaultGotGalleriesCallback(entries) {
128 galleries = entries;
129 }
130
131 function defaultReadDirectoryCallback(entries) {
132 var result = "";
133 if (!expectSucceed) {
134 result = "Unexpected readEntries success";
135 }
136 readEntriesResults.push(result);
137 checkReadEntriesFinished();
138 }
139
140 function defaultReadDirectoryErrorCallback(err) {
141 var result = "";
142 if (expectSucceed) {
143 result = "Unexpected readEntries failure: " + err;
144 }
145 readEntriesResults.push(result);
146 checkReadEntriesFinished();
147 }
148
149 function checkReadEntriesFinished() {
150 if (readEntriesResults.length != galleries.length)
151 return;
152 var success = true;
153 for (var i = 0; i < readEntriesResults.length; i++) {
154 if (readEntriesResults[i]) {
155 success = false;
156 }
157 }
158 if (success) {
159 chrome.test.succeed();
160 return;
161 }
162 chrome.test.fail(readEntriesResults);
163 }
164 }
165
83 // Create a dummy window to prevent the ExtensionProcessManager from suspending 166 // Create a dummy window to prevent the ExtensionProcessManager from suspending
84 // the chrome-test app. Needed because the writer.onerror and writer.onwriteend 167 // the chrome-test app. Needed because the writer.onerror and writer.onwriteend
85 // events do not qualify as pending callbacks, so the app looks dormant. 168 // events do not qualify as pending callbacks, so the app looks dormant.
86 function CreateDummyWindowToPreventSleep() { 169 function CreateDummyWindowToPreventSleep() {
87 chrome.app.runtime.onLaunched.addListener(function() { 170 chrome.app.runtime.onLaunched.addListener(function() {
88 chrome.app.window.create('dummy.html', { 171 chrome.app.window.create('dummy.html', {
89 bounds: { 172 bounds: {
90 width: 800, 173 width: 800,
91 height: 600, 174 height: 600,
92 left: 100, 175 left: 100,
93 top: 100 176 top: 100
94 }, 177 },
95 minWidth: 800, 178 minWidth: 800,
96 minHeight: 600 179 minHeight: 600
97 }); 180 });
98 }); 181 });
99 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698