Here are the examples of the java api @org.chromium.base.VisibleForTesting taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
497 Examples
19
Source : CronetUrlRequestContext.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
@VisibleForTesting
@Override
public void configureNetworkQualityEstimatorForTesting(boolean useLocalHostRequests, boolean useSmallerResponses, boolean disableOfflineCheck) {
if (!mNetworkQualityEstimatorEnabled) {
throw new IllegalStateException("Network quality estimator must be enabled");
}
synchronized (mLock) {
checkHaveAdapter();
nativeConfigureNetworkQualityEstimatorForTesting(mUrlRequestContextAdapter, useLocalHostRequests, useSmallerResponses, disableOfflineCheck);
}
}
19
Source : CronetUrlRequestContext.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
@VisibleForTesting
public long getUrlRequestContextAdapter() {
synchronized (mLock) {
checkHaveAdapter();
return mUrlRequestContextAdapter;
}
}
19
Source : CronetUrlRequest.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
@VisibleForTesting
public void setOnDestroyedUploadCallbackForTesting(Runnable onDestroyedUploadCallbackForTesting) {
mUploadDataStream.setOnDestroyedCallbackForTesting(onDestroyedUploadCallbackForTesting);
}
19
Source : CronetUrlRequest.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
@VisibleForTesting
public void setOnDestroyedCallbackForTesting(Runnable onDestroyedCallbackForTesting) {
synchronized (mUrlRequestAdapterLock) {
mOnDestroyedCallbackForTesting = onDestroyedCallbackForTesting;
}
}
19
Source : CronetUrlRequest.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
@VisibleForTesting
public long getUrlRequestAdapterForTesting() {
synchronized (mUrlRequestAdapterLock) {
return mUrlRequestAdapter;
}
}
19
Source : CronetUploadDataStream.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
@VisibleForTesting
void setOnDestroyedCallbackForTesting(Runnable onDestroyedCallbackForTesting) {
mOnDestroyedCallbackForTesting = onDestroyedCallbackForTesting;
}
19
Source : CronetUploadDataStream.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
/**
* Creates a native CronetUploadDataStreamAdapter and
* CronetUploadDataStream for testing.
* @return the address of the native CronetUploadDataStream object.
*/
@VisibleForTesting
public long createUploadDataStreamForTesting() throws IOException {
synchronized (mLock) {
mUploadDataStreamAdapter = nativeCreateAdapterForTesting();
mLength = mDataProvider.getLength();
mRemainingLength = mLength;
return nativeCreateUploadDataStreamForTesting(mLength, mUploadDataStreamAdapter);
}
}
19
Source : CronetBidirectionalStream.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
/**
* Returns a read-only copy of {@code mPendingData} for testing.
*/
@VisibleForTesting
public List<ByteBuffer> getPendingDataForTesting() {
synchronized (mNativeStreamLock) {
List<ByteBuffer> pendingData = new LinkedList<ByteBuffer>();
for (ByteBuffer buffer : mPendingData) {
pendingData.add(buffer.asReadOnlyBuffer());
}
return pendingData;
}
}
19
Source : CronetBidirectionalStream.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
@VisibleForTesting
public void setOnDestroyedCallbackForTesting(Runnable onDestroyedCallbackForTesting) {
mOnDestroyedCallbackForTesting = onDestroyedCallbackForTesting;
}
19
Source : CronetBidirectionalStream.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
/**
* Returns a read-only copy of {@code mFlushData} for testing.
*/
@VisibleForTesting
public List<ByteBuffer> getFlushDataForTesting() {
synchronized (mNativeStreamLock) {
List<ByteBuffer> flushData = new LinkedList<ByteBuffer>();
for (ByteBuffer buffer : mFlushData) {
flushData.add(buffer.asReadOnlyBuffer());
}
return flushData;
}
}
19
Source : BidirectionalStreamNetworkException.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
/**
* Used in {@link CronetBidirectionalStream}. Implements {@link NetworkExceptionImpl}.
*/
@VisibleForTesting
public clreplaced BidirectionalStreamNetworkException extends NetworkExceptionImpl {
public BidirectionalStreamNetworkException(String message, int errorCode, int cronetInternalErrorCode) {
super(message, errorCode, cronetInternalErrorCode);
}
@Override
public boolean immediatelyRetryable() {
switch(mCronetInternalErrorCode) {
case NetError.ERR_SPDY_PING_FAILED:
case NetError.ERR_QUIC_HANDSHAKE_FAILED:
replacedert mErrorCode == ERROR_OTHER;
return true;
default:
return super.immediatelyRetryable();
}
}
}
19
Source : HttpNegotiateAuthenticator.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
/**
* @param accountType The Android account type to use.
*/
@VisibleForTesting
@CalledByNative
static HttpNegotiateAuthenticator create(String accountType) {
return new HttpNegotiateAuthenticator(accountType);
}
19
Source : RecordUserAction.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
/**
* Tests may not have native initialized, so they may need to disable metrics. The value should
* be reset after the test done, to avoid carrying over state to unrelated tests.
*/
@VisibleForTesting
public static void setDisabledForTests(boolean disabled) {
if (disabled && sDisabledBy != null) {
throw new IllegalStateException("UserActions are already disabled.", sDisabledBy);
}
sDisabledBy = disabled ? new Throwable() : null;
}
19
Source : RecordHistogram.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
/**
* Returns the number of samples recorded in the given bucket of the given histogram.
* @param name name of the histogram to look up
* @param sample the bucket containing this sample value will be looked up
*/
@VisibleForTesting
public static int getHistogramValueCountForTesting(String name, int sample) {
return nativeGetHistogramValueCountForTesting(name, sample);
}
19
Source : RecordHistogram.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
/**
* Tests may not have native initialized, so they may need to disable metrics. The value should
* be reset after the test done, to avoid carrying over state to unrelated tests.
*
* In JUnit tests this can be done automatically using
* {@link org.chromium.chrome.browser.DisableHistogramsRule}
*/
@VisibleForTesting
public static void setDisabledForTests(boolean disabled) {
if (disabled && sDisabledBy != null) {
throw new IllegalStateException("Histograms are already disabled.", sDisabledBy);
}
sDisabledBy = disabled ? new Throwable() : null;
}
19
Source : RecordHistogram.java
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
with BSD 3-Clause "New" or "Revised" License
from lizhangqu
/**
* Returns the number of samples recorded for the given histogram.
* @param name name of the histogram to look up.
*/
@VisibleForTesting
public static int getHistogramTotalCountForTesting(String name) {
return nativeGetHistogramTotalCountForTesting(name);
}
19
Source : ToolbarProgressBar.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* @return The number of times the progress bar has been triggered.
*/
@VisibleForTesting
public int getStartCountForTesting() {
return mProgressStartCount;
}
19
Source : ToolbarProgressBar.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Set alpha show&hide animation duration. This is for faster testing.
* @param alphaAnimationDurationMs Alpha animation duration in milliseconds.
*/
@VisibleForTesting
public void setAlphaAnimationDuration(long alphaAnimationDurationMs) {
mAlphaAnimationDurationMs = alphaAnimationDurationMs;
}
19
Source : ToolbarProgressBar.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Set hiding delay duration. This is for faster testing.
* @param hidngDelayMs Hiding delay duration in milliseconds.
*/
@VisibleForTesting
public void setHidingDelay(long hidngDelayMs) {
mHidingDelayMs = hidngDelayMs;
}
19
Source : ToolbarProgressBar.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Reset the number of times the progress bar has been triggered.
*/
@VisibleForTesting
public void resetStartCountForTesting() {
mProgressStartCount = 0;
}
19
Source : OverviewListLayout.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
public ViewGroup getContainer() {
return mTabModelWrapper;
}
19
Source : FindToolbar.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Returns whether an animation to show/hide the FindToolbar is currently running.
*/
@VisibleForTesting
public boolean isAnimating() {
return false;
}
19
Source : FindToolbar.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
public FindResultBar getFindResultBar() {
return mResultBar;
}
19
Source : AccessibilityTabModelListItem.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
public void disableAnimations() {
mCloseAnimationDurationMs = 0;
mDefaultAnimationDurationMs = 0;
mCloseTimeoutMs = 0;
}
19
Source : WebappUrlBar.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* @return the security icon being displayed for the current URL.
*/
@VisibleForTesting
protected int getCurrentIconResourceForTests() {
return mCurrentIconResource;
}
19
Source : WebappUrlBar.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* @return the URL being displayed.
*/
@VisibleForTesting
protected CharSequence getDisplayedUrlForTests() {
return mUrlBar.getText();
}
19
Source : WebappDataStorage.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Sets the clock used to get the current time.
*/
@VisibleForTesting
public static void setClockForTests(Clock clock) {
sClock = clock;
}
19
Source : WebappDataStorage.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Sets the factory used to generate WebappDataStorage objects.
*/
@VisibleForTesting
public static void setFactoryForTests(Factory factory) {
sFactory = factory;
}
19
Source : WebappActivity.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
boolean isUrlBarVisible() {
return findViewById(R.id.control_container).getVisibility() == View.VISIBLE;
}
19
Source : WebappActivity.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
WebappUrlBar getUrlBarForTests() {
return mUrlBar;
}
19
Source : WebappActivity.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
ViewGroup getSplashScreenForTests() {
return mSplashScreen;
}
19
Source : WebappActivity.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
boolean isSplashScreenVisibleForTests() {
return mSplashScreen != null;
}
19
Source : AddToHomescreenDialog.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
public static AlertDialog getCurrentDialogForTest() {
return sCurrentDialog;
}
19
Source : ActivityAssigner.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Returns the current mapping between Activities and apps.
*/
@VisibleForTesting
List<ActivityEntry> getEntries() {
return mActivityList;
}
19
Source : ActivityAssigner.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
String getPreferenceNumberOfSavedEntries() {
return mPrefNumSavedEntries;
}
19
Source : UrlUtilities.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* @return whether two URLs match, ignoring the #fragment.
*/
@VisibleForTesting
public static boolean urlsMatchIgnoringFragments(String url, String url2) {
if (TextUtils.equals(url, url2))
return true;
return nativeUrlsMatchIgnoringFragments(url, url2);
}
19
Source : UrlUtilities.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* @param url An Android intent:// URL to validate.
*
* @throws URISyntaxException if url is not a valid Android intent://
* URL, as specified at
* https://developer.chrome.com/multidevice/android/intents#syntax.
*/
@VisibleForTesting
public static boolean validateIntentUrl(String url) {
if (url == null) {
Log.d(TAG, "url was null");
return false;
}
URI parsed;
try {
parsed = new URI(url);
} catch (URISyntaxException e) {
// It may be that we received a URI of the form "intent:#Intent...",
// which e.g. Google Authenticator produces. Work around that
// specific case.
if (url.indexOf("intent:#Intent;") == 0) {
return validateIntentUrl(url.replace("intent:#Intent;", "intent://foo/#Intent;"));
}
Log.d(TAG, "Could not parse url '%s': %s", url, e.toString());
return false;
}
String scheme = parsed.getScheme();
if (scheme == null || !scheme.equals("intent")) {
Log.d(TAG, "scheme was not 'intent'");
return false;
}
String hostname = parsed.getHost();
if (hostname == null) {
Log.d(TAG, "hostname was null for '%s'", url);
return false;
}
Matcher m = DNS_HOSTNAME_PATTERN.matcher(hostname);
if (!m.matches()) {
Log.d(TAG, "hostname did not match DNS_HOSTNAME_PATTERN");
return false;
}
String path = parsed.getPath();
if (path == null || (!path.isEmpty() && !path.equals("/"))) {
Log.d(TAG, "path was null or not \"/\"");
return false;
}
// We need to get the raw, unparsed, un-URL-decoded fragment.
// parsed.getFragment() returns a URL-decoded fragment, which can
// interfere with lexing and parsing Intent extras correctly. Therefore,
// we handle the fragment "manually", but first replacedert that it
// URL-decodes correctly.
int fragmentStart = url.indexOf('#');
if (fragmentStart == -1 || fragmentStart == url.length() - 1) {
Log.d(TAG, "Could not find '#'");
return false;
}
String fragment = url.substring(url.indexOf('#') + 1);
try {
String f = parsed.getFragment();
if (f == null) {
Log.d(TAG, "Could not get fragment from parsed URL");
return false;
}
if (!URLDecoder.decode(fragment, "UTF-8").equals(f)) {
Log.d(TAG, "Parsed fragment does not equal lexed fragment");
return false;
}
} catch (UnsupportedEncodingException e) {
Log.d(TAG, e.toString());
return false;
}
// Now lex and parse the correctly-encoded fragment.
String[] parts = fragment.split(";");
if (parts.length < 3 || !parts[0].equals("Intent") || !parts[parts.length - 1].equals("end")) {
Log.d(TAG, "Invalid fragment (not enough parts, lacking Intent, or lacking end)");
return false;
}
boolean seenPackage = false;
boolean seenAction = false;
boolean seenCategory = false;
boolean seenComponent = false;
boolean seenScheme = false;
for (int i = 1; i < parts.length - 1; ++i) {
// This is OK *only* because no valid package, action, category,
// component, or scheme contains (unencoded) "=".
String[] pair = parts[i].split("=");
if (2 != pair.length) {
Log.d(TAG, "Invalid key=value pair '%s'", parts[i]);
return false;
}
m = JAVA_PACKAGE_NAME_PATTERN.matcher(pair[1]);
if (pair[0].equals("package")) {
if (seenPackage || !m.matches()) {
Log.d(TAG, "Invalid package '%s'", pair[1]);
return false;
}
seenPackage = true;
} else if (pair[0].equals("action")) {
if (seenAction || !m.matches()) {
Log.d(TAG, "Invalid action '%s'", pair[1]);
return false;
}
seenAction = true;
} else if (pair[0].equals("category")) {
if (seenCategory || !m.matches()) {
Log.d(TAG, "Invalid category '%s'", pair[1]);
return false;
}
seenCategory = true;
} else if (pair[0].equals("component")) {
Matcher componentMatcher = ANDROID_COMPONENT_NAME_PATTERN.matcher(pair[1]);
if (seenComponent || !componentMatcher.matches()) {
Log.d(TAG, "Invalid component '%s'", pair[1]);
return false;
}
seenComponent = true;
} else if (pair[0].equals("scheme")) {
if (seenScheme)
return false;
Matcher schemeMatcher = URL_SCHEME_PATTERN.matcher(pair[1]);
if (!schemeMatcher.matches()) {
Log.d(TAG, "Invalid scheme '%s'", pair[1]);
return false;
}
seenScheme = true;
} else {
// replacedume we are seeing an Intent Extra. Up above, we ensured
// that the #Intent... fragment was correctly URL-encoded;
// beyond that, there is no further validation we can do. Extras
// are blobs to us.
continue;
}
}
return true;
}
19
Source : UrlUtilities.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* @return whether the #fragmant differs in two URLs.
*/
@VisibleForTesting
public static boolean urlsFragmentsDiffer(String url, String url2) {
if (TextUtils.equals(url, url2))
return false;
return nativeUrlsFragmentsDiffer(url, url2);
}
19
Source : NonThreadSafe.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Changes the thread that is checked for in CalledOnValidThread. This may
* be useful when an object may be created on one thread and then used
* exclusively on another thread.
*/
@SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD")
@VisibleForTesting
public synchronized void detachFromThread() {
mThreadId = null;
}
19
Source : UsbChooserDialog.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
@CalledByNative
void addDevice(String deviceId, String deviceName) {
mItemChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow(deviceId, deviceName));
}
19
Source : TabSwitcherDrawable.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* @return The current tab count this drawable is displaying.
*/
@VisibleForTesting
public int getTabCount() {
return mTabCount;
}
19
Source : CustomTabToolbar.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* @return The custom action button. For test purpose only.
*/
@VisibleForTesting
public ImageButton getCustomActionButtonForTest() {
return mCustomActionButton;
}
19
Source : TabState.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Overrides the channel name for testing.
* @param name Channel to use.
*/
@VisibleForTesting
public static void setChannelNameOverrideForTest(String name) {
sChannelNameOverrideForTest = name;
}
19
Source : TabWindowManager.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Allows overriding the default {@link TabModelSelectorFactory} with another one. Typically
* for testing.
* @param factory A {@link TabModelSelectorFactory} instance.
*/
@VisibleForTesting
public void setTabModelSelectorFactory(TabModelSelectorFactory factory) {
mSelectorFactory = factory;
}
19
Source : DocumentModeAssassin.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Migrates the user from doreplacedent mode to tabbed mode if necessary.
*/
@VisibleForTesting
public final void migrateFromDoreplacedentToTabbedMode() {
ThreadUtils.replacedertOnUiThread();
// Migration is already underway.
if (mStage != STAGE_UNINITIALIZED)
return;
// If migration isn't necessary, don't do anything.
if (!isMigrationNecessary()) {
setStage(STAGE_UNINITIALIZED, STAGE_DONE);
return;
}
// If we've crashed or failed too many times, send them to tabbed mode without their data.
// - Any incorrect or invalid files in the tabbed mode directory will be wiped out by the
// TabPersistentStore when the ChromeTabbedActivity starts.
//
// - If it crashes in the step after being migrated, then the user will simply be left
// with a bunch of inaccessible doreplacedent mode data instead of being stuck trying to
// migrate, which is a lesser evil. This case will be caught by the check above to see if
// migration is even necessary.
SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
int numMigrationAttempts = prefs.getInt(PREF_NUM_MIGRATION_ATTEMPTS, 0);
if (numMigrationAttempts >= MAX_MIGRATION_ATTEMPTS_BEFORE_FAILURE) {
Log.e(TAG, "Too many failures. Migrating user to tabbed mode without data.");
setStage(STAGE_UNINITIALIZED, STAGE_WRITE_TABMODEL_METADATA_DONE);
return;
}
// Kick off the migration pipeline.
// Using apply() instead of commit() seems to save the preference just fine, even if Chrome
// crashes immediately afterward.
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(PREF_NUM_MIGRATION_ATTEMPTS, numMigrationAttempts + 1);
editor.apply();
setStage(STAGE_UNINITIALIZED, STAGE_INITIALIZED);
}
19
Source : OffTheRecordDocumentTabModel.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
public boolean isDoreplacedentTabModelImplCreated() {
return !(getDelegateModel() instanceof EmptyTabModel);
}
19
Source : DocumentTabModelSelector.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Overrides the regular StorageDelegate in the constructor. MUST be called before the
* DoreplacedentTabModelSelector instance is created to take effect.
*/
@VisibleForTesting
public static void setStorageDelegateForTests(StorageDelegate delegate) {
synchronized (STORAGE_DELEGATE_FOR_TESTS_LOCK) {
sStorageDelegateForTests = delegate;
}
}
19
Source : InterceptNavigationDelegateImpl.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
public OverrideUrlLoadingResult getLastOverrideUrlLoadingResultForTests() {
return mLastOverrideUrlLoadingResult;
}
19
Source : SyncCustomizationFragment.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
/**
* Returns the sync action bar switch to enable/disable sync.
*
* @return the mActionBarSwitch
*/
@VisibleForTesting
public ChromeSwitchPreference getSyncSwitchPreference() {
return mSyncSwitchPreference;
}
19
Source : ProfileSyncService.java
with Apache License 2.0
from derry
with Apache License 2.0
from derry
@VisibleForTesting
public static void overrideForTests(ProfileSyncService profileSyncService) {
sProfileSyncService = profileSyncService;
sInitialized = true;
}
See More Examples