@Test public void intentForNativeBrowserScheme_shouldProperlyHandleEncodedUrls() throws UrlParseException { Intent intent; intent = Intents.intentForNativeBrowserScheme( Uri.parse("mopubnativebrowser://navigate?url=https%3A%2F%2Fwww.example.com")); assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW); assertThat(intent.getDataString()).isEqualTo("https://www.example.com"); intent = Intents.intentForNativeBrowserScheme( Uri.parse("mopubnativebrowser://navigate?url=https://www.example.com/?query=1&two=2")); assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW); assertThat(intent.getDataString()).isEqualTo("https://www.example.com/?query=1"); intent = Intents.intentForNativeBrowserScheme( Uri.parse( "mopubnativebrowser://navigate?url=https%3A%2F%2Fwww.example.com%2F%3Fquery%3D1%26two%3D2")); assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW); assertThat(intent.getDataString()).isEqualTo("https://www.example.com/?query=1&two=2"); }
@Test(expected = UrlParseException.class) public void intentForNativeBrowserScheme_whenUrlParameterMissing_shouldThrowException() throws UrlParseException { Intents.intentForNativeBrowserScheme(Uri.parse("mopubnativebrowser://navigate")); }
@Test(expected = UrlParseException.class) public void intentForNativeBrowserScheme_whenNotNavigate_shouldThrowException() throws UrlParseException { Intents.intentForNativeBrowserScheme( Uri.parse("mopubnativebrowser://getout?url=https://www.example.com")); }
@Test(expected = UrlParseException.class) public void intentForNativeBrowserScheme_whenNotMoPubNativeBrowser_shouldThrowException() throws UrlParseException { Intents.intentForNativeBrowserScheme( Uri.parse("mailto://navigate?url=https://www.example.com")); }