Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1908)

Unified Diff: base/system_monitor/system_monitor_unittest.cc

Issue 10917166: Extend the capability of SystemMonitor to support watching storage free space change (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update and add unit test Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/system_monitor/system_monitor_unittest.cc
diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/system_monitor/system_monitor_unittest.cc
index feff9740797dce70bc01ea0f59a68f123b359a64..79c48cbc2f91f55e7c60e441ab419e951118b23c 100644
--- a/base/system_monitor/system_monitor_unittest.cc
+++ b/base/system_monitor/system_monitor_unittest.cc
@@ -47,6 +47,28 @@ class PowerTest : public SystemMonitor::PowerObserver {
int resumes_; // Count of OnResume notifications.
};
+class MockStorageFreeSpaceDelegateTest
+ : public SystemMonitor::StorageFreeSpaceDelegate {
+ public:
+ MockStorageFreeSpaceDelegateTest() {}
+ virtual ~MockStorageFreeSpaceDelegateTest() {}
+ MOCK_METHOD1(StartWatchingStorage, void(const FilePath& path));
+ MOCK_METHOD1(StopWatchingStorage, void(const FilePath& path));
+ DISALLOW_COPY_AND_ASSIGN(MockStorageFreeSpaceDelegateTest);
+};
+
+class MockStorageFreeSpaceObserver
+ : public SystemMonitor::StorageFreeSpaceObserver {
+ public:
+ MockStorageFreeSpaceObserver() {}
+ virtual ~MockStorageFreeSpaceObserver() {}
+ MOCK_METHOD2(OnFreeSpaceChanged,
+ void(const FilePath& path, int64 available_bytes));
+ MOCK_METHOD1(OnFreeSpaceChangeError,
+ void(const FilePath& path));
+ DISALLOW_COPY_AND_ASSIGN(MockStorageFreeSpaceObserver);
+};
+
class SystemMonitorTest : public testing::Test {
protected:
SystemMonitorTest() {
@@ -54,12 +76,13 @@ class SystemMonitorTest : public testing::Test {
// This needs to happen before SystemMonitor's ctor.
SystemMonitor::AllocateSystemIOPorts();
#endif
- system_monitor_.reset(new SystemMonitor);
+ system_monitor_.reset(new SystemMonitor(&delegate_test_));
}
virtual ~SystemMonitorTest() {}
MessageLoop message_loop_;
scoped_ptr<SystemMonitor> system_monitor_;
+ MockStorageFreeSpaceDelegateTest delegate_test_;
DISALLOW_COPY_AND_ASSIGN(SystemMonitorTest);
};
@@ -197,6 +220,67 @@ TEST_F(SystemMonitorTest, GetAttachedRemovableStorageAttachDetach) {
EXPECT_EQ(0U, devices.size());
}
+TEST_F(SystemMonitorTest, StorageFreeSpaceChangedNotification) {
+ const int kObservers = 3;
+ const FilePath kFilePath(FILE_PATH_LITERAL("one"));
+ const FilePath kInvalidFilePath(FILE_PATH_LITERAL("invalid_path"));
+
+ testing::Sequence mock_sequencer[kObservers], seq;
+ MockStorageFreeSpaceObserver observers[kObservers];
+
+ EXPECT_CALL(delegate_test_,
+ StartWatchingStorage(kFilePath))
+ .Times(1).InSequence(seq);
+ EXPECT_CALL(delegate_test_,
+ StartWatchingStorage(kInvalidFilePath))
+ .Times(1).InSequence(seq);
+ EXPECT_CALL(delegate_test_,
+ StopWatchingStorage(kFilePath))
+ .Times(1).InSequence(seq);
+ EXPECT_CALL(delegate_test_,
+ StopWatchingStorage(kInvalidFilePath))
+ .Times(0).InSequence(seq);
+
+ for (int i = 0; i < kObservers - 1; ++i) {
+ EXPECT_CALL(observers[i],
+ OnFreeSpaceChanged(kFilePath, 1000))
+ .Times(1).InSequence(mock_sequencer[i]);
+ EXPECT_CALL(observers[i],
+ OnFreeSpaceChanged(kFilePath, 2000))
+ .Times(1).InSequence(mock_sequencer[i]);
+ EXPECT_CALL(observers[i],
+ OnFreeSpaceChangeError(kFilePath))
+ .Times(0).InSequence(mock_sequencer[i]);
+ }
+ EXPECT_CALL(observers[kObservers - 1],
+ OnFreeSpaceChangeError(kInvalidFilePath))
+ .Times(1).InSequence(mock_sequencer[kObservers - 1]);
+ EXPECT_CALL(observers[0],
+ OnFreeSpaceChanged(kFilePath, 3000))
+ .Times(1).InSequence(mock_sequencer[kObservers - 1]);
+ EXPECT_CALL(observers[1],
+ OnFreeSpaceChanged(kFilePath, 3000))
+ .Times(0).InSequence(mock_sequencer[kObservers - 1]);
+
+ system_monitor_->AddStorageFreeSpaceObserver(kFilePath, &observers[0]);
+ system_monitor_->AddStorageFreeSpaceObserver(kFilePath, &observers[1]);
+
+ system_monitor_->ProcessStorageFreeSpaceChanged(kFilePath, 1000);
+ system_monitor_->ProcessStorageFreeSpaceChanged(kFilePath, 2000);
+ message_loop_.RunAllPending();
+
+ system_monitor_->AddStorageFreeSpaceObserver(kInvalidFilePath, &observers[2]);
+ system_monitor_->ProcessStorageFreeSpaceChangeError(kInvalidFilePath);
+ message_loop_.RunAllPending();
+
+ system_monitor_->RemoveStorageFreeSpaceObserver(kFilePath, &observers[1]);
+ system_monitor_->ProcessStorageFreeSpaceChanged(kFilePath, 3000);
+ message_loop_.RunAllPending();
+
+ system_monitor_->RemoveStorageFreeSpaceObserver(kFilePath, &observers[0]);
+ message_loop_.RunAllPending();
+}
+
} // namespace
} // namespace base
« no previous file with comments | « base/system_monitor/system_monitor.cc ('k') | chrome/browser/system_monitor/removable_device_notifications_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698