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

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

Issue 16634016: Support png wallpapers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: spelling Created 7 years, 6 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
« no previous file with comments | « chrome/browser/resources/chromeos/wallpaper_manager/main.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 wallpaperJpeg;
13 var wallpaperPng;
13 var wallpaperStrings; 14 var wallpaperStrings;
14 var requestImage = function(url, onLoadCallback) { 15 var requestImage = function(url, onLoadCallback) {
15 var wallpaperRequest = new XMLHttpRequest(); 16 var wallpaperRequest = new XMLHttpRequest();
16 wallpaperRequest.open('GET', url, true); 17 wallpaperRequest.open('GET', url, true);
17 wallpaperRequest.responseType = 'arraybuffer'; 18 wallpaperRequest.responseType = 'arraybuffer';
18 try { 19 try {
19 wallpaperRequest.send(null); 20 wallpaperRequest.send(null);
20 wallpaperRequest.onloadend = function(e) { 21 wallpaperRequest.onloadend = function(e) {
21 onLoadCallback(wallpaperRequest.status, wallpaperRequest.response); 22 onLoadCallback(wallpaperRequest.status, wallpaperRequest.response);
22 }; 23 };
23 } catch (e) { 24 } catch (e) {
24 console.error(e); 25 console.error(e);
25 chrome.test.fail('An error thrown when requesting wallpaper.'); 26 chrome.test.fail('An error thrown when requesting wallpaper.');
26 }; 27 };
27 }; 28 };
28 chrome.test.runTests([ 29 chrome.test.runTests([
29 function getWallpaperStrings() { 30 function getWallpaperStrings() {
30 chrome.wallpaperPrivate.getStrings(pass(function(strings) { 31 chrome.wallpaperPrivate.getStrings(pass(function(strings) {
31 wallpaperStrings = strings; 32 wallpaperStrings = strings;
32 })); 33 }));
33 }, 34 },
34 function setOnlineJpegWallpaper() { 35 function setOnlineJpegWallpaper() {
35 var url = "http://a.com:PORT/files/extensions/api_test" + 36 var url = "http://a.com:PORT/files/extensions/api_test" +
36 "/wallpaper_manager/test.jpg"; 37 "/wallpaper_manager/test.jpg";
37 url = url.replace(/PORT/, config.testServer.port); 38 url = url.replace(/PORT/, config.testServer.port);
38 requestImage(url, function(requestStatus, response) { 39 requestImage(url, function(requestStatus, response) {
39 if (requestStatus === 200) { 40 if (requestStatus === 200) {
40 wallpaper = response; 41 wallpaperJpeg = response;
41 chrome.wallpaperPrivate.setWallpaper(wallpaper, 42 chrome.wallpaperPrivate.setWallpaper(wallpaperJpeg,
42 'CENTER_CROPPED', 43 'CENTER_CROPPED',
43 url, 44 url,
44 pass(function() { 45 pass(function() {
45 chrome.wallpaperPrivate.setCustomWallpaperLayout('CENTER', 46 chrome.wallpaperPrivate.setCustomWallpaperLayout('CENTER',
46 fail('Only custom wallpaper can change layout.')); 47 fail('Only custom wallpaper can change layout.'));
47 })); 48 }));
48 } else { 49 } else {
49 chrome.test.fail('Failed to load test.jpg from local server.'); 50 chrome.test.fail('Failed to load test.jpg from local server.');
50 } 51 }
51 }); 52 });
52 }, 53 },
53 function setCustomJpegWallpaper() { 54 function setCustomJpegWallpaper() {
54 chrome.wallpaperPrivate.setCustomWallpaper(wallpaper, 55 chrome.wallpaperPrivate.setCustomWallpaper(wallpaperJpeg,
55 'CENTER_CROPPED', 56 'CENTER_CROPPED',
56 true, 57 true,
57 '123', 58 '123',
58 pass(function(thumbnail) { 59 pass(function(thumbnail) {
59 chrome.wallpaperPrivate.setCustomWallpaperLayout('CENTER', 60 chrome.wallpaperPrivate.setCustomWallpaperLayout('CENTER',
60 pass(function() { 61 pass(function() {
61 chrome.wallpaperPrivate.setCustomWallpaperLayout('STRETCH', pass()); 62 chrome.wallpaperPrivate.setCustomWallpaperLayout('STRETCH', pass());
62 })); 63 }));
63 })); 64 }));
64 }, 65 },
65 function getCustomWallpaperThumbnail() { 66 function setCustomPngWallpaper() {
66 chrome.wallpaperPrivate.getOfflineWallpaperList('CUSTOM', 67 var url = "http://a.com:PORT/files/extensions/api_test" +
67 pass(function(lists) { 68 "/wallpaper_manager/test.png";
68 chrome.test.assertEq(1, lists.length); 69 url = url.replace(/PORT/, config.testServer.port);
69 chrome.wallpaperPrivate.getThumbnail(lists[0], 'CUSTOM', 70 requestImage(url, function(requestStatus, response) {
70 pass(function(data) { 71 if (requestStatus === 200) {
71 chrome.test.assertNoLastError(); 72 wallpaperPng = response;
72 })); 73 chrome.wallpaperPrivate.setCustomWallpaper(wallpaperPng,
73 })); 74 'CENTER_CROPPED',
75 true,
76 '123',
77 pass(function(thumbnail) {
78 chrome.wallpaperPrivate.setCustomWallpaperLayout('CENTER',
79 pass(function() {
80 chrome.wallpaperPrivate.setCustomWallpaperLayout('STRETCH',
81 pass());
82 }));
83 }));
84 } else {
85 chrome.test.fail('Failed to load test.png from local server.');
86 }
87 });
74 }, 88 },
75 function setCustomJepgBadWallpaper() { 89 function setCustomJepgBadWallpaper() {
76 var url = "http://a.com:PORT/files/extensions/api_test" + 90 var url = "http://a.com:PORT/files/extensions/api_test" +
77 "/wallpaper_manager/test_bad.jpg"; 91 "/wallpaper_manager/test_bad.jpg";
78 url = url.replace(/PORT/, config.testServer.port); 92 url = url.replace(/PORT/, config.testServer.port);
79 requestImage(url, function(requestStatus, response) { 93 requestImage(url, function(requestStatus, response) {
80 if (requestStatus === 200) { 94 if (requestStatus === 200) {
81 var badWallpaper = response; 95 var badWallpaper = response;
82 chrome.wallpaperPrivate.setCustomWallpaper(badWallpaper, 96 chrome.wallpaperPrivate.setCustomWallpaper(badWallpaper,
83 'CENTER_CROPPED', false, '123', 97 'CENTER_CROPPED', false, '123',
(...skipping 19 matching lines...) Expand all
103 function getAndSetThumbnail() { 117 function getAndSetThumbnail() {
104 var url = "http://a.com:PORT/files/extensions/api_test" + 118 var url = "http://a.com:PORT/files/extensions/api_test" +
105 "/wallpaper_manager/test.jpg"; 119 "/wallpaper_manager/test.jpg";
106 url = url.replace(/PORT/, config.testServer.port); 120 url = url.replace(/PORT/, config.testServer.port);
107 chrome.wallpaperPrivate.getThumbnail(url, 'ONLINE', pass(function(data) { 121 chrome.wallpaperPrivate.getThumbnail(url, 'ONLINE', pass(function(data) {
108 chrome.test.assertNoLastError(); 122 chrome.test.assertNoLastError();
109 if (data) { 123 if (data) {
110 chrome.test.fail('Thumbnail is not found. getThumbnail should not ' + 124 chrome.test.fail('Thumbnail is not found. getThumbnail should not ' +
111 'return any data.'); 125 'return any data.');
112 } 126 }
113 chrome.wallpaperPrivate.saveThumbnail(url, wallpaper, pass(function() { 127 chrome.wallpaperPrivate.saveThumbnail(url, wallpaperJpeg,
128 pass(function() {
114 chrome.test.assertNoLastError(); 129 chrome.test.assertNoLastError();
115 chrome.wallpaperPrivate.getThumbnail(url, 'ONLINE', 130 chrome.wallpaperPrivate.getThumbnail(url, 'ONLINE',
116 pass(function(data) { 131 pass(function(data) {
117 chrome.test.assertNoLastError(); 132 chrome.test.assertNoLastError();
118 // Thumbnail should already be saved to thumbnail directory. 133 // Thumbnail should already be saved to thumbnail directory.
119 chrome.test.assertEq(wallpaper, data); 134 chrome.test.assertEq(wallpaperJpeg, data);
120 })); 135 }));
121 })); 136 }));
122 })); 137 }));
123 }, 138 },
124 function getOfflineWallpaperList() { 139 function getOfflineWallpaperList() {
125 chrome.wallpaperPrivate.getOfflineWallpaperList('ONLINE', 140 chrome.wallpaperPrivate.getOfflineWallpaperList('ONLINE',
126 pass(function(list) { 141 pass(function(list) {
127 // We have previously saved test.jpg in wallpaper directory. 142 // We have previously saved test.jpg in wallpaper directory.
128 chrome.test.assertEq('test.jpg', list[0]); 143 chrome.test.assertEq('test.jpg', list[0]);
129 // Saves the same wallpaper to wallpaper directory but name it as 144 // Saves the same wallpaper to wallpaper directory but name it as
130 // test1.jpg. 145 // test1.jpg.
131 chrome.wallpaperPrivate.setWallpaper(wallpaper, 146 chrome.wallpaperPrivate.setWallpaper(wallpaperJpeg,
132 'CENTER_CROPPED', 147 'CENTER_CROPPED',
133 'http://dummyurl/test1.jpg', 148 'http://dummyurl/test1.jpg',
134 pass(function() { 149 pass(function() {
135 chrome.wallpaperPrivate.getOfflineWallpaperList('ONLINE', 150 chrome.wallpaperPrivate.getOfflineWallpaperList('ONLINE',
136 pass(function(list) { 151 pass(function(list) {
137 chrome.test.assertEq('test.jpg', list[0]); 152 chrome.test.assertEq('test.jpg', list[0]);
138 chrome.test.assertEq('test1.jpg', list[1]); 153 chrome.test.assertEq('test1.jpg', list[1]);
139 })); 154 }));
140 })); 155 }));
141 })); 156 }));
142 } 157 }
143 ]); 158 ]);
144 }); 159 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/wallpaper_manager/main.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698