OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_shell; | 5 package org.chromium.content_shell; |
6 | 6 |
7 import android.content.ComponentName; | 7 import android.content.ComponentName; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 import android.net.Uri; | 9 import android.net.Uri; |
10 import android.test.ActivityInstrumentationTestCase2; | 10 import android.test.ActivityInstrumentationTestCase2; |
11 import android.text.TextUtils; | 11 import android.text.TextUtils; |
12 | 12 |
13 import java.util.concurrent.atomic.AtomicBoolean; | 13 import java.util.concurrent.atomic.AtomicBoolean; |
14 import java.util.concurrent.atomic.AtomicReference; | 14 import java.util.concurrent.atomic.AtomicReference; |
15 | 15 |
| 16 import org.chromium.base.test.util.UrlUtils; |
| 17 import org.chromium.content.browser.ContentView; |
| 18 import org.chromium.content.browser.ContentViewCore; |
16 import org.chromium.content.browser.test.util.Criteria; | 19 import org.chromium.content.browser.test.util.Criteria; |
17 import org.chromium.content.browser.test.util.CriteriaHelper; | 20 import org.chromium.content.browser.test.util.CriteriaHelper; |
18 | 21 |
19 /** | 22 /** |
20 * Base test class for all ContentShell based tests. | 23 * Base test class for all ContentShell based tests. |
21 */ | 24 */ |
22 public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
ntShellActivity> { | 25 public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
ntShellActivity> { |
23 | 26 |
24 /** The maximum time the waitForActiveShellToBeDoneLoading method will wait.
*/ | 27 /** The maximum time the waitForActiveShellToBeDoneLoading method will wait.
*/ |
25 private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = 10000; | 28 private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = 10000; |
(...skipping 23 matching lines...) Expand all Loading... |
49 if (url != null) intent.setData(Uri.parse(url)); | 52 if (url != null) intent.setData(Uri.parse(url)); |
50 intent.setComponent(new ComponentName(getInstrumentation().getTargetCont
ext(), | 53 intent.setComponent(new ComponentName(getInstrumentation().getTargetCont
ext(), |
51 ContentShellActivity.class)); | 54 ContentShellActivity.class)); |
52 if (commandLineArgs != null) { | 55 if (commandLineArgs != null) { |
53 intent.putExtra(ContentShellActivity.COMMAND_LINE_ARGS_KEY, commandL
ineArgs); | 56 intent.putExtra(ContentShellActivity.COMMAND_LINE_ARGS_KEY, commandL
ineArgs); |
54 } | 57 } |
55 setActivityIntent(intent); | 58 setActivityIntent(intent); |
56 return getActivity(); | 59 return getActivity(); |
57 } | 60 } |
58 | 61 |
| 62 // TODO(cjhopman): These functions are inconsistent with launchContentShell*
**. Should be |
| 63 // startContentShell*** and should use the url exactly without the getTestFi
leUrl call. Possibly |
| 64 // these two ways of starting the activity (launch* and start*) should be me
rged into one. |
| 65 /** |
| 66 * Starts the content shell activity with the provided test url. |
| 67 * The url is synchronously loaded. |
| 68 * @param url Test url to load. |
| 69 */ |
| 70 protected void startActivityWithTestUrl(String url) throws Throwable { |
| 71 launchContentShellWithUrl(UrlUtils.getTestFileUrl(url)); |
| 72 assertNotNull(getActivity()); |
| 73 assertTrue(waitForActiveShellToBeDoneLoading()); |
| 74 assertEquals(UrlUtils.getTestFileUrl(url), getContentView().getUrl()); |
| 75 } |
| 76 |
| 77 /** |
| 78 * Starts the content shell activity with the provided test url and optional
command line |
| 79 * arguments to append. |
| 80 * The url is synchronously loaded. |
| 81 * @param url Test url to load. |
| 82 * @param commandLineArgs Optional command line args to append when launchin
g the activity. |
| 83 */ |
| 84 protected void startActivityWithTestUrlAndCommandLineArgs( |
| 85 String url, String[] commandLineArgs) throws Throwable { |
| 86 launchContentShellWithUrlAndCommandLineArgs( |
| 87 UrlUtils.getTestFileUrl(url), commandLineArgs); |
| 88 assertNotNull(getActivity()); |
| 89 assertTrue(waitForActiveShellToBeDoneLoading()); |
| 90 } |
| 91 |
| 92 /** |
| 93 * Returns the current ContentView. |
| 94 */ |
| 95 protected ContentView getContentView() { |
| 96 return getActivity().getActiveShell().getContentView(); |
| 97 } |
| 98 |
| 99 /** |
| 100 * Returns the current ContentViewCore or null if there is no ContentView. |
| 101 */ |
| 102 protected ContentViewCore getContentViewCore() { |
| 103 return getContentView() == null ? null : getContentView().getContentView
Core(); |
| 104 } |
59 | 105 |
60 /** | 106 /** |
61 * Waits for the Active shell to finish loading. This times out after | 107 * Waits for the Active shell to finish loading. This times out after |
62 * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds and it shouldn't be us
ed for long | 108 * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds and it shouldn't be us
ed for long |
63 * loading pages. Instead it should be used more for test initialization. Th
e proper way | 109 * loading pages. Instead it should be used more for test initialization. Th
e proper way |
64 * to wait is to use a TestCallbackHelperContainer after the initial load is
completed. | 110 * to wait is to use a TestCallbackHelperContainer after the initial load is
completed. |
65 * @return Whether or not the Shell was actually finished loading. | 111 * @return Whether or not the Shell was actually finished loading. |
66 * @throws Exception | 112 * @throws Exception |
67 */ | 113 */ |
68 protected boolean waitForActiveShellToBeDoneLoading() throws Exception { | 114 protected boolean waitForActiveShellToBeDoneLoading() throws Exception { |
(...skipping 23 matching lines...) Expand all Loading... |
92 }); | 138 }); |
93 | 139 |
94 return isLoaded.get(); | 140 return isLoaded.get(); |
95 } catch (Throwable e) { | 141 } catch (Throwable e) { |
96 return false; | 142 return false; |
97 } | 143 } |
98 } | 144 } |
99 }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT, CriteriaHelper.DEFAULT_POLLING
_INTERVAL); | 145 }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT, CriteriaHelper.DEFAULT_POLLING
_INTERVAL); |
100 } | 146 } |
101 } | 147 } |
OLD | NEW |