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

Unified Diff: chrome/test/data/extensions/api_test/wallpaper/test.js

Issue 153093010: Add wallpaper api tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/wallpaper/test.js
diff --git a/chrome/test/data/extensions/api_test/wallpaper/test.js b/chrome/test/data/extensions/api_test/wallpaper/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..3cb3cc63a8c274fb9858f9e6c0eb06b6854a8b44
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/wallpaper/test.js
@@ -0,0 +1,104 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var pass = chrome.test.callbackPass;
+var fail = chrome.test.callbackFail;
+
+chrome.test.getConfig(function(config) {
+
+ var baseURL = "http://a.com:" + config.testServer.port +
+ "/extensions/api_test/wallpaper/";
+
+ /*
+ * Calls chrome.wallpaper.setWallpaper using an arraybuffer.
+ * @param {string} filePath An extension relative file path.
+ */
+ var testSetWallpaperFromArrayBuffer = function (filePath) {
+ // Loads an extension local file to an arraybuffer.
+ var url = chrome.runtime.getURL(filePath);
+ var wallpaperRequest = new XMLHttpRequest();
+ wallpaperRequest.open('GET', url, true);
+ wallpaperRequest.responseType = 'arraybuffer';
+ try {
+ wallpaperRequest.send(null);
+ wallpaperRequest.onloadend = function(e) {
+ if (wallpaperRequest.status === 200) {
+ chrome.wallpaper.setWallpaper(
+ {'wallpaperData': wallpaperRequest.response,
+ 'layout': 'CENTER_CROPPED',
+ 'name': 'test'},
+ // Set wallpaper directly with an arraybuffer should pass.
+ pass()
+ );
+ } else {
+ chrome.test.fail('Failed to load local file: ' + filePath + '.');
+ }
+ };
+ } catch (e) {
+ console.error(e);
+ chrome.test.fail('An error thrown when requesting wallpaper.');
+ }
+ };
+
+ /*
+ * Calls chrome.wallpaper.setWallpaper using an URL.
+ * @param {string} relativeURL The relative URL of an online image.
+ * @param {boolean} success True if expecting the API call success.
+ * @param {string=} optExpectedError The expected error string if API call
+ * failed. An error string must be provided if success is set to false.
+ */
+ var testSetWallpaperFromURL = function (relativeURL,
+ success,
+ optExpectedError) {
+ var url = baseURL + relativeURL;
+ if (success) {
+ chrome.wallpaper.setWallpaper(
+ {'url': url,
+ 'layout': 'CENTER_CROPPED',
+ 'name': 'test'},
+ // A valid url should set wallpaper correctly.
+ pass()
+ );
+ } else {
+ if (optExpectedError == undefined) {
+ chrome.test.fail('No expected error string is provided.');
+ return;
+ }
+ chrome.wallpaper.setWallpaper(
+ {'url': url,
+ 'layout': 'CENTER_CROPPED',
+ 'name': 'test'},
+ // Expect a failure.
+ fail(optExpectedError));
+ }
+ };
+
+ chrome.test.runTests([
+ function setJpgWallpaperFromAppLocalFile() {
+ testSetWallpaperFromArrayBuffer('test.jpg');
+ },
+ function setPngWallpaperFromAppLocalFile() {
+ testSetWallpaperFromArrayBuffer('test.png');
+ },
+ function setJpgWallpaperFromURL () {
+ testSetWallpaperFromURL('test.jpg', true);
+ },
+ function setPngWallpaperFromURL () {
+ testSetWallpaperFromURL('test.png', true);
+ },
+ function setNoExistingWallpaperFromURL () {
+ // test1.jpg doesn't exist. Expect Chrome cannot set wallpaper failure.
+ testSetWallpaperFromURL('test1.jpg',
+ false,
+ 'Chrome cannot set wallpaper.');
+ },
+ function newRequestCancelPreviousRequest() {
+ // The first request should be canceled.
+ testSetWallpaperFromURL('test.png',
+ false,
+ 'Downloading wallpaper test.png is canceled.');
+ testSetWallpaperFromURL('test.jpg', true);
+ }
+ ]);
+});
« no previous file with comments | « chrome/test/data/extensions/api_test/wallpaper/test.jpg ('k') | chrome/test/data/extensions/api_test/wallpaper/test.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698