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.enabledExperimentalFeatureCallback = function(callback) {
12 WallpaperUtil.enabledSyncThemesCallback = function(callback) {
17 mockController = new MockController();
18 installMockXMLHttpRequest();
22 mockController.verifyMocks();
23 mockController.reset();
24 uninstallMockXMLHttpRequest();
29 // Test set custom wallpaper from syncFS. When local wallpaper name is different
30 // with the name in server, wallpaper should use the one in server.
31 function testSyncCustomWallpaperSet() {
32 var mockSetCustomWallpaper = mockController.createFunctionMock(
33 chrome.wallpaperPrivate, 'setCustomWallpaper');
34 mockSetCustomWallpaper.addExpectation(TestConstants.FILESTRING,
38 var syncFSChanges = {};
39 syncFSChanges.status = 'synced';
40 syncFSChanges.direction = 'remote_to_local';
41 syncFSChanges.action = 'added';
42 syncFSChanges.fileEntry = mockSyncFS.mockTestFile('dummy');
43 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
46 // Test store historical custom wallpaper. When receive a historical wallpaper
47 // from syncFS, we store it to local.
48 function testSyncCustoWallpapermStore() {
49 var syncFSChanges = {};
50 syncFSChanges.status = 'synced';
51 syncFSChanges.direction = 'remote_to_local';
52 syncFSChanges.action = 'added';
53 syncFSChanges.fileEntry = mockSyncFS.mockTestFile('historicalwallpaper');
55 // TODO(ranj): support two callbacks with success and failure?
56 var mockWrite = mockController.createFunctionMock(mockWriter, 'write');
57 mockWrite.addExpectation(new Blob([new Int8Array(TestConstants.FILESTRING)]));
58 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
61 // Test delete custom wallpaper from local. When receive a syncFS delete file
62 // event, delete the file in localFS as well.
63 function testSyncCustomWallpaperDelete() {
64 var localOriginalPath = Constants.WallpaperDirNameEnum.ORIGINAL + '/' +
65 'deletewallpapername';
66 var localThumbnailPath = Constants.WallpaperDirNameEnum.THUMBNAIL + '/' +
67 'deletewallpapername';
68 var originalFE = mockLocalFS.mockTestFile(localOriginalPath);
69 var thumbnailFE = mockLocalFS.mockTestFile(localThumbnailPath);
70 var syncFSChanges = {};
71 syncFSChanges.status = 'synced';
72 syncFSChanges.direction = 'remote_to_local';
73 syncFSChanges.action = 'deleted';
74 syncFSChanges.fileEntry = new FileEntry('deletewallpapername');
75 var mockRemoveOriginal = mockController.createFunctionMock(originalFE,
77 mockRemoveOriginal.addExpectation(function() {}, null);
78 var mockRemoveThumbnail = mockController.createFunctionMock(thumbnailFE,
80 mockRemoveThumbnail.addExpectation(function() {}, null);
81 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
84 // Test sync online wallpaper. When the synced wallpaper info is not the same as
85 // the local wallpaper info, wallpaper should set to the synced one.
86 function testSyncOnlineWallpaper() {
89 changes[Constants.AccessSyncWallpaperInfoKey] = {};
90 changes[Constants.AccessSyncWallpaperInfoKey].newValue = {
91 'url': TestConstants.wallpaperURL,
93 'source': Constants.WallpaperSourceEnum.Online
96 var mockSetWallpaperIfExists = mockController.createFunctionMock(
97 chrome.wallpaperPrivate, 'setWallpaperIfExists');
98 mockSetWallpaperIfExists.addExpectation(
99 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url,
100 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout);
101 mockSetWallpaperIfExists.callbackData = [false];
103 var mockSetWallpaper = mockController.createFunctionMock(
104 chrome.wallpaperPrivate, 'setWallpaper');
105 mockSetWallpaper.addExpectation(
107 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout,
108 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url);
110 chrome.storage.onChanged.dispatch(changes);