Skip to content

Commit

Permalink
Add tests for basic context switching.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunesacar committed Jan 22, 2019
1 parent e71605e commit 94390ac
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions tbselenium/test/test_context_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
from tbselenium.test import TBB_PATH
from tbselenium.test.fixtures import TBDriverFixture
from tbselenium.common import CHECK_TPO_URL
from selenium.common.exceptions import WebDriverException

# based on https://stackoverflow.com/a/6549765
ENUMERATE_FONTS = """
var font_enumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
.getService(Components.interfaces.nsIFontEnumerator);
return enumerator.EnumerateAllFonts({});"""
var font_enumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
.getService(Components.interfaces.nsIFontEnumerator);
return font_enumerator.EnumerateAllFonts({});"""

COMPONENT_CLASSES_JS = "var c = Components.classes; return c;"


class TestGeckoDriverChromeScript(unittest.TestCase):

def test_bundled_font_via_chrome_script(self):
def test_should_not_run_chrome_script_without_context_switch(self):
with self.assertRaises(WebDriverException):
with TBDriverFixture(TBB_PATH) as driver:
driver.execute_script(COMPONENT_CLASSES_JS)

def test_should_run_chrome_script(self):
with TBDriverFixture(TBB_PATH) as driver:
driver.set_context('chrome')
driver.execute_script(COMPONENT_CLASSES_JS)

def test_bundled_fonts_via_chrome_script(self):
# do not disable this pref when crawling untrusted sites
pref_dict = {"dom.ipc.cpows.forbid-unsafe-from-browser": False}

Expand Down

0 comments on commit 94390ac

Please sign in to comment.