Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 'use strict'; | 4 'use strict'; |
| 5 | 5 |
| 6 var mockController; | 6 var mockController; |
| 7 | 7 |
| 8 WallpaperUtil.enabledExperimentalFeatureCallback = function(callback) { | |
| 9 callback(); | |
| 10 }; | |
| 11 | |
| 12 WallpaperUtil.enabledSyncThemesCallback = function(callback) { | |
| 13 callback(); | |
| 14 }; | |
| 15 | |
| 8 function setUp() { | 16 function setUp() { |
| 9 mockController = new MockController(); | 17 mockController = new MockController(); |
| 10 installMockXMLHttpRequest(); | 18 installMockXMLHttpRequest(); |
| 11 } | 19 } |
| 12 | 20 |
| 13 function tearDown() { | 21 function tearDown() { |
| 14 mockController.verifyMocks(); | 22 mockController.verifyMocks(); |
| 15 mockController.reset(); | 23 mockController.reset(); |
| 16 uninstallMockXMLHttpRequest(); | 24 uninstallMockXMLHttpRequest(); |
| 25 mockSyncFS.reset(); | |
| 26 mockLocalFS.reset(); | |
| 27 } | |
| 28 | |
| 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, | |
| 35 'dummy', | |
| 36 true, | |
| 37 'dummy'); | |
| 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); | |
| 44 } | |
| 45 | |
| 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'); | |
| 54 | |
| 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); | |
| 59 } | |
| 60 | |
| 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, | |
| 76 'remove'); | |
| 77 mockRemoveOriginal.addExpectation(function() {}, null); | |
| 78 var mockRemoveThumbnail = mockController.createFunctionMock(thumbnailFE, | |
| 79 'remove'); | |
| 80 mockRemoveThumbnail.addExpectation(function() {}, null); | |
| 81 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges); | |
| 17 } | 82 } |
| 18 | 83 |
|
bshe
2014/10/28 22:34:57
Is it possible to add a test that a new custom wal
Ran
2014/10/29 19:13:13
Not possible for now as the FS operations takes tw
bshe
2014/10/30 12:51:36
never mind. you can do it in a separate CL.
| |
| 19 // Test sync online wallpaper. When the synced wallpaper info is not the same as | 84 // Test sync online wallpaper. When the synced wallpaper info is not the same as |
| 20 // the local wallpaper info, wallpaper should set to the synced one. | 85 // the local wallpaper info, wallpaper should set to the synced one. |
| 21 function testSyncOnlineWallpaper() { | 86 function testSyncOnlineWallpaper() { |
| 22 // Setup sync value. | 87 // Setup sync value. |
| 23 var changes = {}; | 88 var changes = {}; |
| 24 changes[Constants.AccessSyncWallpaperInfoKey] = {}; | 89 changes[Constants.AccessSyncWallpaperInfoKey] = {}; |
| 25 changes[Constants.AccessSyncWallpaperInfoKey].newValue = { | 90 changes[Constants.AccessSyncWallpaperInfoKey].newValue = { |
| 26 'url': TestConstants.wallpaperURL, | 91 'url': TestConstants.wallpaperURL, |
| 27 'layout': 'custom', | 92 'layout': 'custom', |
| 28 'source': Constants.WallpaperSourceEnum.Online | 93 'source': Constants.WallpaperSourceEnum.Online |
| 29 }; | 94 }; |
| 30 | 95 |
| 31 var mockSetWallpaperIfExists = mockController.createFunctionMock( | 96 var mockSetWallpaperIfExists = mockController.createFunctionMock( |
| 32 chrome.wallpaperPrivate, 'setWallpaperIfExists'); | 97 chrome.wallpaperPrivate, 'setWallpaperIfExists'); |
| 33 mockSetWallpaperIfExists.addExpectation( | 98 mockSetWallpaperIfExists.addExpectation( |
| 34 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url, | 99 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url, |
| 35 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout); | 100 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout); |
| 36 mockSetWallpaperIfExists.callbackData = [false]; | 101 mockSetWallpaperIfExists.callbackData = [false]; |
| 37 | 102 |
| 38 var mockSetWallpaper = mockController.createFunctionMock( | 103 var mockSetWallpaper = mockController.createFunctionMock( |
| 39 chrome.wallpaperPrivate, 'setWallpaper'); | 104 chrome.wallpaperPrivate, 'setWallpaper'); |
| 40 mockSetWallpaper.addExpectation( | 105 mockSetWallpaper.addExpectation( |
| 41 TestConstants.image, | 106 TestConstants.image, |
| 42 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout, | 107 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout, |
| 43 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url); | 108 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url); |
| 44 | 109 |
| 45 chrome.storage.onChanged.dispatch(changes); | 110 chrome.storage.onChanged.dispatch(changes); |
| 46 } | 111 } |
| OLD | NEW |