diff --git a/README.md b/README.md index c6e53970..a8b13c2c 100644 --- a/README.md +++ b/README.md @@ -487,11 +487,11 @@ provided, such as: a version number within a defined [VersionRange](https://github.com/openid/AppAuth-Android/blob/master/library/java/net/openid/appauth/browser/VersionRange.java). This class also provides some static instances for matching Chrome, Firefox and Samsung SBrowser. -- [BrowserWhitelist](https://github.com/openid/AppAuth-Android/blob/master/library/java/net/openid/appauth/browser/BrowserWhitelist.java): +- [BrowserAllowList](https://github.com/openid/AppAuth-Android/blob/master/library/java/net/openid/appauth/browser/BrowserAllowList.java): takes a list of BrowserMatcher instances, and will match a browser if any of these child BrowserMatcher instances signals a match. -- [BrowserBlacklist](https://github.com/openid/AppAuth-Android/blob/master/library/java/net/openid/appauth/browser/BrowserBlacklist.java): - the inverse of BrowserWhitelist - takes a list of browser matcher instances, +- [BrowserDenyList](https://github.com/openid/AppAuth-Android/blob/master/library/java/net/openid/appauth/browser/BrowserDenyList.java): + the inverse of BrowserAllowList - takes a list of browser matcher instances, and will match a browser if it _does not_ match any of these child BrowserMatcher instances. @@ -500,7 +500,7 @@ or SBrowser as a custom tab: ```java AppAuthConfiguration appAuthConfig = new AppAuthConfiguration.Builder() - .setBrowserMatcher(new BrowserWhitelist( + .setBrowserMatcher(new BrowserAllowList( VersionedBrowserMatcher.CHROME_CUSTOM_TAB, VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB)) .build(); @@ -513,7 +513,7 @@ Samsung SBrowser: ```java AppAuthConfiguration appAuthConfig = new AppAuthConfiguration.Builder() - .setBrowserMatcher(new BrowserBlacklist( + .setBrowserMatcher(new BrowserDenyList( new VersionedBrowserMatcher( Browsers.SBrowser.PACKAGE_NAME, Browsers.SBrowser.SIGNATURE_SET, diff --git a/config/testdeps.gradle b/config/testdeps.gradle index e6180f01..1a670e35 100644 --- a/config/testdeps.gradle +++ b/config/testdeps.gradle @@ -3,3 +3,4 @@ testImplementation 'org.mockito:mockito-core:2.19.0' testImplementation 'org.robolectric:robolectric:3.8' testImplementation 'com.squareup.assertj:assertj-android:1.2.0' testImplementation 'org.assertj:assertj-core:3.10.0' +testImplementation 'xmlpull:xmlpull:1.1.3.1' diff --git a/library/java/net/openid/appauth/browser/BrowserAllowList.java b/library/java/net/openid/appauth/browser/BrowserAllowList.java new file mode 100644 index 00000000..0b69fd8a --- /dev/null +++ b/library/java/net/openid/appauth/browser/BrowserAllowList.java @@ -0,0 +1,64 @@ +/* + * Copyright 2016 The AppAuth for Android Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openid.appauth.browser; + +import androidx.annotation.NonNull; + +import java.util.Arrays; +import java.util.List; + +/** + * A allowList of browsers which can be used as part of an authorization flows. Examples: + * + * ```java + * // only allow Chrome, and only as a standalone browser + * new BrowserAllowList(VersionedBrowserMatcher.CHROME_BROWSER); + * + * // allow Chrome custom tabs only, but exclude a version range + * new BrowserAllowList( + * new VersionedBrowserMatcher( + * Browsers.Chrome.PACKAGE_NAME, + * Browsers.Chrome.SIGNATURE_SET, + * true, + * VersionRange.atMost("45.1")), + * new VersionedBrowserMatcher( + * Browsers.Chrome.PACKAGE_NAME, + * Browsers.Chrome.SIGNATURE_SET, + * true, + * VersionRange.atLeast("45.3")); + * ``` + */ +public class BrowserAllowList implements BrowserMatcher { + + private List mBrowserMatchers; + + /** + * Creates a browser allowList, which will match if any of the provided matchers do. + */ + public BrowserAllowList(BrowserMatcher... matchers) { + mBrowserMatchers = Arrays.asList(matchers); + } + + @Override + public boolean matches(@NonNull BrowserDescriptor descriptor) { + for (BrowserMatcher matcher : mBrowserMatchers) { + if (matcher.matches(descriptor)) { + return true; + } + } + + return false; + } +} diff --git a/library/java/net/openid/appauth/browser/BrowserBlacklist.java b/library/java/net/openid/appauth/browser/BrowserBlacklist.java index ff71ea56..4fd15283 100644 --- a/library/java/net/openid/appauth/browser/BrowserBlacklist.java +++ b/library/java/net/openid/appauth/browser/BrowserBlacklist.java @@ -14,55 +14,27 @@ package net.openid.appauth.browser; -import androidx.annotation.NonNull; - -import java.util.Arrays; -import java.util.List; - /** - * A blacklist of browsers. This will reject a match for any browser on the list, and permit - * all others. Examples: - * - * ```java - * // blacklist Chrome, whether using a custom tab or not - * new BrowserBlacklist( - * VersionedBrowserMatcher.CHROME_BROWSER, - * VersionedBrowserMatcher.CHROME_CUSTOM_TAB); - * - * // blacklist Firefox - * new BrowserBlacklist( - * VersionedBrowserMatcher.FIREFOX_BROWSER, - * VersionedBrowserMatcher.FIREFOX_CUSTOM_TAB); - * - * // blacklist Dolphin Browser - * new BrowserBlacklist( - * new VersionedBrowserMatcher( - * "mobi.mgeek.TunnyBrowser", - * "", - * false, - * VersionRange.ANY_VERSION)); - * } - * ``` + * This class is deprecated in favor of BrowserDenyList, + * and will be removed completely in the next major version */ -public class BrowserBlacklist implements BrowserMatcher { - - private List mBrowserMatchers; - +@Deprecated +public class BrowserBlacklist extends BrowserDenyList { /** - * Creates a blacklist from the provided set of matchers. + * This class is deprecated in favor of BrowserDenyList, + * and will be removed completely in the next major version */ + @Deprecated public BrowserBlacklist(BrowserMatcher... matchers) { - mBrowserMatchers = Arrays.asList(matchers); + super(matchers); } - @Override - public boolean matches(@NonNull BrowserDescriptor descriptor) { - for (BrowserMatcher matcher : mBrowserMatchers) { - if (matcher.matches(descriptor)) { - return false; - } - } - - return true; + /** + * This class is deprecated in favor of BrowserDenyList, + * and will be removed completely in the next major version + */ + @Deprecated + public BrowserBlacklist() { } + } diff --git a/library/java/net/openid/appauth/browser/BrowserDenyList.java b/library/java/net/openid/appauth/browser/BrowserDenyList.java new file mode 100644 index 00000000..88219d4b --- /dev/null +++ b/library/java/net/openid/appauth/browser/BrowserDenyList.java @@ -0,0 +1,68 @@ +/* + * Copyright 2016 The AppAuth for Android Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openid.appauth.browser; + +import androidx.annotation.NonNull; + +import java.util.Arrays; +import java.util.List; + +/** + * A denyList of browsers. This will reject a match for any browser on the list, and permit + * all others. Examples: + * + * ```java + * // denyList Chrome, whether using a custom tab or not + * new BrowserDenyList( + * VersionedBrowserMatcher.CHROME_BROWSER, + * VersionedBrowserMatcher.CHROME_CUSTOM_TAB); + * + * // denyList Firefox + * new BrowserDenyList( + * VersionedBrowserMatcher.FIREFOX_BROWSER, + * VersionedBrowserMatcher.FIREFOX_CUSTOM_TAB); + * + * // denyList Dolphin Browser + * new BrowserDenyList( + * new VersionedBrowserMatcher( + * "mobi.mgeek.TunnyBrowser", + * "", + * false, + * VersionRange.ANY_VERSION)); + * } + * ``` + */ +public class BrowserDenyList implements BrowserMatcher { + + private List mBrowserMatchers; + + /** + * Creates a denyList from the provided set of matchers. + */ + public BrowserDenyList(BrowserMatcher... matchers) { + mBrowserMatchers = Arrays.asList(matchers); + } + + @Override + public boolean matches(@NonNull BrowserDescriptor descriptor) { + for (BrowserMatcher matcher : mBrowserMatchers) { + if (matcher.matches(descriptor)) { + return false; + } + } + + return true; + } +} diff --git a/library/java/net/openid/appauth/browser/BrowserWhitelist.java b/library/java/net/openid/appauth/browser/BrowserWhitelist.java index e11cff0f..3533fdf9 100644 --- a/library/java/net/openid/appauth/browser/BrowserWhitelist.java +++ b/library/java/net/openid/appauth/browser/BrowserWhitelist.java @@ -14,51 +14,26 @@ package net.openid.appauth.browser; -import androidx.annotation.NonNull; - -import java.util.Arrays; -import java.util.List; - /** - * A whitelist of browsers which can be used as part of an authorization flows. Examples: - * - * ```java - * // only allow Chrome, and only as a standalone browser - * new BrowserWhitelist(VersionedBrowserMatcher.CHROME_BROWSER); - * - * // allow Chrome custom tabs only, but exclude a version range - * new BrowserWhitelist( - * new VersionedBrowserMatcher( - * Browsers.Chrome.PACKAGE_NAME, - * Browsers.Chrome.SIGNATURE_SET, - * true, - * VersionRange.atMost("45.1")), - * new VersionedBrowserMatcher( - * Browsers.Chrome.PACKAGE_NAME, - * Browsers.Chrome.SIGNATURE_SET, - * true, - * VersionRange.atLeast("45.3")); - * ``` + * This class is deprecated in favor of BrowserAllowList, + * and will be removed completely in the next major version */ -public class BrowserWhitelist implements BrowserMatcher { - - private List mBrowserMatchers; - +@Deprecated +public class BrowserWhitelist extends BrowserAllowList { /** - * Creates a browser whitelist, which will match if any of the provided matchers do. + * This class is deprecated in favor of BrowserAllowList, + * and will be removed completely in the next major version */ + @Deprecated public BrowserWhitelist(BrowserMatcher... matchers) { - mBrowserMatchers = Arrays.asList(matchers); + super(matchers); } - @Override - public boolean matches(@NonNull BrowserDescriptor descriptor) { - for (BrowserMatcher matcher : mBrowserMatchers) { - if (matcher.matches(descriptor)) { - return true; - } - } - - return false; + /** + * This class is deprecated in favor of BrowserAllowList, + * and will be removed completely in the next major version + */ + @Deprecated + public BrowserWhitelist() { } } diff --git a/library/java/net/openid/appauth/browser/VersionedBrowserMatcher.java b/library/java/net/openid/appauth/browser/VersionedBrowserMatcher.java index 3daa7dd2..f4b09ffe 100644 --- a/library/java/net/openid/appauth/browser/VersionedBrowserMatcher.java +++ b/library/java/net/openid/appauth/browser/VersionedBrowserMatcher.java @@ -21,7 +21,7 @@ /** * Matches a browser based on its package name, set of signatures, version and whether it is - * being used as a custom tab. This can be used as part of a browser whitelist or blacklist. + * being used as a custom tab. This can be used as part of a browser allowList or denyList. */ public class VersionedBrowserMatcher implements BrowserMatcher { diff --git a/library/javatests/net/openid/appauth/browser/BrowserWhitelistTest.java b/library/javatests/net/openid/appauth/browser/BrowserAllowListTest.java similarity index 56% rename from library/javatests/net/openid/appauth/browser/BrowserWhitelistTest.java rename to library/javatests/net/openid/appauth/browser/BrowserAllowListTest.java index a8c18e5f..a550d7ba 100644 --- a/library/javatests/net/openid/appauth/browser/BrowserWhitelistTest.java +++ b/library/javatests/net/openid/appauth/browser/BrowserAllowListTest.java @@ -24,52 +24,52 @@ @RunWith(RobolectricTestRunner.class) @Config(constants = BuildConfig.class, sdk=16) -public class BrowserWhitelistTest { +public class BrowserAllowListTest { @Test - public void testMatches_emptyWhitelist() { - BrowserWhitelist whitelist = new BrowserWhitelist(); - assertThat(whitelist.matches(Browsers.Chrome.customTab("46"))).isFalse(); - assertThat(whitelist.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); - assertThat(whitelist.matches(Browsers.Firefox.customTab("57"))).isFalse(); - assertThat(whitelist.matches(Browsers.SBrowser.standaloneBrowser("11"))).isFalse(); + public void testMatches_emptyAllowList() { + BrowserAllowList allowList = new BrowserAllowList(); + assertThat(allowList.matches(Browsers.Chrome.customTab("46"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.customTab("57"))).isFalse(); + assertThat(allowList.matches(Browsers.SBrowser.standaloneBrowser("11"))).isFalse(); } @Test public void testMatches_chromeBrowserOnly() { - BrowserWhitelist whitelist = new BrowserWhitelist(VersionedBrowserMatcher.CHROME_BROWSER); - assertThat(whitelist.matches(Browsers.Chrome.standaloneBrowser("46"))).isTrue(); - assertThat(whitelist.matches(Browsers.Chrome.customTab("46"))).isFalse(); - assertThat(whitelist.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); - assertThat(whitelist.matches(Browsers.Firefox.customTab("57"))).isFalse(); + BrowserAllowList allowList = new BrowserAllowList(VersionedBrowserMatcher.CHROME_BROWSER); + assertThat(allowList.matches(Browsers.Chrome.standaloneBrowser("46"))).isTrue(); + assertThat(allowList.matches(Browsers.Chrome.customTab("46"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.customTab("57"))).isFalse(); } @Test public void testMatches_chromeCustomTabOrBrowser() { - BrowserWhitelist whitelist = new BrowserWhitelist( + BrowserAllowList allowList = new BrowserAllowList( VersionedBrowserMatcher.CHROME_BROWSER, VersionedBrowserMatcher.CHROME_CUSTOM_TAB); - assertThat(whitelist.matches(Browsers.Chrome.standaloneBrowser("46"))).isTrue(); - assertThat(whitelist.matches(Browsers.Chrome.customTab("46"))).isTrue(); - assertThat(whitelist.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); - assertThat(whitelist.matches(Browsers.Firefox.customTab("57"))).isFalse(); + assertThat(allowList.matches(Browsers.Chrome.standaloneBrowser("46"))).isTrue(); + assertThat(allowList.matches(Browsers.Chrome.customTab("46"))).isTrue(); + assertThat(allowList.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.customTab("57"))).isFalse(); } @Test public void testMatches_firefoxOrSamsung() { - BrowserWhitelist whitelist = new BrowserWhitelist( + BrowserAllowList allowList = new BrowserAllowList( VersionedBrowserMatcher.FIREFOX_BROWSER, VersionedBrowserMatcher.FIREFOX_CUSTOM_TAB, VersionedBrowserMatcher.SAMSUNG_BROWSER, VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB); - assertThat(whitelist.matches(Browsers.Chrome.standaloneBrowser("46"))).isFalse(); - assertThat(whitelist.matches(Browsers.Chrome.customTab("46"))).isFalse(); - assertThat(whitelist.matches(Browsers.Firefox.standaloneBrowser("10"))).isTrue(); - assertThat(whitelist.matches(Browsers.Firefox.customTab("56"))).isFalse(); - assertThat(whitelist.matches(Browsers.Firefox.customTab("57"))).isTrue(); - assertThat(whitelist.matches(Browsers.SBrowser.standaloneBrowser("10"))).isTrue(); - assertThat(whitelist.matches(Browsers.SBrowser.customTab("4.0"))).isTrue(); - assertThat(whitelist.matches(Browsers.SBrowser.customTab("3.9"))).isFalse(); + assertThat(allowList.matches(Browsers.Chrome.standaloneBrowser("46"))).isFalse(); + assertThat(allowList.matches(Browsers.Chrome.customTab("46"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.standaloneBrowser("10"))).isTrue(); + assertThat(allowList.matches(Browsers.Firefox.customTab("56"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.customTab("57"))).isTrue(); + assertThat(allowList.matches(Browsers.SBrowser.standaloneBrowser("10"))).isTrue(); + assertThat(allowList.matches(Browsers.SBrowser.customTab("4.0"))).isTrue(); + assertThat(allowList.matches(Browsers.SBrowser.customTab("3.9"))).isFalse(); } } diff --git a/library/javatests/net/openid/appauth/browser/BrowserBlacklistTest.java b/library/javatests/net/openid/appauth/browser/BrowserDenyListTest.java similarity index 51% rename from library/javatests/net/openid/appauth/browser/BrowserBlacklistTest.java rename to library/javatests/net/openid/appauth/browser/BrowserDenyListTest.java index 022375c2..253dd6fc 100644 --- a/library/javatests/net/openid/appauth/browser/BrowserBlacklistTest.java +++ b/library/javatests/net/openid/appauth/browser/BrowserDenyListTest.java @@ -24,33 +24,33 @@ @RunWith(RobolectricTestRunner.class) @Config(constants = BuildConfig.class, sdk=16) -public class BrowserBlacklistTest { +public class BrowserDenyListTest { @Test - public void testMatches_emptyBlacklist() { - BrowserBlacklist blacklist = new BrowserBlacklist(); - assertThat(blacklist.matches(Browsers.Chrome.customTab("46"))).isTrue(); - assertThat(blacklist.matches(Browsers.Firefox.standaloneBrowser("10"))).isTrue(); - assertThat(blacklist.matches(Browsers.SBrowser.standaloneBrowser("11"))).isTrue(); + public void testMatches_emptyDenyList() { + BrowserDenyList denyList = new BrowserDenyList(); + assertThat(denyList.matches(Browsers.Chrome.customTab("46"))).isTrue(); + assertThat(denyList.matches(Browsers.Firefox.standaloneBrowser("10"))).isTrue(); + assertThat(denyList.matches(Browsers.SBrowser.standaloneBrowser("11"))).isTrue(); } @Test public void testMatches_singleBrowser() { - BrowserBlacklist blacklist = new BrowserBlacklist(VersionedBrowserMatcher.FIREFOX_BROWSER); - assertThat(blacklist.matches(Browsers.Chrome.customTab("46"))).isTrue(); - assertThat(blacklist.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); - assertThat(blacklist.matches(Browsers.SBrowser.standaloneBrowser("11"))).isTrue(); + BrowserDenyList denyList = new BrowserDenyList(VersionedBrowserMatcher.FIREFOX_BROWSER); + assertThat(denyList.matches(Browsers.Chrome.customTab("46"))).isTrue(); + assertThat(denyList.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); + assertThat(denyList.matches(Browsers.SBrowser.standaloneBrowser("11"))).isTrue(); } @Test public void testMatches_customTabs() { - BrowserBlacklist blacklist = new BrowserBlacklist( + BrowserDenyList denyList = new BrowserDenyList( VersionedBrowserMatcher.CHROME_CUSTOM_TAB, VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB); - assertThat(blacklist.matches(Browsers.Chrome.standaloneBrowser("46"))).isTrue(); - assertThat(blacklist.matches(Browsers.Chrome.customTab("46"))).isFalse(); - assertThat(blacklist.matches(Browsers.SBrowser.standaloneBrowser("11"))).isTrue(); - assertThat(blacklist.matches(Browsers.SBrowser.customTab("11"))).isFalse(); + assertThat(denyList.matches(Browsers.Chrome.standaloneBrowser("46"))).isTrue(); + assertThat(denyList.matches(Browsers.Chrome.customTab("46"))).isFalse(); + assertThat(denyList.matches(Browsers.SBrowser.standaloneBrowser("11"))).isTrue(); + assertThat(denyList.matches(Browsers.SBrowser.customTab("11"))).isFalse(); } } diff --git a/library/javatests/net/openid/appauth/browser/BrowserSelectorTest.java b/library/javatests/net/openid/appauth/browser/BrowserSelectorTest.java index 54fc9bb9..04d5093e 100644 --- a/library/javatests/net/openid/appauth/browser/BrowserSelectorTest.java +++ b/library/javatests/net/openid/appauth/browser/BrowserSelectorTest.java @@ -178,7 +178,7 @@ public void testSelect_ignoreBrowsersWithoutHttpsSupport() @Test public void testSelect_matcherPrefersStandaloneChrome() throws NameNotFoundException { // in this scenario, the user has firefox as their default but the app insists on using - // chrome via a browser whitelist. + // chrome via a browser allowList. setBrowserList(FIREFOX, CHROME, DOLPHIN); setBrowsersWithWarmupSupport(FIREFOX, CHROME); checkSelectedBrowser(CHROME, diff --git a/library/javatests/net/openid/appauth/browser/DeprecationMigrationTest.java b/library/javatests/net/openid/appauth/browser/DeprecationMigrationTest.java new file mode 100644 index 00000000..2734ef75 --- /dev/null +++ b/library/javatests/net/openid/appauth/browser/DeprecationMigrationTest.java @@ -0,0 +1,90 @@ +package net.openid.appauth.browser; + +import net.openid.appauth.BuildConfig; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk=16) +public class DeprecationMigrationTest { + + @Test + public void testMatches_emptyDenyList() { + BrowserDenyList denyList = new BrowserBlacklist(); + assertThat(denyList.matches(Browsers.Chrome.customTab("46"))).isTrue(); + assertThat(denyList.matches(Browsers.Firefox.standaloneBrowser("10"))).isTrue(); + assertThat(denyList.matches(Browsers.SBrowser.standaloneBrowser("11"))).isTrue(); + } + + @Test + public void testMatches_singleBrowser() { + BrowserDenyList denyList = new BrowserBlacklist(VersionedBrowserMatcher.FIREFOX_BROWSER); + assertThat(denyList.matches(Browsers.Chrome.customTab("46"))).isTrue(); + assertThat(denyList.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); + assertThat(denyList.matches(Browsers.SBrowser.standaloneBrowser("11"))).isTrue(); + } + + @Test + public void testMatches_customTabs() { + BrowserDenyList denyList = new BrowserBlacklist( + VersionedBrowserMatcher.CHROME_CUSTOM_TAB, + VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB); + + assertThat(denyList.matches(Browsers.Chrome.standaloneBrowser("46"))).isTrue(); + assertThat(denyList.matches(Browsers.Chrome.customTab("46"))).isFalse(); + assertThat(denyList.matches(Browsers.SBrowser.standaloneBrowser("11"))).isTrue(); + assertThat(denyList.matches(Browsers.SBrowser.customTab("11"))).isFalse(); + } + + + @Test + public void testMatches_emptyAllowList() { + BrowserAllowList allowList = new BrowserWhitelist(); + assertThat(allowList.matches(Browsers.Chrome.customTab("46"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.customTab("57"))).isFalse(); + assertThat(allowList.matches(Browsers.SBrowser.standaloneBrowser("11"))).isFalse(); + } + + @Test + public void testMatches_chromeBrowserOnly() { + BrowserAllowList allowList = new BrowserWhitelist(VersionedBrowserMatcher.CHROME_BROWSER); + assertThat(allowList.matches(Browsers.Chrome.standaloneBrowser("46"))).isTrue(); + assertThat(allowList.matches(Browsers.Chrome.customTab("46"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.customTab("57"))).isFalse(); + } + + @Test + public void testMatches_chromeCustomTabOrBrowser() { + BrowserAllowList allowList = new BrowserWhitelist( + VersionedBrowserMatcher.CHROME_BROWSER, + VersionedBrowserMatcher.CHROME_CUSTOM_TAB); + assertThat(allowList.matches(Browsers.Chrome.standaloneBrowser("46"))).isTrue(); + assertThat(allowList.matches(Browsers.Chrome.customTab("46"))).isTrue(); + assertThat(allowList.matches(Browsers.Firefox.standaloneBrowser("10"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.customTab("57"))).isFalse(); + } + + @Test + public void testMatches_firefoxOrSamsung() { + BrowserAllowList allowList = new BrowserWhitelist( + VersionedBrowserMatcher.FIREFOX_BROWSER, + VersionedBrowserMatcher.FIREFOX_CUSTOM_TAB, + VersionedBrowserMatcher.SAMSUNG_BROWSER, + VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB); + assertThat(allowList.matches(Browsers.Chrome.standaloneBrowser("46"))).isFalse(); + assertThat(allowList.matches(Browsers.Chrome.customTab("46"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.standaloneBrowser("10"))).isTrue(); + assertThat(allowList.matches(Browsers.Firefox.customTab("56"))).isFalse(); + assertThat(allowList.matches(Browsers.Firefox.customTab("57"))).isTrue(); + assertThat(allowList.matches(Browsers.SBrowser.standaloneBrowser("10"))).isTrue(); + assertThat(allowList.matches(Browsers.SBrowser.customTab("4.0"))).isTrue(); + assertThat(allowList.matches(Browsers.SBrowser.customTab("3.9"))).isFalse(); + } +}