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