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

Unified Diff: chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc

Issue 10836341: Add the basic code skeleton for system info event router (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: update with using std::string.size() instead of strlen Created 8 years, 4 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: 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..18868f7cf778d182dadee6220e3f06ff71a2d046 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,8 +3,11 @@
// 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/browser/extensions/extension_test_message_listener.h"
+#include "chrome/browser/extensions/system_info_event_router.h"
#include "chrome/common/chrome_switches.h"
namespace extensions {
@@ -12,10 +15,17 @@ namespace extensions {
using api::experimental_system_info_storage::StorageInfo;
using api::experimental_system_info_storage::StorageUnitInfo;
+const int kDefaultInterval = 200; // default interval is 200ms.
Mihai Parparita -not on Chrome 2012/08/31 01:01:00 Instead of needing a comment, can you make the con
Hongbo Min 2012/08/31 15:29:53 Done.
+const int kAvailableCapacityBase = 10000;
Mihai Parparita -not on Chrome 2012/08/31 01:01:00 Ditto here (add a "Bytes" suffix to the name) and
Hongbo Min 2012/08/31 15:29:53 Done.
+const int kChangeStep = 10;
+
class MockStorageInfoProvider : public StorageInfoProvider {
public:
- MockStorageInfoProvider() {}
- virtual ~MockStorageInfoProvider() {}
+ MockStorageInfoProvider() : timer_(NULL), is_watching_(false) {
+ }
+ virtual ~MockStorageInfoProvider() {
+ StopWatching();
+ }
virtual bool QueryInfo(StorageInfo* info) OVERRIDE {
info->units.clear();
@@ -30,10 +40,45 @@ 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;
}
+
+ bool StartWatching() {
+ if (is_watching_) return false;
+
+ 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;
+ }
+
+ bool StopWatching() {
+ if (!is_watching_) return false;
+ is_watching_ = false;
+ timer_->Stop();
+ delete timer_;
Mihai Parparita -not on Chrome 2012/08/31 01:01:00 Since you only call StopWatching from the destruct
Hongbo Min 2012/08/31 15:29:53 Done.
+ timer_ = NULL;
+ return true;
+ }
+
+ private:
+ void OnTimeoutEvent() {
+ static int count;
+ SystemInfoEventRouter::GetInstance()->
+ OnStorageAvailableCapacityChanged("/dev/sda1",
+ kAvailableCapacityBase - count * kChangeStep);
+ count++;
+ }
+
+ // Use a repeating timer to emulate storage free space change event.
+ base::RepeatingTimer<MockStorageInfoProvider>* timer_;
+ bool is_watching_;
Mihai Parparita -not on Chrome 2012/08/31 01:01:00 Nit: extra space after bool.
Hongbo Min 2012/08/31 15:29:53 Done.
};
class SystemInfoStorageApiTest: public ExtensionApiTest {
@@ -56,9 +101,14 @@ class SystemInfoStorageApiTest: public ExtensionApiTest {
};
IN_PROC_BROWSER_TEST_F(SystemInfoStorageApiTest, Storage) {
- StorageInfoProvider* provider = new MockStorageInfoProvider();
+ MockStorageInfoProvider* provider = new MockStorageInfoProvider();
StorageInfoProvider::InitializeForTesting(provider);
- ASSERT_TRUE(RunExtensionTest("systeminfo/storage")) << message_;
+
+ ExtensionTestMessageListener listener("ready", true);
+ ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("systeminfo/storage")));
+ EXPECT_TRUE(listener.WaitUntilSatisfied());
+ provider->StartWatching();
+ listener.Reply("go");
}
} // namespace extensions
« no previous file with comments | « no previous file | chrome/browser/extensions/event_names.h » ('j') | chrome/browser/extensions/system_info_event_router.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698