OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if defined(OS_LINUX) | 5 #include "webkit/glue/resource_fetcher.h" |
6 #include <gtk/gtk.h> | |
7 #endif | |
8 | 6 |
9 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 7 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" | 8 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
11 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
12 #include "webkit/glue/unittest_test_server.h" | 10 #include "webkit/glue/unittest_test_server.h" |
13 #include "webkit/glue/resource_fetcher.h" | |
14 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 11 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
15 #include "webkit/tools/test_shell/test_shell_test.h" | 12 #include "webkit/tools/test_shell/test_shell_test.h" |
16 | 13 |
| 14 #if defined(TOOLKIT_USES_GTK) |
| 15 #include <gtk/gtk.h> |
| 16 #endif |
| 17 |
17 using WebKit::WebFrame; | 18 using WebKit::WebFrame; |
18 using WebKit::WebURLResponse; | 19 using WebKit::WebURLResponse; |
19 using webkit_glue::ResourceFetcher; | 20 using webkit_glue::ResourceFetcher; |
20 using webkit_glue::ResourceFetcherWithTimeout; | 21 using webkit_glue::ResourceFetcherWithTimeout; |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 class ResourceFetcherTests : public TestShellTest { | 25 class ResourceFetcherTests : public TestShellTest { |
25 public: | 26 public: |
26 void SetUp() { | 27 void SetUp() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // MessageLoop's Quit method. | 70 // MessageLoop's Quit method. |
70 void WaitForResponse() { | 71 void WaitForResponse() { |
71 while (!completed() && !timed_out()) | 72 while (!completed() && !timed_out()) |
72 MessageLoop::current()->Run(); | 73 MessageLoop::current()->Run(); |
73 } | 74 } |
74 | 75 |
75 void CreateTimer(int interval) { | 76 void CreateTimer(int interval) { |
76 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
77 timer_id_ = ::SetTimer(NULL, NULL, interval, | 78 timer_id_ = ::SetTimer(NULL, NULL, interval, |
78 &FetcherDelegate::TimerCallback); | 79 &FetcherDelegate::TimerCallback); |
79 #elif defined(OS_LINUX) | 80 #elif defined(TOOLKIT_USES_GTK) |
80 timer_id_ = g_timeout_add(interval, &FetcherDelegate::TimerCallback, NULL); | 81 timer_id_ = g_timeout_add(interval, &FetcherDelegate::TimerCallback, NULL); |
81 #elif defined(OS_MACOSX) | 82 #elif defined(OS_MACOSX) |
82 // CFAbsoluteTime is in seconds and |interval| is in ms, so make sure we | 83 // CFAbsoluteTime is in seconds and |interval| is in ms, so make sure we |
83 // keep the units correct. | 84 // keep the units correct. |
84 CFTimeInterval interval_in_seconds = static_cast<double>(interval) / 1000.0; | 85 CFTimeInterval interval_in_seconds = static_cast<double>(interval) / 1000.0; |
85 CFAbsoluteTime fire_date = | 86 CFAbsoluteTime fire_date = |
86 CFAbsoluteTimeGetCurrent() + interval_in_seconds; | 87 CFAbsoluteTimeGetCurrent() + interval_in_seconds; |
87 timer_id_ = CFRunLoopTimerCreate(NULL, fire_date, interval_in_seconds, 0, | 88 timer_id_ = CFRunLoopTimerCreate(NULL, fire_date, interval_in_seconds, 0, |
88 0, FetcherDelegate::TimerCallback, NULL); | 89 0, FetcherDelegate::TimerCallback, NULL); |
89 CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer_id_, kCFRunLoopCommonModes); | 90 CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer_id_, kCFRunLoopCommonModes); |
90 #endif | 91 #endif |
91 } | 92 } |
92 | 93 |
93 void DestroyTimer() { | 94 void DestroyTimer() { |
94 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
95 ::KillTimer(NULL, timer_id_); | 96 ::KillTimer(NULL, timer_id_); |
96 #elif defined(OS_LINUX) | 97 #elif defined(TOOLKIT_USES_GTK) |
97 g_source_remove(timer_id_); | 98 g_source_remove(timer_id_); |
98 #elif defined(OS_MACOSX) | 99 #elif defined(OS_MACOSX) |
99 CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), timer_id_, | 100 CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), timer_id_, |
100 kCFRunLoopCommonModes); | 101 kCFRunLoopCommonModes); |
101 CFRelease(timer_id_); | 102 CFRelease(timer_id_); |
102 #endif | 103 #endif |
103 } | 104 } |
104 | 105 |
105 #if defined(OS_WIN) | 106 #if defined(OS_WIN) |
106 // Static timer callback, just passes through to instance version. | 107 // Static timer callback, just passes through to instance version. |
107 static VOID CALLBACK TimerCallback(HWND hwnd, UINT msg, UINT_PTR timer_id, | 108 static VOID CALLBACK TimerCallback(HWND hwnd, UINT msg, UINT_PTR timer_id, |
108 DWORD ms) { | 109 DWORD ms) { |
109 instance_->TimerFired(); | 110 instance_->TimerFired(); |
110 } | 111 } |
111 #elif defined(OS_LINUX) | 112 #elif defined(TOOLKIT_USES_GTK) |
112 static gboolean TimerCallback(gpointer data) { | 113 static gboolean TimerCallback(gpointer data) { |
113 instance_->TimerFired(); | 114 instance_->TimerFired(); |
114 return true; | 115 return true; |
115 } | 116 } |
116 #elif defined(OS_MACOSX) | 117 #elif defined(OS_MACOSX) |
117 static void TimerCallback(CFRunLoopTimerRef timer, void* info) { | 118 static void TimerCallback(CFRunLoopTimerRef timer, void* info) { |
118 instance_->TimerFired(); | 119 instance_->TimerFired(); |
119 } | 120 } |
120 #endif | 121 #endif |
121 | 122 |
122 void TimerFired() { | 123 void TimerFired() { |
123 ASSERT_FALSE(completed_); | 124 ASSERT_FALSE(completed_); |
124 | 125 |
125 if (timed_out()) { | 126 if (timed_out()) { |
126 DestroyTimer(); | 127 DestroyTimer(); |
127 MessageLoop::current()->Quit(); | 128 MessageLoop::current()->Quit(); |
128 FAIL() << "fetch timed out"; | 129 FAIL() << "fetch timed out"; |
129 return; | 130 return; |
130 } | 131 } |
131 | 132 |
132 time_elapsed_ms_ += kWaitIntervalMs; | 133 time_elapsed_ms_ += kWaitIntervalMs; |
133 } | 134 } |
134 | 135 |
135 static FetcherDelegate* instance_; | 136 static FetcherDelegate* instance_; |
136 | 137 |
137 private: | 138 private: |
138 #if defined(OS_WIN) | 139 #if defined(OS_WIN) |
139 UINT_PTR timer_id_; | 140 UINT_PTR timer_id_; |
140 #elif defined(OS_LINUX) | 141 #elif defined(TOOLKIT_USES_GTK) |
141 guint timer_id_; | 142 guint timer_id_; |
142 #elif defined(OS_MACOSX) | 143 #elif defined(OS_MACOSX) |
143 CFRunLoopTimerRef timer_id_; | 144 CFRunLoopTimerRef timer_id_; |
144 #endif | 145 #endif |
145 bool completed_; | 146 bool completed_; |
146 int time_elapsed_ms_; | 147 int time_elapsed_ms_; |
147 WebURLResponse response_; | 148 WebURLResponse response_; |
148 std::string data_; | 149 std::string data_; |
149 }; | 150 }; |
150 | 151 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 224 |
224 // When we timeout, we still call the Delegate callback but we pass in empty | 225 // When we timeout, we still call the Delegate callback but we pass in empty |
225 // values. | 226 // values. |
226 EXPECT_TRUE(delegate->completed()); | 227 EXPECT_TRUE(delegate->completed()); |
227 EXPECT_TRUE(delegate->response().isNull()); | 228 EXPECT_TRUE(delegate->response().isNull()); |
228 EXPECT_EQ(delegate->data(), std::string()); | 229 EXPECT_EQ(delegate->data(), std::string()); |
229 EXPECT_TRUE(delegate->time_elapsed_ms() < kMaxWaitTimeMs); | 230 EXPECT_TRUE(delegate->time_elapsed_ms() < kMaxWaitTimeMs); |
230 } | 231 } |
231 | 232 |
232 } // namespace | 233 } // namespace |
OLD | NEW |