Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: chrome/test/data/chromeos/wallpaper_manager/unit_tests/event_page_unittest.js

Issue 642943002: Add tests for sync custom wallpaper feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move mock functions to api_mock.js Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6afef32e7c3d9f063596fde9a960a6a66fa37f75 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,14 @@
var mockController;
+WallpaperUtil.enabledExperimentalFeatureCallback = function(callback) {
+ callback();
+};
+
+WallpaperUtil.enabledSyncThemesCallback = function(callback) {
+ callback();
+};
+
function setUp() {
mockController = new MockController();
installMockXMLHttpRequest();
@@ -14,6 +22,82 @@ function tearDown() {
mockController.verifyMocks();
mockController.reset();
uninstallMockXMLHttpRequest();
+ mockSyncFS.reset();
+ mockLocalFS.reset();
+}
+
+// Test set custom wallpaper from syncFS. When local wallpaper name is different
+// with the name in server, wallpaper should use the one in server.
+function testSyncCustomWallpaperSet() {
+ var mockSetCustomWallpaper = mockController.createFunctionMock(
+ chrome.wallpaperPrivate, 'setCustomWallpaper');
+ mockSetCustomWallpaper.addExpectation(TestConstants.fileString,
+ 'dummy',
+ true,
+ 'dummy');
+ mockSyncFS.addFile('dummy');
+ var syncFSChanges = {};
+ syncFSChanges.status = 'synced';
+ syncFSChanges.direction = 'remote_to_local';
+ syncFSChanges.action = 'added';
+
+ mockSyncFS.root.getFile('dummy', {create:false}, function(fe) {
+ syncFSChanges.fileEntry = fe;
+ chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
bshe 2014/10/27 20:14:51 I think it is probably easier to make "addFile" re
Ran 2014/10/27 22:22:01 Done.
+ }, function(e) {
+ console.error(e);
+ });
+}
+
+// Test store historical custom wallpaper. When receive a historical wallpaper
+// from syncFS, we store it to local.
+function testSyncCustoWallpapermStore() {
+ mockSyncFS.addFile('historicalwallpaper');
+ var syncFSChanges = {};
+ syncFSChanges.status = 'synced';
+ syncFSChanges.direction = 'remote_to_local';
+ syncFSChanges.action = 'added';
+ syncFSChanges.fileEntry = new FileEntry('historicalwallpaper');
+
+ // TODO(ranj): support two callbacks with success and failure?
+ var mockWrite = mockController.createFunctionMock(mockWriter, 'write');
+ mockWrite.addExpectation(new Blob([new Int8Array(TestConstants.fileString)]));
bshe 2014/10/27 20:14:51 Blob probably dont have == operator. would it be p
Ran 2014/10/27 22:22:01 Done.
+ chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
+}
+
+// Test delete custom wallpaper from local. When receive a syncFS delete file
+// event, delete the file in localFS as well.
+function testSyncCustomWallpaperDelete() {
+ var localOriginalPath = Constants.WallpaperDirNameEnum.ORIGINAL + '/' +
+ 'deletewallpapername';
+ var localThumbnailPath = Constants.WallpaperDirNameEnum.THUMBNAIL + '/' +
+ 'deletewallpapername';
+ mockLocalFS.addFile(localThumbnailPath);
+ mockLocalFS.addFile(localOriginalPath);
+ var syncFSChanges = {};
+ syncFSChanges.status = 'synced';
+ syncFSChanges.direction = 'remote_to_local';
+ syncFSChanges.action = 'deleted';
+ syncFSChanges.fileEntry = new FileEntry('deletewallpapername');
+ var originalFE;
+ var thumbnailFE;
+ mockLocalFS.root.getFile(localOriginalPath, {create:false}, function(fe) {
+ originalFE = fe;
+ var mockRemoveOriginal = mockController.createFunctionMock(originalFE,
+ 'remove');
+ mockRemoveOriginal.addExpectation(function() {}, null);
+ }, function(e) {
+ console.error(e);
+ });
+ mockLocalFS.root.getFile(localThumbnailPath, {create:false}, function(fe) {
+ thumbnailFE = fe;
+ var mockRemoveThumbnail = mockController.createFunctionMock(thumbnailFE,
+ 'remove');
+ mockRemoveThumbnail.addExpectation(function() {}, null);
+ }, function(e) {
+ console.error(e);
+ });
+ chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
}
// Test sync online wallpaper. When the synced wallpaper info is not the same as

Powered by Google App Engine
This is Rietveld 408576698