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

Unified Diff: chrome/browser/chromeos/file_system_provider/request_manager_unittest.cc

Issue 241673005: [fsp] Initial implementation of timeout logic for requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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/chromeos/file_system_provider/request_manager_unittest.cc
diff --git a/chrome/browser/chromeos/file_system_provider/request_manager_unittest.cc b/chrome/browser/chromeos/file_system_provider/request_manager_unittest.cc
index 95005fa7839911c93d1448dde5fee5946fa619a4..e92c282fc21150a6bfd08950299604b0abc10b8b 100644
--- a/chrome/browser/chromeos/file_system_provider/request_manager_unittest.cc
+++ b/chrome/browser/chromeos/file_system_provider/request_manager_unittest.cc
@@ -5,13 +5,16 @@
#include <string>
#include "base/bind.h"
+#include "base/callback.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
+#include "base/run_loop.h"
#include "base/values.h"
#include "chrome/browser/chromeos/file_system_provider/request_manager.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
@@ -70,6 +73,15 @@ class EventLogger {
base::WeakPtrFactory<EventLogger> weak_ptr_factory_;
};
+// Handles a request error due to a timeout. Registers the call in the logger
+// via |logger_callback| and quits a RunLoop instance with the |quit_closure|.
+void OnRequestTimeout(base::Callback<void(base::File::Error)> logger_callback,
+ base::Closure quit_closure,
+ base::File::Error error) {
+ logger_callback.Run(error);
+ quit_closure.Run();
+}
+
} // namespace
class FileSystemProviderRequestManagerTest : public testing::Test {
@@ -81,6 +93,7 @@ class FileSystemProviderRequestManagerTest : public testing::Test {
request_manager_.reset(new RequestManager());
}
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<RequestManager> request_manager_;
};
@@ -303,5 +316,26 @@ TEST_F(FileSystemProviderRequestManagerTest, AbortOnDestroy) {
EXPECT_EQ(0u, logger.success_events().size());
}
+TEST_F(FileSystemProviderRequestManagerTest, AbortOnTimeout) {
+ EventLogger logger;
+ base::RunLoop run_loop;
+
+ request_manager_->SetTimeoutForTests(100);
hashimoto 2014/04/18 05:28:09 Can't we use 0 as the timeout? Then you can use Ru
mtomasz 2014/04/18 05:56:18 Good idea. Done.
+ int request_id = request_manager_->CreateRequest(
+ base::Bind(&EventLogger::OnSuccess, logger.GetWeakPtr()),
+ base::Bind(&OnRequestTimeout,
+ base::Bind(&EventLogger::OnError, logger.GetWeakPtr()),
+ run_loop.QuitClosure()));
+ EXPECT_LT(0, request_id);
+
+ // Wait until the request is timeouted. Note, that the entire test case will
+ // timeout if the request never timeouts.
+ run_loop.Run();
+
+ ASSERT_EQ(1u, logger.error_events().size());
+ EventLogger::ErrorEvent* event = logger.error_events()[0];
+ EXPECT_EQ(base::File::FILE_ERROR_ABORT, event->error());
+}
+
} // namespace file_system_provider
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698