Bug 1332122 - Add unit tests for navigating to file:// URLs. draft
authorHenrik Skupin <mail@hskupin.info>
Wed, 05 Jul 2017 20:24:48 +0200
changeset 604892 13c95b16a634dbd1020412daae01e34825489770
parent 604891 51dceb7d83fa029fa21fbe6676f3e7772ee14c3b
child 636319 e03d61d411e4591c36c2b3eebc599048bff4e61c
push id67218
push userbmo:hskupin@gmail.com
push dateThu, 06 Jul 2017 16:38:41 +0000
bugs1332122
milestone56.0a1
Bug 1332122 - Add unit tests for navigating to file:// URLs. MozReview-Commit-ID: 7GAHkfuvMcB
testing/marionette/harness/marionette_harness/tests/unit/data/test.html
testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
new file mode 100644
--- /dev/null
+++ b/testing/marionette/harness/marionette_harness/tests/unit/data/test.html
@@ -0,0 +1,13 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!DOCTYPE html>
+<html>
+<head>
+<title>Marionette Test</title>
+</head>
+<body>
+  <p id="file-url">Loaded via file://</p>
+</body>
+</html>
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
@@ -1,36 +1,42 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import contextlib
+import os
 import urllib
 
 from marionette_driver import By, errors, expected, Wait
 from marionette_driver.keys import Keys
 from marionette_harness import (
     MarionetteTestCase,
     run_if_e10s,
     run_if_manage_instance,
     skip,
     skip_if_mobile,
     WindowManagerMixin,
 )
 
+here = os.path.abspath(os.path.dirname(__file__))
+
 
 def inline(doc):
     return "data:text/html;charset=utf-8,%s" % urllib.quote(doc)
 
 
 class BaseNavigationTestCase(WindowManagerMixin, MarionetteTestCase):
 
     def setUp(self):
         super(BaseNavigationTestCase, self).setUp()
 
+        file_path = os.path.join(here, 'data', 'test.html').replace("\\", "/")
+
+        self.test_page_file_url = "file:///{}".format(file_path)
         self.test_page_frameset = self.marionette.absolute_url("frameset.html")
         self.test_page_insecure = self.fixtures.where_is("test.html", on="https")
         self.test_page_not_remote = "about:robots"
         self.test_page_remote = self.marionette.absolute_url("test.html")
         self.test_page_slow_resource = self.marionette.absolute_url("slow_resource.html")
 
         if self.marionette.session_capabilities["platformName"] == "darwin":
             self.mod_key = Keys.META
@@ -186,16 +192,35 @@ class TestNavigate(BaseNavigationTestCas
     def test_navigate_hash_change(self):
         doc = inline("<p id=foo>")
         self.marionette.navigate(doc)
         self.marionette.execute_script("window.visited = true", sandbox=None)
         self.marionette.navigate("{}#foo".format(doc))
         self.assertTrue(self.marionette.execute_script(
             "return window.visited", sandbox=None))
 
+    @skip_if_mobile("Test file is only located on host machine")
+    def test_navigate_file_url(self):
+        self.marionette.navigate(self.test_page_file_url)
+        self.marionette.find_element(By.ID, "file-url")
+        self.marionette.navigate(self.test_page_remote)
+
+    @run_if_e10s("Requires e10s mode enabled")
+    @skip_if_mobile("Test file is only located on host machine")
+    def test_navigate_file_url_remoteness_change(self):
+        self.marionette.navigate("about:robots")
+        self.assertFalse(self.is_remote_tab)
+
+        self.marionette.navigate(self.test_page_file_url)
+        self.assertTrue(self.is_remote_tab)
+        self.marionette.find_element(By.ID, "file-url")
+
+        self.marionette.navigate("about:robots")
+        self.assertFalse(self.is_remote_tab)
+
     @skip_if_mobile("Bug 1334095 - Timeout: No new tab has been opened")
     def test_about_blank_for_new_docshell(self):
         self.assertEqual(self.marionette.get_url(), "about:blank")
 
         self.marionette.navigate("about:blank")
 
     @skip("Bug 1332064 - NoSuchElementException: Unable to locate element: :focus")
     @run_if_manage_instance("Only runnable if Marionette manages the instance")
@@ -329,16 +354,25 @@ class TestBackForwardNavigation(BaseNavi
     def test_same_document_hash_change(self):
         test_pages = [
             {"url": "{}#23".format(self.test_page_remote)},
             {"url": self.test_page_remote},
             {"url": "{}#42".format(self.test_page_remote)},
         ]
         self.run_bfcache_test(test_pages)
 
+    @skip_if_mobile("Test file is only located on host machine")
+    def test_file_url(self):
+        test_pages = [
+            {"url": self.test_page_remote},
+            {"url": self.test_page_file_url},
+            {"url": self.test_page_remote},
+        ]
+        self.run_bfcache_test(test_pages)
+
     @skip("Causes crashes for JS GC (bug 1344863) and a11y (bug 1344868)")
     def test_frameset(self):
         test_pages = [
             {"url": self.marionette.absolute_url("frameset.html")},
             {"url": self.test_page_remote},
             {"url": self.marionette.absolute_url("frameset.html")},
         ]
         self.run_bfcache_test(test_pages)
@@ -507,16 +541,24 @@ class TestRefresh(BaseNavigationTestCase
         frame = self.marionette.find_element(By.NAME, "third")
         self.marionette.switch_to_frame(frame)
         self.assertRaises(errors.NoSuchElementException,
                           self.marionette.find_element, By.NAME, "third")
 
         self.marionette.refresh()
         self.marionette.find_element(By.NAME, "third")
 
+    @skip_if_mobile("Test file is only located on host machine")
+    def test_file_url(self):
+        self.marionette.navigate(self.test_page_file_url)
+        self.assertEqual(self.test_page_file_url, self.marionette.get_url())
+
+        self.marionette.refresh()
+        self.assertEqual(self.test_page_file_url, self.marionette.get_url())
+
     def test_image(self):
         image = self.marionette.absolute_url('black.png')
 
         self.marionette.navigate(image)
         self.assertEqual(image, self.marionette.get_url())
 
         self.marionette.refresh()
         self.assertEqual(image, self.marionette.get_url())