Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / xwalk / test / android / core / javatests / src / org / xwalk / core / xwview / test / ShouldOverrideUrlLoadingTest.java
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2014 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 package org.xwalk.core.xwview.test;
7
8 import android.test.suitebuilder.annotation.SmallTest;
9 import android.util.Pair;
10
11 import java.util.ArrayList;
12 import java.util.concurrent.Callable;
13 import java.util.concurrent.TimeUnit;
14 import java.util.List;
15
16 import org.chromium.base.test.util.DisabledTest;
17 import org.chromium.base.test.util.Feature;
18 import org.chromium.content_public.browser.LoadUrlParams;
19 import org.chromium.content.browser.test.util.CallbackHelper;
20 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
21 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageStartedHelper;
22 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnReceivedErrorHelper;
23 import org.chromium.net.test.util.TestWebServer;
24
25 import org.xwalk.core.xwview.test.util.CommonResources;
26
27 /**
28  * Tests for the shouldOverrideUrlLoading() method.
29  */
30 public class ShouldOverrideUrlLoadingTest extends XWalkViewTestBase {
31     private static final String ABOUT_BLANK_URL = "about:blank";
32     private static final String DATA_URL = "data:text/html,<div/>";
33     private static final String REDIRECT_TARGET_PATH = "/redirect_target.html";
34     private static final String TITLE = "TITLE";
35     private TestHelperBridge.ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper;
36     private OnPageFinishedHelper mOnPageFinishedHelper;
37     private TestWebServer mWebServer;
38
39     @Override
40     protected void setUp() throws Exception {
41         super.setUp();
42         mShouldOverrideUrlLoadingHelper = mTestHelperBridge.getShouldOverrideUrlLoadingHelper();
43         mOnPageFinishedHelper = mTestHelperBridge.getOnPageFinishedHelper();
44         mWebServer = TestWebServer.start();
45     }
46
47     @Override
48     protected void tearDown() throws Exception {
49         mWebServer.shutdown();
50         super.tearDown();
51     }
52
53     // Since this value is read on the UI thread, it's simpler to set it there too.
54     void setShouldOverrideUrlLoadingReturnValueOnUiThread(
55             final boolean value) throws Throwable {
56         runTestOnUiThread(new Runnable() {
57             @Override
58             public void run() {
59                 mShouldOverrideUrlLoadingHelper.setShouldOverrideUrlLoadingReturnValue(value);
60             }
61         });
62     }
63
64     private String getTestPageCommonHeaders() {
65         return "<title>" + TITLE + "</title> ";
66     }
67
68     private String makeHtmlPageFrom(String headers, String body) {
69         return CommonResources.makeHtmlPageFrom(getTestPageCommonHeaders() + headers, body);
70     }
71
72     private String getHtmlForPageWithJsAssignLinkTo(String url) {
73         return makeHtmlPageFrom("",
74                 "<img onclick=\"location.href='" + url + "'\" class=\"big\" id=\"link\" />");
75     }
76
77     private String getHtmlForPageWithJsReplaceLinkTo(String url) {
78         return makeHtmlPageFrom("",
79                 "<img onclick=\"location.replace('" + url + "');\" class=\"big\" id=\"link\" />");
80     }
81
82     private String getHtmlForPageWithMetaRefreshRedirectTo(String url) {
83         return makeHtmlPageFrom("<meta http-equiv=\"refresh\" content=\"0;url=" + url + "\" />",
84                 "<div>Meta refresh redirect</div>");
85     }
86
87     private String getHtmlForPageWithJsRedirectTo(String url, String method, int timeout) {
88         return makeHtmlPageFrom(
89                 "<script>" +
90                   "function doRedirectAssign() {" +
91                     "location.href = '" + url + "';" +
92                   "} " +
93                   "function doRedirectReplace() {" +
94                     "location.replace('" + url + "');" +
95                   "} " +
96                 "</script>",
97                 String.format("<iframe onLoad=\"setTimeout('doRedirect%s()', %d);\" />",
98                     method, timeout));
99     }
100
101     private String addPageToTestServer(TestWebServer webServer, String httpPath, String html) {
102         List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>();
103         headers.add(Pair.create("Content-Type", "text/html"));
104         headers.add(Pair.create("Cache-Control", "no-store"));
105         return webServer.setResponse(httpPath, html, headers);
106     }
107
108     private String createRedirectTargetPage(TestWebServer webServer) {
109         return addPageToTestServer(webServer, REDIRECT_TARGET_PATH,
110                 makeHtmlPageFrom("", "<div>This is the end of the redirect chain</div>"));
111     }
112
113     @SmallTest
114     @Feature({"XWalkView", "Navigation"})
115     public void testNotCalledOnLoadData() throws Throwable {
116         loadDataSync(null,
117                 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/html", false);
118
119         assertEquals(0, mShouldOverrideUrlLoadingHelper.getCallCount());
120     }
121
122     private void waitForNavigationRunnableAndAssertTitleChanged(
123             CallbackHelper onPageFinishedHelper,
124             Runnable navigationRunnable) throws Exception {
125         final int callCount = onPageFinishedHelper.getCallCount();
126         final String oldTitle = getTitleOnUiThread();
127         getInstrumentation().runOnMainSync(navigationRunnable);
128         onPageFinishedHelper.waitForCallback(callCount);
129         assertFalse(oldTitle.equals(getTitleOnUiThread()));
130     }
131
132     @SmallTest
133     @Feature({"XWalkView", "Navigation"})
134     public void testCalledOnBackForwardNavigation() throws Throwable {
135         final String url = "file:///android_asset/www/index.html";
136         final String httpPath = "/test.html";
137         final String httpPathOnServer = mWebServer.getResponseUrl(httpPath);
138         addPageToTestServer(mWebServer, httpPath,
139                 CommonResources.makeHtmlPageWithSimpleLinkTo(httpPathOnServer));
140
141         loadUrlSync(httpPathOnServer);
142         loadUrlSync(url);
143         assertEquals(2, mShouldOverrideUrlLoadingHelper.getCallCount());
144         String oldTitle = getTitleOnUiThread();
145         goBackSync();
146         assertFalse(oldTitle.equals(getTitleOnUiThread()));
147         assertEquals(3, mShouldOverrideUrlLoadingHelper.getCallCount());
148
149         oldTitle = getTitleOnUiThread();
150         goForwardSync();
151         assertFalse(oldTitle.equals(getTitleOnUiThread()));
152         assertEquals(4, mShouldOverrideUrlLoadingHelper.getCallCount());
153     }
154
155     @SmallTest
156     @Feature({"XWalkView", "Navigation"})
157     public void testCantBlockLoads() throws Throwable {
158         setShouldOverrideUrlLoadingReturnValueOnUiThread(true);
159
160         loadDataSync(null,
161                 CommonResources.makeHtmlPageWithSimpleLinkTo(getTestPageCommonHeaders(),
162                         DATA_URL), "text/html", false);
163
164         assertEquals(TITLE, getTitleOnUiThread());
165     }
166
167     @SmallTest
168     @Feature({"XWalkView", "Navigation"})
169     public void testCalledBeforeOnPageStarted() throws Throwable {
170         OnPageStartedHelper onPageStartedHelper = mTestHelperBridge.getOnPageStartedHelper();
171
172         loadDataSync(null,
173                 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/html", false);
174
175         final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
176         final int onPageStartedCallCount = onPageStartedHelper.getCallCount();
177         setShouldOverrideUrlLoadingReturnValueOnUiThread(true);
178         clickOnElementId("link", null);
179
180         mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount);
181         assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount());
182     }
183
184     @SmallTest
185     @Feature({"XWalkView", "Navigation"})
186     public void testDoesNotCauseOnReceivedError() throws Throwable {
187         OnReceivedErrorHelper onReceivedErrorHelper = mTestHelperBridge.getOnReceivedErrorHelper();
188         final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount();
189
190         loadDataSync(null,
191                 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/html", false);
192
193         final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
194
195         setShouldOverrideUrlLoadingReturnValueOnUiThread(true);
196
197         clickOnElementId("link", null);
198
199         mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount);
200
201         setShouldOverrideUrlLoadingReturnValueOnUiThread(false);
202
203         // After we load this URL we're certain that any in-flight callbacks for the previous
204         // navigation have been delivered.
205         loadUrlSync(ABOUT_BLANK_URL);
206
207         assertEquals(onReceivedErrorCallCount, onReceivedErrorHelper.getCallCount());
208     }
209
210     @SmallTest
211     @Feature({"XWalkView", "Navigation"})
212     public void testNotCalledForAnchorNavigations() throws Throwable {
213         doTestNotCalledForAnchorNavigations(false);
214     }
215
216     @SmallTest
217     @Feature({"XWalkView", "Navigation"})
218     public void testNotCalledForAnchorNavigationsWithNonHierarchicalScheme() throws Throwable {
219         doTestNotCalledForAnchorNavigations(true);
220     }
221
222     private void doTestNotCalledForAnchorNavigations(boolean useLoadData) throws Throwable {
223         final String anchorLinkPath = "/anchor_link.html";
224         final String anchorLinkUrl = mWebServer.getResponseUrl(anchorLinkPath);
225         addPageToTestServer(mWebServer, anchorLinkPath,
226                 CommonResources.makeHtmlPageWithSimpleLinkTo(anchorLinkUrl + "#anchor"));
227
228         if (useLoadData) {
229             loadDataSync(null,
230                     CommonResources.makeHtmlPageWithSimpleLinkTo("#anchor"), "text/html", false);
231         } else {
232             loadUrlSync(anchorLinkUrl);
233         }
234
235         final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
236
237         clickOnElementId("link", null);
238
239         // After we load this URL we're certain that any in-flight callbacks for the previous
240         // navigation have been delivered.
241         loadUrlSync(ABOUT_BLANK_URL);
242
243         assertEquals(shouldOverrideUrlLoadingCallCount,
244                 mShouldOverrideUrlLoadingHelper.getCallCount());
245     }
246
247     @SmallTest
248     @Feature({"XWalkView", "Navigation"})
249     public void testCalledWhenLinkClicked() throws Throwable {
250         // We can't go to about:blank from here because we'd get a cross-origin error.
251         loadDataSync(null,
252                 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/html", false);
253
254         int callCount = mShouldOverrideUrlLoadingHelper.getCallCount();
255
256         clickOnElementId("link", null);
257
258         mShouldOverrideUrlLoadingHelper.waitForCallback(callCount);
259     }
260
261     @SmallTest
262     @Feature({"XWalkView", "Navigation"})
263     public void testCalledWhenSelfLinkClicked() throws Throwable {
264         final String httpPath = "/page_with_link_to_self.html";
265         final String httpPathOnServer = mWebServer.getResponseUrl(httpPath);
266         addPageToTestServer(mWebServer, httpPath,
267                 CommonResources.makeHtmlPageWithSimpleLinkTo(httpPathOnServer));
268
269         loadUrlSync(httpPathOnServer);
270
271         int callCount = mShouldOverrideUrlLoadingHelper.getCallCount();
272
273         clickOnElementId("link", null);
274
275         mShouldOverrideUrlLoadingHelper.waitForCallback(callCount);
276         assertEquals(httpPathOnServer,
277                 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl());
278     }
279
280     @SmallTest
281     @Feature({"XWalkView", "Navigation"})
282     public void testCalledWhenNavigatingFromJavaScriptUsingAssign()
283             throws Throwable {
284         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
285         loadDataSync(null,
286                 getHtmlForPageWithJsAssignLinkTo(redirectTargetUrl), "text/html", false);
287
288         int callCount = mShouldOverrideUrlLoadingHelper.getCallCount();
289
290         clickOnElementId("link", null);
291
292         mShouldOverrideUrlLoadingHelper.waitForCallback(callCount);
293     }
294
295     @SmallTest
296     @Feature({"XWalkView", "Navigation"})
297     public void testCalledWhenNavigatingFromJavaScriptUsingReplace()
298             throws Throwable {
299         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
300         loadDataSync(null,
301                 getHtmlForPageWithJsReplaceLinkTo(redirectTargetUrl), "text/html", false);
302
303         int callCount = mShouldOverrideUrlLoadingHelper.getCallCount();
304         clickOnElementId("link", null);
305         mShouldOverrideUrlLoadingHelper.waitForCallback(callCount);
306     }
307
308     @SmallTest
309     @Feature({"XWalkView", "Navigation"})
310     public void testPassesCorrectUrl() throws Throwable {
311         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
312         loadDataSync(null,
313                 CommonResources.makeHtmlPageWithSimpleLinkTo(redirectTargetUrl), "text/html", false);
314
315         int callCount = mShouldOverrideUrlLoadingHelper.getCallCount();
316         clickOnElementId("link", null);
317         mShouldOverrideUrlLoadingHelper.waitForCallback(callCount);
318         assertEquals(redirectTargetUrl,
319                 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl());
320     }
321
322     // This test case is not stable, disable it temporarily.
323     // @SmallTest
324     // @Feature({"XWalkView", "Navigation"})
325     @DisabledTest
326     public void testCanIgnoreLoading() throws Throwable {
327         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
328         final String pageWithLinkToIgnorePath = "/page_with_link_to_ignore.html";
329         final String pageWithLinkToIgnoreUrl = addPageToTestServer(mWebServer,
330                 pageWithLinkToIgnorePath, CommonResources.makeHtmlPageWithSimpleLinkTo(redirectTargetUrl));
331         final String synchronizationPath = "/sync.html";
332         final String synchronizationUrl = addPageToTestServer(mWebServer, synchronizationPath,
333                 CommonResources.makeHtmlPageWithSimpleLinkTo(redirectTargetUrl));
334
335         loadUrlSync(pageWithLinkToIgnoreUrl);
336
337         setShouldOverrideUrlLoadingReturnValueOnUiThread(true);
338
339         int callCount = mShouldOverrideUrlLoadingHelper.getCallCount();
340         clickOnElementId("link", null);
341         // Some time around here true should be returned from the shouldOverrideUrlLoading
342         // callback causing the navigation caused by calling clickOnElementId to be ignored.
343         // We validate this by checking which pages were loaded on the server.
344         mShouldOverrideUrlLoadingHelper.waitForCallback(callCount);
345         mOnPageFinishedHelper.waitForCallback(
346                 mOnPageFinishedHelper.getCallCount(), 1, 15, TimeUnit.SECONDS);
347
348         setShouldOverrideUrlLoadingReturnValueOnUiThread(false);
349
350         loadUrlSync(synchronizationUrl);
351
352         assertEquals(1, mWebServer.getRequestCount(pageWithLinkToIgnorePath));
353         assertEquals(1, mWebServer.getRequestCount(synchronizationPath));
354         assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH));
355     }
356
357     @SmallTest
358     @Feature({"XWalkView", "Navigation"})
359     public void testCalledForDataUrl() throws Throwable {
360         final String dataUrl =
361                 "data:text/html;base64," +
362                 "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90aXRsZT48" +
363                 "L2hlYWQ+PC9odG1sPg==";
364         loadDataSync(null,
365                 CommonResources.makeHtmlPageWithSimpleLinkTo(dataUrl), "text/html", false);
366
367         int callCount = mShouldOverrideUrlLoadingHelper.getCallCount();
368         clickOnElementId("link", null);
369
370         mShouldOverrideUrlLoadingHelper.waitForCallback(callCount);
371         assertTrue("Expected URL that starts with 'data:' but got: <" +
372                 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl() + "> instead.",
373                 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl().startsWith(
374                         "data:"));
375     }
376
377     @SmallTest
378     @Feature({"XWalkView", "Navigation"})
379     public void testCalledForUnsupportedSchemes() throws Throwable {
380         final String unsupportedSchemeUrl = "foobar://resource/1";
381         loadDataSync(null,
382                 CommonResources.makeHtmlPageWithSimpleLinkTo(unsupportedSchemeUrl), "text/html",
383                         false);
384
385         int callCount = mShouldOverrideUrlLoadingHelper.getCallCount();
386         clickOnElementId("link", null);
387
388         mShouldOverrideUrlLoadingHelper.waitForCallback(callCount);
389         assertEquals(unsupportedSchemeUrl,
390                 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl());
391     }
392
393     @SmallTest
394     @Feature({"XWalkView", "Navigation"})
395     public void testCalledForPostNavigations() throws Throwable {
396         // The reason POST requests are excluded is BUG 155250.
397         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
398         final String postLinkUrl = addPageToTestServer(mWebServer, "/page_with_post_link.html",
399                 CommonResources.makeHtmlPageWithSimplePostFormTo(redirectTargetUrl));
400
401         loadUrlSync(postLinkUrl);
402
403         final int shouldOverrideUrlLoadingCallCount =
404             mShouldOverrideUrlLoadingHelper.getCallCount();
405
406         assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH));
407         clickOnElementId("link", null);
408
409         // Wait for the target URL to be fetched from the server.
410         pollOnUiThread(new Callable<Boolean>() {
411             @Override
412             public Boolean call() throws Exception {
413                 return mWebServer.getRequestCount(REDIRECT_TARGET_PATH) == 1;
414             }
415         });
416
417         // Since the targetURL was loaded from the test server it means all processing related
418         // to dispatching a shouldOverrideUrlLoading callback had finished and checking the call
419         // is stable.
420         assertEquals(shouldOverrideUrlLoadingCallCount + 1,
421                 mShouldOverrideUrlLoadingHelper.getCallCount());
422     }
423
424     @SmallTest
425     @Feature({"XWalkView", "Navigation"})
426     public void testCalledFor302AfterPostNavigations() throws Throwable {
427         // The reason POST requests are excluded is BUG 155250.
428         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
429         final String postToGetRedirectUrl = mWebServer.setRedirect("/302.html", redirectTargetUrl);
430         final String postLinkUrl = addPageToTestServer(mWebServer, "/page_with_post_link.html",
431                 CommonResources.makeHtmlPageWithSimplePostFormTo(postToGetRedirectUrl));
432
433         loadUrlSync(postLinkUrl);
434
435         final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
436
437         clickOnElementId("link", null);
438
439         mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount);
440
441         // Wait for the target URL to be fetched from the server.
442         pollOnUiThread(new Callable<Boolean>() {
443             @Override
444             public Boolean call() throws Exception {
445                 return mWebServer.getRequestCount(REDIRECT_TARGET_PATH) == 1;
446             }
447         });
448
449         assertEquals(redirectTargetUrl,
450                 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl());
451     }
452
453     @SmallTest
454     @Feature({"XWalkView", "Navigation"})
455     public void testCalledForIframeHttpNavigations() throws Throwable {
456         final String iframeRedirectTargetUrl = createRedirectTargetPage(mWebServer);
457         final String iframeRedirectUrl = mWebServer.setRedirect("/302.html", iframeRedirectTargetUrl);
458         final String pageWithIframeUrl = addPageToTestServer(mWebServer, "/iframe_intercept.html",
459                 makeHtmlPageFrom("", "<iframe src=\"" + iframeRedirectUrl + "\" />"));
460
461         assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH));
462         loadUrlSync(pageWithIframeUrl);
463
464         // Wait for the redirect target URL to be fetched from the server.
465         pollOnUiThread(new Callable<Boolean>() {
466             @Override
467             public Boolean call() throws Exception {
468                 return mWebServer.getRequestCount(REDIRECT_TARGET_PATH) == 1;
469             }
470         });
471
472         assertEquals(1, mShouldOverrideUrlLoadingHelper.getCallCount());
473     }
474
475     /**
476      * Worker method for the various redirect tests.
477      *
478      * Calling this will first load the redirect URL built from redirectFilePath, query and
479      * locationFilePath and assert that we get a override callback for the destination.
480      * The second part of the test loads a page that contains a link which points at the redirect
481      * URL. We expect two callbacks - one for the redirect link and another for the destination.
482      */
483     private void doTestCalledOnRedirect(TestWebServer webServer,
484             String redirectUrl, String redirectTarget) throws Throwable {
485         final String pageWithLinkToRedirectUrl = addPageToTestServer(webServer,
486                 "/page_with_link_to_redirect.html",
487                          CommonResources.makeHtmlPageWithSimpleLinkTo(redirectUrl));
488         int directLoadCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
489         loadUrlSync(redirectUrl);
490
491         mShouldOverrideUrlLoadingHelper.waitForCallback(directLoadCallCount, 2);
492         assertEquals(redirectTarget,
493                 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl());
494
495         int indirectLoadCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();
496         loadUrlSync(pageWithLinkToRedirectUrl);
497
498         clickOnElementId("link", null);
499
500         mShouldOverrideUrlLoadingHelper.waitForCallback(indirectLoadCallCount, 3);
501         assertEquals(redirectTarget,
502                 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl());
503         assertEquals(redirectUrl,
504                 mShouldOverrideUrlLoadingHelper.getPreviousShouldOverrideUrlLoadingUrl());
505     }
506
507     @SmallTest
508     @Feature({"XWalkView", "Navigation"})
509     public void testCalledOn302Redirect() throws Throwable {
510         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
511         final String redirectUrl = mWebServer.setRedirect("/302.html", redirectTargetUrl);
512
513         doTestCalledOnRedirect(mWebServer, redirectUrl, redirectTargetUrl);
514     }
515
516     @SmallTest
517     @Feature({"XWalkView", "Navigation"})
518     public void testCalledOnMetaRefreshRedirect() throws Throwable {
519         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
520         final String redirectUrl = addPageToTestServer(mWebServer, "/meta_refresh.html",
521                 getHtmlForPageWithMetaRefreshRedirectTo(redirectTargetUrl));
522         doTestCalledOnRedirect(mWebServer, redirectUrl, redirectTargetUrl);
523     }
524
525
526     @SmallTest
527     @Feature({"XWalkView", "Navigation"})
528     public void testCalledOnJavaScriptLocationImmediateAssignRedirect()
529             throws Throwable {
530         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
531         final String redirectUrl = addPageToTestServer(mWebServer, "/js_immediate_assign.html",
532                 getHtmlForPageWithJsRedirectTo(redirectTargetUrl, "Assign", 0));
533         doTestCalledOnRedirect(mWebServer, redirectUrl, redirectTargetUrl);
534     }
535
536     @SmallTest
537     @Feature({"XWalkView", "Navigation"})
538     public void testCalledOnJavaScriptLocationImmediateReplaceRedirect()
539             throws Throwable {
540         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
541         final String redirectUrl = addPageToTestServer(mWebServer, "/js_immediate_replace.html",
542                 getHtmlForPageWithJsRedirectTo(redirectTargetUrl, "Replace", 0));
543         doTestCalledOnRedirect(mWebServer, redirectUrl, redirectTargetUrl);
544     }
545
546     @SmallTest
547     @Feature({"XWalkView", "Navigation"})
548     public void testCalledOnJavaScriptLocationDelayedAssignRedirect()
549             throws Throwable {
550         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
551         final String redirectUrl = addPageToTestServer(mWebServer, "/js_delayed_assign.html",
552                 getHtmlForPageWithJsRedirectTo(redirectTargetUrl, "Assign", 100));
553         doTestCalledOnRedirect(mWebServer, redirectUrl, redirectTargetUrl);
554     }
555
556     @SmallTest
557     @Feature({"XWalkView", "Navigation"})
558     public void testCalledOnJavaScriptLocationDelayedReplaceRedirect()
559             throws Throwable {
560         final String redirectTargetUrl = createRedirectTargetPage(mWebServer);
561         final String redirectUrl = addPageToTestServer(mWebServer, "/js_delayed_replace.html",
562                 getHtmlForPageWithJsRedirectTo(redirectTargetUrl, "Replace", 100));
563         doTestCalledOnRedirect(mWebServer, redirectUrl, redirectTargetUrl);
564     }
565
566     @SmallTest
567     @Feature({"XWalkView", "Navigation"})
568     public void testDoubleNavigateDoesNotSuppressInitialNavigate() throws Throwable {
569         final String jsUrl = "javascript:try{console.log('processed js loadUrl');}catch(e){};";
570
571         // Do a double navigagtion, the second being an effective no-op, in quick succession (i.e.
572         // without yielding the main thread inbetween).
573         loadDataSync(null,
574                 CommonResources.makeHtmlPageWithSimpleLinkTo(DATA_URL), "text/html", false);
575         loadJavaScriptUrl(jsUrl);
576         assertEquals(0, mShouldOverrideUrlLoadingHelper.getCallCount());
577     }
578 }