| Index: chrome/browser/extensions/api/system_info_storage/storage_info_provider_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/system_info_storage/storage_info_provider_unittest.cc b/chrome/browser/extensions/api/system_info_storage/storage_info_provider_unittest.cc
|
| index 3575bec33fccf74fda539d5fb9c6c53f1620c4a0..7d959804d6581045de60b8011b153a4dfc6555a1 100644
|
| --- a/chrome/browser/extensions/api/system_info_storage/storage_info_provider_unittest.cc
|
| +++ b/chrome/browser/extensions/api/system_info_storage/storage_info_provider_unittest.cc
|
| @@ -26,28 +26,29 @@ struct TestUnitInfo {
|
| std::string type;
|
| double capacity;
|
| double available_capacity;
|
| + int threshold;
|
| // The change step of free space.
|
| int change_step;
|
| };
|
|
|
| struct TestUnitInfo testing_data[] = {
|
| - {"C:", "unknown", 1000, 10, 0},
|
| - {"d:", "removable", 2000, 10, 1 },
|
| - {"/home","harddisk", 3000, 10, 2},
|
| - {"/", "removable", 4000, 10, 3}
|
| + {"C:", "unknown", 1000, 10, 1, 0},
|
| + {"d:", "removable", 2000, 10, 2, 3 },
|
| + {"/home","harddisk", 3000, 10, 2, 2},
|
| + {"/", "removable", 4000, 10, 1, 3}
|
| };
|
|
|
| // The watching interval for unit test is 1 milliseconds.
|
| const unsigned int kWatchingIntervalMs = 1u;
|
| const int kCallTimes = 3;
|
|
|
| -class MockStorageObserver : public StorageInfoProvider::Observer {
|
| +class MockStorageObserver : public StorageInfoObserver {
|
| public:
|
| MockStorageObserver() {}
|
| virtual ~MockStorageObserver() {}
|
|
|
| - MOCK_METHOD3(OnStorageFreeSpaceChanged, void(const std::string&,
|
| - double, double));
|
| + MOCK_METHOD4(OnStorageFreeSpaceChanged, void(const std::string&,
|
| + double, double, int));
|
|
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(MockStorageObserver);
|
| @@ -155,42 +156,72 @@ void StorageInfoProviderTest::ResetTestingData() {
|
|
|
| TEST_F(StorageInfoProviderTest, WatchingNoChangedStorage) {
|
| // Case 1: watching a storage that the free space is not changed.
|
| - StorageInfoProvider::Get()->StartWatching(testing_data[0].id);
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(testing_data[0].id, _, _))
|
| + StorageInfoProvider::Get()->StartWatching(testing_data[0].id,
|
| + testing_data[0].threshold);
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[0].id, _, _, _))
|
| .Times(0);
|
| RunMessageLoopUntilTimeout(10 * kWatchingIntervalMs);
|
| - StorageInfoProvider::Get()->StopWatching(testing_data[0].id);
|
| + StorageInfoProvider::Get()->StopWatching(testing_data[0].id,
|
| + testing_data[0].threshold);
|
| RunMessageLoopUntilIdle();
|
| }
|
|
|
| TEST_F(StorageInfoProviderTest, WatchingOneStorage) {
|
| // Case 2: only watching one storage.
|
| - StorageInfoProvider::Get()->StartWatching(testing_data[1].id);
|
| + StorageInfoProvider::Get()->StartWatching(testing_data[1].id,
|
| + testing_data[1].threshold);
|
| RunMessageLoopUntilIdle();
|
|
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(testing_data[1].id, _, _))
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[1].id, _, _, _))
|
| .WillRepeatedly(Return());
|
| double base_value = testing_data[1].available_capacity;
|
| int step = testing_data[1].change_step;
|
| for (int i = 0; i < kCallTimes; i++) {
|
| double expected_old_value = base_value + i * step;
|
| double expected_new_value = base_value + (i + 1) * step;
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(testing_data[1].id,
|
| - expected_old_value, expected_new_value)).WillOnce(Return());
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[1].id,
|
| + expected_old_value,
|
| + expected_new_value,
|
| + testing_data[1].threshold))
|
| + .WillOnce(Return());
|
| }
|
| // The other storages won't get free space change notification.
|
| for (size_t i = 2; i < arraysize(testing_data); ++i) {
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(testing_data[i].id, _, _))
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[i].id, _, _, _))
|
| .Times(0);
|
| }
|
| RunMessageLoopUntilTimeout(100 * kWatchingIntervalMs);
|
|
|
| - StorageInfoProvider::Get()->StopWatching(testing_data[1].id);
|
| + // Watching it again.
|
| + StorageInfoProvider::Get()->StartWatching(testing_data[1].id,
|
| + testing_data[1].threshold);
|
| + RunMessageLoopUntilIdle();
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[1].id, _, _, _))
|
| + .WillRepeatedly(Return());
|
| + for (int i = 0; i < kCallTimes; i++) {
|
| + double expected_old_value = base_value + i * step;
|
| + double expected_new_value = base_value + (i + 1) * step;
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[1].id,
|
| + expected_old_value,
|
| + expected_new_value,
|
| + testing_data[1].threshold))
|
| + .WillOnce(Return());
|
| + }
|
| + RunMessageLoopUntilTimeout(100 * kWatchingIntervalMs);
|
| +
|
| + StorageInfoProvider::Get()->StopWatching(testing_data[1].id,
|
| + testing_data[1].threshold);
|
| RunMessageLoopUntilIdle();
|
| // The watched storage won't get free space change notification after
|
| // stopping.
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(testing_data[1].id, _, _))
|
| - .Times(0);
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[1].id, _, _, _)).Times(0);
|
| RunMessageLoopUntilIdle();
|
| }
|
|
|
| @@ -198,54 +229,73 @@ TEST_F(StorageInfoProviderTest, WatchingMultipleStorages) {
|
| // Case 2: watching multiple storages. We ignore the first entry in
|
| // |testing_data| since its change_step is zero.
|
| for (size_t k = 1; k < arraysize(testing_data); ++k) {
|
| - StorageInfoProvider::Get()->StartWatching(testing_data[k].id);
|
| + StorageInfoProvider::Get()->StartWatching(testing_data[k].id,
|
| + testing_data[k].threshold);
|
| }
|
| // Run the message loop to given a chance for storage info provider to start
|
| // watching.
|
| RunMessageLoopUntilIdle();
|
|
|
| for (size_t k = 1; k < arraysize(testing_data); ++k) {
|
| - EXPECT_CALL(observer(),
|
| - OnStorageFreeSpaceChanged(testing_data[k].id, _, _))
|
| - .WillRepeatedly(Return());
|
| -
|
| - double base_value = testing_data[k].available_capacity;
|
| - int step = testing_data[k].change_step;
|
| - for (int i = 0; i < kCallTimes; i++) {
|
| - double expected_old_value = base_value + i * step;
|
| - double expected_new_value = base_value + (i + 1) * step;
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(testing_data[k].id,
|
| - expected_old_value, expected_new_value)).WillOnce(Return());
|
| + if (testing_data[k].threshold <= testing_data[k].change_step) {
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[k].id, _, _, _))
|
| + .WillRepeatedly(Return());
|
| + double base_value = testing_data[k].available_capacity;
|
| + int step = testing_data[k].change_step;
|
| + for (int i = 0; i < kCallTimes; i++) {
|
| + double expected_old_value = base_value + i * step;
|
| + double expected_new_value = base_value + (i + 1) * step;
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[k].id,
|
| + expected_old_value,
|
| + expected_new_value,
|
| + testing_data[k].threshold))
|
| + .WillOnce(Return());
|
| + }
|
| + } else {
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[k].id, _, _, _)).Times(0);
|
| }
|
| }
|
| RunMessageLoopUntilTimeout(100 * kWatchingIntervalMs);
|
|
|
| // Stop watching the first storage.
|
| - StorageInfoProvider::Get()->StopWatching(testing_data[1].id);
|
| + StorageInfoProvider::Get()->StopWatching(testing_data[1].id,
|
| + testing_data[1].threshold);
|
| RunMessageLoopUntilIdle();
|
|
|
| for (size_t k = 2; k < arraysize(testing_data); ++k) {
|
| - EXPECT_CALL(observer(),
|
| - OnStorageFreeSpaceChanged(testing_data[k].id, _, _))
|
| - .WillRepeatedly(Return());
|
| -
|
| - double base_value = testing_data[k].available_capacity;
|
| - int step = testing_data[k].change_step;
|
| - for (int i = 0; i < kCallTimes; i++) {
|
| - double expected_old_value = base_value + i * step;
|
| - double expected_new_value = base_value + (i + 1) * step;
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(testing_data[k].id,
|
| - expected_old_value, expected_new_value)).WillOnce(Return());
|
| + if (testing_data[k].threshold <= testing_data[k].change_step) {
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[k].id, _, _, _))
|
| + .WillRepeatedly(Return());
|
| + double base_value = testing_data[k].available_capacity;
|
| + int step = testing_data[k].change_step;
|
| + for (int i = 0; i < kCallTimes; i++) {
|
| + double expected_old_value = base_value + i * step;
|
| + double expected_new_value = base_value + (i + 1) * step;
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[k].id,
|
| + expected_old_value,
|
| + expected_new_value,
|
| + testing_data[k].threshold))
|
| + .WillOnce(Return());
|
| + }
|
| + } else {
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[k].id, _, _, _)).Times(0);
|
| }
|
| }
|
| // After stopping watching, the callback won't get called.
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(testing_data[1].id, _, _))
|
| - .Times(0);
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[1].id, _, _, _)).Times(0);
|
| RunMessageLoopUntilTimeout(100 * kWatchingIntervalMs);
|
|
|
| // Stop watching all storages.
|
| for (size_t k = 1; k < arraysize(testing_data); ++k) {
|
| - StorageInfoProvider::Get()->StopWatching(testing_data[k].id);
|
| + StorageInfoProvider::Get()->StopWatching(testing_data[k].id,
|
| + testing_data[k].threshold);
|
| }
|
| // Run the message loop to given a chance for storage info provider to stop
|
| // watching.
|
| @@ -253,8 +303,8 @@ TEST_F(StorageInfoProviderTest, WatchingMultipleStorages) {
|
|
|
| // After stopping watching, the callback won't get called.
|
| for (size_t k = 1; k < arraysize(testing_data); ++k) {
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(testing_data[k].id, _, _))
|
| - .Times(0);
|
| + EXPECT_CALL(observer(),
|
| + OnStorageFreeSpaceChanged(testing_data[k].id, _, _, _)).Times(0);
|
| }
|
| RunMessageLoopUntilIdle();
|
| }
|
| @@ -262,11 +312,11 @@ TEST_F(StorageInfoProviderTest, WatchingMultipleStorages) {
|
| TEST_F(StorageInfoProviderTest, WatchingInvalidStorage) {
|
| // Case 3: watching an invalid storage.
|
| std::string invalid_id("invalid_id");
|
| - StorageInfoProvider::Get()->StartWatching(invalid_id);
|
| - EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(invalid_id, _, _))
|
| + StorageInfoProvider::Get()->StartWatching(invalid_id, 10);
|
| + EXPECT_CALL(observer(), OnStorageFreeSpaceChanged(invalid_id, _, _, _))
|
| .Times(0);
|
| RunMessageLoopUntilTimeout(10 * kWatchingIntervalMs);
|
| - StorageInfoProvider::Get()->StopWatching(invalid_id);
|
| + StorageInfoProvider::Get()->StopWatching(invalid_id, 10);
|
| RunMessageLoopUntilIdle();
|
| }
|
|
|
|
|