| Index: chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc
|
| diff --git a/chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc b/chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc
|
| index 9d467065b64c6b7c75ad9e932199b5b5a417ae2d..12dca8182d45aa3288617c757daa680c281cb3f7 100644
|
| --- a/chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc
|
| +++ b/chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc
|
| @@ -3,6 +3,7 @@
|
| // found in the LICENSE file.
|
| #include "base/command_line.h"
|
| #include "base/message_loop.h"
|
| +#include "base/timer.h"
|
| #include "chrome/browser/extensions/api/system_info_storage/storage_info_provider.h"
|
| #include "chrome/browser/extensions/extension_apitest.h"
|
| #include "chrome/common/chrome_switches.h"
|
| @@ -12,9 +13,13 @@ namespace extensions {
|
| using api::experimental_system_info_storage::StorageInfo;
|
| using api::experimental_system_info_storage::StorageUnitInfo;
|
|
|
| +const int kDefaultInterval = 200; // default interval is 200ms.
|
| +const int kAvailableCapacityBase = 10000;
|
| +const int kChangeStep = 10;
|
| +
|
| class MockStorageInfoProvider : public StorageInfoProvider {
|
| public:
|
| - MockStorageInfoProvider() {}
|
| + MockStorageInfoProvider() : timer_(NULL) {}
|
| virtual ~MockStorageInfoProvider() {}
|
|
|
| virtual bool QueryInfo(StorageInfo* info) OVERRIDE {
|
| @@ -30,10 +35,46 @@ class MockStorageInfoProvider : public StorageInfoProvider {
|
| return true;
|
| }
|
|
|
| - virtual bool QueryUnitInfo(const std::string& id,
|
| + virtual bool QueryUnitInfo(const FilePath::StringType& path,
|
| StorageUnitInfo* info) OVERRIDE {
|
| return false;
|
| }
|
| +
|
| + virtual bool PlatformStartWatching(Delegate* delegate) OVERRIDE{
|
| + if (is_watching_) return false;
|
| +
|
| + delegate_ = delegate;
|
| + timer_ = new base::RepeatingTimer<MockStorageInfoProvider>();
|
| + // Start the timer to emulate storage.onChanged event.
|
| + timer_->Start(FROM_HERE,
|
| + base::TimeDelta::FromMilliseconds(kDefaultInterval),
|
| + this, &MockStorageInfoProvider::OnTimeoutEvent);
|
| +
|
| + is_watching_ = true;
|
| + return true;
|
| + }
|
| +
|
| + virtual bool PlatformStopWatching() OVERRIDE {
|
| + if (!is_watching_) return false;
|
| + is_watching_ = false;
|
| + timer_->Stop();
|
| + delete timer_;
|
| + timer_ = NULL;
|
| + return true;
|
| + }
|
| +
|
| + private:
|
| + void OnTimeoutEvent() {
|
| + static int count = 0;
|
| + if (delegate_) {
|
| + delegate_->OnStorageDeviceAvailableCapacityChanged(
|
| + "/dev/sda1", kAvailableCapacityBase - kChangeStep*count);
|
| + count++;
|
| + }
|
| + }
|
| +
|
| + // Use a repeating timer to emulate storage free space change event.
|
| + base::RepeatingTimer<MockStorageInfoProvider>* timer_;
|
| };
|
|
|
| class SystemInfoStorageApiTest: public ExtensionApiTest {
|
|
|