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

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: use event router forwarder instead 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..09284f4c077001cd69447cf92f6498eacc698d1f 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 kDefaultIntervalMs = 200;
+const int kAvailableCapacityBytes = 10000;
+const int kChangeDelta = 10;
+
class MockStorageInfoProvider : public StorageInfoProvider {
public:
- MockStorageInfoProvider() {}
- virtual ~MockStorageInfoProvider() {}
+ MockStorageInfoProvider() : is_watching_(false) {
+ }
+ virtual ~MockStorageInfoProvider() {
+ StopWatching();
+ }
virtual bool QueryInfo(StorageInfo* info) OVERRIDE {
info->units.clear();
@@ -34,6 +44,38 @@ class MockStorageInfoProvider : public StorageInfoProvider {
StorageUnitInfo* info) OVERRIDE {
return false;
}
+
+ bool StartWatching() {
+ if (is_watching_) return false;
+
+ // Start the timer to emulate storage.onChanged event.
+ timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kDefaultIntervalMs),
+ this, &MockStorageInfoProvider::OnTimeoutEvent);
+
+ is_watching_ = true;
+ return true;
+ }
+
+ bool StopWatching() {
+ if (!is_watching_) return false;
+ is_watching_ = false;
+ timer_.Stop();
+ return true;
+ }
+
+ private:
+ void OnTimeoutEvent() {
+ static int count;
+ SystemInfoEventRouter::GetInstance()->
+ OnStorageAvailableCapacityChanged("/dev/sda1",
+ kAvailableCapacityBytes - count * kChangeDelta);
+ count++;
+ }
+
+ // Use a repeating timer to emulate storage free space change event.
+ base::RepeatingTimer<MockStorageInfoProvider> timer_;
+ bool is_watching_;
};
class SystemInfoStorageApiTest: public ExtensionApiTest {
@@ -56,9 +98,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