summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/cros/mock_mount_library.cc
blob: 0f96b1ca7fe9adf611134014108d9248590dc2c7 (plain)
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
// Copyright (c) 2009 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 "chrome/browser/chromeos/cros/mock_mount_library.h"

#include "base/message_loop.h"
#include "base/string_util.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/chromeos/cros/cros_library.h"

namespace chromeos {

using testing::_;
using testing::Invoke;

const char* kTestSystemPath = "/this/system/path";
const char* kTestDevicePath = "/this/device/path";
const char* kTestMountPath = "/media/foofoo";

void MockMountLibrary::AddObserverInternal(MountLibrary::Observer* observer) {
  observers_.AddObserver(observer);
}

void MockMountLibrary::RemoveObserverInternal(MountLibrary::Observer* observer) {
  observers_.RemoveObserver(observer);
}

MockMountLibrary::MockMountLibrary() {
  ON_CALL(*this, AddObserver(_))
      .WillByDefault(Invoke(this, &MockMountLibrary::AddObserverInternal));
  ON_CALL(*this, RemoveObserver(_))
      .WillByDefault(Invoke(this, &MockMountLibrary::RemoveObserverInternal));
  ON_CALL(*this, disks())
      .WillByDefault(Invoke(this, &MockMountLibrary::disksInternal));
}

MockMountLibrary::~MockMountLibrary() {

}

void MockMountLibrary::FireDeviceInsertEvents() {

  disks_.clear();

  disks_.push_back(Disk(kTestDevicePath, "",  kTestSystemPath, false, true));

  // Device Added
  chromeos::MountEventType evt;
  evt = chromeos::DEVICE_ADDED;
  UpdateMountStatus(evt, kTestSystemPath);

  // Disk Added
  evt = chromeos::DISK_ADDED;
  UpdateMountStatus(evt, kTestDevicePath);

  // Disk Changed
  disks_.clear();
  disks_.push_back(Disk(kTestDevicePath, kTestMountPath, kTestSystemPath, false, true));
  evt = chromeos::DISK_CHANGED;
  UpdateMountStatus(evt, kTestDevicePath);
}

void MockMountLibrary::FireDeviceRemoveEvents() {
  disks_.clear();
  chromeos::MountEventType evt;
  evt = chromeos::DISK_REMOVED;
  UpdateMountStatus(evt, kTestDevicePath);
}

void MockMountLibrary::UpdateMountStatus(MountEventType evt,
                                         const std::string& path) {
  // Make sure we run on UI thread.
  DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));

  FOR_EACH_OBSERVER(Observer, observers_, MountChanged(this, evt, path));
}

}  // namespace chromeos