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

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

Issue 167243002: Revert 251087 "Add wallpaper api tests" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 var pass = chrome.test.callbackPass;
6 var fail = chrome.test.callbackFail;
7
8 chrome.test.getConfig(function(config) {
9
10 var baseURL = "http://a.com:" + config.testServer.port +
11 "/extensions/api_test/wallpaper/";
12
13 /*
14 * Calls chrome.wallpaper.setWallpaper using an arraybuffer.
15 * @param {string} filePath An extension relative file path.
16 */
17 var testSetWallpaperFromArrayBuffer = function (filePath) {
18 // Loads an extension local file to an arraybuffer.
19 var url = chrome.runtime.getURL(filePath);
20 var wallpaperRequest = new XMLHttpRequest();
21 wallpaperRequest.open('GET', url, true);
22 wallpaperRequest.responseType = 'arraybuffer';
23 try {
24 wallpaperRequest.send(null);
25 wallpaperRequest.onloadend = function(e) {
26 if (wallpaperRequest.status === 200) {
27 chrome.wallpaper.setWallpaper(
28 {'wallpaperData': wallpaperRequest.response,
29 'layout': 'CENTER_CROPPED',
30 'name': 'test'},
31 // Set wallpaper directly with an arraybuffer should pass.
32 pass()
33 );
34 } else {
35 chrome.test.fail('Failed to load local file: ' + filePath + '.');
36 }
37 };
38 } catch (e) {
39 console.error(e);
40 chrome.test.fail('An error thrown when requesting wallpaper.');
41 }
42 };
43
44 /*
45 * Calls chrome.wallpaper.setWallpaper using an URL.
46 * @param {string} relativeURL The relative URL of an online image.
47 * @param {boolean} success True if expecting the API call success.
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.
50 */
51 var testSetWallpaperFromURL = function (relativeURL,
52 success,
53 optExpectedError) {
54 var url = baseURL + relativeURL;
55 if (success) {
56 chrome.wallpaper.setWallpaper(
57 {'url': url,
58 'layout': 'CENTER_CROPPED',
59 'name': 'test'},
60 // A valid url should set wallpaper correctly.
61 pass()
62 );
63 } else {
64 if (optExpectedError == undefined) {
65 chrome.test.fail('No expected error string is provided.');
66 return;
67 }
68 chrome.wallpaper.setWallpaper(
69 {'url': url,
70 'layout': 'CENTER_CROPPED',
71 'name': 'test'},
72 // Expect a failure.
73 fail(optExpectedError));
74 }
75 };
76
77 chrome.test.runTests([
78 function setJpgWallpaperFromAppLocalFile() {
79 testSetWallpaperFromArrayBuffer('test.jpg');
80 },
81 function setPngWallpaperFromAppLocalFile() {
82 testSetWallpaperFromArrayBuffer('test.png');
83 },
84 function setJpgWallpaperFromURL () {
85 testSetWallpaperFromURL('test.jpg', true);
86 },
87 function setPngWallpaperFromURL () {
88 testSetWallpaperFromURL('test.png', true);
89 },
90 function setNoExistingWallpaperFromURL () {
91 // test1.jpg doesn't exist. Expect Chrome cannot set wallpaper failure.
92 testSetWallpaperFromURL('test1.jpg',
93 false,
94 'Chrome cannot set wallpaper.');
95 },
96 function newRequestCancelPreviousRequest() {
97 // The first request should be canceled.
98 testSetWallpaperFromURL('test.png',
99 false,
100 'Downloading wallpaper test.png is canceled.');
101 testSetWallpaperFromURL('test.jpg', true);
102 }
103 ]);
104 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698