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