From fae6bcfce44f32f0a5e3e0f0c29f8aa232bddfda Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 6 Feb 2014 16:30:47 +0000 Subject: [PATCH] Merge revision 1594 changes: - Fix completion status for asynchronous custom resource handler requests (issue #1066, issue #1187). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1750@1598 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- .../stream_resource_handler_unittest.cc | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/unittests/stream_resource_handler_unittest.cc b/tests/unittests/stream_resource_handler_unittest.cc index dd20e9701..3b2143b23 100644 --- a/tests/unittests/stream_resource_handler_unittest.cc +++ b/tests/unittests/stream_resource_handler_unittest.cc @@ -5,11 +5,15 @@ #include #include #include +#include "include/cef_runnable.h" #include "include/cef_stream.h" #include "include/wrapper/cef_stream_resource_handler.h" #include "testing/gtest/include/gtest/gtest.h" #include "tests/unittests/routing_test_handler.h" +// Comment out this define to disable the unit test timeout. +#define TIMEOUT_ENABLED 1 + namespace { const char kTestUrl[] = "http://tests-srh/test.html"; @@ -96,6 +100,12 @@ class ReadTestHandler : public RoutingTestHandler { virtual void RunTest() OVERRIDE { // Create the browser. CreateBrowser(kTestUrl); + +#if defined(TIMEOUT_ENABLED) + // Time out the test after a reasonable period of time. + CefPostDelayedTask(TID_UI, + NewCefRunnableMethod(this, &ReadTestHandler::DestroyTest), 3000); +#endif } virtual CefRefPtr GetResourceHandler( @@ -127,15 +137,31 @@ class ReadTestHandler : public RoutingTestHandler { const int actual_result = atoi(request.ToString().c_str()); EXPECT_EQ(expected_result_, actual_result); - DestroyTest(); + DestroyTestIfDone(); return true; } + virtual void OnLoadingStateChange(CefRefPtr browser, + bool isLoading, + bool canGoBack, + bool canGoForward) OVERRIDE { + if (!isLoading) { + got_on_loading_state_change_done_.yes(); + DestroyTestIfDone(); + } + } + private: + void DestroyTestIfDone() { + if (got_on_query_ && got_on_loading_state_change_done_) + DestroyTest(); + } + virtual void DestroyTest() OVERRIDE { EXPECT_TRUE(got_resource_handler_); EXPECT_TRUE(got_on_query_); + EXPECT_TRUE(got_on_loading_state_change_done_); RoutingTestHandler::DestroyTest(); } @@ -144,6 +170,7 @@ class ReadTestHandler : public RoutingTestHandler { int expected_result_; TrackCallback got_resource_handler_; TrackCallback got_on_query_; + TrackCallback got_on_loading_state_change_done_; }; } // namespace