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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
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 mockSyncFS.addFile('dummy');
39 var syncFSChanges = {};
40 syncFSChanges.status = 'synced';
41 syncFSChanges.direction = 'remote_to_local';
42 syncFSChanges.action = 'added';
43
44 mockSyncFS.root.getFile('dummy', {create:false}, function(fe) {
45 syncFSChanges.fileEntry = fe;
46 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.
47 }, function(e) {
48 console.error(e);
49 });
50 }
51
52 // Test store historical custom wallpaper. When receive a historical wallpaper
53 // from syncFS, we store it to local.
54 function testSyncCustoWallpapermStore() {
55 mockSyncFS.addFile('historicalwallpaper');
56 var syncFSChanges = {};
57 syncFSChanges.status = 'synced';
58 syncFSChanges.direction = 'remote_to_local';
59 syncFSChanges.action = 'added';
60 syncFSChanges.fileEntry = new FileEntry('historicalwallpaper');
61
62 // TODO(ranj): support two callbacks with success and failure?
63 var mockWrite = mockController.createFunctionMock(mockWriter, 'write');
64 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.
65 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
66 }
67
68 // Test delete custom wallpaper from local. When receive a syncFS delete file
69 // event, delete the file in localFS as well.
70 function testSyncCustomWallpaperDelete() {
71 var localOriginalPath = Constants.WallpaperDirNameEnum.ORIGINAL + '/' +
72 'deletewallpapername';
73 var localThumbnailPath = Constants.WallpaperDirNameEnum.THUMBNAIL + '/' +
74 'deletewallpapername';
75 mockLocalFS.addFile(localThumbnailPath);
76 mockLocalFS.addFile(localOriginalPath);
77 var syncFSChanges = {};
78 syncFSChanges.status = 'synced';
79 syncFSChanges.direction = 'remote_to_local';
80 syncFSChanges.action = 'deleted';
81 syncFSChanges.fileEntry = new FileEntry('deletewallpapername');
82 var originalFE;
83 var thumbnailFE;
84 mockLocalFS.root.getFile(localOriginalPath, {create:false}, function(fe) {
85 originalFE = fe;
86 var mockRemoveOriginal = mockController.createFunctionMock(originalFE,
87 'remove');
88 mockRemoveOriginal.addExpectation(function() {}, null);
89 }, function(e) {
90 console.error(e);
91 });
92 mockLocalFS.root.getFile(localThumbnailPath, {create:false}, function(fe) {
93 thumbnailFE = fe;
94 var mockRemoveThumbnail = mockController.createFunctionMock(thumbnailFE,
95 'remove');
96 mockRemoveThumbnail.addExpectation(function() {}, null);
97 }, function(e) {
98 console.error(e);
99 });
100 chrome.syncFileSystem.onFileStatusChanged.dispatch(syncFSChanges);
17 } 101 }
18 102
19 // Test sync online wallpaper. When the synced wallpaper info is not the same as 103 // 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. 104 // the local wallpaper info, wallpaper should set to the synced one.
21 function testSyncOnlineWallpaper() { 105 function testSyncOnlineWallpaper() {
22 // Setup sync value. 106 // Setup sync value.
23 var changes = {}; 107 var changes = {};
24 changes[Constants.AccessSyncWallpaperInfoKey] = {}; 108 changes[Constants.AccessSyncWallpaperInfoKey] = {};
25 changes[Constants.AccessSyncWallpaperInfoKey].newValue = { 109 changes[Constants.AccessSyncWallpaperInfoKey].newValue = {
26 'url': TestConstants.wallpaperURL, 110 'url': TestConstants.wallpaperURL,
(...skipping 10 matching lines...) Expand all
37 121
38 var mockSetWallpaper = mockController.createFunctionMock( 122 var mockSetWallpaper = mockController.createFunctionMock(
39 chrome.wallpaperPrivate, 'setWallpaper'); 123 chrome.wallpaperPrivate, 'setWallpaper');
40 mockSetWallpaper.addExpectation( 124 mockSetWallpaper.addExpectation(
41 TestConstants.image, 125 TestConstants.image,
42 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout, 126 changes[Constants.AccessSyncWallpaperInfoKey].newValue.layout,
43 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url); 127 changes[Constants.AccessSyncWallpaperInfoKey].newValue.url);
44 128
45 chrome.storage.onChanged.dispatch(changes); 129 chrome.storage.onChanged.dispatch(changes);
46 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698