Bug 1501108 - [2.3] Add Session Context ID test. r=snorp,baku
authorEugen Sawin <esawin@mozilla.com>
Tue, 16 Apr 2019 20:25:10 +0000
changeset 469878 335cec0aacd802843cabef2767ae1f8cd5cfed0a
parent 469877 23a77e063257414dd78aeb70d59e29cd68aa3295
child 469879 99ba286125d17b0172563906642955fcc0946ab9
push id83399
push useresawin@mozilla.com
push dateWed, 17 Apr 2019 16:23:09 +0000
treeherderautoland@8f2d511ad49f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, baku
bugs1501108
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1501108 - [2.3] Add Session Context ID test. r=snorp,baku Differential Revision: https://phabricator.services.mozilla.com/D20008
mobile/android/geckoview/src/androidTest/assets/www/reflect_local_storage_into_title.html
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
new file mode 100644
--- /dev/null
+++ b/mobile/android/geckoview/src/androidTest/assets/www/reflect_local_storage_into_title.html
@@ -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>
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
@@ -49,16 +49,17 @@ open class BaseSessionTest(noErrorCollec
         const val UNKNOWN_HOST_URI = "http://www.test.invalid/"
         const val FULLSCREEN_PATH = "/assets/www/fullscreen.html"
         const val VIEWPORT_PATH = "/assets/www/viewport.html"
         const val IFRAME_REDIRECT_LOCAL = "/assets/www/iframe_redirect_local.html"
         const val IFRAME_REDIRECT_AUTOMATION = "/assets/www/iframe_redirect_automation.html"
         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()
 
     @get:Rule val errors = ErrorCollector()
 
     val mainSession get() = sessionRule.session
 
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
@@ -1166,9 +1166,80 @@ class NavigationDelegateTest : BaseSessi
         // This loads in the parent process
         mainSession.loadUri("about:config")
         sessionRule.waitForPageStop()
 
         // This will load a page in the child
         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"))
+            }
+        })
+    }
 }