summaryrefslogtreecommitdiffstats
path: root/webkit/glue/resource_fetcher_unittest.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-07 23:35:26 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-07 23:35:26 +0000
commit19ef18a1027eaa9eb95bc89bf7fb27c102a24c16 (patch)
tree4f1286f431a970b73551552ec6fe9d4b15d3e746 /webkit/glue/resource_fetcher_unittest.cc
parent796f48504671973b239858cc619375c662692783 (diff)
downloadchromium_src-19ef18a1027eaa9eb95bc89bf7fb27c102a24c16.zip
chromium_src-19ef18a1027eaa9eb95bc89bf7fb27c102a24c16.tar.gz
chromium_src-19ef18a1027eaa9eb95bc89bf7fb27c102a24c16.tar.bz2
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
Diffstat (limited to 'webkit/glue/resource_fetcher_unittest.cc')
-rw-r--r--webkit/glue/resource_fetcher_unittest.cc49
1 files changed, 39 insertions, 10 deletions
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 <gtk/gtk.h>
+#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_;