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

Unified Diff: chrome/test/data/chromeos/wallpaper_manager/unit_tests/api_mock.js

Issue 618743003: Unit test for sync online wallpaper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/chromeos/wallpaper_manager/unit_tests/api_mock.js
diff --git a/chrome/test/data/chromeos/wallpaper_manager/unit_tests/api_mock.js b/chrome/test/data/chromeos/wallpaper_manager/unit_tests/api_mock.js
new file mode 100644
index 0000000000000000000000000000000000000000..59a25b85aaaf7b802dbf2f4c1602d072c635b20c
--- /dev/null
+++ b/chrome/test/data/chromeos/wallpaper_manager/unit_tests/api_mock.js
@@ -0,0 +1,121 @@
+// 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 TestConstants = {
+ wallpaperURL: 'https://test.com/test.jpg',
+ // A dummy string which is used to mock an image.
+ image: '*#*@#&'
+};
+
+// Mock a few chrome apis.
+var chrome = {
+ storage: {
+ local: {
+ get: function(key, callback) {
+ var items = {};
+ switch (key) {
+ case Constants.AccessLocalWallpaperInfoKey:
+ items[Constants.AccessLocalWallpaperInfoKey] = {
+ 'url': 'dummy',
+ 'layout': 'dummy',
+ 'source': 'dummy'
+ };
+ }
+ callback(items);
+ },
+ set: function(items, callback) {
+ }
+ },
+ sync: {
+ get: function(key, callback) {
+ },
+ set: function(items, callback) {
+ }
+ },
+ onChanged: {
+ addListener: function(listener) {
+ this.dispatch = listener;
+ }
+ }
+ },
+ app: {
+ runtime: {
+ onLaunched: {
+ addListener: function(listener) {
+ }
+ }
+ }
+ },
+ alarms: {
+ onAlarm: {
+ addListener: function(listener) {
+ }
+ }
+ }
+};
+
+(function (exports) {
+ var originalXMLHttpRequest = window.XMLHttpRequest;
+
+ // Mock XMLHttpRequest. It dispatches a 'load' event immediately with status
+ // equals to 200 in function |send|.
+ function MockXMLHttpRequest() {
+ }
+
+ MockXMLHttpRequest.prototype = {
+ responseType: null,
+ url: null,
+
+ send: function(data) {
+ this.status = 200;
+ this.dispatchEvent('load');
+ },
+
+ addEventListener: function(type, listener) {
+ this.eventListeners = this.eventListeners || {};
+ this.eventListeners[type] = this.eventListeners[type] || [];
+ this.eventListeners[type].push(listener);
+ },
+
+ removeEventListener: function (type, listener) {
+ var listeners = this.eventListeners && this.eventListeners[type] || [];
+
+ for (var i = 0; i < listeners.length; ++i) {
+ if (listeners[i] == listener) {
+ return listeners.splice(i, 1);
+ }
+ }
+ },
+
+ dispatchEvent: function(type) {
+ var listeners = this.eventListeners && this.eventListeners[type] || [];
+
+ if (/test.jpg$/g.test(this.url)) {
+ this.response = TestConstants.image;
+ } else {
+ this.response = '';
+ }
+
+ for (var i = 0; i < listeners.length; ++i)
+ listeners[i].call(this, new Event(type));
+ },
+
+ open: function(method, url, async) {
+ this.url = url;
+ }
+ };
+
+ function installMockXMLHttpRequest() {
+ window['XMLHttpRequest'] = MockXMLHttpRequest;
+ };
+
+ function uninstallMockXMLHttpRequest() {
+ window['XMLHttpRequest'] = originalXMLHttpRequest;
+ };
+
+ exports.installMockXMLHttpRequest = installMockXMLHttpRequest;
+ exports.uninstallMockXMLHttpRequest = uninstallMockXMLHttpRequest;
+
+})(window);

Powered by Google App Engine
This is Rietveld 408576698