Chromium Code Reviews| Index: chrome/test/data/chromeos/wallpaper_manager/unit_tests/event_page_unittest.js |
| diff --git a/chrome/test/data/chromeos/wallpaper_manager/unit_tests/event_page_unittest.js b/chrome/test/data/chromeos/wallpaper_manager/unit_tests/event_page_unittest.js |
| index f836ad4b647548a06d2127b2db141ff1560eea27..a2e6b4e76645493e8fa3e945ae45177d6a721284 100644 |
| --- a/chrome/test/data/chromeos/wallpaper_manager/unit_tests/event_page_unittest.js |
| +++ b/chrome/test/data/chromeos/wallpaper_manager/unit_tests/event_page_unittest.js |
| @@ -5,6 +5,136 @@ |
| var mockController; |
| +var fileString = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; |
| +var mockWriter = {}; |
| +mockWriter.write = function(blobData) { |
| +}; |
| + |
| +var currentWallpaperName = 'currentwallpapername'; |
|
bshe
2014/10/20 21:01:00
nit: all the variables are defined in global names
Ran
2014/10/23 15:58:59
Done.
|
| +var currentWallpaperLayout = 'currentwallpaperlayout'; |
| +var newWallpaperName = 'newwallpapername'; |
| +var existWallpaperName = 'existwallpapername'; |
| +var existWallpaperThumbnailNameInSync = existWallpaperName + |
| + Constants.CustomWallpaperThumbnailSuffix; |
| +var existOriginalWallpaperPath = Constants.WallpaperDirNameEnum.ORIGINAL + '/' + |
| + existWallpaperName; |
| +var existThumbnailWallpaperPath = Constants.WallpaperDirNameEnum.THUMBNAIL + |
| + '/'+ existWallpaperName; |
| +var mockCurrentFileEntry = new FileEntry(currentWallpaperName); |
| +var mockNewFileEntry = new FileEntry(newWallpaperName); |
| +var mockExistFileEntry = new FileEntry(existWallpaperName); |
| +var mockExistFileEntryThumbnailInSync = new FileEntry( |
| + existWallpaperThumbnailNameInSync); |
| +var mockExistFileEntryOriginalPath = new FileEntry(existOriginalWallpaperPath); |
| +var mockExistFileEntryThumbnailPath = new FileEntry( |
| + existThumbnailWallpaperPath); |
| + |
| +var mockSyncFS = {}; |
| +var mockLocalFS = {}; |
| +var mockLocalFSDir = {}; |
| + |
| +mockSyncFS.fileList = [mockCurrentFileEntry, mockNewFileEntry, |
| + mockExistFileEntry, mockExistFileEntryThumbnailInSync]; |
| +mockSyncFS.root = { |
| + getFile: function(fileName, isCreate, success, failure) { |
| + for(var i = 0; i < mockSyncFS.fileList.length; i++) { |
| + if (fileName == mockSyncFS.fileList[i].name) { |
| + success(mockSyncFS.fileList[i]); |
| + return; |
| + } |
| + } |
| + if (isCreate.create == false) { |
| + if (failure) |
| + failure('FILE_NOT_FOUND'); |
| + } |
| + else { |
| + mockSyncFS.fileList.push(new FileEntry(fileName)); |
| + success(mockSyncFS.fileList[mockSyncFS.fileList.length - 1]); |
| + } |
| + } |
| +}; |
| + |
| +var selectedFileEntry = null; |
| +mockLocalFSDir.fileList = [mockCurrentFileEntry, mockExistFileEntry, |
| + mockExistFileEntryOriginalPath, |
| + mockExistFileEntryThumbnailPath]; |
| +mockLocalFSDir.getFile = function(fileName, isCreate, success, failure) { |
| + for(var i = 0; i < mockLocalFSDir.fileList.length; i++) { |
| + if (fileName == mockLocalFSDir.fileList[i].name) { |
| + selectedFileEntry = mockLocalFSDir.fileList[i]; |
| + success(selectedFileEntry); |
| + return; |
| + } |
| + } |
| + if (isCreate.create == false) { |
| + if (failure) { |
| + failure('FILE_NOT_FOUND'); |
| + } |
| + } |
| + else { |
| + mockLocalFSDir.fileList.push( new FileEntry(fileName) ); |
| + selectedFileEntry = mockLocalFSDir.fileList[mockLocalFSDir.fileList.length - |
| + 1]; |
| + success(selectedFileEntry ); |
| + } |
| +} |
| + |
| +mockLocalFS.root = { |
| + getDirectory: function(dir, isCreate, success, fail) { |
| + success(mockLocalFSDir); |
| + }, |
| + getFile: function(fileName, isCreate, success, failure) { |
| + mockLocalFSDir.getFile(fileName, isCreate, success, failure); |
| + } |
| +} |
| + |
| +window.webkitRequestFileSystem = function(dontcare1, dontcare2, callback) { |
| + callback(mockLocalFS); |
| +} |
| + |
| +chrome.syncFileSystem.requestFileSystem = function(callback) { |
| + callback(mockSyncFS); |
| +}; |
| + |
| +WallpaperUtil.enabledExperimentalFeatureCallback = function(callback) { |
| + callback(); |
| +}; |
| + |
| +chrome.storage.local.get = function(key, callback) { |
|
bshe
2014/10/20 21:00:59
this overrides the globe stub implementation of ch
Ran
2014/10/23 15:58:58
Done.
|
| + var items = {}; |
| + switch (key) { |
| + case Constants.AccessLocalWallpaperInfoKey: |
| + items[Constants.AccessLocalWallpaperInfoKey] = { |
| + 'url': currentWallpaperName, |
| + 'layout': currentWallpaperLayout, |
| + 'source': Constants.WallpaperSourceEnum.Custom |
| + }; |
| + } |
| + callback(items); |
| +}; |
| + |
|
bshe
2014/10/20 21:00:59
I think FileEntry and FileReader could move to api
Ran
2014/10/23 15:58:58
Done.
|
| +function FileEntry(filename) { |
| + this.name = filename; |
| + this.file = function(callback) { |
| + callback(fileString); |
| + }; |
| + this.createWriter = function(callback) { |
| + callback(mockWriter); |
| + }; |
| + this.remove = function(success, failure) { |
| + }; |
| +} |
| + |
| +function FileReader() { |
| + this.result = ''; |
| + this.onloadend = function() { |
| + }; |
| + this.readAsArrayBuffer = function(mockFile) { |
| + this.result = mockFile; |
| + this.onloadend(); |
| + } |
| +} |
| + |
| function setUp() { |
| mockController = new MockController(); |
| installMockXMLHttpRequest(); |
| @@ -14,6 +144,57 @@ function tearDown() { |
| mockController.verifyMocks(); |
| mockController.reset(); |
| uninstallMockXMLHttpRequest(); |
| + selectedFileEntry = null; |
| +} |
| + |
| +// Test sync Custom wallpaper. When the synced wallpaper info is not the same as |
| +// the local wallpaper info, wallpaper should set to the synced one. |
| +function testSyncCustomWallpaperSet() { |
| + var mockSetCustomWallpaper = mockController.createFunctionMock( |
| + chrome.wallpaperPrivate, 'setCustomWallpaper'); |
| + mockSetCustomWallpaper.addExpectation(fileString, |
| + currentWallpaperLayout, |
| + true, |
| + currentWallpaperName); |
| + var syncFSChanges = {}; |
| + syncFSChanges.status = 'synced'; |
| + syncFSChanges.direction = 'remote_to_local'; |
| + syncFSChanges.action = 'added'; |
| + syncFSChanges.fileEntry = mockCurrentFileEntry; |
| + chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges); |
| +} |
| + |
| +// Test sync Custom wallpaper. When the synced wallpaper info is not the same as |
| +// the local wallpaper info, wallpaper should set to the synced one. |
| +function testSyncCustoWallpapermStore() { |
| + var syncFSChanges = {}; |
| + syncFSChanges.status = 'synced'; |
| + syncFSChanges.direction = 'remote_to_local'; |
| + syncFSChanges.action = 'added'; |
| + syncFSChanges.fileEntry = mockNewFileEntry; |
| + |
| + // TODO(ranj): support two callbacks with success and failure? |
| + var mockWrite = mockController.createFunctionMock(mockWriter, 'write'); |
| + mockWrite.addExpectation(new Blob([new Int8Array(fileString)])); |
|
bshe
2014/10/20 21:00:59
Is it possible to move this to previous test? This
Ran
2014/10/23 15:58:59
I think it might be clear to separate them since o
|
| + chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges); |
| +} |
| + |
| +// Test sync Custom wallpaper. When the synced wallpaper info is not the same as |
| +// the local wallpaper info, wallpaper should set to the synced one. |
|
bshe
2014/10/20 21:00:59
nit: update the comment.
Ran
2014/10/23 15:58:58
Done.
|
| +function testSyncCustomWallpaperDelete() { |
| + var syncFSChanges = {}; |
| + syncFSChanges.status = 'synced'; |
| + syncFSChanges.direction = 'remote_to_local'; |
| + syncFSChanges.action = 'deleted'; |
| + syncFSChanges.fileEntry = mockExistFileEntry; |
| + |
| + var mockRemoveThumbnail = mockController.createFunctionMock( |
| + mockExistFileEntryThumbnailPath, 'remove'); |
| + mockRemoveThumbnail.addExpectation(function() {}, null); |
| + var mockRemoveOriginal = mockController.createFunctionMock( |
| + mockExistFileEntryOriginalPath, 'remove'); |
| + mockRemoveOriginal.addExpectation(function() {}, null); |
| + chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges); |
| } |
| // Test sync online wallpaper. When the synced wallpaper info is not the same as |