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.
8 WallpaperUtil.enabledSyncThemesCallback = function(callback) {
9 chrome.wallpaperPrivate.getSyncSetting(function(setting) {
10 callback(setting.syncThemes);
15 mockController = new MockController();
16 installMockXMLHttpRequest();
20 mockController.verifyMocks();
21 mockController.reset();
22 uninstallMockXMLHttpRequest();
27 // Test set custom wallpaper from syncFS. When local wallpaper name is different
28 // with the name in server, wallpaper should use the one in server.
29 function testSyncCustomWallpaperSet() {
30 var mockSetCustomWallpaper = mockController.createFunctionMock(
31 chrome.wallpaperPrivate, 'setCustomWallpaper');
32 mockSetCustomWallpaper.addExpectation(TestConstants.FILESTRING,
36 var syncFSChanges = {};
37 syncFSChanges.status = 'synced';
38 syncFSChanges.direction = 'remote_to_local';
39 syncFSChanges.action = 'added';
40 syncFSChanges.fileEntry = mockSyncFS.mockTestFile('dummy');
41 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
44 // Test store historical custom wallpaper. When receive a historical wallpaper
45 // from syncFS, we store it to local.
46 function testSyncCustoWallpapermStore() {
47 var syncFSChanges = {};
48 syncFSChanges.status = 'synced';
49 syncFSChanges.direction = 'remote_to_local';
50 syncFSChanges.action = 'added';
51 syncFSChanges.fileEntry = mockSyncFS.mockTestFile('historicalwallpaper');
53 // TODO(ranj): support two callbacks with success and failure?
54 var mockWrite = mockController.createFunctionMock(mockWriter, 'write');
55 mockWrite.addExpectation(new Blob([new Int8Array(TestConstants.FILESTRING)]));
56 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
59 // Test delete custom wallpaper from local. When receive a syncFS delete file
60 // event, delete the file in localFS as well.
61 function testSyncCustomWallpaperDelete() {
62 var localOriginalPath = Constants.WallpaperDirNameEnum.ORIGINAL + '/' +
63 'deletewallpapername';
64 var localThumbnailPath = Constants.WallpaperDirNameEnum.THUMBNAIL + '/' +
65 'deletewallpapername';
66 var originalFE = mockLocalFS.mockTestFile(localOriginalPath);
67 var thumbnailFE = mockLocalFS.mockTestFile(localThumbnailPath);
68 var syncFSChanges = {};
69 syncFSChanges.status = 'synced';
70 syncFSChanges.direction = 'remote_to_local';
71 syncFSChanges.action = 'deleted';
72 syncFSChanges.fileEntry = new FileEntry('deletewallpapername');
73 var mockRemoveOriginal = mockController.createFunctionMock(originalFE,
75 mockRemoveOriginal.addExpectation(function() {}, null);
76 var mockRemoveThumbnail = mockController.createFunctionMock(thumbnailFE,
78 mockRemoveThumbnail.addExpectation(function() {}, null);
79 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
82 // Test sync online wallpaper. When the synced wallpaper info is not the same as
83 // the local wallpaper info, wallpaper should set to the synced one.
84 function testSyncOnlineWallpaper() {
87 changes[Constants.AccessSyncWallpaperInfoKey] = {};
88 changes[Constants.AccessSyncWallpaperInfoKey].newValue = {
89 'url': TestConstants.wallpaperURL,
91 'source': Constants.WallpaperSourceEnum.Online
94 var mockSetWallpaperIfExists = mockController.createFunctionMock(
95 chrome.wallpaperPrivate, 'setWallpaperIfExists');
96 mockSetWallpaperIfExists.addExpectation(
97 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url,
98 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout);
99 mockSetWallpaperIfExists.callbackData = [false];
101 var mockSetWallpaper = mockController.createFunctionMock(
102 chrome.wallpaperPrivate, 'setWallpaper');
103 mockSetWallpaper.addExpectation(
105 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout,
106 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url);
108 chrome.storage.onChanged.dispatch(changes);