1 // Copyright 2013 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.
6 // Set up string assets.
8 DRIVE_DIRECTORY_LABEL: 'My Drive',
9 DOWNLOADS_DIRECTORY_LABEL: 'Downloads'
12 // Override VolumeInfo.prototype.resolveDisplayRoot.
13 VolumeInfo.prototype.resolveDisplayRoot = function() {};
16 function testModel() {
17 var volumeManager = new MockVolumeManager();
18 var shortcutListModel = new MockFolderShortcutDataModel(
19 [new MockFileEntry('drive', '/root/shortcut')]);
20 var model = new NavigationListModel(volumeManager, shortcutListModel);
22 assertEquals(3, model.length);
23 assertEquals('drive', model.item(0).volumeInfo.volumeId);
24 assertEquals('downloads', model.item(1).volumeInfo.volumeId);
25 assertEquals('/root/shortcut', model.item(2).entry.fullPath);
28 function testAddAndRemoveShortcuts() {
29 var volumeManager = new MockVolumeManager();
30 var shortcutListModel = new MockFolderShortcutDataModel(
31 [new MockFileEntry('drive', '/root/shortcut')]);
32 var model = new NavigationListModel(volumeManager, shortcutListModel);
34 assertEquals(3, model.length);
36 // Add a shortcut at the tail.
37 shortcutListModel.splice(1, 0, new MockFileEntry('drive', '/root/shortcut2'));
38 assertEquals(4, model.length);
39 assertEquals('/root/shortcut2', model.item(3).entry.fullPath);
41 // Add a shortcut at the head.
42 shortcutListModel.splice(0, 0, new MockFileEntry('drive', '/root/hoge'));
43 assertEquals(5, model.length);
44 assertEquals('/root/hoge', model.item(2).entry.fullPath);
45 assertEquals('/root/shortcut', model.item(3).entry.fullPath);
46 assertEquals('/root/shortcut2', model.item(4).entry.fullPath);
48 // Remove the last shortcut.
49 shortcutListModel.splice(2, 1);
50 assertEquals(4, model.length);
51 assertEquals('/root/hoge', model.item(2).entry.fullPath);
52 assertEquals('/root/shortcut', model.item(3).entry.fullPath);
54 // Remove the first shortcut.
55 shortcutListModel.splice(0, 1);
56 assertEquals(3, model.length);
57 assertEquals('/root/shortcut', model.item(2).entry.fullPath);
60 function testAddAndRemoveVolumes() {
61 var volumeManager = new MockVolumeManager();
62 var shortcutListModel = new MockFolderShortcutDataModel(
63 [new MockFileEntry('drive', '/root/shortcut')]);
64 var model = new NavigationListModel(volumeManager, shortcutListModel);
66 assertEquals(3, model.length);
68 // Removable volume 'hoge' is mounted.
69 volumeManager.volumeInfoList.push(MockVolumeManager.createMockVolumeInfo(
70 VolumeManagerCommon.VolumeType.REMOVABLE, 'removable:hoge'));
71 assertEquals(4, model.length);
72 assertEquals('drive', model.item(0).volumeInfo.volumeId);
73 assertEquals('downloads', model.item(1).volumeInfo.volumeId);
74 assertEquals('removable:hoge', model.item(2).volumeInfo.volumeId);
75 assertEquals('/root/shortcut', model.item(3).entry.fullPath);
77 // Removable volume 'fuga' is mounted.
78 volumeManager.volumeInfoList.push(MockVolumeManager.createMockVolumeInfo(
79 VolumeManagerCommon.VolumeType.REMOVABLE, 'removable:fuga'));
80 assertEquals(5, model.length);
81 assertEquals('drive', model.item(0).volumeInfo.volumeId);
82 assertEquals('downloads', model.item(1).volumeInfo.volumeId);
83 assertEquals('removable:hoge', model.item(2).volumeInfo.volumeId);
84 assertEquals('removable:fuga', model.item(3).volumeInfo.volumeId);
85 assertEquals('/root/shortcut', model.item(4).entry.fullPath);
87 // A shortcut is created on the 'hoge' volume.
88 shortcutListModel.splice(
89 1, 0, new MockFileEntry('removable:hoge', '/shortcut2'));
90 assertEquals(6, model.length);
91 assertEquals('drive', model.item(0).volumeInfo.volumeId);
92 assertEquals('downloads', model.item(1).volumeInfo.volumeId);
93 assertEquals('removable:hoge', model.item(2).volumeInfo.volumeId);
94 assertEquals('removable:fuga', model.item(3).volumeInfo.volumeId);
95 assertEquals('/root/shortcut', model.item(4).entry.fullPath);
96 assertEquals('/shortcut2', model.item(5).entry.fullPath);