Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / file_manager / unit_tests / navigation_list_model_unittest.js
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.
4
5 function setUp() {
6   // Set up string assets.
7   loadTimeData.data = {
8     DRIVE_DIRECTORY_LABEL: 'My Drive',
9     DOWNLOADS_DIRECTORY_LABEL: 'Downloads'
10   };
11
12   // Override VolumeInfo.prototype.resolveDisplayRoot.
13   VolumeInfo.prototype.resolveDisplayRoot = function() {};
14 }
15
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);
21
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);
26 }
27
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);
33
34   assertEquals(3, model.length);
35
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);
40
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);
47
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);
53
54   // Remove the first shortcut.
55   shortcutListModel.splice(0, 1);
56   assertEquals(3, model.length);
57   assertEquals('/root/shortcut', model.item(2).entry.fullPath);
58 }
59
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);
65
66   assertEquals(3, model.length);
67
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);
76
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);
86
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);
97 }