OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.test.suitebuilder.annotation.LargeTest; | 7 import android.test.suitebuilder.annotation.LargeTest; |
8 | 8 |
9 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
10 import org.chromium.base.test.util.Feature; | 10 import org.chromium.base.test.util.Feature; |
11 import org.chromium.base.test.util.UrlUtils; | 11 import org.chromium.base.test.util.UrlUtils; |
12 import org.chromium.content.browser.test.util.Criteria; | 12 import org.chromium.content.browser.test.util.Criteria; |
13 import org.chromium.content.browser.test.util.CriteriaHelper; | 13 import org.chromium.content.browser.test.util.CriteriaHelper; |
14 import org.chromium.content.browser.test.util.TouchCommon; | 14 import org.chromium.content.browser.test.util.TouchCommon; |
15 import org.chromium.content_public.browser.WebContents; | 15 import org.chromium.content_public.browser.WebContents; |
16 import org.chromium.content_shell_apk.ContentShellActivity; | 16 import org.chromium.content_shell_apk.ContentShellActivity; |
17 import org.chromium.content_shell_apk.ContentShellTestBase; | 17 import org.chromium.content_shell_apk.ContentShellTestBase; |
18 | 18 |
19 import java.util.concurrent.Callable; | 19 import java.util.concurrent.Callable; |
20 import java.util.concurrent.ExecutionException; | 20 import java.util.concurrent.ExecutionException; |
21 | 21 |
22 /** | 22 /** |
23 * Tests for interstitial pages. | 23 * Tests for interstitial pages. |
24 */ | 24 */ |
25 public class InterstitialPageTest extends ContentShellTestBase { | 25 public class InterstitialPageTest extends ContentShellTestBase { |
26 | 26 |
27 private static final String URL = UrlUtils.encodeHtmlDataUri( | 27 private static final String URL = UrlUtils.encodeHtmlDataUri( |
28 "<html><head></head><body>test</body></html>"); | 28 "<html><head></head><body>test</body></html>"); |
29 | 29 |
30 private static class TestWebContentsObserverAndroid extends WebContentsObser
verAndroid { | 30 private static class TestWebContentsObserver extends WebContentsObserver { |
31 private boolean mInterstitialShowing; | 31 private boolean mInterstitialShowing; |
32 | 32 |
33 public TestWebContentsObserverAndroid(WebContents webContents) { | 33 public TestWebContentsObserver(WebContents webContents) { |
34 super(webContents); | 34 super(webContents); |
35 } | 35 } |
36 | 36 |
37 public boolean isInterstitialShowing() throws ExecutionException { | 37 public boolean isInterstitialShowing() throws ExecutionException { |
38 return ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() { | 38 return ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() { |
39 @Override | 39 @Override |
40 public Boolean call() throws Exception { | 40 public Boolean call() throws Exception { |
41 return mInterstitialShowing; | 41 return mInterstitialShowing; |
42 } | 42 } |
43 }).booleanValue(); | 43 }).booleanValue(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 "</body>" + | 104 "</body>" + |
105 "</html>"; | 105 "</html>"; |
106 final InterstitialPageDelegateAndroid delegate = | 106 final InterstitialPageDelegateAndroid delegate = |
107 new InterstitialPageDelegateAndroid(htmlContent) { | 107 new InterstitialPageDelegateAndroid(htmlContent) { |
108 @Override | 108 @Override |
109 protected void commandReceived(String command) { | 109 protected void commandReceived(String command) { |
110 assertEquals(command, proceedCommand); | 110 assertEquals(command, proceedCommand); |
111 proceed(); | 111 proceed(); |
112 } | 112 } |
113 }; | 113 }; |
114 TestWebContentsObserverAndroid observer = ThreadUtils.runOnUiThreadBlock
ing( | 114 TestWebContentsObserver observer = ThreadUtils.runOnUiThreadBlocking( |
115 new Callable<TestWebContentsObserverAndroid>() { | 115 new Callable<TestWebContentsObserver>() { |
116 @Override | 116 @Override |
117 public TestWebContentsObserverAndroid call() throws Exceptio
n { | 117 public TestWebContentsObserver call() throws Exception { |
118 getContentViewCore().showInterstitialPage(URL, delegate)
; | 118 getContentViewCore().showInterstitialPage(URL, delegate)
; |
119 return new TestWebContentsObserverAndroid( | 119 return new TestWebContentsObserver( |
120 getContentViewCore().getWebContents()); | 120 getContentViewCore().getWebContents()); |
121 } | 121 } |
122 }); | 122 }); |
123 | 123 |
124 assertTrue("Interstitial never shown.", waitForInterstitial(true)); | 124 assertTrue("Interstitial never shown.", waitForInterstitial(true)); |
125 assertTrue("WebContentsObserver not notified of interstitial showing", | 125 assertTrue("WebContentsObserver not notified of interstitial showing", |
126 observer.isInterstitialShowing()); | 126 observer.isInterstitialShowing()); |
127 TouchCommon touchCommon = new TouchCommon(this); | 127 TouchCommon touchCommon = new TouchCommon(this); |
128 touchCommon.singleClickViewRelative(getContentViewCore().getContainerVie
w(), 10, 10); | 128 touchCommon.singleClickViewRelative(getContentViewCore().getContainerVie
w(), 10, 10); |
129 assertTrue("Interstitial never hidden.", waitForInterstitial(false)); | 129 assertTrue("Interstitial never hidden.", waitForInterstitial(false)); |
130 assertTrue("WebContentsObserver not notified of interstitial hiding", | 130 assertTrue("WebContentsObserver not notified of interstitial hiding", |
131 !observer.isInterstitialShowing()); | 131 !observer.isInterstitialShowing()); |
132 } | 132 } |
133 } | 133 } |
OLD | NEW |