|
27 | 27 | #include "WebViewTest.h"
|
28 | 28 | #include <gtk/gtk.h>
|
29 | 29 | #include <libsoup/soup.h>
|
| 30 | +#include <wtf/Vector.h> |
30 | 31 | #include <wtf/text/CString.h>
|
31 | 32 |
|
32 | 33 | static WebKitTestBus* bus;
|
@@ -209,51 +210,100 @@ class ViewURITrackingTest: public LoadTrackingTest {
|
209 | 210 |
|
210 | 211 | static void uriChanged(GObject*, GParamSpec*, ViewURITrackingTest* test)
|
211 | 212 | {
|
212 |
| - g_assert_cmpstr(test->m_activeURI.data(), !=, webkit_web_view_get_uri(test->m_webView)); |
213 |
| - test->m_activeURI = webkit_web_view_get_uri(test->m_webView); |
| 213 | + g_assert_cmpstr(test->m_currentURI.data(), !=, webkit_web_view_get_uri(test->m_webView)); |
| 214 | + test->m_currentURI = webkit_web_view_get_uri(test->m_webView); |
214 | 215 | }
|
215 | 216 |
|
216 | 217 | ViewURITrackingTest()
|
217 |
| - : m_activeURI(webkit_web_view_get_uri(m_webView)) |
| 218 | + : m_currentURI(webkit_web_view_get_uri(m_webView)) |
218 | 219 | {
|
219 |
| - g_assert(m_activeURI.isNull()); |
| 220 | + g_assert(m_currentURI.isNull()); |
| 221 | + m_currentURIList.grow(m_currentURIList.capacity()); |
220 | 222 | g_signal_connect(m_webView, "notify::uri", G_CALLBACK(uriChanged), this);
|
221 | 223 | }
|
222 | 224 |
|
| 225 | + enum State { Provisional, ProvisionalAfterRedirect, Commited, Finished }; |
| 226 | + |
| 227 | + void loadURI(const char* uri) |
| 228 | + { |
| 229 | + reset(); |
| 230 | + LoadTrackingTest::loadURI(uri); |
| 231 | + } |
| 232 | + |
223 | 233 | void provisionalLoadStarted()
|
224 | 234 | {
|
225 |
| - checkActiveURI("/redirect"); |
| 235 | + m_currentURIList[Provisional] = m_currentURI; |
226 | 236 | }
|
227 | 237 |
|
228 | 238 | void provisionalLoadReceivedServerRedirect()
|
229 | 239 | {
|
230 |
| - checkActiveURI("/normal"); |
| 240 | + m_currentURIList[ProvisionalAfterRedirect] = m_currentURI; |
231 | 241 | }
|
232 | 242 |
|
233 | 243 | void loadCommitted()
|
234 | 244 | {
|
235 |
| - checkActiveURI("/normal"); |
| 245 | + m_currentURIList[Commited] = m_currentURI; |
236 | 246 | }
|
237 | 247 |
|
238 | 248 | void loadFinished()
|
239 | 249 | {
|
240 |
| - checkActiveURI("/normal"); |
| 250 | + m_currentURIList[Finished] = m_currentURI; |
241 | 251 | LoadTrackingTest::loadFinished();
|
242 | 252 | }
|
243 | 253 |
|
244 |
| - CString m_activeURI; |
| 254 | + void checkURIAtState(State state, const char* path) |
| 255 | + { |
| 256 | + if (path) |
| 257 | + ASSERT_CMP_CSTRING(m_currentURIList[state], ==, kServer->getURIForPath(path)); |
| 258 | + else |
| 259 | + g_assert(m_currentURIList[state].isNull()); |
| 260 | + } |
245 | 261 |
|
246 | 262 | private:
|
247 |
| - void checkActiveURI(const char* uri) |
| 263 | + void reset() |
248 | 264 | {
|
249 |
| - ASSERT_CMP_CSTRING(m_activeURI, ==, kServer->getURIForPath(uri)); |
| 265 | + m_currentURI = CString(); |
| 266 | + m_currentURIList.clear(); |
| 267 | + m_currentURIList.grow(m_currentURIList.capacity()); |
250 | 268 | }
|
| 269 | + |
| 270 | + CString m_currentURI; |
| 271 | + Vector<CString, 4> m_currentURIList; |
251 | 272 | };
|
252 | 273 |
|
253 | 274 | static void testWebViewActiveURI(ViewURITrackingTest* test, gconstpointer)
|
254 | 275 | {
|
| 276 | + // Normal load, the URL doesn't change. |
| 277 | + test->loadURI(kServer->getURIForPath("/normal1").data()); |
| 278 | + test->waitUntilLoadFinished(); |
| 279 | + test->checkURIAtState(ViewURITrackingTest::State::Provisional, "/normal1"); |
| 280 | + test->checkURIAtState(ViewURITrackingTest::State::ProvisionalAfterRedirect, nullptr); |
| 281 | + test->checkURIAtState(ViewURITrackingTest::State::Commited, "/normal1"); |
| 282 | + test->checkURIAtState(ViewURITrackingTest::State::Finished, "/normal1"); |
| 283 | + |
| 284 | + // Redirect, the URL changes after the redirect. |
255 | 285 | test->loadURI(kServer->getURIForPath("/redirect").data());
|
256 | 286 | test->waitUntilLoadFinished();
|
| 287 | + test->checkURIAtState(ViewURITrackingTest::State::Provisional, "/redirect"); |
| 288 | + test->checkURIAtState(ViewURITrackingTest::State::ProvisionalAfterRedirect, "/normal"); |
| 289 | + test->checkURIAtState(ViewURITrackingTest::State::Commited, "/normal"); |
| 290 | + test->checkURIAtState(ViewURITrackingTest::State::Finished, "/normal"); |
| 291 | + |
| 292 | + // Normal load, URL changed by WebKitPage::send-request. |
| 293 | + test->loadURI(kServer->getURIForPath("/normal-change-request").data()); |
| 294 | + test->waitUntilLoadFinished(); |
| 295 | + test->checkURIAtState(ViewURITrackingTest::State::Provisional, "/normal-change-request"); |
| 296 | + test->checkURIAtState(ViewURITrackingTest::State::ProvisionalAfterRedirect, nullptr); |
| 297 | + test->checkURIAtState(ViewURITrackingTest::State::Commited, "/request-changed"); |
| 298 | + test->checkURIAtState(ViewURITrackingTest::State::Finished, "/request-changed"); |
| 299 | + |
| 300 | + // Redirect, URL changed by WebKitPage::send-request. |
| 301 | + test->loadURI(kServer->getURIForPath("/redirect-to-change-request").data()); |
| 302 | + test->waitUntilLoadFinished(); |
| 303 | + test->checkURIAtState(ViewURITrackingTest::State::Provisional, "/redirect-to-change-request"); |
| 304 | + test->checkURIAtState(ViewURITrackingTest::State::ProvisionalAfterRedirect, "/normal-change-request"); |
| 305 | + test->checkURIAtState(ViewURITrackingTest::State::Commited, "/request-changed-on-redirect"); |
| 306 | + test->checkURIAtState(ViewURITrackingTest::State::Finished, "/request-changed-on-redirect"); |
257 | 307 | }
|
258 | 308 |
|
259 | 309 | class ViewIsLoadingTest: public LoadTrackingTest {
|
@@ -484,6 +534,9 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
|
484 | 534 | else if (g_str_equal(path, "/redirect")) {
|
485 | 535 | soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY);
|
486 | 536 | soup_message_headers_append(message->response_headers, "Location", "/normal");
|
| 537 | + } else if (g_str_equal(path, "/redirect-to-change-request")) { |
| 538 | + soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY); |
| 539 | + soup_message_headers_append(message->response_headers, "Location", "/normal-change-request"); |
487 | 540 | } else if (g_str_equal(path, "/cancelled")) {
|
488 | 541 | soup_message_headers_set_encoding(message->response_headers, SOUP_ENCODING_CHUNKED);
|
489 | 542 | soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString));
|
|
0 commit comments