1# This Source Code Form is subject to the terms of the Mozilla Public 2# License, v. 2.0. If a copy of the MPL was not distributed with this 3# file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5from __future__ import absolute_import 6 7import copy 8 9import requests 10 11from marionette_harness import MarionetteTestCase 12 13 14class TestCommandLineArguments(MarionetteTestCase): 15 def setUp(self): 16 super(TestCommandLineArguments, self).setUp() 17 18 self.orig_arguments = copy.copy(self.marionette.instance.app_args) 19 20 def tearDown(self): 21 self.marionette.instance.app_args = self.orig_arguments 22 self.marionette.quit(clean=True) 23 24 super(TestCommandLineArguments, self).tearDown() 25 26 def test_debugger_address_cdp_status(self): 27 # By default Remote Agent is not enabled 28 debugger_address = self.marionette.session_capabilities.get( 29 "moz:debuggerAddress" 30 ) 31 self.assertIsNone(debugger_address) 32 33 # With BiDi only enabled the capability doesn't have to be returned 34 self.marionette.enforce_gecko_prefs({"remote.active-protocols": 1}) 35 try: 36 self.marionette.quit() 37 self.marionette.instance.app_args.append("-remote-debugging-port") 38 self.marionette.start_session() 39 40 debugger_address = self.marionette.session_capabilities.get( 41 "moz:debuggerAddress" 42 ) 43 self.assertIsNone(debugger_address) 44 finally: 45 self.marionette.clear_pref("remote.active-protocols") 46 self.marionette.restart() 47 48 # With all protocols enabled the capability has to be returned 49 self.marionette.quit() 50 self.marionette.instance.switch_profile() 51 self.marionette.start_session() 52 53 debugger_address = self.marionette.session_capabilities.get( 54 "moz:debuggerAddress" 55 ) 56 57 self.assertEqual(debugger_address, "localhost:9222") 58 result = requests.get(url="http://{}/json/version".format(debugger_address)) 59 self.assertTrue(result.ok) 60 61 def test_start_in_safe_mode(self): 62 self.marionette.instance.app_args.append("-safe-mode") 63 64 self.marionette.quit() 65 self.marionette.start_session() 66 67 with self.marionette.using_context("chrome"): 68 safe_mode = self.marionette.execute_script( 69 """ 70 Cu.import("resource://gre/modules/Services.jsm"); 71 72 return Services.appinfo.inSafeMode; 73 """ 74 ) 75 self.assertTrue(safe_mode, "Safe Mode has not been enabled") 76 77 def test_startup_timeout(self): 78 try: 79 self.marionette.quit() 80 with self.assertRaisesRegexp(IOError, "Process killed after 0s"): 81 # Use a small enough timeout which should always cause an IOError 82 self.marionette.start_session(timeout=0) 83 finally: 84 self.marionette.start_session() 85