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 testSyncCustomWallpaperStore() {
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 that historical custom wallpapers from syncFS get synced to localFS on
60 // powerwashed (or recovered) devices.
61 function testSyncCustomWallpaperStoreOnPowerwashedDevice() {
62 TestConstants.isPowerwashed = 1;
63 var syncFSChanges = {};
64 syncFSChanges.status = 'synced';
65 syncFSChanges.direction = 'remote_to_local';
66 syncFSChanges.action = 'added';
67 syncFSChanges.fileEntry = mockSyncFS.mockTestFile('historicalwallpaper');
69 // TODO(ranj): support two callbacks with success and failure?
70 var mockWrite = mockController.createFunctionMock(mockWriter, 'write');
71 mockWrite.addExpectation(new Blob([new Int8Array(TestConstants.FILESTRING)]));
72 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
73 TestConstants.isPowerwashed = 0;
77 // Test delete custom wallpaper from local. When receive a syncFS delete file
78 // event, delete the file in localFS as well.
79 function testSyncCustomWallpaperDelete() {
80 var localOriginalPath = Constants.WallpaperDirNameEnum.ORIGINAL + '/' +
81 'deletewallpapername';
82 var localThumbnailPath = Constants.WallpaperDirNameEnum.THUMBNAIL + '/' +
83 'deletewallpapername';
84 var originalFE = mockLocalFS.mockTestFile(localOriginalPath);
85 var thumbnailFE = mockLocalFS.mockTestFile(localThumbnailPath);
86 var syncFSChanges = {};
87 syncFSChanges.status = 'synced';
88 syncFSChanges.direction = 'remote_to_local';
89 syncFSChanges.action = 'deleted';
90 syncFSChanges.fileEntry = new FileEntry('deletewallpapername');
91 var mockRemoveOriginal = mockController.createFunctionMock(originalFE,
93 mockRemoveOriginal.addExpectation(function() {}, null);
94 var mockRemoveThumbnail = mockController.createFunctionMock(thumbnailFE,
96 mockRemoveThumbnail.addExpectation(function() {}, null);
97 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
100 // Test sync online wallpaper. When the synced wallpaper info is not the same as
101 // the local wallpaper info, wallpaper should set to the synced one.
102 function testSyncOnlineWallpaper() {
105 changes[Constants.AccessSyncWallpaperInfoKey] = {};
106 changes[Constants.AccessSyncWallpaperInfoKey].newValue = {
107 'url': TestConstants.wallpaperURL,
109 'source': Constants.WallpaperSourceEnum.Online
112 var mockSetWallpaperIfExists = mockController.createFunctionMock(
113 chrome.wallpaperPrivate, 'setWallpaperIfExists');
114 mockSetWallpaperIfExists.addExpectation(
115 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url,
116 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout);
117 mockSetWallpaperIfExists.callbackData = [false];
119 var mockSetWallpaper = mockController.createFunctionMock(
120 chrome.wallpaperPrivate, 'setWallpaper');
121 mockSetWallpaper.addExpectation(
123 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout,
124 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url);
126 chrome.storage.onChanged.dispatch(changes);