| 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.content.browser.test.util.Criteria; | 16 import org.chromium.content.browser.test.util.Criteria; |
| 17 import org.chromium.content.browser.test.util.CriteriaHelper; | 17 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Base test class for all ContentShell based tests. | 20 * Base test class for all ContentShell based tests. |
| 21 */ | 21 */ |
| 22 public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
ntShellActivity> { | 22 public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
ntShellActivity> { |
| 23 | 23 |
| 24 /** The maximum time the waitForActiveShellToBeDoneLoading method will wait.
*/ |
| 25 private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = 10000; |
| 26 |
| 24 public ContentShellTestBase() { | 27 public ContentShellTestBase() { |
| 25 super(ContentShellActivity.class); | 28 super(ContentShellActivity.class); |
| 26 } | 29 } |
| 27 | 30 |
| 28 /** | 31 /** |
| 29 * Starts the ContentShell activity and loads the given URL. | 32 * Starts the ContentShell activity and loads the given URL. |
| 33 * The URL can be null, in which case will default to ContentShellActivity.D
EFAULT_SHELL_URL. |
| 30 */ | 34 */ |
| 31 protected ContentShellActivity launchContentShellWithUrl(String url) { | 35 protected ContentShellActivity launchContentShellWithUrl(String url) { |
| 36 return launchContentShellWithUrlAndCommandLineArgs(url, null); |
| 37 } |
| 38 |
| 39 /** |
| 40 * Starts the ContentShell activity appending the provided command line argu
ments |
| 41 * and loads the given URL. The URL can be null, in which case will default
to |
| 42 * ContentShellActivity.DEFAULT_SHELL_URL. |
| 43 */ |
| 44 protected ContentShellActivity launchContentShellWithUrlAndCommandLineArgs(S
tring url, |
| 45 String[] commandLineArgs) { |
| 32 Intent intent = new Intent(Intent.ACTION_MAIN); | 46 Intent intent = new Intent(Intent.ACTION_MAIN); |
| 33 intent.addCategory(Intent.CATEGORY_LAUNCHER); | 47 intent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 34 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 48 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 35 intent.setData(Uri.parse(url)); | 49 if (url != null) intent.setData(Uri.parse(url)); |
| 36 intent.setComponent(new ComponentName(getInstrumentation().getTargetCont
ext(), | 50 intent.setComponent(new ComponentName(getInstrumentation().getTargetCont
ext(), |
| 37 ContentShellActivity.class)); | 51 ContentShellActivity.class)); |
| 52 if (commandLineArgs != null) { |
| 53 intent.putExtra(ContentShellActivity.COMMAND_LINE_ARGS_KEY, commandL
ineArgs); |
| 54 } |
| 38 setActivityIntent(intent); | 55 setActivityIntent(intent); |
| 39 return getActivity(); | 56 return getActivity(); |
| 40 } | 57 } |
| 41 | 58 |
| 59 |
| 42 /** | 60 /** |
| 43 * Waits for the Active shell to finish loading. This times out after three
seconds, | 61 * Waits for the Active shell to finish loading. This times out after |
| 44 * so it shouldn't be used for long loading pages. Instead it should be use
d more for | 62 * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds and it shouldn't be us
ed for long |
| 45 * test initialization. The proper way to wait is to use a TestCallbackHelp
erContainer | 63 * loading pages. Instead it should be used more for test initialization. Th
e proper way |
| 46 * after the initial load is completed. | 64 * to wait is to use a TestCallbackHelperContainer after the initial load is
completed. |
| 47 * @return Whether or not the Shell was actually finished loading. | 65 * @return Whether or not the Shell was actually finished loading. |
| 48 * @throws Exception | 66 * @throws Exception |
| 49 */ | 67 */ |
| 50 protected boolean waitForActiveShellToBeDoneLoading() throws Exception { | 68 protected boolean waitForActiveShellToBeDoneLoading() throws Exception { |
| 51 final ContentShellActivity activity = getActivity(); | 69 final ContentShellActivity activity = getActivity(); |
| 52 | 70 |
| 53 // Wait for the Content Shell to be initialized. | 71 // Wait for the Content Shell to be initialized. |
| 54 return CriteriaHelper.pollForCriteria(new Criteria() { | 72 return CriteriaHelper.pollForCriteria(new Criteria() { |
| 55 @Override | 73 @Override |
| 56 public boolean isSatisfied() { | 74 public boolean isSatisfied() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 71 isLoaded.set(false); | 89 isLoaded.set(false); |
| 72 } | 90 } |
| 73 } | 91 } |
| 74 }); | 92 }); |
| 75 | 93 |
| 76 return isLoaded.get(); | 94 return isLoaded.get(); |
| 77 } catch (Throwable e) { | 95 } catch (Throwable e) { |
| 78 return false; | 96 return false; |
| 79 } | 97 } |
| 80 } | 98 } |
| 81 }); | 99 }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT, CriteriaHelper.DEFAULT_POLLING
_INTERVAL); |
| 82 } | 100 } |
| 83 } | 101 } |
| OLD | NEW |