1# Copyright 2019 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4from autotest_lib.client.common_lib import error 5from autotest_lib.client.cros.enterprise import enterprise_policy_base 6 7 8class policy_DefaultNotificationsSetting( 9 enterprise_policy_base.EnterprisePolicyTest): 10 """ 11 Test effect of DefaultNotificationsSetting policy on Chrome OS. 12 13 This test will set the policy, then will check the notification.permission 14 js call to determine if the policy worked or not. 15 16 17 """ 18 version = 1 19 20 POLICY_NAME = 'DefaultNotificationsSetting' 21 policy_setting = {'granted': 1, 22 'denied': 2, 23 'default': 3, 24 'not_set': None} 25 26 def _notification_check(self, case): 27 """ 28 Navigates to a page, and check the Notification status. 29 30 @param case: the setting of the DefaultNotificationsSetting Policy 31 32 """ 33 tab = self.navigate_to_url('chrome://policy') 34 35 content = tab.EvaluateJavaScript('Notification.permission') 36 37 # prompt is the default setting 38 if case == 'not_set': 39 case = 'default' 40 if content != case: 41 raise error.TestError('Geolocation Setting did not match setting.' 42 'Expected {e} but received {r}' 43 .format(e=case, r=content)) 44 45 def run_once(self, case): 46 """ 47 Setup and run the test configured for the specified test case. 48 49 @param case: Name of the test case to run. 50 51 """ 52 self.setup_case(user_policies={ 53 self.POLICY_NAME: self.policy_setting[case]}) 54 self._notification_check(case) 55