-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from hotwired/user-agent-prefix
Breaking API change: applications can set a User-Agent prefix
- Loading branch information
Showing
4 changed files
with
66 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 42 additions & 8 deletions
50
core/src/test/kotlin/dev/hotwire/core/bridge/UserAgentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,58 @@ | ||
package dev.hotwire.core.bridge | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import androidx.test.core.app.ApplicationProvider | ||
import dev.hotwire.core.config.Hotwire | ||
import dev.hotwire.core.turbo.BaseUnitTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config(sdk = [Build.VERSION_CODES.R]) | ||
class UserAgentTest : BaseUnitTest() { | ||
private lateinit var context: Context | ||
|
||
@Before | ||
override fun setup() { | ||
super.setup() | ||
context = ApplicationProvider.getApplicationContext() | ||
Hotwire.config.applicationUserAgentPrefix = null | ||
} | ||
|
||
class UserAgentTest { | ||
@Test | ||
fun userAgentSubstring() { | ||
fun `user agent with no prefix`() { | ||
Hotwire.config.registeredBridgeComponentFactories = TestData.componentFactories | ||
|
||
val userAgentSubstring = Hotwire.config.userAgentSubstring() | ||
assertEquals(userAgentSubstring, "Hotwire Native Android; Turbo Native Android; bridge-components: [one two];") | ||
val userAgent = Hotwire.config.userAgent(context) | ||
val expectedUserAgent = | ||
"Hotwire Native Android; Turbo Native Android; " + | ||
"bridge-components: [one two]; " + | ||
TEST_USER_AGENT | ||
|
||
assertEquals(expectedUserAgent, userAgent) | ||
} | ||
|
||
@Test | ||
fun userAgent() { | ||
fun `user agent with prefix`() { | ||
Hotwire.config.applicationUserAgentPrefix = "My Application Prefix;" | ||
Hotwire.config.registeredBridgeComponentFactories = TestData.componentFactories | ||
Hotwire.config.userAgent = "Test; ${Hotwire.config.userAgentSubstring()}" | ||
|
||
val userAgent = Hotwire.config.userAgent | ||
assertEquals(userAgent, "Test; Hotwire Native Android; Turbo Native Android; bridge-components: [one two];") | ||
val userAgent = Hotwire.config.userAgent(context) | ||
val expectedUserAgent = | ||
"My Application Prefix; " + | ||
"Hotwire Native Android; Turbo Native Android; " + | ||
"bridge-components: [one two]; " + | ||
TEST_USER_AGENT | ||
|
||
assertEquals(expectedUserAgent, userAgent) | ||
} | ||
|
||
companion object { | ||
private const val TEST_USER_AGENT = "user" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters