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

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

Issue 11348215: Make wallpaper picker manifest and thumbnails available when offline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove success paramter and add a todo Created 8 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 // 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 // wallpaperPrivate api test 5 // wallpaperPrivate api test
6 // browser_tests --gtest_filter=ExtensionApiTest.wallpaperPrivate 6 // browser_tests --gtest_filter=ExtensionApiTest.wallpaperPrivate
7 7
8 var pass = chrome.test.callbackPass; 8 var pass = chrome.test.callbackPass;
9 var fail = chrome.test.callbackFail; 9 var fail = chrome.test.callbackFail;
10 10
11 chrome.test.getConfig(function(config) { 11 chrome.test.getConfig(function(config) {
12 var wallpaper; 12 var wallpaper;
13 var wallpaperStrings; 13 var wallpaperStrings;
14 var requestImage = function(url, onLoadCallback) {
15 var wallpaperRequest = new XMLHttpRequest();
16 wallpaperRequest.open('GET', url, true);
17 wallpaperRequest.responseType = 'arraybuffer';
18 try {
19 wallpaperRequest.send(null);
20 wallpaperRequest.onloadend = function(e) {
21 onLoadCallback(wallpaperRequest.status, wallpaperRequest.response);
22 };
23 } catch (e) {
24 console.error(e);
25 chrome.test.fail('An error thrown when requesting wallpaper.');
26 };
27 };
14 chrome.test.runTests([ 28 chrome.test.runTests([
15 function getWallpaperStrings() { 29 function getWallpaperStrings() {
16 chrome.wallpaperPrivate.getStrings(pass(function(strings) { 30 chrome.wallpaperPrivate.getStrings(pass(function(strings) {
17 wallpaperStrings = strings; 31 wallpaperStrings = strings;
18 })); 32 }));
19 }, 33 },
20 function setOnlineJpegWallpaper() { 34 function setOnlineJpegWallpaper() {
21 var wallpaperRequest = new XMLHttpRequest();
22 var url = "http://a.com:PORT/files/extensions/api_test" + 35 var url = "http://a.com:PORT/files/extensions/api_test" +
23 "/wallpaper_manager/test.jpg"; 36 "/wallpaper_manager/test.jpg";
24 url = url.replace(/PORT/, config.testServer.port); 37 url = url.replace(/PORT/, config.testServer.port);
25 wallpaperRequest.open('GET', url, true); 38 requestImage(url, function(requestStatus, response) {
26 wallpaperRequest.responseType = 'arraybuffer'; 39 if (requestStatus === 200) {
27 try { 40 wallpaper = response;
28 wallpaperRequest.send(null); 41 chrome.wallpaperPrivate.setWallpaper(wallpaper,
29 wallpaperRequest.onload = function (e) { 42 'CENTER_CROPPED',
30 if (wallpaperRequest.status === 200) { 43 url,
31 wallpaper = wallpaperRequest.response; 44 pass());
32 chrome.wallpaperPrivate.setWallpaper(wallpaper, 45 } else {
33 'CENTER_CROPPED', 46 chrome.test.fail('Failed to load test.jpg from local server.');
34 url, 47 }
35 pass()); 48 });
36 } else {
37 chrome.test.fail('Failed to load test.jpg from local server.');
38 }
39 };
40 } catch (e) {
41 console.error(e);
42 chrome.test.fail('An error thrown when requesting wallpaper.');
43 };
44 }, 49 },
45 function setCustomJpegWallpaper() { 50 function setCustomJpegWallpaper() {
46 chrome.wallpaperPrivate.setCustomWallpaper(wallpaper, 51 chrome.wallpaperPrivate.setCustomWallpaper(wallpaper,
47 'CENTER_CROPPED', 52 'CENTER_CROPPED',
48 pass()); 53 pass());
49 }, 54 },
50 function setCustomJepgBadWallpaper() { 55 function setCustomJepgBadWallpaper() {
51 var wallpaperRequest = new XMLHttpRequest();
52 var url = "http://a.com:PORT/files/extensions/api_test" + 56 var url = "http://a.com:PORT/files/extensions/api_test" +
53 "/wallpaper_manager/test_bad.jpg"; 57 "/wallpaper_manager/test_bad.jpg";
54 url = url.replace(/PORT/, config.testServer.port); 58 url = url.replace(/PORT/, config.testServer.port);
55 wallpaperRequest.open('GET', url, true); 59 requestImage(url, function(requestStatus, response) {
56 wallpaperRequest.responseType = 'arraybuffer'; 60 if (requestStatus === 200) {
57 try { 61 var badWallpaper = response;
58 wallpaperRequest.send(null); 62 chrome.wallpaperPrivate.setCustomWallpaper(badWallpaper,
59 wallpaperRequest.onload = function (e) { 63 'CENTER_CROPPED', fail(wallpaperStrings.invalidWallpaper));
60 if (wallpaperRequest.status === 200) { 64 } else {
61 var badWallpaper = wallpaperRequest.response; 65 chrome.test.fail('Failed to load test_bad.jpg from local server.');
62 chrome.wallpaperPrivate.setCustomWallpaper(badWallpaper, 66 }
63 'CENTER_CROPPED', fail(wallpaperStrings.invalidWallpaper)); 67 });
64 } else { 68 },
65 chrome.test.fail('Failed to load test_bad.jpg from local server.'); 69 function getAndSetThumbnail() {
66 } 70 var url = "http://a.com:PORT/files/extensions/api_test" +
67 }; 71 "/wallpaper_manager/test.jpg";
68 } catch (e) { 72 url = url.replace(/PORT/, config.testServer.port);
69 console.error(e); 73 chrome.wallpaperPrivate.getThumbnail(url, pass(function(data) {
70 chrome.test.fail('An error thrown when requesting wallpaper.'); 74 chrome.test.assertNoLastError();
71 }; 75 if (data)
76 chrome.test.fail('Thumbnail is not found. getThumbnail should not ' +
77 'return any data.');
78 chrome.wallpaperPrivate.saveThumbnail(url, wallpaper, pass(function() {
79 chrome.test.assertNoLastError();
80 chrome.wallpaperPrivate.getThumbnail(url, pass(function(data) {
81 chrome.test.assertNoLastError();
82 // Thumbnail should already be saved to thumbnail directory.
83 chrome.test.assertEq(wallpaper, data);
84 }));
85 }));
86 }));
72 } 87 }
73 ]); 88 ]);
74 }); 89 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698