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

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

Issue 559583002: change chrome.wallpaper.setWallpaper api (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
« no previous file with comments | « chrome/common/extensions/docs/templates/intros/wallpaper.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 var pass = chrome.test.callbackPass; 5 var pass = chrome.test.callbackPass;
6 var fail = chrome.test.callbackFail; 6 var fail = chrome.test.callbackFail;
7 7
8 chrome.test.getConfig(function(config) { 8 chrome.test.getConfig(function(config) {
9 9
10 var baseURL = "http://a.com:" + config.testServer.port + 10 var baseURL = "http://a.com:" + config.testServer.port +
11 "/extensions/api_test/wallpaper/"; 11 "/extensions/api_test/wallpaper/";
12 12
13 /* 13 /*
14 * Calls chrome.wallpaper.setWallpaper using an arraybuffer. 14 * Calls chrome.wallpaper.setWallpaper using an arraybuffer.
15 * @param {string} filePath An extension relative file path. 15 * @param {string} filePath An extension relative file path.
16 */ 16 */
17 var testSetWallpaperFromArrayBuffer = function (filePath) { 17 var testSetWallpaperFromArrayBuffer = function (filePath) {
18 // Loads an extension local file to an arraybuffer. 18 // Loads an extension local file to an arraybuffer.
19 var url = chrome.runtime.getURL(filePath); 19 var url = chrome.runtime.getURL(filePath);
20 var wallpaperRequest = new XMLHttpRequest(); 20 var wallpaperRequest = new XMLHttpRequest();
21 wallpaperRequest.open('GET', url, true); 21 wallpaperRequest.open('GET', url, true);
22 wallpaperRequest.responseType = 'arraybuffer'; 22 wallpaperRequest.responseType = 'arraybuffer';
23 try { 23 try {
24 wallpaperRequest.send(null); 24 wallpaperRequest.send(null);
25 wallpaperRequest.onloadend = function(e) { 25 wallpaperRequest.onloadend = function(e) {
26 if (wallpaperRequest.status === 200) { 26 if (wallpaperRequest.status === 200) {
27 chrome.wallpaper.setWallpaper( 27 chrome.wallpaper.setWallpaper(
28 {'wallpaperData': wallpaperRequest.response, 28 {'data': wallpaperRequest.response,
29 'layout': 'CENTER_CROPPED', 29 'layout': 'CENTER_CROPPED',
30 'name': 'test'}, 30 'filename': 'test'},
31 // Set wallpaper directly with an arraybuffer should pass. 31 // Set wallpaper directly with an arraybuffer should pass.
32 pass() 32 pass()
33 ); 33 );
34 } else { 34 } else {
35 chrome.test.fail('Failed to load local file: ' + filePath + '.'); 35 chrome.test.fail('Failed to load local file: ' + filePath + '.');
36 } 36 }
37 }; 37 };
38 } catch (e) { 38 } catch (e) {
39 console.error(e); 39 console.error(e);
40 chrome.test.fail('An error thrown when requesting wallpaper.'); 40 chrome.test.fail('An error thrown when requesting wallpaper.');
41 } 41 }
42 }; 42 };
43 43
44 /* 44 /*
45 * Calls chrome.wallpaper.setWallpaper using an URL. 45 * Calls chrome.wallpaper.setWallpaper using an URL.
46 * @param {string} relativeURL The relative URL of an online image. 46 * @param {string} relativeURL The relative URL of an online image.
47 * @param {boolean} success True if expecting the API call success. 47 * @param {boolean} success True if expecting the API call success.
48 * @param {string=} optExpectedError The expected error string if API call 48 * @param {string=} optExpectedError The expected error string if API call
49 * failed. An error string must be provided if success is set to false. 49 * failed. An error string must be provided if success is set to false.
50 */ 50 */
51 var testSetWallpaperFromURL = function (relativeURL, 51 var testSetWallpaperFromURL = function (relativeURL,
52 success, 52 success,
53 optExpectedError) { 53 optExpectedError) {
54 var url = baseURL + relativeURL; 54 var url = baseURL + relativeURL;
55 if (success) { 55 if (success) {
56 chrome.wallpaper.setWallpaper( 56 chrome.wallpaper.setWallpaper(
57 {'url': url, 57 {'url': url,
58 'layout': 'CENTER_CROPPED', 58 'layout': 'CENTER_CROPPED',
59 'name': 'test'}, 59 'filename': 'test'},
60 // A valid url should set wallpaper correctly. 60 // A valid url should set wallpaper correctly.
61 pass() 61 pass()
62 ); 62 );
63 } else { 63 } else {
64 if (optExpectedError == undefined) { 64 if (optExpectedError == undefined) {
65 chrome.test.fail('No expected error string is provided.'); 65 chrome.test.fail('No expected error string is provided.');
66 return; 66 return;
67 } 67 }
68 chrome.wallpaper.setWallpaper( 68 chrome.wallpaper.setWallpaper(
69 {'url': url, 69 {'url': url,
70 'layout': 'CENTER_CROPPED', 70 'layout': 'CENTER_CROPPED',
71 'name': 'test'}, 71 'filename': 'test'},
72 // Expect a failure. 72 // Expect a failure.
73 fail(optExpectedError)); 73 fail(optExpectedError));
74 } 74 }
75 }; 75 };
76 76
77 chrome.test.runTests([ 77 chrome.test.runTests([
78 function setJpgWallpaperFromAppLocalFile() { 78 function setJpgWallpaperFromAppLocalFile() {
79 testSetWallpaperFromArrayBuffer('test.jpg'); 79 testSetWallpaperFromArrayBuffer('test.jpg');
80 }, 80 },
81 function setPngWallpaperFromAppLocalFile() { 81 function setPngWallpaperFromAppLocalFile() {
(...skipping 15 matching lines...) Expand all
97 }, 97 },
98 function newRequestCancelPreviousRequest() { 98 function newRequestCancelPreviousRequest() {
99 // The first request should be canceled. 99 // The first request should be canceled.
100 testSetWallpaperFromURL('test.png', 100 testSetWallpaperFromURL('test.png',
101 false, 101 false,
102 'Set wallpaper was canceled.'); 102 'Set wallpaper was canceled.');
103 testSetWallpaperFromURL('test.jpg', true); 103 testSetWallpaperFromURL('test.jpg', true);
104 } 104 }
105 ]); 105 ]);
106 }); 106 });
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/templates/intros/wallpaper.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698