From 19ef18a1027eaa9eb95bc89bf7fb27c102a24c16 Mon Sep 17 00:00:00 2001 From: "estade@chromium.org" Date: Fri, 7 Nov 2008 23:35:26 +0000 Subject: Port a resource fetcher test shell test to linux. Review URL: http://codereview.chromium.org/9701 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5034 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/resource_fetcher_unittest.cc | 49 +++++++++++++++++++++++++------- webkit/tools/test_shell/SConscript | 2 +- 2 files changed, 40 insertions(+), 11 deletions(-) (limited to 'webkit') diff --git a/webkit/glue/resource_fetcher_unittest.cc b/webkit/glue/resource_fetcher_unittest.cc index 86ec091..cad4bbc 100644 --- a/webkit/glue/resource_fetcher_unittest.cc +++ b/webkit/glue/resource_fetcher_unittest.cc @@ -11,6 +11,10 @@ MSVC_PUSH_WARNING_LEVEL(0); MSVC_POP_WARNING(); #undef LOG +#if defined(OS_LINUX) +#include +#endif + #include "webkit/glue/unittest_test_server.h" #include "webkit/glue/webview.h" #include "webkit/glue/webframe_impl.h" @@ -22,7 +26,6 @@ using WebCore::ResourceResponse; namespace { - class ResourceFetcherTests : public TestShellTest { public: void SetUp() { @@ -43,16 +46,15 @@ class FetcherDelegate : public ResourceFetcher::Delegate { // Start a repeating timer waiting for the download to complete. The // callback has to be a static function, so we hold on to our instance. FetcherDelegate::instance_ = this; - timer_id_ = SetTimer(NULL, NULL, kWaitIntervalMs, - &FetcherDelegate::TimerCallback); + CreateTimer(kWaitIntervalMs); } - + virtual void OnURLFetchComplete(const ResourceResponse& response, const std::string& data) { response_ = response; data_ = data; completed_ = true; - KillTimer(NULL, timer_id_); + DestroyTimer(); MessageLoop::current()->Quit(); } @@ -71,18 +73,41 @@ class FetcherDelegate : public ResourceFetcher::Delegate { MessageLoop::current()->Run(); } + void CreateTimer(int interval) { +#if defined(OS_WIN) + timer_id_ = ::SetTimer(NULL, NULL, interval, + &FetcherDelegate::TimerCallback); +#elif defined(OS_LINUX) + timer_id_ = g_timeout_add(interval, &FetcherDelegate::TimerCallback, NULL); +#endif + } + + void DestroyTimer() { +#if defined(OS_WIN) + ::KillTimer(NULL, timer_id_); +#elif defined(OS_LINUX) + g_source_remove(timer_id_); +#endif + } + +#if defined(OS_WIN) // Static timer callback, just passes through to instance version. static VOID CALLBACK TimerCallback(HWND hwnd, UINT msg, UINT_PTR timer_id, DWORD ms) { - instance_->TimerFired(hwnd, timer_id); + instance_->TimerFired(); } - - void TimerFired(HWND hwnd, UINT_PTR timer_id) { +#elif defined(OS_LINUX) + static gboolean TimerCallback(gpointer data) { + instance_->TimerFired(); + return true; + } +#endif + + void TimerFired() { ASSERT_FALSE(completed_); if (timed_out()) { - printf("timer fired\n"); - KillTimer(hwnd, timer_id); + DestroyTimer(); MessageLoop::current()->Quit(); FAIL() << "fetch timed out"; return; @@ -94,7 +119,11 @@ class FetcherDelegate : public ResourceFetcher::Delegate { static FetcherDelegate* instance_; private: +#if defined(OS_WIN) UINT_PTR timer_id_; +#elif defined(OS_LINUX) + guint timer_id_; +#endif bool completed_; int time_elapsed_ms_; ResourceResponse response_; diff --git a/webkit/tools/test_shell/SConscript b/webkit/tools/test_shell/SConscript index 4182d4e..a3764f9 100644 --- a/webkit/tools/test_shell/SConscript +++ b/webkit/tools/test_shell/SConscript @@ -170,6 +170,7 @@ test_files = [ '$WEBKIT_DIR/glue/multipart_response_delegate_unittest.cc', '$WEBKIT_DIR/glue/password_autocomplete_listener_unittest.cc', '$WEBKIT_DIR/glue/regular_expression_unittest.cc', + '$WEBKIT_DIR/glue/resource_fetcher_unittest.cc', '$WEBKIT_DIR/glue/webframe_unittest.cc', '$WEBKIT_DIR/port/platform/GKURL_unittest.cpp', '$V8_DIR/snapshot-empty$OBJSUFFIX', @@ -182,7 +183,6 @@ if env['PLATFORM'] == 'win32': 'text_input_controller_unittest.cc', '$WEBKIT_DIR/glue/context_menu_unittest.cc', '$WEBKIT_DIR/glue/mimetype_unittest.cc', - '$WEBKIT_DIR/glue/resource_fetcher_unittest.cc', # Commented out until a regression is fixed and this file is restored. #'$WEBKIT_DIR/glue/stringimpl_unittest.cc', '$WEBKIT_DIR/glue/webplugin_impl_unittest.cc', -- cgit v1.1