OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "chrome/browser/chromeos/cros/cros_library.h" | 7 #include "base/stl_util.h" |
8 #include "chrome/browser/chromeos/cros/mock_mount_library.h" | 8 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "webkit/fileapi/file_system_context.h" | 12 #include "webkit/fileapi/file_system_context.h" |
13 #include "webkit/fileapi/file_system_mount_point_provider.h" | 13 #include "webkit/fileapi/file_system_mount_point_provider.h" |
14 #include "webkit/fileapi/file_system_path_manager.h" | 14 #include "webkit/fileapi/file_system_path_manager.h" |
15 | 15 |
16 using ::testing::_; | 16 using ::testing::_; |
17 using ::testing::ReturnRef; | 17 using ::testing::ReturnRef; |
18 using ::testing::StrEq; | 18 using ::testing::StrEq; |
19 | 19 |
20 class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { | 20 class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { |
21 public: | 21 public: |
22 ExtensionFileBrowserPrivateApiTest() : test_mount_point_("/tmp") { | 22 ExtensionFileBrowserPrivateApiTest() |
23 mount_library_mock_.SetupDefaultReplies(); | 23 : disk_mount_manager_mock_(NULL), |
24 | 24 test_mount_point_("/tmp") { |
25 chromeos::CrosLibrary::Get()->GetTestApi()->SetMountLibrary( | |
26 &mount_library_mock_, | |
27 false); // We own the mock library object. | |
28 | |
29 CreateVolumeMap(); | 25 CreateVolumeMap(); |
30 } | 26 } |
31 | 27 |
32 virtual ~ExtensionFileBrowserPrivateApiTest() { | 28 virtual ~ExtensionFileBrowserPrivateApiTest() { |
33 DeleteVolumeMap(); | 29 DCHECK(!disk_mount_manager_mock_); |
34 chromeos::CrosLibrary::Get()->GetTestApi()->SetMountLibrary(NULL, true); | 30 STLDeleteValues(&volumes_); |
| 31 } |
| 32 |
| 33 // ExtensionApiTest override |
| 34 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 35 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 36 |
| 37 disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager; |
| 38 chromeos::disks::DiskMountManager::InitializeForTesting( |
| 39 disk_mount_manager_mock_); |
| 40 disk_mount_manager_mock_->SetupDefaultReplies(); |
| 41 } |
| 42 |
| 43 // ExtensionApiTest override |
| 44 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { |
| 45 chromeos::disks::DiskMountManager::Shutdown(); |
| 46 disk_mount_manager_mock_ = NULL; |
| 47 |
| 48 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); |
35 } | 49 } |
36 | 50 |
37 void AddTmpMountPoint() { | 51 void AddTmpMountPoint() { |
38 fileapi::FileSystemPathManager* path_manager = | 52 fileapi::FileSystemPathManager* path_manager = |
39 browser()->profile()->GetFileSystemContext()->path_manager(); | 53 browser()->profile()->GetFileSystemContext()->path_manager(); |
40 fileapi::ExternalFileSystemMountPointProvider* provider = | 54 fileapi::ExternalFileSystemMountPointProvider* provider = |
41 path_manager->external_provider(); | 55 path_manager->external_provider(); |
42 provider->AddMountPoint(test_mount_point_); | 56 provider->AddMountPoint(test_mount_point_); |
43 } | 57 } |
44 | 58 |
45 private: | 59 private: |
46 void CreateVolumeMap() { | 60 void CreateVolumeMap() { |
47 // These have to be sync'd with values in filebrowser_mount extension. | 61 // These have to be sync'd with values in filebrowser_mount extension. |
48 volumes_.insert( | 62 volumes_.insert( |
49 std::pair<std::string, chromeos::MountLibrary::Disk*>( | 63 std::pair<std::string, chromeos::disks::DiskMountManager::Disk*>( |
50 "device_path1", | 64 "device_path1", |
51 new chromeos::MountLibrary::Disk("device_path1", | 65 new chromeos::disks::DiskMountManager::Disk( |
52 "/media/removable/mount_path1", | 66 "device_path1", |
53 "system_path1", | 67 "/media/removable/mount_path1", |
54 "file_path1", | 68 "system_path1", |
55 "device_label1", | 69 "file_path1", |
56 "drive_label1", | 70 "device_label1", |
57 "parent_path1", | 71 "drive_label1", |
58 "system_path_prefix1", | 72 "system_path_prefix1", |
59 chromeos::FLASH, | 73 chromeos::FLASH, |
60 1073741824, | 74 1073741824, |
61 false, | 75 false, |
62 false, | 76 false, |
63 false, | 77 false, |
64 false, | 78 false, |
65 false))); | 79 false))); |
66 volumes_.insert( | 80 volumes_.insert( |
67 std::pair<std::string, chromeos::MountLibrary::Disk*>( | 81 std::pair<std::string, chromeos::disks::DiskMountManager::Disk*>( |
68 "device_path2", | 82 "device_path2", |
69 new chromeos::MountLibrary::Disk("device_path2", | 83 new chromeos::disks::DiskMountManager::Disk( |
70 "/media/removable/mount_path2", | 84 "device_path2", |
71 "system_path2", | 85 "/media/removable/mount_path2", |
72 "file_path2", | 86 "system_path2", |
73 "device_label2", | 87 "file_path2", |
74 "drive_label2", | 88 "device_label2", |
75 "parent_path2", | 89 "drive_label2", |
76 "system_path_prefix2", | 90 "system_path_prefix2", |
77 chromeos::HDD, | 91 chromeos::HDD, |
78 47723, | 92 47723, |
79 true, | 93 true, |
80 true, | 94 true, |
81 true, | 95 true, |
82 true, | 96 true, |
83 false))); | 97 false))); |
84 volumes_.insert( | 98 volumes_.insert( |
85 std::pair<std::string, chromeos::MountLibrary::Disk*>( | 99 std::pair<std::string, chromeos::disks::DiskMountManager::Disk*>( |
86 "device_path3", | 100 "device_path3", |
87 new chromeos::MountLibrary::Disk("device_path3", | 101 new chromeos::disks::DiskMountManager::Disk( |
88 "/media/removable/mount_path3", | 102 "device_path3", |
89 "system_path3", | 103 "/media/removable/mount_path3", |
90 "file_path3", | 104 "system_path3", |
91 "device_label3", | 105 "file_path3", |
92 "drive_label3", | 106 "device_label3", |
93 "parent_path3", | 107 "drive_label3", |
94 "system_path_prefix3", | 108 "system_path_prefix3", |
95 chromeos::OPTICAL, | 109 chromeos::OPTICAL, |
96 0, | 110 0, |
97 true, | 111 true, |
98 false, | 112 false, |
99 false, | 113 false, |
100 true, | 114 true, |
101 false))); | 115 false))); |
102 } | |
103 | |
104 void DeleteVolumeMap() { | |
105 for (chromeos::MountLibrary::DiskMap::iterator it = volumes_.begin(); | |
106 it != volumes_.end(); | |
107 ++it) { | |
108 delete it->second; | |
109 } | |
110 volumes_.clear(); | |
111 } | 116 } |
112 | 117 |
113 protected: | 118 protected: |
114 chromeos::MockMountLibrary mount_library_mock_; | 119 chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; |
115 chromeos::MountLibrary::DiskMap volumes_; | 120 chromeos::disks::DiskMountManager::DiskMap volumes_; |
116 | 121 |
117 private: | 122 private: |
118 FilePath test_mount_point_; | 123 FilePath test_mount_point_; |
119 }; | 124 }; |
120 | 125 |
121 IN_PROC_BROWSER_TEST_F(ExtensionFileBrowserPrivateApiTest, FileBrowserMount) { | 126 IN_PROC_BROWSER_TEST_F(ExtensionFileBrowserPrivateApiTest, FileBrowserMount) { |
122 // We will call fileBrowserPrivate.unmountVolume once. To test that method, we | 127 // We will call fileBrowserPrivate.unmountVolume once. To test that method, we |
123 // check that UnmountPath is really called with the same value. | 128 // check that UnmountPath is really called with the same value. |
124 AddTmpMountPoint(); | 129 AddTmpMountPoint(); |
125 EXPECT_CALL(mount_library_mock_, UnmountPath(_)) | 130 EXPECT_CALL(*disk_mount_manager_mock_, UnmountPath(_)) |
126 .Times(0); | 131 .Times(0); |
127 EXPECT_CALL(mount_library_mock_, UnmountPath(StrEq("/tmp/test_file.zip"))) | 132 EXPECT_CALL(*disk_mount_manager_mock_, |
128 .Times(1); | 133 UnmountPath(StrEq("/tmp/test_file.zip"))).Times(1); |
129 | 134 |
130 EXPECT_CALL(mount_library_mock_, disks()) | 135 EXPECT_CALL(*disk_mount_manager_mock_, disks()) |
131 .WillRepeatedly(ReturnRef(volumes_)); | 136 .WillRepeatedly(ReturnRef(volumes_)); |
132 | 137 |
133 ASSERT_TRUE(RunComponentExtensionTest("filebrowser_mount")) << message_; | 138 ASSERT_TRUE(RunComponentExtensionTest("filebrowser_mount")) << message_; |
134 } | 139 } |
135 | |
OLD | NEW |