Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_manager / drive_test_util.cc
blobb0c6692aa605a1e90db10a3288eb0fbadec6e386
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/drive_test_util.h"
7 #include "base/files/file_path.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_context.h"
12 #include "webkit/browser/fileapi/external_mount_points.h"
14 namespace file_manager {
15 namespace test_util {
17 namespace {
19 // Helper class used to wait for |OnFileSystemMounted| event from a drive file
20 // system.
21 class DriveMountPointWaiter : public drive::DriveIntegrationServiceObserver {
22 public:
23 explicit DriveMountPointWaiter(
24 drive::DriveIntegrationService* integration_service)
25 : integration_service_(integration_service) {
26 integration_service_->AddObserver(this);
29 virtual ~DriveMountPointWaiter() {
30 integration_service_->RemoveObserver(this);
33 // DriveIntegrationServiceObserver override.
34 virtual void OnFileSystemMounted() OVERRIDE {
35 // Note that it is OK for |run_loop_.Quit| to be called before
36 // |run_loop_.Run|. In this case |Run| will return immediately.
37 run_loop_.Quit();
40 // Runs loop until the file system is mounted.
41 void Wait() {
42 run_loop_.Run();
45 private:
46 drive::DriveIntegrationService* integration_service_;
47 base::RunLoop run_loop_;
50 } // namespace
52 void WaitUntilDriveMountPointIsAdded(Profile* profile) {
53 DCHECK(profile);
55 // Drive mount point is added by the browser when the drive system service
56 // is first initialized. It is done asynchronously after some other parts of
57 // the service are initialized (e.g. resource metadata and cache), thus racy
58 // with the test start. To handle this raciness, the test verifies that
59 // drive mount point is added before continuing. If this is not the case,
60 // drive file system is observed for FileSystemMounted event (by
61 // |mount_point_waiter|) and test continues once the event is encountered.
62 drive::DriveIntegrationService* integration_service =
63 drive::DriveIntegrationServiceFactory::FindForProfileRegardlessOfStates(
64 profile);
65 DCHECK(integration_service);
66 DCHECK(integration_service->is_enabled());
68 if (integration_service->IsMounted())
69 return;
71 DriveMountPointWaiter mount_point_waiter(integration_service);
72 VLOG(1) << "Waiting for drive mount point to get mounted.";
73 mount_point_waiter.Wait();
74 VLOG(1) << "Drive mount point found.";
77 } // namespace test_util
78 } // namespace file_manager