1 // Copyright (c) 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.
5 #include "chrome/browser/chromeos/file_manager/mount_test_util.h"
7 #include "base/run_loop.h"
8 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
10 namespace file_manager
{
15 // Helper class used to wait for |OnFileSystemMounted| event from a drive file
17 class DriveMountPointWaiter
: public drive::DriveIntegrationServiceObserver
{
19 explicit DriveMountPointWaiter(
20 drive::DriveIntegrationService
* integration_service
)
21 : integration_service_(integration_service
) {
22 integration_service_
->AddObserver(this);
25 ~DriveMountPointWaiter() override
{
26 integration_service_
->RemoveObserver(this);
29 // DriveIntegrationServiceObserver override.
30 void OnFileSystemMounted() override
{
31 // Note that it is OK for |run_loop_.Quit| to be called before
32 // |run_loop_.Run|. In this case |Run| will return immediately.
36 // Runs loop until the file system is mounted.
42 drive::DriveIntegrationService
* integration_service_
;
43 base::RunLoop run_loop_
;
48 void WaitUntilDriveMountPointIsAdded(Profile
* profile
) {
51 // Drive mount point is added by the browser when the drive system service
52 // is first initialized. It is done asynchronously after some other parts of
53 // the service are initialized (e.g. resource metadata and cache), thus racy
54 // with the test start. To handle this raciness, the test verifies that
55 // drive mount point is added before continuing. If this is not the case,
56 // drive file system is observed for FileSystemMounted event (by
57 // |mount_point_waiter|) and test continues once the event is encountered.
58 drive::DriveIntegrationService
* integration_service
=
59 drive::DriveIntegrationServiceFactory::FindForProfile(profile
);
60 DCHECK(integration_service
);
61 DCHECK(integration_service
->is_enabled());
63 if (integration_service
->IsMounted())
66 DriveMountPointWaiter
mount_point_waiter(integration_service
);
67 VLOG(1) << "Waiting for drive mount point to get mounted.";
68 mount_point_waiter
.Wait();
69 VLOG(1) << "Drive mount point found.";
72 } // namespace test_util
73 } // namespace file_manager