• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5from autotest_lib.client.cros.enterprise import enterprise_policy_base
6
7
8class policy_ExtensionControl(
9        enterprise_policy_base.EnterprisePolicyTest):
10    """
11    Test effect of multiple Extension control policies on Chrome OS.
12
13    Test ExtensionInstallBlacklist prevents configured extensions from being
14        installed.
15    Test ExtensionInstallWhitelist does not prevent extensions from being
16        installed.
17    Test ExtensionInstallForcelist automatically installs configured
18        extensions.
19    Test when the ExtensionInstallBlacklist is set to '*', and an extension is
20        on the ExtensionInstallWhitelist, it can be installed, showing the
21        Whitelist takes priority over the Blacklist.
22
23    """
24    version = 1
25    EXTENSION_ID = 'hoppbgdeajkagempifacalpdapphfoai'
26    EXTENSION_PAGE = ('chrome://extensions/?id=%s'
27                           % EXTENSION_ID)
28    BLOCK_MSG = '/{}"\) is blocked/'.format(EXTENSION_ID)
29    DOWNLOAD_URL = ('https://chrome.google.com/webstore/detail/platformkeys-test-extensi/{}'
30                    .format(EXTENSION_ID))
31
32    def _ext_check(self):
33        """Verifies the extension install permissions are correct."""
34
35        self.navigate_to_url(self.DOWNLOAD_URL)
36
37        if 'ExtensionInstallForcelist' in self.pol_setting:
38            # If the extension is installed, the Remove button will be present.
39            self.ui.wait_for_ui_obj('Remove from Chrome', role='button')
40        else:
41            # Wait for the "Add to Chrome" button to load and click on it.
42            self.ui.wait_for_ui_obj('Add to Chrome', role='button')
43            self.ui.doDefault_on_obj('Add to Chrome', role='button')
44            if ('ExtensionInstallWhitelist' in self.pol_setting):
45                self.ui.wait_for_ui_obj('Add extension', role='button')
46                self.ui.did_obj_not_load(self.BLOCK_MSG, isRegex=True)
47            else:
48                self.ui.wait_for_ui_obj(self.BLOCK_MSG, isRegex=True)
49
50    def _update_policy(self):
51        """
52        Update the policy Blacklist to '*', and add the autotest extension to
53        the Whitelist.
54
55        NOTE: This is being done after the initial setup_case has been run to
56        avoid an issue where the autotest extension will not load with the
57        blacklist set to '*', even with it on the Whitelist. This caused the
58        test to error and fail. Probably a race on the policy loading.
59
60        """
61
62        self.pol_setting['ExtensionInstallBlacklist'] = ['*']
63        # Updating the fake DM server, and checking policy page.
64        self.fake_dm_server.setup_policy(self._make_json_blob(
65            user_policies=self.pol_setting))
66        self.reload_policies()
67        self.verify_policy_stats(self.pol_setting)
68
69    def _configure_test(self, case):
70        """
71        Configures the test variables.
72
73        @param case: Name of the test case to run.
74
75        """
76        # Used during the test run.
77        autotest_id = 'behllobkkfkfnphdnhnkndlbkcpglgmj'
78
79        if 'Whitelist' in case:
80            self.pol_setting['ExtensionInstallWhitelist'] = [self.EXTENSION_ID,
81                                                             autotest_id]
82        if 'Blacklist' in case and 'Whitelist' not in case:
83            self.pol_setting['ExtensionInstallBlacklist'] = [self.EXTENSION_ID]
84        if 'Force_Install' in case:
85            self.pol_setting['ExtensionInstallForcelist'] = [self.EXTENSION_ID]
86
87    def run_once(self, case):
88        """
89        Setup and run the test configured for the specified test case.
90
91        @param case: Name of the test case to run.
92
93        """
94        self.pol_setting = {}
95
96        self._configure_test(case)
97        self.setup_case(user_policies=self.pol_setting)
98        self.ui.start_ui_root(self.cr)
99        # In this case there is both a Whitelist and Blacklist.
100        if len(case) > 1:
101            self._update_policy()
102
103        self._ext_check()
104