Bug 1501108 - [2.3] Add Session Context ID test. r=snorp,baku

Differential Revision: https://phabricator.services.mozilla.com/D20008

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eugen Sawin 2019-04-16 20:25:10 +00:00
parent 2fd75d1a4e
commit c5f6173444
3 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,17 @@
<html>
<head>
<meta charset="UTF-8">
<title>no title</title>
<script>
// If we have a query string, save it to the local storage.
if (window.location.search.length > 0) {
const value = window.location.search.substr(1);
localStorage.setItem("ctx", value);
}
// Set the title to reflect the local storage value.
document.title = "storage=" + localStorage.getItem("ctx");
</script>
</head>
<body></body>
</html>

View File

@ -54,6 +54,7 @@ open class BaseSessionTest(noErrorCollector: Boolean = false) {
const val AUTOPLAY_PATH = "/assets/www/autoplay.html"
const val SCROLL_TEST_PATH = "/assets/www/scroll.html"
const val COLORS_HTML_PATH = "/assets/www/colors.html"
const val STORAGE_TITLE_HTML_PATH = "/assets/www/reflect_local_storage_into_title.html"
}
@get:Rule val sessionRule = GeckoSessionTestRule()

View File

@ -1171,4 +1171,75 @@ class NavigationDelegateTest : BaseSessionTest() {
mainSession.loadTestPath(HELLO_HTML_PATH)
sessionRule.waitForPageStop()
}
@WithDevToolsAPI
@Test fun sessionContextId() {
val session1 = sessionRule.createOpenSession(
GeckoSessionSettings.Builder(mainSession.settings)
.contextId("1")
.build())
session1.loadTestPath(STORAGE_TITLE_HTML_PATH + "?ctx1")
session1.waitForPageStop()
session1.forCallbacksDuringWait(object: Callbacks.ContentDelegate {
@AssertCalled(count = 1)
override fun onTitleChange(session: GeckoSession, title: String?) {
assertThat("Title should not be empty", title, not(isEmptyOrNullString()))
assertThat("Title should match", title,
equalTo("storage=ctx1"))
}
})
session1.loadTestPath(STORAGE_TITLE_HTML_PATH)
session1.waitForPageStop()
session1.forCallbacksDuringWait(object: Callbacks.ContentDelegate {
@AssertCalled(count = 1)
override fun onTitleChange(session: GeckoSession, title: String?) {
assertThat("Title should not be empty", title, not(isEmptyOrNullString()))
assertThat("Title should match", title,
equalTo("storage=ctx1"))
}
})
val session2 = sessionRule.createOpenSession(
GeckoSessionSettings.Builder(mainSession.settings)
.contextId("2")
.build())
session2.loadTestPath(STORAGE_TITLE_HTML_PATH)
session2.waitForPageStop()
session2.forCallbacksDuringWait(object: Callbacks.ContentDelegate {
@AssertCalled(count = 1)
override fun onTitleChange(session: GeckoSession, title: String?) {
assertThat("Title should not be empty", title, not(isEmptyOrNullString()))
assertThat("Title should match", title,
equalTo("storage=null"))
}
})
session2.loadTestPath(STORAGE_TITLE_HTML_PATH + "?ctx2")
session2.waitForPageStop()
session2.forCallbacksDuringWait(object: Callbacks.ContentDelegate {
@AssertCalled(count = 1)
override fun onTitleChange(session: GeckoSession, title: String?) {
assertThat("Title should not be empty", title, not(isEmptyOrNullString()))
assertThat("Title should match", title,
equalTo("storage=ctx2"))
}
})
session1.loadTestPath(STORAGE_TITLE_HTML_PATH)
session1.waitForPageStop()
session1.forCallbacksDuringWait(object: Callbacks.ContentDelegate {
@AssertCalled(count = 1)
override fun onTitleChange(session: GeckoSession, title: String?) {
assertThat("Title should not be empty", title, not(isEmptyOrNullString()))
assertThat("Title should match", title,
equalTo("storage=ctx1"))
}
})
}
}