Search in sources :

Example 1 with CustomTabsSessionToken

use of androidx.browser.customtabs.CustomTabsSessionToken in project android-browser-helper by GoogleChrome.

the class TwaLauncherTest method createsDifferentSessions_IfDifferentIdsSpecified.

@Test
public void createsDifferentSessions_IfDifferentIdsSpecified() {
    int sessionId1 = 1;
    int sessionId2 = 2;
    TwaLauncher launcher1 = new TwaLauncher(mActivity, null, sessionId1, new SharedPreferencesTokenStore(mActivity));
    CustomTabsSessionToken token1 = getSessionTokenFromLaunchedBrowser(() -> launcher1.launch(URL));
    launcher1.destroy();
    // New activity is created (e.g. by an external VIEW intent).
    TwaLauncher launcher2 = new TwaLauncher(mActivity, null, sessionId2, new SharedPreferencesTokenStore(mActivity));
    CustomTabsSessionToken token2 = getSessionTokenFromLaunchedBrowser(() -> launcher2.launch(URL));
    launcher2.destroy();
    assertNotEquals(token1, token2);
}
Also used : CustomTabsSessionToken(androidx.browser.customtabs.CustomTabsSessionToken) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Example 2 with CustomTabsSessionToken

use of androidx.browser.customtabs.CustomTabsSessionToken in project android-browser-helper by GoogleChrome.

the class TwaQualityEnforcerTest method triggerQualityEnforcement_NoCrashReason.

@Test
public void triggerQualityEnforcement_NoCrashReason() {
    Runnable launchRunnable = () -> mTwaLauncher.launch(new TrustedWebActivityIntentBuilder(URL), mCustomTabsCallback, null, null);
    CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFromIntent(getBrowserActivityWhenLaunched(launchRunnable).getIntent());
    CustomTabsCallback callback = token.getCallback();
    Bundle args = Bundle.EMPTY;
    Bundle result = callback.extraCallbackWithResult(QualityEnforcer.CRASH, args);
    assertFalse(result.getBoolean(QualityEnforcer.KEY_SUCCESS));
}
Also used : TrustedWebActivityIntentBuilder(androidx.browser.trusted.TrustedWebActivityIntentBuilder) Bundle(android.os.Bundle) CustomTabsSessionToken(androidx.browser.customtabs.CustomTabsSessionToken) CustomTabsCallback(androidx.browser.customtabs.CustomTabsCallback) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Example 3 with CustomTabsSessionToken

use of androidx.browser.customtabs.CustomTabsSessionToken in project android-browser-helper by GoogleChrome.

the class TwaLauncherTest method reusesSessionForSubsequentLaunches.

@Test
public void reusesSessionForSubsequentLaunches() {
    TwaLauncher launcher1 = new TwaLauncher(mActivity);
    CustomTabsSessionToken token1 = getSessionTokenFromLaunchedBrowser(() -> launcher1.launch(URL));
    launcher1.destroy();
    // New activity is created (e.g. by an external VIEW intent).
    TwaLauncher launcher2 = new TwaLauncher(mActivity);
    CustomTabsSessionToken token2 = getSessionTokenFromLaunchedBrowser(() -> launcher2.launch(URL));
    launcher2.destroy();
    assertEquals(token1, token2);
}
Also used : CustomTabsSessionToken(androidx.browser.customtabs.CustomTabsSessionToken) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Example 4 with CustomTabsSessionToken

use of androidx.browser.customtabs.CustomTabsSessionToken in project android-browser-helper by GoogleChrome.

the class TwaQualityEnforcerTest method triggerQualityEnforcement_Crash.

@Test
public void triggerQualityEnforcement_Crash() {
    Runnable launchRunnable = () -> mTwaLauncher.launch(new TrustedWebActivityIntentBuilder(URL), mCustomTabsCallback, null, null);
    CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFromIntent(getBrowserActivityWhenLaunched(launchRunnable).getIntent());
    CustomTabsCallback callback = token.getCallback();
    Bundle args = new Bundle();
    String message = "TestMessage";
    args.putString(QualityEnforcer.KEY_CRASH_REASON, message);
    Bundle result = callback.extraCallbackWithResult(QualityEnforcer.CRASH, args);
    assertTrue(result.getBoolean(QualityEnforcer.KEY_SUCCESS));
    assertTrue(mCrashed);
}
Also used : TrustedWebActivityIntentBuilder(androidx.browser.trusted.TrustedWebActivityIntentBuilder) Bundle(android.os.Bundle) CustomTabsSessionToken(androidx.browser.customtabs.CustomTabsSessionToken) CustomTabsCallback(androidx.browser.customtabs.CustomTabsCallback) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

CustomTabsSessionToken (androidx.browser.customtabs.CustomTabsSessionToken)4 MediumTest (androidx.test.filters.MediumTest)4 Test (org.junit.Test)4 Bundle (android.os.Bundle)2 CustomTabsCallback (androidx.browser.customtabs.CustomTabsCallback)2 TrustedWebActivityIntentBuilder (androidx.browser.trusted.TrustedWebActivityIntentBuilder)2