[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium 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 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | #include <stdint.h> |
dcheng | 08cfe9ba | 2016-04-14 17:46:45 | [diff] [blame] | 7 | |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 8 | #include <algorithm> |
dcheng | 08cfe9ba | 2016-04-14 17:46:45 | [diff] [blame] | 9 | #include <memory> |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 10 | #include <string> |
dcheng | cf738a9 | 2015-12-31 16:11:45 | [diff] [blame] | 11 | #include <utility> |
[email protected] | 2321f0b | 2012-09-10 01:51:51 | [diff] [blame] | 12 | #include <vector> |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 13 | |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 14 | #include "base/atomic_ref_count.h" |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 15 | #include "base/bind.h" |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 16 | #include "base/bind_helpers.h" |
[email protected] | aecb608 | 2013-07-09 14:29:41 | [diff] [blame] | 17 | #include "base/callback.h" |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 18 | #include "base/callback_helpers.h" |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 19 | #include "base/command_line.h" |
Carlos IL | 798c47c8ce | 2018-11-26 17:30:41 | [diff] [blame] | 20 | #include "base/feature_list.h" |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 21 | #include "base/files/file_enumerator.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 22 | #include "base/files/file_path.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 23 | #include "base/files/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 24 | #include "base/files/scoped_temp_dir.h" |
Sorin Jianu | 55587d3 | 2018-11-14 21:43:27 | [diff] [blame] | 25 | #include "base/json/json_reader.h" |
dcheng | 08cfe9ba | 2016-04-14 17:46:45 | [diff] [blame] | 26 | #include "base/memory/ptr_util.h" |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 27 | #include "base/memory/ref_counted.h" |
Alexander Timin | 4f9c35c | 2018-11-01 20:15:20 | [diff] [blame] | 28 | #include "base/message_loop/message_loop.h" |
Gabriel Charette | bbb7d2f | 2018-04-24 07:58:06 | [diff] [blame] | 29 | #include "base/message_loop/message_loop_current.h" |
Mathieu Perreault | 18170a4 | 2018-05-17 12:48:15 | [diff] [blame] | 30 | #include "base/metrics/histogram_base.h" |
| 31 | #include "base/metrics/histogram_samples.h" |
| 32 | #include "base/metrics/statistics_recorder.h" |
[email protected] | 2321f0b | 2012-09-10 01:51:51 | [diff] [blame] | 33 | #include "base/path_service.h" |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 34 | #include "base/run_loop.h" |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 35 | #include "base/stl_util.h" |
Clark DuVall | 385b5a5 | 2018-06-14 21:33:32 | [diff] [blame] | 36 | #include "base/strings/strcat.h" |
[email protected] | 76fb05c | 2013-06-11 04:38:05 | [diff] [blame] | 37 | #include "base/strings/string16.h" |
felt | 2d3f65e | 2015-05-18 15:26:04 | [diff] [blame] | 38 | #include "base/strings/string_number_conversions.h" |
[email protected] | 76fb05c | 2013-06-11 04:38:05 | [diff] [blame] | 39 | #include "base/strings/string_util.h" |
| 40 | #include "base/strings/stringprintf.h" |
[email protected] | e309f31 | 2013-06-07 21:50:08 | [diff] [blame] | 41 | #include "base/strings/utf_string_conversions.h" |
Gabriel Charette | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 42 | #include "base/task/post_task.h" |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 43 | #include "base/test/bind_test_util.h" |
chaopeng | 01e3b25 | 2017-10-18 22:33:37 | [diff] [blame] | 44 | #include "base/test/scoped_feature_list.h" |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 45 | #include "base/test/test_file_util.h" |
jam | 3f2d393 | 2017-04-26 20:28:51 | [diff] [blame] | 46 | #include "base/threading/thread_restrictions.h" |
[email protected] | ff54ace2 | 2013-06-28 01:26:21 | [diff] [blame] | 47 | #include "base/time/time.h" |
[email protected] | 2321f0b | 2012-09-10 01:51:51 | [diff] [blame] | 48 | #include "base/values.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 49 | #include "build/build_config.h" |
[email protected] | b3fc7b7 | 2012-08-28 15:04:04 | [diff] [blame] | 50 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 51 | #include "chrome/browser/background/background_contents_service.h" |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 52 | #include "chrome/browser/browser_process.h" |
[email protected] | 25ff086 | 2013-07-12 00:59:03 | [diff] [blame] | 53 | #include "chrome/browser/chrome_notification_types.h" |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 54 | #include "chrome/browser/chromeos/policy/configuration_policy_handler_chromeos.h" |
waffles | a4f53d4 | 2017-02-07 01:19:31 | [diff] [blame] | 55 | #include "chrome/browser/component_updater/chrome_component_updater_configurator.h" |
Clark DuVall | 385b5a5 | 2018-06-14 21:33:32 | [diff] [blame] | 56 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
[email protected] | d017a70 | 2013-01-27 23:51:36 | [diff] [blame] | 57 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 58 | #include "chrome/browser/devtools/devtools_window_testing.h" |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 59 | #include "chrome/browser/download/download_prefs.h" |
Michael Giuffrida | 9e1a9f8 | 2017-08-08 14:23:29 | [diff] [blame] | 60 | #include "chrome/browser/extensions/api/chrome_extensions_api_client.h" |
limasdf | c83e0b7 | 2017-03-03 17:08:35 | [diff] [blame] | 61 | #include "chrome/browser/extensions/chrome_test_extension_loader.h" |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 62 | #include "chrome/browser/extensions/crx_installer.h" |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 63 | #include "chrome/browser/extensions/extension_management_constants.h" |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 64 | #include "chrome/browser/extensions/extension_management_test_util.h" |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 65 | #include "chrome/browser/extensions/extension_service.h" |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 66 | #include "chrome/browser/extensions/install_verifier.h" |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 67 | #include "chrome/browser/extensions/shared_module_service.h" |
[email protected] | ec1b3e71 | 2013-05-25 14:29:16 | [diff] [blame] | 68 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 69 | #include "chrome/browser/extensions/updater/extension_cache_fake.h" |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 70 | #include "chrome/browser/extensions/updater/extension_updater.h" |
[email protected] | 4a8adfa0 | 2013-03-19 22:37:46 | [diff] [blame] | 71 | #include "chrome/browser/infobars/infobar_service.h" |
fahl | e66e7ff | 2015-04-23 19:38:30 | [diff] [blame] | 72 | #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" |
mcasas | a2023ab | 2016-09-08 01:06:36 | [diff] [blame] | 73 | #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 74 | #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
Elad Alon | 6bd69cb | 2018-08-06 18:20:45 | [diff] [blame] | 75 | #include "chrome/browser/media/webrtc/webrtc_event_log_manager.h" |
[email protected] | 27ef988d | 2014-08-01 17:00:40 | [diff] [blame] | 76 | #include "chrome/browser/net/prediction_options.h" |
Min Qin | b4bba9d | 2018-08-21 18:26:54 | [diff] [blame] | 77 | #include "chrome/browser/net/system_network_context_manager.h" |
raymes | 2d2d7d7 | 2017-03-06 22:16:33 | [diff] [blame] | 78 | #include "chrome/browser/permissions/permission_request_manager.h" |
Scott Violet | fdd6f35 | 2018-01-12 19:12:29 | [diff] [blame] | 79 | #include "chrome/browser/policy/chrome_browser_policy_connector.h" |
[email protected] | f97bd48 | 2013-11-21 13:04:28 | [diff] [blame] | 80 | #include "chrome/browser/policy/profile_policy_connector.h" |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 81 | #include "chrome/browser/prefs/session_startup_pref.h" |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 82 | #include "chrome/browser/profiles/profile.h" |
Francois Doray | 8059c54 | 2018-07-05 21:16:20 | [diff] [blame] | 83 | #include "chrome/browser/resource_coordinator/tab_load_tracker_test_support.h" |
Jialiu Lin | 219b9786 | 2018-01-27 02:39:59 | [diff] [blame] | 84 | #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 85 | #include "chrome/browser/search/search.h" |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 86 | #include "chrome/browser/search_engines/template_url_service_factory.h" |
felt | 2d3f65e | 2015-05-18 15:26:04 | [diff] [blame] | 87 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
avi | 24d693f | 2016-08-06 18:03:52 | [diff] [blame] | 88 | #include "chrome/browser/task_manager/task_manager_interface.h" |
[email protected] | 255ab97 | 2014-06-04 12:14:22 | [diff] [blame] | 89 | #include "chrome/browser/translate/chrome_translate_client.h" |
[email protected] | 546f5d6 | 2014-02-10 17:54:50 | [diff] [blame] | 90 | #include "chrome/browser/translate/translate_service.h" |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 91 | #include "chrome/browser/ui/bookmarks/bookmark_bar.h" |
| 92 | #include "chrome/browser/ui/browser.h" |
[email protected] | b3fc7b7 | 2012-08-28 15:04:04 | [diff] [blame] | 93 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | e417178 | 2013-02-14 18:22:57 | [diff] [blame] | 94 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 95 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 96 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | d57ce6a | 2014-07-03 15:39:23 | [diff] [blame] | 97 | #include "chrome/browser/ui/location_bar/location_bar.h" |
timloh | fa10d43 | 2017-06-20 00:50:23 | [diff] [blame] | 98 | #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 99 | #include "chrome/browser/ui/search/instant_test_utils.h" |
| 100 | #include "chrome/browser/ui/search/local_ntp_test_utils.h" |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 101 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
Lei Zhang | c5b042c | 2017-11-11 00:39:23 | [diff] [blame] | 102 | #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" |
Hector Carmona | 1e62e35 | 2019-06-24 19:18:17 | [diff] [blame] | 103 | #include "chrome/browser/ui/webui/welcome/nux_helper.h" |
Reilly Grant | 6f18e1f | 2018-04-03 02:03:22 | [diff] [blame] | 104 | #include "chrome/browser/usb/usb_chooser_context.h" |
| 105 | #include "chrome/browser/usb/usb_chooser_context_factory.h" |
Alexander Hendrich | 9ce4926 | 2018-05-29 13:35:46 | [diff] [blame] | 106 | #include "chrome/common/chrome_constants.h" |
timloh | fa10d43 | 2017-06-20 00:50:23 | [diff] [blame] | 107 | #include "chrome/common/chrome_features.h" |
[email protected] | 69fe7ac | 2013-01-02 21:33:59 | [diff] [blame] | 108 | #include "chrome/common/chrome_paths.h" |
[email protected] | 2bfe6ce | 2012-09-13 09:47:39 | [diff] [blame] | 109 | #include "chrome/common/chrome_switches.h" |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 110 | #include "chrome/common/extensions/extension_constants.h" |
Konstantin Ganenko | ae1129c | 2017-09-15 16:28:59 | [diff] [blame] | 111 | #include "chrome/common/extensions/extension_test_util.h" |
Giovanni Ortuño Urquidi | 77b5bf7 | 2018-08-23 06:43:29 | [diff] [blame] | 112 | #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 113 | #include "chrome/common/net/safe_search_util.h" |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 114 | #include "chrome/common/pref_names.h" |
[email protected] | bb34f26 | 2012-09-05 09:09:46 | [diff] [blame] | 115 | #include "chrome/common/url_constants.h" |
Christopher Lam | 96b044c | 2017-11-24 03:29:46 | [diff] [blame] | 116 | #include "chrome/common/web_application_info.h" |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 117 | #include "chrome/common/webui_url_constants.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 118 | #include "chrome/grit/generated_resources.h" |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 119 | #include "chrome/grit/locale_settings.h" |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 120 | #include "chrome/test/base/in_process_browser_test.h" |
thestig | f8056446 | 2015-09-29 23:12:08 | [diff] [blame] | 121 | #include "chrome/test/base/search_test_utils.h" |
Alexander Hendrich | 9ce4926 | 2018-05-29 13:35:46 | [diff] [blame] | 122 | #include "chrome/test/base/testing_profile.h" |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 123 | #include "chrome/test/base/ui_test_utils.h" |
brettw | e1f0af8b | 2015-10-09 21:30:46 | [diff] [blame] | 124 | #include "components/bookmarks/common/bookmark_pref_names.h" |
dullweber | 303f444 | 2017-03-03 11:50:19 | [diff] [blame] | 125 | #include "components/browsing_data/core/pref_names.h" |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 126 | #include "components/component_updater/component_updater_service.h" |
Antonio Gomes | b616250 | 2018-06-28 20:21:55 | [diff] [blame] | 127 | #include "components/component_updater/component_updater_switches.h" |
Clark DuVall | 385b5a5 | 2018-06-14 21:33:32 | [diff] [blame] | 128 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 129 | #include "components/content_settings/core/common/content_settings.h" |
vasilii | f62dbf9 | 2014-09-05 10:23:13 | [diff] [blame] | 130 | #include "components/content_settings/core/common/content_settings_pattern.h" |
brettw | e1f0af8b | 2015-10-09 21:30:46 | [diff] [blame] | 131 | #include "components/content_settings/core/common/pref_names.h" |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 132 | #include "components/download/public/common/download_item.h" |
John Abd-El-Malek | d2b62ee | 2018-11-20 07:43:34 | [diff] [blame] | 133 | #include "components/google/core/common/google_util.h" |
[email protected] | 051655ad | 2014-04-18 15:09:41 | [diff] [blame] | 134 | #include "components/infobars/core/infobar.h" |
Ran Ji | 73f3b43 | 2018-07-15 22:10:27 | [diff] [blame] | 135 | #include "components/language/core/browser/pref_names.h" |
John Abd-El-Malek | d2b62ee | 2018-11-20 07:43:34 | [diff] [blame] | 136 | #include "components/network_session_configurator/common/network_switches.h" |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 137 | #include "components/network_time/network_time_tracker.h" |
blundell | 2102f7c | 2015-07-09 10:00:53 | [diff] [blame] | 138 | #include "components/omnibox/browser/autocomplete_controller.h" |
blundell | 7dbd379 | 2015-08-05 15:14:19 | [diff] [blame] | 139 | #include "components/omnibox/browser/omnibox_edit_model.h" |
| 140 | #include "components/omnibox/browser/omnibox_view.h" |
[email protected] | 9727582 | 2014-01-21 19:30:36 | [diff] [blame] | 141 | #include "components/policy/core/browser/browser_policy_connector.h" |
[email protected] | c4a138a | 2013-11-21 19:54:57 | [diff] [blame] | 142 | #include "components/policy/core/common/external_data_fetcher.h" |
[email protected] | f20a3a2 | 2013-12-03 16:12:37 | [diff] [blame] | 143 | #include "components/policy/core/common/mock_configuration_policy_provider.h" |
[email protected] | c4a138a | 2013-11-21 19:54:57 | [diff] [blame] | 144 | #include "components/policy/core/common/policy_map.h" |
[email protected] | 425e337 | 2013-12-17 09:35:43 | [diff] [blame] | 145 | #include "components/policy/core/common/policy_pref_names.h" |
[email protected] | 76b4b15 | 2013-12-08 21:10:04 | [diff] [blame] | 146 | #include "components/policy/core/common/policy_service.h" |
| 147 | #include "components/policy/core/common/policy_service_impl.h" |
fhorschig | 64834b71 | 2015-09-21 14:20:23 | [diff] [blame] | 148 | #include "components/policy/core/common/policy_types.h" |
brettw | 39d6ba4 | 2016-08-24 16:56:38 | [diff] [blame] | 149 | #include "components/policy/policy_constants.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 150 | #include "components/prefs/pref_service.h" |
Luna Lu | aacaa90f | 2018-03-13 15:22:08 | [diff] [blame] | 151 | #include "components/safe_browsing/features.h" |
[email protected] | d550cb0 | 2014-06-25 06:48:11 | [diff] [blame] | 152 | #include "components/search_engines/template_url.h" |
[email protected] | bf5c532d | 2014-07-05 00:29:53 | [diff] [blame] | 153 | #include "components/search_engines/template_url_service.h" |
jialiul | a2c06925 | 2017-01-05 18:13:04 | [diff] [blame] | 154 | #include "components/security_interstitials/content/security_interstitial_page.h" |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 155 | #include "components/security_interstitials/content/security_interstitial_tab_helper.h" |
felt | 9de47c5 | 2015-11-24 03:29:57 | [diff] [blame] | 156 | #include "components/security_interstitials/core/controller_client.h" |
David Roger | 618d1c6 | 2019-01-15 12:55:24 | [diff] [blame] | 157 | #include "components/signin/core/browser/account_info.h" |
blundell | 02d46ab | 2015-12-03 13:23:57 | [diff] [blame] | 158 | #include "components/strings/grit/components_strings.h" |
[email protected] | 5e625b0 | 2014-06-11 09:34:27 | [diff] [blame] | 159 | #include "components/translate/core/browser/language_state.h" |
[email protected] | dbe9bfa | 2014-06-02 16:01:29 | [diff] [blame] | 160 | #include "components/translate/core/browser/translate_infobar_delegate.h" |
Thomas Tangl | 6703fceb | 2018-07-18 15:54:25 | [diff] [blame] | 161 | #include "components/unified_consent/pref_names.h" |
Sorin Jianu | 4e0b41d | 2019-02-20 17:21:58 | [diff] [blame] | 162 | #include "components/update_client/net/url_loader_post_interceptor.h" |
sorin | 2892f721 | 2016-11-07 18:59:43 | [diff] [blame] | 163 | #include "components/update_client/update_client.h" |
sorin | 7b865052 | 2016-11-02 18:23:41 | [diff] [blame] | 164 | #include "components/update_client/update_client_errors.h" |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 165 | #include "components/user_prefs/user_prefs.h" |
blundell | 0300cdea | 2015-09-03 12:47:44 | [diff] [blame] | 166 | #include "components/variations/service/variations_service.h" |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 167 | #include "components/variations/variations_params_manager.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 168 | #include "components/version_info/version_info.h" |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 169 | #include "content/public/browser/browser_context.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 170 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 171 | #include "content/public/browser/browser_thread.h" |
[email protected] | 2321f0b | 2012-09-10 01:51:51 | [diff] [blame] | 172 | #include "content/public/browser/child_process_data.h" |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 173 | #include "content/public/browser/download_manager.h" |
[email protected] | f5b7f6e | 2013-12-10 13:57:32 | [diff] [blame] | 174 | #include "content/public/browser/gpu_data_manager.h" |
estark | 86642d60 | 2015-04-09 20:39:16 | [diff] [blame] | 175 | #include "content/public/browser/interstitial_page.h" |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 176 | #include "content/public/browser/notification_details.h" |
| 177 | #include "content/public/browser/notification_observer.h" |
[email protected] | 9a8764b | 2013-03-27 16:18:09 | [diff] [blame] | 178 | #include "content/public/browser/notification_registrar.h" |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 179 | #include "content/public/browser/notification_service.h" |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 180 | #include "content/public/browser/notification_source.h" |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 181 | #include "content/public/browser/notification_types.h" |
estark | 86642d60 | 2015-04-09 20:39:16 | [diff] [blame] | 182 | #include "content/public/browser/render_frame_host.h" |
[email protected] | 7c60f504 | 2013-02-14 03:39:32 | [diff] [blame] | 183 | #include "content/public/browser/render_process_host.h" |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 184 | #include "content/public/browser/render_view_host.h" |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 185 | #include "content/public/browser/render_widget_host.h" |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 186 | #include "content/public/browser/storage_partition.h" |
Ken Rockot | eff2b82 | 2019-06-20 22:56:53 | [diff] [blame] | 187 | #include "content/public/browser/system_connector.h" |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 188 | #include "content/public/browser/web_contents.h" |
[email protected] | 7327029 | 2013-08-09 03:48:07 | [diff] [blame] | 189 | #include "content/public/common/content_constants.h" |
John Abd-El-Malek | 39d0a67 | 2018-09-28 22:14:05 | [diff] [blame] | 190 | #include "content/public/common/content_features.h" |
[email protected] | 2321f0b | 2012-09-10 01:51:51 | [diff] [blame] | 191 | #include "content/public/common/content_paths.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 192 | #include "content/public/common/content_switches.h" |
John Abd-El-Malek | 9dba1ad | 2018-10-27 02:22:14 | [diff] [blame] | 193 | #include "content/public/common/network_service_util.h" |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 194 | #include "content/public/common/result_codes.h" |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 195 | #include "content/public/common/service_names.mojom.h" |
[email protected] | bb34f26 | 2012-09-05 09:09:46 | [diff] [blame] | 196 | #include "content/public/common/url_constants.h" |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 197 | #include "content/public/common/web_preferences.h" |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 198 | #include "content/public/test/browser_test_utils.h" |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 199 | #include "content/public/test/download_test_observer.h" |
[email protected] | 9a8764b | 2013-03-27 16:18:09 | [diff] [blame] | 200 | #include "content/public/test/mock_notification_observer.h" |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 201 | #include "content/public/test/network_service_test_helper.h" |
Lukasz Anforowicz | 907b6ac | 2019-06-13 01:49:08 | [diff] [blame] | 202 | #include "content/public/test/no_renderer_crashes_assertion.h" |
Kunihiko Sakamoto | f586da6 | 2019-03-28 03:03:04 | [diff] [blame] | 203 | #include "content/public/test/signed_exchange_browser_test_helper.h" |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 204 | #include "content/public/test/test_navigation_observer.h" |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 205 | #include "content/public/test/test_utils.h" |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 206 | #include "content/public/test/url_loader_interceptor.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 207 | #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 208 | #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
Michael Giuffrida | 9e1a9f8 | 2017-08-08 14:23:29 | [diff] [blame] | 209 | #include "extensions/browser/api/messaging/messaging_delegate.h" |
Devlin Cronin | bffe949eb | 2018-01-12 03:03:40 | [diff] [blame] | 210 | #include "extensions/browser/disable_reason.h" |
rdevlin.cronin | 6620949 | 2015-06-10 20:44:05 | [diff] [blame] | 211 | #include "extensions/browser/extension_dialog_auto_confirm.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 212 | #include "extensions/browser/extension_host.h" |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 213 | #include "extensions/browser/extension_prefs.h" |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 214 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 215 | #include "extensions/browser/extension_system.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 216 | #include "extensions/browser/process_manager.h" |
asargent | 75f5548 | 2016-06-08 15:53:54 | [diff] [blame] | 217 | #include "extensions/browser/scoped_ignore_content_verifier_for_test.h" |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 218 | #include "extensions/browser/test_extension_registry_observer.h" |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 219 | #include "extensions/browser/uninstall_reason.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 220 | #include "extensions/common/extension.h" |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 221 | #include "extensions/common/extension_set.h" |
rdevlin.cronin | 4122753 | 2016-07-13 21:24:34 | [diff] [blame] | 222 | #include "extensions/common/features/feature_channel.h" |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 223 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
Toni Barzic | c45d9b1 | 2017-07-25 02:53:36 | [diff] [blame] | 224 | #include "extensions/common/switches.h" |
Christopher Lam | 96b044c | 2017-11-24 03:29:46 | [diff] [blame] | 225 | #include "extensions/common/value_builder.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 226 | #include "media/media_buildflags.h" |
Ryan Sleevi | c8889d0 | 2018-04-06 17:57:05 | [diff] [blame] | 227 | #include "net/base/hash_value.h" |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 228 | #include "net/base/net_errors.h" |
[email protected] | a29ad21 | 2013-05-02 20:18:54 | [diff] [blame] | 229 | #include "net/base/url_util.h" |
Ryan Sleevi | c8889d0 | 2018-04-06 17:57:05 | [diff] [blame] | 230 | #include "net/cert/x509_util.h" |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 231 | #include "net/dns/mock_host_resolver.h" |
[email protected] | 02e09be | 2012-09-09 16:09:29 | [diff] [blame] | 232 | #include "net/http/http_stream_factory.h" |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 233 | #include "net/http/transport_security_state.h" |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 234 | #include "net/test/embedded_test_server/embedded_test_server.h" |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 235 | #include "net/test/embedded_test_server/http_request.h" |
| 236 | #include "net/test/embedded_test_server/http_response.h" |
xunjieli | 2906f15 | 2014-09-12 00:08:23 | [diff] [blame] | 237 | #include "net/test/url_request/url_request_failed_job.h" |
xunjieli | 0332c19 | 2014-09-10 23:23:31 | [diff] [blame] | 238 | #include "net/test/url_request/url_request_mock_http_job.h" |
Maksim Ivanov | eaac2ff | 2018-04-16 16:23:24 | [diff] [blame] | 239 | #include "net/url_request/test_url_request_interceptor.h" |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 240 | #include "net/url_request/url_request.h" |
| 241 | #include "net/url_request/url_request_filter.h" |
pauljensen | 754dde23 | 2015-06-03 05:47:29 | [diff] [blame] | 242 | #include "net/url_request/url_request_interceptor.h" |
Donna Wu | 4dc9df3 | 2019-05-20 03:56:21 | [diff] [blame] | 243 | #include "services/device/public/cpp/test/fake_usb_device_info.h" |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 244 | #include "services/network/public/cpp/features.h" |
| 245 | #include "services/network/public/cpp/network_switches.h" |
Matt Menke | d476edd | 2018-05-03 16:43:50 | [diff] [blame] | 246 | #include "services/network/public/mojom/network_service.mojom.h" |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 247 | #include "services/network/public/mojom/network_service_test.mojom.h" |
| 248 | #include "services/service_manager/public/cpp/connector.h" |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 249 | #include "testing/gmock/include/gmock/gmock.h" |
| 250 | #include "testing/gtest/include/gtest/gtest.h" |
Antonio Gomes | 0d42960a | 2019-06-05 12:35:51 | [diff] [blame] | 251 | #include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 252 | #include "third_party/blink/public/platform/web_input_event.h" |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 253 | #include "ui/base/l10n/l10n_util.h" |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 254 | #include "ui/base/page_transition_types.h" |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 255 | #include "ui/base/resource/resource_bundle.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 256 | #include "ui/display/manager/display_manager.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 257 | #include "url/gurl.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 258 | #include "url/origin.h" |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 259 | |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 260 | #if defined(OS_CHROMEOS) |
Evan Stade | 7d0e823 | 2017-10-04 02:01:36 | [diff] [blame] | 261 | #include "ash/public/cpp/ash_switches.h" |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 262 | #include "ash/shell.h" |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 263 | #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 264 | #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
Qiang Xu | 92eabd4 | 2018-06-27 16:20:05 | [diff] [blame] | 265 | #include "chrome/browser/chromeos/accessibility/magnifier_type.h" |
hidehiko | 5d94408 | 2016-11-18 06:16:04 | [diff] [blame] | 266 | #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
Sam McNally | 5edde0a | 2019-02-27 11:10:03 | [diff] [blame] | 267 | #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
alemate | d70e82f | 2016-04-05 12:21:33 | [diff] [blame] | 268 | #include "chrome/browser/chromeos/login/test/js_checker.h" |
Toni Barzic | c45d9b1 | 2017-07-25 02:53:36 | [diff] [blame] | 269 | #include "chrome/browser/chromeos/note_taking_helper.h" |
Alexander Hendrich | 55d0b0d9 | 2018-05-08 11:29:10 | [diff] [blame] | 270 | #include "chrome/browser/chromeos/policy/login_policy_test_base.h" |
Alexander Hendrich | 9ce4926 | 2018-05-29 13:35:46 | [diff] [blame] | 271 | #include "chrome/browser/chromeos/policy/user_policy_test_helper.h" |
Alexander Hendrich | 55d0b0d9 | 2018-05-08 11:29:10 | [diff] [blame] | 272 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
alemate | d70e82f | 2016-04-05 12:21:33 | [diff] [blame] | 273 | #include "chrome/browser/chromeos/system/timezone_resolver_manager.h" |
flackr | 14908006 | 2014-12-03 14:35:37 | [diff] [blame] | 274 | #include "chrome/browser/ui/ash/chrome_screenshot_grabber.h" |
Elliot Glaysher | 685b3cd | 2018-02-01 23:17:55 | [diff] [blame] | 275 | #include "chrome/browser/ui/ash/chrome_screenshot_grabber_test_observer.h" |
Steven Bennetts | 8314964 | 2018-12-06 01:47:29 | [diff] [blame] | 276 | #include "chrome/browser/ui/ash/keyboard/chrome_keyboard_controller_client.h" |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 277 | #include "chromeos/audio/cras_audio_handler.h" |
Sam McNally | 5edde0a | 2019-02-27 11:10:03 | [diff] [blame] | 278 | #include "chromeos/constants/chromeos_features.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 279 | #include "chromeos/constants/chromeos_switches.h" |
alemate | d70e82f | 2016-04-05 12:21:33 | [diff] [blame] | 280 | #include "chromeos/cryptohome/cryptohome_parameters.h" |
Alexander Alekseev | 3f09a8f | 2018-05-03 02:52:10 | [diff] [blame] | 281 | #include "components/account_id/account_id.h" |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 282 | #include "components/arc/arc_prefs.h" |
hidehiko | aab3dea | 2017-01-30 14:36:46 | [diff] [blame] | 283 | #include "components/arc/arc_util.h" |
Yusuke Sato | d41a2c9 | 2019-03-26 00:55:14 | [diff] [blame] | 284 | #include "components/arc/session/arc_session_runner.h" |
hidehiko | 88160c8 | 2016-10-18 09:43:47 | [diff] [blame] | 285 | #include "components/arc/test/fake_arc_session.h" |
alemate | d70e82f | 2016-04-05 12:21:33 | [diff] [blame] | 286 | #include "components/user_manager/user_manager.h" |
flackr | 14908006 | 2014-12-03 14:35:37 | [diff] [blame] | 287 | #include "ui/snapshot/screenshot_grabber.h" |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 288 | #endif |
| 289 | |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 290 | #if !defined(OS_MACOSX) |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 291 | #include "base/compiler_specific.h" |
thestig | 53986dc | 2014-12-16 06:09:18 | [diff] [blame] | 292 | #include "chrome/browser/ui/extensions/app_launch_params.h" |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 293 | #include "chrome/browser/ui/extensions/application_launch.h" |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 294 | #include "extensions/browser/app_window/app_window.h" |
| 295 | #include "extensions/browser/app_window/app_window_registry.h" |
[email protected] | 2accabe | 2014-08-20 07:48:29 | [diff] [blame] | 296 | #include "extensions/browser/app_window/native_app_window.h" |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 297 | #include "ui/base/window_open_disposition.h" |
| 298 | #endif |
| 299 | |
Nick Peterson | d952cb77 | 2018-03-07 15:46:03 | [diff] [blame] | 300 | #if defined(OS_WIN) |
| 301 | #include "base/win/win_util.h" |
| 302 | #endif |
| 303 | |
Derek Cheng | 3447838 | 2018-04-07 00:32:59 | [diff] [blame] | 304 | #if !defined(OS_ANDROID) |
| 305 | #include "chrome/browser/media/router/media_router_feature.h" |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 306 | #include "chrome/browser/profiles/profile_manager.h" |
| 307 | #include "chrome/browser/ui/browser_finder.h" |
| 308 | #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
Takumi Fujimoto | 906aab7c | 2019-02-22 22:11:16 | [diff] [blame] | 309 | #include "chrome/browser/ui/toolbar/media_router_action_controller.h" |
Derek Cheng | 3447838 | 2018-04-07 00:32:59 | [diff] [blame] | 310 | #endif |
| 311 | |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 312 | using content::BrowserThread; |
xunjieli | 0332c19 | 2014-09-10 23:23:31 | [diff] [blame] | 313 | using net::URLRequestMockHTTPJob; |
Elad Alon | 39b1f6cc | 2018-08-30 09:52:21 | [diff] [blame] | 314 | using testing::_; |
[email protected] | 9a8764b | 2013-03-27 16:18:09 | [diff] [blame] | 315 | using testing::Mock; |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 316 | using testing::Return; |
Elad Alon | 39b1f6cc | 2018-08-30 09:52:21 | [diff] [blame] | 317 | using webrtc_event_logging::WebRtcEventLogManager; |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 318 | |
| 319 | namespace policy { |
| 320 | |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 321 | namespace { |
| 322 | |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 323 | #if defined(OS_CHROMEOS) |
| 324 | const int kOneHourInMs = 60 * 60 * 1000; |
| 325 | const int kThreeHoursInMs = 180 * 60 * 1000; |
| 326 | #endif |
| 327 | |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 328 | const char kURL[] = "http://example.com"; |
| 329 | const char kCookieValue[] = "converted=true"; |
| 330 | // Assigned to Philip J. Fry to fix eventually. |
maksim.sisov | 18b63ea | 2016-06-14 18:05:17 | [diff] [blame] | 331 | // TODO(maksims): use year 3000 when we get rid off the 32-bit |
| 332 | // versions. https://crbug.com/619828 |
| 333 | const char kCookieOptions[] = ";expires=Wed Jan 01 2038 00:00:00 GMT"; |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 334 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 335 | const base::FilePath::CharType kTestExtensionsDir[] = |
| 336 | FILE_PATH_LITERAL("extensions"); |
| 337 | const base::FilePath::CharType kGoodCrxName[] = FILE_PATH_LITERAL("good.crx"); |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 338 | const base::FilePath::CharType kSimpleWithIconCrxName[] = |
| 339 | FILE_PATH_LITERAL("simple_with_icon.crx"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 340 | const base::FilePath::CharType kHostedAppCrxName[] = |
[email protected] | ce4e5d7a | 2012-12-11 20:59:26 | [diff] [blame] | 341 | FILE_PATH_LITERAL("hosted_app.crx"); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 342 | |
| 343 | const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 344 | const char kSimpleWithIconCrxId[] = "dehdlahnlebladnfleagmjdapdjdcnlp"; |
[email protected] | ce4e5d7a | 2012-12-11 20:59:26 | [diff] [blame] | 345 | const char kHostedAppCrxId[] = "kbmnembihfiondgfjekmnmcbddelicoi"; |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 346 | |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 347 | const base::FilePath::CharType kGoodV1CrxName[] = |
| 348 | FILE_PATH_LITERAL("good_v1.crx"); |
Devlin Cronin | 19775cc | 2018-04-19 15:04:26 | [diff] [blame] | 349 | const base::FilePath::CharType kSimpleWithPopupExt[] = |
| 350 | FILE_PATH_LITERAL("simple_with_popup"); |
[email protected] | ec1b3e71 | 2013-05-25 14:29:16 | [diff] [blame] | 351 | const base::FilePath::CharType kAppUnpackedExt[] = |
| 352 | FILE_PATH_LITERAL("app"); |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 353 | |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 354 | const char kAutoplayTestPageURL[] = "/media/autoplay_iframe.html"; |
| 355 | |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 356 | #if !defined(OS_MACOSX) |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 357 | const base::FilePath::CharType kUnpackedFullscreenAppName[] = |
| 358 | FILE_PATH_LITERAL("fullscreen_app"); |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 359 | #endif // !defined(OS_MACOSX) |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 360 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 361 | // Arbitrary port range for testing the WebRTC UDP port policy. |
| 362 | const char kTestWebRtcUdpPortRange[] = "10000-10100"; |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 363 | |
Elad Alon | be6c2cf7 | 2018-09-05 13:24:51 | [diff] [blame] | 364 | constexpr size_t kWebAppId = 42; |
| 365 | |
Jun Cai | aa24869 | 2017-11-10 20:10:51 | [diff] [blame] | 366 | void GetTestDataDirectory(base::FilePath* test_data_directory) { |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 367 | ASSERT_TRUE( |
| 368 | base::PathService::Get(chrome::DIR_TEST_DATA, test_data_directory)); |
Jun Cai | aa24869 | 2017-11-10 20:10:51 | [diff] [blame] | 369 | } |
| 370 | |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 371 | content::RenderFrameHost* GetMostVisitedIframe(content::WebContents* tab) { |
| 372 | for (content::RenderFrameHost* frame : tab->GetAllFrames()) { |
| 373 | if (frame->GetFrameName() == "mv-single") |
| 374 | return frame; |
| 375 | } |
| 376 | return nullptr; |
| 377 | } |
| 378 | |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 379 | // Filters requests to the hosts in |urls| and redirects them to the test data |
| 380 | // dir through URLRequestMockHTTPJobs. |
[email protected] | 233b688e | 2012-11-27 10:44:12 | [diff] [blame] | 381 | void RedirectHostsToTestData(const char* const urls[], size_t size) { |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 382 | // Map the given hosts to the test data dir. |
| 383 | net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 384 | base::FilePath base_path; |
Jun Cai | aa24869 | 2017-11-10 20:10:51 | [diff] [blame] | 385 | GetTestDataDirectory(&base_path); |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 386 | for (size_t i = 0; i < size; ++i) { |
[email protected] | 233b688e | 2012-11-27 10:44:12 | [diff] [blame] | 387 | const GURL url(urls[i]); |
| 388 | EXPECT_TRUE(url.is_valid()); |
Gabriel Charette | cf00b108 | 2017-06-16 19:42:39 | [diff] [blame] | 389 | filter->AddUrlInterceptor( |
| 390 | url, URLRequestMockHTTPJob::CreateInterceptor(base_path)); |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 394 | // Fails requests using ERR_CONNECTION_RESET. |
pauljensen | 754dde23 | 2015-06-03 05:47:29 | [diff] [blame] | 395 | class FailedJobInterceptor : public net::URLRequestInterceptor { |
| 396 | public: |
| 397 | FailedJobInterceptor() {} |
| 398 | ~FailedJobInterceptor() override {} |
| 399 | |
| 400 | // URLRequestInterceptor implementation: |
| 401 | net::URLRequestJob* MaybeInterceptRequest( |
| 402 | net::URLRequest* request, |
| 403 | net::NetworkDelegate* network_delegate) const override { |
| 404 | return new net::URLRequestFailedJob(request, network_delegate, |
| 405 | net::ERR_CONNECTION_RESET); |
| 406 | } |
| 407 | |
| 408 | private: |
| 409 | DISALLOW_COPY_AND_ASSIGN(FailedJobInterceptor); |
| 410 | }; |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 411 | |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 412 | // While |MakeRequestFail| is in scope URLRequests to |host| will fail. |
| 413 | class MakeRequestFail { |
| 414 | public: |
| 415 | // Sets up the filter on IO thread such that requests to |host| fail. |
| 416 | explicit MakeRequestFail(const std::string& host) : host_(host) { |
Wez | c0998d08 | 2018-07-06 17:50:18 | [diff] [blame] | 417 | base::RunLoop run_loop; |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 418 | base::PostTaskWithTraitsAndReply(FROM_HERE, {BrowserThread::IO}, |
| 419 | base::BindOnce(MakeRequestFailOnIO, host_), |
| 420 | run_loop.QuitClosure()); |
Wez | c0998d08 | 2018-07-06 17:50:18 | [diff] [blame] | 421 | run_loop.Run(); |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 422 | } |
| 423 | ~MakeRequestFail() { |
Wez | c0998d08 | 2018-07-06 17:50:18 | [diff] [blame] | 424 | base::RunLoop run_loop; |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 425 | base::PostTaskWithTraitsAndReply( |
| 426 | FROM_HERE, {BrowserThread::IO}, |
Wez | c0998d08 | 2018-07-06 17:50:18 | [diff] [blame] | 427 | base::BindOnce(UndoMakeRequestFailOnIO, host_), run_loop.QuitClosure()); |
| 428 | run_loop.Run(); |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 429 | } |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 430 | |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 431 | private: |
| 432 | // Filters requests to the |host| such that they fail. Run on IO thread. |
| 433 | static void MakeRequestFailOnIO(const std::string& host) { |
| 434 | net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
dcheng | 08cfe9ba | 2016-04-14 17:46:45 | [diff] [blame] | 435 | filter->AddHostnameInterceptor("http", host, |
| 436 | std::unique_ptr<net::URLRequestInterceptor>( |
| 437 | new FailedJobInterceptor())); |
| 438 | filter->AddHostnameInterceptor("https", host, |
| 439 | std::unique_ptr<net::URLRequestInterceptor>( |
| 440 | new FailedJobInterceptor())); |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | // Remove filters for requests to the |host|. Run on IO thread. |
| 444 | static void UndoMakeRequestFailOnIO(const std::string& host) { |
| 445 | net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
| 446 | filter->RemoveHostnameHandler("http", host); |
| 447 | filter->RemoveHostnameHandler("https", host); |
| 448 | } |
| 449 | |
| 450 | const std::string host_; |
| 451 | }; |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 452 | |
Yuzhu Shen | f3c2fcc | 2017-11-30 20:30:22 | [diff] [blame] | 453 | // Registers a handler to respond to requests whose path matches |match_path|. |
| 454 | // The response contents are generated from |template_file|, by replacing all |
| 455 | // "${URL_PLACEHOLDER}" substrings in the file with the request URL excluding |
| 456 | // filename, query values and fragment. |
| 457 | void RegisterURLReplacingHandler(net::EmbeddedTestServer* test_server, |
| 458 | const std::string& match_path, |
| 459 | const base::FilePath& template_file) { |
| 460 | test_server->RegisterRequestHandler(base::Bind( |
| 461 | [](net::EmbeddedTestServer* test_server, const std::string& match_path, |
| 462 | const base::FilePath& template_file, |
| 463 | const net::test_server::HttpRequest& request) |
| 464 | -> std::unique_ptr<net::test_server::HttpResponse> { |
| 465 | GURL url = test_server->GetURL(request.relative_url); |
| 466 | if (url.path() != match_path) |
| 467 | return nullptr; |
| 468 | |
| 469 | std::string contents; |
| 470 | CHECK(base::ReadFileToString(template_file, &contents)); |
| 471 | |
| 472 | GURL url_base = url.GetWithoutFilename(); |
| 473 | base::ReplaceSubstringsAfterOffset(&contents, 0, "${URL_PLACEHOLDER}", |
| 474 | url_base.spec()); |
| 475 | |
| 476 | auto response = std::make_unique<net::test_server::BasicHttpResponse>(); |
| 477 | response->set_content(contents); |
| 478 | response->set_content_type("text/plain"); |
| 479 | return response; |
| 480 | }, |
| 481 | base::Unretained(test_server), match_path, template_file)); |
| 482 | } |
| 483 | |
[email protected] | 233b688e | 2012-11-27 10:44:12 | [diff] [blame] | 484 | // Verifies that the given url |spec| can be opened. This assumes that |spec| |
| 485 | // points at empty.html in the test data dir. |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 486 | void CheckCanOpenURL(Browser* browser, const std::string& spec) { |
[email protected] | 233b688e | 2012-11-27 10:44:12 | [diff] [blame] | 487 | GURL url(spec); |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 488 | ui_test_utils::NavigateToURL(browser, url); |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 489 | content::WebContents* contents = |
| 490 | browser->tab_strip_model()->GetActiveWebContents(); |
jam | d6be16e | 2014-09-28 15:18:34 | [diff] [blame] | 491 | EXPECT_EQ(url, contents->GetURL()); |
edwardjung | e76b580 | 2016-08-11 13:38:48 | [diff] [blame] | 492 | |
| 493 | base::string16 blocked_page_title; |
| 494 | if (url.has_host()) { |
| 495 | blocked_page_title = base::UTF8ToUTF16(url.host()); |
| 496 | } else { |
| 497 | // Local file paths show the full URL. |
| 498 | blocked_page_title = base::UTF8ToUTF16(url.spec()); |
| 499 | } |
| 500 | EXPECT_NE(blocked_page_title, contents->GetTitle()); |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 501 | } |
| 502 | |
[email protected] | 233b688e | 2012-11-27 10:44:12 | [diff] [blame] | 503 | // Verifies that access to the given url |spec| is blocked. |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 504 | void CheckURLIsBlockedInWebContents(content::WebContents* web_contents, |
| 505 | const GURL& url) { |
| 506 | EXPECT_EQ(url, web_contents->GetURL()); |
edwardjung | e76b580 | 2016-08-11 13:38:48 | [diff] [blame] | 507 | |
| 508 | base::string16 blocked_page_title; |
| 509 | if (url.has_host()) { |
| 510 | blocked_page_title = base::UTF8ToUTF16(url.host()); |
| 511 | } else { |
| 512 | // Local file paths show the full URL. |
| 513 | blocked_page_title = base::UTF8ToUTF16(url.spec()); |
| 514 | } |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 515 | EXPECT_EQ(blocked_page_title, web_contents->GetTitle()); |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 516 | |
| 517 | // Verify that the expected error page is being displayed. |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 518 | bool result = false; |
jam | d6be16e | 2014-09-28 15:18:34 | [diff] [blame] | 519 | EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 520 | web_contents, |
[email protected] | 71caef0 | 2013-03-25 17:40:20 | [diff] [blame] | 521 | "var textContent = document.body.textContent;" |
| 522 | "var hasError = textContent.indexOf('ERR_BLOCKED_BY_ADMINISTRATOR') >= 0;" |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 523 | "domAutomationController.send(hasError);", |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 524 | &result)); |
jam | d6be16e | 2014-09-28 15:18:34 | [diff] [blame] | 525 | EXPECT_TRUE(result); |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 526 | } |
| 527 | |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 528 | // Verifies that access to the given url |spec| is blocked. |
| 529 | void CheckURLIsBlocked(Browser* browser, const std::string& spec) { |
| 530 | GURL url(spec); |
| 531 | ui_test_utils::NavigateToURL(browser, url); |
| 532 | content::WebContents* contents = |
| 533 | browser->tab_strip_model()->GetActiveWebContents(); |
| 534 | CheckURLIsBlockedInWebContents(contents, url); |
| 535 | } |
| 536 | |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 537 | // Downloads a file named |file| and expects it to be saved to |dir|, which |
| 538 | // must be empty. |
Mattias Nissler | 441cc65 | 2018-04-05 00:08:56 | [diff] [blame] | 539 | void DownloadAndVerifyFile(Browser* browser, |
| 540 | const base::FilePath& dir, |
| 541 | const base::FilePath& file) { |
Jun Cai | aa24869 | 2017-11-10 20:10:51 | [diff] [blame] | 542 | net::EmbeddedTestServer embedded_test_server; |
| 543 | base::FilePath test_data_directory; |
| 544 | GetTestDataDirectory(&test_data_directory); |
| 545 | embedded_test_server.ServeFilesFromDirectory(test_data_directory); |
| 546 | ASSERT_TRUE(embedded_test_server.Start()); |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 547 | content::DownloadManager* download_manager = |
| 548 | content::BrowserContext::GetDownloadManager(browser->profile()); |
| 549 | content::DownloadTestObserverTerminal observer( |
| 550 | download_manager, 1, |
| 551 | content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
Jun Cai | aa24869 | 2017-11-10 20:10:51 | [diff] [blame] | 552 | GURL url(embedded_test_server.GetURL("/" + file.MaybeAsASCII())); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 553 | base::FilePath downloaded = dir.Append(file); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 554 | EXPECT_FALSE(base::PathExists(downloaded)); |
thestig | 53986dc | 2014-12-16 06:09:18 | [diff] [blame] | 555 | ui_test_utils::NavigateToURL(browser, url); |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 556 | observer.WaitForFinished(); |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 557 | EXPECT_EQ(1u, |
| 558 | observer.NumDownloadsSeenInState(download::DownloadItem::COMPLETE)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 559 | EXPECT_TRUE(base::PathExists(downloaded)); |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 560 | base::FileEnumerator enumerator(dir, false, base::FileEnumerator::FILES); |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 561 | EXPECT_EQ(file, enumerator.Next().BaseName()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 562 | EXPECT_EQ(base::FilePath(), enumerator.Next()); |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 563 | } |
| 564 | |
[email protected] | 81198da5 | 2014-03-19 10:45:20 | [diff] [blame] | 565 | #if defined(OS_CHROMEOS) |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 566 | int CountScreenshots() { |
| 567 | DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( |
[email protected] | 82f5bf3 | 2013-12-23 00:22:00 | [diff] [blame] | 568 | ProfileManager::GetActiveUserProfile()); |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 569 | base::FileEnumerator enumerator(download_prefs->DownloadPath(), |
| 570 | false, base::FileEnumerator::FILES, |
| 571 | "Screenshot*"); |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 572 | int count = 0; |
| 573 | while (!enumerator.Next().empty()) |
| 574 | count++; |
| 575 | return count; |
| 576 | } |
| 577 | #endif |
| 578 | |
[email protected] | bb34f26 | 2012-09-05 09:09:46 | [diff] [blame] | 579 | // Checks if WebGL is enabled in the given WebContents. |
| 580 | bool IsWebGLEnabled(content::WebContents* contents) { |
| 581 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 582 | EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 583 | contents, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 584 | "var canvas = document.createElement('canvas');" |
[email protected] | fb315ea | 2013-11-14 16:23:52 | [diff] [blame] | 585 | "var context = canvas.getContext('webgl');" |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 586 | "domAutomationController.send(context != null);", |
[email protected] | bb34f26 | 2012-09-05 09:09:46 | [diff] [blame] | 587 | &result)); |
| 588 | return result; |
| 589 | } |
| 590 | |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 591 | bool IsJavascriptEnabled(content::WebContents* contents) { |
Avi Drissman | 3d8c65a | 2019-03-19 22:14:07 | [diff] [blame] | 592 | base::Value value = |
dcheng | 08cfe9ba | 2016-04-14 17:46:45 | [diff] [blame] | 593 | content::ExecuteScriptAndGetValue(contents->GetMainFrame(), "123"); |
Avi Drissman | 3d8c65a | 2019-03-19 22:14:07 | [diff] [blame] | 594 | return value.is_int() && value.GetInt() == 123; |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 595 | } |
| 596 | |
[email protected] | 27ef988d | 2014-08-01 17:00:40 | [diff] [blame] | 597 | bool IsNetworkPredictionEnabled(PrefService* prefs) { |
gabadie | 85b991d | 2016-01-07 10:39:39 | [diff] [blame] | 598 | return chrome_browser_net::CanPrefetchAndPrerenderUI(prefs) == |
| 599 | chrome_browser_net::NetworkPredictionStatus::ENABLED; |
[email protected] | 27ef988d | 2014-08-01 17:00:40 | [diff] [blame] | 600 | } |
| 601 | |
[email protected] | 307aec7 | 2012-09-18 21:52:44 | [diff] [blame] | 602 | void FlushBlacklistPolicy() { |
| 603 | // Updates of the URLBlacklist are done on IO, after building the blacklist |
joaodasilva | 8d2d925 | 2014-09-01 14:41:24 | [diff] [blame] | 604 | // on the blocking pool, which is initiated from IO. |
[email protected] | 307aec7 | 2012-09-18 21:52:44 | [diff] [blame] | 605 | content::RunAllPendingInMessageLoop(BrowserThread::IO); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 606 | content::RunAllTasksUntilIdle(); |
[email protected] | 307aec7 | 2012-09-18 21:52:44 | [diff] [blame] | 607 | content::RunAllPendingInMessageLoop(BrowserThread::IO); |
| 608 | } |
| 609 | |
[email protected] | f6c1473 | 2013-02-25 19:09:20 | [diff] [blame] | 610 | bool ContainsVisibleElement(content::WebContents* contents, |
| 611 | const std::string& id) { |
| 612 | bool result; |
| 613 | EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 614 | contents, |
| 615 | "var elem = document.getElementById('" + id + "');" |
[email protected] | 7bc0c9662 | 2013-03-27 15:36:10 | [diff] [blame] | 616 | "domAutomationController.send(!!elem && !elem.hidden);", |
[email protected] | f6c1473 | 2013-02-25 19:09:20 | [diff] [blame] | 617 | &result)); |
| 618 | return result; |
| 619 | } |
| 620 | |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 621 | bool ContainsWebstoreTile(content::RenderFrameHost* iframe) { |
| 622 | int num_webstore_tiles = 0; |
| 623 | EXPECT_TRUE(instant_test_utils::GetIntFromJS( |
| 624 | iframe, |
| 625 | "document.querySelectorAll(\".md-tile[href='" + |
| 626 | l10n_util::GetStringUTF8(IDS_WEBSTORE_URL) + "']\").length", |
| 627 | &num_webstore_tiles)); |
| 628 | return num_webstore_tiles == 1; |
| 629 | } |
| 630 | |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 631 | #if defined(OS_CHROMEOS) |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 632 | class TestAudioObserver : public chromeos::CrasAudioHandler::AudioObserver { |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 633 | public: |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 634 | TestAudioObserver() : output_mute_changed_count_(0) { |
| 635 | } |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 636 | |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 637 | int output_mute_changed_count() const { |
| 638 | return output_mute_changed_count_; |
| 639 | } |
| 640 | |
dcheng | 6d888df | 2015-01-16 18:12:48 | [diff] [blame] | 641 | ~TestAudioObserver() override {} |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 642 | |
| 643 | protected: |
| 644 | // chromeos::CrasAudioHandler::AudioObserver overrides. |
Evan Stade | 5a226fb | 2019-03-18 17:02:12 | [diff] [blame] | 645 | void OnOutputMuteChanged(bool /* mute_on */) override { |
jennyz | 170e7fb | 2015-03-30 23:37:39 | [diff] [blame] | 646 | ++output_mute_changed_count_; |
| 647 | } |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 648 | |
| 649 | private: |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 650 | int output_mute_changed_count_; |
| 651 | |
| 652 | DISALLOW_COPY_AND_ASSIGN(TestAudioObserver); |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 653 | }; |
| 654 | #endif |
| 655 | |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 656 | // This class waits until either a load stops or the WebContents is destroyed. |
| 657 | class WebContentsLoadedOrDestroyedWatcher |
| 658 | : public content::WebContentsObserver { |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 659 | public: |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 660 | explicit WebContentsLoadedOrDestroyedWatcher( |
| 661 | content::WebContents* web_contents); |
dcheng | 32ae6bbb | 2014-10-22 08:47:29 | [diff] [blame] | 662 | ~WebContentsLoadedOrDestroyedWatcher() override; |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 663 | |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 664 | // Waits until the WebContents's load is done or until it is destroyed. |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 665 | void Wait(); |
| 666 | |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 667 | // Overridden WebContentsObserver methods. |
dcheng | 32ae6bbb | 2014-10-22 08:47:29 | [diff] [blame] | 668 | void WebContentsDestroyed() override; |
fdegans | 6ce28f5 | 2015-03-19 12:52:22 | [diff] [blame] | 669 | void DidStopLoading() override; |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 670 | |
| 671 | private: |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 672 | scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 673 | |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 674 | DISALLOW_COPY_AND_ASSIGN(WebContentsLoadedOrDestroyedWatcher); |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 675 | }; |
| 676 | |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 677 | WebContentsLoadedOrDestroyedWatcher::WebContentsLoadedOrDestroyedWatcher( |
| 678 | content::WebContents* web_contents) |
| 679 | : content::WebContentsObserver(web_contents), |
| 680 | message_loop_runner_(new content::MessageLoopRunner) { |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 681 | } |
| 682 | |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 683 | WebContentsLoadedOrDestroyedWatcher::~WebContentsLoadedOrDestroyedWatcher() {} |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 684 | |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 685 | void WebContentsLoadedOrDestroyedWatcher::Wait() { |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 686 | message_loop_runner_->Run(); |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 687 | } |
| 688 | |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 689 | void WebContentsLoadedOrDestroyedWatcher::WebContentsDestroyed() { |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 690 | message_loop_runner_->Quit(); |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 691 | } |
| 692 | |
fdegans | 6ce28f5 | 2015-03-19 12:52:22 | [diff] [blame] | 693 | void WebContentsLoadedOrDestroyedWatcher::DidStopLoading() { |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 694 | message_loop_runner_->Quit(); |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 695 | } |
| 696 | |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 697 | #if !defined(OS_MACOSX) |
| 698 | |
[email protected] | dbb03fb | 2014-02-15 05:36:33 | [diff] [blame] | 699 | // Observer used to wait for the creation of a new app window. |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 700 | class TestAddAppWindowObserver |
| 701 | : public extensions::AppWindowRegistry::Observer { |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 702 | public: |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 703 | explicit TestAddAppWindowObserver(extensions::AppWindowRegistry* registry); |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 704 | ~TestAddAppWindowObserver() override; |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 705 | |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 706 | // extensions::AppWindowRegistry::Observer: |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 707 | void OnAppWindowAdded(extensions::AppWindow* app_window) override; |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 708 | |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 709 | extensions::AppWindow* WaitForAppWindow(); |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 710 | |
| 711 | private: |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 712 | extensions::AppWindowRegistry* registry_; // Not owned. |
| 713 | extensions::AppWindow* window_; // Not owned. |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 714 | base::RunLoop run_loop_; |
| 715 | |
[email protected] | dbb03fb | 2014-02-15 05:36:33 | [diff] [blame] | 716 | DISALLOW_COPY_AND_ASSIGN(TestAddAppWindowObserver); |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 717 | }; |
| 718 | |
[email protected] | dbb03fb | 2014-02-15 05:36:33 | [diff] [blame] | 719 | TestAddAppWindowObserver::TestAddAppWindowObserver( |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 720 | extensions::AppWindowRegistry* registry) |
[email protected] | dbb03fb | 2014-02-15 05:36:33 | [diff] [blame] | 721 | : registry_(registry), window_(NULL) { |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 722 | registry_->AddObserver(this); |
| 723 | } |
| 724 | |
[email protected] | dbb03fb | 2014-02-15 05:36:33 | [diff] [blame] | 725 | TestAddAppWindowObserver::~TestAddAppWindowObserver() { |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 726 | registry_->RemoveObserver(this); |
| 727 | } |
| 728 | |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 729 | void TestAddAppWindowObserver::OnAppWindowAdded( |
| 730 | extensions::AppWindow* app_window) { |
[email protected] | dbb03fb | 2014-02-15 05:36:33 | [diff] [blame] | 731 | window_ = app_window; |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 732 | run_loop_.Quit(); |
| 733 | } |
| 734 | |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 735 | extensions::AppWindow* TestAddAppWindowObserver::WaitForAppWindow() { |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 736 | run_loop_.Run(); |
| 737 | return window_; |
| 738 | } |
| 739 | |
| 740 | #endif |
| 741 | |
Michael Giuffrida | 9e1a9f8 | 2017-08-08 14:23:29 | [diff] [blame] | 742 | #if !defined(OS_CHROMEOS) |
| 743 | extensions::MessagingDelegate::PolicyPermission IsNativeMessagingHostAllowed( |
| 744 | content::BrowserContext* browser_context, |
| 745 | const std::string& native_host_name) { |
| 746 | extensions::MessagingDelegate* messaging_delegate = |
| 747 | extensions::ExtensionsAPIClient::Get()->GetMessagingDelegate(); |
| 748 | EXPECT_NE(messaging_delegate, nullptr); |
| 749 | return messaging_delegate->IsNativeMessagingHostAllowed(browser_context, |
| 750 | native_host_name); |
| 751 | } |
| 752 | #endif |
| 753 | |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 754 | class MockPasswordProtectionService |
| 755 | : public safe_browsing::ChromePasswordProtectionService { |
| 756 | public: |
| 757 | MockPasswordProtectionService(safe_browsing::SafeBrowsingService* sb_service, |
| 758 | Profile* profile) |
| 759 | : safe_browsing::ChromePasswordProtectionService(sb_service, profile) {} |
| 760 | ~MockPasswordProtectionService() override {} |
| 761 | |
| 762 | MOCK_CONST_METHOD0(GetSyncAccountType, |
| 763 | safe_browsing::LoginReputationClientRequest:: |
| 764 | PasswordReuseEvent::SyncAccountType()); |
| 765 | |
| 766 | AccountInfo GetAccountInfo() const override { |
| 767 | AccountInfo info; |
| 768 | info.email = "[email protected]"; |
| 769 | return info; |
| 770 | } |
| 771 | }; |
| 772 | |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 773 | } // namespace |
| 774 | |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 775 | class PolicyTest : public InProcessBrowserTest { |
| 776 | protected: |
| 777 | PolicyTest() {} |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 778 | ~PolicyTest() override {} |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 779 | |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 780 | void SetUp() override { |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 781 | test_extension_cache_.reset(new extensions::ExtensionCacheFake()); |
| 782 | InProcessBrowserTest::SetUp(); |
| 783 | } |
| 784 | |
dcheng | 32ae6bbb | 2014-10-22 08:47:29 | [diff] [blame] | 785 | void SetUpInProcessBrowserTestFixture() override { |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 786 | base::CommandLine::ForCurrentProcess()->AppendSwitch("noerrdialogs"); |
[email protected] | 49d5d42 | 2013-01-31 15:50:49 | [diff] [blame] | 787 | EXPECT_CALL(provider_, IsInitializationComplete(_)) |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 788 | .WillRepeatedly(Return(true)); |
| 789 | BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 790 | } |
| 791 | |
dcheng | 32ae6bbb | 2014-10-22 08:47:29 | [diff] [blame] | 792 | void SetUpOnMainThread() override { |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 793 | host_resolver()->AddRule("*", "127.0.0.1"); |
rockot | ffa65b1 | 2014-10-14 17:19:06 | [diff] [blame] | 794 | if (extension_service()->updater()) { |
| 795 | extension_service()->updater()->SetExtensionCacheForTesting( |
| 796 | test_extension_cache_.get()); |
| 797 | } |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 798 | } |
| 799 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 800 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 801 | variations::testing::VariationParamsManager::AppendVariationParams( |
| 802 | "ReportCertificateErrors", "ShowAndPossiblySend", |
| 803 | {{"sendingThreshold", "1.0"}}, command_line); |
| 804 | } |
| 805 | |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 806 | void SetScreenshotPolicy(bool enabled) { |
| 807 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 808 | policies.Set(key::kDisableScreenshots, POLICY_LEVEL_MANDATORY, |
| 809 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 810 | std::make_unique<base::Value>(!enabled), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 811 | UpdateProviderPolicy(policies); |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 812 | } |
| 813 | |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 814 | void SetShouldRequireCTForTesting(bool* required) { |
Clark DuVall | 8c88d4ef0 | 2018-11-30 01:45:16 | [diff] [blame] | 815 | if (content::IsOutOfProcessNetworkService()) { |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 816 | network::mojom::NetworkServiceTestPtr network_service_test; |
Ken Rockot | eff2b82 | 2019-06-20 22:56:53 | [diff] [blame] | 817 | content::GetSystemConnector()->BindInterface( |
| 818 | content::mojom::kNetworkServiceName, &network_service_test); |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 819 | network::mojom::NetworkServiceTest::ShouldRequireCT required_ct; |
| 820 | if (!required) { |
| 821 | required_ct = |
| 822 | network::mojom::NetworkServiceTest::ShouldRequireCT::RESET; |
| 823 | } else { |
| 824 | required_ct = |
| 825 | *required |
| 826 | ? network::mojom::NetworkServiceTest::ShouldRequireCT::REQUIRE |
| 827 | : network::mojom::NetworkServiceTest::ShouldRequireCT:: |
| 828 | DONT_REQUIRE; |
| 829 | } |
| 830 | |
| 831 | mojo::ScopedAllowSyncCallForTesting allow_sync_call; |
| 832 | network_service_test->SetShouldRequireCT(required_ct); |
| 833 | return; |
| 834 | } |
| 835 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 836 | base::PostTaskWithTraits( |
| 837 | FROM_HERE, {BrowserThread::IO}, |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 838 | base::BindOnce( |
| 839 | &net::TransportSecurityState::SetShouldRequireCTForTesting, |
| 840 | required)); |
| 841 | } |
| 842 | |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 843 | #if defined(OS_CHROMEOS) |
Elliot Glaysher | 685b3cd | 2018-02-01 23:17:55 | [diff] [blame] | 844 | class QuitMessageLoopAfterScreenshot |
| 845 | : public ChromeScreenshotGrabberTestObserver { |
[email protected] | 24e4cac | 2014-01-15 09:54:59 | [diff] [blame] | 846 | public: |
Wez | c0998d08 | 2018-07-06 17:50:18 | [diff] [blame] | 847 | explicit QuitMessageLoopAfterScreenshot(base::OnceClosure done) |
| 848 | : done_(std::move(done)) {} |
dcheng | 6d888df | 2015-01-16 18:12:48 | [diff] [blame] | 849 | void OnScreenshotCompleted( |
Elliot Glaysher | 685b3cd | 2018-02-01 23:17:55 | [diff] [blame] | 850 | ui::ScreenshotResult screenshot_result, |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame] | 851 | const base::FilePath& screenshot_path) override { |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 852 | base::PostTaskWithTraitsAndReply(FROM_HERE, {BrowserThread::IO}, |
| 853 | base::DoNothing(), std::move(done_)); |
[email protected] | 24e4cac | 2014-01-15 09:54:59 | [diff] [blame] | 854 | } |
| 855 | |
dcheng | 6d888df | 2015-01-16 18:12:48 | [diff] [blame] | 856 | ~QuitMessageLoopAfterScreenshot() override {} |
Wez | c0998d08 | 2018-07-06 17:50:18 | [diff] [blame] | 857 | |
| 858 | private: |
| 859 | base::OnceClosure done_; |
[email protected] | 24e4cac | 2014-01-15 09:54:59 | [diff] [blame] | 860 | }; |
| 861 | |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 862 | void TestScreenshotFile(bool enabled) { |
Wez | c0998d08 | 2018-07-06 17:50:18 | [diff] [blame] | 863 | base::RunLoop run_loop; |
| 864 | QuitMessageLoopAfterScreenshot observer_(run_loop.QuitClosure()); |
| 865 | |
James Cook | 5e9d340 | 2017-11-01 00:20:12 | [diff] [blame] | 866 | ChromeScreenshotGrabber* grabber = ChromeScreenshotGrabber::Get(); |
Elliot Glaysher | 685b3cd | 2018-02-01 23:17:55 | [diff] [blame] | 867 | grabber->test_observer_ = &observer_; |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 868 | SetScreenshotPolicy(enabled); |
James Cook | 5e9d340 | 2017-11-01 00:20:12 | [diff] [blame] | 869 | grabber->HandleTakeScreenshotForAllRootWindows(); |
Wez | c0998d08 | 2018-07-06 17:50:18 | [diff] [blame] | 870 | run_loop.Run(); |
| 871 | |
Elliot Glaysher | 685b3cd | 2018-02-01 23:17:55 | [diff] [blame] | 872 | grabber->test_observer_ = nullptr; |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 873 | } |
James Cook | 5e9d340 | 2017-11-01 00:20:12 | [diff] [blame] | 874 | #endif // defined(OS_CHROMEOS) |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 875 | |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 876 | extensions::ExtensionService* extension_service() { |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 877 | extensions::ExtensionSystem* system = |
| 878 | extensions::ExtensionSystem::Get(browser()->profile()); |
| 879 | return system->extension_service(); |
| 880 | } |
| 881 | |
| 882 | const extensions::Extension* InstallExtension( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 883 | const base::FilePath::StringType& name) { |
| 884 | base::FilePath extension_path(ui_test_utils::GetTestFilePath( |
| 885 | base::FilePath(kTestExtensionsDir), base::FilePath(name))); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 886 | scoped_refptr<extensions::CrxInstaller> installer = |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 887 | extensions::CrxInstaller::CreateSilent(extension_service()); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 888 | installer->set_allow_silent_install(true); |
| 889 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
| 890 | installer->set_creation_flags(extensions::Extension::FROM_WEBSTORE); |
Joshua Pawlicki | fd01b7c | 2019-01-17 16:18:34 | [diff] [blame] | 891 | installer->set_off_store_install_allow_reason( |
| 892 | extensions::CrxInstaller::OffStoreInstallAllowReason:: |
| 893 | OffStoreInstallAllowedInTest); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 894 | |
| 895 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 896 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 897 | content::NotificationService::AllSources()); |
| 898 | installer->InstallCrx(extension_path); |
| 899 | observer.Wait(); |
| 900 | content::Details<const extensions::Extension> details = observer.details(); |
| 901 | return details.ptr(); |
| 902 | } |
| 903 | |
Christopher Lam | 96b044c | 2017-11-24 03:29:46 | [diff] [blame] | 904 | const extensions::Extension* InstallBookmarkApp() { |
| 905 | WebApplicationInfo web_app; |
| 906 | web_app.title = base::ASCIIToUTF16("Bookmark App"); |
| 907 | web_app.app_url = GURL("http://www.google.com"); |
| 908 | |
| 909 | scoped_refptr<extensions::CrxInstaller> installer = |
| 910 | extensions::CrxInstaller::CreateSilent(extension_service()); |
| 911 | |
| 912 | content::WindowedNotificationObserver observer( |
| 913 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
| 914 | content::NotificationService::AllSources()); |
| 915 | installer->InstallWebApp(web_app); |
| 916 | observer.Wait(); |
| 917 | content::Details<const extensions::Extension> details = observer.details(); |
| 918 | return details.ptr(); |
| 919 | } |
| 920 | |
limasdf | c83e0b7 | 2017-03-03 17:08:35 | [diff] [blame] | 921 | scoped_refptr<const extensions::Extension> LoadUnpackedExtension( |
| 922 | const base::FilePath::StringType& name) { |
[email protected] | ec1b3e71 | 2013-05-25 14:29:16 | [diff] [blame] | 923 | base::FilePath extension_path(ui_test_utils::GetTestFilePath( |
| 924 | base::FilePath(kTestExtensionsDir), base::FilePath(name))); |
limasdf | c83e0b7 | 2017-03-03 17:08:35 | [diff] [blame] | 925 | extensions::ChromeTestExtensionLoader loader(browser()->profile()); |
| 926 | return loader.LoadExtension(extension_path); |
[email protected] | ec1b3e71 | 2013-05-25 14:29:16 | [diff] [blame] | 927 | } |
| 928 | |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 929 | void UninstallExtension(const std::string& id, bool expect_success) { |
limasdf | 6ab4c2f | 2015-03-31 16:19:54 | [diff] [blame] | 930 | if (expect_success) { |
| 931 | extensions::TestExtensionRegistryObserver observer( |
| 932 | extensions::ExtensionRegistry::Get(browser()->profile())); |
| 933 | extension_service()->UninstallExtension( |
Devlin Cronin | 218df7f | 2017-11-21 21:41:31 | [diff] [blame] | 934 | id, extensions::UNINSTALL_REASON_FOR_TESTING, NULL); |
limasdf | 6ab4c2f | 2015-03-31 16:19:54 | [diff] [blame] | 935 | observer.WaitForExtensionUninstalled(); |
| 936 | } else { |
| 937 | content::WindowedNotificationObserver observer( |
| 938 | extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 939 | content::NotificationService::AllSources()); |
| 940 | extension_service()->UninstallExtension( |
| 941 | id, |
| 942 | extensions::UNINSTALL_REASON_FOR_TESTING, |
limasdf | 6ab4c2f | 2015-03-31 16:19:54 | [diff] [blame] | 943 | NULL); |
| 944 | observer.Wait(); |
| 945 | } |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 946 | } |
| 947 | |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 948 | void DisableExtension(const std::string& id) { |
limasdf | 6ab4c2f | 2015-03-31 16:19:54 | [diff] [blame] | 949 | extensions::TestExtensionRegistryObserver observer( |
| 950 | extensions::ExtensionRegistry::Get(browser()->profile())); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 951 | extension_service()->DisableExtension( |
Michael Giuffrida | b16cab3 | 2017-10-04 21:56:09 | [diff] [blame] | 952 | id, extensions::disable_reason::DISABLE_USER_ACTION); |
limasdf | 6ab4c2f | 2015-03-31 16:19:54 | [diff] [blame] | 953 | observer.WaitForExtensionUnloaded(); |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 954 | } |
| 955 | |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 956 | void UpdateProviderPolicy(const PolicyMap& policy) { |
Bartosz Fabianowski | 0248c49 | 2018-07-02 13:44:32 | [diff] [blame] | 957 | PolicyMap policy_with_defaults; |
| 958 | policy_with_defaults.CopyFrom(policy); |
| 959 | #if defined(OS_CHROMEOS) |
| 960 | SetEnterpriseUsersDefaults(&policy_with_defaults); |
| 961 | #endif |
| 962 | provider_.UpdateChromePolicy(policy_with_defaults); |
Gabriel Charette | bbb7d2f | 2018-04-24 07:58:06 | [diff] [blame] | 963 | DCHECK(base::MessageLoopCurrent::Get()); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 964 | base::RunLoop loop; |
| 965 | loop.RunUntilIdle(); |
| 966 | } |
| 967 | |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 968 | // Sends a mouse click at the given coordinates to the current renderer. |
| 969 | void PerformClick(int x, int y) { |
| 970 | content::WebContents* contents = |
| 971 | browser()->tab_strip_model()->GetActiveWebContents(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 972 | blink::WebMouseEvent click_event( |
| 973 | blink::WebInputEvent::kMouseDown, blink::WebInputEvent::kNoModifiers, |
Daniel Cheng | 93c80a9 | 2018-02-14 19:02:43 | [diff] [blame] | 974 | blink::WebInputEvent::GetStaticTimeStampForTests()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 975 | click_event.button = blink::WebMouseEvent::Button::kLeft; |
| 976 | click_event.click_count = 1; |
| 977 | click_event.SetPositionInWidget(x, y); |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 978 | contents->GetRenderViewHost()->GetWidget()->ForwardMouseEvent(click_event); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 979 | click_event.SetType(blink::WebInputEvent::kMouseUp); |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 980 | contents->GetRenderViewHost()->GetWidget()->ForwardMouseEvent(click_event); |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 981 | } |
| 982 | |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 983 | void SetPolicy(PolicyMap* policies, |
| 984 | const char* key, |
| 985 | std::unique_ptr<base::Value> value) { |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 986 | if (value) { |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 987 | policies->Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 988 | POLICY_SOURCE_CLOUD, std::move(value), nullptr); |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 989 | } else { |
| 990 | policies->Erase(key); |
| 991 | } |
| 992 | } |
| 993 | |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 994 | void ApplySafeSearchPolicy(std::unique_ptr<base::Value> legacy_safe_search, |
| 995 | std::unique_ptr<base::Value> google_safe_search, |
| 996 | std::unique_ptr<base::Value> legacy_youtube, |
| 997 | std::unique_ptr<base::Value> youtube_restrict) { |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 998 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 999 | SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); |
| 1000 | SetPolicy(&policies, key::kForceGoogleSafeSearch, |
| 1001 | std::move(google_safe_search)); |
| 1002 | SetPolicy(&policies, key::kForceYouTubeSafetyMode, |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1003 | std::move(legacy_youtube)); |
| 1004 | SetPolicy(&policies, key::kForceYouTubeRestrict, |
| 1005 | std::move(youtube_restrict)); |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1006 | UpdateProviderPolicy(policies); |
| 1007 | } |
| 1008 | |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 1009 | #if defined(OS_CHROMEOS) |
Darren Shen | 8604a21 | 2019-06-07 00:41:38 | [diff] [blame] | 1010 | void SetEnableFlag(const keyboard::KeyboardEnableFlag& flag) { |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 1011 | auto* keyboard_client = ChromeKeyboardControllerClient::Get(); |
| 1012 | keyboard_client->SetEnableFlag(flag); |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 1013 | } |
| 1014 | |
Darren Shen | 8604a21 | 2019-06-07 00:41:38 | [diff] [blame] | 1015 | void ClearEnableFlag(const keyboard::KeyboardEnableFlag& flag) { |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 1016 | auto* keyboard_client = ChromeKeyboardControllerClient::Get(); |
| 1017 | keyboard_client->ClearEnableFlag(flag); |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 1018 | } |
| 1019 | #endif |
| 1020 | |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 1021 | static GURL GetExpectedSearchURL(bool expect_safe_search) { |
| 1022 | std::string expected_url("http://google.com/"); |
| 1023 | if (expect_safe_search) { |
| 1024 | expected_url += "?" + |
| 1025 | std::string(safe_search_util::kSafeSearchSafeParameter) + |
| 1026 | "&" + safe_search_util::kSafeSearchSsuiParameter; |
| 1027 | } |
| 1028 | return GURL(expected_url); |
| 1029 | } |
| 1030 | |
John Abd-El-Malek | d2b62ee | 2018-11-20 07:43:34 | [diff] [blame] | 1031 | static void CheckSafeSearch(Browser* browser, |
| 1032 | bool expect_safe_search, |
| 1033 | const std::string& url = "http://google.com/") { |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1034 | content::WebContents* web_contents = |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 1035 | browser->tab_strip_model()->GetActiveWebContents(); |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1036 | content::TestNavigationObserver observer(web_contents); |
Evan Stade | ad9765ab | 2019-07-02 17:02:41 | [diff] [blame] | 1037 | ui_test_utils::SendToOmniboxAndSubmit(browser, url); |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1038 | observer.Wait(); |
Evan Stade | ad9765ab | 2019-07-02 17:02:41 | [diff] [blame] | 1039 | OmniboxEditModel* model = |
| 1040 | browser->window()->GetLocationBar()->GetOmniboxView()->model(); |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1041 | EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid()); |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 1042 | EXPECT_EQ(GetExpectedSearchURL(expect_safe_search), web_contents->GetURL()); |
| 1043 | } |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1044 | |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 1045 | static void CheckYouTubeRestricted( |
| 1046 | int youtube_restrict_mode, |
| 1047 | const std::map<GURL, net::HttpRequestHeaders>& urls_requested, |
| 1048 | const GURL& url) { |
| 1049 | auto iter = urls_requested.find(url); |
| 1050 | ASSERT_TRUE(iter != urls_requested.end()); |
| 1051 | std::string header; |
| 1052 | iter->second.GetHeader(safe_search_util::kYouTubeRestrictHeaderName, |
| 1053 | &header); |
| 1054 | if (youtube_restrict_mode == safe_search_util::YOUTUBE_RESTRICT_OFF) { |
| 1055 | EXPECT_TRUE(header.empty()); |
| 1056 | } else if (youtube_restrict_mode == |
| 1057 | safe_search_util::YOUTUBE_RESTRICT_MODERATE) { |
| 1058 | EXPECT_EQ(header, safe_search_util::kYouTubeRestrictHeaderValueModerate); |
| 1059 | } else if (youtube_restrict_mode == |
| 1060 | safe_search_util::YOUTUBE_RESTRICT_STRICT) { |
| 1061 | EXPECT_EQ(header, safe_search_util::kYouTubeRestrictHeaderValueStrict); |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1062 | } |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | static void CheckAllowedDomainsHeader( |
| 1066 | const std::string& allowed_domain, |
| 1067 | const std::map<GURL, net::HttpRequestHeaders>& urls_requested, |
| 1068 | const GURL& url) { |
| 1069 | auto iter = urls_requested.find(url); |
| 1070 | ASSERT_TRUE(iter != urls_requested.end()); |
| 1071 | if (allowed_domain.empty()) { |
| 1072 | EXPECT_TRUE( |
| 1073 | !iter->second.HasHeader(safe_search_util::kGoogleAppsAllowedDomains)); |
| 1074 | return; |
| 1075 | } |
| 1076 | |
| 1077 | std::string header; |
| 1078 | iter->second.GetHeader(safe_search_util::kGoogleAppsAllowedDomains, |
| 1079 | &header); |
| 1080 | EXPECT_EQ(header, allowed_domain); |
| 1081 | } |
| 1082 | |
| 1083 | static bool FetchSubresource(content::WebContents* web_contents, |
| 1084 | const GURL& url) { |
| 1085 | std::string script( |
| 1086 | "var xhr = new XMLHttpRequest();" |
| 1087 | "xhr.open('GET', '"); |
| 1088 | script += url.spec() + |
| 1089 | "', true);" |
| 1090 | "xhr.onload = function (e) {" |
| 1091 | " if (xhr.readyState === 4) {" |
| 1092 | " window.domAutomationController.send(xhr.status === 200);" |
| 1093 | " }" |
| 1094 | "};" |
| 1095 | "xhr.onerror = function () {" |
| 1096 | " window.domAutomationController.send(false);" |
| 1097 | "};" |
| 1098 | "xhr.send(null)"; |
| 1099 | bool xhr_result = false; |
| 1100 | bool execute_result = |
| 1101 | content::ExecuteScriptAndExtractBool(web_contents, script, &xhr_result); |
| 1102 | return xhr_result && execute_result; |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1103 | } |
| 1104 | |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 1105 | bool IsShowingInterstitial(content::WebContents* tab) { |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 1106 | security_interstitials::SecurityInterstitialTabHelper* helper = |
| 1107 | security_interstitials::SecurityInterstitialTabHelper::FromWebContents( |
| 1108 | tab); |
| 1109 | if (!helper) { |
| 1110 | return false; |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 1111 | } |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 1112 | return helper->GetBlockingPageForCurrentlyCommittedNavigationForTesting() != |
| 1113 | nullptr; |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | void WaitForInterstitial(content::WebContents* tab) { |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 1117 | ASSERT_TRUE(IsShowingInterstitial(tab)); |
| 1118 | ASSERT_TRUE(WaitForRenderFrameReady(tab->GetMainFrame())); |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 1119 | } |
| 1120 | |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 1121 | int IsExtendedReportingCheckboxVisibleOnInterstitial() { |
| 1122 | const std::string command = base::StringPrintf( |
| 1123 | "var node = document.getElementById('extended-reporting-opt-in');" |
| 1124 | "if (node) {" |
| 1125 | " window.domAutomationController.send(node.offsetWidth > 0 || " |
| 1126 | " node.offsetHeight > 0 ? %d : %d);" |
| 1127 | "} else {" |
| 1128 | // The node should be present but not visible, so trigger an error |
| 1129 | // by sending false if it's not present. |
| 1130 | " window.domAutomationController.send(%d);" |
| 1131 | "}", |
| 1132 | security_interstitials::CMD_TEXT_FOUND, |
| 1133 | security_interstitials::CMD_TEXT_NOT_FOUND, |
| 1134 | security_interstitials::CMD_ERROR); |
| 1135 | |
| 1136 | content::WebContents* tab = |
| 1137 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1138 | WaitForInterstitial(tab); |
| 1139 | int result = 0; |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 1140 | EXPECT_TRUE(content::ExecuteScriptAndExtractInt(tab->GetMainFrame(), |
| 1141 | command, &result)); |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 1142 | return result; |
| 1143 | } |
| 1144 | |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 1145 | void SendInterstitialCommand( |
| 1146 | content::WebContents* tab, |
| 1147 | security_interstitials::SecurityInterstitialCommand command) { |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 1148 | security_interstitials::SecurityInterstitialTabHelper* helper = |
| 1149 | security_interstitials::SecurityInterstitialTabHelper::FromWebContents( |
| 1150 | tab); |
| 1151 | helper->GetBlockingPageForCurrentlyCommittedNavigationForTesting() |
| 1152 | ->CommandReceived(base::NumberToString(command)); |
| 1153 | return; |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 1154 | } |
| 1155 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 1156 | MockConfigurationPolicyProvider provider_; |
| 1157 | std::unique_ptr<extensions::ExtensionCacheFake> test_extension_cache_; |
| 1158 | extensions::ScopedIgnoreContentVerifierForTest ignore_content_verifier_; |
| 1159 | extensions::ExtensionUpdater::ScopedSkipScheduledCheckForTest |
| 1160 | skip_scheduled_extension_checks_; |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 1161 | }; |
| 1162 | |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 1163 | #if defined(OS_WIN) |
| 1164 | // This policy only exists on Windows. |
| 1165 | |
| 1166 | // Sets the locale policy before the browser is started. |
| 1167 | class LocalePolicyTest : public PolicyTest { |
| 1168 | public: |
| 1169 | LocalePolicyTest() {} |
nick | ddb02ac | 2015-04-24 20:45:38 | [diff] [blame] | 1170 | ~LocalePolicyTest() override {} |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 1171 | |
nick | ddb02ac | 2015-04-24 20:45:38 | [diff] [blame] | 1172 | void SetUpInProcessBrowserTestFixture() override { |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 1173 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 1174 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1175 | policies.Set(key::kApplicationLocaleValue, POLICY_LEVEL_MANDATORY, |
| 1176 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1177 | std::make_unique<base::Value>("fr"), nullptr); |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 1178 | provider_.UpdateChromePolicy(policies); |
| 1179 | // The "en-US" ResourceBundle is always loaded before this step for tests, |
| 1180 | // but in this test we want the browser to load the bundle as it |
| 1181 | // normally would. |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 1182 | ui::ResourceBundle::CleanupSharedInstance(); |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 1183 | } |
| 1184 | }; |
| 1185 | |
| 1186 | IN_PROC_BROWSER_TEST_F(LocalePolicyTest, ApplicationLocaleValue) { |
| 1187 | // Verifies that the default locale can be overridden with policy. |
| 1188 | EXPECT_EQ("fr", g_browser_process->GetApplicationLocale()); |
[email protected] | 19506d54 | 2013-10-15 23:11:06 | [diff] [blame] | 1189 | ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 1190 | base::string16 french_title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| 1191 | base::string16 title; |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 1192 | EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title)); |
| 1193 | EXPECT_EQ(french_title, title); |
| 1194 | |
| 1195 | // Make sure this is really French and differs from the English title. |
Francois Doray | e6fb2d0 | 2017-10-18 21:29:13 | [diff] [blame] | 1196 | base::ScopedAllowBlockingForTesting allow_blocking; |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 1197 | std::string loaded = |
| 1198 | ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US"); |
| 1199 | EXPECT_EQ("en-US", loaded); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 1200 | base::string16 english_title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 1201 | EXPECT_NE(french_title, english_title); |
| 1202 | } |
| 1203 | #endif |
| 1204 | |
Alexander Hendrich | 55d0b0d9 | 2018-05-08 11:29:10 | [diff] [blame] | 1205 | #if defined(OS_CHROMEOS) |
Zakhar Voit | 1f16c5e | 2018-10-26 12:08:23 | [diff] [blame] | 1206 | IN_PROC_BROWSER_TEST_F(LoginPolicyTestBase, PRE_AllowedLanguages) { |
Alexander Hendrich | 55d0b0d9 | 2018-05-08 11:29:10 | [diff] [blame] | 1207 | SkipToLoginScreen(); |
| 1208 | LogIn(kAccountId, kAccountPassword, kEmptyServices); |
| 1209 | |
Jit Yao Yap | d219c5f | 2019-05-24 13:07:43 | [diff] [blame] | 1210 | Profile* const profile = GetProfileForActiveUser(); |
Alexander Hendrich | 9ce4926 | 2018-05-29 13:35:46 | [diff] [blame] | 1211 | PrefService* prefs = profile->GetPrefs(); |
| 1212 | |
| 1213 | // Set locale and preferred languages to "en-US". |
Ran Ji | 73f3b43 | 2018-07-15 22:10:27 | [diff] [blame] | 1214 | prefs->SetString(language::prefs::kApplicationLocale, "en-US"); |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 1215 | prefs->SetString(language::prefs::kPreferredLanguages, "en-US"); |
Alexander Hendrich | 9ce4926 | 2018-05-29 13:35:46 | [diff] [blame] | 1216 | |
| 1217 | // Set policy to only allow "fr" as locale. |
| 1218 | std::unique_ptr<base::DictionaryValue> policy = |
| 1219 | std::make_unique<base::DictionaryValue>(); |
Zakhar Voit | 1f16c5e | 2018-10-26 12:08:23 | [diff] [blame] | 1220 | base::ListValue allowed_languages; |
| 1221 | allowed_languages.AppendString("fr"); |
| 1222 | policy->SetKey(key::kAllowedLanguages, std::move(allowed_languages)); |
Roman Sorokin | 886bf37b | 2019-04-28 05:57:27 | [diff] [blame] | 1223 | user_policy_helper()->SetPolicyAndWait(*policy, base::DictionaryValue(), |
| 1224 | profile); |
Alexander Hendrich | 9ce4926 | 2018-05-29 13:35:46 | [diff] [blame] | 1225 | } |
| 1226 | |
Zakhar Voit | 1f16c5e | 2018-10-26 12:08:23 | [diff] [blame] | 1227 | IN_PROC_BROWSER_TEST_F(LoginPolicyTestBase, AllowedLanguages) { |
Alexander Hendrich | 9ce4926 | 2018-05-29 13:35:46 | [diff] [blame] | 1228 | LogIn(kAccountId, kAccountPassword, kEmptyServices); |
| 1229 | |
Jit Yao Yap | d219c5f | 2019-05-24 13:07:43 | [diff] [blame] | 1230 | Profile* const profile = GetProfileForActiveUser(); |
Alexander Hendrich | 9ce4926 | 2018-05-29 13:35:46 | [diff] [blame] | 1231 | const PrefService* prefs = profile->GetPrefs(); |
Alexander Hendrich | 55d0b0d9 | 2018-05-08 11:29:10 | [diff] [blame] | 1232 | |
| 1233 | // Verifies that the default locale has been overridden by policy |
| 1234 | // (see |GetMandatoryPoliciesValue|) |
| 1235 | Browser* browser = CreateBrowser(profile); |
Ran Ji | 73f3b43 | 2018-07-15 22:10:27 | [diff] [blame] | 1236 | EXPECT_EQ("fr", prefs->GetString(language::prefs::kApplicationLocale)); |
Alexander Hendrich | 55d0b0d9 | 2018-05-08 11:29:10 | [diff] [blame] | 1237 | ui_test_utils::NavigateToURL(browser, GURL(chrome::kChromeUINewTabURL)); |
| 1238 | base::string16 french_title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| 1239 | base::string16 title; |
| 1240 | EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser, &title)); |
| 1241 | EXPECT_EQ(french_title, title); |
| 1242 | |
| 1243 | // Make sure this is really French and differs from the English title. |
| 1244 | base::ScopedAllowBlockingForTesting allow_blocking; |
| 1245 | std::string loaded = |
| 1246 | ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US"); |
| 1247 | EXPECT_EQ("en-US", loaded); |
| 1248 | base::string16 english_title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| 1249 | EXPECT_NE(french_title, english_title); |
Alexander Hendrich | 9ce4926 | 2018-05-29 13:35:46 | [diff] [blame] | 1250 | |
| 1251 | // Verifiy that the enforced locale is added into the list of |
| 1252 | // preferred languages. |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 1253 | EXPECT_EQ("fr", prefs->GetString(language::prefs::kPreferredLanguages)); |
Alexander Hendrich | 55d0b0d9 | 2018-05-08 11:29:10 | [diff] [blame] | 1254 | } |
Alexander Hendrich | a4c3953 | 2018-06-27 08:33:05 | [diff] [blame] | 1255 | |
| 1256 | IN_PROC_BROWSER_TEST_F(LoginPolicyTestBase, AllowedInputMethods) { |
| 1257 | SkipToLoginScreen(); |
| 1258 | LogIn(kAccountId, kAccountPassword, kEmptyServices); |
| 1259 | |
Jit Yao Yap | d219c5f | 2019-05-24 13:07:43 | [diff] [blame] | 1260 | Profile* const profile = GetProfileForActiveUser(); |
Alexander Hendrich | a4c3953 | 2018-06-27 08:33:05 | [diff] [blame] | 1261 | |
| 1262 | chromeos::input_method::InputMethodManager* imm = |
| 1263 | chromeos::input_method::InputMethodManager::Get(); |
| 1264 | ASSERT_TRUE(imm); |
| 1265 | scoped_refptr<chromeos::input_method::InputMethodManager::State> ime_state = |
| 1266 | imm->GetActiveIMEState(); |
| 1267 | ASSERT_TRUE(ime_state.get()); |
| 1268 | |
| 1269 | std::vector<std::string> input_methods; |
| 1270 | input_methods.emplace_back("xkb:us::eng"); |
| 1271 | input_methods.emplace_back("xkb:fr::fra"); |
| 1272 | input_methods.emplace_back("xkb:de::ger"); |
| 1273 | EXPECT_TRUE(imm->MigrateInputMethods(&input_methods)); |
| 1274 | |
| 1275 | // No restrictions and current input method should be "xkb:us::eng" (default). |
| 1276 | EXPECT_EQ(0U, ime_state->GetAllowedInputMethods().size()); |
| 1277 | EXPECT_EQ(input_methods[0], ime_state->GetCurrentInputMethod().id()); |
| 1278 | EXPECT_TRUE(ime_state->EnableInputMethod(input_methods[1])); |
| 1279 | EXPECT_TRUE(ime_state->EnableInputMethod(input_methods[2])); |
| 1280 | |
| 1281 | // Set policy to only allow "xkb:fr::fra", "xkb:de::ger" an an invalid value |
| 1282 | // as input method. |
| 1283 | std::unique_ptr<base::DictionaryValue> policy = |
| 1284 | std::make_unique<base::DictionaryValue>(); |
| 1285 | base::ListValue allowed_input_methods; |
| 1286 | allowed_input_methods.AppendString("xkb:fr::fra"); |
| 1287 | allowed_input_methods.AppendString("xkb:de::ger"); |
| 1288 | allowed_input_methods.AppendString("invalid_value_will_be_ignored"); |
| 1289 | policy->SetKey(key::kAllowedInputMethods, std::move(allowed_input_methods)); |
Roman Sorokin | 886bf37b | 2019-04-28 05:57:27 | [diff] [blame] | 1290 | user_policy_helper()->SetPolicyAndWait(*policy, base::DictionaryValue(), |
| 1291 | profile); |
Alexander Hendrich | a4c3953 | 2018-06-27 08:33:05 | [diff] [blame] | 1292 | |
| 1293 | // Only "xkb:fr::fra", "xkb:de::ger" should be allowed, current input method |
| 1294 | // should be "xkb:fr::fra", enabling "xkb:us::eng" should not be possible, |
| 1295 | // enabling "xkb:de::ger" should be possible. |
| 1296 | EXPECT_EQ(2U, ime_state->GetAllowedInputMethods().size()); |
| 1297 | EXPECT_EQ(2U, ime_state->GetActiveInputMethods()->size()); |
| 1298 | EXPECT_EQ(input_methods[1], ime_state->GetCurrentInputMethod().id()); |
| 1299 | EXPECT_FALSE(ime_state->EnableInputMethod(input_methods[0])); |
| 1300 | EXPECT_TRUE(ime_state->EnableInputMethod(input_methods[2])); |
| 1301 | |
| 1302 | // Set policy to only allow an invalid value as input method. |
| 1303 | std::unique_ptr<base::DictionaryValue> policy_invalid = |
| 1304 | std::make_unique<base::DictionaryValue>(); |
| 1305 | base::ListValue invalid_input_methods; |
| 1306 | invalid_input_methods.AppendString("invalid_value_will_be_ignored"); |
| 1307 | policy_invalid->SetKey(key::kAllowedInputMethods, |
| 1308 | std::move(invalid_input_methods)); |
Roman Sorokin | 886bf37b | 2019-04-28 05:57:27 | [diff] [blame] | 1309 | user_policy_helper()->SetPolicyAndWait(*policy_invalid, |
| 1310 | base::DictionaryValue(), profile); |
Alexander Hendrich | a4c3953 | 2018-06-27 08:33:05 | [diff] [blame] | 1311 | |
| 1312 | // No restrictions and current input method should still be "xkb:fr::fra". |
| 1313 | EXPECT_EQ(0U, ime_state->GetAllowedInputMethods().size()); |
| 1314 | EXPECT_EQ(input_methods[1], ime_state->GetCurrentInputMethod().id()); |
| 1315 | EXPECT_TRUE(ime_state->EnableInputMethod(input_methods[0])); |
| 1316 | EXPECT_TRUE(ime_state->EnableInputMethod(input_methods[2])); |
| 1317 | |
| 1318 | // Allow all input methods again. |
Roman Sorokin | 886bf37b | 2019-04-28 05:57:27 | [diff] [blame] | 1319 | user_policy_helper()->SetPolicyAndWait(base::DictionaryValue(), |
| 1320 | base::DictionaryValue(), profile); |
Alexander Hendrich | a4c3953 | 2018-06-27 08:33:05 | [diff] [blame] | 1321 | |
| 1322 | // No restrictions and current input method should still be "xkb:fr::fra". |
| 1323 | EXPECT_EQ(0U, ime_state->GetAllowedInputMethods().size()); |
| 1324 | EXPECT_EQ(input_methods[1], ime_state->GetCurrentInputMethod().id()); |
| 1325 | EXPECT_TRUE(ime_state->EnableInputMethod(input_methods[0])); |
| 1326 | EXPECT_TRUE(ime_state->EnableInputMethod(input_methods[2])); |
| 1327 | } |
| 1328 | |
Jit Yao Yap | d219c5f | 2019-05-24 13:07:43 | [diff] [blame] | 1329 | class StartupBrowserWindowLaunchSuppressedTest : public LoginPolicyTestBase { |
| 1330 | public: |
| 1331 | StartupBrowserWindowLaunchSuppressedTest() = default; |
| 1332 | |
| 1333 | void SetUpPolicy(bool enabled) { |
| 1334 | std::unique_ptr<base::DictionaryValue> policy = |
| 1335 | std::make_unique<base::DictionaryValue>(); |
| 1336 | |
| 1337 | policy->SetKey(key::kStartupBrowserWindowLaunchSuppressed, |
| 1338 | base::Value(enabled)); |
| 1339 | |
| 1340 | user_policy_helper()->SetPolicy(*policy, base::DictionaryValue()); |
| 1341 | } |
| 1342 | |
| 1343 | void CheckLaunchedBrowserCount(unsigned int count) { |
| 1344 | SkipToLoginScreen(); |
| 1345 | LogIn(kAccountId, kAccountPassword, kEmptyServices); |
| 1346 | |
| 1347 | Profile* const profile = GetProfileForActiveUser(); |
| 1348 | |
| 1349 | ASSERT_EQ(count, chrome::GetBrowserCount(profile)); |
| 1350 | } |
| 1351 | |
| 1352 | private: |
| 1353 | DISALLOW_COPY_AND_ASSIGN(StartupBrowserWindowLaunchSuppressedTest); |
| 1354 | }; |
| 1355 | |
| 1356 | // Test that the browser window is not launched when |
| 1357 | // StartupBrowserWindowLaunchSuppressed is set to true. |
| 1358 | IN_PROC_BROWSER_TEST_F(StartupBrowserWindowLaunchSuppressedTest, |
| 1359 | TrueDoesNotAllowBrowserWindowLaunch) { |
| 1360 | SetUpPolicy(true); |
| 1361 | CheckLaunchedBrowserCount(0u); |
| 1362 | } |
| 1363 | |
| 1364 | // Test that the browser window is launched when |
| 1365 | // StartupBrowserWindowLaunchSuppressed is set to false. |
| 1366 | IN_PROC_BROWSER_TEST_F(StartupBrowserWindowLaunchSuppressedTest, |
| 1367 | FalseAllowsBrowserWindowLaunch) { |
| 1368 | SetUpPolicy(false); |
| 1369 | CheckLaunchedBrowserCount(1u); |
| 1370 | } |
| 1371 | |
Alexander Hendrich | a4c3953 | 2018-06-27 08:33:05 | [diff] [blame] | 1372 | #endif // defined(OS_CHROMEOS) |
Alexander Hendrich | 55d0b0d9 | 2018-05-08 11:29:10 | [diff] [blame] | 1373 | |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 1374 | IN_PROC_BROWSER_TEST_F(PolicyTest, BookmarkBarEnabled) { |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 1375 | // Verifies that the bookmarks bar can be forced to always or never show up. |
| 1376 | |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 1377 | // Test starts in about:blank. |
| 1378 | PrefService* prefs = browser()->profile()->GetPrefs(); |
tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 1379 | EXPECT_FALSE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar)); |
| 1380 | EXPECT_FALSE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 1381 | EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); |
| 1382 | |
| 1383 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1384 | policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, |
| 1385 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1386 | std::make_unique<base::Value>(true), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 1387 | UpdateProviderPolicy(policies); |
tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 1388 | EXPECT_TRUE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar)); |
| 1389 | EXPECT_TRUE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 1390 | EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 1391 | } |
| 1392 | |
[email protected] | 96da69d1 | 2013-05-28 17:00:05 | [diff] [blame] | 1393 | IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_PRE_DefaultCookiesSetting) { |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 1394 | // Verifies that cookies are deleted on shutdown. This test is split in 3 |
| 1395 | // parts because it spans 2 browser restarts. |
| 1396 | |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 1397 | Profile* profile = browser()->profile(); |
| 1398 | GURL url(kURL); |
| 1399 | // No cookies at startup. |
| 1400 | EXPECT_TRUE(content::GetCookies(profile, url).empty()); |
| 1401 | // Set a cookie now. |
Clark DuVall | 385b5a5 | 2018-06-14 21:33:32 | [diff] [blame] | 1402 | std::string value = base::StrCat({kCookieValue, kCookieOptions}); |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 1403 | EXPECT_TRUE(content::SetCookie(profile, url, value)); |
| 1404 | // Verify it was set. |
| 1405 | EXPECT_EQ(kCookieValue, GetCookies(profile, url)); |
| 1406 | } |
| 1407 | |
[email protected] | 96da69d1 | 2013-05-28 17:00:05 | [diff] [blame] | 1408 | IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_DefaultCookiesSetting) { |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 1409 | // Verify that the cookie persists across restarts. |
| 1410 | EXPECT_EQ(kCookieValue, GetCookies(browser()->profile(), GURL(kURL))); |
| 1411 | // Now set the policy and the cookie should be gone after another restart. |
| 1412 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1413 | policies.Set(key::kDefaultCookiesSetting, POLICY_LEVEL_MANDATORY, |
| 1414 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Clark DuVall | 385b5a5 | 2018-06-14 21:33:32 | [diff] [blame] | 1415 | std::make_unique<base::Value>(CONTENT_SETTING_SESSION_ONLY), |
| 1416 | nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 1417 | UpdateProviderPolicy(policies); |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 1418 | } |
| 1419 | |
[email protected] | 96da69d1 | 2013-05-28 17:00:05 | [diff] [blame] | 1420 | IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultCookiesSetting) { |
[email protected] | b561aab | 2012-08-27 20:17:49 | [diff] [blame] | 1421 | // Verify that the cookie is gone. |
| 1422 | EXPECT_TRUE(GetCookies(browser()->profile(), GURL(kURL)).empty()); |
| 1423 | } |
| 1424 | |
Clark DuVall | 385b5a5 | 2018-06-14 21:33:32 | [diff] [blame] | 1425 | IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_PRE_WebsiteCookiesSetting) { |
| 1426 | // Verifies that cookies are deleted on shutdown. This test is split in 3 |
| 1427 | // parts because it spans 2 browser restarts. |
| 1428 | |
| 1429 | Profile* profile = browser()->profile(); |
| 1430 | GURL url(kURL); |
| 1431 | // No cookies at startup. |
| 1432 | EXPECT_TRUE(content::GetCookies(profile, url).empty()); |
| 1433 | // Set a cookie now. |
| 1434 | std::string value = base::StrCat({kCookieValue, kCookieOptions}); |
| 1435 | EXPECT_TRUE(content::SetCookie(profile, url, value)); |
| 1436 | // Verify it was set. |
| 1437 | EXPECT_EQ(kCookieValue, GetCookies(profile, url)); |
| 1438 | } |
| 1439 | |
| 1440 | IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_WebsiteCookiesSetting) { |
| 1441 | // Verify that the cookie persists across restarts. |
| 1442 | EXPECT_EQ(kCookieValue, GetCookies(browser()->profile(), GURL(kURL))); |
| 1443 | // Now set the policy and the cookie should be gone after another restart. |
| 1444 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 1445 | ->SetWebsiteSettingDefaultScope( |
| 1446 | GURL(kURL), GURL(kURL), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 1447 | std::make_unique<base::Value>(CONTENT_SETTING_SESSION_ONLY)); |
| 1448 | } |
| 1449 | |
| 1450 | IN_PROC_BROWSER_TEST_F(PolicyTest, WebsiteCookiesSetting) { |
| 1451 | // Verify that the cookie is gone. |
| 1452 | EXPECT_TRUE(GetCookies(browser()->profile(), GURL(kURL)).empty()); |
| 1453 | } |
| 1454 | |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1455 | IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { |
[email protected] | f53b480 | 2012-12-20 17:04:23 | [diff] [blame] | 1456 | MakeRequestFail make_request_fail("search.example"); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 1457 | |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1458 | // Verifies that a default search is made using the provider configured via |
| 1459 | // policy. Also checks that default search can be completely disabled. |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 1460 | const base::string16 kKeyword(base::ASCIIToUTF16("testsearch")); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1461 | const std::string kSearchURL("http://search.example/search?q={searchTerms}"); |
[email protected] | 250bf23 | 2012-10-15 14:36:33 | [diff] [blame] | 1462 | const std::string kAlternateURL0( |
| 1463 | "http://search.example/search#q={searchTerms}"); |
| 1464 | const std::string kAlternateURL1("http://search.example/#q={searchTerms}"); |
[email protected] | 39682d1 | 2013-07-31 23:02:05 | [diff] [blame] | 1465 | const std::string kImageURL("http://test.com/searchbyimage/upload"); |
| 1466 | const std::string kImageURLPostParams( |
| 1467 | "image_content=content,image_url=http://test.com/test.png"); |
[email protected] | 041238dd | 2013-08-19 21:05:12 | [diff] [blame] | 1468 | const std::string kNewTabURL("http://search.example/newtab"); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1469 | |
| 1470 | TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( |
| 1471 | browser()->profile()); |
thestig | f8056446 | 2015-09-29 23:12:08 | [diff] [blame] | 1472 | search_test_utils::WaitForTemplateURLServiceToLoad(service); |
jeffschiller | 8aa7a4e | 2017-04-23 02:22:10 | [diff] [blame] | 1473 | const TemplateURL* default_search = service->GetDefaultSearchProvider(); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1474 | ASSERT_TRUE(default_search); |
| 1475 | EXPECT_NE(kKeyword, default_search->keyword()); |
| 1476 | EXPECT_NE(kSearchURL, default_search->url()); |
[email protected] | 250bf23 | 2012-10-15 14:36:33 | [diff] [blame] | 1477 | EXPECT_FALSE( |
| 1478 | default_search->alternate_urls().size() == 2 && |
| 1479 | default_search->alternate_urls()[0] == kAlternateURL0 && |
[email protected] | 008987b0 | 2013-01-03 21:22:43 | [diff] [blame] | 1480 | default_search->alternate_urls()[1] == kAlternateURL1 && |
[email protected] | 39682d1 | 2013-07-31 23:02:05 | [diff] [blame] | 1481 | default_search->image_url() == kImageURL && |
[email protected] | 041238dd | 2013-08-19 21:05:12 | [diff] [blame] | 1482 | default_search->image_url_post_params() == kImageURLPostParams && |
| 1483 | default_search->new_tab_url() == kNewTabURL); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1484 | |
| 1485 | // Override the default search provider using policies. |
| 1486 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1487 | policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
| 1488 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1489 | std::make_unique<base::Value>(true), nullptr); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1490 | policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, |
| 1491 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1492 | std::make_unique<base::Value>(kKeyword), nullptr); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1493 | policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
| 1494 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1495 | std::make_unique<base::Value>(kSearchURL), nullptr); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1496 | std::unique_ptr<base::ListValue> alternate_urls(new base::ListValue); |
[email protected] | 250bf23 | 2012-10-15 14:36:33 | [diff] [blame] | 1497 | alternate_urls->AppendString(kAlternateURL0); |
| 1498 | alternate_urls->AppendString(kAlternateURL1); |
| 1499 | policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1500 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 1501 | std::move(alternate_urls), nullptr); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1502 | policies.Set(key::kDefaultSearchProviderImageURL, POLICY_LEVEL_MANDATORY, |
| 1503 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1504 | std::make_unique<base::Value>(kImageURL), nullptr); |
[email protected] | 39682d1 | 2013-07-31 23:02:05 | [diff] [blame] | 1505 | policies.Set(key::kDefaultSearchProviderImageURLPostParams, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1506 | POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1507 | std::make_unique<base::Value>(kImageURLPostParams), nullptr); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1508 | policies.Set(key::kDefaultSearchProviderNewTabURL, POLICY_LEVEL_MANDATORY, |
| 1509 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1510 | std::make_unique<base::Value>(kNewTabURL), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 1511 | UpdateProviderPolicy(policies); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1512 | default_search = service->GetDefaultSearchProvider(); |
| 1513 | ASSERT_TRUE(default_search); |
| 1514 | EXPECT_EQ(kKeyword, default_search->keyword()); |
| 1515 | EXPECT_EQ(kSearchURL, default_search->url()); |
[email protected] | 250bf23 | 2012-10-15 14:36:33 | [diff] [blame] | 1516 | EXPECT_EQ(2U, default_search->alternate_urls().size()); |
| 1517 | EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); |
| 1518 | EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); |
[email protected] | 39682d1 | 2013-07-31 23:02:05 | [diff] [blame] | 1519 | EXPECT_EQ(kImageURL, default_search->image_url()); |
| 1520 | EXPECT_EQ(kImageURLPostParams, default_search->image_url_post_params()); |
[email protected] | 041238dd | 2013-08-19 21:05:12 | [diff] [blame] | 1521 | EXPECT_EQ(kNewTabURL, default_search->new_tab_url()); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1522 | |
| 1523 | // Verify that searching from the omnibox uses kSearchURL. |
| 1524 | chrome::FocusLocationBar(browser()); |
Evan Stade | ad9765ab | 2019-07-02 17:02:41 | [diff] [blame] | 1525 | ui_test_utils::SendToOmniboxAndSubmit(browser(), "stuff to search for"); |
| 1526 | OmniboxEditModel* model = |
| 1527 | browser()->window()->GetLocationBar()->GetOmniboxView()->model(); |
[email protected] | 31511bbc | 2013-06-18 17:40:57 | [diff] [blame] | 1528 | EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid()); |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 1529 | content::WebContents* web_contents = |
| 1530 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1531 | GURL expected("http://search.example/search?q=stuff+to+search+for"); |
| 1532 | EXPECT_EQ(expected, web_contents->GetURL()); |
| 1533 | |
| 1534 | // Verify that searching from the omnibox can be disabled. |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 1535 | ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1536 | policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
| 1537 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1538 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1539 | EXPECT_TRUE(service->GetDefaultSearchProvider()); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 1540 | UpdateProviderPolicy(policies); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1541 | EXPECT_FALSE(service->GetDefaultSearchProvider()); |
Evan Stade | ad9765ab | 2019-07-02 17:02:41 | [diff] [blame] | 1542 | ui_test_utils::SendToOmniboxAndSubmit(browser(), "should not work"); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1543 | // This means that submitting won't trigger any action. |
[email protected] | 31511bbc | 2013-06-18 17:40:57 | [diff] [blame] | 1544 | EXPECT_FALSE(model->CurrentMatch(NULL).destination_url.is_valid()); |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 1545 | EXPECT_EQ(GURL(url::kAboutBlankURL), web_contents->GetURL()); |
[email protected] | 771c4b9 | 2012-08-29 10:19:27 | [diff] [blame] | 1546 | } |
| 1547 | |
emaxx | b88b2c6 | 2017-01-31 17:50:19 | [diff] [blame] | 1548 | IN_PROC_BROWSER_TEST_F(PolicyTest, SeparateProxyPoliciesMerging) { |
[email protected] | f97bd48 | 2013-11-21 13:04:28 | [diff] [blame] | 1549 | // Add an individual proxy policy value. |
| 1550 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1551 | policies.Set(key::kProxyServerMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1552 | POLICY_SOURCE_CLOUD, std::make_unique<base::Value>(3), nullptr); |
[email protected] | f97bd48 | 2013-11-21 13:04:28 | [diff] [blame] | 1553 | UpdateProviderPolicy(policies); |
| 1554 | |
| 1555 | // It should be removed and replaced with a dictionary. |
| 1556 | PolicyMap expected; |
dcheng | 08cfe9ba | 2016-04-14 17:46:45 | [diff] [blame] | 1557 | std::unique_ptr<base::DictionaryValue> expected_value( |
| 1558 | new base::DictionaryValue); |
[email protected] | f97bd48 | 2013-11-21 13:04:28 | [diff] [blame] | 1559 | expected_value->SetInteger(key::kProxyServerMode, 3); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1560 | expected.Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 1561 | POLICY_SOURCE_CLOUD, std::move(expected_value), nullptr); |
Bartosz Fabianowski | 0248c49 | 2018-07-02 13:44:32 | [diff] [blame] | 1562 | #if defined(OS_CHROMEOS) |
| 1563 | SetEnterpriseUsersDefaults(&expected); |
| 1564 | #endif |
[email protected] | f97bd48 | 2013-11-21 13:04:28 | [diff] [blame] | 1565 | |
| 1566 | // Check both the browser and the profile. |
| 1567 | const PolicyMap& actual_from_browser = |
| 1568 | g_browser_process->browser_policy_connector() |
| 1569 | ->GetPolicyService() |
| 1570 | ->GetPolicies(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 1571 | EXPECT_TRUE(expected.Equals(actual_from_browser)); |
| 1572 | const PolicyMap& actual_from_profile = |
Xi Han | fe39afc6 | 2019-04-29 14:50:14 | [diff] [blame] | 1573 | browser() |
| 1574 | ->profile() |
| 1575 | ->GetProfilePolicyConnector() |
[email protected] | f97bd48 | 2013-11-21 13:04:28 | [diff] [blame] | 1576 | ->policy_service() |
| 1577 | ->GetPolicies(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 1578 | EXPECT_TRUE(expected.Equals(actual_from_profile)); |
| 1579 | } |
| 1580 | |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1581 | IN_PROC_BROWSER_TEST_F(PolicyTest, LegacySafeSearch) { |
| 1582 | static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 && |
| 1583 | safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 && |
| 1584 | safe_search_util::YOUTUBE_RESTRICT_STRICT == 2 && |
| 1585 | safe_search_util::YOUTUBE_RESTRICT_COUNT == 3, |
| 1586 | "This test relies on mapping ints to enum values."); |
| 1587 | |
| 1588 | // Go over all combinations of (undefined, true, false) for the policies |
| 1589 | // ForceSafeSearch, ForceGoogleSafeSearch and ForceYouTubeSafetyMode as well |
| 1590 | // as (undefined, off, moderate, strict) for ForceYouTubeRestrict and make |
| 1591 | // sure the prefs are set as expected. |
| 1592 | const int num_restrict_modes = 1 + safe_search_util::YOUTUBE_RESTRICT_COUNT; |
| 1593 | for (int i = 0; i < 3 * 3 * 3 * num_restrict_modes; i++) { |
| 1594 | int val = i; |
| 1595 | int legacy_safe_search = val % 3; val /= 3; |
| 1596 | int google_safe_search = val % 3; val /= 3; |
| 1597 | int legacy_youtube = val % 3; val /= 3; |
| 1598 | int youtube_restrict = val % num_restrict_modes; |
| 1599 | |
| 1600 | // Override the default SafeSearch setting using policies. |
| 1601 | ApplySafeSearchPolicy( |
| 1602 | legacy_safe_search == 0 |
| 1603 | ? nullptr |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1604 | : std::make_unique<base::Value>(legacy_safe_search == 1), |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1605 | google_safe_search == 0 |
| 1606 | ? nullptr |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1607 | : std::make_unique<base::Value>(google_safe_search == 1), |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1608 | legacy_youtube == 0 |
| 1609 | ? nullptr |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1610 | : std::make_unique<base::Value>(legacy_youtube == 1), |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1611 | youtube_restrict == 0 |
| 1612 | ? nullptr // subtracting 1 gives 0,1,2, see above |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1613 | : std::make_unique<base::Value>(youtube_restrict - 1)); |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1614 | |
| 1615 | // The legacy ForceSafeSearch policy should only have an effect if none of |
| 1616 | // the other 3 policies are defined. |
| 1617 | bool legacy_safe_search_in_effect = |
| 1618 | google_safe_search == 0 && legacy_youtube == 0 && |
| 1619 | youtube_restrict == 0 && legacy_safe_search != 0; |
| 1620 | bool legacy_safe_search_enabled = |
| 1621 | legacy_safe_search_in_effect && legacy_safe_search == 1; |
| 1622 | |
| 1623 | // Likewise, ForceYouTubeSafetyMode should only have an effect if |
| 1624 | // ForceYouTubeRestrict is not set. |
| 1625 | bool legacy_youtube_in_effect = |
| 1626 | youtube_restrict == 0 && legacy_youtube != 0; |
| 1627 | bool legacy_youtube_enabled = |
| 1628 | legacy_youtube_in_effect && legacy_youtube == 1; |
| 1629 | |
| 1630 | // Consistency check, can't have both legacy modes at the same time. |
| 1631 | EXPECT_FALSE(legacy_youtube_in_effect && legacy_safe_search_in_effect); |
| 1632 | |
| 1633 | // Google safe search can be triggered by the ForceGoogleSafeSearch policy |
| 1634 | // or the legacy safe search mode. |
| 1635 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 1636 | EXPECT_EQ(google_safe_search != 0 || legacy_safe_search_in_effect, |
| 1637 | prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); |
| 1638 | EXPECT_EQ(google_safe_search == 1 || legacy_safe_search_enabled, |
| 1639 | prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); |
| 1640 | |
| 1641 | // YouTube restrict mode can be triggered by the ForceYouTubeRestrict policy |
| 1642 | // or any of the legacy modes. |
| 1643 | EXPECT_EQ(youtube_restrict != 0 || legacy_safe_search_in_effect || |
| 1644 | legacy_youtube_in_effect, |
| 1645 | prefs->IsManagedPreference(prefs::kForceYouTubeRestrict)); |
| 1646 | |
| 1647 | if (youtube_restrict != 0) { |
| 1648 | // The ForceYouTubeRestrict policy should map directly to the pref. |
| 1649 | EXPECT_EQ(youtube_restrict - 1, |
| 1650 | prefs->GetInteger(prefs::kForceYouTubeRestrict)); |
| 1651 | } else { |
| 1652 | // The legacy modes should result in MODERATE strictness, if enabled. |
| 1653 | safe_search_util::YouTubeRestrictMode expected_mode = |
| 1654 | legacy_safe_search_enabled || legacy_youtube_enabled |
| 1655 | ? safe_search_util::YOUTUBE_RESTRICT_MODERATE |
| 1656 | : safe_search_util::YOUTUBE_RESTRICT_OFF; |
| 1657 | EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict), expected_mode); |
| 1658 | } |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | IN_PROC_BROWSER_TEST_F(PolicyTest, ForceGoogleSafeSearch) { |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 1663 | base::Lock lock; |
| 1664 | std::set<GURL> google_urls_requested; |
| 1665 | content::URLLoaderInterceptor interceptor(base::BindLambdaForTesting( |
| 1666 | [&](content::URLLoaderInterceptor::RequestParams* params) -> bool { |
| 1667 | if (params->url_request.url.host() != "google.com") |
| 1668 | return false; |
| 1669 | base::AutoLock auto_lock(lock); |
| 1670 | google_urls_requested.insert(params->url_request.url); |
| 1671 | std::string relative_path("chrome/test/data/simple.html"); |
| 1672 | content::URLLoaderInterceptor::WriteResponse(relative_path, |
| 1673 | params->client.get()); |
| 1674 | return true; |
| 1675 | })); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 1676 | |
| 1677 | // Verifies that requests to Google Search engine with the SafeSearch |
| 1678 | // enabled set the safe=active&ssui=on parameters at the end of the query. |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 1679 | // First check that nothing happens. |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 1680 | CheckSafeSearch(browser(), false); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 1681 | |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1682 | // Go over all combinations of (undefined, true, false) for the |
| 1683 | // ForceGoogleSafeSearch policy. |
| 1684 | for (int safe_search = 0; safe_search < 3; safe_search++) { |
| 1685 | // Override the Google safe search policy. |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 1686 | ApplySafeSearchPolicy(nullptr, // ForceSafeSearch |
| 1687 | safe_search == 0 // ForceGoogleSafeSearch |
| 1688 | ? nullptr |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1689 | : std::make_unique<base::Value>(safe_search == 1), |
Lukasz Anforowicz | 0e9fdcd | 2017-09-28 13:00:03 | [diff] [blame] | 1690 | nullptr, // ForceYouTubeSafetyMode |
| 1691 | nullptr); // ForceYouTubeRestrict |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1692 | // Verify that the safe search pref behaves the way we expect. |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1693 | PrefService* prefs = browser()->profile()->GetPrefs(); |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1694 | EXPECT_EQ(safe_search != 0, |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1695 | prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1696 | EXPECT_EQ(safe_search == 1, |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1697 | prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 1698 | |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 1699 | // Verify that safe search actually works. |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 1700 | CheckSafeSearch(browser(), safe_search == 1); |
| 1701 | |
| 1702 | GURL google_url(GetExpectedSearchURL(safe_search == 1)); |
| 1703 | |
| 1704 | { |
| 1705 | // Verify that the network request is what we expect. |
| 1706 | base::AutoLock auto_lock(lock); |
| 1707 | ASSERT_TRUE(google_urls_requested.find(google_url) != |
| 1708 | google_urls_requested.end()); |
| 1709 | google_urls_requested.clear(); |
| 1710 | } |
| 1711 | |
| 1712 | { |
| 1713 | // Now check subresource loads. |
| 1714 | FetchSubresource(browser()->tab_strip_model()->GetActiveWebContents(), |
| 1715 | GURL("http://google.com/")); |
| 1716 | |
| 1717 | base::AutoLock auto_lock(lock); |
| 1718 | ASSERT_TRUE(google_urls_requested.find(google_url) != |
| 1719 | google_urls_requested.end()); |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | |
John Abd-El-Malek | d2b62ee | 2018-11-20 07:43:34 | [diff] [blame] | 1724 | class PolicyTestSafeSearchRedirect : public PolicyTest { |
| 1725 | public: |
| 1726 | PolicyTestSafeSearchRedirect() = default; |
| 1727 | |
| 1728 | private: |
| 1729 | void SetUpOnMainThread() override { |
| 1730 | // The test makes requests to google.com which we want to redirect to the |
| 1731 | // test server. |
| 1732 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 1733 | |
| 1734 | // The production code only allows known ports (80 for http and 443 for |
| 1735 | // https), but the test server runs on a random port. |
| 1736 | google_util::IgnorePortNumbersForGoogleURLChecksForTesting(); |
| 1737 | } |
| 1738 | |
| 1739 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1740 | // HTTPS server only serves a valid cert for localhost, so this is needed to |
| 1741 | // load pages from "www.google.com" without an interstitial. |
| 1742 | command_line->AppendSwitch(switches::kIgnoreCertificateErrors); |
| 1743 | } |
| 1744 | |
| 1745 | DISALLOW_COPY_AND_ASSIGN(PolicyTestSafeSearchRedirect); |
| 1746 | }; |
| 1747 | |
| 1748 | IN_PROC_BROWSER_TEST_F(PolicyTestSafeSearchRedirect, ForceGoogleSafeSearch) { |
| 1749 | net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
Alan Cutter | a9a96c5 | 2019-03-28 07:15:39 | [diff] [blame] | 1750 | https_server.AddDefaultHandlers(GetChromeTestDataDir()); |
John Abd-El-Malek | d2b62ee | 2018-11-20 07:43:34 | [diff] [blame] | 1751 | ASSERT_TRUE(https_server.Start()); |
| 1752 | |
| 1753 | ApplySafeSearchPolicy(nullptr, // ForceSafeSearch |
| 1754 | std::make_unique<base::Value>(true), |
| 1755 | nullptr, // ForceYouTubeSafetyMode |
| 1756 | nullptr); // ForceYouTubeRestrict |
| 1757 | |
| 1758 | GURL url = https_server.GetURL("www.google.com", |
| 1759 | "/server-redirect?http://google.com/"); |
| 1760 | CheckSafeSearch(browser(), true, url.spec()); |
| 1761 | } |
| 1762 | |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 1763 | IN_PROC_BROWSER_TEST_F(PolicyTest, ForceYouTubeRestrict) { |
| 1764 | base::Lock lock; |
| 1765 | std::map<GURL, net::HttpRequestHeaders> urls_requested; |
| 1766 | content::URLLoaderInterceptor interceptor(base::BindLambdaForTesting( |
| 1767 | [&](content::URLLoaderInterceptor::RequestParams* params) -> bool { |
| 1768 | if (params->url_request.url.host() != "youtube.com") |
| 1769 | return false; |
| 1770 | |
| 1771 | base::AutoLock auto_lock(lock); |
| 1772 | urls_requested[params->url_request.url] = params->url_request.headers; |
| 1773 | |
| 1774 | std::string relative_path("chrome/test/data/simple.html"); |
| 1775 | content::URLLoaderInterceptor::WriteResponse(relative_path, |
| 1776 | params->client.get()); |
| 1777 | return true; |
| 1778 | })); |
| 1779 | |
| 1780 | for (int youtube_restrict_mode = safe_search_util::YOUTUBE_RESTRICT_OFF; |
| 1781 | youtube_restrict_mode < safe_search_util::YOUTUBE_RESTRICT_COUNT; |
| 1782 | ++youtube_restrict_mode) { |
| 1783 | ApplySafeSearchPolicy(nullptr, // ForceSafeSearch |
| 1784 | nullptr, // ForceGoogleSafeSearch |
| 1785 | nullptr, // ForceYouTubeSafetyMode |
| 1786 | std::make_unique<base::Value>(youtube_restrict_mode)); |
| 1787 | { |
| 1788 | // First check frame requests. |
| 1789 | GURL youtube_url("http://youtube.com"); |
| 1790 | ui_test_utils::NavigateToURL(browser(), youtube_url); |
| 1791 | |
| 1792 | base::AutoLock auto_lock(lock); |
| 1793 | CheckYouTubeRestricted(youtube_restrict_mode, urls_requested, |
| 1794 | youtube_url); |
| 1795 | } |
| 1796 | |
| 1797 | { |
| 1798 | // Now check subresource loads. |
| 1799 | GURL youtube_script("http://youtube.com/foo.js"); |
| 1800 | FetchSubresource(browser()->tab_strip_model()->GetActiveWebContents(), |
| 1801 | youtube_script); |
| 1802 | |
| 1803 | base::AutoLock auto_lock(lock); |
| 1804 | CheckYouTubeRestricted(youtube_restrict_mode, urls_requested, |
| 1805 | youtube_script); |
| 1806 | } |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | IN_PROC_BROWSER_TEST_F(PolicyTest, AllowedDomainsForApps) { |
| 1811 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1812 | base::Lock lock; |
| 1813 | std::map<GURL, net::HttpRequestHeaders> urls_requested; |
| 1814 | content::URLLoaderInterceptor interceptor(base::BindLambdaForTesting( |
| 1815 | [&](content::URLLoaderInterceptor::RequestParams* params) -> bool { |
| 1816 | base::AutoLock auto_lock(lock); |
| 1817 | urls_requested[params->url_request.url] = params->url_request.headers; |
| 1818 | return false; |
| 1819 | })); |
| 1820 | |
| 1821 | for (int allowed_domains = 0; allowed_domains < 2; ++allowed_domains) { |
| 1822 | std::string allowed_domain; |
| 1823 | if (allowed_domains) { |
| 1824 | PolicyMap policies; |
| 1825 | allowed_domain = "foo.com"; |
| 1826 | SetPolicy(&policies, key::kAllowedDomainsForApps, |
| 1827 | std::make_unique<base::Value>(allowed_domain)); |
| 1828 | UpdateProviderPolicy(policies); |
| 1829 | } |
| 1830 | |
| 1831 | { |
| 1832 | // First check frame requests. |
| 1833 | GURL google_url = |
| 1834 | embedded_test_server()->GetURL("google.com", "/empty.html"); |
| 1835 | ui_test_utils::NavigateToURL(browser(), google_url); |
| 1836 | |
| 1837 | base::AutoLock auto_lock(lock); |
| 1838 | CheckAllowedDomainsHeader(allowed_domain, urls_requested, google_url); |
| 1839 | } |
| 1840 | |
| 1841 | { |
| 1842 | // Now check subresource loads. |
| 1843 | GURL google_script = |
| 1844 | embedded_test_server()->GetURL("google.com", "/result_queue.js"); |
| 1845 | |
| 1846 | FetchSubresource(browser()->tab_strip_model()->GetActiveWebContents(), |
| 1847 | google_script); |
| 1848 | |
| 1849 | base::AutoLock auto_lock(lock); |
| 1850 | CheckAllowedDomainsHeader(allowed_domain, urls_requested, google_script); |
| 1851 | } |
| 1852 | |
| 1853 | { |
| 1854 | // Double check that a frame to a non-Google url doesn't have the header. |
| 1855 | GURL non_google_url = embedded_test_server()->GetURL("/empty.html"); |
| 1856 | ui_test_utils::NavigateToURL(browser(), non_google_url); |
| 1857 | |
| 1858 | base::AutoLock auto_lock(lock); |
| 1859 | CheckAllowedDomainsHeader(std::string(), urls_requested, non_google_url); |
| 1860 | } |
treib | 2b18805 | 2015-04-17 12:32:50 | [diff] [blame] | 1861 | } |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 1862 | } |
| 1863 | |
tzik | 8826eda | 2016-11-09 04:30:28 | [diff] [blame] | 1864 | IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { |
[email protected] | f5b7f6e | 2013-12-10 13:57:32 | [diff] [blame] | 1865 | // This test assumes Gpu access. |
kinuko | 7e9da25 | 2017-03-10 07:18:42 | [diff] [blame] | 1866 | if (!content::GpuDataManager::GetInstance()->HardwareAccelerationEnabled()) |
[email protected] | f5b7f6e | 2013-12-10 13:57:32 | [diff] [blame] | 1867 | return; |
| 1868 | |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 1869 | ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
[email protected] | bb34f26 | 2012-09-05 09:09:46 | [diff] [blame] | 1870 | // WebGL is enabled by default. |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 1871 | content::WebContents* contents = |
| 1872 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | bb34f26 | 2012-09-05 09:09:46 | [diff] [blame] | 1873 | EXPECT_TRUE(IsWebGLEnabled(contents)); |
| 1874 | // Disable with a policy. |
| 1875 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1876 | policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1877 | POLICY_SOURCE_CLOUD, std::make_unique<base::Value>(true), |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 1878 | nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 1879 | UpdateProviderPolicy(policies); |
[email protected] | bb34f26 | 2012-09-05 09:09:46 | [diff] [blame] | 1880 | // Crash and reload the tab to get a new renderer. |
| 1881 | content::CrashTab(contents); |
| 1882 | EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD)); |
| 1883 | EXPECT_FALSE(IsWebGLEnabled(contents)); |
| 1884 | // Enable with a policy. |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1885 | policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1886 | POLICY_SOURCE_CLOUD, std::make_unique<base::Value>(false), |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 1887 | nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 1888 | UpdateProviderPolicy(policies); |
[email protected] | bb34f26 | 2012-09-05 09:09:46 | [diff] [blame] | 1889 | content::CrashTab(contents); |
| 1890 | EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD)); |
| 1891 | EXPECT_TRUE(IsWebGLEnabled(contents)); |
| 1892 | } |
[email protected] | bb34f26 | 2012-09-05 09:09:46 | [diff] [blame] | 1893 | |
Pavol Marko | debb0ff | 2018-05-07 18:35:41 | [diff] [blame] | 1894 | IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabledByLegacyPolicy) { |
| 1895 | // Verifies that access to the developer tools can be disabled by setting the |
| 1896 | // legacy DeveloperToolsDisabled policy. |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 1897 | |
| 1898 | // Open devtools. |
| 1899 | EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 1900 | content::WebContents* contents = |
| 1901 | browser()->tab_strip_model()->GetActiveWebContents(); |
binjin | 828b1416 | 2014-12-01 13:04:29 | [diff] [blame] | 1902 | DevToolsWindow* devtools_window = |
[email protected] | db90e8a | 2014-07-07 17:57:35 | [diff] [blame] | 1903 | DevToolsWindow::GetInstanceForInspectedWebContents(contents); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 1904 | EXPECT_TRUE(devtools_window); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 1905 | |
| 1906 | // Disable devtools via policy. |
| 1907 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 1908 | policies.Set(key::kDeveloperToolsDisabled, POLICY_LEVEL_MANDATORY, |
| 1909 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 1910 | std::make_unique<base::Value>(true), nullptr); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 1911 | content::WindowedNotificationObserver close_observer( |
| 1912 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
[email protected] | f77a652 | 2014-05-30 10:55:56 | [diff] [blame] | 1913 | content::Source<content::WebContents>( |
[email protected] | d118ad7 | 2014-07-21 14:07:01 | [diff] [blame] | 1914 | DevToolsWindowTesting::Get(devtools_window)->main_web_contents())); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 1915 | UpdateProviderPolicy(policies); |
[email protected] | a1406cb | 2013-10-16 14:30:43 | [diff] [blame] | 1916 | // wait for devtools close |
| 1917 | close_observer.Wait(); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 1918 | // The existing devtools window should have closed. |
[email protected] | db90e8a | 2014-07-07 17:57:35 | [diff] [blame] | 1919 | EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 1920 | // And it's not possible to open it again. |
| 1921 | EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
[email protected] | db90e8a | 2014-07-07 17:57:35 | [diff] [blame] | 1922 | EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 1923 | } |
| 1924 | |
Pavol Marko | debb0ff | 2018-05-07 18:35:41 | [diff] [blame] | 1925 | IN_PROC_BROWSER_TEST_F(PolicyTest, |
| 1926 | DeveloperToolsDisabledByDeveloperToolsAvailability) { |
| 1927 | // Verifies that access to the developer tools can be disabled by setting the |
| 1928 | // DeveloperToolsAvailability policy. |
| 1929 | |
| 1930 | // Open devtools. |
| 1931 | EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
| 1932 | content::WebContents* contents = |
| 1933 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1934 | DevToolsWindow* devtools_window = |
| 1935 | DevToolsWindow::GetInstanceForInspectedWebContents(contents); |
| 1936 | EXPECT_TRUE(devtools_window); |
| 1937 | |
| 1938 | // Disable devtools via policy. |
| 1939 | PolicyMap policies; |
| 1940 | policies.Set(key::kDeveloperToolsAvailability, POLICY_LEVEL_MANDATORY, |
| 1941 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 1942 | std::make_unique<base::Value>(2 /* DeveloperToolsDisallowed */), |
| 1943 | nullptr); |
| 1944 | content::WindowedNotificationObserver close_observer( |
| 1945 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 1946 | content::Source<content::WebContents>( |
| 1947 | DevToolsWindowTesting::Get(devtools_window)->main_web_contents())); |
| 1948 | UpdateProviderPolicy(policies); |
| 1949 | // wait for devtools close |
| 1950 | close_observer.Wait(); |
| 1951 | // The existing devtools window should have closed. |
| 1952 | EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); |
| 1953 | // And it's not possible to open it again. |
| 1954 | EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
| 1955 | EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); |
| 1956 | } |
| 1957 | |
pmarko | 6e36b463 | 2016-12-13 17:45:50 | [diff] [blame] | 1958 | namespace { |
| 1959 | |
| 1960 | // Utility for waiting until the dev-mode controls are visible/hidden |
| 1961 | // Uses a MutationObserver on the attributes of the DOM element. |
| 1962 | void WaitForExtensionsDevModeControlsVisibility( |
| 1963 | content::WebContents* contents, |
| 1964 | const char* dev_controls_accessor_js, |
| 1965 | const char* dev_controls_visibility_check_js, |
| 1966 | bool expected_visible) { |
| 1967 | bool done = false; |
| 1968 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 1969 | contents, |
| 1970 | base::StringPrintf( |
| 1971 | "var screenElement = %s;" |
| 1972 | "function SendReplyIfAsExpected() {" |
| 1973 | " var is_visible = %s;" |
| 1974 | " if (is_visible != %s)" |
| 1975 | " return false;" |
| 1976 | " observer.disconnect();" |
| 1977 | " domAutomationController.send(true);" |
| 1978 | " return true;" |
| 1979 | "}" |
| 1980 | "var observer = new MutationObserver(SendReplyIfAsExpected);" |
| 1981 | "if (!SendReplyIfAsExpected()) {" |
| 1982 | " var options = { 'attributes': true };" |
| 1983 | " observer.observe(screenElement, options);" |
| 1984 | "}", |
| 1985 | dev_controls_accessor_js, |
| 1986 | dev_controls_visibility_check_js, |
| 1987 | (expected_visible ? "true" : "false")), |
| 1988 | &done)); |
| 1989 | } |
| 1990 | |
| 1991 | } // namespace |
| 1992 | |
| 1993 | IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabledExtensionsDevMode) { |
dpapad | d74544f | 2018-01-22 19:26:03 | [diff] [blame] | 1994 | // Verifies that when DeveloperToolsDisabled policy is set, the "dev mode" |
| 1995 | // in chrome://extensions is actively turned off and the checkbox |
| 1996 | // is disabled. |
| 1997 | // Note: We don't test the indicator as it is tested in the policy pref test |
Pavol Marko | debb0ff | 2018-05-07 18:35:41 | [diff] [blame] | 1998 | // for kDeveloperToolsDisabled and kDeveloperToolsAvailability. |
dpapad | d74544f | 2018-01-22 19:26:03 | [diff] [blame] | 1999 | |
| 2000 | // This test depends on the following helper methods to locate the DOM elemens |
| 2001 | // to be tested. |
| 2002 | const char define_helpers_js[] = |
| 2003 | R"(function getToolbar() { |
| 2004 | const manager = document.querySelector('extensions-manager'); |
| 2005 | return manager.$$('extensions-toolbar'); |
| 2006 | } |
| 2007 | |
| 2008 | function getToggle() { |
Esmael El-Moslimany | 4e9b4a41 | 2018-02-26 16:55:16 | [diff] [blame] | 2009 | return getToolbar().$.devMode; |
dpapad | d74544f | 2018-01-22 19:26:03 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | function getControls() { |
Esmael El-Moslimany | 4e9b4a41 | 2018-02-26 16:55:16 | [diff] [blame] | 2013 | return getToolbar().$.devDrawer; |
dpapad | d74544f | 2018-01-22 19:26:03 | [diff] [blame] | 2014 | } |
| 2015 | )"; |
| 2016 | |
| 2017 | const char toggle_dev_mode_accessor_js[] = "getToggle()"; |
| 2018 | const char dev_controls_accessor_js[] = "getControls()"; |
| 2019 | const char dev_controls_visibility_check_js[] = |
| 2020 | "getControls().hasAttribute('expanded')"; |
| 2021 | |
| 2022 | // Navigate to the extensions frame and enabled "Developer mode" |
| 2023 | ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIExtensionsURL)); |
| 2024 | |
| 2025 | content::WebContents* contents = |
| 2026 | browser()->tab_strip_model()->GetActiveWebContents(); |
Jialiu Lin | c534b0d | 2018-03-01 16:51:52 | [diff] [blame] | 2027 | EXPECT_TRUE(content::ExecuteScript(contents, std::string(define_helpers_js))); |
dpapad | d74544f | 2018-01-22 19:26:03 | [diff] [blame] | 2028 | |
| 2029 | EXPECT_TRUE(content::ExecuteScript( |
| 2030 | contents, base::StringPrintf("domAutomationController.send(%s.click());", |
| 2031 | toggle_dev_mode_accessor_js))); |
| 2032 | |
| 2033 | WaitForExtensionsDevModeControlsVisibility(contents, dev_controls_accessor_js, |
| 2034 | dev_controls_visibility_check_js, |
| 2035 | true); |
| 2036 | |
| 2037 | // Disable devtools via policy. |
| 2038 | PolicyMap policies; |
Pavol Marko | debb0ff | 2018-05-07 18:35:41 | [diff] [blame] | 2039 | policies.Set(key::kDeveloperToolsAvailability, POLICY_LEVEL_MANDATORY, |
dpapad | d74544f | 2018-01-22 19:26:03 | [diff] [blame] | 2040 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Pavol Marko | debb0ff | 2018-05-07 18:35:41 | [diff] [blame] | 2041 | std::make_unique<base::Value>(2 /*DeveloperToolsDisallowed*/), |
| 2042 | nullptr); |
dpapad | d74544f | 2018-01-22 19:26:03 | [diff] [blame] | 2043 | UpdateProviderPolicy(policies); |
| 2044 | |
| 2045 | // Expect devcontrols to be hidden now... |
| 2046 | WaitForExtensionsDevModeControlsVisibility(contents, dev_controls_accessor_js, |
| 2047 | dev_controls_visibility_check_js, |
| 2048 | false); |
| 2049 | |
| 2050 | // ... and checkbox is disabled |
| 2051 | bool is_toggle_dev_mode_checkbox_disabled = false; |
| 2052 | EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 2053 | contents, |
| 2054 | base::StringPrintf( |
| 2055 | "domAutomationController.send(%s.hasAttribute('disabled'))", |
| 2056 | toggle_dev_mode_accessor_js), |
| 2057 | &is_toggle_dev_mode_checkbox_disabled)); |
| 2058 | EXPECT_TRUE(is_toggle_dev_mode_checkbox_disabled); |
| 2059 | } |
| 2060 | |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 2061 | IN_PROC_BROWSER_TEST_F(PolicyTest, DownloadDirectory) { |
| 2062 | // Verifies that the download directory can be forced by policy. |
| 2063 | |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 2064 | // Don't prompt for the download location during this test. |
| 2065 | browser()->profile()->GetPrefs()->SetBoolean( |
| 2066 | prefs::kPromptForDownload, false); |
| 2067 | |
Mattias Nissler | 441cc65 | 2018-04-05 00:08:56 | [diff] [blame] | 2068 | base::FilePath initial_dir = |
| 2069 | DownloadPrefs(browser()->profile()).DownloadPath(); |
| 2070 | |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 2071 | // Verify that downloads end up on the default directory. |
Mattias Nissler | 441cc65 | 2018-04-05 00:08:56 | [diff] [blame] | 2072 | base::ScopedAllowBlockingForTesting allow_blocking; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2073 | base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
Mattias Nissler | 441cc65 | 2018-04-05 00:08:56 | [diff] [blame] | 2074 | DownloadAndVerifyFile(browser(), initial_dir, file); |
| 2075 | base::DieFileDie(initial_dir.Append(file), false); |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 2076 | |
| 2077 | // Override the download directory with the policy and verify a download. |
Mattias Nissler | 441cc65 | 2018-04-05 00:08:56 | [diff] [blame] | 2078 | base::FilePath forced_dir = initial_dir.AppendASCII("forced"); |
| 2079 | |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 2080 | PolicyMap policies; |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 2081 | policies.Set(key::kDownloadDirectory, POLICY_LEVEL_MANDATORY, |
| 2082 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Mattias Nissler | 441cc65 | 2018-04-05 00:08:56 | [diff] [blame] | 2083 | std::make_unique<base::Value>(forced_dir.value()), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 2084 | UpdateProviderPolicy(policies); |
Mattias Nissler | 441cc65 | 2018-04-05 00:08:56 | [diff] [blame] | 2085 | DownloadAndVerifyFile(browser(), forced_dir, file); |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 2086 | // Verify that the first download location wasn't affected. |
Mattias Nissler | 441cc65 | 2018-04-05 00:08:56 | [diff] [blame] | 2087 | EXPECT_FALSE(base::PathExists(initial_dir.Append(file))); |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 2088 | } |
[email protected] | d125121 | 2012-08-29 13:15:59 | [diff] [blame] | 2089 | |
Sam McNally | 5edde0a | 2019-02-27 11:10:03 | [diff] [blame] | 2090 | #if defined(OS_CHROMEOS) |
| 2091 | class DrivePolicyTest : public PolicyTest, |
| 2092 | public testing::WithParamInterface<bool> { |
| 2093 | public: |
| 2094 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 2095 | PolicyTest::SetUpCommandLine(command_line); |
| 2096 | if (GetParam()) { |
| 2097 | scoped_feature_list_.InitAndEnableFeature(chromeos::features::kDriveFs); |
| 2098 | } else { |
| 2099 | scoped_feature_list_.InitAndDisableFeature(chromeos::features::kDriveFs); |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | private: |
| 2104 | base::test::ScopedFeatureList scoped_feature_list_; |
| 2105 | }; |
| 2106 | |
| 2107 | // Verifies that the download directory can be forced to Google Drive by policy. |
| 2108 | IN_PROC_BROWSER_TEST_P(DrivePolicyTest, DownloadDirectory_Drive) { |
| 2109 | // Override the download directory with the policy. |
| 2110 | { |
| 2111 | PolicyMap policies; |
| 2112 | policies.Set(key::kDownloadDirectory, POLICY_LEVEL_RECOMMENDED, |
| 2113 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2114 | std::make_unique<base::Value>("${google_drive}/"), nullptr); |
| 2115 | UpdateProviderPolicy(policies); |
| 2116 | |
| 2117 | EXPECT_EQ(drive::DriveIntegrationServiceFactory::FindForProfile( |
| 2118 | browser()->profile()) |
| 2119 | ->GetMountPointPath() |
| 2120 | .AppendASCII("root"), |
| 2121 | DownloadPrefs(browser()->profile()) |
| 2122 | .DownloadPath() |
| 2123 | .StripTrailingSeparators()); |
| 2124 | } |
| 2125 | |
| 2126 | PolicyMap policies; |
| 2127 | policies.Set(key::kDownloadDirectory, POLICY_LEVEL_MANDATORY, |
| 2128 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2129 | std::make_unique<base::Value>("${google_drive}/Downloads"), |
| 2130 | nullptr); |
| 2131 | UpdateProviderPolicy(policies); |
| 2132 | |
| 2133 | EXPECT_EQ(drive::DriveIntegrationServiceFactory::FindForProfile( |
| 2134 | browser()->profile()) |
| 2135 | ->GetMountPointPath() |
| 2136 | .AppendASCII("root/Downloads"), |
| 2137 | DownloadPrefs(browser()->profile()) |
| 2138 | .DownloadPath() |
| 2139 | .StripTrailingSeparators()); |
| 2140 | } |
| 2141 | |
| 2142 | INSTANTIATE_TEST_SUITE_P(DrivePolicyTestInstance, |
| 2143 | DrivePolicyTest, |
| 2144 | testing::Bool()); |
| 2145 | |
| 2146 | #endif // !defined(OS_CHROMEOS) |
| 2147 | |
[email protected] | 3b594141 | 2014-08-20 10:54:32 | [diff] [blame] | 2148 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallBlacklistSelective) { |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2149 | // Verifies that blacklisted extensions can't be installed. |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2150 | extensions::ExtensionService* service = extension_service(); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2151 | ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2152 | ASSERT_FALSE(service->GetExtensionById(kSimpleWithIconCrxId, true)); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2153 | base::ListValue blacklist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 2154 | blacklist.AppendString(kGoodCrxId); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2155 | PolicyMap policies; |
| 2156 | policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2157 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2158 | blacklist.CreateDeepCopy(), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 2159 | UpdateProviderPolicy(policies); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2160 | |
| 2161 | // "good.crx" is blacklisted. |
| 2162 | EXPECT_FALSE(InstallExtension(kGoodCrxName)); |
| 2163 | EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
| 2164 | |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2165 | // "simple_with_icon.crx" is not. |
| 2166 | const extensions::Extension* simple_with_icon = |
| 2167 | InstallExtension(kSimpleWithIconCrxName); |
| 2168 | ASSERT_TRUE(simple_with_icon); |
| 2169 | EXPECT_EQ(kSimpleWithIconCrxId, simple_with_icon->id()); |
| 2170 | EXPECT_EQ(simple_with_icon, |
| 2171 | service->GetExtensionById(kSimpleWithIconCrxId, true)); |
[email protected] | b0aa6ae15 | 2013-08-07 09:56:16 | [diff] [blame] | 2172 | } |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2173 | |
Christopher Lam | 96b044c | 2017-11-24 03:29:46 | [diff] [blame] | 2174 | // Ensure that bookmark apps are not blocked by the ExtensionInstallBlacklist |
| 2175 | // policy. |
| 2176 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallBlacklist_BookmarkApp) { |
| 2177 | const extensions::Extension* bookmark_app = InstallBookmarkApp(); |
| 2178 | ASSERT_TRUE(bookmark_app); |
| 2179 | EXPECT_TRUE(InstallExtension(kGoodCrxName)); |
| 2180 | |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2181 | extensions::ExtensionService* service = extension_service(); |
Christopher Lam | 96b044c | 2017-11-24 03:29:46 | [diff] [blame] | 2182 | EXPECT_TRUE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2183 | EXPECT_TRUE(service->IsExtensionEnabled(bookmark_app->id())); |
| 2184 | |
| 2185 | // Now set ExtensionInstallBlacklist policy to block all extensions. |
| 2186 | PolicyMap policies; |
| 2187 | policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
| 2188 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2189 | extensions::ListBuilder().Append("*").Build(), nullptr); |
| 2190 | UpdateProviderPolicy(policies); |
| 2191 | |
| 2192 | // The bookmark app should still be enabled, with |kGoodCrxId| being disabled. |
| 2193 | EXPECT_FALSE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2194 | EXPECT_TRUE(service->IsExtensionEnabled(bookmark_app->id())); |
| 2195 | } |
| 2196 | |
Kyle Spiers | a3b1845 | 2019-05-07 16:07:09 | [diff] [blame] | 2197 | // Ensure that when INSTALLATION_REMOVED is set |
Kyle Spiers | bb4b9f5f5 | 2019-05-02 17:17:15 | [diff] [blame] | 2198 | // that blacklisted extensions are removed from the device. |
| 2199 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallRemovedPolicy) { |
| 2200 | EXPECT_TRUE(InstallExtension(kGoodCrxName)); |
| 2201 | |
| 2202 | extensions::ExtensionService* service = extension_service(); |
| 2203 | EXPECT_TRUE(service->GetInstalledExtension(kGoodCrxId)); |
| 2204 | |
| 2205 | // Should uninstall good_v1.crx. |
| 2206 | base::DictionaryValue dict_value; |
| 2207 | dict_value.SetString(std::string(kGoodCrxId) + "." + |
| 2208 | extensions::schema_constants::kInstallationMode, |
| 2209 | extensions::schema_constants::kRemoved); |
| 2210 | PolicyMap policies; |
| 2211 | policies.Set(key::kExtensionSettings, POLICY_LEVEL_MANDATORY, |
| 2212 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2213 | dict_value.CreateDeepCopy(), nullptr); |
| 2214 | extensions::TestExtensionRegistryObserver observer( |
| 2215 | extensions::ExtensionRegistry::Get(browser()->profile())); |
| 2216 | UpdateProviderPolicy(policies); |
| 2217 | observer.WaitForExtensionUnloaded(); |
| 2218 | |
| 2219 | EXPECT_FALSE(service->GetInstalledExtension(kGoodCrxId)); |
| 2220 | } |
| 2221 | |
Kyle Spiers | 42145b7 | 2019-06-19 20:32:28 | [diff] [blame] | 2222 | // Ensure that when INSTALLATION_REMOVED is set for wildcard |
| 2223 | // that blacklisted extensions are removed from the device. |
| 2224 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionWildcardRemovedPolicy) { |
| 2225 | EXPECT_TRUE(InstallExtension(kGoodCrxName)); |
| 2226 | |
| 2227 | extensions::ExtensionService* service = extension_service(); |
| 2228 | EXPECT_TRUE(service->GetInstalledExtension(kGoodCrxId)); |
| 2229 | |
| 2230 | // Should uninstall good_v1.crx. |
| 2231 | base::DictionaryValue dict_value; |
| 2232 | dict_value.SetString( |
| 2233 | std::string("*") + "." + extensions::schema_constants::kInstallationMode, |
| 2234 | extensions::schema_constants::kRemoved); |
| 2235 | PolicyMap policies; |
| 2236 | policies.Set(key::kExtensionSettings, POLICY_LEVEL_MANDATORY, |
| 2237 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2238 | dict_value.CreateDeepCopy(), nullptr); |
| 2239 | extensions::TestExtensionRegistryObserver observer( |
| 2240 | extensions::ExtensionRegistry::Get(browser()->profile())); |
| 2241 | UpdateProviderPolicy(policies); |
| 2242 | observer.WaitForExtensionUnloaded(); |
| 2243 | |
| 2244 | EXPECT_FALSE(service->GetInstalledExtension(kGoodCrxId)); |
| 2245 | } |
| 2246 | |
Christopher Lam | 96b044c | 2017-11-24 03:29:46 | [diff] [blame] | 2247 | // Ensure that bookmark apps are not blocked by the ExtensionAllowedTypes |
| 2248 | // policy. |
| 2249 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes_BookmarkApp) { |
| 2250 | const extensions::Extension* bookmark_app = InstallBookmarkApp(); |
| 2251 | ASSERT_TRUE(bookmark_app); |
| 2252 | EXPECT_TRUE(InstallExtension(kGoodCrxName)); |
| 2253 | |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2254 | extensions::ExtensionService* service = extension_service(); |
Christopher Lam | 96b044c | 2017-11-24 03:29:46 | [diff] [blame] | 2255 | EXPECT_TRUE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2256 | EXPECT_TRUE(service->IsExtensionEnabled(bookmark_app->id())); |
| 2257 | |
| 2258 | // Now set policy to only allow themes. Note: Bookmark apps are hosted |
| 2259 | // apps. |
| 2260 | PolicyMap policies; |
| 2261 | policies.Set(key::kExtensionAllowedTypes, POLICY_LEVEL_MANDATORY, |
| 2262 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2263 | extensions::ListBuilder().Append("theme").Build(), nullptr); |
| 2264 | UpdateProviderPolicy(policies); |
| 2265 | |
| 2266 | // The bookmark app should still be enabled, with |kGoodCrxId| being disabled. |
| 2267 | EXPECT_FALSE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2268 | EXPECT_TRUE(service->IsExtensionEnabled(bookmark_app->id())); |
| 2269 | } |
| 2270 | |
| 2271 | // Ensure that bookmark apps are not blocked by the ExtensionSettings |
| 2272 | // policy. |
| 2273 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionSettings_BookmarkApp) { |
| 2274 | const extensions::Extension* bookmark_app = InstallBookmarkApp(); |
| 2275 | ASSERT_TRUE(bookmark_app); |
| 2276 | EXPECT_TRUE(InstallExtension(kGoodCrxName)); |
| 2277 | |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2278 | extensions::ExtensionService* service = extension_service(); |
Christopher Lam | 96b044c | 2017-11-24 03:29:46 | [diff] [blame] | 2279 | EXPECT_TRUE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2280 | EXPECT_TRUE(service->IsExtensionEnabled(bookmark_app->id())); |
| 2281 | |
| 2282 | // Now set policy to block all extensions. |
| 2283 | PolicyMap policies; |
| 2284 | policies.Set(key::kExtensionSettings, POLICY_LEVEL_MANDATORY, |
| 2285 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2286 | extensions::DictionaryBuilder() |
| 2287 | .Set("*", extensions::DictionaryBuilder() |
| 2288 | .Set("installation_mode", "blocked") |
| 2289 | .Build()) |
| 2290 | .Build(), |
| 2291 | nullptr); |
| 2292 | UpdateProviderPolicy(policies); |
| 2293 | |
| 2294 | // The bookmark app should still be enabled, with |kGoodCrxId| being disabled. |
| 2295 | EXPECT_FALSE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2296 | EXPECT_TRUE(service->IsExtensionEnabled(bookmark_app->id())); |
| 2297 | |
| 2298 | // Clear all policies. |
| 2299 | policies.Clear(); |
| 2300 | UpdateProviderPolicy(policies); |
| 2301 | |
| 2302 | EXPECT_TRUE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2303 | EXPECT_TRUE(service->IsExtensionEnabled(bookmark_app->id())); |
| 2304 | |
| 2305 | // Now set policy to only allow themes. Note: Bookmark apps are hosted |
| 2306 | // apps. |
| 2307 | policies.Set( |
| 2308 | key::kExtensionSettings, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 2309 | POLICY_SOURCE_CLOUD, |
| 2310 | extensions::DictionaryBuilder() |
| 2311 | .Set("*", extensions::DictionaryBuilder() |
| 2312 | .Set("allowed_types", |
| 2313 | extensions::ListBuilder().Append("theme").Build()) |
| 2314 | .Build()) |
| 2315 | .Build(), |
| 2316 | nullptr); |
| 2317 | UpdateProviderPolicy(policies); |
| 2318 | |
| 2319 | // The bookmark app should still be enabled, with |kGoodCrxId| being disabled. |
| 2320 | EXPECT_FALSE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2321 | EXPECT_TRUE(service->IsExtensionEnabled(bookmark_app->id())); |
| 2322 | } |
| 2323 | |
[email protected] | 72ba2eb | 2013-10-16 16:06:47 | [diff] [blame] | 2324 | // Flaky on windows; http://crbug.com/307994. |
| 2325 | #if defined(OS_WIN) |
| 2326 | #define MAYBE_ExtensionInstallBlacklistWildcard DISABLED_ExtensionInstallBlacklistWildcard |
| 2327 | #else |
| 2328 | #define MAYBE_ExtensionInstallBlacklistWildcard ExtensionInstallBlacklistWildcard |
| 2329 | #endif |
| 2330 | IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallBlacklistWildcard) { |
[email protected] | b0aa6ae15 | 2013-08-07 09:56:16 | [diff] [blame] | 2331 | // Verify that a wildcard blacklist takes effect. |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2332 | EXPECT_TRUE(InstallExtension(kSimpleWithIconCrxName)); |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2333 | extensions::ExtensionService* service = extension_service(); |
[email protected] | b0aa6ae15 | 2013-08-07 09:56:16 | [diff] [blame] | 2334 | ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2335 | ASSERT_TRUE(service->GetExtensionById(kSimpleWithIconCrxId, true)); |
[email protected] | b0aa6ae15 | 2013-08-07 09:56:16 | [diff] [blame] | 2336 | base::ListValue blacklist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 2337 | blacklist.AppendString("*"); |
[email protected] | b0aa6ae15 | 2013-08-07 09:56:16 | [diff] [blame] | 2338 | PolicyMap policies; |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2339 | policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2340 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2341 | blacklist.CreateDeepCopy(), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 2342 | UpdateProviderPolicy(policies); |
[email protected] | b0aa6ae15 | 2013-08-07 09:56:16 | [diff] [blame] | 2343 | |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2344 | // "simple_with_icon" should be disabled. |
| 2345 | EXPECT_TRUE(service->GetExtensionById(kSimpleWithIconCrxId, true)); |
| 2346 | EXPECT_FALSE(service->IsExtensionEnabled(kSimpleWithIconCrxId)); |
[email protected] | b0aa6ae15 | 2013-08-07 09:56:16 | [diff] [blame] | 2347 | |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2348 | // It shouldn't be possible to re-enable "simple_with_icon", until it |
| 2349 | // satisfies management policy. |
| 2350 | service->EnableExtension(kSimpleWithIconCrxId); |
| 2351 | EXPECT_FALSE(service->IsExtensionEnabled(kSimpleWithIconCrxId)); |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 2352 | |
| 2353 | // It shouldn't be possible to install good.crx. |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2354 | EXPECT_FALSE(InstallExtension(kGoodCrxName)); |
| 2355 | EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
| 2356 | } |
| 2357 | |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 2358 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallBlacklistSharedModules) { |
| 2359 | // Verifies that shared_modules are not affected by the blacklist. |
| 2360 | |
Yuzhu Shen | f3c2fcc | 2017-11-30 20:30:22 | [diff] [blame] | 2361 | base::FilePath base_path; |
| 2362 | GetTestDataDirectory(&base_path); |
| 2363 | base::FilePath update_xml_template_path = |
| 2364 | base_path.Append(kTestExtensionsDir) |
| 2365 | .AppendASCII("policy_shared_module") |
| 2366 | .AppendASCII("update_template.xml"); |
| 2367 | |
| 2368 | std::string update_xml_path = |
| 2369 | "/" + base::FilePath(kTestExtensionsDir).MaybeAsASCII() + |
| 2370 | "/policy_shared_module/gen_update.xml"; |
| 2371 | RegisterURLReplacingHandler(embedded_test_server(), update_xml_path, |
| 2372 | update_xml_template_path); |
| 2373 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 2374 | |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 2375 | const char kImporterId[] = "pchakhniekfaeoddkifplhnfbffomabh"; |
| 2376 | const char kSharedModuleId[] = "nfgclafboonjbiafbllihiailjlhelpm"; |
| 2377 | |
| 2378 | // Make sure that "import" and "export" are available to these extension IDs |
| 2379 | // by mocking the release channel. |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 2380 | extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 2381 | |
| 2382 | // Verify that the extensions are not installed initially. |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2383 | extensions::ExtensionService* service = extension_service(); |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 2384 | ASSERT_FALSE(service->GetExtensionById(kImporterId, true)); |
| 2385 | ASSERT_FALSE(service->GetExtensionById(kSharedModuleId, true)); |
| 2386 | |
| 2387 | // Mock the webstore update URL. This is where the shared module extension |
| 2388 | // will be installed from. |
Yuzhu Shen | f3c2fcc | 2017-11-30 20:30:22 | [diff] [blame] | 2389 | GURL update_xml_url = embedded_test_server()->GetURL(update_xml_path); |
Konstantin Ganenko | ae1129c | 2017-09-15 16:28:59 | [diff] [blame] | 2390 | extension_test_util::SetGalleryUpdateURL(update_xml_url); |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 2391 | ui_test_utils::NavigateToURL(browser(), update_xml_url); |
| 2392 | |
| 2393 | // Blacklist "*" but force-install the importer extension. The shared module |
| 2394 | // should be automatically installed too. |
| 2395 | base::ListValue blacklist; |
| 2396 | blacklist.AppendString("*"); |
| 2397 | base::ListValue forcelist; |
| 2398 | forcelist.AppendString( |
| 2399 | base::StringPrintf("%s;%s", kImporterId, update_xml_url.spec().c_str())); |
| 2400 | PolicyMap policies; |
| 2401 | policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2402 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2403 | blacklist.CreateDeepCopy(), nullptr); |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 2404 | policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2405 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2406 | forcelist.CreateDeepCopy(), nullptr); |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 2407 | |
| 2408 | extensions::ExtensionRegistry* registry = |
| 2409 | extensions::ExtensionRegistry::Get(browser()->profile()); |
| 2410 | extensions::TestExtensionRegistryObserver observe_importer( |
| 2411 | registry, kImporterId); |
| 2412 | extensions::TestExtensionRegistryObserver observe_shared_module( |
| 2413 | registry, kSharedModuleId); |
| 2414 | UpdateProviderPolicy(policies); |
| 2415 | observe_importer.WaitForExtensionLoaded(); |
| 2416 | observe_shared_module.WaitForExtensionLoaded(); |
| 2417 | |
| 2418 | // Verify that both extensions got installed. |
| 2419 | const extensions::Extension* importer = |
| 2420 | service->GetExtensionById(kImporterId, true); |
| 2421 | ASSERT_TRUE(importer); |
| 2422 | EXPECT_EQ(kImporterId, importer->id()); |
| 2423 | const extensions::Extension* shared_module = |
| 2424 | service->GetExtensionById(kSharedModuleId, true); |
| 2425 | ASSERT_TRUE(shared_module); |
| 2426 | EXPECT_EQ(kSharedModuleId, shared_module->id()); |
| 2427 | EXPECT_TRUE(shared_module->is_shared_module()); |
| 2428 | |
| 2429 | // Verify the dependency. |
dcheng | 08cfe9ba | 2016-04-14 17:46:45 | [diff] [blame] | 2430 | std::unique_ptr<extensions::ExtensionSet> set = |
joaodasilva | 30c8be9 | 2014-10-23 23:40:41 | [diff] [blame] | 2431 | service->shared_module_service()->GetDependentExtensions(shared_module); |
| 2432 | ASSERT_TRUE(set); |
| 2433 | EXPECT_EQ(1u, set->size()); |
| 2434 | EXPECT_TRUE(set->Contains(importer->id())); |
| 2435 | |
| 2436 | std::vector<extensions::SharedModuleInfo::ImportInfo> imports = |
| 2437 | extensions::SharedModuleInfo::GetImports(importer); |
| 2438 | ASSERT_EQ(1u, imports.size()); |
| 2439 | EXPECT_EQ(kSharedModuleId, imports[0].extension_id); |
| 2440 | } |
| 2441 | |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2442 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallWhitelist) { |
| 2443 | // Verifies that the whitelist can open exceptions to the blacklist. |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2444 | extensions::ExtensionService* service = extension_service(); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2445 | ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2446 | ASSERT_FALSE(service->GetExtensionById(kSimpleWithIconCrxId, true)); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2447 | base::ListValue blacklist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 2448 | blacklist.AppendString("*"); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2449 | base::ListValue whitelist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 2450 | whitelist.AppendString(kGoodCrxId); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2451 | PolicyMap policies; |
| 2452 | policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2453 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2454 | blacklist.CreateDeepCopy(), nullptr); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2455 | policies.Set(key::kExtensionInstallWhitelist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2456 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2457 | whitelist.CreateDeepCopy(), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 2458 | UpdateProviderPolicy(policies); |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2459 | // "simple_with_icon.crx" is blacklisted. |
| 2460 | EXPECT_FALSE(InstallExtension(kSimpleWithIconCrxName)); |
| 2461 | EXPECT_FALSE(service->GetExtensionById(kSimpleWithIconCrxId, true)); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2462 | // "good.crx" has a whitelist exception. |
| 2463 | const extensions::Extension* good = InstallExtension(kGoodCrxName); |
| 2464 | ASSERT_TRUE(good); |
| 2465 | EXPECT_EQ(kGoodCrxId, good->id()); |
| 2466 | EXPECT_EQ(good, service->GetExtensionById(kGoodCrxId, true)); |
| 2467 | // The user can also remove this extension. |
| 2468 | UninstallExtension(kGoodCrxId, true); |
| 2469 | } |
| 2470 | |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2471 | namespace { |
| 2472 | |
| 2473 | class ExtensionRequestInterceptor { |
| 2474 | public: |
| 2475 | ExtensionRequestInterceptor() |
| 2476 | : interceptor_( |
| 2477 | base::BindRepeating(&ExtensionRequestInterceptor::OnRequest, |
| 2478 | base::Unretained(this))) {} |
| 2479 | |
| 2480 | void set_interceptor_hook( |
| 2481 | content::URLLoaderInterceptor::InterceptCallback callback) { |
| 2482 | callback_ = std::move(callback); |
| 2483 | } |
| 2484 | |
| 2485 | private: |
| 2486 | bool OnRequest(content::URLLoaderInterceptor::RequestParams* params) { |
| 2487 | if (callback_ && callback_.Run(params)) |
| 2488 | return true; |
| 2489 | // Mock out requests to the Web Store. |
| 2490 | if (params->url_request.url.host() == "clients2.google.com" && |
| 2491 | params->url_request.url.path() == "/service/update2/crx") { |
| 2492 | content::URLLoaderInterceptor::WriteResponse( |
| 2493 | "chrome/test/data/extensions/good2_update_manifest.xml", |
| 2494 | params->client.get()); |
| 2495 | return true; |
| 2496 | } |
| 2497 | |
| 2498 | if (params->url_request.url.path() == "/good_update_manifest.xml") { |
| 2499 | content::URLLoaderInterceptor::WriteResponse( |
| 2500 | "chrome/test/data/extensions/good2_update_manifest.xml", |
| 2501 | params->client.get()); |
| 2502 | return true; |
| 2503 | } |
| 2504 | if (params->url_request.url.path() == "/extensions/good_v1.crx") { |
| 2505 | content::URLLoaderInterceptor::WriteResponse( |
| 2506 | "chrome/test/data/extensions/good_v1.crx", params->client.get()); |
| 2507 | return true; |
| 2508 | } |
| 2509 | if (params->url_request.url.path() == "/extensions/good2.crx") { |
| 2510 | content::URLLoaderInterceptor::WriteResponse( |
| 2511 | "chrome/test/data/extensions/good2.crx", params->client.get()); |
| 2512 | return true; |
| 2513 | } |
| 2514 | |
| 2515 | return false; |
| 2516 | } |
| 2517 | |
| 2518 | content::URLLoaderInterceptor::InterceptCallback callback_; |
| 2519 | content::URLLoaderInterceptor interceptor_; |
| 2520 | }; |
| 2521 | |
| 2522 | } // namespace |
| 2523 | |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2524 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallForcelist) { |
| 2525 | // Verifies that extensions that are force-installed by policies are |
| 2526 | // installed and can't be uninstalled. |
Maksim Ivanov | eaac2ff | 2018-04-16 16:23:24 | [diff] [blame] | 2527 | |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2528 | ExtensionRequestInterceptor interceptor; |
| 2529 | |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2530 | extensions::ExtensionService* service = extension_service(); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2531 | ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
| 2532 | |
| 2533 | // Extensions that are force-installed come from an update URL, which defaults |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2534 | // to the webstore. Use a test URL for this test with an update manifest |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 2535 | // that includes "good_v1.crx". |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2536 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 2537 | GURL url = |
| 2538 | embedded_test_server()->GetURL("/extensions/good_v1_update_manifest.xml"); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2539 | |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 2540 | // Setting the forcelist extension should install "good_v1.crx". |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2541 | base::ListValue forcelist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 2542 | forcelist.AppendString( |
| 2543 | base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str())); |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2544 | PolicyMap policies; |
| 2545 | policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2546 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2547 | forcelist.CreateDeepCopy(), nullptr); |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2548 | extensions::TestExtensionRegistryObserver observer( |
| 2549 | extensions::ExtensionRegistry::Get(browser()->profile())); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 2550 | UpdateProviderPolicy(policies); |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2551 | observer.WaitForExtensionWillBeInstalled(); |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 2552 | // Note: Cannot check that the notification details match the expected |
| 2553 | // exception, since the details object has already been freed prior to |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2554 | // the completion of observer.WaitForExtensionWillBeInstalled(). |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 2555 | |
| 2556 | EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); |
| 2557 | |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2558 | // The user is not allowed to uninstall force-installed extensions. |
| 2559 | UninstallExtension(kGoodCrxId, false); |
[email protected] | ec1b3e71 | 2013-05-25 14:29:16 | [diff] [blame] | 2560 | |
limasdf | c83e0b7 | 2017-03-03 17:08:35 | [diff] [blame] | 2561 | scoped_refptr<extensions::UnpackedInstaller> installer = |
| 2562 | extensions::UnpackedInstaller::Create(extension_service()); |
| 2563 | |
[email protected] | ec1b3e71 | 2013-05-25 14:29:16 | [diff] [blame] | 2564 | // The user is not allowed to load an unpacked extension with the |
| 2565 | // same ID as a force-installed extension. |
limasdf | c83e0b7 | 2017-03-03 17:08:35 | [diff] [blame] | 2566 | base::FilePath good_extension_path(ui_test_utils::GetTestFilePath( |
Devlin Cronin | 19775cc | 2018-04-19 15:04:26 | [diff] [blame] | 2567 | base::FilePath(kTestExtensionsDir), base::FilePath(kSimpleWithPopupExt))); |
limasdf | c83e0b7 | 2017-03-03 17:08:35 | [diff] [blame] | 2568 | content::WindowedNotificationObserver extension_load_error_observer( |
| 2569 | extensions::NOTIFICATION_EXTENSION_LOAD_ERROR, |
| 2570 | content::NotificationService::AllSources()); |
| 2571 | installer->Load(good_extension_path); |
| 2572 | extension_load_error_observer.Wait(); |
[email protected] | ec1b3e71 | 2013-05-25 14:29:16 | [diff] [blame] | 2573 | |
| 2574 | // Loading other unpacked extensions are not blocked. |
limasdf | c83e0b7 | 2017-03-03 17:08:35 | [diff] [blame] | 2575 | scoped_refptr<const extensions::Extension> extension = |
| 2576 | LoadUnpackedExtension(kAppUnpackedExt); |
| 2577 | ASSERT_TRUE(extension); |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 2578 | |
| 2579 | const std::string old_version_number = |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 2580 | service->GetExtensionById(kGoodCrxId, true)->version().GetString(); |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 2581 | |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2582 | content::WindowedNotificationObserver new_process_observer( |
| 2583 | content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 2584 | content::NotificationService::AllSources()); |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 2585 | |
| 2586 | // Updating the force-installed extension. |
| 2587 | extensions::ExtensionUpdater* updater = service->updater(); |
| 2588 | extensions::ExtensionUpdater::CheckParams params; |
| 2589 | params.install_immediately = true; |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2590 | extensions::TestExtensionRegistryObserver update_observer( |
| 2591 | extensions::ExtensionRegistry::Get(browser()->profile())); |
Minh X. Nguyen | 722b968 | 2018-04-25 21:46:48 | [diff] [blame] | 2592 | updater->CheckNow(std::move(params)); |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2593 | update_observer.WaitForExtensionWillBeInstalled(); |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 2594 | |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 2595 | const base::Version& new_version = |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 2596 | service->GetExtensionById(kGoodCrxId, true)->version(); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 2597 | ASSERT_TRUE(new_version.IsValid()); |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 2598 | base::Version old_version(old_version_number); |
| 2599 | ASSERT_TRUE(old_version.IsValid()); |
| 2600 | |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 2601 | EXPECT_EQ(1, new_version.CompareTo(old_version)); |
[email protected] | 6b6a6e6 | 2013-05-28 19:33:37 | [diff] [blame] | 2602 | |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2603 | // Wait for the new extension process to launch. |
| 2604 | new_process_observer.Wait(); |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 2605 | |
| 2606 | // Wait until any background pages belonging to force-installed extensions |
| 2607 | // have been loaded. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 2608 | extensions::ProcessManager* manager = |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 2609 | extensions::ProcessManager::Get(browser()->profile()); |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 2610 | extensions::ProcessManager::FrameSet all_frames = manager->GetAllFrames(); |
jdoerrie | 601c715 | 2018-10-02 23:43:11 | [diff] [blame] | 2611 | for (auto iter = all_frames.begin(); iter != all_frames.end();) { |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 2612 | content::WebContents* web_contents = |
| 2613 | content::WebContents::FromRenderFrameHost(*iter); |
| 2614 | ASSERT_TRUE(web_contents); |
| 2615 | if (!web_contents->IsLoading()) { |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 2616 | ++iter; |
| 2617 | } else { |
[email protected] | 1eb3964 | 2013-10-17 22:06:53 | [diff] [blame] | 2618 | WebContentsLoadedOrDestroyedWatcher(web_contents).Wait(); |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 2619 | |
| 2620 | // Test activity may have modified the set of extension processes during |
| 2621 | // message processing, so re-start the iteration to catch added/removed |
| 2622 | // processes. |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 2623 | all_frames = manager->GetAllFrames(); |
| 2624 | iter = all_frames.begin(); |
[email protected] | 6b9dafc | 2013-08-30 15:41:59 | [diff] [blame] | 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | // Test policy-installed extensions are reloaded when killed. |
Lukasz Anforowicz | 907b6ac | 2019-06-13 01:49:08 | [diff] [blame] | 2629 | { |
Lukasz Anforowicz | 907b6ac | 2019-06-13 01:49:08 | [diff] [blame] | 2630 | BackgroundContentsService:: |
| 2631 | SetRestartDelayForForceInstalledAppsAndExtensionsForTesting(0); |
| 2632 | content::WindowedNotificationObserver extension_crashed_observer( |
| 2633 | extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| 2634 | content::NotificationService::AllSources()); |
| 2635 | extensions::TestExtensionRegistryObserver extension_loaded_observer( |
| 2636 | extensions::ExtensionRegistry::Get(browser()->profile()), kGoodCrxId); |
| 2637 | extensions::ExtensionHost* extension_host = |
| 2638 | extensions::ProcessManager::Get(browser()->profile()) |
| 2639 | ->GetBackgroundHostForExtension(kGoodCrxId); |
Lukasz Anforowicz | d97bc0ec | 2019-06-19 23:58:22 | [diff] [blame] | 2640 | content::RenderProcessHost* process = extension_host->render_process_host(); |
| 2641 | content::ScopedAllowRendererCrashes allow_renderer_crashes(process); |
| 2642 | process->Shutdown(content::RESULT_CODE_KILLED); |
Lukasz Anforowicz | 907b6ac | 2019-06-13 01:49:08 | [diff] [blame] | 2643 | extension_crashed_observer.Wait(); |
| 2644 | extension_loaded_observer.WaitForExtensionLoaded(); |
| 2645 | } |
[email protected] | ec29ec03 | 2012-09-10 18:27:09 | [diff] [blame] | 2646 | } |
| 2647 | |
Maksim Ivanov | eaac2ff | 2018-04-16 16:23:24 | [diff] [blame] | 2648 | IN_PROC_BROWSER_TEST_F(PolicyTest, |
| 2649 | ExtensionInstallForcelist_DefaultedUpdateUrl) { |
| 2650 | // Verifies the ExtensionInstallForcelist policy with an empty (defaulted) |
| 2651 | // "update" URL. |
| 2652 | |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2653 | ExtensionRequestInterceptor interceptor; |
| 2654 | |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2655 | extensions::ExtensionService* service = extension_service(); |
Maksim Ivanov | eaac2ff | 2018-04-16 16:23:24 | [diff] [blame] | 2656 | ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
| 2657 | |
Maksim Ivanov | eaac2ff | 2018-04-16 16:23:24 | [diff] [blame] | 2658 | // Setting the forcelist extension should install "good_v1.crx". |
| 2659 | base::ListValue forcelist; |
| 2660 | forcelist.AppendString(kGoodCrxId); |
| 2661 | PolicyMap policies; |
| 2662 | policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, |
| 2663 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2664 | forcelist.CreateDeepCopy(), nullptr); |
| 2665 | extensions::TestExtensionRegistryObserver observer( |
| 2666 | extensions::ExtensionRegistry::Get(browser()->profile())); |
| 2667 | UpdateProviderPolicy(policies); |
| 2668 | observer.WaitForExtensionWillBeInstalled(); |
| 2669 | |
Maksim Ivanov | eaac2ff | 2018-04-16 16:23:24 | [diff] [blame] | 2670 | EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); |
| 2671 | } |
| 2672 | |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 2673 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionRecommendedInstallationMode) { |
| 2674 | // Verifies that extensions that are recommended-installed by policies are |
| 2675 | // installed, can be disabled but not uninstalled. |
Nick Peterson | d952cb77 | 2018-03-07 15:46:03 | [diff] [blame] | 2676 | |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2677 | ExtensionRequestInterceptor interceptor; |
| 2678 | |
| 2679 | // Extensions that are force-installed come from an update URL, which defaults |
| 2680 | // to the webstore. Use a test URL for this test with an update manifest |
| 2681 | // that includes "good_v1.crx". |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2682 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 2683 | GURL url = |
| 2684 | embedded_test_server()->GetURL("/extensions/good_v1_update_manifest.xml"); |
| 2685 | |
Nick Peterson | d952cb77 | 2018-03-07 15:46:03 | [diff] [blame] | 2686 | // Mark as enterprise managed. |
| 2687 | #if defined(OS_WIN) |
Roger Tawa | c1b544a8 | 2018-08-24 16:23:25 | [diff] [blame] | 2688 | base::win::ScopedDomainStateForTesting scoped_domain(true); |
Nick Peterson | d952cb77 | 2018-03-07 15:46:03 | [diff] [blame] | 2689 | #endif |
| 2690 | |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2691 | extensions::ExtensionService* service = extension_service(); |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 2692 | ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
| 2693 | |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 2694 | // Setting the forcelist extension should install "good_v1.crx". |
| 2695 | base::DictionaryValue dict_value; |
| 2696 | dict_value.SetString(std::string(kGoodCrxId) + "." + |
| 2697 | extensions::schema_constants::kInstallationMode, |
| 2698 | extensions::schema_constants::kNormalInstalled); |
| 2699 | dict_value.SetString( |
| 2700 | std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl, |
| 2701 | url.spec()); |
| 2702 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2703 | policies.Set(key::kExtensionSettings, POLICY_LEVEL_MANDATORY, |
| 2704 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2705 | dict_value.CreateDeepCopy(), nullptr); |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2706 | extensions::TestExtensionRegistryObserver observer( |
| 2707 | extensions::ExtensionRegistry::Get(browser()->profile())); |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 2708 | UpdateProviderPolicy(policies); |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2709 | observer.WaitForExtensionWillBeInstalled(); |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 2710 | |
| 2711 | EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); |
| 2712 | |
| 2713 | // The user is not allowed to uninstall recommended-installed extensions. |
| 2714 | UninstallExtension(kGoodCrxId, false); |
| 2715 | |
| 2716 | // Explictly re-enables the extension. |
| 2717 | service->EnableExtension(kGoodCrxId); |
| 2718 | |
| 2719 | // But the user is allowed to disable them. |
| 2720 | EXPECT_TRUE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2721 | DisableExtension(kGoodCrxId); |
| 2722 | EXPECT_FALSE(service->IsExtensionEnabled(kGoodCrxId)); |
| 2723 | } |
| 2724 | |
Pavol Marko | 81e6971 | 2019-02-22 15:19:23 | [diff] [blame] | 2725 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { |
[email protected] | ce4e5d7a | 2012-12-11 20:59:26 | [diff] [blame] | 2726 | // Verifies that extensions are blocked if policy specifies an allowed types |
| 2727 | // list and the extension's type is not on that list. |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2728 | extensions::ExtensionService* service = extension_service(); |
[email protected] | ce4e5d7a | 2012-12-11 20:59:26 | [diff] [blame] | 2729 | ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
| 2730 | ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); |
| 2731 | |
| 2732 | base::ListValue allowed_types; |
| 2733 | allowed_types.AppendString("hosted_app"); |
| 2734 | PolicyMap policies; |
| 2735 | policies.Set(key::kExtensionAllowedTypes, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2736 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 2737 | allowed_types.CreateDeepCopy(), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 2738 | UpdateProviderPolicy(policies); |
[email protected] | ce4e5d7a | 2012-12-11 20:59:26 | [diff] [blame] | 2739 | |
| 2740 | // "good.crx" is blocked. |
| 2741 | EXPECT_FALSE(InstallExtension(kGoodCrxName)); |
| 2742 | EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
| 2743 | |
| 2744 | // "hosted_app.crx" is of a whitelisted type. |
| 2745 | const extensions::Extension* hosted_app = InstallExtension(kHostedAppCrxName); |
| 2746 | ASSERT_TRUE(hosted_app); |
| 2747 | EXPECT_EQ(kHostedAppCrxId, hosted_app->id()); |
| 2748 | EXPECT_EQ(hosted_app, service->GetExtensionById(kHostedAppCrxId, true)); |
| 2749 | |
| 2750 | // The user can remove the extension. |
| 2751 | UninstallExtension(kHostedAppCrxId, true); |
| 2752 | } |
| 2753 | |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 2754 | // Checks that a click on an extension CRX download triggers the extension |
| 2755 | // installation prompt without further user interaction when the source is |
| 2756 | // whitelisted by policy. |
[email protected] | 2107935b | 2013-09-20 16:41:46 | [diff] [blame] | 2757 | // Flaky on windows; http://crbug.com/295729 . |
| 2758 | #if defined(OS_WIN) |
| 2759 | #define MAYBE_ExtensionInstallSources DISABLED_ExtensionInstallSources |
| 2760 | #else |
| 2761 | #define MAYBE_ExtensionInstallSources ExtensionInstallSources |
| 2762 | #endif |
| 2763 | IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallSources) { |
rdevlin.cronin | 6620949 | 2015-06-10 20:44:05 | [diff] [blame] | 2764 | extensions::ScopedTestDialogAutoConfirm auto_confirm( |
| 2765 | extensions::ScopedTestDialogAutoConfirm::ACCEPT); |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2766 | extensions::ScopedInstallVerifierBypassForTest install_verifier_bypass; |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 2767 | |
John Abd-El-Malek | 9db74cc6 | 2018-08-08 19:25:21 | [diff] [blame] | 2768 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 2769 | |
John Abd-El-Malek | 9db74cc6 | 2018-08-08 19:25:21 | [diff] [blame] | 2770 | GURL download_page_url = embedded_test_server()->GetURL( |
| 2771 | "/policy/extension_install_sources_test.html"); |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 2772 | ui_test_utils::NavigateToURL(browser(), download_page_url); |
| 2773 | |
John Abd-El-Malek | 9db74cc6 | 2018-08-08 19:25:21 | [diff] [blame] | 2774 | const GURL install_source_url( |
| 2775 | embedded_test_server()->GetURL("/extensions/*")); |
| 2776 | const GURL referrer_url(embedded_test_server()->GetURL("/policy/*")); |
| 2777 | |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 2778 | // As long as the policy is not present, extensions are considered dangerous. |
| 2779 | content::DownloadTestObserverTerminal download_observer( |
| 2780 | content::BrowserContext::GetDownloadManager(browser()->profile()), 1, |
| 2781 | content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY); |
| 2782 | PerformClick(0, 0); |
| 2783 | download_observer.WaitForFinished(); |
| 2784 | |
| 2785 | // Install the policy and trigger another download. |
| 2786 | base::ListValue install_sources; |
| 2787 | install_sources.AppendString(install_source_url.spec()); |
| 2788 | install_sources.AppendString(referrer_url.spec()); |
| 2789 | PolicyMap policies; |
| 2790 | policies.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY, |
fhorschig | 64834b71 | 2015-09-21 14:20:23 | [diff] [blame] | 2791 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 2792 | install_sources.CreateDeepCopy(), nullptr); |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 2793 | UpdateProviderPolicy(policies); |
| 2794 | |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2795 | extensions::TestExtensionRegistryObserver observer( |
| 2796 | extensions::ExtensionRegistry::Get(browser()->profile())); |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 2797 | PerformClick(1, 0); |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2798 | observer.WaitForExtensionWillBeInstalled(); |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 2799 | // Note: Cannot check that the notification details match the expected |
| 2800 | // exception, since the details object has already been freed prior to |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2801 | // the completion of observer.WaitForExtensionWillBeInstalled(). |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 2802 | |
| 2803 | // The first extension shouldn't be present, the second should be there. |
| 2804 | EXPECT_FALSE(extension_service()->GetExtensionById(kGoodCrxId, true)); |
Devlin Cronin | 5e9387c3 | 2018-04-20 04:22:03 | [diff] [blame] | 2805 | EXPECT_TRUE( |
| 2806 | extension_service()->GetExtensionById(kSimpleWithIconCrxId, false)); |
[email protected] | 8967816d | 2013-03-26 12:58:25 | [diff] [blame] | 2807 | } |
| 2808 | |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2809 | // Verifies that extensions with version older than the minimum version required |
| 2810 | // by policy will get disabled, and will be auto-updated and/or re-enabled upon |
| 2811 | // policy changes as well as regular auto-updater scheduled updates. |
| 2812 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequired) { |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2813 | ExtensionRequestInterceptor interceptor; |
| 2814 | |
| 2815 | base::AtomicRefCount update_extension_count; |
| 2816 | base::RunLoop first_update_extension_runloop; |
| 2817 | interceptor.set_interceptor_hook(base::BindLambdaForTesting( |
| 2818 | [&](content::URLLoaderInterceptor::RequestParams* params) { |
| 2819 | if (params->url_request.url.host() != "update.extension") |
| 2820 | return false; |
| 2821 | |
| 2822 | if (!update_extension_count.IsZero() && !update_extension_count.IsOne()) |
| 2823 | return false; |
| 2824 | |
| 2825 | if (update_extension_count.IsZero()) { |
| 2826 | content::URLLoaderInterceptor::WriteResponse( |
| 2827 | "400 Bad request", std::string(), params->client.get()); |
| 2828 | } else { |
| 2829 | content::URLLoaderInterceptor::WriteResponse( |
| 2830 | "chrome/test/data/extensions/good2_update_manifest.xml", |
| 2831 | params->client.get()); |
| 2832 | } |
| 2833 | if (update_extension_count.IsZero()) |
| 2834 | first_update_extension_runloop.Quit(); |
| 2835 | update_extension_count.Increment(); |
| 2836 | return true; |
| 2837 | })); |
| 2838 | |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2839 | extensions::ExtensionService* service = extension_service(); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2840 | extensions::ExtensionRegistry* registry = |
| 2841 | extensions::ExtensionRegistry::Get(browser()->profile()); |
| 2842 | extensions::ExtensionPrefs* extension_prefs = |
| 2843 | extensions::ExtensionPrefs::Get(browser()->profile()); |
| 2844 | |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2845 | // Install the extension. |
| 2846 | EXPECT_TRUE(InstallExtension(kGoodV1CrxName)); |
| 2847 | EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2848 | |
| 2849 | // Update policy to set a minimum version of 1.0.0.0, the extension (with |
| 2850 | // version 1.0.0.0) should still be enabled. |
| 2851 | { |
| 2852 | extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2853 | management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.0"); |
| 2854 | } |
| 2855 | base::RunLoop().RunUntilIdle(); |
| 2856 | |
| 2857 | EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2858 | |
| 2859 | // Update policy to set a minimum version of 1.0.0.1, the extension (with |
| 2860 | // version 1.0.0.0) should now be disabled. |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2861 | EXPECT_TRUE(update_extension_count.IsZero()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2862 | { |
| 2863 | extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2864 | management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.1"); |
| 2865 | } |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2866 | first_update_extension_runloop.Run(); |
| 2867 | EXPECT_TRUE(update_extension_count.IsOne()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2868 | |
| 2869 | EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 2870 | EXPECT_EQ(extensions::disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2871 | extension_prefs->GetDisableReasons(kGoodCrxId)); |
| 2872 | |
| 2873 | // Provide a new version (1.0.0.1) which is expected to be auto updated to |
| 2874 | // via the update URL in the manifest of the older version. |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2875 | EXPECT_TRUE(update_extension_count.IsOne()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2876 | { |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2877 | extensions::TestExtensionRegistryObserver update_observer( |
| 2878 | extensions::ExtensionRegistry::Get(browser()->profile())); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2879 | service->updater()->CheckSoon(); |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2880 | update_observer.WaitForExtensionWillBeInstalled(); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2881 | } |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2882 | EXPECT_EQ(2, update_extension_count.SubtleRefCountForDebug()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2883 | |
| 2884 | // The extension should be auto-updated to newer version and re-enabled. |
| 2885 | EXPECT_EQ("1.0.0.1", |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 2886 | service->GetInstalledExtension(kGoodCrxId)->version().GetString()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2887 | EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2888 | } |
| 2889 | |
| 2890 | // Similar to ExtensionMinimumVersionRequired test, but with different settings |
| 2891 | // and orders. |
| 2892 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionRequiredAlt) { |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2893 | ExtensionRequestInterceptor interceptor; |
| 2894 | |
| 2895 | base::AtomicRefCount update_extension_count; |
| 2896 | interceptor.set_interceptor_hook(base::BindLambdaForTesting( |
| 2897 | [&](content::URLLoaderInterceptor::RequestParams* params) { |
| 2898 | if (params->url_request.url.host() == "update.extension" && |
| 2899 | update_extension_count.IsZero()) { |
| 2900 | content::URLLoaderInterceptor::WriteResponse( |
| 2901 | "chrome/test/data/extensions/good2_update_manifest.xml", |
| 2902 | params->client.get()); |
| 2903 | update_extension_count.Increment(); |
| 2904 | return true; |
| 2905 | } |
| 2906 | return false; |
| 2907 | })); |
| 2908 | |
Devlin Cronin | 2824e9c | 2018-06-01 23:32:05 | [diff] [blame] | 2909 | extensions::ExtensionService* service = extension_service(); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2910 | extensions::ExtensionRegistry* registry = |
| 2911 | extensions::ExtensionRegistry::Get(browser()->profile()); |
| 2912 | extensions::ExtensionPrefs* extension_prefs = |
| 2913 | extensions::ExtensionPrefs::Get(browser()->profile()); |
| 2914 | |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2915 | // Set the policy to require an even higher minimum version this time. |
| 2916 | { |
| 2917 | extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2918 | management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.2"); |
| 2919 | } |
| 2920 | base::RunLoop().RunUntilIdle(); |
| 2921 | |
| 2922 | // Install the 1.0.0.0 version, it should be installed but disabled. |
| 2923 | EXPECT_TRUE(InstallExtension(kGoodV1CrxName)); |
| 2924 | EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 2925 | EXPECT_EQ(extensions::disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2926 | extension_prefs->GetDisableReasons(kGoodCrxId)); |
| 2927 | EXPECT_EQ("1.0.0.0", |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 2928 | service->GetInstalledExtension(kGoodCrxId)->version().GetString()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2929 | |
| 2930 | // An extension management policy update should trigger an update as well. |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2931 | EXPECT_TRUE(update_extension_count.IsZero()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2932 | { |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2933 | extensions::TestExtensionRegistryObserver update_observer( |
| 2934 | extensions::ExtensionRegistry::Get(browser()->profile())); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2935 | { |
| 2936 | // Set a higher minimum version, just intend to trigger a policy update. |
| 2937 | extensions::ExtensionManagementPolicyUpdater management_policy( |
| 2938 | &provider_); |
| 2939 | management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.3"); |
| 2940 | } |
| 2941 | base::RunLoop().RunUntilIdle(); |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2942 | update_observer.WaitForExtensionWillBeInstalled(); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2943 | } |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2944 | EXPECT_TRUE(update_extension_count.IsOne()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2945 | |
| 2946 | // It should be updated to 1.0.0.1 but remain disabled. |
| 2947 | EXPECT_EQ("1.0.0.1", |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 2948 | service->GetInstalledExtension(kGoodCrxId)->version().GetString()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2949 | EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 2950 | EXPECT_EQ(extensions::disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2951 | extension_prefs->GetDisableReasons(kGoodCrxId)); |
| 2952 | |
| 2953 | // Remove the minimum version requirement. The extension should be re-enabled. |
| 2954 | { |
| 2955 | extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2956 | management_policy.UnsetMinimumVersionRequired(kGoodCrxId); |
| 2957 | } |
| 2958 | base::RunLoop().RunUntilIdle(); |
| 2959 | |
| 2960 | EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2961 | EXPECT_FALSE(extension_prefs->HasDisableReason( |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 2962 | kGoodCrxId, |
| 2963 | extensions::disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY)); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | // Verifies that a force-installed extension which does not meet a subsequently |
| 2967 | // set minimum version requirement is handled well. |
| 2968 | IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionForceInstalled) { |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2969 | ExtensionRequestInterceptor interceptor; |
| 2970 | |
Nick Peterson | d952cb77 | 2018-03-07 15:46:03 | [diff] [blame] | 2971 | // Mark as enterprise managed. |
| 2972 | #if defined(OS_WIN) |
Roger Tawa | c1b544a8 | 2018-08-24 16:23:25 | [diff] [blame] | 2973 | base::win::ScopedDomainStateForTesting scoped_domain(true); |
Nick Peterson | d952cb77 | 2018-03-07 15:46:03 | [diff] [blame] | 2974 | #endif |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2975 | extensions::ExtensionRegistry* registry = |
| 2976 | extensions::ExtensionRegistry::Get(browser()->profile()); |
| 2977 | extensions::ExtensionPrefs* extension_prefs = |
| 2978 | extensions::ExtensionPrefs::Get(browser()->profile()); |
| 2979 | |
| 2980 | // Prepare the update URL for force installing. |
John Abd-El-Malek | 580bc96a5 | 2018-08-10 02:24:47 | [diff] [blame] | 2981 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 2982 | GURL url = |
| 2983 | embedded_test_server()->GetURL("/extensions/good_v1_update_manifest.xml"); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2984 | |
| 2985 | // Set policy to force-install the extension, it should be installed and |
| 2986 | // enabled. |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2987 | extensions::TestExtensionRegistryObserver install_observer( |
| 2988 | extensions::ExtensionRegistry::Get(browser()->profile())); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2989 | EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2990 | { |
| 2991 | extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 2992 | management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId, |
| 2993 | url.spec(), true); |
| 2994 | } |
| 2995 | base::RunLoop().RunUntilIdle(); |
limasdf | 8fec661 | 2015-10-12 10:03:06 | [diff] [blame] | 2996 | install_observer.WaitForExtensionWillBeInstalled(); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 2997 | |
| 2998 | EXPECT_TRUE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2999 | |
| 3000 | // Set policy a minimum version of "1.0.0.1", the extension now should be |
| 3001 | // disabled. |
| 3002 | { |
| 3003 | extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
| 3004 | management_policy.SetMinimumVersionRequired(kGoodCrxId, "1.0.0.1"); |
| 3005 | } |
| 3006 | base::RunLoop().RunUntilIdle(); |
| 3007 | EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 3008 | EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 3009 | EXPECT_EQ(extensions::disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 3010 | extension_prefs->GetDisableReasons(kGoodCrxId)); |
| 3011 | } |
| 3012 | |
[email protected] | ecde07ed | 2012-09-11 13:08:47 | [diff] [blame] | 3013 | IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) { |
| 3014 | // Verifies that the homepage can be configured with policies. |
| 3015 | // Set a default, and check that the home button navigates there. |
| 3016 | browser()->profile()->GetPrefs()->SetString( |
| 3017 | prefs::kHomePage, chrome::kChromeUIPolicyURL); |
| 3018 | browser()->profile()->GetPrefs()->SetBoolean( |
| 3019 | prefs::kHomePageIsNewTabPage, false); |
| 3020 | EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL), |
| 3021 | browser()->profile()->GetHomePage()); |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 3022 | content::WebContents* contents = |
| 3023 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 3024 | EXPECT_EQ(GURL(url::kAboutBlankURL), contents->GetURL()); |
[email protected] | ecde07ed | 2012-09-11 13:08:47 | [diff] [blame] | 3025 | EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); |
| 3026 | EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL), contents->GetURL()); |
| 3027 | |
| 3028 | // Now override with policy. |
| 3029 | PolicyMap policies; |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 3030 | policies.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY, |
| 3031 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3032 | std::make_unique<base::Value>(chrome::kChromeUICreditsURL), |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 3033 | nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3034 | UpdateProviderPolicy(policies); |
[email protected] | ecde07ed | 2012-09-11 13:08:47 | [diff] [blame] | 3035 | EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); |
| 3036 | content::WaitForLoadStop(contents); |
[email protected] | a44a14f | 2012-09-26 22:48:22 | [diff] [blame] | 3037 | EXPECT_EQ(GURL(chrome::kChromeUICreditsURL), contents->GetURL()); |
[email protected] | ecde07ed | 2012-09-11 13:08:47 | [diff] [blame] | 3038 | |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3039 | policies.Set(key::kHomepageIsNewTabPage, POLICY_LEVEL_MANDATORY, |
| 3040 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3041 | std::make_unique<base::Value>(true), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3042 | UpdateProviderPolicy(policies); |
[email protected] | ecde07ed | 2012-09-11 13:08:47 | [diff] [blame] | 3043 | EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); |
[email protected] | 19506d54 | 2013-10-15 23:11:06 | [diff] [blame] | 3044 | content::WaitForLoadStop(contents); |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 3045 | EXPECT_TRUE(search::IsInstantNTP(contents)); |
[email protected] | ecde07ed | 2012-09-11 13:08:47 | [diff] [blame] | 3046 | } |
| 3047 | |
Guido Urdaneta | 3c8fefc0 | 2016-12-15 13:29:18 | [diff] [blame] | 3048 | #if defined(OS_MACOSX) && defined(ADDRESS_SANITIZER) |
| 3049 | // Flaky on ASAN on Mac. See https://crbug.com/674497. |
| 3050 | #define MAYBE_IncognitoEnabled DISABLED_IncognitoEnabled |
| 3051 | #else |
| 3052 | #define MAYBE_IncognitoEnabled IncognitoEnabled |
| 3053 | #endif |
| 3054 | IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_IncognitoEnabled) { |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 3055 | // Verifies that incognito windows can't be opened when disabled by policy. |
| 3056 | |
scottmg | 0d8e4ab | 2016-01-28 00:34:55 | [diff] [blame] | 3057 | const BrowserList* active_browser_list = BrowserList::GetInstance(); |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 3058 | |
[email protected] | b3fc7b7 | 2012-08-28 15:04:04 | [diff] [blame] | 3059 | // Disable incognito via policy and verify that incognito windows can't be |
| 3060 | // opened. |
[email protected] | 7d1a810b | 2013-06-26 19:51:59 | [diff] [blame] | 3061 | EXPECT_EQ(1u, active_browser_list->size()); |
trizzofo | 49b95f5 | 2016-07-02 00:26:13 | [diff] [blame] | 3062 | EXPECT_FALSE(BrowserList::IsIncognitoSessionActive()); |
[email protected] | b3fc7b7 | 2012-08-28 15:04:04 | [diff] [blame] | 3063 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3064 | policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, |
| 3065 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3066 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3067 | UpdateProviderPolicy(policies); |
[email protected] | b3fc7b7 | 2012-08-28 15:04:04 | [diff] [blame] | 3068 | EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); |
[email protected] | 7d1a810b | 2013-06-26 19:51:59 | [diff] [blame] | 3069 | EXPECT_EQ(1u, active_browser_list->size()); |
trizzofo | 49b95f5 | 2016-07-02 00:26:13 | [diff] [blame] | 3070 | EXPECT_FALSE(BrowserList::IsIncognitoSessionActive()); |
[email protected] | b3fc7b7 | 2012-08-28 15:04:04 | [diff] [blame] | 3071 | |
| 3072 | // Enable via policy and verify that incognito windows can be opened. |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3073 | policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, |
| 3074 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3075 | std::make_unique<base::Value>(true), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3076 | UpdateProviderPolicy(policies); |
[email protected] | b3fc7b7 | 2012-08-28 15:04:04 | [diff] [blame] | 3077 | EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); |
[email protected] | 7d1a810b | 2013-06-26 19:51:59 | [diff] [blame] | 3078 | EXPECT_EQ(2u, active_browser_list->size()); |
trizzofo | 49b95f5 | 2016-07-02 00:26:13 | [diff] [blame] | 3079 | EXPECT_TRUE(BrowserList::IsIncognitoSessionActive()); |
[email protected] | b3fc7b7 | 2012-08-28 15:04:04 | [diff] [blame] | 3080 | } |
| 3081 | |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 3082 | IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) { |
| 3083 | // Verifies that Javascript can be disabled. |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 3084 | content::WebContents* contents = |
| 3085 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 3086 | EXPECT_TRUE(IsJavascriptEnabled(contents)); |
| 3087 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); |
| 3088 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); |
[email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 3089 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_DEVICES)); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 3090 | |
| 3091 | // Disable Javascript via policy. |
| 3092 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3093 | policies.Set(key::kJavascriptEnabled, POLICY_LEVEL_MANDATORY, |
| 3094 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3095 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3096 | UpdateProviderPolicy(policies); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 3097 | // Reload the page. |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 3098 | ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 3099 | EXPECT_FALSE(IsJavascriptEnabled(contents)); |
| 3100 | // Developer tools still work when javascript is disabled. |
| 3101 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); |
| 3102 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); |
[email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 3103 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_DEVICES)); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 3104 | // Javascript is always enabled for the internal pages. |
[email protected] | e1f2b8aa | 2012-09-28 14:22:16 | [diff] [blame] | 3105 | ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 3106 | EXPECT_TRUE(IsJavascriptEnabled(contents)); |
| 3107 | |
| 3108 | // The javascript content setting policy overrides the javascript policy. |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 3109 | ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 3110 | EXPECT_FALSE(IsJavascriptEnabled(contents)); |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 3111 | policies.Set(key::kDefaultJavaScriptSetting, POLICY_LEVEL_MANDATORY, |
| 3112 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3113 | std::make_unique<base::Value>(CONTENT_SETTING_ALLOW), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3114 | UpdateProviderPolicy(policies); |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 3115 | ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
[email protected] | ea82636 | 2012-09-05 23:31:37 | [diff] [blame] | 3116 | EXPECT_TRUE(IsJavascriptEnabled(contents)); |
| 3117 | } |
| 3118 | |
[email protected] | 27ef988d | 2014-08-01 17:00:40 | [diff] [blame] | 3119 | IN_PROC_BROWSER_TEST_F(PolicyTest, NetworkPrediction) { |
| 3120 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 3121 | |
| 3122 | // Enabled by default. |
| 3123 | EXPECT_TRUE(IsNetworkPredictionEnabled(prefs)); |
| 3124 | |
| 3125 | // Disable by old, deprecated policy. |
| 3126 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3127 | policies.Set(key::kDnsPrefetchingEnabled, POLICY_LEVEL_MANDATORY, |
| 3128 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3129 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 27ef988d | 2014-08-01 17:00:40 | [diff] [blame] | 3130 | UpdateProviderPolicy(policies); |
| 3131 | |
| 3132 | EXPECT_FALSE(IsNetworkPredictionEnabled(prefs)); |
| 3133 | |
| 3134 | // Enabled by new policy, this should override old one. |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3135 | policies.Set(key::kNetworkPredictionOptions, POLICY_LEVEL_MANDATORY, |
| 3136 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3137 | std::make_unique<base::Value>( |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 3138 | chrome_browser_net::NETWORK_PREDICTION_ALWAYS), |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3139 | nullptr); |
[email protected] | 27ef988d | 2014-08-01 17:00:40 | [diff] [blame] | 3140 | UpdateProviderPolicy(policies); |
| 3141 | |
| 3142 | EXPECT_TRUE(IsNetworkPredictionEnabled(prefs)); |
| 3143 | } |
| 3144 | |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 3145 | IN_PROC_BROWSER_TEST_F(PolicyTest, SavingBrowserHistoryDisabled) { |
| 3146 | // Verifies that browsing history is not saved. |
| 3147 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3148 | policies.Set(key::kSavingBrowserHistoryDisabled, POLICY_LEVEL_MANDATORY, |
| 3149 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3150 | std::make_unique<base::Value>(true), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3151 | UpdateProviderPolicy(policies); |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 3152 | GURL url = ui_test_utils::GetTestUrl( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3153 | base::FilePath(base::FilePath::kCurrentDirectory), |
| 3154 | base::FilePath(FILE_PATH_LITERAL("empty.html"))); |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 3155 | ui_test_utils::NavigateToURL(browser(), url); |
| 3156 | // Verify that the navigation wasn't saved in the history. |
[email protected] | 2fa63948 | 2012-08-30 19:32:04 | [diff] [blame] | 3157 | ui_test_utils::HistoryEnumerator enumerator1(browser()->profile()); |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 3158 | EXPECT_EQ(0u, enumerator1.urls().size()); |
| 3159 | |
| 3160 | // Now flip the policy and try again. |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3161 | policies.Set(key::kSavingBrowserHistoryDisabled, POLICY_LEVEL_MANDATORY, |
| 3162 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3163 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3164 | UpdateProviderPolicy(policies); |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 3165 | ui_test_utils::NavigateToURL(browser(), url); |
| 3166 | // Verify that the navigation was saved in the history. |
[email protected] | 2fa63948 | 2012-08-30 19:32:04 | [diff] [blame] | 3167 | ui_test_utils::HistoryEnumerator enumerator2(browser()->profile()); |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 3168 | ASSERT_EQ(1u, enumerator2.urls().size()); |
| 3169 | EXPECT_EQ(url, enumerator2.urls()[0]); |
| 3170 | } |
| 3171 | |
dullweber | 303f444 | 2017-03-03 11:50:19 | [diff] [blame] | 3172 | IN_PROC_BROWSER_TEST_F(PolicyTest, DeletingBrowsingHistoryDisabled) { |
| 3173 | // Verifies that deleting the browsing history can be disabled. |
| 3174 | |
| 3175 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 3176 | EXPECT_FALSE(prefs->IsManagedPreference(prefs::kAllowDeletingBrowserHistory)); |
| 3177 | EXPECT_TRUE(prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory)); |
| 3178 | |
| 3179 | EXPECT_TRUE(prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory)); |
| 3180 | EXPECT_TRUE(prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory)); |
| 3181 | EXPECT_TRUE( |
| 3182 | prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistoryBasic)); |
| 3183 | |
| 3184 | PolicyMap policies; |
| 3185 | policies.Set(key::kAllowDeletingBrowserHistory, POLICY_LEVEL_MANDATORY, |
| 3186 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3187 | std::make_unique<base::Value>(true), nullptr); |
dullweber | 303f444 | 2017-03-03 11:50:19 | [diff] [blame] | 3188 | UpdateProviderPolicy(policies); |
| 3189 | EXPECT_TRUE(prefs->IsManagedPreference(prefs::kAllowDeletingBrowserHistory)); |
| 3190 | EXPECT_TRUE(prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory)); |
| 3191 | |
| 3192 | EXPECT_TRUE(prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory)); |
| 3193 | EXPECT_TRUE(prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory)); |
| 3194 | EXPECT_TRUE( |
| 3195 | prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistoryBasic)); |
| 3196 | |
| 3197 | policies.Set(key::kAllowDeletingBrowserHistory, POLICY_LEVEL_MANDATORY, |
| 3198 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3199 | std::make_unique<base::Value>(false), nullptr); |
dullweber | 303f444 | 2017-03-03 11:50:19 | [diff] [blame] | 3200 | UpdateProviderPolicy(policies); |
| 3201 | EXPECT_TRUE(prefs->IsManagedPreference(prefs::kAllowDeletingBrowserHistory)); |
| 3202 | EXPECT_FALSE(prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory)); |
| 3203 | |
| 3204 | EXPECT_FALSE(prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory)); |
| 3205 | EXPECT_FALSE(prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory)); |
| 3206 | EXPECT_FALSE( |
| 3207 | prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistoryBasic)); |
| 3208 | |
| 3209 | policies.Clear(); |
| 3210 | UpdateProviderPolicy(policies); |
| 3211 | EXPECT_FALSE(prefs->IsManagedPreference(prefs::kAllowDeletingBrowserHistory)); |
| 3212 | EXPECT_TRUE(prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory)); |
| 3213 | |
| 3214 | EXPECT_TRUE(prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory)); |
| 3215 | EXPECT_TRUE(prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory)); |
| 3216 | EXPECT_TRUE( |
| 3217 | prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistoryBasic)); |
| 3218 | } |
| 3219 | |
hans | f281a58 | 2015-11-02 23:23:18 | [diff] [blame] | 3220 | // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
| 3221 | #if !defined(USE_AURA) |
[email protected] | 884e4d7a | 2013-05-17 05:48:24 | [diff] [blame] | 3222 | // http://crbug.com/241691 PolicyTest.TranslateEnabled is failing regularly. |
| 3223 | IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_TranslateEnabled) { |
[email protected] | b8b2705 | 2012-08-29 14:05:16 | [diff] [blame] | 3224 | // Verifies that translate can be forced enabled or disabled by policy. |
| 3225 | |
[email protected] | 4f822f02 | 2012-12-20 19:11:42 | [diff] [blame] | 3226 | // Get the InfoBarService, and verify that there are no infobars on startup. |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 3227 | content::WebContents* contents = |
| 3228 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3229 | ASSERT_TRUE(contents); |
[email protected] | 4f822f02 | 2012-12-20 19:11:42 | [diff] [blame] | 3230 | InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); |
| 3231 | ASSERT_TRUE(infobar_service); |
[email protected] | b44f1d3 | 2014-04-10 13:53:26 | [diff] [blame] | 3232 | EXPECT_EQ(0u, infobar_service->infobar_count()); |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3233 | |
| 3234 | // Force enable the translate feature. |
| 3235 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3236 | policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, |
| 3237 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 3238 | base::WrapUnique(new base::Value(true)), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3239 | UpdateProviderPolicy(policies); |
Avi Drissman | d3f956d7 | 2018-04-02 21:44:07 | [diff] [blame] | 3240 | // Instead of waiting for an infobar, this test waits for |
| 3241 | // NOTIFICATION_TAB_LANGUAGE_DETERMINED because that's what the |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3242 | // TranslateManager observes. This allows checking that an infobar is NOT |
Avi Drissman | d3f956d7 | 2018-04-02 21:44:07 | [diff] [blame] | 3243 | // shown below, without polling for infobars for some indeterminate amount of |
| 3244 | // time. |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3245 | GURL url = ui_test_utils::GetTestUrl( |
[email protected] | c727beda9 | 2013-05-03 13:50:32 | [diff] [blame] | 3246 | base::FilePath(), |
| 3247 | base::FilePath(FILE_PATH_LITERAL("translate/fr_test.html"))); |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3248 | content::WindowedNotificationObserver language_observer1( |
| 3249 | chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
| 3250 | content::NotificationService::AllSources()); |
| 3251 | ui_test_utils::NavigateToURL(browser(), url); |
| 3252 | language_observer1.Wait(); |
[email protected] | c727beda9 | 2013-05-03 13:50:32 | [diff] [blame] | 3253 | |
| 3254 | // Verify the translation detected for this tab. |
[email protected] | 255ab97 | 2014-06-04 12:14:22 | [diff] [blame] | 3255 | ChromeTranslateClient* chrome_translate_client = |
| 3256 | ChromeTranslateClient::FromWebContents(contents); |
| 3257 | ASSERT_TRUE(chrome_translate_client); |
[email protected] | e5e72cc | 2014-07-22 19:06:49 | [diff] [blame] | 3258 | translate::LanguageState& language_state = |
| 3259 | chrome_translate_client->GetLanguageState(); |
[email protected] | c727beda9 | 2013-05-03 13:50:32 | [diff] [blame] | 3260 | EXPECT_EQ("fr", language_state.original_language()); |
[email protected] | 54e4b52 | 2013-05-21 08:36:23 | [diff] [blame] | 3261 | EXPECT_TRUE(language_state.page_needs_translation()); |
[email protected] | c727beda9 | 2013-05-03 13:50:32 | [diff] [blame] | 3262 | EXPECT_FALSE(language_state.translation_pending()); |
| 3263 | EXPECT_FALSE(language_state.translation_declined()); |
| 3264 | EXPECT_FALSE(language_state.IsPageTranslated()); |
| 3265 | |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3266 | // Verify that the translate infobar showed up. |
[email protected] | b44f1d3 | 2014-04-10 13:53:26 | [diff] [blame] | 3267 | ASSERT_EQ(1u, infobar_service->infobar_count()); |
[email protected] | 051655ad | 2014-04-18 15:09:41 | [diff] [blame] | 3268 | infobars::InfoBar* infobar = infobar_service->infobar_at(0); |
[email protected] | e5e72cc | 2014-07-22 19:06:49 | [diff] [blame] | 3269 | translate::TranslateInfoBarDelegate* translate_infobar_delegate = |
[email protected] | 39308cb | 2013-12-06 03:01:48 | [diff] [blame] | 3270 | infobar->delegate()->AsTranslateInfoBarDelegate(); |
[email protected] | 4ee3c91 | 2013-07-19 20:20:42 | [diff] [blame] | 3271 | ASSERT_TRUE(translate_infobar_delegate); |
[email protected] | b5d2278 | 2014-04-07 11:02:09 | [diff] [blame] | 3272 | EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, |
[email protected] | bccf5ab | 2014-02-15 08:20:30 | [diff] [blame] | 3273 | translate_infobar_delegate->translate_step()); |
[email protected] | 4ee3c91 | 2013-07-19 20:20:42 | [diff] [blame] | 3274 | EXPECT_EQ("fr", translate_infobar_delegate->original_language_code()); |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3275 | |
| 3276 | // Now force disable translate. |
[email protected] | b44f1d3 | 2014-04-10 13:53:26 | [diff] [blame] | 3277 | infobar_service->RemoveInfoBar(infobar); |
| 3278 | EXPECT_EQ(0u, infobar_service->infobar_count()); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3279 | policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, |
| 3280 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 3281 | base::WrapUnique(new base::Value(false)), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3282 | UpdateProviderPolicy(policies); |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3283 | // Navigating to the same URL now doesn't trigger an infobar. |
| 3284 | content::WindowedNotificationObserver language_observer2( |
| 3285 | chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
| 3286 | content::NotificationService::AllSources()); |
| 3287 | ui_test_utils::NavigateToURL(browser(), url); |
| 3288 | language_observer2.Wait(); |
[email protected] | b44f1d3 | 2014-04-10 13:53:26 | [diff] [blame] | 3289 | EXPECT_EQ(0u, infobar_service->infobar_count()); |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3290 | } |
hans | f281a58 | 2015-11-02 23:23:18 | [diff] [blame] | 3291 | #endif // !defined(USE_AURA) |
[email protected] | 850b4be | 2012-08-28 15:10:34 | [diff] [blame] | 3292 | |
[email protected] | 307aec7 | 2012-09-18 21:52:44 | [diff] [blame] | 3293 | IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) { |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 3294 | // Checks that URLs can be blacklisted, and that exceptions can be made to |
| 3295 | // the blacklist. |
[email protected] | 233b688e | 2012-11-27 10:44:12 | [diff] [blame] | 3296 | |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 3297 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 3298 | |
| 3299 | const std::string kURLS[] = { |
| 3300 | embedded_test_server()->GetURL("aaa.com", "/empty.html").spec(), |
| 3301 | embedded_test_server()->GetURL("bbb.com", "/empty.html").spec(), |
| 3302 | embedded_test_server()->GetURL("sub.bbb.com", "/empty.html").spec(), |
| 3303 | embedded_test_server()->GetURL("bbb.com", "/policy/blank.html").spec(), |
| 3304 | embedded_test_server()->GetURL("bbb.com.", "/policy/blank.html").spec(), |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 3305 | }; |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 3306 | |
[email protected] | 00367e0 | 2013-03-19 20:07:56 | [diff] [blame] | 3307 | // Verify that "bbb.com" opens before applying the blacklist. |
jam | d6be16e | 2014-09-28 15:18:34 | [diff] [blame] | 3308 | CheckCanOpenURL(browser(), kURLS[1]); |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 3309 | |
| 3310 | // Set a blacklist. |
| 3311 | base::ListValue blacklist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 3312 | blacklist.AppendString("bbb.com"); |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 3313 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3314 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3315 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3316 | UpdateProviderPolicy(policies); |
[email protected] | 307aec7 | 2012-09-18 21:52:44 | [diff] [blame] | 3317 | FlushBlacklistPolicy(); |
[email protected] | 00367e0 | 2013-03-19 20:07:56 | [diff] [blame] | 3318 | // All bbb.com URLs are blocked, and "aaa.com" is still unblocked. |
jam | d6be16e | 2014-09-28 15:18:34 | [diff] [blame] | 3319 | CheckCanOpenURL(browser(), kURLS[0]); |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 3320 | for (size_t i = 1; i < base::size(kURLS); ++i) |
jam | d6be16e | 2014-09-28 15:18:34 | [diff] [blame] | 3321 | CheckURLIsBlocked(browser(), kURLS[i]); |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 3322 | |
| 3323 | // Whitelist some sites of bbb.com. |
| 3324 | base::ListValue whitelist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 3325 | whitelist.AppendString("sub.bbb.com"); |
| 3326 | whitelist.AppendString("bbb.com/policy"); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3327 | policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3328 | POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3329 | UpdateProviderPolicy(policies); |
[email protected] | 307aec7 | 2012-09-18 21:52:44 | [diff] [blame] | 3330 | FlushBlacklistPolicy(); |
jam | d6be16e | 2014-09-28 15:18:34 | [diff] [blame] | 3331 | CheckURLIsBlocked(browser(), kURLS[1]); |
| 3332 | CheckCanOpenURL(browser(), kURLS[2]); |
| 3333 | CheckCanOpenURL(browser(), kURLS[3]); |
mnissler | d9cdcd87 | 2015-05-29 13:57:41 | [diff] [blame] | 3334 | CheckCanOpenURL(browser(), kURLS[4]); |
[email protected] | 38a4db9 | 2012-08-29 09:36:05 | [diff] [blame] | 3335 | } |
| 3336 | |
Doug Turner | b4927e7 | 2018-03-14 17:03:44 | [diff] [blame] | 3337 | IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistIncognito) { |
| 3338 | // Checks that URLs can be blacklisted, and that exceptions can be made to |
| 3339 | // the blacklist. |
| 3340 | |
| 3341 | Browser* incognito_browser = |
| 3342 | OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
| 3343 | |
| 3344 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 3345 | |
| 3346 | const std::string kURLS[] = { |
| 3347 | embedded_test_server()->GetURL("aaa.com", "/empty.html").spec(), |
| 3348 | embedded_test_server()->GetURL("bbb.com", "/empty.html").spec(), |
| 3349 | embedded_test_server()->GetURL("sub.bbb.com", "/empty.html").spec(), |
| 3350 | embedded_test_server()->GetURL("bbb.com", "/policy/blank.html").spec(), |
| 3351 | embedded_test_server()->GetURL("bbb.com.", "/policy/blank.html").spec(), |
| 3352 | }; |
| 3353 | |
| 3354 | // Verify that "bbb.com" opens before applying the blacklist. |
| 3355 | CheckCanOpenURL(incognito_browser, kURLS[1]); |
| 3356 | |
| 3357 | // Set a blacklist. |
| 3358 | base::ListValue blacklist; |
| 3359 | blacklist.AppendString("bbb.com"); |
| 3360 | PolicyMap policies; |
| 3361 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3362 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
| 3363 | UpdateProviderPolicy(policies); |
| 3364 | FlushBlacklistPolicy(); |
| 3365 | // All bbb.com URLs are blocked, and "aaa.com" is still unblocked. |
| 3366 | CheckCanOpenURL(incognito_browser, kURLS[0]); |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 3367 | for (size_t i = 1; i < base::size(kURLS); ++i) |
Doug Turner | b4927e7 | 2018-03-14 17:03:44 | [diff] [blame] | 3368 | CheckURLIsBlocked(incognito_browser, kURLS[i]); |
| 3369 | |
| 3370 | // Whitelist some sites of bbb.com. |
| 3371 | base::ListValue whitelist; |
| 3372 | whitelist.AppendString("sub.bbb.com"); |
| 3373 | whitelist.AppendString("bbb.com/policy"); |
| 3374 | policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3375 | POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr); |
| 3376 | UpdateProviderPolicy(policies); |
| 3377 | FlushBlacklistPolicy(); |
| 3378 | CheckURLIsBlocked(incognito_browser, kURLS[1]); |
| 3379 | CheckCanOpenURL(incognito_browser, kURLS[2]); |
| 3380 | CheckCanOpenURL(incognito_browser, kURLS[3]); |
| 3381 | CheckCanOpenURL(incognito_browser, kURLS[4]); |
| 3382 | } |
| 3383 | |
John Abd-El-Malek | 337a87dc | 2017-08-16 15:06:02 | [diff] [blame] | 3384 | IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistAndWhitelist) { |
| 3385 | // Regression test for http://crbug.com/755256. Blacklisting * and |
| 3386 | // whitelisting an origin should work. |
| 3387 | |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 3388 | ASSERT_TRUE(embedded_test_server()->Start()); |
John Abd-El-Malek | 337a87dc | 2017-08-16 15:06:02 | [diff] [blame] | 3389 | |
| 3390 | base::ListValue blacklist; |
| 3391 | blacklist.AppendString("*"); |
| 3392 | PolicyMap policies; |
| 3393 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3394 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
| 3395 | |
| 3396 | base::ListValue whitelist; |
| 3397 | whitelist.AppendString("aaa.com"); |
| 3398 | policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3399 | POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr); |
| 3400 | UpdateProviderPolicy(policies); |
| 3401 | FlushBlacklistPolicy(); |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 3402 | CheckCanOpenURL( |
| 3403 | browser(), |
| 3404 | embedded_test_server()->GetURL("aaa.com", "/empty.html").spec()); |
John Abd-El-Malek | 337a87dc | 2017-08-16 15:06:02 | [diff] [blame] | 3405 | } |
| 3406 | |
mmenke | fb2ba51 | 2015-06-04 14:00:37 | [diff] [blame] | 3407 | IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistSubresources) { |
| 3408 | // Checks that an image with a blacklisted URL is loaded, but an iframe with a |
| 3409 | // blacklisted URL is not. |
| 3410 | |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 3411 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 3412 | |
tfarina | 5e7b5723 | 2015-10-17 23:37:40 | [diff] [blame] | 3413 | GURL main_url = |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 3414 | embedded_test_server()->GetURL("/policy/blacklist-subresources.html"); |
| 3415 | GURL image_url = embedded_test_server()->GetURL("/policy/pixel.png"); |
| 3416 | GURL subframe_url = embedded_test_server()->GetURL("/policy/blank.html"); |
mmenke | fb2ba51 | 2015-06-04 14:00:37 | [diff] [blame] | 3417 | |
| 3418 | // Set a blacklist containing the image and the iframe which are used by the |
| 3419 | // main document. |
| 3420 | base::ListValue blacklist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 3421 | blacklist.AppendString(image_url.spec().c_str()); |
| 3422 | blacklist.AppendString(subframe_url.spec().c_str()); |
mmenke | fb2ba51 | 2015-06-04 14:00:37 | [diff] [blame] | 3423 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3424 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3425 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
mmenke | fb2ba51 | 2015-06-04 14:00:37 | [diff] [blame] | 3426 | UpdateProviderPolicy(policies); |
| 3427 | FlushBlacklistPolicy(); |
| 3428 | |
| 3429 | std::string blacklisted_image_load_result; |
| 3430 | ui_test_utils::NavigateToURL(browser(), main_url); |
| 3431 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 3432 | browser()->tab_strip_model()->GetActiveWebContents(), |
| 3433 | "window.domAutomationController.send(imageLoadResult)", |
| 3434 | &blacklisted_image_load_result)); |
| 3435 | EXPECT_EQ("success", blacklisted_image_load_result); |
| 3436 | |
| 3437 | std::string blacklisted_iframe_load_result; |
| 3438 | ui_test_utils::NavigateToURL(browser(), main_url); |
| 3439 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 3440 | browser()->tab_strip_model()->GetActiveWebContents(), |
| 3441 | "window.domAutomationController.send(iframeLoadResult)", |
| 3442 | &blacklisted_iframe_load_result)); |
| 3443 | EXPECT_EQ("error", blacklisted_iframe_load_result); |
| 3444 | } |
| 3445 | |
Doug Turner | bbcf5e2 | 2017-12-21 22:43:07 | [diff] [blame] | 3446 | IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistClientRedirect) { |
| 3447 | // Checks that a client side redirect to a blacklisted URL is blocked. |
| 3448 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 3449 | |
| 3450 | GURL redirected_url = |
| 3451 | embedded_test_server()->GetURL("/policy/blacklist-redirect.html"); |
| 3452 | GURL first_url = embedded_test_server()->GetURL("/client-redirect?" + |
| 3453 | redirected_url.spec()); |
| 3454 | |
Doug Turner | 43b5c50 | 2018-02-06 16:30:49 | [diff] [blame] | 3455 | // There are two navigations: one when loading client-redirect.html and |
| 3456 | // another when the document redirects using http-equiv="refresh". |
| 3457 | ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
| 3458 | first_url, 2); |
Doug Turner | bbcf5e2 | 2017-12-21 22:43:07 | [diff] [blame] | 3459 | EXPECT_EQ(base::ASCIIToUTF16("Redirected!"), |
| 3460 | browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 3461 | |
| 3462 | base::ListValue blacklist; |
| 3463 | blacklist.AppendString(redirected_url.spec().c_str()); |
| 3464 | PolicyMap policies; |
| 3465 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3466 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
| 3467 | UpdateProviderPolicy(policies); |
| 3468 | FlushBlacklistPolicy(); |
| 3469 | |
| 3470 | ui_test_utils::NavigateToURL(browser(), first_url); |
| 3471 | content::WaitForLoadStop( |
| 3472 | browser()->tab_strip_model()->GetActiveWebContents()); |
| 3473 | EXPECT_NE(base::ASCIIToUTF16("Redirected!"), |
| 3474 | browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 3475 | } |
| 3476 | |
| 3477 | IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistServerRedirect) { |
| 3478 | // Checks that a server side redirect to a blacklisted URL is blocked. |
| 3479 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 3480 | |
| 3481 | GURL redirected_url = |
| 3482 | embedded_test_server()->GetURL("/policy/blacklist-redirect.html"); |
| 3483 | GURL first_url = embedded_test_server()->GetURL("/server-redirect?" + |
| 3484 | redirected_url.spec()); |
| 3485 | |
| 3486 | ui_test_utils::NavigateToURL(browser(), first_url); |
| 3487 | content::WaitForLoadStop( |
| 3488 | browser()->tab_strip_model()->GetActiveWebContents()); |
| 3489 | EXPECT_EQ(base::ASCIIToUTF16("Redirected!"), |
| 3490 | browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 3491 | |
| 3492 | base::ListValue blacklist; |
| 3493 | blacklist.AppendString(redirected_url.spec().c_str()); |
| 3494 | PolicyMap policies; |
| 3495 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3496 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
| 3497 | UpdateProviderPolicy(policies); |
| 3498 | FlushBlacklistPolicy(); |
| 3499 | |
| 3500 | ui_test_utils::NavigateToURL(browser(), first_url); |
| 3501 | content::WaitForLoadStop( |
| 3502 | browser()->tab_strip_model()->GetActiveWebContents()); |
| 3503 | EXPECT_NE(base::ASCIIToUTF16("Redirected!"), |
| 3504 | browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 3505 | } |
| 3506 | |
jam | d6be16e | 2014-09-28 15:18:34 | [diff] [blame] | 3507 | #if defined(OS_MACOSX) |
| 3508 | // http://crbug.com/339240 |
| 3509 | #define MAYBE_FileURLBlacklist DISABLED_FileURLBlacklist |
| 3510 | #else |
| 3511 | #define MAYBE_FileURLBlacklist FileURLBlacklist |
| 3512 | #endif |
| 3513 | IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_FileURLBlacklist) { |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3514 | // Check that FileURLs can be blacklisted and DisabledSchemes works together |
| 3515 | // with URLblacklisting and URLwhitelisting. |
| 3516 | |
| 3517 | base::FilePath test_path; |
Jun Cai | aa24869 | 2017-11-10 20:10:51 | [diff] [blame] | 3518 | GetTestDataDirectory(&test_path); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3519 | const std::string base_path = "file://" + test_path.AsUTF8Unsafe() +"/"; |
| 3520 | const std::string folder_path = base_path + "apptest/"; |
| 3521 | const std::string file_path1 = base_path + "title1.html"; |
| 3522 | const std::string file_path2 = folder_path + "basic.html"; |
| 3523 | |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 3524 | CheckCanOpenURL(browser(), file_path1); |
| 3525 | CheckCanOpenURL(browser(), file_path2); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3526 | |
| 3527 | // Set a blacklist for all the files. |
| 3528 | base::ListValue blacklist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 3529 | blacklist.AppendString("file://*"); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3530 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3531 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3532 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3533 | UpdateProviderPolicy(policies); |
| 3534 | FlushBlacklistPolicy(); |
| 3535 | |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 3536 | CheckURLIsBlocked(browser(), file_path1); |
| 3537 | CheckURLIsBlocked(browser(), file_path2); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3538 | |
| 3539 | // Replace the URLblacklist with disabling the file scheme. |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 3540 | blacklist.Remove(base::Value("file://*"), NULL); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3541 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3542 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3543 | UpdateProviderPolicy(policies); |
| 3544 | FlushBlacklistPolicy(); |
| 3545 | |
| 3546 | PrefService* prefs = browser()->profile()->GetPrefs(); |
[email protected] | 425e337 | 2013-12-17 09:35:43 | [diff] [blame] | 3547 | const base::ListValue* list_url = prefs->GetList(policy_prefs::kUrlBlacklist); |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 3548 | EXPECT_EQ(list_url->Find(base::Value("file://*")), list_url->end()); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3549 | |
| 3550 | base::ListValue disabledscheme; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 3551 | disabledscheme.AppendString("file"); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3552 | policies.Set(key::kDisabledSchemes, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3553 | POLICY_SOURCE_CLOUD, disabledscheme.CreateDeepCopy(), nullptr); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3554 | UpdateProviderPolicy(policies); |
| 3555 | FlushBlacklistPolicy(); |
| 3556 | |
[email protected] | 425e337 | 2013-12-17 09:35:43 | [diff] [blame] | 3557 | list_url = prefs->GetList(policy_prefs::kUrlBlacklist); |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 3558 | EXPECT_NE(list_url->Find(base::Value("file://*")), list_url->end()); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3559 | |
| 3560 | // Whitelist one folder and blacklist an another just inside. |
| 3561 | base::ListValue whitelist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 3562 | whitelist.AppendString(base_path); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3563 | policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3564 | POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr); |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 3565 | blacklist.AppendString(folder_path); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3566 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 3567 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3568 | UpdateProviderPolicy(policies); |
| 3569 | FlushBlacklistPolicy(); |
| 3570 | |
Yuzhu Shen | 6ccfd56 | 2017-10-27 16:38:18 | [diff] [blame] | 3571 | CheckCanOpenURL(browser(), file_path1); |
| 3572 | CheckURLIsBlocked(browser(), file_path2); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3573 | } |
| 3574 | |
Thomas Tangl | 6703fceb | 2018-07-18 15:54:25 | [diff] [blame] | 3575 | IN_PROC_BROWSER_TEST_F(PolicyTest, UrlKeyedAnonymizedDataCollection) { |
| 3576 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 3577 | prefs->SetBoolean( |
| 3578 | unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled, true); |
| 3579 | EXPECT_TRUE(prefs->GetBoolean( |
| 3580 | unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled)); |
| 3581 | |
| 3582 | // Disable by policy. |
| 3583 | PolicyMap policies; |
| 3584 | policies.Set(key::kUrlKeyedAnonymizedDataCollectionEnabled, |
| 3585 | POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 3586 | std::make_unique<base::Value>(false), nullptr); |
| 3587 | UpdateProviderPolicy(policies); |
| 3588 | |
| 3589 | EXPECT_FALSE(prefs->GetBoolean( |
| 3590 | unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled)); |
| 3591 | } |
| 3592 | |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 3593 | #if !defined(OS_MACOSX) |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 3594 | IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedBrowser) { |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 3595 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3596 | policies.Set(key::kFullscreenAllowed, POLICY_LEVEL_MANDATORY, |
| 3597 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3598 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 3599 | UpdateProviderPolicy(policies); |
| 3600 | |
| 3601 | BrowserWindow* browser_window = browser()->window(); |
| 3602 | ASSERT_TRUE(browser_window); |
| 3603 | |
| 3604 | EXPECT_FALSE(browser_window->IsFullscreen()); |
| 3605 | chrome::ToggleFullscreenMode(browser()); |
| 3606 | EXPECT_FALSE(browser_window->IsFullscreen()); |
| 3607 | } |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 3608 | |
| 3609 | IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedApp) { |
| 3610 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3611 | policies.Set(key::kFullscreenAllowed, POLICY_LEVEL_MANDATORY, |
| 3612 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3613 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 3614 | UpdateProviderPolicy(policies); |
| 3615 | |
limasdf | c83e0b7 | 2017-03-03 17:08:35 | [diff] [blame] | 3616 | scoped_refptr<const extensions::Extension> extension = |
| 3617 | LoadUnpackedExtension(kUnpackedFullscreenAppName); |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 3618 | ASSERT_TRUE(extension); |
| 3619 | |
| 3620 | // Launch an app that tries to open a fullscreen window. |
[email protected] | dbb03fb | 2014-02-15 05:36:33 | [diff] [blame] | 3621 | TestAddAppWindowObserver add_window_observer( |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 3622 | extensions::AppWindowRegistry::Get(browser()->profile())); |
Eric Willigers | 618e130 | 2019-06-23 23:03:47 | [diff] [blame] | 3623 | OpenApplication( |
| 3624 | AppLaunchParams(browser()->profile(), extension->id(), |
| 3625 | extensions::LaunchContainer::kLaunchContainerNone, |
| 3626 | WindowOpenDisposition::NEW_WINDOW, |
| 3627 | extensions::AppLaunchSource::kSourceTest)); |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 3628 | extensions::AppWindow* window = add_window_observer.WaitForAppWindow(); |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 3629 | ASSERT_TRUE(window); |
| 3630 | |
| 3631 | // Verify that the window is not in fullscreen mode. |
| 3632 | EXPECT_FALSE(window->GetBaseWindow()->IsFullscreen()); |
| 3633 | |
jam | 2637dd1 | 2016-09-23 16:39:18 | [diff] [blame] | 3634 | // For PlzNavigate case, we have to wait for the navigation to commit since |
| 3635 | // the JS object registration is delayed (see |
| 3636 | // AppWindowCreateFunction::RunAsync). |
| 3637 | content::WaitForLoadStop(window->web_contents()); |
| 3638 | |
[email protected] | 369d5a5 | 2013-09-18 10:09:53 | [diff] [blame] | 3639 | // Verify that the window cannot be toggled into fullscreen mode via apps |
| 3640 | // APIs. |
| 3641 | EXPECT_TRUE(content::ExecuteScript( |
| 3642 | window->web_contents(), |
| 3643 | "chrome.app.window.current().fullscreen();")); |
| 3644 | EXPECT_FALSE(window->GetBaseWindow()->IsFullscreen()); |
| 3645 | |
| 3646 | // Verify that the window cannot be toggled into fullscreen mode from within |
| 3647 | // Chrome (e.g., using keyboard accelerators). |
| 3648 | window->Fullscreen(); |
| 3649 | EXPECT_FALSE(window->GetBaseWindow()->IsFullscreen()); |
| 3650 | } |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 3651 | #endif |
| 3652 | |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 3653 | #if defined(OS_CHROMEOS) |
earthdok | 9f1ec6f | 2015-04-14 19:55:43 | [diff] [blame] | 3654 | |
kjellander | d2c0774 | 2016-09-12 07:59:57 | [diff] [blame] | 3655 | // Flaky on MSan (crbug.com/476964) and regular Chrome OS (crbug.com/645769). |
| 3656 | IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_DisableScreenshotsFile) { |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 3657 | int screenshot_count = CountScreenshots(); |
| 3658 | |
| 3659 | // Make sure screenshots are counted correctly. |
| 3660 | TestScreenshotFile(true); |
| 3661 | ASSERT_EQ(CountScreenshots(), screenshot_count + 1); |
| 3662 | |
| 3663 | // Check if trying to take a screenshot fails when disabled by policy. |
| 3664 | TestScreenshotFile(false); |
| 3665 | ASSERT_EQ(CountScreenshots(), screenshot_count + 1); |
| 3666 | } |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 3667 | |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 3668 | IN_PROC_BROWSER_TEST_F(PolicyTest, DisableAudioOutput) { |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 3669 | // Set up the mock observer. |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 3670 | chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); |
dcheng | 08cfe9ba | 2016-04-14 17:46:45 | [diff] [blame] | 3671 | std::unique_ptr<TestAudioObserver> test_observer(new TestAudioObserver); |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 3672 | audio_handler->AddAudioObserver(test_observer.get()); |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 3673 | |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 3674 | bool prior_state = audio_handler->IsOutputMuted(); |
| 3675 | // Make sure the audio is not muted and then toggle the policy and observe |
| 3676 | // if the output mute changed event is fired. |
| 3677 | audio_handler->SetOutputMute(false); |
| 3678 | EXPECT_FALSE(audio_handler->IsOutputMuted()); |
| 3679 | EXPECT_EQ(1, test_observer->output_mute_changed_count()); |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 3680 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3681 | policies.Set(key::kAudioOutputAllowed, POLICY_LEVEL_MANDATORY, |
| 3682 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3683 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3684 | UpdateProviderPolicy(policies); |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 3685 | EXPECT_TRUE(audio_handler->IsOutputMuted()); |
| 3686 | // This should not change the state now and should not trigger output mute |
| 3687 | // changed event. |
| 3688 | audio_handler->SetOutputMute(false); |
| 3689 | EXPECT_TRUE(audio_handler->IsOutputMuted()); |
| 3690 | EXPECT_EQ(1, test_observer->output_mute_changed_count()); |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 3691 | |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 3692 | // Toggle back and observe if the output mute changed event is fired. |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3693 | policies.Set(key::kAudioOutputAllowed, POLICY_LEVEL_MANDATORY, |
| 3694 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3695 | std::make_unique<base::Value>(true), nullptr); |
[email protected] | 161245d | 2013-01-09 14:28:11 | [diff] [blame] | 3696 | UpdateProviderPolicy(policies); |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 3697 | EXPECT_FALSE(audio_handler->IsOutputMuted()); |
| 3698 | EXPECT_EQ(1, test_observer->output_mute_changed_count()); |
| 3699 | audio_handler->SetOutputMute(true); |
| 3700 | EXPECT_TRUE(audio_handler->IsOutputMuted()); |
| 3701 | EXPECT_EQ(2, test_observer->output_mute_changed_count()); |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 3702 | // Revert the prior state. |
[email protected] | 934e3c9 | 2013-08-01 00:18:23 | [diff] [blame] | 3703 | audio_handler->SetOutputMute(prior_state); |
| 3704 | audio_handler->RemoveAudioObserver(test_observer.get()); |
[email protected] | 6af5e30 | 2012-09-20 19:29:09 | [diff] [blame] | 3705 | } |
[email protected] | 9a8764b | 2013-03-27 16:18:09 | [diff] [blame] | 3706 | |
achuith | af1ca27 | 2015-10-29 22:53:21 | [diff] [blame] | 3707 | IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_SessionLengthLimit) { |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 3708 | // Indicate that the session started 2 hours ago and no user activity has |
| 3709 | // occurred yet. |
[email protected] | 9a8764b | 2013-03-27 16:18:09 | [diff] [blame] | 3710 | g_browser_process->local_state()->SetInt64( |
| 3711 | prefs::kSessionStartTime, |
| 3712 | (base::TimeTicks::Now() - base::TimeDelta::FromHours(2)) |
| 3713 | .ToInternalValue()); |
| 3714 | } |
| 3715 | |
achuith | af1ca27 | 2015-10-29 22:53:21 | [diff] [blame] | 3716 | IN_PROC_BROWSER_TEST_F(PolicyTest, SessionLengthLimit) { |
[email protected] | 9a8764b | 2013-03-27 16:18:09 | [diff] [blame] | 3717 | content::MockNotificationObserver observer; |
| 3718 | content::NotificationRegistrar registrar; |
| 3719 | registrar.Add(&observer, |
| 3720 | chrome::NOTIFICATION_APP_TERMINATING, |
| 3721 | content::NotificationService::AllSources()); |
| 3722 | |
| 3723 | // Set the session length limit to 3 hours. Verify that the session is not |
| 3724 | // terminated. |
| 3725 | EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)) |
| 3726 | .Times(0); |
| 3727 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3728 | policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY, |
| 3729 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3730 | std::make_unique<base::Value>(kThreeHoursInMs), nullptr); |
[email protected] | 9a8764b | 2013-03-27 16:18:09 | [diff] [blame] | 3731 | UpdateProviderPolicy(policies); |
| 3732 | base::RunLoop().RunUntilIdle(); |
| 3733 | Mock::VerifyAndClearExpectations(&observer); |
| 3734 | |
| 3735 | // Decrease the session length limit to 1 hour. Verify that the session is |
| 3736 | // terminated immediately. |
| 3737 | EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3738 | policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY, |
| 3739 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3740 | std::make_unique<base::Value>(kOneHourInMs), nullptr); |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 3741 | UpdateProviderPolicy(policies); |
| 3742 | base::RunLoop().RunUntilIdle(); |
| 3743 | Mock::VerifyAndClearExpectations(&observer); |
| 3744 | } |
| 3745 | |
achuith | 171b061 | 2015-11-17 18:44:52 | [diff] [blame] | 3746 | // Disabled, see http://crbug.com/554728. |
[email protected] | 69c0c686 | 2013-11-05 23:30:23 | [diff] [blame] | 3747 | IN_PROC_BROWSER_TEST_F(PolicyTest, |
achuith | 171b061 | 2015-11-17 18:44:52 | [diff] [blame] | 3748 | DISABLED_PRE_WaitForInitialUserActivityUnsatisfied) { |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 3749 | // Indicate that the session started 2 hours ago and no user activity has |
| 3750 | // occurred yet. |
| 3751 | g_browser_process->local_state()->SetInt64( |
| 3752 | prefs::kSessionStartTime, |
| 3753 | (base::TimeTicks::Now() - base::TimeDelta::FromHours(2)) |
| 3754 | .ToInternalValue()); |
| 3755 | } |
| 3756 | |
achuith | 171b061 | 2015-11-17 18:44:52 | [diff] [blame] | 3757 | // Disabled, see http://crbug.com/554728. |
[email protected] | 69c0c686 | 2013-11-05 23:30:23 | [diff] [blame] | 3758 | IN_PROC_BROWSER_TEST_F(PolicyTest, |
achuith | 171b061 | 2015-11-17 18:44:52 | [diff] [blame] | 3759 | DISABLED_WaitForInitialUserActivityUnsatisfied) { |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 3760 | content::MockNotificationObserver observer; |
| 3761 | content::NotificationRegistrar registrar; |
| 3762 | registrar.Add(&observer, |
| 3763 | chrome::NOTIFICATION_APP_TERMINATING, |
| 3764 | content::NotificationService::AllSources()); |
| 3765 | |
| 3766 | // Require initial user activity. |
| 3767 | PolicyMap policies; |
| 3768 | policies.Set(key::kWaitForInitialUserActivity, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3769 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 3770 | base::WrapUnique(new base::Value(true)), nullptr); |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 3771 | UpdateProviderPolicy(policies); |
| 3772 | base::RunLoop().RunUntilIdle(); |
| 3773 | |
| 3774 | // Set the session length limit to 1 hour. Verify that the session is not |
| 3775 | // terminated. |
| 3776 | EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)) |
| 3777 | .Times(0); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3778 | policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY, |
| 3779 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 3780 | base::WrapUnique(new base::Value(kOneHourInMs)), nullptr); |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 3781 | UpdateProviderPolicy(policies); |
| 3782 | base::RunLoop().RunUntilIdle(); |
| 3783 | Mock::VerifyAndClearExpectations(&observer); |
| 3784 | } |
| 3785 | |
[email protected] | 69c0c686 | 2013-11-05 23:30:23 | [diff] [blame] | 3786 | IN_PROC_BROWSER_TEST_F(PolicyTest, |
achuith | 0404e01 | 2015-10-29 22:58:33 | [diff] [blame] | 3787 | PRE_WaitForInitialUserActivitySatisfied) { |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 3788 | // Indicate that initial user activity in this session occurred 2 hours ago. |
| 3789 | g_browser_process->local_state()->SetInt64( |
| 3790 | prefs::kSessionStartTime, |
| 3791 | (base::TimeTicks::Now() - base::TimeDelta::FromHours(2)) |
| 3792 | .ToInternalValue()); |
| 3793 | g_browser_process->local_state()->SetBoolean( |
| 3794 | prefs::kSessionUserActivitySeen, |
| 3795 | true); |
| 3796 | } |
| 3797 | |
[email protected] | 69c0c686 | 2013-11-05 23:30:23 | [diff] [blame] | 3798 | IN_PROC_BROWSER_TEST_F(PolicyTest, |
achuith | 0404e01 | 2015-10-29 22:58:33 | [diff] [blame] | 3799 | WaitForInitialUserActivitySatisfied) { |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 3800 | content::MockNotificationObserver observer; |
| 3801 | content::NotificationRegistrar registrar; |
| 3802 | registrar.Add(&observer, |
| 3803 | chrome::NOTIFICATION_APP_TERMINATING, |
| 3804 | content::NotificationService::AllSources()); |
| 3805 | |
| 3806 | // Require initial user activity and set the session length limit to 3 hours. |
| 3807 | // Verify that the session is not terminated. |
| 3808 | EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)) |
| 3809 | .Times(0); |
| 3810 | PolicyMap policies; |
| 3811 | policies.Set(key::kWaitForInitialUserActivity, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3812 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3813 | std::make_unique<base::Value>(true), nullptr); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3814 | policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY, |
| 3815 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3816 | std::make_unique<base::Value>(kThreeHoursInMs), nullptr); |
[email protected] | 8e0ba06b | 2013-10-28 15:38:09 | [diff] [blame] | 3817 | UpdateProviderPolicy(policies); |
| 3818 | base::RunLoop().RunUntilIdle(); |
| 3819 | Mock::VerifyAndClearExpectations(&observer); |
| 3820 | |
| 3821 | // Decrease the session length limit to 1 hour. Verify that the session is |
| 3822 | // terminated immediately. |
| 3823 | EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3824 | policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY, |
| 3825 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3826 | std::make_unique<base::Value>(kOneHourInMs), nullptr); |
[email protected] | 9a8764b | 2013-03-27 16:18:09 | [diff] [blame] | 3827 | UpdateProviderPolicy(policies); |
| 3828 | base::RunLoop().RunUntilIdle(); |
| 3829 | Mock::VerifyAndClearExpectations(&observer); |
| 3830 | } |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3831 | |
| 3832 | IN_PROC_BROWSER_TEST_F(PolicyTest, LargeCursorEnabled) { |
| 3833 | // Verifies that the large cursor accessibility feature can be controlled |
| 3834 | // through policy. |
| 3835 | chromeos::AccessibilityManager* accessibility_manager = |
| 3836 | chromeos::AccessibilityManager::Get(); |
| 3837 | |
| 3838 | // Manually enable the large cursor. |
| 3839 | accessibility_manager->EnableLargeCursor(true); |
| 3840 | EXPECT_TRUE(accessibility_manager->IsLargeCursorEnabled()); |
| 3841 | |
| 3842 | // Verify that policy overrides the manual setting. |
| 3843 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3844 | policies.Set(key::kLargeCursorEnabled, POLICY_LEVEL_MANDATORY, |
| 3845 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3846 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3847 | UpdateProviderPolicy(policies); |
| 3848 | EXPECT_FALSE(accessibility_manager->IsLargeCursorEnabled()); |
| 3849 | |
| 3850 | // Verify that the large cursor cannot be enabled manually anymore. |
| 3851 | accessibility_manager->EnableLargeCursor(true); |
| 3852 | EXPECT_FALSE(accessibility_manager->IsLargeCursorEnabled()); |
| 3853 | } |
| 3854 | |
| 3855 | IN_PROC_BROWSER_TEST_F(PolicyTest, SpokenFeedbackEnabled) { |
| 3856 | // Verifies that the spoken feedback accessibility feature can be controlled |
| 3857 | // through policy. |
| 3858 | chromeos::AccessibilityManager* accessibility_manager = |
| 3859 | chromeos::AccessibilityManager::Get(); |
| 3860 | |
| 3861 | // Manually enable spoken feedback. |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 3862 | accessibility_manager->EnableSpokenFeedback(true); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3863 | EXPECT_TRUE(accessibility_manager->IsSpokenFeedbackEnabled()); |
| 3864 | |
| 3865 | // Verify that policy overrides the manual setting. |
| 3866 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3867 | policies.Set(key::kSpokenFeedbackEnabled, POLICY_LEVEL_MANDATORY, |
| 3868 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3869 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3870 | UpdateProviderPolicy(policies); |
| 3871 | EXPECT_FALSE(accessibility_manager->IsSpokenFeedbackEnabled()); |
| 3872 | |
| 3873 | // Verify that spoken feedback cannot be enabled manually anymore. |
Qiang Xu | 60e7903 | 2018-03-29 08:18:31 | [diff] [blame] | 3874 | accessibility_manager->EnableSpokenFeedback(true); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3875 | EXPECT_FALSE(accessibility_manager->IsSpokenFeedbackEnabled()); |
| 3876 | } |
| 3877 | |
| 3878 | IN_PROC_BROWSER_TEST_F(PolicyTest, HighContrastEnabled) { |
| 3879 | // Verifies that the high contrast mode accessibility feature can be |
| 3880 | // controlled through policy. |
| 3881 | chromeos::AccessibilityManager* accessibility_manager = |
| 3882 | chromeos::AccessibilityManager::Get(); |
| 3883 | |
| 3884 | // Manually enable high contrast mode. |
| 3885 | accessibility_manager->EnableHighContrast(true); |
| 3886 | EXPECT_TRUE(accessibility_manager->IsHighContrastEnabled()); |
| 3887 | |
| 3888 | // Verify that policy overrides the manual setting. |
| 3889 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3890 | policies.Set(key::kHighContrastEnabled, POLICY_LEVEL_MANDATORY, |
| 3891 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3892 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3893 | UpdateProviderPolicy(policies); |
| 3894 | EXPECT_FALSE(accessibility_manager->IsHighContrastEnabled()); |
| 3895 | |
| 3896 | // Verify that high contrast mode cannot be enabled manually anymore. |
| 3897 | accessibility_manager->EnableHighContrast(true); |
| 3898 | EXPECT_FALSE(accessibility_manager->IsHighContrastEnabled()); |
| 3899 | } |
| 3900 | |
| 3901 | IN_PROC_BROWSER_TEST_F(PolicyTest, ScreenMagnifierTypeNone) { |
| 3902 | // Verifies that the screen magnifier can be disabled through policy. |
| 3903 | chromeos::MagnificationManager* magnification_manager = |
| 3904 | chromeos::MagnificationManager::Get(); |
| 3905 | |
| 3906 | // Manually enable the full-screen magnifier. |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3907 | magnification_manager->SetMagnifierEnabled(true); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3908 | EXPECT_TRUE(magnification_manager->IsMagnifierEnabled()); |
| 3909 | |
| 3910 | // Verify that policy overrides the manual setting. |
| 3911 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3912 | policies.Set(key::kScreenMagnifierType, POLICY_LEVEL_MANDATORY, |
| 3913 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3914 | std::make_unique<base::Value>(0), nullptr); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3915 | UpdateProviderPolicy(policies); |
| 3916 | EXPECT_FALSE(magnification_manager->IsMagnifierEnabled()); |
| 3917 | |
| 3918 | // Verify that the screen magnifier cannot be enabled manually anymore. |
| 3919 | magnification_manager->SetMagnifierEnabled(true); |
| 3920 | EXPECT_FALSE(magnification_manager->IsMagnifierEnabled()); |
Anatoliy Potapchuk | 4b03b470 | 2019-06-07 10:35:13 | [diff] [blame] | 3921 | // Verify that the docked magnifier cannot be enabled manually anymore. |
| 3922 | magnification_manager->SetDockedMagnifierEnabled(true); |
| 3923 | EXPECT_FALSE(magnification_manager->IsDockedMagnifierEnabled()); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | IN_PROC_BROWSER_TEST_F(PolicyTest, ScreenMagnifierTypeFull) { |
| 3927 | // Verifies that the full-screen magnifier can be enabled through policy. |
| 3928 | chromeos::MagnificationManager* magnification_manager = |
| 3929 | chromeos::MagnificationManager::Get(); |
| 3930 | |
| 3931 | // Verify that the screen magnifier is initially disabled. |
| 3932 | EXPECT_FALSE(magnification_manager->IsMagnifierEnabled()); |
| 3933 | |
| 3934 | // Verify that policy can enable the full-screen magnifier. |
| 3935 | PolicyMap policies; |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 3936 | policies.Set(key::kScreenMagnifierType, POLICY_LEVEL_MANDATORY, |
| 3937 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Qiang Xu | 92eabd4 | 2018-06-27 16:20:05 | [diff] [blame] | 3938 | std::make_unique<base::Value>(chromeos::MAGNIFIER_FULL), |
| 3939 | nullptr); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3940 | UpdateProviderPolicy(policies); |
[email protected] | 2968e4f745 | 2013-06-10 17:39:07 | [diff] [blame] | 3941 | EXPECT_TRUE(magnification_manager->IsMagnifierEnabled()); |
| 3942 | |
| 3943 | // Verify that the screen magnifier cannot be disabled manually anymore. |
| 3944 | magnification_manager->SetMagnifierEnabled(false); |
| 3945 | EXPECT_TRUE(magnification_manager->IsMagnifierEnabled()); |
| 3946 | } |
| 3947 | |
Anatoliy Potapchuk | 4b03b470 | 2019-06-07 10:35:13 | [diff] [blame] | 3948 | IN_PROC_BROWSER_TEST_F(PolicyTest, ScreenMagnifierTypeDocked) { |
| 3949 | // Verifies that the docked magnifier accessibility feature can be |
| 3950 | // controlled through policy. |
| 3951 | chromeos::MagnificationManager* magnification_manager = |
| 3952 | chromeos::MagnificationManager::Get(); |
| 3953 | |
| 3954 | // Verify that the docked magnifier is initially disabled |
| 3955 | EXPECT_FALSE(magnification_manager->IsDockedMagnifierEnabled()); |
| 3956 | |
| 3957 | // Verify that policy overrides the manual setting. |
| 3958 | PolicyMap policies; |
| 3959 | policies.Set(key::kScreenMagnifierType, POLICY_LEVEL_MANDATORY, |
| 3960 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 3961 | std::make_unique<base::Value>(chromeos::MAGNIFIER_DOCKED), |
| 3962 | nullptr); |
| 3963 | UpdateProviderPolicy(policies); |
| 3964 | EXPECT_TRUE(magnification_manager->IsDockedMagnifierEnabled()); |
| 3965 | |
| 3966 | // Verify that the docked magnifier cannot be disabled manually anymore. |
| 3967 | magnification_manager->SetDockedMagnifierEnabled(false); |
| 3968 | EXPECT_TRUE(magnification_manager->IsDockedMagnifierEnabled()); |
| 3969 | } |
| 3970 | |
[email protected] | 7a22697 | 2014-06-19 11:12:43 | [diff] [blame] | 3971 | IN_PROC_BROWSER_TEST_F(PolicyTest, AccessibilityVirtualKeyboardEnabled) { |
[email protected] | 43ceb5a | 2014-02-14 16:40:07 | [diff] [blame] | 3972 | // Verifies that the on-screen keyboard accessibility feature can be |
| 3973 | // controlled through policy. |
| 3974 | chromeos::AccessibilityManager* accessibility_manager = |
| 3975 | chromeos::AccessibilityManager::Get(); |
| 3976 | |
| 3977 | // Manually enable the on-screen keyboard. |
| 3978 | accessibility_manager->EnableVirtualKeyboard(true); |
| 3979 | EXPECT_TRUE(accessibility_manager->IsVirtualKeyboardEnabled()); |
| 3980 | |
| 3981 | // Verify that policy overrides the manual setting. |
| 3982 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 3983 | policies.Set(key::kVirtualKeyboardEnabled, POLICY_LEVEL_MANDATORY, |
| 3984 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 3985 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 43ceb5a | 2014-02-14 16:40:07 | [diff] [blame] | 3986 | UpdateProviderPolicy(policies); |
| 3987 | EXPECT_FALSE(accessibility_manager->IsVirtualKeyboardEnabled()); |
| 3988 | |
| 3989 | // Verify that the on-screen keyboard cannot be enabled manually anymore. |
| 3990 | accessibility_manager->EnableVirtualKeyboard(true); |
| 3991 | EXPECT_FALSE(accessibility_manager->IsVirtualKeyboardEnabled()); |
| 3992 | } |
| 3993 | |
Amr Aboelkher | baf15984 | 2019-04-29 15:57:04 | [diff] [blame] | 3994 | IN_PROC_BROWSER_TEST_F(PolicyTest, StickyKeysEnabled) { |
| 3995 | // Verifies that the sticky keys accessibility feature can be |
| 3996 | // controlled through policy. |
| 3997 | chromeos::AccessibilityManager* accessibility_manager = |
| 3998 | chromeos::AccessibilityManager::Get(); |
| 3999 | |
| 4000 | // Verify that the sticky keys is initially disabled |
| 4001 | EXPECT_FALSE(accessibility_manager->IsStickyKeysEnabled()); |
| 4002 | |
| 4003 | // Manually enable the sticky keys. |
| 4004 | accessibility_manager->EnableStickyKeys(true); |
| 4005 | EXPECT_TRUE(accessibility_manager->IsStickyKeysEnabled()); |
| 4006 | |
| 4007 | // Verify that policy overrides the manual setting. |
| 4008 | PolicyMap policies; |
| 4009 | policies.Set(key::kStickyKeysEnabled, POLICY_LEVEL_MANDATORY, |
| 4010 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4011 | std::make_unique<base::Value>(false), nullptr); |
| 4012 | UpdateProviderPolicy(policies); |
| 4013 | EXPECT_FALSE(accessibility_manager->IsStickyKeysEnabled()); |
| 4014 | |
| 4015 | // Verify that the sticky keys cannot be enabled manually anymore. |
| 4016 | accessibility_manager->EnableStickyKeys(true); |
| 4017 | EXPECT_FALSE(accessibility_manager->IsStickyKeysEnabled()); |
| 4018 | } |
| 4019 | |
Amr Aboelkher | e623033 | 2019-05-02 13:05:50 | [diff] [blame] | 4020 | |
[email protected] | 7a22697 | 2014-06-19 11:12:43 | [diff] [blame] | 4021 | IN_PROC_BROWSER_TEST_F(PolicyTest, VirtualKeyboardEnabled) { |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 4022 | auto* keyboard_client = ChromeKeyboardControllerClient::Get(); |
| 4023 | ASSERT_TRUE(keyboard_client); |
| 4024 | |
[email protected] | 7a22697 | 2014-06-19 11:12:43 | [diff] [blame] | 4025 | // Verify keyboard disabled by default. |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 4026 | EXPECT_FALSE(keyboard_client->is_keyboard_enabled()); |
| 4027 | |
[email protected] | 7a22697 | 2014-06-19 11:12:43 | [diff] [blame] | 4028 | // Verify keyboard can be toggled by default. |
Darren Shen | 8604a21 | 2019-06-07 00:41:38 | [diff] [blame] | 4029 | SetEnableFlag(keyboard::KeyboardEnableFlag::kTouchEnabled); |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 4030 | EXPECT_TRUE(keyboard_client->is_keyboard_enabled()); |
Darren Shen | 8604a21 | 2019-06-07 00:41:38 | [diff] [blame] | 4031 | ClearEnableFlag(keyboard::KeyboardEnableFlag::kTouchEnabled); |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 4032 | EXPECT_FALSE(keyboard_client->is_keyboard_enabled()); |
[email protected] | 7a22697 | 2014-06-19 11:12:43 | [diff] [blame] | 4033 | |
| 4034 | // Verify enabling the policy takes effect immediately and that that user |
| 4035 | // cannot disable the keyboard.. |
| 4036 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 4037 | policies.Set(key::kTouchVirtualKeyboardEnabled, POLICY_LEVEL_MANDATORY, |
| 4038 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 4039 | std::make_unique<base::Value>(true), nullptr); |
[email protected] | 7a22697 | 2014-06-19 11:12:43 | [diff] [blame] | 4040 | UpdateProviderPolicy(policies); |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 4041 | EXPECT_TRUE(keyboard_client->is_keyboard_enabled()); |
Darren Shen | 8604a21 | 2019-06-07 00:41:38 | [diff] [blame] | 4042 | ClearEnableFlag(keyboard::KeyboardEnableFlag::kTouchEnabled); |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 4043 | EXPECT_TRUE(keyboard_client->is_keyboard_enabled()); |
[email protected] | 7a22697 | 2014-06-19 11:12:43 | [diff] [blame] | 4044 | |
| 4045 | // Verify that disabling the policy takes effect immediately and that the user |
| 4046 | // cannot enable the keyboard. |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 4047 | policies.Set(key::kTouchVirtualKeyboardEnabled, POLICY_LEVEL_MANDATORY, |
| 4048 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 4049 | std::make_unique<base::Value>(false), nullptr); |
[email protected] | 7a22697 | 2014-06-19 11:12:43 | [diff] [blame] | 4050 | UpdateProviderPolicy(policies); |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 4051 | EXPECT_FALSE(keyboard_client->is_keyboard_enabled()); |
Darren Shen | 8604a21 | 2019-06-07 00:41:38 | [diff] [blame] | 4052 | SetEnableFlag(keyboard::KeyboardEnableFlag::kTouchEnabled); |
Steven Bennetts | 34692a33 | 2018-11-10 02:11:44 | [diff] [blame] | 4053 | EXPECT_FALSE(keyboard_client->is_keyboard_enabled()); |
[email protected] | 7a22697 | 2014-06-19 11:12:43 | [diff] [blame] | 4054 | } |
| 4055 | |
Yue Li | 74df9de | 2019-05-16 00:03:46 | [diff] [blame] | 4056 | IN_PROC_BROWSER_TEST_F(PolicyTest, AssistantContextEnabled) { |
| 4057 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 4058 | EXPECT_FALSE( |
| 4059 | prefs->IsManagedPreference(arc::prefs::kVoiceInteractionContextEnabled)); |
| 4060 | EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled)); |
| 4061 | prefs->SetBoolean(arc::prefs::kVoiceInteractionContextEnabled, true); |
| 4062 | EXPECT_TRUE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled)); |
| 4063 | |
| 4064 | // Verifies that the Assistant context can be forced to always disabled. |
| 4065 | PolicyMap policies; |
| 4066 | policies.Set(key::kVoiceInteractionContextEnabled, POLICY_LEVEL_MANDATORY, |
| 4067 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4068 | std::make_unique<base::Value>(false), nullptr); |
| 4069 | UpdateProviderPolicy(policies); |
| 4070 | EXPECT_TRUE( |
| 4071 | prefs->IsManagedPreference(arc::prefs::kVoiceInteractionContextEnabled)); |
| 4072 | EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled)); |
| 4073 | prefs->SetBoolean(arc::prefs::kVoiceInteractionContextEnabled, true); |
| 4074 | EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled)); |
| 4075 | |
| 4076 | // Verifies that the Assistant context can be forced to always enabled. |
| 4077 | policies.Set(key::kVoiceInteractionContextEnabled, POLICY_LEVEL_MANDATORY, |
| 4078 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4079 | std::make_unique<base::Value>(true), nullptr); |
| 4080 | UpdateProviderPolicy(policies); |
| 4081 | EXPECT_TRUE( |
| 4082 | prefs->IsManagedPreference(arc::prefs::kVoiceInteractionContextEnabled)); |
| 4083 | EXPECT_TRUE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled)); |
| 4084 | prefs->SetBoolean(arc::prefs::kVoiceInteractionContextEnabled, false); |
| 4085 | EXPECT_TRUE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled)); |
| 4086 | } |
| 4087 | |
| 4088 | IN_PROC_BROWSER_TEST_F(PolicyTest, AssistantHotwordEnabled) { |
| 4089 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 4090 | EXPECT_FALSE( |
| 4091 | prefs->IsManagedPreference(arc::prefs::kVoiceInteractionHotwordEnabled)); |
| 4092 | EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled)); |
| 4093 | prefs->SetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled, true); |
| 4094 | EXPECT_TRUE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled)); |
| 4095 | |
| 4096 | // Verifies that the Assistant hotword can be forced to always disabled. |
| 4097 | PolicyMap policies; |
| 4098 | policies.Set(key::kVoiceInteractionHotwordEnabled, POLICY_LEVEL_MANDATORY, |
| 4099 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4100 | std::make_unique<base::Value>(false), nullptr); |
| 4101 | UpdateProviderPolicy(policies); |
| 4102 | EXPECT_TRUE( |
| 4103 | prefs->IsManagedPreference(arc::prefs::kVoiceInteractionHotwordEnabled)); |
| 4104 | EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled)); |
| 4105 | prefs->SetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled, true); |
| 4106 | EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled)); |
| 4107 | |
| 4108 | // Verifies that the Assistant hotword can be forced to always enabled. |
| 4109 | policies.Set(key::kVoiceInteractionHotwordEnabled, POLICY_LEVEL_MANDATORY, |
| 4110 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4111 | std::make_unique<base::Value>(true), nullptr); |
| 4112 | UpdateProviderPolicy(policies); |
| 4113 | EXPECT_TRUE( |
| 4114 | prefs->IsManagedPreference(arc::prefs::kVoiceInteractionHotwordEnabled)); |
| 4115 | EXPECT_TRUE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled)); |
| 4116 | prefs->SetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled, false); |
| 4117 | EXPECT_TRUE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled)); |
| 4118 | } |
| 4119 | |
| 4120 | #endif // defined(OS_CHROMEOS) |
[email protected] | 7ea4870 | 2012-09-03 20:41:06 | [diff] [blame] | 4121 | |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4122 | namespace { |
| 4123 | |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 4124 | constexpr const char* kRestoredURLs[] = { |
| 4125 | "http://aaa.com/empty.html", "http://bbb.com/empty.html", |
[email protected] | 983ac6a4 | 2013-01-18 17:22:20 | [diff] [blame] | 4126 | }; |
| 4127 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 4128 | bool IsNonSwitchArgument(const base::CommandLine::StringType& s) { |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4129 | return s.empty() || s[0] != '-'; |
| 4130 | } |
| 4131 | |
| 4132 | } // namespace |
| 4133 | |
| 4134 | // Similar to PolicyTest but allows setting policies before the browser is |
| 4135 | // created. Each test parameter is a method that sets up the early policies |
| 4136 | // and stores the expected startup URLs in |expected_urls_|. |
| 4137 | class RestoreOnStartupPolicyTest |
| 4138 | : public PolicyTest, |
| 4139 | public testing::WithParamInterface< |
| 4140 | void (RestoreOnStartupPolicyTest::*)(void)> { |
| 4141 | public: |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 4142 | RestoreOnStartupPolicyTest() = default; |
| 4143 | virtual ~RestoreOnStartupPolicyTest() = default; |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4144 | |
[email protected] | 2bfe6ce | 2012-09-13 09:47:39 | [diff] [blame] | 4145 | #if defined(OS_CHROMEOS) |
dcheng | 6d888df | 2015-01-16 18:12:48 | [diff] [blame] | 4146 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | 2bfe6ce | 2012-09-13 09:47:39 | [diff] [blame] | 4147 | // TODO(nkostylev): Investigate if we can remove this switch. |
| 4148 | command_line->AppendSwitch(switches::kCreateBrowserOnStartupForTests); |
| 4149 | PolicyTest::SetUpCommandLine(command_line); |
| 4150 | } |
| 4151 | #endif |
| 4152 | |
dcheng | 32ae6bbb | 2014-10-22 08:47:29 | [diff] [blame] | 4153 | void SetUpInProcessBrowserTestFixture() override { |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4154 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 4155 | // Set early policies now, before the browser is created. |
| 4156 | (this->*(GetParam()))(); |
| 4157 | |
| 4158 | // Remove the non-switch arguments, so that session restore kicks in for |
| 4159 | // these tests. |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 4160 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 4161 | base::CommandLine::StringVector argv = command_line->argv(); |
Zhuoyu Qian | 779e425 | 2019-02-14 00:45:49 | [diff] [blame] | 4162 | base::EraseIf(argv, IsNonSwitchArgument); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4163 | command_line->InitFromArgv(argv); |
| 4164 | ASSERT_TRUE(std::equal(argv.begin(), argv.end(), |
| 4165 | command_line->argv().begin())); |
xunjieli | 0332c19 | 2014-09-10 23:23:31 | [diff] [blame] | 4166 | } |
[email protected] | 233b688e | 2012-11-27 10:44:12 | [diff] [blame] | 4167 | |
dcheng | 32ae6bbb | 2014-10-22 08:47:29 | [diff] [blame] | 4168 | void SetUpOnMainThread() override { |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 4169 | base::PostTaskWithTraits( |
| 4170 | FROM_HERE, {BrowserThread::IO}, |
tzik | 56432d9 | 2017-04-26 05:25:25 | [diff] [blame] | 4171 | base::BindOnce(RedirectHostsToTestData, kRestoredURLs, |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 4172 | base::size(kRestoredURLs))); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4173 | } |
| 4174 | |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4175 | void ListOfURLs() { |
| 4176 | // Verifies that policy can set the startup pages to a list of URLs. |
| 4177 | base::ListValue urls; |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 4178 | for (size_t i = 0; i < base::size(kRestoredURLs); ++i) { |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 4179 | urls.AppendString(kRestoredURLs[i]); |
[email protected] | 983ac6a4 | 2013-01-18 17:22:20 | [diff] [blame] | 4180 | expected_urls_.push_back(GURL(kRestoredURLs[i])); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4181 | } |
| 4182 | PolicyMap policies; |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 4183 | policies.Set( |
| 4184 | key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 4185 | POLICY_SOURCE_CLOUD, |
| 4186 | base::WrapUnique(new base::Value(SessionStartupPref::kPrefValueURLs)), |
| 4187 | nullptr); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 4188 | policies.Set(key::kRestoreOnStartupURLs, POLICY_LEVEL_MANDATORY, |
| 4189 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, urls.CreateDeepCopy(), |
| 4190 | nullptr); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4191 | provider_.UpdateChromePolicy(policies); |
| 4192 | } |
| 4193 | |
| 4194 | void NTP() { |
| 4195 | // Verifies that policy can set the startup page to the NTP. |
| 4196 | PolicyMap policies; |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 4197 | policies.Set( |
| 4198 | key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 4199 | POLICY_SOURCE_CLOUD, |
| 4200 | base::WrapUnique(new base::Value(SessionStartupPref::kPrefValueNewTab)), |
| 4201 | nullptr); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4202 | provider_.UpdateChromePolicy(policies); |
[email protected] | 233b688e | 2012-11-27 10:44:12 | [diff] [blame] | 4203 | expected_urls_.push_back(GURL(chrome::kChromeUINewTabURL)); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4204 | } |
| 4205 | |
| 4206 | void Last() { |
| 4207 | // Verifies that policy can set the startup pages to the last session. |
| 4208 | PolicyMap policies; |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 4209 | policies.Set( |
| 4210 | key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 4211 | POLICY_SOURCE_CLOUD, |
| 4212 | base::WrapUnique(new base::Value(SessionStartupPref::kPrefValueLast)), |
| 4213 | nullptr); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4214 | provider_.UpdateChromePolicy(policies); |
| 4215 | // This should restore the tabs opened at PRE_RunTest below. |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 4216 | for (size_t i = 0; i < base::size(kRestoredURLs); ++i) |
[email protected] | 983ac6a4 | 2013-01-18 17:22:20 | [diff] [blame] | 4217 | expected_urls_.push_back(GURL(kRestoredURLs[i])); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4218 | } |
| 4219 | |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 4220 | void Blocked() { |
| 4221 | // Verifies that URLs are blocked during session restore. |
| 4222 | PolicyMap policies; |
| 4223 | policies.Set( |
| 4224 | key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 4225 | POLICY_SOURCE_CLOUD, |
| 4226 | std::make_unique<base::Value>(SessionStartupPref::kPrefValueLast), |
| 4227 | nullptr); |
| 4228 | auto urls = std::make_unique<base::Value>(base::Value::Type::LIST); |
| 4229 | for (const auto* url_string : kRestoredURLs) |
| 4230 | urls->GetList().emplace_back(url_string); |
| 4231 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 4232 | POLICY_SOURCE_CLOUD, std::move(urls), nullptr); |
| 4233 | provider_.UpdateChromePolicy(policies); |
| 4234 | // This should restore the tabs opened at PRE_RunTest below, yet all should |
| 4235 | // be blocked. |
| 4236 | blocked_ = true; |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 4237 | for (size_t i = 0; i < base::size(kRestoredURLs); ++i) |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 4238 | expected_urls_.emplace_back(kRestoredURLs[i]); |
| 4239 | } |
| 4240 | |
| 4241 | // URLs that are expected to be loaded. |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4242 | std::vector<GURL> expected_urls_; |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 4243 | |
| 4244 | // True if the loaded URLs should be blocked by policy. |
| 4245 | bool blocked_ = false; |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4246 | }; |
| 4247 | |
| 4248 | IN_PROC_BROWSER_TEST_P(RestoreOnStartupPolicyTest, PRE_RunTest) { |
tmartino | f9a9ef14 | 2017-02-01 21:11:07 | [diff] [blame] | 4249 | // Do not show Welcome Page. |
| 4250 | browser()->profile()->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, |
| 4251 | true); |
| 4252 | |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4253 | // Open some tabs to verify if they are restored after the browser restarts. |
| 4254 | // Most policy settings override this, except kPrefValueLast which enforces |
| 4255 | // a restore. |
[email protected] | 983ac6a4 | 2013-01-18 17:22:20 | [diff] [blame] | 4256 | ui_test_utils::NavigateToURL(browser(), GURL(kRestoredURLs[0])); |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 4257 | for (size_t i = 1; i < base::size(kRestoredURLs); ++i) { |
[email protected] | 19506d54 | 2013-10-15 23:11:06 | [diff] [blame] | 4258 | content::WindowedNotificationObserver observer( |
| 4259 | content::NOTIFICATION_LOAD_STOP, |
| 4260 | content::NotificationService::AllSources()); |
| 4261 | chrome::AddSelectedTabWithURL(browser(), GURL(kRestoredURLs[i]), |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 4262 | ui::PAGE_TRANSITION_LINK); |
[email protected] | 19506d54 | 2013-10-15 23:11:06 | [diff] [blame] | 4263 | observer.Wait(); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4264 | } |
| 4265 | } |
| 4266 | |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 4267 | // Flaky on Linux; see https://crbug.com/701023. |
| 4268 | #if defined(OS_LINUX) |
| 4269 | #define MAYBE_RunTest DISABLED_RunTest |
| 4270 | #else |
| 4271 | #define MAYBE_RunTest RunTest |
| 4272 | #endif |
| 4273 | IN_PROC_BROWSER_TEST_P(RestoreOnStartupPolicyTest, MAYBE_RunTest) { |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4274 | TabStripModel* model = browser()->tab_strip_model(); |
| 4275 | int size = static_cast<int>(expected_urls_.size()); |
| 4276 | EXPECT_EQ(size, model->count()); |
Francois Doray | 8059c54 | 2018-07-05 21:16:20 | [diff] [blame] | 4277 | resource_coordinator::WaitForTransitionToLoaded(model); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4278 | for (int i = 0; i < size && i < model->count(); ++i) { |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 4279 | content::WebContents* web_contents = model->GetWebContentsAt(i); |
Greg Thompson | 2f011a45 | 2018-04-30 09:44:14 | [diff] [blame] | 4280 | if (blocked_) |
| 4281 | CheckURLIsBlockedInWebContents(web_contents, expected_urls_[i]); |
| 4282 | else if (expected_urls_[i] == GURL(chrome::kChromeUINewTabURL)) |
| 4283 | EXPECT_TRUE(search::IsInstantNTP(web_contents)); |
| 4284 | else |
| 4285 | EXPECT_EQ(expected_urls_[i], web_contents->GetURL()); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4286 | } |
| 4287 | } |
Greg Thompson | a37b35b | 2018-06-29 11:35:44 | [diff] [blame] | 4288 | #undef MAYBE_RunTest |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4289 | |
Victor Costan | e5e9151 | 2019-02-13 08:24:02 | [diff] [blame] | 4290 | INSTANTIATE_TEST_SUITE_P( |
| 4291 | RestoreOnStartupPolicyTestInstance, |
| 4292 | RestoreOnStartupPolicyTest, |
| 4293 | testing::Values(&RestoreOnStartupPolicyTest::ListOfURLs, |
| 4294 | &RestoreOnStartupPolicyTest::NTP, |
| 4295 | &RestoreOnStartupPolicyTest::Last, |
| 4296 | &RestoreOnStartupPolicyTest::Blocked)); |
[email protected] | 88ce3e7 | 2012-09-11 08:34:22 | [diff] [blame] | 4297 | |
[email protected] | 09f6906e | 2012-10-12 10:49:02 | [diff] [blame] | 4298 | // Similar to PolicyTest but sets a couple of policies before the browser is |
| 4299 | // started. |
| 4300 | class PolicyStatisticsCollectorTest : public PolicyTest { |
| 4301 | public: |
| 4302 | PolicyStatisticsCollectorTest() {} |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 4303 | ~PolicyStatisticsCollectorTest() override {} |
[email protected] | 09f6906e | 2012-10-12 10:49:02 | [diff] [blame] | 4304 | |
dcheng | 32ae6bbb | 2014-10-22 08:47:29 | [diff] [blame] | 4305 | void SetUpInProcessBrowserTestFixture() override { |
[email protected] | 09f6906e | 2012-10-12 10:49:02 | [diff] [blame] | 4306 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 4307 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 4308 | policies.Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY, |
| 4309 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 4310 | std::make_unique<base::Value>(true), nullptr); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 4311 | policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, |
| 4312 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 4313 | std::make_unique<base::Value>(false), nullptr); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 4314 | policies.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY, |
| 4315 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 4316 | std::make_unique<base::Value>("http://chromium.org"), nullptr); |
[email protected] | 09f6906e | 2012-10-12 10:49:02 | [diff] [blame] | 4317 | provider_.UpdateChromePolicy(policies); |
| 4318 | } |
| 4319 | }; |
| 4320 | |
| 4321 | IN_PROC_BROWSER_TEST_F(PolicyStatisticsCollectorTest, Startup) { |
| 4322 | // Verifies that policy usage histograms are collected at startup. |
| 4323 | |
| 4324 | // BrowserPolicyConnector::Init() has already been called. Make sure the |
| 4325 | // CompleteInitialization() task has executed as well. |
| 4326 | content::RunAllPendingInMessageLoop(); |
| 4327 | |
Mathieu Perreault | 18170a4 | 2018-05-17 12:48:15 | [diff] [blame] | 4328 | base::HistogramBase* histogram = |
| 4329 | base::StatisticsRecorder::FindHistogram("Enterprise.Policies"); |
| 4330 | std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); |
[email protected] | 09f6906e | 2012-10-12 10:49:02 | [diff] [blame] | 4331 | // HomepageLocation has policy ID 1. |
Mathieu Perreault | 18170a4 | 2018-05-17 12:48:15 | [diff] [blame] | 4332 | EXPECT_GT(samples->GetCount(1), 0); |
[email protected] | 09f6906e | 2012-10-12 10:49:02 | [diff] [blame] | 4333 | // ShowHomeButton has policy ID 35. |
Mathieu Perreault | 18170a4 | 2018-05-17 12:48:15 | [diff] [blame] | 4334 | EXPECT_GT(samples->GetCount(35), 0); |
[email protected] | 09f6906e | 2012-10-12 10:49:02 | [diff] [blame] | 4335 | // BookmarkBarEnabled has policy ID 82. |
Mathieu Perreault | 18170a4 | 2018-05-17 12:48:15 | [diff] [blame] | 4336 | EXPECT_GT(samples->GetCount(82), 0); |
[email protected] | 09f6906e | 2012-10-12 10:49:02 | [diff] [blame] | 4337 | } |
| 4338 | |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 4339 | // Similar to PolicyTest, but force to enable the new tab material design flag |
| 4340 | // before the browser start. |
| 4341 | class PolicyWebStoreIconTest : public PolicyTest { |
| 4342 | public: |
| 4343 | PolicyWebStoreIconTest() {} |
| 4344 | ~PolicyWebStoreIconTest() override {} |
| 4345 | |
| 4346 | void SetUpInProcessBrowserTestFixture() override { |
| 4347 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 4348 | } |
| 4349 | |
| 4350 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 4351 | PolicyTest::SetUpCommandLine(command_line); |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | private: |
Sorin Jianu | 55587d3 | 2018-11-14 21:43:27 | [diff] [blame] | 4355 | DISALLOW_COPY_AND_ASSIGN(PolicyWebStoreIconTest); |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 4356 | }; |
| 4357 | |
| 4358 | IN_PROC_BROWSER_TEST_F(PolicyWebStoreIconTest, AppsWebStoreIconHidden) { |
| 4359 | // Verifies that the web store icon can be hidden from the chrome://apps |
| 4360 | // page. A policy change takes immediate effect on the apps page for the |
| 4361 | // current profile. Browser restart is not required. |
| 4362 | |
| 4363 | // Open new tab page and look for the web store icons. |
| 4364 | ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAppsURL)); |
| 4365 | content::WebContents* contents = |
| 4366 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 4367 | |
| 4368 | #if !defined(OS_CHROMEOS) |
| 4369 | // Look for web store's app ID in the apps page. |
| 4370 | EXPECT_TRUE( |
| 4371 | ContainsVisibleElement(contents, "ahfgeienlihckogmohjhadlkjgocpleb")); |
| 4372 | #endif |
| 4373 | |
| 4374 | // The next NTP has no footer. |
| 4375 | if (ContainsVisibleElement(contents, "footer")) |
| 4376 | EXPECT_TRUE(ContainsVisibleElement(contents, "chrome-web-store-link")); |
| 4377 | |
| 4378 | // Turn off the web store icons. |
| 4379 | PolicyMap policies; |
| 4380 | policies.Set(key::kHideWebStoreIcon, POLICY_LEVEL_MANDATORY, |
| 4381 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4382 | base::WrapUnique(new base::Value(true)), nullptr); |
| 4383 | UpdateProviderPolicy(policies); |
| 4384 | |
| 4385 | // The web store icons should now be hidden. |
| 4386 | ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAppsURL)); |
| 4387 | EXPECT_FALSE( |
| 4388 | ContainsVisibleElement(contents, "ahfgeienlihckogmohjhadlkjgocpleb")); |
| 4389 | EXPECT_FALSE(ContainsVisibleElement(contents, "chrome-web-store-link")); |
| 4390 | } |
| 4391 | |
| 4392 | IN_PROC_BROWSER_TEST_F(PolicyWebStoreIconTest, NTPWebStoreIconShown) { |
| 4393 | // This test is to verify that the web store icons is shown when no policy |
| 4394 | // applies. See WebStoreIconPolicyTest.NTPWebStoreIconHidden for verification |
| 4395 | // when a policy is in effect. |
| 4396 | |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 4397 | // Open new tab page and look for the web store icons. |
| 4398 | content::WebContents* active_tab = |
| 4399 | local_ntp_test_utils::OpenNewTab(browser(), GURL("about:blank")); |
| 4400 | local_ntp_test_utils::NavigateToNTPAndWaitUntilLoaded(browser()); |
| 4401 | |
| 4402 | content::RenderFrameHost* iframe = GetMostVisitedIframe(active_tab); |
| 4403 | |
| 4404 | // Look though all the tiles and see whether there is a webstore icon. |
| 4405 | // Make sure that there is one web store icon. |
| 4406 | EXPECT_TRUE(ContainsWebstoreTile(iframe)); |
| 4407 | } |
| 4408 | |
| 4409 | // Similar to PolicyWebStoreIconShownTest, but applies the HideWebStoreIcon |
| 4410 | // policy before the browser is started. This is required because the list that |
| 4411 | // includes the WebStoreIcon on the NTP is initialized at browser start. |
| 4412 | class PolicyWebStoreIconHiddenTest : public PolicyTest { |
| 4413 | public: |
| 4414 | PolicyWebStoreIconHiddenTest() {} |
| 4415 | ~PolicyWebStoreIconHiddenTest() override {} |
| 4416 | |
| 4417 | void SetUpInProcessBrowserTestFixture() override { |
| 4418 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 4419 | PolicyMap policies; |
| 4420 | policies.Set(key::kHideWebStoreIcon, POLICY_LEVEL_MANDATORY, |
| 4421 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4422 | std::make_unique<base::Value>(true), nullptr); |
| 4423 | provider_.UpdateChromePolicy(policies); |
| 4424 | } |
| 4425 | |
| 4426 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 4427 | PolicyTest::SetUpCommandLine(command_line); |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 4428 | } |
| 4429 | |
| 4430 | private: |
Sorin Jianu | 55587d3 | 2018-11-14 21:43:27 | [diff] [blame] | 4431 | DISALLOW_COPY_AND_ASSIGN(PolicyWebStoreIconHiddenTest); |
Weilun Shi | b59ba59 | 2018-08-07 22:42:35 | [diff] [blame] | 4432 | }; |
| 4433 | |
| 4434 | IN_PROC_BROWSER_TEST_F(PolicyWebStoreIconHiddenTest, NTPWebStoreIconHidden) { |
| 4435 | // Verifies that the web store icon can be hidden from the new tab page. Check |
| 4436 | // to see NTPWebStoreIconShown for behavior when the policy is not applied. |
| 4437 | |
| 4438 | // Open new tab page and look for the web store icon |
| 4439 | content::WebContents* active_tab = |
| 4440 | local_ntp_test_utils::OpenNewTab(browser(), GURL("about:blank")); |
| 4441 | local_ntp_test_utils::NavigateToNTPAndWaitUntilLoaded(browser()); |
| 4442 | |
| 4443 | content::RenderFrameHost* iframe = GetMostVisitedIframe(active_tab); |
| 4444 | |
| 4445 | // Applying the policy before the browser started, the web store icon should |
| 4446 | // now be hidden. |
| 4447 | EXPECT_FALSE(ContainsWebstoreTile(iframe)); |
| 4448 | } |
| 4449 | |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4450 | class MediaStreamDevicesControllerBrowserTest |
| 4451 | : public PolicyTest, |
| 4452 | public testing::WithParamInterface<bool> { |
| 4453 | public: |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4454 | MediaStreamDevicesControllerBrowserTest() |
Raymes Khoury | a9873a15 | 2017-10-23 07:15:08 | [diff] [blame] | 4455 | : request_url_allowed_via_whitelist_(false) { |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4456 | policy_value_ = GetParam(); |
| 4457 | } |
| 4458 | virtual ~MediaStreamDevicesControllerBrowserTest() {} |
| 4459 | |
raymes | 3bc708e | 2017-04-11 00:38:24 | [diff] [blame] | 4460 | void SetUpOnMainThread() override { |
| 4461 | PolicyTest::SetUpOnMainThread(); |
Raymes Khoury | a9873a15 | 2017-10-23 07:15:08 | [diff] [blame] | 4462 | |
| 4463 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 4464 | request_url_ = embedded_test_server()->GetURL("/simple.html"); |
| 4465 | request_pattern_ = request_url_.GetOrigin().spec(); |
raymes | 3bc708e | 2017-04-11 00:38:24 | [diff] [blame] | 4466 | ui_test_utils::NavigateToURL(browser(), request_url_); |
timloh | fa10d43 | 2017-06-20 00:50:23 | [diff] [blame] | 4467 | |
| 4468 | // Testing both the new (PermissionManager) and old code-paths is not simple |
| 4469 | // since we are already using WithParamInterface. We only test whichever one |
| 4470 | // is enabled in chrome_features.cc since we won't keep the old path around |
| 4471 | // for long once we flip the flag. |
Timothy Loh | 8786fb3 | 2017-09-06 03:04:05 | [diff] [blame] | 4472 | PermissionRequestManager* manager = |
| 4473 | PermissionRequestManager::FromWebContents( |
| 4474 | browser()->tab_strip_model()->GetActiveWebContents()); |
| 4475 | prompt_factory_.reset(new MockPermissionPromptFactory(manager)); |
| 4476 | prompt_factory_->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
raymes | 3bc708e | 2017-04-11 00:38:24 | [diff] [blame] | 4477 | } |
| 4478 | |
timloh | fa10d43 | 2017-06-20 00:50:23 | [diff] [blame] | 4479 | void TearDownOnMainThread() override { prompt_factory_.reset(); } |
| 4480 | |
raymes | 3bc708e | 2017-04-11 00:38:24 | [diff] [blame] | 4481 | content::MediaStreamRequest CreateRequest( |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 4482 | blink::mojom::MediaStreamType audio_request_type, |
| 4483 | blink::mojom::MediaStreamType video_request_type) { |
raymes | 3bc708e | 2017-04-11 00:38:24 | [diff] [blame] | 4484 | content::WebContents* web_contents = |
| 4485 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 4486 | EXPECT_EQ(request_url_, |
| 4487 | web_contents->GetMainFrame()->GetLastCommittedURL()); |
Lukasz Anforowicz | 0e9fdcd | 2017-09-28 13:00:03 | [diff] [blame] | 4488 | int render_process_id = web_contents->GetMainFrame()->GetProcess()->GetID(); |
raymes | 3bc708e | 2017-04-11 00:38:24 | [diff] [blame] | 4489 | int render_frame_id = web_contents->GetMainFrame()->GetRoutingID(); |
| 4490 | return content::MediaStreamRequest( |
| 4491 | render_process_id, render_frame_id, 0, request_url_.GetOrigin(), false, |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 4492 | blink::MEDIA_DEVICE_ACCESS, std::string(), std::string(), |
raymes | 3bc708e | 2017-04-11 00:38:24 | [diff] [blame] | 4493 | audio_request_type, video_request_type, false); |
| 4494 | } |
| 4495 | |
raymes | 8a2eb046 | 2015-07-06 01:54:09 | [diff] [blame] | 4496 | // Configure a given policy map. The |policy_name| is the name of either the |
| 4497 | // audio or video capture allow policy and must never be NULL. |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4498 | // |whitelist_policy| and |allow_rule| are optional. If NULL, no whitelist |
raymes | 8a2eb046 | 2015-07-06 01:54:09 | [diff] [blame] | 4499 | // policy is set. If non-NULL, the whitelist policy is set to contain either |
| 4500 | // the |allow_rule| (if non-NULL) or an "allow all" wildcard. |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4501 | void ConfigurePolicyMap(PolicyMap* policies, const char* policy_name, |
| 4502 | const char* whitelist_policy, |
| 4503 | const char* allow_rule) { |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 4504 | policies->Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
fhorschig | 64834b71 | 2015-09-21 14:20:23 | [diff] [blame] | 4505 | POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 4506 | std::make_unique<base::Value>(policy_value_), nullptr); |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4507 | |
| 4508 | if (whitelist_policy) { |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4509 | // Add an entry to the whitelist that allows the specified URL regardless |
| 4510 | // of the setting of kAudioCapturedAllowed. |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 4511 | std::unique_ptr<base::ListValue> list(new base::ListValue); |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4512 | if (allow_rule) { |
| 4513 | list->AppendString(allow_rule); |
| 4514 | request_url_allowed_via_whitelist_ = true; |
| 4515 | } else { |
| 4516 | list->AppendString(ContentSettingsPattern::Wildcard().ToString()); |
| 4517 | // We should ignore all wildcard entries in the whitelist, so even |
| 4518 | // though we've added an entry, it should be ignored and our expectation |
| 4519 | // is that the request has not been allowed via the whitelist. |
| 4520 | request_url_allowed_via_whitelist_ = false; |
| 4521 | } |
fhorschig | 64834b71 | 2015-09-21 14:20:23 | [diff] [blame] | 4522 | policies->Set(whitelist_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 4523 | POLICY_SOURCE_CLOUD, std::move(list), nullptr); |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4524 | } |
| 4525 | } |
| 4526 | |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 4527 | void Accept(const blink::MediaStreamDevices& devices, |
Antonio Gomes | 0d42960a | 2019-06-05 12:35:51 | [diff] [blame] | 4528 | blink::mojom::MediaStreamRequestResult result, |
dcheng | 08cfe9ba | 2016-04-14 17:46:45 | [diff] [blame] | 4529 | std::unique_ptr<content::MediaStreamUI> ui) { |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4530 | if (policy_value_ || request_url_allowed_via_whitelist_) { |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4531 | ASSERT_EQ(1U, devices.size()); |
| 4532 | ASSERT_EQ("fake_dev", devices[0].id); |
| 4533 | } else { |
| 4534 | ASSERT_EQ(0U, devices.size()); |
| 4535 | } |
| 4536 | } |
| 4537 | |
| 4538 | void FinishAudioTest() { |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 4539 | content::MediaStreamRequest request( |
| 4540 | CreateRequest(blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE, |
| 4541 | blink::mojom::MediaStreamType::NO_SERVICE)); |
[email protected] | ae6ef14 | 2013-06-13 22:50:52 | [diff] [blame] | 4542 | // TODO(raymes): Test MEDIA_DEVICE_OPEN (Pepper) which grants both webcam |
| 4543 | // and microphone permissions at the same time. |
Timothy Loh | 8786fb3 | 2017-09-06 03:04:05 | [diff] [blame] | 4544 | MediaStreamDevicesController::RequestPermissions( |
| 4545 | request, base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, |
| 4546 | base::Unretained(this))); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4547 | |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 4548 | base::RunLoop::QuitCurrentWhenIdleDeprecated(); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | void FinishVideoTest() { |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 4552 | content::MediaStreamRequest request( |
| 4553 | CreateRequest(blink::mojom::MediaStreamType::NO_SERVICE, |
| 4554 | blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE)); |
raymes | 8a2eb046 | 2015-07-06 01:54:09 | [diff] [blame] | 4555 | // TODO(raymes): Test MEDIA_DEVICE_OPEN (Pepper) which grants both webcam |
| 4556 | // and microphone permissions at the same time. |
Timothy Loh | 8786fb3 | 2017-09-06 03:04:05 | [diff] [blame] | 4557 | MediaStreamDevicesController::RequestPermissions( |
| 4558 | request, base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, |
| 4559 | base::Unretained(this))); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4560 | |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 4561 | base::RunLoop::QuitCurrentWhenIdleDeprecated(); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4562 | } |
| 4563 | |
timloh | fa10d43 | 2017-06-20 00:50:23 | [diff] [blame] | 4564 | std::unique_ptr<MockPermissionPromptFactory> prompt_factory_; |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4565 | bool policy_value_; |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4566 | bool request_url_allowed_via_whitelist_; |
| 4567 | GURL request_url_; |
Raymes Khoury | a9873a15 | 2017-10-23 07:15:08 | [diff] [blame] | 4568 | std::string request_pattern_; |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4569 | }; |
| 4570 | |
| 4571 | IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
| 4572 | AudioCaptureAllowed) { |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 4573 | blink::MediaStreamDevices audio_devices; |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 4574 | blink::MediaStreamDevice fake_audio_device( |
| 4575 | blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE, "fake_dev", |
| 4576 | "Fake Audio Device"); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4577 | audio_devices.push_back(fake_audio_device); |
| 4578 | |
| 4579 | PolicyMap policies; |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4580 | ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed, NULL, NULL); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4581 | UpdateProviderPolicy(policies); |
| 4582 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 4583 | base::PostTaskWithTraitsAndReply( |
| 4584 | FROM_HERE, {content::BrowserThread::IO}, |
tzik | 56432d9 | 2017-04-26 05:25:25 | [diff] [blame] | 4585 | base::BindOnce( |
| 4586 | &MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices, |
| 4587 | base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 4588 | audio_devices), |
| 4589 | base::BindOnce(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, |
| 4590 | base::Unretained(this))); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4591 | |
fdoray | cb32419d | 2016-06-23 15:52:55 | [diff] [blame] | 4592 | base::RunLoop().Run(); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4596 | AudioCaptureAllowedUrls) { |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 4597 | blink::MediaStreamDevices audio_devices; |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 4598 | blink::MediaStreamDevice fake_audio_device( |
| 4599 | blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE, "fake_dev", |
| 4600 | "Fake Audio Device"); |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4601 | audio_devices.push_back(fake_audio_device); |
| 4602 | |
| 4603 | const char* allow_pattern[] = { |
Raymes Khoury | a9873a15 | 2017-10-23 07:15:08 | [diff] [blame] | 4604 | request_pattern_.c_str(), |
| 4605 | // This will set an allow-all policy whitelist. Since we do not allow |
| 4606 | // setting an allow-all entry in the whitelist, this entry should be |
| 4607 | // ignored and therefore the request should be denied. |
| 4608 | nullptr, |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4609 | }; |
| 4610 | |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 4611 | for (size_t i = 0; i < base::size(allow_pattern); ++i) { |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4612 | PolicyMap policies; |
| 4613 | ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed, |
| 4614 | key::kAudioCaptureAllowedUrls, allow_pattern[i]); |
| 4615 | UpdateProviderPolicy(policies); |
| 4616 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 4617 | base::PostTaskWithTraitsAndReply( |
| 4618 | FROM_HERE, {content::BrowserThread::IO}, |
tzik | 56432d9 | 2017-04-26 05:25:25 | [diff] [blame] | 4619 | base::BindOnce( |
[email protected] | 060ffdb | 2014-03-14 21:09:37 | [diff] [blame] | 4620 | &MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices, |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4621 | base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 4622 | audio_devices), |
tzik | 56432d9 | 2017-04-26 05:25:25 | [diff] [blame] | 4623 | base::BindOnce( |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4624 | &MediaStreamDevicesControllerBrowserTest::FinishAudioTest, |
tzik | e04a147 | 2016-08-02 21:00:33 | [diff] [blame] | 4625 | base::Unretained(this))); |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4626 | |
fdoray | cb32419d | 2016-06-23 15:52:55 | [diff] [blame] | 4627 | base::RunLoop().Run(); |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4628 | } |
| 4629 | } |
| 4630 | |
| 4631 | IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4632 | VideoCaptureAllowed) { |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 4633 | blink::MediaStreamDevices video_devices; |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 4634 | blink::MediaStreamDevice fake_video_device( |
| 4635 | blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE, "fake_dev", |
| 4636 | "Fake Video Device"); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4637 | video_devices.push_back(fake_video_device); |
| 4638 | |
| 4639 | PolicyMap policies; |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4640 | ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed, NULL, NULL); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4641 | UpdateProviderPolicy(policies); |
| 4642 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 4643 | base::PostTaskWithTraitsAndReply( |
| 4644 | FROM_HERE, {content::BrowserThread::IO}, |
tzik | 56432d9 | 2017-04-26 05:25:25 | [diff] [blame] | 4645 | base::BindOnce( |
| 4646 | &MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices, |
| 4647 | base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 4648 | video_devices), |
| 4649 | base::BindOnce(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, |
| 4650 | base::Unretained(this))); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4651 | |
fdoray | cb32419d | 2016-06-23 15:52:55 | [diff] [blame] | 4652 | base::RunLoop().Run(); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4653 | } |
| 4654 | |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4655 | IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
| 4656 | VideoCaptureAllowedUrls) { |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 4657 | blink::MediaStreamDevices video_devices; |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 4658 | blink::MediaStreamDevice fake_video_device( |
| 4659 | blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE, "fake_dev", |
| 4660 | "Fake Video Device"); |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4661 | video_devices.push_back(fake_video_device); |
| 4662 | |
| 4663 | const char* allow_pattern[] = { |
Raymes Khoury | a9873a15 | 2017-10-23 07:15:08 | [diff] [blame] | 4664 | request_pattern_.c_str(), |
| 4665 | // This will set an allow-all policy whitelist. Since we do not allow |
| 4666 | // setting an allow-all entry in the whitelist, this entry should be |
| 4667 | // ignored and therefore the request should be denied. |
| 4668 | nullptr, |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4669 | }; |
| 4670 | |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 4671 | for (size_t i = 0; i < base::size(allow_pattern); ++i) { |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4672 | PolicyMap policies; |
| 4673 | ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed, |
| 4674 | key::kVideoCaptureAllowedUrls, allow_pattern[i]); |
| 4675 | UpdateProviderPolicy(policies); |
| 4676 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 4677 | base::PostTaskWithTraitsAndReply( |
| 4678 | FROM_HERE, {content::BrowserThread::IO}, |
tzik | 56432d9 | 2017-04-26 05:25:25 | [diff] [blame] | 4679 | base::BindOnce( |
| 4680 | &MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices, |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4681 | base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 4682 | video_devices), |
tzik | 56432d9 | 2017-04-26 05:25:25 | [diff] [blame] | 4683 | base::BindOnce( |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4684 | &MediaStreamDevicesControllerBrowserTest::FinishVideoTest, |
tzik | e04a147 | 2016-08-02 21:00:33 | [diff] [blame] | 4685 | base::Unretained(this))); |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4686 | |
fdoray | cb32419d | 2016-06-23 15:52:55 | [diff] [blame] | 4687 | base::RunLoop().Run(); |
[email protected] | e2d3140 | 2013-05-28 15:26:20 | [diff] [blame] | 4688 | } |
| 4689 | } |
| 4690 | |
Victor Costan | e5e9151 | 2019-02-13 08:24:02 | [diff] [blame] | 4691 | INSTANTIATE_TEST_SUITE_P(MediaStreamDevicesControllerBrowserTestInstance, |
| 4692 | MediaStreamDevicesControllerBrowserTest, |
| 4693 | testing::Bool()); |
[email protected] | 4ee5604f | 2013-01-24 14:43:50 | [diff] [blame] | 4694 | |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 4695 | class WebBluetoothPolicyTest : public PolicyTest { |
| 4696 | void SetUpCommandLine(base::CommandLine* command_line)override { |
juncai | 3ad09e10 | 2016-10-28 03:08:06 | [diff] [blame] | 4697 | // TODO(juncai): Remove this switch once Web Bluetooth is supported on Linux |
| 4698 | // and Windows. |
| 4699 | // https://crbug.com/570344 |
| 4700 | // https://crbug.com/507419 |
| 4701 | command_line->AppendSwitch( |
| 4702 | switches::kEnableExperimentalWebPlatformFeatures); |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 4703 | PolicyTest::SetUpCommandLine(command_line); |
| 4704 | } |
| 4705 | }; |
| 4706 | |
| 4707 | IN_PROC_BROWSER_TEST_F(WebBluetoothPolicyTest, Block) { |
| 4708 | // Fake the BluetoothAdapter to say it's present. |
| 4709 | scoped_refptr<device::MockBluetoothAdapter> adapter = |
| 4710 | new testing::NiceMock<device::MockBluetoothAdapter>; |
| 4711 | EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(testing::Return(true)); |
ortuno | 6312047 | 2017-05-02 23:34:53 | [diff] [blame] | 4712 | auto bt_global_values = |
| 4713 | device::BluetoothAdapterFactory::Get().InitGlobalValuesForTesting(); |
| 4714 | bt_global_values->SetLESupported(true); |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 4715 | device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); |
| 4716 | |
| 4717 | // Navigate to a secure context. |
| 4718 | embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data"); |
| 4719 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 4720 | ui_test_utils::NavigateToURL( |
| 4721 | browser(), |
| 4722 | embedded_test_server()->GetURL("localhost", "/simple_page.html")); |
| 4723 | content::WebContents* const web_contents = |
| 4724 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 4725 | EXPECT_THAT( |
| 4726 | web_contents->GetMainFrame()->GetLastCommittedOrigin().Serialize(), |
| 4727 | testing::StartsWith("http://localhost:")); |
| 4728 | |
| 4729 | // Set the policy to block Web Bluetooth. |
| 4730 | PolicyMap policies; |
| 4731 | policies.Set(key::kDefaultWebBluetoothGuardSetting, POLICY_LEVEL_MANDATORY, |
| 4732 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 4733 | std::make_unique<base::Value>(2), nullptr); |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 4734 | UpdateProviderPolicy(policies); |
| 4735 | |
| 4736 | std::string rejection; |
| 4737 | EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 4738 | web_contents, |
| 4739 | "navigator.bluetooth.requestDevice({filters: [{name: 'Hello'}]})" |
| 4740 | " .then(() => { domAutomationController.send('Success'); }," |
| 4741 | " reason => {" |
| 4742 | " domAutomationController.send(reason.name + ': ' + reason.message);" |
| 4743 | " });", |
| 4744 | &rejection)); |
| 4745 | EXPECT_THAT(rejection, testing::MatchesRegex("NotFoundError: .*policy.*")); |
| 4746 | } |
| 4747 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4748 | IN_PROC_BROWSER_TEST_F(PolicyTest, |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 4749 | CertificateTransparencyEnforcementDisabledForUrls) { |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 4750 | net::EmbeddedTestServer https_server_ok(net::EmbeddedTestServer::TYPE_HTTPS); |
| 4751 | https_server_ok.SetSSLConfig(net::EmbeddedTestServer::CERT_OK); |
| 4752 | https_server_ok.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 4753 | ASSERT_TRUE(https_server_ok.Start()); |
| 4754 | |
| 4755 | // Require CT for all hosts (in the absence of policy). |
Doug Turner | 9e79cf0c | 2018-04-05 21:32:30 | [diff] [blame] | 4756 | bool required = true; |
| 4757 | SetShouldRequireCTForTesting(&required); |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 4758 | |
| 4759 | ui_test_utils::NavigateToURL(browser(), https_server_ok.GetURL("/")); |
| 4760 | |
| 4761 | // The page should initially be blocked. |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 4762 | content::WebContents* tab = |
| 4763 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 4764 | WaitForInterstitial(tab); |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 4765 | |
| 4766 | EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4767 | tab->GetMainFrame(), "proceed-link")); |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 4768 | EXPECT_NE(base::UTF8ToUTF16("OK"), |
| 4769 | browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 4770 | |
| 4771 | // Now exempt the URL from being blocked by setting policy. |
| 4772 | std::unique_ptr<base::ListValue> disabled_urls = |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 4773 | std::make_unique<base::ListValue>(); |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 4774 | disabled_urls->AppendString(https_server_ok.host_port_pair().HostForURL()); |
| 4775 | |
| 4776 | PolicyMap policies; |
| 4777 | policies.Set(key::kCertificateTransparencyEnforcementDisabledForUrls, |
| 4778 | POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4779 | std::move(disabled_urls), nullptr); |
| 4780 | UpdateProviderPolicy(policies); |
| 4781 | FlushBlacklistPolicy(); |
| 4782 | |
| 4783 | ui_test_utils::NavigateToURL(browser(), |
| 4784 | https_server_ok.GetURL("/simple.html")); |
| 4785 | |
| 4786 | // There should be no interstitial after the page loads. |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 4787 | EXPECT_FALSE(IsShowingInterstitial(tab)); |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 4788 | EXPECT_EQ(base::UTF8ToUTF16("OK"), |
| 4789 | browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
John Abd-El-Malek | 39d0a67 | 2018-09-28 22:14:05 | [diff] [blame] | 4790 | |
| 4791 | // Now ensure that this setting still works after a network process crash. |
John Abd-El-Malek | 9dba1ad | 2018-10-27 02:22:14 | [diff] [blame] | 4792 | if (!content::IsOutOfProcessNetworkService()) |
John Abd-El-Malek | 39d0a67 | 2018-09-28 22:14:05 | [diff] [blame] | 4793 | return; |
John Abd-El-Malek | 39d0a67 | 2018-09-28 22:14:05 | [diff] [blame] | 4794 | |
| 4795 | ui_test_utils::NavigateToURL(browser(), |
| 4796 | https_server_ok.GetURL("/title1.html")); |
| 4797 | |
| 4798 | SimulateNetworkServiceCrash(); |
| 4799 | SetShouldRequireCTForTesting(&required); |
| 4800 | |
| 4801 | ui_test_utils::NavigateToURL(browser(), |
| 4802 | https_server_ok.GetURL("/simple.html")); |
| 4803 | |
| 4804 | // There should be no interstitial after the page loads. |
| 4805 | EXPECT_FALSE(IsShowingInterstitial(tab)); |
| 4806 | EXPECT_EQ(base::UTF8ToUTF16("OK"), |
| 4807 | browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
rsleevi | 96356f8 | 2016-06-30 09:01:20 | [diff] [blame] | 4808 | } |
| 4809 | |
Ryan Sleevi | c8889d0 | 2018-04-06 17:57:05 | [diff] [blame] | 4810 | IN_PROC_BROWSER_TEST_F(PolicyTest, |
| 4811 | CertificateTransparencyEnforcementDisabledForCas) { |
| 4812 | net::EmbeddedTestServer https_server_ok(net::EmbeddedTestServer::TYPE_HTTPS); |
| 4813 | https_server_ok.SetSSLConfig(net::EmbeddedTestServer::CERT_OK); |
| 4814 | https_server_ok.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 4815 | ASSERT_TRUE(https_server_ok.Start()); |
| 4816 | |
| 4817 | // Require CT for all hosts (in the absence of policy). |
| 4818 | bool required = true; |
| 4819 | SetShouldRequireCTForTesting(&required); |
| 4820 | |
| 4821 | ui_test_utils::NavigateToURL(browser(), https_server_ok.GetURL("/")); |
| 4822 | |
Carlos IL | 798c47c8ce | 2018-11-26 17:30:41 | [diff] [blame] | 4823 | content::WebContents* web_contents = |
| 4824 | browser()->tab_strip_model()->GetActiveWebContents(); |
Carlos IL | a1b9cd3 | 2018-11-20 01:21:55 | [diff] [blame] | 4825 | |
Carlos IL | 798c47c8ce | 2018-11-26 17:30:41 | [diff] [blame] | 4826 | // The page should initially be blocked. |
| 4827 | content::RenderFrameHost* main_frame; |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4828 | security_interstitials::SecurityInterstitialTabHelper* helper = |
| 4829 | security_interstitials::SecurityInterstitialTabHelper::FromWebContents( |
| 4830 | web_contents); |
| 4831 | ASSERT_TRUE(helper); |
| 4832 | ASSERT_TRUE( |
| 4833 | helper->GetBlockingPageForCurrentlyCommittedNavigationForTesting()); |
| 4834 | main_frame = web_contents->GetMainFrame(); |
Carlos IL | 798c47c8ce | 2018-11-26 17:30:41 | [diff] [blame] | 4835 | ASSERT_TRUE(content::WaitForRenderFrameReady(main_frame)); |
Maxim Kolosovskiy | 3260717 | 2018-11-20 10:09:21 | [diff] [blame] | 4836 | EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
Carlos IL | 798c47c8ce | 2018-11-26 17:30:41 | [diff] [blame] | 4837 | main_frame, "proceed-link")); |
| 4838 | |
Ryan Sleevi | c8889d0 | 2018-04-06 17:57:05 | [diff] [blame] | 4839 | EXPECT_NE(base::UTF8ToUTF16("OK"), |
| 4840 | browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 4841 | |
| 4842 | // Now exempt the leaf SPKI from being blocked by setting policy. |
| 4843 | net::HashValue leaf_hash; |
| 4844 | ASSERT_TRUE(net::x509_util::CalculateSha256SpkiHash( |
| 4845 | https_server_ok.GetCertificate()->cert_buffer(), &leaf_hash)); |
| 4846 | std::unique_ptr<base::ListValue> disabled_spkis = |
| 4847 | std::make_unique<base::ListValue>(); |
| 4848 | disabled_spkis->AppendString(leaf_hash.ToString()); |
| 4849 | |
| 4850 | PolicyMap policies; |
| 4851 | policies.Set(key::kCertificateTransparencyEnforcementDisabledForCas, |
| 4852 | POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4853 | std::move(disabled_spkis), nullptr); |
| 4854 | UpdateProviderPolicy(policies); |
| 4855 | FlushBlacklistPolicy(); |
| 4856 | |
| 4857 | ui_test_utils::NavigateToURL(browser(), |
| 4858 | https_server_ok.GetURL("/simple.html")); |
| 4859 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4860 | // Check we are no longer in the interstitial. |
Ryan Sleevi | c8889d0 | 2018-04-06 17:57:05 | [diff] [blame] | 4861 | EXPECT_EQ(base::UTF8ToUTF16("OK"), |
| 4862 | browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 4863 | } |
| 4864 | |
estark | 86642d60 | 2015-04-09 20:39:16 | [diff] [blame] | 4865 | // Test that when extended reporting opt-in is disabled by policy, the |
| 4866 | // opt-in checkbox does not appear on SSL blocking pages. |
Luke Zielinski | 47a9285 | 2018-03-01 20:42:57 | [diff] [blame] | 4867 | // Note: SafeBrowsingExtendedReportingOptInAllowed policy is being deprecated. |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4868 | IN_PROC_BROWSER_TEST_F(PolicyTest, SafeBrowsingExtendedReportingOptInAllowed) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 4869 | net::EmbeddedTestServer https_server_expired( |
| 4870 | net::EmbeddedTestServer::TYPE_HTTPS); |
| 4871 | https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); |
| 4872 | https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data"); |
estark | 86642d60 | 2015-04-09 20:39:16 | [diff] [blame] | 4873 | ASSERT_TRUE(https_server_expired.Start()); |
| 4874 | |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 4875 | // First, navigate to an SSL error page and make sure the checkbox appears by |
| 4876 | // default. |
| 4877 | ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/")); |
| 4878 | EXPECT_EQ(security_interstitials::CMD_TEXT_FOUND, |
| 4879 | IsExtendedReportingCheckboxVisibleOnInterstitial()); |
| 4880 | |
estark | 86642d60 | 2015-04-09 20:39:16 | [diff] [blame] | 4881 | // Set the enterprise policy to disallow opt-in. |
| 4882 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
| 4883 | EXPECT_TRUE( |
| 4884 | prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); |
| 4885 | PolicyMap policies; |
| 4886 | policies.Set(key::kSafeBrowsingExtendedReportingOptInAllowed, |
fhorschig | 64834b71 | 2015-09-21 14:20:23 | [diff] [blame] | 4887 | POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 4888 | base::WrapUnique(new base::Value(false)), nullptr); |
estark | 86642d60 | 2015-04-09 20:39:16 | [diff] [blame] | 4889 | UpdateProviderPolicy(policies); |
| 4890 | EXPECT_FALSE( |
| 4891 | prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); |
| 4892 | |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 4893 | // Navigate to an SSL error page, the checkbox should not appear. |
estark | 86642d60 | 2015-04-09 20:39:16 | [diff] [blame] | 4894 | ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/")); |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 4895 | EXPECT_EQ(security_interstitials::CMD_TEXT_NOT_FOUND, |
| 4896 | IsExtendedReportingCheckboxVisibleOnInterstitial()); |
estark | 86642d60 | 2015-04-09 20:39:16 | [diff] [blame] | 4897 | } |
| 4898 | |
Luke Zielinski | 47a9285 | 2018-03-01 20:42:57 | [diff] [blame] | 4899 | // Test that when extended reporting is managed by policy, the opt-in checkbox |
| 4900 | // does not appear on SSL blocking pages. |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4901 | IN_PROC_BROWSER_TEST_F(PolicyTest, SafeBrowsingExtendedReportingPolicyManaged) { |
Luke Zielinski | 47a9285 | 2018-03-01 20:42:57 | [diff] [blame] | 4902 | net::EmbeddedTestServer https_server_expired( |
| 4903 | net::EmbeddedTestServer::TYPE_HTTPS); |
| 4904 | https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); |
| 4905 | https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 4906 | ASSERT_TRUE(https_server_expired.Start()); |
| 4907 | |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 4908 | // Set the extended reporting pref to True and ensure the enterprise policy |
| 4909 | // can overwrite it. |
| 4910 | PrefService* prefs = browser()->profile()->GetPrefs(); |
| 4911 | prefs->SetBoolean(prefs::kSafeBrowsingScoutReportingEnabled, true); |
| 4912 | |
| 4913 | // First, navigate to an SSL error page and make sure the checkbox appears by |
| 4914 | // default. |
| 4915 | ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/")); |
| 4916 | EXPECT_EQ(security_interstitials::CMD_TEXT_FOUND, |
| 4917 | IsExtendedReportingCheckboxVisibleOnInterstitial()); |
| 4918 | |
Luke Zielinski | 47a9285 | 2018-03-01 20:42:57 | [diff] [blame] | 4919 | // Set the enterprise policy to disable extended reporting. |
Luke Zielinski | 47a9285 | 2018-03-01 20:42:57 | [diff] [blame] | 4920 | EXPECT_TRUE( |
| 4921 | prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); |
| 4922 | PolicyMap policies; |
| 4923 | policies.Set(key::kSafeBrowsingExtendedReportingEnabled, |
| 4924 | POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 4925 | base::WrapUnique(new base::Value(false)), nullptr); |
| 4926 | UpdateProviderPolicy(policies); |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 4927 | // Policy should have overwritten the pref, and it should be managed. |
| 4928 | EXPECT_FALSE(prefs->GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)); |
| 4929 | EXPECT_TRUE( |
| 4930 | prefs->IsManagedPreference(prefs::kSafeBrowsingScoutReportingEnabled)); |
| 4931 | |
| 4932 | // Also make sure the SafeBrowsing prefs helper functions agree with the |
| 4933 | // policy. |
Luke Zielinski | 47a9285 | 2018-03-01 20:42:57 | [diff] [blame] | 4934 | EXPECT_TRUE(safe_browsing::IsExtendedReportingPolicyManaged(*prefs)); |
| 4935 | // Note that making SBER policy managed does NOT affect the SBEROptInAllowed |
| 4936 | // setting, which is intentionally kept distinct for now. When the latter is |
| 4937 | // deprecated, then SBER's policy management will imply whether the checkbox |
| 4938 | // is visible. |
| 4939 | EXPECT_TRUE(safe_browsing::IsExtendedReportingOptInAllowed(*prefs)); |
| 4940 | |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 4941 | // Navigate to an SSL error page, the checkbox should not appear. |
Luke Zielinski | 47a9285 | 2018-03-01 20:42:57 | [diff] [blame] | 4942 | ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/")); |
Luke Zielinski | 389909fa | 2018-06-10 02:10:56 | [diff] [blame] | 4943 | EXPECT_EQ(security_interstitials::CMD_TEXT_NOT_FOUND, |
| 4944 | IsExtendedReportingCheckboxVisibleOnInterstitial()); |
Luke Zielinski | 47a9285 | 2018-03-01 20:42:57 | [diff] [blame] | 4945 | } |
| 4946 | |
fahl | e66e7ff | 2015-04-23 19:38:30 | [diff] [blame] | 4947 | // Test that when SSL error overriding is allowed by policy (default), the |
| 4948 | // proceed link appears on SSL blocking pages. |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4949 | IN_PROC_BROWSER_TEST_F(PolicyTest, SSLErrorOverridingAllowed) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 4950 | net::EmbeddedTestServer https_server_expired( |
| 4951 | net::EmbeddedTestServer::TYPE_HTTPS); |
| 4952 | https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); |
| 4953 | https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data"); |
fahl | e66e7ff | 2015-04-23 19:38:30 | [diff] [blame] | 4954 | ASSERT_TRUE(https_server_expired.Start()); |
| 4955 | |
| 4956 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
| 4957 | |
| 4958 | // Policy should allow overriding by default. |
| 4959 | EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed)); |
| 4960 | |
| 4961 | // Policy allows overriding - navigate to an SSL error page and expect the |
| 4962 | // proceed link. |
| 4963 | ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/")); |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 4964 | content::WebContents* tab = |
| 4965 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 4966 | WaitForInterstitial(tab); |
fahl | e66e7ff | 2015-04-23 19:38:30 | [diff] [blame] | 4967 | |
| 4968 | // The interstitial should display the proceed link. |
| 4969 | EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4970 | tab->GetMainFrame(), "proceed-link")); |
fahl | e66e7ff | 2015-04-23 19:38:30 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | // Test that when SSL error overriding is disallowed by policy, the |
felt | 2d3f65e | 2015-05-18 15:26:04 | [diff] [blame] | 4974 | // proceed link does not appear on SSL blocking pages and users should not |
| 4975 | // be able to proceed. |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4976 | IN_PROC_BROWSER_TEST_F(PolicyTest, SSLErrorOverridingDisallowed) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 4977 | net::EmbeddedTestServer https_server_expired( |
| 4978 | net::EmbeddedTestServer::TYPE_HTTPS); |
| 4979 | https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); |
| 4980 | https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data"); |
fahl | e66e7ff | 2015-04-23 19:38:30 | [diff] [blame] | 4981 | ASSERT_TRUE(https_server_expired.Start()); |
| 4982 | |
| 4983 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
| 4984 | EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed)); |
| 4985 | |
| 4986 | // Disallowing the proceed link by setting the policy to |false|. |
| 4987 | PolicyMap policies; |
| 4988 | policies.Set(key::kSSLErrorOverrideAllowed, POLICY_LEVEL_MANDATORY, |
fhorschig | 64834b71 | 2015-09-21 14:20:23 | [diff] [blame] | 4989 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 4990 | base::WrapUnique(new base::Value(false)), nullptr); |
fahl | e66e7ff | 2015-04-23 19:38:30 | [diff] [blame] | 4991 | UpdateProviderPolicy(policies); |
| 4992 | |
| 4993 | // Policy should not allow overriding anymore. |
| 4994 | EXPECT_FALSE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed)); |
| 4995 | |
| 4996 | // Policy disallows overriding - navigate to an SSL error page and expect no |
| 4997 | // proceed link. |
| 4998 | ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/")); |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 4999 | content::WebContents* tab = |
| 5000 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 5001 | WaitForInterstitial(tab); |
fahl | e66e7ff | 2015-04-23 19:38:30 | [diff] [blame] | 5002 | |
| 5003 | // The interstitial should not display the proceed link. |
| 5004 | EXPECT_FALSE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 5005 | tab->GetMainFrame(), "proceed-link")); |
felt | 2d3f65e | 2015-05-18 15:26:04 | [diff] [blame] | 5006 | |
| 5007 | // The interstitial should not proceed, even if the command is sent in |
| 5008 | // some other way (e.g., via the keyboard shortcut). |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 5009 | SendInterstitialCommand(tab, security_interstitials::CMD_PROCEED); |
| 5010 | EXPECT_TRUE(IsShowingInterstitial(tab)); |
fahl | e66e7ff | 2015-04-23 19:38:30 | [diff] [blame] | 5011 | } |
| 5012 | |
afakhry | 17406972 | 2016-05-24 19:16:16 | [diff] [blame] | 5013 | // Test that TaskManagerInterface::IsEndProcessEnabled is controlled by |
hunyadym | e7a3229 | 2016-04-20 00:23:43 | [diff] [blame] | 5014 | // TaskManagerEndProcessEnabled policy |
| 5015 | IN_PROC_BROWSER_TEST_F(PolicyTest, TaskManagerEndProcessEnabled) { |
| 5016 | // By default it's allowed to end tasks. |
avi | 24d693f | 2016-08-06 18:03:52 | [diff] [blame] | 5017 | EXPECT_TRUE(task_manager::TaskManagerInterface::IsEndProcessEnabled()); |
hunyadym | e7a3229 | 2016-04-20 00:23:43 | [diff] [blame] | 5018 | |
| 5019 | // Disabling ending tasks in task manager by policy |
| 5020 | PolicyMap policies1; |
| 5021 | policies1.Set(key::kTaskManagerEndProcessEnabled, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5022 | POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 5023 | base::WrapUnique(new base::Value(false)), nullptr); |
hunyadym | e7a3229 | 2016-04-20 00:23:43 | [diff] [blame] | 5024 | UpdateProviderPolicy(policies1); |
| 5025 | |
| 5026 | // Policy should not allow ending tasks anymore. |
avi | 24d693f | 2016-08-06 18:03:52 | [diff] [blame] | 5027 | EXPECT_FALSE(task_manager::TaskManagerInterface::IsEndProcessEnabled()); |
hunyadym | e7a3229 | 2016-04-20 00:23:43 | [diff] [blame] | 5028 | |
| 5029 | // Enabling ending tasks in task manager by policy |
| 5030 | PolicyMap policies2; |
| 5031 | policies2.Set(key::kTaskManagerEndProcessEnabled, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5032 | POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 5033 | base::WrapUnique(new base::Value(true)), nullptr); |
hunyadym | e7a3229 | 2016-04-20 00:23:43 | [diff] [blame] | 5034 | UpdateProviderPolicy(policies2); |
| 5035 | |
| 5036 | // Policy should allow ending tasks again. |
avi | 24d693f | 2016-08-06 18:03:52 | [diff] [blame] | 5037 | EXPECT_TRUE(task_manager::TaskManagerInterface::IsEndProcessEnabled()); |
hunyadym | e7a3229 | 2016-04-20 00:23:43 | [diff] [blame] | 5038 | } |
| 5039 | |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5040 | // Test that when password protection warning trigger is set for users who are |
| 5041 | // not signed-into Chrome, Chrome password protection service gets the correct |
| 5042 | // value. |
| 5043 | IN_PROC_BROWSER_TEST_F(PolicyTest, |
| 5044 | PasswordProtectionWarningTriggerNotLoggedIn) { |
| 5045 | MockPasswordProtectionService mock_service( |
| 5046 | g_browser_process->safe_browsing_service(), browser()->profile()); |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5047 | |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5048 | // If user is not signed-in, |GetPasswordProtectionWarningTriggerPref(...)| |
Bettina | 06c3237 | 2019-04-16 16:53:55 | [diff] [blame] | 5049 | // should return |PHISHING_REUSE| unless specified by policy. |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5050 | EXPECT_CALL(mock_service, GetSyncAccountType()) |
| 5051 | .WillRepeatedly(Return(safe_browsing::LoginReputationClientRequest:: |
| 5052 | PasswordReuseEvent::NOT_SIGNED_IN)); |
Jialiu Lin | 219b9786 | 2018-01-27 02:39:59 | [diff] [blame] | 5053 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
Jialiu Lin | 219b9786 | 2018-01-27 02:39:59 | [diff] [blame] | 5054 | EXPECT_FALSE(prefs->FindPreference(prefs::kPasswordProtectionWarningTrigger) |
| 5055 | ->IsManaged()); |
Bettina | 06c3237 | 2019-04-16 16:53:55 | [diff] [blame] | 5056 | EXPECT_EQ(safe_browsing::PHISHING_REUSE, |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5057 | mock_service.GetPasswordProtectionWarningTriggerPref()); |
Jialiu Lin | 219b9786 | 2018-01-27 02:39:59 | [diff] [blame] | 5058 | // Sets the enterprise policy to 1 (a.k.a PASSWORD_REUSE). |
| 5059 | PolicyMap policies; |
| 5060 | policies.Set(key::kPasswordProtectionWarningTrigger, POLICY_LEVEL_MANDATORY, |
| 5061 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5062 | std::make_unique<base::Value>(1), nullptr); |
| 5063 | UpdateProviderPolicy(policies); |
| 5064 | EXPECT_TRUE(prefs->FindPreference(prefs::kPasswordProtectionWarningTrigger) |
| 5065 | ->IsManaged()); |
Jialiu Lin | 49602f04 | 2018-06-14 19:50:06 | [diff] [blame] | 5066 | EXPECT_EQ(safe_browsing::PASSWORD_REUSE, |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5067 | mock_service.GetPasswordProtectionWarningTriggerPref()); |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5068 | // Sets the enterprise policy to 2 (a.k.a PHISHING_REUSE). |
| 5069 | policies.Set(key::kPasswordProtectionWarningTrigger, POLICY_LEVEL_MANDATORY, |
| 5070 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5071 | std::make_unique<base::Value>(2), nullptr); |
| 5072 | UpdateProviderPolicy(policies); |
Jialiu Lin | 49602f04 | 2018-06-14 19:50:06 | [diff] [blame] | 5073 | EXPECT_EQ(safe_browsing::PHISHING_REUSE, |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5074 | mock_service.GetPasswordProtectionWarningTriggerPref()); |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5075 | } |
| 5076 | |
| 5077 | // Test that when password protection warning trigger is set for Gmail users, |
| 5078 | // Chrome password protection service gets the correct |
| 5079 | // value. |
| 5080 | IN_PROC_BROWSER_TEST_F(PolicyTest, PasswordProtectionWarningTriggerGmail) { |
| 5081 | MockPasswordProtectionService mock_service( |
| 5082 | g_browser_process->safe_browsing_service(), browser()->profile()); |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5083 | |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5084 | // If user is a Gmail user, |GetPasswordProtectionWarningTriggerPref(...)| |
| 5085 | // should return |PHISHING_REUSE| unless specified by policy. |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5086 | EXPECT_CALL(mock_service, GetSyncAccountType()) |
| 5087 | .WillRepeatedly(Return(safe_browsing::LoginReputationClientRequest:: |
| 5088 | PasswordReuseEvent::GMAIL)); |
| 5089 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
| 5090 | EXPECT_FALSE(prefs->FindPreference(prefs::kPasswordProtectionWarningTrigger) |
| 5091 | ->IsManaged()); |
| 5092 | EXPECT_EQ(safe_browsing::PHISHING_REUSE, |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5093 | mock_service.GetPasswordProtectionWarningTriggerPref()); |
Bettina | 06c3237 | 2019-04-16 16:53:55 | [diff] [blame] | 5094 | // Sets the enterprise policy to 1 (a.k.a PASSWORD_REUSE). Gmail accounts |
| 5095 | // should always return PHISHING_REUSE regardless of what the policy is set |
| 5096 | // to. |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5097 | PolicyMap policies; |
| 5098 | policies.Set(key::kPasswordProtectionWarningTrigger, POLICY_LEVEL_MANDATORY, |
| 5099 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5100 | std::make_unique<base::Value>(1), nullptr); |
Jialiu Lin | 219b9786 | 2018-01-27 02:39:59 | [diff] [blame] | 5101 | UpdateProviderPolicy(policies); |
| 5102 | EXPECT_TRUE(prefs->FindPreference(prefs::kPasswordProtectionWarningTrigger) |
| 5103 | ->IsManaged()); |
Bettina | 06c3237 | 2019-04-16 16:53:55 | [diff] [blame] | 5104 | EXPECT_EQ(safe_browsing::PHISHING_REUSE, |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5105 | mock_service.GetPasswordProtectionWarningTriggerPref()); |
Jialiu Lin | 219b9786 | 2018-01-27 02:39:59 | [diff] [blame] | 5106 | // Sets the enterprise policy to 2 (a.k.a PHISHING_REUSE). |
| 5107 | policies.Set(key::kPasswordProtectionWarningTrigger, POLICY_LEVEL_MANDATORY, |
| 5108 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5109 | std::make_unique<base::Value>(2), nullptr); |
Jialiu Lin | 219b9786 | 2018-01-27 02:39:59 | [diff] [blame] | 5110 | UpdateProviderPolicy(policies); |
| 5111 | EXPECT_EQ(safe_browsing::PHISHING_REUSE, |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5112 | mock_service.GetPasswordProtectionWarningTriggerPref()); |
Jialiu Lin | 219b9786 | 2018-01-27 02:39:59 | [diff] [blame] | 5113 | } |
| 5114 | |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5115 | // Test that when password protection warning trigger is set for GSuite users, |
| 5116 | // Chrome password protection service gets the correct value. |
| 5117 | IN_PROC_BROWSER_TEST_F(PolicyTest, PasswordProtectionWarningTriggerGSuite) { |
| 5118 | MockPasswordProtectionService mock_service( |
| 5119 | g_browser_process->safe_browsing_service(), browser()->profile()); |
| 5120 | EXPECT_CALL(mock_service, GetSyncAccountType()) |
| 5121 | .WillRepeatedly(Return(safe_browsing::LoginReputationClientRequest:: |
| 5122 | PasswordReuseEvent::GSUITE)); |
Jialiu Lin | 92b357f | 2018-04-24 17:08:45 | [diff] [blame] | 5123 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5124 | PolicyMap policies; |
| 5125 | |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5126 | // If user is a GSuite user, |GetPasswordProtectionWarningTriggerPref(...)| |
Bettina | 06c3237 | 2019-04-16 16:53:55 | [diff] [blame] | 5127 | // should return |PHISHING_REUSE| unless specified by policy. |
Jialiu Lin | 92b357f | 2018-04-24 17:08:45 | [diff] [blame] | 5128 | EXPECT_FALSE(prefs->FindPreference(prefs::kPasswordProtectionWarningTrigger) |
| 5129 | ->IsManaged()); |
Bettina | 06c3237 | 2019-04-16 16:53:55 | [diff] [blame] | 5130 | EXPECT_EQ(safe_browsing::PHISHING_REUSE, |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5131 | mock_service.GetPasswordProtectionWarningTriggerPref()); |
Jialiu Lin | 92b357f | 2018-04-24 17:08:45 | [diff] [blame] | 5132 | // Sets the enterprise policy to 1 (a.k.a PASSWORD_REUSE). |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5133 | policies.Set(key::kPasswordProtectionWarningTrigger, POLICY_LEVEL_MANDATORY, |
| 5134 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5135 | std::make_unique<base::Value>(1), nullptr); |
| 5136 | UpdateProviderPolicy(policies); |
Jialiu Lin | 92b357f | 2018-04-24 17:08:45 | [diff] [blame] | 5137 | EXPECT_TRUE(prefs->FindPreference(prefs::kPasswordProtectionWarningTrigger) |
| 5138 | ->IsManaged()); |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5139 | EXPECT_EQ(safe_browsing::PASSWORD_REUSE, |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5140 | mock_service.GetPasswordProtectionWarningTriggerPref()); |
Jialiu Lin | 92b357f | 2018-04-24 17:08:45 | [diff] [blame] | 5141 | // Sets the enterprise policy to 2 (a.k.a PHISHING_REUSE). |
Jialiu Lin | 4d7c604 | 2018-04-04 17:45:35 | [diff] [blame] | 5142 | policies.Set(key::kPasswordProtectionWarningTrigger, POLICY_LEVEL_MANDATORY, |
| 5143 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5144 | std::make_unique<base::Value>(2), nullptr); |
| 5145 | UpdateProviderPolicy(policies); |
| 5146 | EXPECT_EQ(safe_browsing::PHISHING_REUSE, |
Jialiu Lin | 1d1a55e | 2018-05-18 17:40:15 | [diff] [blame] | 5147 | mock_service.GetPasswordProtectionWarningTriggerPref()); |
Jialiu Lin | 219b9786 | 2018-01-27 02:39:59 | [diff] [blame] | 5148 | } |
| 5149 | |
Jialiu Lin | 924ee4d | 2018-02-13 20:34:40 | [diff] [blame] | 5150 | // Test that when safe browsing whitelist domains are set by policy, safe |
| 5151 | // browsing service gets the correct value. |
| 5152 | IN_PROC_BROWSER_TEST_F(PolicyTest, SafeBrowsingWhitelistDomains) { |
| 5153 | // Without setting up the enterprise policy, |
| 5154 | // |GetSafeBrowsingDomainsPref(..) should return empty list. |
| 5155 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
| 5156 | EXPECT_FALSE( |
| 5157 | prefs->FindPreference(prefs::kSafeBrowsingWhitelistDomains)->IsManaged()); |
| 5158 | std::vector<std::string> canonicalized_domains; |
| 5159 | safe_browsing::GetSafeBrowsingWhitelistDomainsPref(*prefs, |
| 5160 | &canonicalized_domains); |
| 5161 | EXPECT_TRUE(canonicalized_domains.empty()); |
| 5162 | |
| 5163 | // Add 2 whitelisted domains to this policy. |
| 5164 | PolicyMap policies; |
| 5165 | base::ListValue whitelist_domains; |
| 5166 | whitelist_domains.AppendString("mydomain.com"); |
| 5167 | whitelist_domains.AppendString("mydomain.net"); |
| 5168 | policies.Set(key::kSafeBrowsingWhitelistDomains, POLICY_LEVEL_MANDATORY, |
| 5169 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5170 | whitelist_domains.CreateDeepCopy(), nullptr); |
| 5171 | UpdateProviderPolicy(policies); |
| 5172 | EXPECT_TRUE( |
| 5173 | prefs->FindPreference(prefs::kSafeBrowsingWhitelistDomains)->IsManaged()); |
| 5174 | safe_browsing::GetSafeBrowsingWhitelistDomainsPref(*prefs, |
| 5175 | &canonicalized_domains); |
| 5176 | EXPECT_EQ(2u, canonicalized_domains.size()); |
| 5177 | EXPECT_EQ("mydomain.com", canonicalized_domains[0]); |
| 5178 | EXPECT_EQ("mydomain.net", canonicalized_domains[1]); |
| 5179 | |
| 5180 | // Invalid domains will be skipped. |
| 5181 | whitelist_domains.Clear(); |
| 5182 | whitelist_domains.AppendString(std::string("%EF%BF%BDzyx.com")); |
| 5183 | policies.Set(key::kSafeBrowsingWhitelistDomains, POLICY_LEVEL_MANDATORY, |
| 5184 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5185 | whitelist_domains.CreateDeepCopy(), nullptr); |
| 5186 | UpdateProviderPolicy(policies); |
| 5187 | EXPECT_TRUE( |
| 5188 | prefs->FindPreference(prefs::kSafeBrowsingWhitelistDomains)->IsManaged()); |
| 5189 | canonicalized_domains.clear(); |
| 5190 | safe_browsing::GetSafeBrowsingWhitelistDomainsPref(*prefs, |
| 5191 | &canonicalized_domains); |
| 5192 | EXPECT_TRUE(canonicalized_domains.empty()); |
| 5193 | } |
| 5194 | |
| 5195 | // Test that when password protection login URLs are set by policy, password |
| 5196 | // protection service gets the correct value. |
| 5197 | IN_PROC_BROWSER_TEST_F(PolicyTest, PasswordProtectionLoginURLs) { |
| 5198 | // Without setting up the enterprise policy, |
| 5199 | // |GetPasswordProtectionLoginURLsPref(..) should return empty list. |
| 5200 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
Jialiu Lin | 924ee4d | 2018-02-13 20:34:40 | [diff] [blame] | 5201 | EXPECT_FALSE( |
| 5202 | prefs->FindPreference(prefs::kPasswordProtectionLoginURLs)->IsManaged()); |
| 5203 | std::vector<GURL> login_urls; |
Jialiu Lin | c534b0d | 2018-03-01 16:51:52 | [diff] [blame] | 5204 | safe_browsing::GetPasswordProtectionLoginURLsPref(*prefs, &login_urls); |
Jialiu Lin | 924ee4d | 2018-02-13 20:34:40 | [diff] [blame] | 5205 | EXPECT_TRUE(login_urls.empty()); |
| 5206 | |
| 5207 | // Add 2 login URLs to this enterprise policy . |
| 5208 | PolicyMap policies; |
| 5209 | base::ListValue login_url_values; |
| 5210 | login_url_values.AppendString("https://login.mydomain.com"); |
| 5211 | login_url_values.AppendString("https://mydomian.com/login.html"); |
| 5212 | policies.Set(key::kPasswordProtectionLoginURLs, POLICY_LEVEL_MANDATORY, |
| 5213 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5214 | login_url_values.CreateDeepCopy(), nullptr); |
| 5215 | UpdateProviderPolicy(policies); |
| 5216 | EXPECT_TRUE( |
| 5217 | prefs->FindPreference(prefs::kPasswordProtectionLoginURLs)->IsManaged()); |
Jialiu Lin | c534b0d | 2018-03-01 16:51:52 | [diff] [blame] | 5218 | safe_browsing::GetPasswordProtectionLoginURLsPref(*prefs, &login_urls); |
Jialiu Lin | 924ee4d | 2018-02-13 20:34:40 | [diff] [blame] | 5219 | EXPECT_EQ(2u, login_urls.size()); |
| 5220 | EXPECT_EQ(GURL("https://login.mydomain.com"), login_urls[0]); |
| 5221 | EXPECT_EQ(GURL("https://mydomian.com/login.html"), login_urls[1]); |
| 5222 | |
| 5223 | // Verify non-http/https schemes, or invalid URLs will be skipped. |
| 5224 | login_url_values.Clear(); |
| 5225 | login_url_values.AppendString(std::string("invalid")); |
| 5226 | login_url_values.AppendString(std::string("ftp://login.mydomain.com")); |
| 5227 | policies.Set(key::kPasswordProtectionLoginURLs, POLICY_LEVEL_MANDATORY, |
| 5228 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5229 | login_url_values.CreateDeepCopy(), nullptr); |
| 5230 | UpdateProviderPolicy(policies); |
| 5231 | EXPECT_TRUE( |
| 5232 | prefs->FindPreference(prefs::kPasswordProtectionLoginURLs)->IsManaged()); |
| 5233 | login_urls.clear(); |
Jialiu Lin | c534b0d | 2018-03-01 16:51:52 | [diff] [blame] | 5234 | safe_browsing::GetPasswordProtectionLoginURLsPref(*prefs, &login_urls); |
Jialiu Lin | 924ee4d | 2018-02-13 20:34:40 | [diff] [blame] | 5235 | EXPECT_TRUE(login_urls.empty()); |
| 5236 | } |
| 5237 | |
| 5238 | // Test that when password protection change password URL is set by policy, |
| 5239 | // password protection service gets the correct value. |
| 5240 | IN_PROC_BROWSER_TEST_F(PolicyTest, PasswordProtectionChangePasswordURL) { |
| 5241 | // Without setting up the enterprise policy, |
Jialiu Lin | 49602f04 | 2018-06-14 19:50:06 | [diff] [blame] | 5242 | // |GetEnterpriseChangePasswordURL(..) should return default GAIA change |
| 5243 | // password URL. |
Jialiu Lin | 924ee4d | 2018-02-13 20:34:40 | [diff] [blame] | 5244 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
| 5245 | const safe_browsing::ChromePasswordProtectionService* const service = |
| 5246 | safe_browsing::ChromePasswordProtectionService:: |
| 5247 | GetPasswordProtectionService(browser()->profile()); |
| 5248 | EXPECT_FALSE( |
| 5249 | prefs->FindPreference(prefs::kPasswordProtectionChangePasswordURL) |
| 5250 | ->IsManaged()); |
| 5251 | EXPECT_FALSE(prefs->HasPrefPath(prefs::kPasswordProtectionChangePasswordURL)); |
Jialiu Lin | 49602f04 | 2018-06-14 19:50:06 | [diff] [blame] | 5252 | EXPECT_TRUE(service->GetEnterpriseChangePasswordURL().DomainIs( |
| 5253 | "accounts.google.com")); |
Jialiu Lin | 924ee4d | 2018-02-13 20:34:40 | [diff] [blame] | 5254 | |
| 5255 | // Add change password URL to this enterprise policy . |
| 5256 | PolicyMap policies; |
| 5257 | policies.Set( |
| 5258 | key::kPasswordProtectionChangePasswordURL, POLICY_LEVEL_MANDATORY, |
| 5259 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5260 | base::WrapUnique(new base::Value("https://changepassword.mydomain.com")), |
| 5261 | nullptr); |
| 5262 | UpdateProviderPolicy(policies); |
| 5263 | EXPECT_TRUE(prefs->FindPreference(prefs::kPasswordProtectionChangePasswordURL) |
| 5264 | ->IsManaged()); |
| 5265 | EXPECT_EQ(GURL("https://changepassword.mydomain.com"), |
Jialiu Lin | 49602f04 | 2018-06-14 19:50:06 | [diff] [blame] | 5266 | service->GetEnterpriseChangePasswordURL()); |
Jialiu Lin | 924ee4d | 2018-02-13 20:34:40 | [diff] [blame] | 5267 | |
| 5268 | // Verify non-http/https change password URL will be skipped. |
| 5269 | policies.Set(key::kPasswordProtectionChangePasswordURL, |
| 5270 | POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5271 | base::WrapUnique(new base::Value("data:text/html,login page")), |
| 5272 | nullptr); |
| 5273 | UpdateProviderPolicy(policies); |
| 5274 | EXPECT_TRUE(prefs->FindPreference(prefs::kPasswordProtectionChangePasswordURL) |
| 5275 | ->IsManaged()); |
Jialiu Lin | 49602f04 | 2018-06-14 19:50:06 | [diff] [blame] | 5276 | EXPECT_TRUE(service->GetEnterpriseChangePasswordURL().DomainIs( |
| 5277 | "accounts.google.com")); |
Jialiu Lin | 924ee4d | 2018-02-13 20:34:40 | [diff] [blame] | 5278 | } |
| 5279 | |
imcheng | c2b6c18 | 2016-06-07 21:31:16 | [diff] [blame] | 5280 | // Sets the proper policy before the browser is started. |
| 5281 | template<bool enable> |
| 5282 | class MediaRouterPolicyTest : public PolicyTest { |
| 5283 | public: |
| 5284 | void SetUpInProcessBrowserTestFixture() override { |
| 5285 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 5286 | PolicyMap policies; |
| 5287 | policies.Set(key::kEnableMediaRouter, POLICY_LEVEL_MANDATORY, |
| 5288 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 5289 | std::make_unique<base::Value>(enable), nullptr); |
imcheng | c2b6c18 | 2016-06-07 21:31:16 | [diff] [blame] | 5290 | provider_.UpdateChromePolicy(policies); |
| 5291 | } |
| 5292 | }; |
| 5293 | |
| 5294 | using MediaRouterEnabledPolicyTest = MediaRouterPolicyTest<true>; |
| 5295 | using MediaRouterDisabledPolicyTest = MediaRouterPolicyTest<false>; |
| 5296 | |
| 5297 | IN_PROC_BROWSER_TEST_F(MediaRouterEnabledPolicyTest, MediaRouterEnabled) { |
| 5298 | EXPECT_TRUE(media_router::MediaRouterEnabled(browser()->profile())); |
| 5299 | } |
| 5300 | |
| 5301 | IN_PROC_BROWSER_TEST_F(MediaRouterDisabledPolicyTest, MediaRouterDisabled) { |
| 5302 | EXPECT_FALSE(media_router::MediaRouterEnabled(browser()->profile())); |
| 5303 | } |
takumif | 1a5f285 | 2017-01-31 19:10:50 | [diff] [blame] | 5304 | |
Derek Cheng | 3447838 | 2018-04-07 00:32:59 | [diff] [blame] | 5305 | #if !defined(OS_ANDROID) |
takumif | 1a5f285 | 2017-01-31 19:10:50 | [diff] [blame] | 5306 | template <bool enable> |
| 5307 | class MediaRouterActionPolicyTest : public PolicyTest { |
| 5308 | public: |
| 5309 | void SetUpInProcessBrowserTestFixture() override { |
| 5310 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 5311 | PolicyMap policies; |
| 5312 | policies.Set(key::kShowCastIconInToolbar, POLICY_LEVEL_MANDATORY, |
| 5313 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 5314 | std::make_unique<base::Value>(enable), nullptr); |
takumif | 1a5f285 | 2017-01-31 19:10:50 | [diff] [blame] | 5315 | provider_.UpdateChromePolicy(policies); |
| 5316 | } |
takumif | 1a5f285 | 2017-01-31 19:10:50 | [diff] [blame] | 5317 | }; |
| 5318 | |
| 5319 | using MediaRouterActionEnabledPolicyTest = MediaRouterActionPolicyTest<true>; |
| 5320 | using MediaRouterActionDisabledPolicyTest = MediaRouterActionPolicyTest<false>; |
| 5321 | |
| 5322 | IN_PROC_BROWSER_TEST_F(MediaRouterActionEnabledPolicyTest, |
| 5323 | MediaRouterActionEnabled) { |
| 5324 | EXPECT_TRUE( |
| 5325 | MediaRouterActionController::IsActionShownByPolicy(browser()->profile())); |
takumif | 1a5f285 | 2017-01-31 19:10:50 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | IN_PROC_BROWSER_TEST_F(MediaRouterActionDisabledPolicyTest, |
| 5329 | MediaRouterActionDisabled) { |
| 5330 | EXPECT_FALSE( |
| 5331 | MediaRouterActionController::IsActionShownByPolicy(browser()->profile())); |
takumif | 1a5f285 | 2017-01-31 19:10:50 | [diff] [blame] | 5332 | } |
imcheng | c2b6c18 | 2016-06-07 21:31:16 | [diff] [blame] | 5333 | |
Derek Cheng | 3447838 | 2018-04-07 00:32:59 | [diff] [blame] | 5334 | class MediaRouterCastAllowAllIPsPolicyTest |
| 5335 | : public PolicyTest, |
| 5336 | public testing::WithParamInterface<bool> { |
| 5337 | public: |
| 5338 | void SetUpInProcessBrowserTestFixture() override { |
| 5339 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 5340 | PolicyMap policies; |
| 5341 | policies.Set(key::kMediaRouterCastAllowAllIPs, POLICY_LEVEL_MANDATORY, |
| 5342 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5343 | std::make_unique<base::Value>(is_enabled()), nullptr); |
| 5344 | provider_.UpdateChromePolicy(policies); |
| 5345 | } |
| 5346 | |
| 5347 | bool is_enabled() const { return GetParam(); } |
| 5348 | }; |
| 5349 | |
| 5350 | IN_PROC_BROWSER_TEST_P(MediaRouterCastAllowAllIPsPolicyTest, RunTest) { |
| 5351 | PrefService* const pref = g_browser_process->local_state(); |
| 5352 | ASSERT_TRUE(pref); |
| 5353 | EXPECT_EQ(is_enabled(), |
| 5354 | pref->GetBoolean(media_router::prefs::kMediaRouterCastAllowAllIPs)); |
| 5355 | EXPECT_TRUE(pref->IsManagedPreference( |
| 5356 | media_router::prefs::kMediaRouterCastAllowAllIPs)); |
| 5357 | EXPECT_EQ(is_enabled(), media_router::GetCastAllowAllIPsPref(pref)); |
| 5358 | } |
| 5359 | |
Victor Costan | e5e9151 | 2019-02-13 08:24:02 | [diff] [blame] | 5360 | INSTANTIATE_TEST_SUITE_P(MediaRouterCastAllowAllIPsPolicyTestInstance, |
| 5361 | MediaRouterCastAllowAllIPsPolicyTest, |
| 5362 | testing::Values(true, false)); |
Derek Cheng | 3447838 | 2018-04-07 00:32:59 | [diff] [blame] | 5363 | #endif // !defined(OS_ANDROID) |
| 5364 | |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 5365 | // Sets the proper policy before the browser is started. |
| 5366 | template <bool enable> |
| 5367 | class WebRtcUdpPortRangePolicyTest : public PolicyTest { |
| 5368 | public: |
| 5369 | WebRtcUdpPortRangePolicyTest() = default; |
| 5370 | void SetUpInProcessBrowserTestFixture() override { |
| 5371 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 5372 | PolicyMap policies; |
| 5373 | if (enable) { |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 5374 | policies.Set(key::kWebRtcUdpPortRange, POLICY_LEVEL_MANDATORY, |
| 5375 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 5376 | std::make_unique<base::Value>(kTestWebRtcUdpPortRange), |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 5377 | nullptr); |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 5378 | } |
| 5379 | provider_.UpdateChromePolicy(policies); |
| 5380 | } |
| 5381 | |
| 5382 | private: |
| 5383 | DISALLOW_COPY_AND_ASSIGN(WebRtcUdpPortRangePolicyTest<enable>); |
| 5384 | }; |
| 5385 | |
| 5386 | using WebRtcUdpPortRangeEnabledPolicyTest = WebRtcUdpPortRangePolicyTest<true>; |
| 5387 | using WebRtcUdpPortRangeDisabledPolicyTest = |
| 5388 | WebRtcUdpPortRangePolicyTest<false>; |
| 5389 | |
| 5390 | IN_PROC_BROWSER_TEST_F(WebRtcUdpPortRangeEnabledPolicyTest, |
| 5391 | WebRtcUdpPortRangeEnabled) { |
| 5392 | std::string port_range; |
| 5393 | const PrefService::Preference* pref = |
| 5394 | user_prefs::UserPrefs::Get(browser()->profile()) |
| 5395 | ->FindPreference(prefs::kWebRTCUDPPortRange); |
| 5396 | pref->GetValue()->GetAsString(&port_range); |
| 5397 | EXPECT_EQ(kTestWebRtcUdpPortRange, port_range); |
| 5398 | } |
| 5399 | |
| 5400 | IN_PROC_BROWSER_TEST_F(WebRtcUdpPortRangeDisabledPolicyTest, |
| 5401 | WebRtcUdpPortRangeDisabled) { |
| 5402 | std::string port_range; |
| 5403 | const PrefService::Preference* pref = |
| 5404 | user_prefs::UserPrefs::Get(browser()->profile()) |
| 5405 | ->FindPreference(prefs::kWebRTCUDPPortRange); |
| 5406 | pref->GetValue()->GetAsString(&port_range); |
| 5407 | EXPECT_TRUE(port_range.empty()); |
| 5408 | } |
guidou | ca055a54 | 2016-08-11 11:15:53 | [diff] [blame] | 5409 | |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5410 | // Tests the ComponentUpdater's EnabledComponentUpdates group policy by |
| 5411 | // calling the OnDemand interface. It uses the network interceptor to inspect |
| 5412 | // the presence of the updatedisabled="true" attribute in the update check |
| 5413 | // request. The update check request is expected to fail, since CUP fails. |
| 5414 | class ComponentUpdaterPolicyTest : public PolicyTest { |
| 5415 | public: |
| 5416 | ComponentUpdaterPolicyTest(); |
| 5417 | ~ComponentUpdaterPolicyTest() override; |
| 5418 | |
Antonio Gomes | b616250 | 2018-06-28 20:21:55 | [diff] [blame] | 5419 | void SetUpCommandLine(base::CommandLine* command_line) override; |
| 5420 | void SetUpOnMainThread() override; |
| 5421 | |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5422 | protected: |
| 5423 | using TestCaseAction = void (ComponentUpdaterPolicyTest::*)(); |
| 5424 | using TestCase = std::pair<TestCaseAction, TestCaseAction>; |
| 5425 | |
| 5426 | // These test scenarios run as part of one test case by using the |
| 5427 | // CallAsync helper, which calls OnDemand, then chains up to the next |
| 5428 | // scenario when the OnDemandComplete callback fires. |
| 5429 | void DefaultPolicy_GroupPolicySupported(); |
| 5430 | void FinishDefaultPolicy_GroupPolicySupported(); |
| 5431 | |
| 5432 | void DefaultPolicy_GroupPolicyNotSupported(); |
| 5433 | void FinishDefaultPolicy_GroupPolicyNotSupported(); |
| 5434 | |
| 5435 | void EnabledPolicy_GroupPolicySupported(); |
| 5436 | void FinishEnabledPolicy_GroupPolicySupported(); |
| 5437 | |
| 5438 | void EnabledPolicy_GroupPolicyNotSupported(); |
| 5439 | void FinishEnabledPolicy_GroupPolicyNotSupported(); |
| 5440 | |
| 5441 | void DisabledPolicy_GroupPolicySupported(); |
| 5442 | void FinishDisabled_PolicyGroupPolicySupported(); |
| 5443 | |
| 5444 | void DisabledPolicy_GroupPolicyNotSupported(); |
| 5445 | void FinishDisabledPolicy_GroupPolicyNotSupported(); |
| 5446 | |
| 5447 | void BeginTest(); |
| 5448 | void EndTest(); |
| 5449 | |
| 5450 | void UpdateComponent(const update_client::CrxComponent& crx_component); |
| 5451 | void CallAsync(TestCaseAction action); |
| 5452 | void VerifyExpectations(bool update_disabled); |
| 5453 | |
| 5454 | void SetEnableComponentUpdates(bool enable_component_updates); |
| 5455 | |
| 5456 | static update_client::CrxComponent MakeCrxComponent( |
| 5457 | bool supports_group_policy_enable_component_updates); |
| 5458 | |
| 5459 | TestCase cur_test_case_; |
| 5460 | |
| 5461 | static const char component_id_[]; |
| 5462 | |
| 5463 | static const bool kUpdateDisabled = true; |
| 5464 | |
| 5465 | private: |
sorin | 7b865052 | 2016-11-02 18:23:41 | [diff] [blame] | 5466 | void OnDemandComplete(update_client::Error error); |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5467 | |
Antonio Gomes | b616250 | 2018-06-28 20:21:55 | [diff] [blame] | 5468 | std::unique_ptr<update_client::URLLoaderPostInterceptor> post_interceptor_; |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5469 | |
| 5470 | // This member is owned by g_browser_process; |
Sorin Jianu | 015681f | 2018-04-04 16:43:33 | [diff] [blame] | 5471 | component_updater::ComponentUpdateService* cus_ = nullptr; |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5472 | |
Antonio Gomes | b616250 | 2018-06-28 20:21:55 | [diff] [blame] | 5473 | net::EmbeddedTestServer https_server_; |
| 5474 | |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5475 | DISALLOW_COPY_AND_ASSIGN(ComponentUpdaterPolicyTest); |
| 5476 | }; |
| 5477 | |
| 5478 | const char ComponentUpdaterPolicyTest::component_id_[] = |
| 5479 | "jebgalgnebhfojomionfpkfelancnnkf"; |
| 5480 | |
Antonio Gomes | b616250 | 2018-06-28 20:21:55 | [diff] [blame] | 5481 | ComponentUpdaterPolicyTest::ComponentUpdaterPolicyTest() |
| 5482 | : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {} |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5483 | |
| 5484 | ComponentUpdaterPolicyTest::~ComponentUpdaterPolicyTest() {} |
| 5485 | |
Antonio Gomes | b616250 | 2018-06-28 20:21:55 | [diff] [blame] | 5486 | void ComponentUpdaterPolicyTest::SetUpCommandLine( |
| 5487 | base::CommandLine* command_line) { |
| 5488 | // Set up the mock server, for the network requests. |
| 5489 | ASSERT_TRUE(https_server_.InitializeAndListen()); |
| 5490 | const std::string val = base::StringPrintf( |
| 5491 | "url-source=%s", https_server_.GetURL("/service/update2").spec().c_str()); |
| 5492 | command_line->AppendSwitchASCII(switches::kComponentUpdater, val.c_str()); |
| 5493 | PolicyTest::SetUpCommandLine(command_line); |
| 5494 | } |
| 5495 | |
| 5496 | void ComponentUpdaterPolicyTest::SetUpOnMainThread() { |
| 5497 | const auto config = component_updater::MakeChromeComponentUpdaterConfigurator( |
| 5498 | base::CommandLine::ForCurrentProcess(), g_browser_process->local_state()); |
| 5499 | const auto urls = config->UpdateUrl(); |
| 5500 | ASSERT_EQ(1u, urls.size()); |
| 5501 | post_interceptor_ = std::make_unique<update_client::URLLoaderPostInterceptor>( |
| 5502 | urls, &https_server_); |
| 5503 | |
| 5504 | https_server_.StartAcceptingConnections(); |
| 5505 | PolicyTest::SetUpOnMainThread(); |
| 5506 | } |
| 5507 | |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5508 | void ComponentUpdaterPolicyTest::SetEnableComponentUpdates( |
| 5509 | bool enable_component_updates) { |
| 5510 | PolicyMap policies; |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 5511 | policies.Set(key::kComponentUpdatesEnabled, POLICY_LEVEL_MANDATORY, |
| 5512 | POLICY_SCOPE_MACHINE, POLICY_SOURCE_ENTERPRISE_DEFAULT, |
| 5513 | base::WrapUnique(new base::Value(enable_component_updates)), |
| 5514 | nullptr); |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5515 | UpdateProviderPolicy(policies); |
| 5516 | } |
| 5517 | |
| 5518 | update_client::CrxComponent ComponentUpdaterPolicyTest::MakeCrxComponent( |
| 5519 | bool supports_group_policy_enable_component_updates) { |
| 5520 | class MockInstaller : public update_client::CrxInstaller { |
| 5521 | public: |
| 5522 | MockInstaller() {} |
| 5523 | |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 5524 | void Install(const base::FilePath& unpack_path, |
| 5525 | const std::string& public_key, |
Daniel Cheng | 5124995 | 2018-04-27 06:48:50 | [diff] [blame] | 5526 | Callback callback) override { |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 5527 | DoInstall(unpack_path, public_key, std::move(callback)); |
| 5528 | } |
| 5529 | |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5530 | MOCK_METHOD1(OnUpdateError, void(int error)); |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 5531 | MOCK_METHOD3(DoInstall, |
Sorin Jianu | 7aa6d1f | 2017-10-13 20:29:29 | [diff] [blame] | 5532 | void(const base::FilePath& unpack_path, |
Sorin Jianu | ea5534e9 | 2017-10-27 01:40:28 | [diff] [blame] | 5533 | const std::string& public_key, |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 5534 | const Callback& callback)); |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5535 | MOCK_METHOD2(GetInstalledFile, |
| 5536 | bool(const std::string& file, base::FilePath* installed_file)); |
| 5537 | MOCK_METHOD0(Uninstall, bool()); |
| 5538 | |
| 5539 | private: |
| 5540 | ~MockInstaller() override {} |
| 5541 | }; |
| 5542 | |
| 5543 | // component id "jebgalgnebhfojomionfpkfelancnnkf". |
| 5544 | static const uint8_t jebg_hash[] = { |
| 5545 | 0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec, 0x8e, 0xd5, 0xfa, |
| 5546 | 0x54, 0xb0, 0xd2, 0xdd, 0xa5, 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, |
| 5547 | 0xf6, 0xc4, 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}; |
| 5548 | |
| 5549 | // The component uses HTTPS only for network interception purposes. |
| 5550 | update_client::CrxComponent crx_component; |
| 5551 | crx_component.pk_hash.assign(std::begin(jebg_hash), std::end(jebg_hash)); |
pwnall | 8c3feb2 | 2016-09-01 21:10:44 | [diff] [blame] | 5552 | crx_component.version = base::Version("0.9"); |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5553 | crx_component.installer = scoped_refptr<MockInstaller>(new MockInstaller()); |
| 5554 | crx_component.requires_network_encryption = true; |
| 5555 | crx_component.supports_group_policy_enable_component_updates = |
| 5556 | supports_group_policy_enable_component_updates; |
| 5557 | |
| 5558 | return crx_component; |
| 5559 | } |
| 5560 | |
| 5561 | void ComponentUpdaterPolicyTest::UpdateComponent( |
| 5562 | const update_client::CrxComponent& crx_component) { |
| 5563 | post_interceptor_->Reset(); |
| 5564 | EXPECT_TRUE(post_interceptor_->ExpectRequest( |
Sorin Jianu | 015681f | 2018-04-04 16:43:33 | [diff] [blame] | 5565 | std::make_unique<update_client::PartialMatch>("updatecheck"))); |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5566 | EXPECT_TRUE(cus_->RegisterComponent(crx_component)); |
| 5567 | cus_->GetOnDemandUpdater().OnDemandUpdate( |
Sorin Jianu | d20ed853 | 2018-06-28 17:24:31 | [diff] [blame] | 5568 | component_id_, component_updater::OnDemandUpdater::Priority::FOREGROUND, |
| 5569 | base::BindOnce(&ComponentUpdaterPolicyTest::OnDemandComplete, |
| 5570 | base::Unretained(this))); |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | void ComponentUpdaterPolicyTest::CallAsync(TestCaseAction action) { |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 5574 | base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, |
| 5575 | base::BindOnce(action, base::Unretained(this))); |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5576 | } |
| 5577 | |
sorin | 7b865052 | 2016-11-02 18:23:41 | [diff] [blame] | 5578 | void ComponentUpdaterPolicyTest::OnDemandComplete(update_client::Error error) { |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5579 | CallAsync(cur_test_case_.second); |
| 5580 | } |
| 5581 | |
| 5582 | void ComponentUpdaterPolicyTest::BeginTest() { |
| 5583 | cus_ = g_browser_process->component_updater(); |
| 5584 | |
waffles | a4f53d4 | 2017-02-07 01:19:31 | [diff] [blame] | 5585 | const auto config = component_updater::MakeChromeComponentUpdaterConfigurator( |
Sorin Jianu | 556147d | 2018-01-19 21:55:21 | [diff] [blame] | 5586 | base::CommandLine::ForCurrentProcess(), g_browser_process->local_state()); |
waffles | a4f53d4 | 2017-02-07 01:19:31 | [diff] [blame] | 5587 | const auto urls = config->UpdateUrl(); |
| 5588 | ASSERT_TRUE(urls.size()); |
| 5589 | const GURL url = urls.front(); |
| 5590 | |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5591 | cur_test_case_ = std::make_pair( |
| 5592 | &ComponentUpdaterPolicyTest::DefaultPolicy_GroupPolicySupported, |
| 5593 | &ComponentUpdaterPolicyTest::FinishDefaultPolicy_GroupPolicySupported); |
| 5594 | |
| 5595 | CallAsync(cur_test_case_.first); |
| 5596 | } |
| 5597 | |
| 5598 | void ComponentUpdaterPolicyTest::EndTest() { |
Antonio Gomes | b616250 | 2018-06-28 20:21:55 | [diff] [blame] | 5599 | post_interceptor_.reset(); |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5600 | cus_ = nullptr; |
| 5601 | |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 5602 | base::RunLoop::QuitCurrentWhenIdleDeprecated(); |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | void ComponentUpdaterPolicyTest::VerifyExpectations(bool update_disabled) { |
| 5606 | EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| 5607 | << post_interceptor_->GetRequestsAsString(); |
| 5608 | ASSERT_EQ(1, post_interceptor_->GetCount()) |
| 5609 | << post_interceptor_->GetRequestsAsString(); |
Sorin Jianu | 55587d3 | 2018-11-14 21:43:27 | [diff] [blame] | 5610 | |
| 5611 | const auto& request = post_interceptor_->GetRequestBody(0); |
| 5612 | |
| 5613 | // Handle XML and JSON protocols. |
| 5614 | if (base::StartsWith(request, "<?xml", base::CompareCase::SENSITIVE)) { |
| 5615 | EXPECT_NE(std::string::npos, |
| 5616 | request.find(base::StringPrintf( |
| 5617 | "<updatecheck%s/>", |
| 5618 | update_disabled ? " updatedisabled=\"true\"" : ""))); |
| 5619 | } else if (base::StartsWith(request, R"({"request":{)", |
| 5620 | base::CompareCase::SENSITIVE)) { |
Lei Zhang | 025edc2 | 2019-02-16 05:02:25 | [diff] [blame] | 5621 | const auto root = base::JSONReader().ReadDeprecated(request); |
Sorin Jianu | 55587d3 | 2018-11-14 21:43:27 | [diff] [blame] | 5622 | ASSERT_TRUE(root); |
| 5623 | const auto* update_check = |
| 5624 | root->FindKey("request")->FindKey("app")->GetList()[0].FindKey( |
| 5625 | "updatecheck"); |
| 5626 | ASSERT_TRUE(update_check); |
| 5627 | if (update_disabled) { |
| 5628 | EXPECT_EQ(true, update_check->FindKey("updatedisabled")->GetBool()); |
| 5629 | } else { |
| 5630 | EXPECT_FALSE(update_check->FindKey("updatedisabled")); |
| 5631 | } |
| 5632 | } else { |
| 5633 | NOTREACHED(); |
| 5634 | } |
sorin | 0b99b8d | 2016-08-22 20:40:53 | [diff] [blame] | 5635 | } |
| 5636 | |
| 5637 | void ComponentUpdaterPolicyTest::DefaultPolicy_GroupPolicySupported() { |
| 5638 | UpdateComponent(MakeCrxComponent(true)); |
| 5639 | } |
| 5640 | |
| 5641 | void ComponentUpdaterPolicyTest::FinishDefaultPolicy_GroupPolicySupported() { |
| 5642 | // Default policy && policy support -> updates are enabled. |
| 5643 | VerifyExpectations(!kUpdateDisabled); |
| 5644 | |
| 5645 | cur_test_case_ = std::make_pair( |
| 5646 | &ComponentUpdaterPolicyTest::DefaultPolicy_GroupPolicyNotSupported, |
| 5647 | &ComponentUpdaterPolicyTest::FinishDefaultPolicy_GroupPolicyNotSupported); |
| 5648 | CallAsync(cur_test_case_.first); |
| 5649 | } |
| 5650 | |
| 5651 | void ComponentUpdaterPolicyTest::DefaultPolicy_GroupPolicyNotSupported() { |
| 5652 | UpdateComponent(MakeCrxComponent(false)); |
| 5653 | } |
| 5654 | |
| 5655 | void ComponentUpdaterPolicyTest::FinishDefaultPolicy_GroupPolicyNotSupported() { |
| 5656 | // Default policy && no policy support -> updates are enabled. |
| 5657 | VerifyExpectations(!kUpdateDisabled); |
| 5658 | |
| 5659 | cur_test_case_ = std::make_pair( |
| 5660 | &ComponentUpdaterPolicyTest::EnabledPolicy_GroupPolicySupported, |
| 5661 | &ComponentUpdaterPolicyTest::FinishEnabledPolicy_GroupPolicySupported); |
| 5662 | CallAsync(cur_test_case_.first); |
| 5663 | } |
| 5664 | |
| 5665 | void ComponentUpdaterPolicyTest::EnabledPolicy_GroupPolicySupported() { |
| 5666 | SetEnableComponentUpdates(true); |
| 5667 | UpdateComponent(MakeCrxComponent(true)); |
| 5668 | } |
| 5669 | |
| 5670 | void ComponentUpdaterPolicyTest::FinishEnabledPolicy_GroupPolicySupported() { |
| 5671 | // Updates enabled policy && policy support -> updates are enabled. |
| 5672 | VerifyExpectations(!kUpdateDisabled); |
| 5673 | |
| 5674 | cur_test_case_ = std::make_pair( |
| 5675 | &ComponentUpdaterPolicyTest::EnabledPolicy_GroupPolicyNotSupported, |
| 5676 | &ComponentUpdaterPolicyTest::FinishEnabledPolicy_GroupPolicyNotSupported); |
| 5677 | CallAsync(cur_test_case_.first); |
| 5678 | } |
| 5679 | |
| 5680 | void ComponentUpdaterPolicyTest::EnabledPolicy_GroupPolicyNotSupported() { |
| 5681 | SetEnableComponentUpdates(true); |
| 5682 | UpdateComponent(MakeCrxComponent(false)); |
| 5683 | } |
| 5684 | |
| 5685 | void ComponentUpdaterPolicyTest::FinishEnabledPolicy_GroupPolicyNotSupported() { |
| 5686 | // Updates enabled policy && no policy support -> updates are enabled. |
| 5687 | VerifyExpectations(!kUpdateDisabled); |
| 5688 | |
| 5689 | cur_test_case_ = std::make_pair( |
| 5690 | &ComponentUpdaterPolicyTest::DisabledPolicy_GroupPolicySupported, |
| 5691 | &ComponentUpdaterPolicyTest::FinishDisabled_PolicyGroupPolicySupported); |
| 5692 | CallAsync(cur_test_case_.first); |
| 5693 | } |
| 5694 | |
| 5695 | void ComponentUpdaterPolicyTest::DisabledPolicy_GroupPolicySupported() { |
| 5696 | SetEnableComponentUpdates(false); |
| 5697 | UpdateComponent(MakeCrxComponent(true)); |
| 5698 | } |
| 5699 | |
| 5700 | void ComponentUpdaterPolicyTest::FinishDisabled_PolicyGroupPolicySupported() { |
| 5701 | // Updates enabled policy && policy support -> updates are disabled. |
| 5702 | VerifyExpectations(kUpdateDisabled); |
| 5703 | |
| 5704 | cur_test_case_ = std::make_pair( |
| 5705 | &ComponentUpdaterPolicyTest::DisabledPolicy_GroupPolicyNotSupported, |
| 5706 | &ComponentUpdaterPolicyTest:: |
| 5707 | FinishDisabledPolicy_GroupPolicyNotSupported); |
| 5708 | CallAsync(cur_test_case_.first); |
| 5709 | } |
| 5710 | |
| 5711 | void ComponentUpdaterPolicyTest::DisabledPolicy_GroupPolicyNotSupported() { |
| 5712 | SetEnableComponentUpdates(false); |
| 5713 | UpdateComponent(MakeCrxComponent(false)); |
| 5714 | } |
| 5715 | |
| 5716 | void ComponentUpdaterPolicyTest:: |
| 5717 | FinishDisabledPolicy_GroupPolicyNotSupported() { |
| 5718 | // Updates enabled policy && no policy support -> updates are enabled. |
| 5719 | VerifyExpectations(!kUpdateDisabled); |
| 5720 | |
| 5721 | cur_test_case_ = TestCase(); |
| 5722 | CallAsync(&ComponentUpdaterPolicyTest::EndTest); |
| 5723 | } |
| 5724 | |
| 5725 | IN_PROC_BROWSER_TEST_F(ComponentUpdaterPolicyTest, EnabledComponentUpdates) { |
| 5726 | BeginTest(); |
| 5727 | base::RunLoop().Run(); |
| 5728 | } |
| 5729 | |
[email protected] | fb49060 | 2013-04-18 17:23:07 | [diff] [blame] | 5730 | #if !defined(OS_CHROMEOS) |
| 5731 | // Similar to PolicyTest but sets the proper policy before the browser is |
| 5732 | // started. |
| 5733 | class PolicyVariationsServiceTest : public PolicyTest { |
| 5734 | public: |
dcheng | 32ae6bbb | 2014-10-22 08:47:29 | [diff] [blame] | 5735 | void SetUpInProcessBrowserTestFixture() override { |
[email protected] | fb49060 | 2013-04-18 17:23:07 | [diff] [blame] | 5736 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 5737 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5738 | policies.Set(key::kVariationsRestrictParameter, POLICY_LEVEL_MANDATORY, |
| 5739 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 5740 | std::make_unique<base::Value>("restricted"), nullptr); |
[email protected] | fb49060 | 2013-04-18 17:23:07 | [diff] [blame] | 5741 | provider_.UpdateChromePolicy(policies); |
| 5742 | } |
| 5743 | }; |
| 5744 | |
| 5745 | IN_PROC_BROWSER_TEST_F(PolicyVariationsServiceTest, VariationsURLIsValid) { |
| 5746 | const std::string default_variations_url = |
blundell | 57bcfed | 2015-09-04 08:44:45 | [diff] [blame] | 5747 | variations::VariationsService::GetDefaultVariationsServerURLForTesting(); |
[email protected] | fb49060 | 2013-04-18 17:23:07 | [diff] [blame] | 5748 | |
Ilya Sherman | f65350f1 | 2017-07-12 19:25:32 | [diff] [blame] | 5749 | const GURL url = |
| 5750 | g_browser_process->variations_service()->GetVariationsServerURL( |
Carlos IL | a03ca60d | 2017-12-11 21:43:27 | [diff] [blame] | 5751 | variations::VariationsService::HttpOptions::USE_HTTPS); |
brettw | 66d1b81b | 2015-07-06 19:29:40 | [diff] [blame] | 5752 | EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, |
| 5753 | base::CompareCase::SENSITIVE)); |
[email protected] | a29ad21 | 2013-05-02 20:18:54 | [diff] [blame] | 5754 | std::string value; |
| 5755 | EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
| 5756 | EXPECT_EQ("restricted", value); |
[email protected] | fb49060 | 2013-04-18 17:23:07 | [diff] [blame] | 5757 | } |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5758 | |
| 5759 | IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistSelective) { |
| 5760 | base::ListValue blacklist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 5761 | blacklist.AppendString("host.name"); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5762 | PolicyMap policies; |
| 5763 | policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5764 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5765 | blacklist.CreateDeepCopy(), nullptr); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5766 | UpdateProviderPolicy(policies); |
| 5767 | |
Michael Giuffrida | b378399 | 2017-07-22 05:01:03 | [diff] [blame] | 5768 | EXPECT_EQ(extensions::MessagingDelegate::PolicyPermission::DISALLOW, |
Michael Giuffrida | 9e1a9f8 | 2017-08-08 14:23:29 | [diff] [blame] | 5769 | IsNativeMessagingHostAllowed(browser()->profile(), "host.name")); |
| 5770 | EXPECT_EQ( |
| 5771 | extensions::MessagingDelegate::PolicyPermission::ALLOW_ALL, |
| 5772 | IsNativeMessagingHostAllowed(browser()->profile(), "other.host.name")); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistWildcard) { |
| 5776 | base::ListValue blacklist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 5777 | blacklist.AppendString("*"); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5778 | PolicyMap policies; |
| 5779 | policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5780 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5781 | blacklist.CreateDeepCopy(), nullptr); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5782 | UpdateProviderPolicy(policies); |
| 5783 | |
Michael Giuffrida | b378399 | 2017-07-22 05:01:03 | [diff] [blame] | 5784 | EXPECT_EQ(extensions::MessagingDelegate::PolicyPermission::DISALLOW, |
Michael Giuffrida | 9e1a9f8 | 2017-08-08 14:23:29 | [diff] [blame] | 5785 | IsNativeMessagingHostAllowed(browser()->profile(), "host.name")); |
| 5786 | EXPECT_EQ( |
| 5787 | extensions::MessagingDelegate::PolicyPermission::DISALLOW, |
| 5788 | IsNativeMessagingHostAllowed(browser()->profile(), "other.host.name")); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingWhitelist) { |
| 5792 | base::ListValue blacklist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 5793 | blacklist.AppendString("*"); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5794 | base::ListValue whitelist; |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 5795 | whitelist.AppendString("host.name"); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5796 | PolicyMap policies; |
| 5797 | policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5798 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5799 | blacklist.CreateDeepCopy(), nullptr); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5800 | policies.Set(key::kNativeMessagingWhitelist, POLICY_LEVEL_MANDATORY, |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5801 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5802 | whitelist.CreateDeepCopy(), nullptr); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5803 | UpdateProviderPolicy(policies); |
| 5804 | |
Michael Giuffrida | b378399 | 2017-07-22 05:01:03 | [diff] [blame] | 5805 | EXPECT_EQ(extensions::MessagingDelegate::PolicyPermission::ALLOW_ALL, |
Michael Giuffrida | 9e1a9f8 | 2017-08-08 14:23:29 | [diff] [blame] | 5806 | IsNativeMessagingHostAllowed(browser()->profile(), "host.name")); |
| 5807 | EXPECT_EQ( |
| 5808 | extensions::MessagingDelegate::PolicyPermission::DISALLOW, |
| 5809 | IsNativeMessagingHostAllowed(browser()->profile(), "other.host.name")); |
[email protected] | 4c7d2ca | 2014-01-09 04:48:29 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | #endif // !defined(CHROME_OS) |
[email protected] | fb49060 | 2013-04-18 17:23:07 | [diff] [blame] | 5813 | |
Lei Zhang | c5b042c | 2017-11-11 00:39:23 | [diff] [blame] | 5814 | #if !defined(OS_CHROMEOS) |
zmo | d6486a6 | 2015-07-17 02:20:48 | [diff] [blame] | 5815 | // Sets the hardware acceleration mode policy before the browser is started. |
| 5816 | class HardwareAccelerationModePolicyTest : public PolicyTest { |
| 5817 | public: |
| 5818 | HardwareAccelerationModePolicyTest() {} |
| 5819 | |
| 5820 | void SetUpInProcessBrowserTestFixture() override { |
| 5821 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 5822 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5823 | policies.Set(key::kHardwareAccelerationModeEnabled, POLICY_LEVEL_MANDATORY, |
| 5824 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 5825 | std::make_unique<base::Value>(false), nullptr); |
zmo | d6486a6 | 2015-07-17 02:20:48 | [diff] [blame] | 5826 | provider_.UpdateChromePolicy(policies); |
| 5827 | } |
| 5828 | }; |
| 5829 | |
| 5830 | IN_PROC_BROWSER_TEST_F(HardwareAccelerationModePolicyTest, |
| 5831 | HardwareAccelerationDisabled) { |
| 5832 | // Verifies that hardware acceleration can be disabled with policy. |
| 5833 | EXPECT_FALSE( |
kinuko | 7e9da25 | 2017-03-10 07:18:42 | [diff] [blame] | 5834 | content::GpuDataManager::GetInstance()->HardwareAccelerationEnabled()); |
zmo | d6486a6 | 2015-07-17 02:20:48 | [diff] [blame] | 5835 | } |
Lei Zhang | c5b042c | 2017-11-11 00:39:23 | [diff] [blame] | 5836 | #endif // !defined(OS_CHROMEOS) |
zmo | d6486a6 | 2015-07-17 02:20:48 | [diff] [blame] | 5837 | |
phweiss | a16ceae2 | 2015-09-17 09:33:12 | [diff] [blame] | 5838 | #if defined(OS_CHROMEOS) |
| 5839 | // Policy is only available in ChromeOS |
| 5840 | IN_PROC_BROWSER_TEST_F(PolicyTest, UnifiedDesktopEnabledByDefault) { |
| 5841 | // Verify that Unified Desktop can be enabled by policy |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 5842 | display::DisplayManager* display_manager = |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 5843 | ash::Shell::Get()->display_manager(); |
phweiss | a16ceae2 | 2015-09-17 09:33:12 | [diff] [blame] | 5844 | |
| 5845 | // The policy description promises that Unified Desktop is not available |
| 5846 | // unless the policy is set (or a command line or an extension is used). If |
| 5847 | // this default behaviour changes, please change the description at |
| 5848 | // components/policy/resources/policy_templates.json. |
| 5849 | EXPECT_FALSE(display_manager->unified_desktop_enabled()); |
| 5850 | // Now set the policy and check that unified desktop is turned on. |
| 5851 | PolicyMap policies; |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5852 | policies.Set(key::kUnifiedDesktopEnabledByDefault, POLICY_LEVEL_MANDATORY, |
| 5853 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 5854 | base::WrapUnique(new base::Value(true)), nullptr); |
phweiss | a16ceae2 | 2015-09-17 09:33:12 | [diff] [blame] | 5855 | UpdateProviderPolicy(policies); |
| 5856 | EXPECT_TRUE(display_manager->unified_desktop_enabled()); |
dcheng | 3b344bc2 | 2016-05-10 02:26:09 | [diff] [blame] | 5857 | policies.Set(key::kUnifiedDesktopEnabledByDefault, POLICY_LEVEL_MANDATORY, |
| 5858 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 5859 | base::WrapUnique(new base::Value(false)), nullptr); |
phweiss | a16ceae2 | 2015-09-17 09:33:12 | [diff] [blame] | 5860 | UpdateProviderPolicy(policies); |
| 5861 | EXPECT_FALSE(display_manager->unified_desktop_enabled()); |
| 5862 | } |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5863 | |
| 5864 | class ArcPolicyTest : public PolicyTest { |
| 5865 | public: |
| 5866 | ArcPolicyTest() {} |
| 5867 | ~ArcPolicyTest() override {} |
| 5868 | |
| 5869 | protected: |
hidehiko | aab3dea | 2017-01-30 14:36:46 | [diff] [blame] | 5870 | void SetUpOnMainThread() override { |
| 5871 | PolicyTest::SetUpOnMainThread(); |
Evan Stade | 70719a79 | 2018-04-24 00:13:09 | [diff] [blame] | 5872 | arc::ArcSessionManager::SetUiEnabledForTesting(false); |
hidehiko | 5cc0f2f48 | 2016-12-27 07:14:24 | [diff] [blame] | 5873 | arc::ArcSessionManager::Get()->SetArcSessionRunnerForTesting( |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 5874 | std::make_unique<arc::ArcSessionRunner>( |
Yusuke Sato | 851bbc2 | 2019-03-26 17:16:15 | [diff] [blame] | 5875 | base::BindRepeating(arc::FakeArcSession::Create))); |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5876 | |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 5877 | browser()->profile()->GetPrefs()->SetBoolean(arc::prefs::kArcSignedIn, |
| 5878 | true); |
| 5879 | browser()->profile()->GetPrefs()->SetBoolean(arc::prefs::kArcTermsAccepted, |
hidehiko | 3b196d3 | 2016-12-02 11:05:21 | [diff] [blame] | 5880 | true); |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5881 | } |
| 5882 | |
hidehiko | aab3dea | 2017-01-30 14:36:46 | [diff] [blame] | 5883 | void TearDownOnMainThread() override { |
| 5884 | arc::ArcSessionManager::Get()->Shutdown(); |
| 5885 | PolicyTest::TearDownOnMainThread(); |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5886 | } |
| 5887 | |
xdai | 20e579f | 2016-06-02 06:58:01 | [diff] [blame] | 5888 | void SetUpCommandLine(base::CommandLine* command_line) override { |
hidehiko | aab3dea | 2017-01-30 14:36:46 | [diff] [blame] | 5889 | PolicyTest::SetUpCommandLine(command_line); |
| 5890 | arc::SetArcAvailableCommandLineForTesting(command_line); |
xdai | 20e579f | 2016-06-02 06:58:01 | [diff] [blame] | 5891 | } |
| 5892 | |
khmel | aa5c9359 | 2016-10-05 16:20:01 | [diff] [blame] | 5893 | void SetArcEnabledByPolicy(bool enabled) { |
| 5894 | PolicyMap policies; |
| 5895 | policies.Set(key::kArcEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 5896 | POLICY_SOURCE_CLOUD, |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 5897 | base::WrapUnique(new base::Value(enabled)), nullptr); |
khmel | aa5c9359 | 2016-10-05 16:20:01 | [diff] [blame] | 5898 | UpdateProviderPolicy(policies); |
| 5899 | if (browser()) { |
| 5900 | const PrefService* const prefs = browser()->profile()->GetPrefs(); |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 5901 | EXPECT_EQ(prefs->GetBoolean(arc::prefs::kArcEnabled), enabled); |
khmel | aa5c9359 | 2016-10-05 16:20:01 | [diff] [blame] | 5902 | } |
| 5903 | } |
| 5904 | |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5905 | private: |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5906 | DISALLOW_COPY_AND_ASSIGN(ArcPolicyTest); |
| 5907 | }; |
| 5908 | |
| 5909 | // Test ArcEnabled policy. |
| 5910 | IN_PROC_BROWSER_TEST_F(ArcPolicyTest, ArcEnabled) { |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5911 | const PrefService* const pref = browser()->profile()->GetPrefs(); |
hidehiko | 5cc0f2f48 | 2016-12-27 07:14:24 | [diff] [blame] | 5912 | const auto* const arc_session_manager = arc::ArcSessionManager::Get(); |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5913 | |
| 5914 | // ARC is switched off by default. |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 5915 | EXPECT_FALSE(pref->GetBoolean(arc::prefs::kArcEnabled)); |
Hidehiko Abe | ad836ec | 2017-10-02 13:26:32 | [diff] [blame] | 5916 | EXPECT_FALSE(arc_session_manager->enable_requested()); |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5917 | |
| 5918 | // Enable ARC. |
khmel | aa5c9359 | 2016-10-05 16:20:01 | [diff] [blame] | 5919 | SetArcEnabledByPolicy(true); |
Hidehiko Abe | ad836ec | 2017-10-02 13:26:32 | [diff] [blame] | 5920 | EXPECT_TRUE(arc_session_manager->enable_requested()); |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5921 | |
| 5922 | // Disable ARC. |
khmel | aa5c9359 | 2016-10-05 16:20:01 | [diff] [blame] | 5923 | SetArcEnabledByPolicy(false); |
Hidehiko Abe | ad836ec | 2017-10-02 13:26:32 | [diff] [blame] | 5924 | EXPECT_FALSE(arc_session_manager->enable_requested()); |
pbond | e40ccc1 | 2016-04-04 15:32:38 | [diff] [blame] | 5925 | } |
alemate | d70e82f | 2016-04-05 12:21:33 | [diff] [blame] | 5926 | |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5927 | // Test ArcBackupRestoreServiceEnabled policy. |
| 5928 | IN_PROC_BROWSER_TEST_F(ArcPolicyTest, ArcBackupRestoreServiceEnabled) { |
emaxx | f392d83 | 2017-02-18 07:01:27 | [diff] [blame] | 5929 | PrefService* const pref = browser()->profile()->GetPrefs(); |
poromov | 1df2003 | 2016-07-25 13:02:30 | [diff] [blame] | 5930 | |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5931 | // Enable ARC backup and restore in user prefs. |
| 5932 | pref->SetBoolean(arc::prefs::kArcBackupRestoreEnabled, true); |
poromov | 1df2003 | 2016-07-25 13:02:30 | [diff] [blame] | 5933 | |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5934 | // ARC backup and restore is disabled by policy by default. |
Bartosz Fabianowski | 0248c49 | 2018-07-02 13:44:32 | [diff] [blame] | 5935 | UpdateProviderPolicy(PolicyMap()); |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5936 | EXPECT_FALSE(pref->GetBoolean(arc::prefs::kArcBackupRestoreEnabled)); |
| 5937 | EXPECT_TRUE(pref->IsManagedPreference(arc::prefs::kArcBackupRestoreEnabled)); |
| 5938 | |
| 5939 | // Set ARC backup and restore to user control via policy. |
| 5940 | PolicyMap policies; |
| 5941 | policies.Set(key::kArcBackupRestoreServiceEnabled, POLICY_LEVEL_MANDATORY, |
| 5942 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5943 | std::make_unique<base::Value>( |
| 5944 | static_cast<int>(ArcServicePolicyValue::kUnderUserControl)), |
| 5945 | nullptr); |
| 5946 | UpdateProviderPolicy(policies); |
| 5947 | |
| 5948 | // User choice should be honored now. |
| 5949 | EXPECT_TRUE(pref->GetBoolean(arc::prefs::kArcBackupRestoreEnabled)); |
| 5950 | EXPECT_FALSE(pref->IsManagedPreference(arc::prefs::kArcBackupRestoreEnabled)); |
| 5951 | pref->SetBoolean(arc::prefs::kArcBackupRestoreEnabled, false); |
| 5952 | EXPECT_FALSE(pref->GetBoolean(arc::prefs::kArcBackupRestoreEnabled)); |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 5953 | pref->SetBoolean(arc::prefs::kArcBackupRestoreEnabled, true); |
| 5954 | EXPECT_TRUE(pref->GetBoolean(arc::prefs::kArcBackupRestoreEnabled)); |
emaxx | f392d83 | 2017-02-18 07:01:27 | [diff] [blame] | 5955 | |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5956 | // Set ARC backup and restore to disabled via policy. |
| 5957 | policies.Set(key::kArcBackupRestoreServiceEnabled, POLICY_LEVEL_MANDATORY, |
poromov | 1df2003 | 2016-07-25 13:02:30 | [diff] [blame] | 5958 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5959 | std::make_unique<base::Value>( |
| 5960 | static_cast<int>(ArcServicePolicyValue::kDisabled)), |
| 5961 | nullptr); |
poromov | 1df2003 | 2016-07-25 13:02:30 | [diff] [blame] | 5962 | UpdateProviderPolicy(policies); |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 5963 | EXPECT_FALSE(pref->GetBoolean(arc::prefs::kArcBackupRestoreEnabled)); |
| 5964 | EXPECT_TRUE(pref->IsManagedPreference(arc::prefs::kArcBackupRestoreEnabled)); |
Bartosz Fabianowski | cd76af1 | 2019-04-12 07:53:05 | [diff] [blame] | 5965 | |
| 5966 | // Disable ARC backup and restore in user prefs. |
| 5967 | pref->SetBoolean(arc::prefs::kArcBackupRestoreEnabled, true); |
| 5968 | |
| 5969 | // Set ARC backup and restore to enabled via policy. |
| 5970 | policies.Set(key::kArcBackupRestoreServiceEnabled, POLICY_LEVEL_MANDATORY, |
| 5971 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 5972 | std::make_unique<base::Value>( |
| 5973 | static_cast<int>(ArcServicePolicyValue::kEnabled)), |
| 5974 | nullptr); |
| 5975 | UpdateProviderPolicy(policies); |
| 5976 | EXPECT_TRUE(pref->GetBoolean(arc::prefs::kArcBackupRestoreEnabled)); |
| 5977 | EXPECT_TRUE(pref->IsManagedPreference(arc::prefs::kArcBackupRestoreEnabled)); |
poromov | 1df2003 | 2016-07-25 13:02:30 | [diff] [blame] | 5978 | } |
| 5979 | |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5980 | // Test ArcGoogleLocationServicesEnabled policy and its interplay with the |
emaxx | d996b35e | 2017-02-06 17:03:47 | [diff] [blame] | 5981 | // DefaultGeolocationSetting policy. |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5982 | IN_PROC_BROWSER_TEST_F(ArcPolicyTest, ArcGoogleLocationServicesEnabled) { |
emaxx | f392d83 | 2017-02-18 07:01:27 | [diff] [blame] | 5983 | PrefService* const pref = browser()->profile()->GetPrefs(); |
khmel | 75cf0e7 | 2016-08-17 16:45:17 | [diff] [blame] | 5984 | |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5985 | // Values of the ArcGoogleLocationServicesEnabled policy to be tested. |
jdoerrie | cc9f573 | 2017-08-23 14:12:30 | [diff] [blame] | 5986 | std::vector<base::Value> test_policy_values; |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 5987 | test_policy_values.emplace_back(); // unset |
| 5988 | test_policy_values.emplace_back( |
| 5989 | static_cast<int>(ArcServicePolicyValue::kDisabled)); |
| 5990 | test_policy_values.emplace_back( |
| 5991 | static_cast<int>(ArcServicePolicyValue::kUnderUserControl)); |
Bartosz Fabianowski | cd76af1 | 2019-04-12 07:53:05 | [diff] [blame] | 5992 | test_policy_values.emplace_back( |
| 5993 | static_cast<int>(ArcServicePolicyValue::kEnabled)); |
jdoerrie | cc9f573 | 2017-08-23 14:12:30 | [diff] [blame] | 5994 | |
emaxx | d996b35e | 2017-02-06 17:03:47 | [diff] [blame] | 5995 | // Values of the DefaultGeolocationSetting policy to be tested. |
jdoerrie | cc9f573 | 2017-08-23 14:12:30 | [diff] [blame] | 5996 | std::vector<base::Value> test_default_geo_policy_values; |
| 5997 | test_default_geo_policy_values.emplace_back(); // unset |
| 5998 | test_default_geo_policy_values.emplace_back(1); // 'AllowGeolocation' |
| 5999 | test_default_geo_policy_values.emplace_back(2); // 'BlockGeolocation' |
| 6000 | test_default_geo_policy_values.emplace_back(3); // 'AskGeolocation' |
khmel | 75cf0e7 | 2016-08-17 16:45:17 | [diff] [blame] | 6001 | |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 6002 | // Switch on the pref in user prefs. |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 6003 | pref->SetBoolean(arc::prefs::kArcLocationServiceEnabled, true); |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 6004 | |
| 6005 | // The pref is overridden to disabled by policy by default. |
Bartosz Fabianowski | 0248c49 | 2018-07-02 13:44:32 | [diff] [blame] | 6006 | UpdateProviderPolicy(PolicyMap()); |
Bartosz Fabianowski | cd76af1 | 2019-04-12 07:53:05 | [diff] [blame] | 6007 | EXPECT_FALSE(pref->GetBoolean(arc::prefs::kArcLocationServiceEnabled)); |
| 6008 | EXPECT_TRUE( |
| 6009 | pref->IsManagedPreference(arc::prefs::kArcLocationServiceEnabled)); |
emaxx | f392d83 | 2017-02-18 07:01:27 | [diff] [blame] | 6010 | |
emaxx | d996b35e | 2017-02-06 17:03:47 | [diff] [blame] | 6011 | for (const auto& test_policy_value : test_policy_values) { |
| 6012 | for (const auto& test_default_geo_policy_value : |
| 6013 | test_default_geo_policy_values) { |
| 6014 | PolicyMap policies; |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 6015 | if (test_policy_value.is_int()) { |
| 6016 | policies.Set(key::kArcGoogleLocationServicesEnabled, |
| 6017 | POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 6018 | POLICY_SOURCE_CLOUD, test_policy_value.CreateDeepCopy(), |
| 6019 | nullptr); |
emaxx | d996b35e | 2017-02-06 17:03:47 | [diff] [blame] | 6020 | } |
| 6021 | if (test_default_geo_policy_value.is_int()) { |
| 6022 | policies.Set(key::kDefaultGeolocationSetting, POLICY_LEVEL_MANDATORY, |
| 6023 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 6024 | test_default_geo_policy_value.CreateDeepCopy(), nullptr); |
| 6025 | } |
| 6026 | UpdateProviderPolicy(policies); |
khmel | 75cf0e7 | 2016-08-17 16:45:17 | [diff] [blame] | 6027 | |
emaxx | d996b35e | 2017-02-06 17:03:47 | [diff] [blame] | 6028 | const bool should_be_disabled_by_policy = |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 6029 | test_policy_value.is_none() || |
| 6030 | (test_policy_value.GetInt() == |
| 6031 | static_cast<int>(ArcServicePolicyValue::kDisabled)); |
Bartosz Fabianowski | cd76af1 | 2019-04-12 07:53:05 | [diff] [blame] | 6032 | const bool should_be_enabled_by_policy = |
| 6033 | test_policy_value.is_int() && |
| 6034 | test_policy_value.GetInt() == |
| 6035 | static_cast<int>(ArcServicePolicyValue::kEnabled); |
emaxx | d996b35e | 2017-02-06 17:03:47 | [diff] [blame] | 6036 | const bool should_be_disabled_by_default_geo_policy = |
| 6037 | test_default_geo_policy_value.is_int() && |
| 6038 | test_default_geo_policy_value.GetInt() == 2; |
| 6039 | const bool expected_pref_value = |
| 6040 | !(should_be_disabled_by_policy || |
| 6041 | should_be_disabled_by_default_geo_policy); |
| 6042 | EXPECT_EQ(expected_pref_value, |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 6043 | pref->GetBoolean(arc::prefs::kArcLocationServiceEnabled)) |
Bartosz Fabianowski | cd76af1 | 2019-04-12 07:53:05 | [diff] [blame] | 6044 | << "ArcGoogleLocationServicesEnabled policy is set to " |
| 6045 | << test_policy_value << "DefaultGeolocationSetting policy is set to " |
emaxx | d996b35e | 2017-02-06 17:03:47 | [diff] [blame] | 6046 | << test_default_geo_policy_value; |
khmel | 75cf0e7 | 2016-08-17 16:45:17 | [diff] [blame] | 6047 | |
emaxx | d996b35e | 2017-02-06 17:03:47 | [diff] [blame] | 6048 | const bool expected_pref_managed = |
Bartosz Fabianowski | cd76af1 | 2019-04-12 07:53:05 | [diff] [blame] | 6049 | should_be_disabled_by_policy || should_be_enabled_by_policy || |
Bartosz Fabianowski | 6979a6d | 2018-05-24 13:29:20 | [diff] [blame] | 6050 | should_be_disabled_by_default_geo_policy; |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 6051 | EXPECT_EQ( |
| 6052 | expected_pref_managed, |
| 6053 | pref->IsManagedPreference(arc::prefs::kArcLocationServiceEnabled)) |
Bartosz Fabianowski | cd76af1 | 2019-04-12 07:53:05 | [diff] [blame] | 6054 | << "ArcGoogleLocationServicesEnabled policy is set to " |
| 6055 | << test_policy_value << "DefaultGeolocationSetting policy is set to " |
emaxx | d996b35e | 2017-02-06 17:03:47 | [diff] [blame] | 6056 | << test_default_geo_policy_value; |
| 6057 | } |
| 6058 | } |
khmel | 75cf0e7 | 2016-08-17 16:45:17 | [diff] [blame] | 6059 | } |
| 6060 | |
thestig | f8056446 | 2015-09-29 23:12:08 | [diff] [blame] | 6061 | #endif // defined(OS_CHROMEOS) |
phweiss | a16ceae2 | 2015-09-17 09:33:12 | [diff] [blame] | 6062 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 6063 | class NetworkTimePolicyTest : public PolicyTest { |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6064 | public: |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 6065 | NetworkTimePolicyTest() {} |
chaopeng | 01e3b25 | 2017-10-18 22:33:37 | [diff] [blame] | 6066 | ~NetworkTimePolicyTest() override {} |
| 6067 | |
| 6068 | void SetUpOnMainThread() override { |
| 6069 | std::map<std::string, std::string> parameters; |
| 6070 | parameters["FetchBehavior"] = "on-demand-only"; |
| 6071 | scoped_feature_list_.InitAndEnableFeatureWithParameters( |
| 6072 | network_time::kNetworkTimeServiceQuerying, parameters); |
| 6073 | PolicyTest::SetUpOnMainThread(); |
isherman | 9fb15b8 | 2017-06-10 01:30:34 | [diff] [blame] | 6074 | } |
| 6075 | |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6076 | // A request handler that returns a dummy response and counts the number of |
| 6077 | // times it is called. |
| 6078 | std::unique_ptr<net::test_server::HttpResponse> CountingRequestHandler( |
| 6079 | const net::test_server::HttpRequest& request) { |
| 6080 | net::test_server::BasicHttpResponse* response = |
| 6081 | new net::test_server::BasicHttpResponse(); |
| 6082 | num_requests_++; |
| 6083 | response->set_code(net::HTTP_OK); |
| 6084 | response->set_content( |
| 6085 | ")]}'\n" |
| 6086 | "{\"current_time_millis\":1461621971825,\"server_nonce\":-6." |
| 6087 | "006853099049523E85}"); |
| 6088 | response->AddCustomHeader("x-cup-server-proof", "dead:beef"); |
| 6089 | return std::unique_ptr<net::test_server::HttpResponse>(response); |
| 6090 | } |
| 6091 | |
| 6092 | uint32_t num_requests() { return num_requests_; } |
| 6093 | |
| 6094 | private: |
chaopeng | 01e3b25 | 2017-10-18 22:33:37 | [diff] [blame] | 6095 | base::test::ScopedFeatureList scoped_feature_list_; |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6096 | uint32_t num_requests_ = 0; |
chaopeng | 01e3b25 | 2017-10-18 22:33:37 | [diff] [blame] | 6097 | |
| 6098 | DISALLOW_COPY_AND_ASSIGN(NetworkTimePolicyTest); |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6099 | }; |
| 6100 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 6101 | IN_PROC_BROWSER_TEST_F(NetworkTimePolicyTest, NetworkTimeQueriesDisabled) { |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6102 | // Set a policy to disable network time queries. |
| 6103 | PolicyMap policies; |
estark | 9a1fe80 | 2017-06-01 15:50:17 | [diff] [blame] | 6104 | policies.Set(key::kBrowserNetworkTimeQueriesEnabled, POLICY_LEVEL_MANDATORY, |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6105 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 6106 | std::make_unique<base::Value>(false), nullptr); |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6107 | UpdateProviderPolicy(policies); |
| 6108 | |
| 6109 | embedded_test_server()->RegisterRequestHandler(base::Bind( |
| 6110 | &NetworkTimePolicyTest::CountingRequestHandler, base::Unretained(this))); |
| 6111 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 6112 | g_browser_process->network_time_tracker()->SetTimeServerURLForTesting( |
| 6113 | embedded_test_server()->GetURL("/")); |
| 6114 | |
| 6115 | net::EmbeddedTestServer https_server_expired_( |
| 6116 | net::EmbeddedTestServer::TYPE_HTTPS); |
| 6117 | https_server_expired_.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); |
| 6118 | ASSERT_TRUE(https_server_expired_.Start()); |
| 6119 | |
| 6120 | // Navigate to a page with a certificate date error and then check that a |
| 6121 | // network time query was not sent. |
| 6122 | ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); |
| 6123 | content::WebContents* tab = |
| 6124 | browser()->tab_strip_model()->GetActiveWebContents(); |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 6125 | WaitForInterstitial(tab); |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6126 | EXPECT_EQ(0u, num_requests()); |
| 6127 | |
| 6128 | // Now enable the policy and check that a network time query is sent. |
estark | 9a1fe80 | 2017-06-01 15:50:17 | [diff] [blame] | 6129 | policies.Set(key::kBrowserNetworkTimeQueriesEnabled, POLICY_LEVEL_MANDATORY, |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6130 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 6131 | std::make_unique<base::Value>(true), nullptr); |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6132 | UpdateProviderPolicy(policies); |
| 6133 | ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); |
Carlos IL | 0ea4e59 | 2018-05-11 01:51:57 | [diff] [blame] | 6134 | EXPECT_TRUE(IsShowingInterstitial(tab)); |
estark | 80618c3 | 2017-05-24 02:48:31 | [diff] [blame] | 6135 | EXPECT_EQ(1u, num_requests()); |
| 6136 | } |
| 6137 | |
Toni Barzic | c45d9b1 | 2017-07-25 02:53:36 | [diff] [blame] | 6138 | #if defined(OS_CHROMEOS) |
| 6139 | |
| 6140 | class NoteTakingOnLockScreenPolicyTest : public PolicyTest { |
| 6141 | public: |
| 6142 | NoteTakingOnLockScreenPolicyTest() = default; |
| 6143 | ~NoteTakingOnLockScreenPolicyTest() override = default; |
| 6144 | |
| 6145 | void SetUpCommandLine(base::CommandLine* command_line) override { |
Toni Barzic | c45d9b1 | 2017-07-25 02:53:36 | [diff] [blame] | 6146 | // An app requires lockScreen permission to be enabled as a lock screen app. |
| 6147 | // This permission is protected by a whitelist, so the test app has to be |
| 6148 | // whitelisted as well. |
| 6149 | command_line->AppendSwitchASCII( |
| 6150 | extensions::switches::kWhitelistedExtensionID, kTestAppId); |
Toni Barzic | 579f2d0 | 2017-09-22 23:57:23 | [diff] [blame] | 6151 | command_line->AppendSwitch(ash::switches::kAshForceEnableStylusTools); |
Toni Barzic | c45d9b1 | 2017-07-25 02:53:36 | [diff] [blame] | 6152 | PolicyTest::SetUpCommandLine(command_line); |
| 6153 | } |
| 6154 | |
| 6155 | void SetUserLevelPrefValue(const std::string& app_id, |
| 6156 | bool enabled_on_lock_screen) { |
| 6157 | chromeos::NoteTakingHelper* helper = chromeos::NoteTakingHelper::Get(); |
| 6158 | ASSERT_TRUE(helper); |
| 6159 | |
| 6160 | helper->SetPreferredApp(browser()->profile(), app_id); |
| 6161 | helper->SetPreferredAppEnabledOnLockScreen(browser()->profile(), |
| 6162 | enabled_on_lock_screen); |
| 6163 | } |
| 6164 | |
| 6165 | void SetPolicyValue(std::unique_ptr<base::Value> value) { |
| 6166 | PolicyMap policies; |
| 6167 | if (value) { |
| 6168 | policies.Set(key::kNoteTakingAppsLockScreenWhitelist, |
| 6169 | POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 6170 | POLICY_SOURCE_CLOUD, std::move(value), nullptr); |
| 6171 | } |
| 6172 | UpdateProviderPolicy(policies); |
| 6173 | } |
| 6174 | |
| 6175 | chromeos::NoteTakingLockScreenSupport GetAppLockScreenStatus( |
| 6176 | const std::string& app_id) { |
| 6177 | std::unique_ptr<chromeos::NoteTakingAppInfo> info = |
| 6178 | chromeos::NoteTakingHelper::Get()->GetPreferredChromeAppInfo( |
| 6179 | browser()->profile()); |
| 6180 | if (!info || info->app_id != app_id) |
| 6181 | return chromeos::NoteTakingLockScreenSupport::kNotSupported; |
| 6182 | return info->lock_screen_support; |
| 6183 | } |
| 6184 | |
| 6185 | // The test app ID. |
| 6186 | static const char kTestAppId[]; |
| 6187 | |
| 6188 | private: |
| 6189 | DISALLOW_COPY_AND_ASSIGN(NoteTakingOnLockScreenPolicyTest); |
| 6190 | }; |
| 6191 | |
| 6192 | const char NoteTakingOnLockScreenPolicyTest::kTestAppId[] = |
| 6193 | "cadfeochfldmbdgoccgbeianhamecbae"; |
| 6194 | |
| 6195 | IN_PROC_BROWSER_TEST_F(NoteTakingOnLockScreenPolicyTest, |
| 6196 | DisableLockScreenNoteTakingByPolicy) { |
| 6197 | scoped_refptr<const extensions::Extension> app = |
| 6198 | LoadUnpackedExtension("lock_screen_apps/app_launch"); |
| 6199 | ASSERT_TRUE(app); |
| 6200 | ASSERT_EQ(kTestAppId, app->id()); |
| 6201 | |
| 6202 | SetUserLevelPrefValue(app->id(), true); |
| 6203 | EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kEnabled, |
| 6204 | GetAppLockScreenStatus(app->id())); |
| 6205 | |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 6206 | SetPolicyValue(std::make_unique<base::ListValue>()); |
Toni Barzic | c45d9b1 | 2017-07-25 02:53:36 | [diff] [blame] | 6207 | EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kNotAllowedByPolicy, |
| 6208 | GetAppLockScreenStatus(app->id())); |
| 6209 | |
| 6210 | SetPolicyValue(nullptr); |
| 6211 | EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kEnabled, |
| 6212 | GetAppLockScreenStatus(app->id())); |
| 6213 | } |
| 6214 | |
| 6215 | IN_PROC_BROWSER_TEST_F(NoteTakingOnLockScreenPolicyTest, |
| 6216 | WhitelistLockScreenNoteTakingAppByPolicy) { |
| 6217 | scoped_refptr<const extensions::Extension> app = |
| 6218 | LoadUnpackedExtension("lock_screen_apps/app_launch"); |
| 6219 | ASSERT_TRUE(app); |
| 6220 | ASSERT_EQ(kTestAppId, app->id()); |
| 6221 | |
| 6222 | SetUserLevelPrefValue(app->id(), false); |
| 6223 | EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kSupported, |
| 6224 | GetAppLockScreenStatus(app->id())); |
| 6225 | |
Jinho Bang | 2a49191 | 2018-01-16 07:21:30 | [diff] [blame] | 6226 | auto policy = std::make_unique<base::ListValue>(); |
Toni Barzic | c45d9b1 | 2017-07-25 02:53:36 | [diff] [blame] | 6227 | policy->GetList().emplace_back(base::Value(kTestAppId)); |
| 6228 | SetPolicyValue(std::move(policy)); |
| 6229 | |
| 6230 | EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kSupported, |
| 6231 | GetAppLockScreenStatus(app->id())); |
| 6232 | |
| 6233 | SetUserLevelPrefValue(app->id(), true); |
| 6234 | EXPECT_EQ(chromeos::NoteTakingLockScreenSupport::kEnabled, |
| 6235 | GetAppLockScreenStatus(app->id())); |
| 6236 | } |
| 6237 | |
| 6238 | #endif // defined(OS_CHROMEOS) |
| 6239 | |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 6240 | #if !defined(OS_ANDROID) |
| 6241 | |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 6242 | class AutoplayPolicyTest : public PolicyTest { |
| 6243 | public: |
| 6244 | AutoplayPolicyTest() { |
| 6245 | // Start two embedded test servers on different ports. This will ensure |
| 6246 | // the test works correctly with cross origin iframes and site-per-process. |
Alan Cutter | a9a96c5 | 2019-03-28 07:15:39 | [diff] [blame] | 6247 | embedded_test_server2()->AddDefaultHandlers(GetChromeTestDataDir()); |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 6248 | EXPECT_TRUE(embedded_test_server()->Start()); |
| 6249 | EXPECT_TRUE(embedded_test_server2()->Start()); |
| 6250 | } |
| 6251 | |
| 6252 | void NavigateToTestPage() { |
| 6253 | GURL origin = embedded_test_server()->GetURL(kAutoplayTestPageURL); |
| 6254 | ui_test_utils::NavigateToURL(browser(), origin); |
| 6255 | |
| 6256 | // Navigate the subframe to the test page but on the second origin. |
| 6257 | GURL origin2 = embedded_test_server2()->GetURL(kAutoplayTestPageURL); |
| 6258 | std::string script = base::StringPrintf( |
| 6259 | "setTimeout(\"" |
| 6260 | "document.getElementById('subframe').src='%s';" |
| 6261 | "\",0)", |
| 6262 | origin2.spec().c_str()); |
| 6263 | content::TestNavigationObserver load_observer(GetWebContents()); |
| 6264 | EXPECT_TRUE(ExecuteScriptWithoutUserGesture(GetWebContents(), script)); |
| 6265 | load_observer.Wait(); |
| 6266 | } |
| 6267 | |
| 6268 | net::EmbeddedTestServer* embedded_test_server2() { |
| 6269 | return &embedded_test_server2_; |
| 6270 | } |
| 6271 | |
| 6272 | bool TryAutoplay(content::RenderFrameHost* rfh) { |
| 6273 | bool result = false; |
| 6274 | |
| 6275 | EXPECT_TRUE(content::ExecuteScriptWithoutUserGestureAndExtractBool( |
| 6276 | rfh, "tryPlayback();", &result)); |
| 6277 | |
| 6278 | return result; |
| 6279 | } |
| 6280 | |
| 6281 | content::WebContents* GetWebContents() { |
| 6282 | return browser()->tab_strip_model()->GetActiveWebContents(); |
| 6283 | } |
| 6284 | |
| 6285 | content::RenderFrameHost* GetMainFrame() { |
| 6286 | return GetWebContents()->GetMainFrame(); |
| 6287 | } |
| 6288 | |
| 6289 | content::RenderFrameHost* GetChildFrame() { |
| 6290 | return GetWebContents()->GetAllFrames()[1]; |
| 6291 | } |
| 6292 | |
| 6293 | private: |
| 6294 | // Second instance of embedded test server to provide a second test origin. |
| 6295 | net::EmbeddedTestServer embedded_test_server2_; |
| 6296 | }; |
| 6297 | |
| 6298 | IN_PROC_BROWSER_TEST_F(AutoplayPolicyTest, AutoplayAllowedByPolicy) { |
| 6299 | NavigateToTestPage(); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 6300 | |
| 6301 | // Check that autoplay was not allowed. |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 6302 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6303 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 6304 | |
| 6305 | // Update policy to allow autoplay. |
| 6306 | PolicyMap policies; |
| 6307 | SetPolicy(&policies, key::kAutoplayAllowed, |
| 6308 | std::make_unique<base::Value>(true)); |
| 6309 | UpdateProviderPolicy(policies); |
| 6310 | |
| 6311 | // Check that autoplay was allowed by policy. |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 6312 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6313 | EXPECT_TRUE(TryAutoplay(GetMainFrame())); |
| 6314 | EXPECT_TRUE(TryAutoplay(GetChildFrame())); |
| 6315 | } |
| 6316 | |
| 6317 | IN_PROC_BROWSER_TEST_F(AutoplayPolicyTest, AutoplayWhitelist_Allowed) { |
| 6318 | NavigateToTestPage(); |
| 6319 | |
| 6320 | // Check that autoplay was not allowed. |
| 6321 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6322 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6323 | |
| 6324 | // Create a test whitelist with our origin. |
| 6325 | std::vector<base::Value> whitelist; |
| 6326 | whitelist.push_back(base::Value(embedded_test_server()->GetURL("/").spec())); |
| 6327 | |
| 6328 | // Update policy to allow autoplay for our test origin. |
| 6329 | PolicyMap policies; |
| 6330 | SetPolicy(&policies, key::kAutoplayWhitelist, |
| 6331 | std::make_unique<base::ListValue>(whitelist)); |
| 6332 | UpdateProviderPolicy(policies); |
| 6333 | |
| 6334 | // Check that autoplay was allowed by policy. |
| 6335 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6336 | EXPECT_TRUE(TryAutoplay(GetMainFrame())); |
| 6337 | EXPECT_TRUE(TryAutoplay(GetChildFrame())); |
| 6338 | } |
| 6339 | |
| 6340 | IN_PROC_BROWSER_TEST_F(AutoplayPolicyTest, AutoplayWhitelist_PatternAllowed) { |
| 6341 | NavigateToTestPage(); |
| 6342 | |
| 6343 | // Check that autoplay was not allowed. |
| 6344 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6345 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6346 | |
| 6347 | // Create a test whitelist with our origin. |
| 6348 | std::vector<base::Value> whitelist; |
| 6349 | whitelist.push_back(base::Value("127.0.0.1:*")); |
| 6350 | |
| 6351 | // Update policy to allow autoplay for our test origin. |
| 6352 | PolicyMap policies; |
| 6353 | SetPolicy(&policies, key::kAutoplayWhitelist, |
| 6354 | std::make_unique<base::ListValue>(whitelist)); |
| 6355 | UpdateProviderPolicy(policies); |
| 6356 | |
| 6357 | // Check that autoplay was allowed by policy. |
| 6358 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6359 | EXPECT_TRUE(TryAutoplay(GetMainFrame())); |
| 6360 | EXPECT_TRUE(TryAutoplay(GetChildFrame())); |
| 6361 | } |
| 6362 | |
| 6363 | IN_PROC_BROWSER_TEST_F(AutoplayPolicyTest, AutoplayWhitelist_Missing) { |
| 6364 | NavigateToTestPage(); |
| 6365 | |
| 6366 | // Check that autoplay was not allowed. |
| 6367 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6368 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6369 | |
| 6370 | // Create a test whitelist with a random origin. |
| 6371 | std::vector<base::Value> whitelist; |
| 6372 | whitelist.push_back(base::Value("https://www.example.com")); |
| 6373 | |
| 6374 | // Update policy to allow autoplay for a random origin. |
| 6375 | PolicyMap policies; |
| 6376 | SetPolicy(&policies, key::kAutoplayWhitelist, |
| 6377 | std::make_unique<base::ListValue>(whitelist)); |
| 6378 | UpdateProviderPolicy(policies); |
| 6379 | |
| 6380 | // Check that autoplay was not allowed. |
| 6381 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6382 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6383 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6384 | } |
| 6385 | |
| 6386 | IN_PROC_BROWSER_TEST_F(AutoplayPolicyTest, AutoplayDeniedByPolicy) { |
| 6387 | NavigateToTestPage(); |
| 6388 | |
| 6389 | // Check that autoplay was not allowed. |
| 6390 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6391 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6392 | |
| 6393 | // Update policy to forbid autoplay. |
| 6394 | PolicyMap policies; |
| 6395 | SetPolicy(&policies, key::kAutoplayAllowed, |
| 6396 | std::make_unique<base::Value>(false)); |
| 6397 | UpdateProviderPolicy(policies); |
| 6398 | |
| 6399 | // Check that autoplay was not allowed by policy. |
| 6400 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6401 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6402 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6403 | |
| 6404 | // Create a test whitelist with a random origin. |
| 6405 | std::vector<base::Value> whitelist; |
| 6406 | whitelist.push_back(base::Value("https://www.example.com")); |
| 6407 | |
| 6408 | // Update policy to allow autoplay for a random origin. |
| 6409 | SetPolicy(&policies, key::kAutoplayWhitelist, |
| 6410 | std::make_unique<base::ListValue>(whitelist)); |
| 6411 | UpdateProviderPolicy(policies); |
| 6412 | |
| 6413 | // Check that autoplay was not allowed. |
| 6414 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6415 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6416 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6417 | } |
| 6418 | |
| 6419 | IN_PROC_BROWSER_TEST_F(AutoplayPolicyTest, AutoplayDeniedAllowedWithURL) { |
| 6420 | NavigateToTestPage(); |
| 6421 | |
| 6422 | // Check that autoplay was not allowed. |
| 6423 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6424 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6425 | |
| 6426 | // Update policy to forbid autoplay. |
| 6427 | PolicyMap policies; |
| 6428 | SetPolicy(&policies, key::kAutoplayAllowed, |
| 6429 | std::make_unique<base::Value>(false)); |
| 6430 | UpdateProviderPolicy(policies); |
| 6431 | |
| 6432 | // Check that autoplay was not allowed by policy. |
| 6433 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6434 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6435 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6436 | |
| 6437 | // Create a test whitelist with our test origin. |
| 6438 | std::vector<base::Value> whitelist; |
| 6439 | whitelist.push_back(base::Value(embedded_test_server()->GetURL("/").spec())); |
| 6440 | |
| 6441 | // Update policy to allow autoplay for our test origin. |
| 6442 | SetPolicy(&policies, key::kAutoplayWhitelist, |
| 6443 | std::make_unique<base::ListValue>(whitelist)); |
| 6444 | UpdateProviderPolicy(policies); |
| 6445 | |
| 6446 | // Check that autoplay was allowed by policy. |
| 6447 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6448 | EXPECT_TRUE(TryAutoplay(GetMainFrame())); |
| 6449 | EXPECT_TRUE(TryAutoplay(GetChildFrame())); |
| 6450 | } |
| 6451 | |
| 6452 | IN_PROC_BROWSER_TEST_F(AutoplayPolicyTest, AutoplayAllowedGlobalAndURL) { |
| 6453 | NavigateToTestPage(); |
| 6454 | |
| 6455 | // Check that autoplay was not allowed. |
| 6456 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6457 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6458 | |
| 6459 | // Update policy to forbid autoplay. |
| 6460 | PolicyMap policies; |
| 6461 | SetPolicy(&policies, key::kAutoplayAllowed, |
| 6462 | std::make_unique<base::Value>(false)); |
| 6463 | UpdateProviderPolicy(policies); |
| 6464 | |
| 6465 | // Check that autoplay was not allowed by policy. |
| 6466 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6467 | EXPECT_FALSE(TryAutoplay(GetMainFrame())); |
| 6468 | EXPECT_FALSE(TryAutoplay(GetChildFrame())); |
| 6469 | |
| 6470 | // Create a test whitelist with our test origin. |
| 6471 | std::vector<base::Value> whitelist; |
| 6472 | whitelist.push_back(base::Value(embedded_test_server()->GetURL("/").spec())); |
| 6473 | |
| 6474 | // Update policy to allow autoplay for our test origin. |
| 6475 | SetPolicy(&policies, key::kAutoplayWhitelist, |
| 6476 | std::make_unique<base::ListValue>(whitelist)); |
| 6477 | UpdateProviderPolicy(policies); |
| 6478 | |
| 6479 | // Check that autoplay was allowed by policy. |
| 6480 | GetWebContents()->GetRenderViewHost()->OnWebkitPreferencesChanged(); |
| 6481 | EXPECT_TRUE(TryAutoplay(GetMainFrame())); |
| 6482 | EXPECT_TRUE(TryAutoplay(GetChildFrame())); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | #endif // !defined(OS_ANDROID) |
| 6486 | |
Reilly Grant | 6f18e1f | 2018-04-03 02:03:22 | [diff] [blame] | 6487 | IN_PROC_BROWSER_TEST_F(PolicyTest, WebUsbDefault) { |
Reilly Grant | 2e64da3 | 2019-04-23 18:06:47 | [diff] [blame] | 6488 | const auto kTestOrigin = url::Origin::Create(GURL("https://foo.com:443")); |
Reilly Grant | 6f18e1f | 2018-04-03 02:03:22 | [diff] [blame] | 6489 | |
| 6490 | // Expect the default permission value to be 'ask'. |
| 6491 | auto* context = UsbChooserContextFactory::GetForProfile(browser()->profile()); |
Reilly Grant | 2e64da3 | 2019-04-23 18:06:47 | [diff] [blame] | 6492 | EXPECT_TRUE(context->CanRequestObjectPermission(kTestOrigin, kTestOrigin)); |
Reilly Grant | 6f18e1f | 2018-04-03 02:03:22 | [diff] [blame] | 6493 | |
| 6494 | // Update policy to change the default permission value to 'block'. |
| 6495 | PolicyMap policies; |
| 6496 | SetPolicy(&policies, key::kDefaultWebUsbGuardSetting, |
| 6497 | std::make_unique<base::Value>(2)); |
| 6498 | UpdateProviderPolicy(policies); |
Reilly Grant | 2e64da3 | 2019-04-23 18:06:47 | [diff] [blame] | 6499 | EXPECT_FALSE(context->CanRequestObjectPermission(kTestOrigin, kTestOrigin)); |
Reilly Grant | 6f18e1f | 2018-04-03 02:03:22 | [diff] [blame] | 6500 | |
| 6501 | // Update policy to change the default permission value to 'ask'. |
| 6502 | SetPolicy(&policies, key::kDefaultWebUsbGuardSetting, |
| 6503 | std::make_unique<base::Value>(3)); |
| 6504 | UpdateProviderPolicy(policies); |
Reilly Grant | 2e64da3 | 2019-04-23 18:06:47 | [diff] [blame] | 6505 | EXPECT_TRUE(context->CanRequestObjectPermission(kTestOrigin, kTestOrigin)); |
Reilly Grant | 6f18e1f | 2018-04-03 02:03:22 | [diff] [blame] | 6506 | } |
| 6507 | |
Ovidio Henriquez | e3aa8a56 | 2018-10-09 15:49:15 | [diff] [blame] | 6508 | IN_PROC_BROWSER_TEST_F(PolicyTest, WebUsbAllowDevicesForUrls) { |
Reilly Grant | 392c611 | 2019-04-23 19:12:12 | [diff] [blame] | 6509 | const auto kTestOrigin = url::Origin::Create(GURL("https://foo.com:443")); |
Donna Wu | fd06ab3 | 2019-05-07 16:39:32 | [diff] [blame] | 6510 | scoped_refptr<device::FakeUsbDeviceInfo> device = |
| 6511 | base::MakeRefCounted<device::FakeUsbDeviceInfo>(0, 0, "Google", "Gizmo", |
| 6512 | "123ABC"); |
| 6513 | const auto& device_info = device->GetDeviceInfo(); |
Ovidio Henriquez | e3aa8a56 | 2018-10-09 15:49:15 | [diff] [blame] | 6514 | |
| 6515 | // Expect the default permission value to be empty. |
| 6516 | auto* context = UsbChooserContextFactory::GetForProfile(browser()->profile()); |
Reilly Grant | 392c611 | 2019-04-23 19:12:12 | [diff] [blame] | 6517 | EXPECT_FALSE( |
Donna Wu | fd06ab3 | 2019-05-07 16:39:32 | [diff] [blame] | 6518 | context->HasDevicePermission(kTestOrigin, kTestOrigin, device_info)); |
Ovidio Henriquez | e3aa8a56 | 2018-10-09 15:49:15 | [diff] [blame] | 6519 | |
Reilly Grant | 392c611 | 2019-04-23 19:12:12 | [diff] [blame] | 6520 | // Update policy to add an entry to the permission value to allow |
| 6521 | // |kTestOrigin| to access the device described by |device_info|. |
Ovidio Henriquez | e3aa8a56 | 2018-10-09 15:49:15 | [diff] [blame] | 6522 | PolicyMap policies; |
| 6523 | |
| 6524 | base::Value device_value(base::Value::Type::DICTIONARY); |
| 6525 | device_value.SetKey("vendor_id", base::Value(0)); |
| 6526 | device_value.SetKey("product_id", base::Value(0)); |
| 6527 | |
| 6528 | base::Value devices_value(base::Value::Type::LIST); |
| 6529 | devices_value.GetList().push_back(std::move(device_value)); |
| 6530 | |
Ovidio Henriquez | c6b23f1 | 2018-11-15 21:26:31 | [diff] [blame] | 6531 | base::Value urls_value(base::Value::Type::LIST); |
| 6532 | urls_value.GetList().emplace_back(base::Value("https://foo.com")); |
Ovidio Henriquez | e3aa8a56 | 2018-10-09 15:49:15 | [diff] [blame] | 6533 | |
| 6534 | base::Value entry(base::Value::Type::DICTIONARY); |
| 6535 | entry.SetKey("devices", std::move(devices_value)); |
Ovidio Henriquez | c6b23f1 | 2018-11-15 21:26:31 | [diff] [blame] | 6536 | entry.SetKey("urls", std::move(urls_value)); |
Ovidio Henriquez | e3aa8a56 | 2018-10-09 15:49:15 | [diff] [blame] | 6537 | |
| 6538 | auto policy_value = std::make_unique<base::Value>(base::Value::Type::LIST); |
| 6539 | policy_value->GetList().push_back(std::move(entry)); |
| 6540 | |
| 6541 | SetPolicy(&policies, key::kWebUsbAllowDevicesForUrls, |
| 6542 | std::move(policy_value)); |
| 6543 | UpdateProviderPolicy(policies); |
| 6544 | |
Reilly Grant | 392c611 | 2019-04-23 19:12:12 | [diff] [blame] | 6545 | EXPECT_TRUE( |
Donna Wu | fd06ab3 | 2019-05-07 16:39:32 | [diff] [blame] | 6546 | context->HasDevicePermission(kTestOrigin, kTestOrigin, device_info)); |
Ovidio Henriquez | e3aa8a56 | 2018-10-09 15:49:15 | [diff] [blame] | 6547 | |
| 6548 | // Remove the policy to ensure that it can be dynamically updated. |
| 6549 | SetPolicy(&policies, key::kWebUsbAllowDevicesForUrls, |
| 6550 | std::make_unique<base::Value>(base::Value::Type::LIST)); |
| 6551 | UpdateProviderPolicy(policies); |
| 6552 | |
Reilly Grant | 392c611 | 2019-04-23 19:12:12 | [diff] [blame] | 6553 | EXPECT_FALSE( |
Donna Wu | fd06ab3 | 2019-05-07 16:39:32 | [diff] [blame] | 6554 | context->HasDevicePermission(kTestOrigin, kTestOrigin, device_info)); |
Ovidio Henriquez | e3aa8a56 | 2018-10-09 15:49:15 | [diff] [blame] | 6555 | } |
| 6556 | |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 6557 | // Handler for embedded http-server, returns a small page with javascript |
| 6558 | // variable and a link to increment it. It's for JavascriptBlacklistable test. |
| 6559 | std::unique_ptr<net::test_server::HttpResponse> JSIncrementerPageHandler( |
| 6560 | const net::test_server::HttpRequest& request) { |
| 6561 | if (request.relative_url != "/test.html") { |
| 6562 | return std::unique_ptr<net::test_server::HttpResponse>(); |
| 6563 | } |
| 6564 | |
| 6565 | std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 6566 | new net::test_server::BasicHttpResponse()); |
| 6567 | http_response->set_code(net::HTTP_OK); |
| 6568 | http_response->set_content( |
| 6569 | "<head><script type=\"text/javascript\">\n" |
| 6570 | "<!--\n" |
| 6571 | "var value = 1;" |
| 6572 | "var increment = function() {" |
| 6573 | " value = value + 1;" |
| 6574 | "};\n" |
| 6575 | "//-->\n" |
| 6576 | "</script></head><body>" |
| 6577 | "<a id='link' href=\"javascript:increment();\">click</a>" |
| 6578 | "</body>"); |
| 6579 | http_response->set_content_type("text/html"); |
| 6580 | return http_response; |
| 6581 | } |
| 6582 | |
| 6583 | // Fetch value from page generated by JSIncrementerPageHandler. |
| 6584 | int JSIncrementerFetch(content::WebContents* contents) { |
| 6585 | int result; |
| 6586 | EXPECT_TRUE(content::ExecuteScriptAndExtractInt( |
| 6587 | contents, "domAutomationController.send(value);", &result)); |
| 6588 | return result; |
| 6589 | } |
| 6590 | |
| 6591 | // Tests that javascript-links are handled properly according to blacklist |
| 6592 | // settings, bug 913334. |
| 6593 | IN_PROC_BROWSER_TEST_F(PolicyTest, JavascriptBlacklistable) { |
| 6594 | embedded_test_server()->RegisterRequestHandler( |
| 6595 | base::BindRepeating(&JSIncrementerPageHandler)); |
| 6596 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 6597 | content::WebContents* contents = |
| 6598 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 6599 | ui_test_utils::NavigateToURL(browser(), |
| 6600 | embedded_test_server()->GetURL("/test.html")); |
| 6601 | |
| 6602 | EXPECT_EQ(JSIncrementerFetch(contents), 1); |
| 6603 | |
| 6604 | // Without blacklist policy value is incremented properly. |
| 6605 | ui_test_utils::NavigateToURLWithDisposition( |
| 6606 | browser(), GURL("javascript:increment()"), |
| 6607 | WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); |
| 6608 | |
| 6609 | EXPECT_EQ(JSIncrementerFetch(contents), 2); |
| 6610 | |
| 6611 | // Create and apply a policy. |
| 6612 | base::ListValue blacklist; |
| 6613 | blacklist.AppendString("javascript://*"); |
| 6614 | PolicyMap policies; |
| 6615 | policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 6616 | POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
| 6617 | UpdateProviderPolicy(policies); |
| 6618 | FlushBlacklistPolicy(); |
| 6619 | |
| 6620 | // After applying policy javascript url's don't work any more, value leaves |
| 6621 | // unchanged. |
| 6622 | ui_test_utils::NavigateToURLWithDisposition( |
| 6623 | browser(), GURL("javascript:increment()"), |
| 6624 | WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); |
| 6625 | EXPECT_EQ(JSIncrementerFetch(contents), 2); |
| 6626 | |
| 6627 | // But in-page links still work even if they are javascript-links. |
| 6628 | EXPECT_TRUE(content::ExecuteScript( |
| 6629 | contents, "document.getElementById('link').click();")); |
| 6630 | EXPECT_EQ(JSIncrementerFetch(contents), 3); |
| 6631 | } |
| 6632 | |
Giovanni Ortuño Urquidi | 77b5bf7 | 2018-08-23 06:43:29 | [diff] [blame] | 6633 | // Similar to PolicyTest but sets the WebAppInstallForceList policy before the |
| 6634 | // browser is started. |
| 6635 | class WebAppInstallForceListPolicyTest : public PolicyTest { |
| 6636 | public: |
| 6637 | WebAppInstallForceListPolicyTest() {} |
| 6638 | ~WebAppInstallForceListPolicyTest() override {} |
| 6639 | |
| 6640 | void SetUpInProcessBrowserTestFixture() override { |
| 6641 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 6642 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 6643 | |
| 6644 | policy_app_url_ = |
| 6645 | embedded_test_server()->GetURL("/banners/manifest_test_page.html"); |
| 6646 | base::Value url(policy_app_url_.spec()); |
| 6647 | base::Value launch_container("window"); |
| 6648 | |
| 6649 | base::Value item(base::Value::Type::DICTIONARY); |
| 6650 | item.SetKey("url", std::move(url)); |
Giovanni Ortuño Urquidi | 02a57821 | 2019-03-28 01:57:40 | [diff] [blame] | 6651 | item.SetKey("default_launch_container", std::move(launch_container)); |
Giovanni Ortuño Urquidi | 77b5bf7 | 2018-08-23 06:43:29 | [diff] [blame] | 6652 | |
| 6653 | base::Value list(base::Value::Type::LIST); |
| 6654 | list.GetList().push_back(std::move(item)); |
| 6655 | |
| 6656 | PolicyMap policies; |
| 6657 | SetPolicy(&policies, key::kWebAppInstallForceList, |
| 6658 | base::Value::ToUniquePtrValue(std::move(list))); |
| 6659 | provider_.UpdateChromePolicy(policies); |
| 6660 | } |
| 6661 | |
| 6662 | protected: |
| 6663 | GURL policy_app_url_; |
| 6664 | |
| 6665 | private: |
| 6666 | DISALLOW_COPY_AND_ASSIGN(WebAppInstallForceListPolicyTest); |
| 6667 | }; |
| 6668 | |
Giovanni Ortuño Urquidi | 273c607 | 2019-06-13 07:15:36 | [diff] [blame] | 6669 | IN_PROC_BROWSER_TEST_F(WebAppInstallForceListPolicyTest, StartUpInstallation) { |
Giovanni Ortuño Urquidi | 77b5bf7 | 2018-08-23 06:43:29 | [diff] [blame] | 6670 | extensions::TestExtensionRegistryObserver observer( |
| 6671 | extensions::ExtensionRegistry::Get(browser()->profile())); |
| 6672 | const extensions::Extension* installed_extension = |
| 6673 | observer.WaitForExtensionWillBeInstalled(); |
| 6674 | |
| 6675 | ASSERT_TRUE(installed_extension); |
| 6676 | const GURL installed_app_url = |
| 6677 | extensions::AppLaunchInfo::GetFullLaunchURL(installed_extension); |
| 6678 | EXPECT_EQ(policy_app_url_, installed_app_url); |
| 6679 | } |
| 6680 | |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 6681 | #if defined(OS_WIN) |
| 6682 | |
| 6683 | class ForceNetworkInProcessTest : public InProcessBrowserTest { |
| 6684 | public: |
| 6685 | // InProcessBrowserTest implementation: |
| 6686 | void SetUp() override { |
| 6687 | EXPECT_CALL(policy_provider_, IsInitializationComplete(testing::_)) |
| 6688 | .WillRepeatedly(testing::Return(true)); |
| 6689 | policy::PolicyMap values; |
| 6690 | values.Set(policy::key::kForceNetworkInProcess, |
| 6691 | policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE, |
| 6692 | policy::POLICY_SOURCE_CLOUD, std::make_unique<base::Value>(true), |
| 6693 | nullptr); |
| 6694 | policy_provider_.UpdateChromePolicy(values); |
| 6695 | policy::BrowserPolicyConnector::SetPolicyProviderForTesting( |
| 6696 | &policy_provider_); |
| 6697 | |
| 6698 | InProcessBrowserTest::SetUp(); |
| 6699 | } |
| 6700 | |
| 6701 | private: |
| 6702 | policy::MockConfigurationPolicyProvider policy_provider_; |
| 6703 | }; |
| 6704 | |
| 6705 | IN_PROC_BROWSER_TEST_F(ForceNetworkInProcessTest, Enabled) { |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 6706 | ASSERT_TRUE(content::IsInProcessNetworkService()); |
| 6707 | } |
| 6708 | |
| 6709 | #endif // defined(OS_WIN) |
| 6710 | |
Elad Alon | ef47943 | 2018-08-27 10:43:57 | [diff] [blame] | 6711 | #if !defined(OS_ANDROID) |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6712 | |
| 6713 | // The possibilities for a boolean policy. |
| 6714 | enum class BooleanPolicy { |
| 6715 | kNotConfigured, |
| 6716 | kFalse, |
| 6717 | kTrue, |
| 6718 | }; |
| 6719 | |
Elad Alon | ef47943 | 2018-08-27 10:43:57 | [diff] [blame] | 6720 | #endif // !defined(OS_ANDROID) |
| 6721 | |
| 6722 | #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 6723 | |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6724 | // Tests that the PromotionalTabsEnabled policy properly suppresses the welcome |
| 6725 | // page for browser first-runs. |
| 6726 | class PromotionalTabsEnabledPolicyTest |
| 6727 | : public PolicyTest, |
| 6728 | public testing::WithParamInterface<BooleanPolicy> { |
| 6729 | protected: |
Hector Carmona | 1e62e35 | 2019-06-24 19:18:17 | [diff] [blame] | 6730 | PromotionalTabsEnabledPolicyTest() { |
| 6731 | scoped_feature_list_.InitWithFeatures({nux::kNuxOnboardingForceEnabled}, |
| 6732 | {}); |
| 6733 | } |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6734 | ~PromotionalTabsEnabledPolicyTest() = default; |
| 6735 | |
| 6736 | void SetUp() override { |
| 6737 | // Ordinarily, browser tests include chrome://blank on the command line to |
| 6738 | // suppress any onboarding or promotional tabs. This test, on the other |
| 6739 | // hand, must evaluate startup with nothing on the command line so that a |
| 6740 | // default launch takes place. |
| 6741 | set_open_about_blank_on_browser_launch(false); |
| 6742 | PolicyTest::SetUp(); |
| 6743 | } |
| 6744 | |
| 6745 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 6746 | command_line->AppendSwitch(switches::kForceFirstRun); |
| 6747 | } |
| 6748 | |
| 6749 | void CreatedBrowserMainParts( |
| 6750 | content::BrowserMainParts* browser_main_parts) override { |
Greg Thompson | 5cd9ed31 | 2018-07-23 13:40:48 | [diff] [blame] | 6751 | // Set policies before the browser starts up. |
| 6752 | PolicyMap policies; |
| 6753 | |
| 6754 | // Suppress the first-run dialog by disabling metrics reporting. |
| 6755 | policies.Set(key::kMetricsReportingEnabled, POLICY_LEVEL_MANDATORY, |
| 6756 | POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
| 6757 | std::make_unique<base::Value>(false), nullptr); |
| 6758 | |
| 6759 | // Apply the policy setting under test. |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6760 | if (GetParam() != BooleanPolicy::kNotConfigured) { |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6761 | policies.Set( |
| 6762 | key::kPromotionalTabsEnabled, POLICY_LEVEL_MANDATORY, |
| 6763 | POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
| 6764 | std::make_unique<base::Value>(GetParam() == BooleanPolicy::kTrue), |
| 6765 | nullptr); |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6766 | } |
Greg Thompson | 5cd9ed31 | 2018-07-23 13:40:48 | [diff] [blame] | 6767 | |
| 6768 | UpdateProviderPolicy(policies); |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6769 | PolicyTest::CreatedBrowserMainParts(browser_main_parts); |
| 6770 | } |
| 6771 | |
| 6772 | private: |
Hector Carmona | 1e62e35 | 2019-06-24 19:18:17 | [diff] [blame] | 6773 | base::test::ScopedFeatureList scoped_feature_list_; |
| 6774 | |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6775 | DISALLOW_COPY_AND_ASSIGN(PromotionalTabsEnabledPolicyTest); |
| 6776 | }; |
| 6777 | |
Greg Thompson | 5cd9ed31 | 2018-07-23 13:40:48 | [diff] [blame] | 6778 | IN_PROC_BROWSER_TEST_P(PromotionalTabsEnabledPolicyTest, RunTest) { |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6779 | TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 6780 | ASSERT_GE(tab_strip->count(), 1); |
| 6781 | const auto& url = tab_strip->GetWebContentsAt(0)->GetURL(); |
| 6782 | switch (GetParam()) { |
| 6783 | case BooleanPolicy::kFalse: |
| 6784 | // Only the NTP should show. |
| 6785 | EXPECT_EQ(tab_strip->count(), 1); |
| 6786 | if (url.possibly_invalid_spec() != chrome::kChromeUINewTabURL) |
Kyle Milka | e0f5250 | 2019-04-17 00:24:08 | [diff] [blame] | 6787 | EXPECT_TRUE(search::IsNTPOrRelatedURL(url, browser()->profile())) |
| 6788 | << url; |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6789 | break; |
| 6790 | case BooleanPolicy::kNotConfigured: |
| 6791 | case BooleanPolicy::kTrue: |
| 6792 | // One or more onboarding tabs should show. |
| 6793 | EXPECT_NE(url.possibly_invalid_spec(), chrome::kChromeUINewTabURL); |
Kyle Milka | e0f5250 | 2019-04-17 00:24:08 | [diff] [blame] | 6794 | EXPECT_FALSE(search::IsNTPOrRelatedURL(url, browser()->profile())) << url; |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6795 | break; |
| 6796 | } |
| 6797 | } |
Greg Thompson | a37b35b | 2018-06-29 11:35:44 | [diff] [blame] | 6798 | #undef MAYBE_RunTest |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6799 | |
Victor Costan | e5e9151 | 2019-02-13 08:24:02 | [diff] [blame] | 6800 | INSTANTIATE_TEST_SUITE_P(, |
| 6801 | PromotionalTabsEnabledPolicyTest, |
| 6802 | ::testing::Values(BooleanPolicy::kNotConfigured, |
| 6803 | BooleanPolicy::kFalse, |
| 6804 | BooleanPolicy::kTrue)); |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6805 | |
Elad Alon | ef47943 | 2018-08-27 10:43:57 | [diff] [blame] | 6806 | #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 6807 | |
| 6808 | #if !defined(OS_ANDROID) |
Elad Alon | 6bd69cb | 2018-08-06 18:20:45 | [diff] [blame] | 6809 | class WebRtcEventLogCollectionAllowedPolicyTest |
| 6810 | : public PolicyTest, |
| 6811 | public testing::WithParamInterface<BooleanPolicy> { |
| 6812 | public: |
| 6813 | ~WebRtcEventLogCollectionAllowedPolicyTest() override = default; |
| 6814 | |
| 6815 | void SetUpInProcessBrowserTestFixture() override { |
| 6816 | PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 6817 | PolicyMap policies; |
| 6818 | |
| 6819 | const BooleanPolicy policy = GetParam(); |
| 6820 | if (policy == BooleanPolicy::kFalse || policy == BooleanPolicy::kTrue) { |
| 6821 | const bool policy_bool = (policy == BooleanPolicy::kTrue); |
| 6822 | policies.Set(policy::key::kWebRtcEventLogCollectionAllowed, |
| 6823 | policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 6824 | policy::POLICY_SOURCE_ENTERPRISE_DEFAULT, |
| 6825 | std::make_unique<base::Value>(policy_bool), nullptr); |
| 6826 | } |
| 6827 | |
| 6828 | provider_.UpdateChromePolicy(policies); |
| 6829 | } |
| 6830 | |
| 6831 | const PrefService::Preference* GetPreference() const { |
| 6832 | auto* service = user_prefs::UserPrefs::Get(browser()->profile()); |
| 6833 | return service->FindPreference(prefs::kWebRtcEventLogCollectionAllowed); |
| 6834 | } |
| 6835 | |
| 6836 | base::OnceCallback<void(bool)> BlockingBoolExpectingReply( |
| 6837 | base::RunLoop* run_loop, |
| 6838 | bool expected_value) { |
| 6839 | return base::BindOnce( |
| 6840 | [](base::RunLoop* run_loop, bool expected_value, bool value) { |
| 6841 | EXPECT_EQ(expected_value, value); |
| 6842 | run_loop->Quit(); |
| 6843 | }, |
| 6844 | run_loop, expected_value); |
| 6845 | } |
| 6846 | |
| 6847 | // The "extras" in question are the ID and error (only one of which may |
| 6848 | // be non-null), which this test ignores (tested elsewhere). |
| 6849 | base::OnceCallback<void(bool, const std::string&, const std::string&)> |
| 6850 | BlockingBoolExpectingReplyWithExtras(base::RunLoop* run_loop, |
| 6851 | bool expected_value) { |
| 6852 | return base::BindOnce( |
| 6853 | [](base::RunLoop* run_loop, bool expected_value, bool value, |
| 6854 | const std::string& ignored_log_id, |
| 6855 | const std::string& ignored_error) { |
| 6856 | EXPECT_EQ(expected_value, value); |
| 6857 | run_loop->Quit(); |
| 6858 | }, |
| 6859 | run_loop, expected_value); |
| 6860 | } |
| 6861 | }; |
| 6862 | |
| 6863 | IN_PROC_BROWSER_TEST_P(WebRtcEventLogCollectionAllowedPolicyTest, RunTest) { |
| 6864 | const PrefService::Preference* const pref = GetPreference(); |
| 6865 | const bool remote_logging_allowed = (GetParam() == BooleanPolicy::kTrue); |
| 6866 | ASSERT_EQ(pref->GetValue()->GetBool(), remote_logging_allowed); |
| 6867 | |
| 6868 | auto* webrtc_event_log_manager = WebRtcEventLogManager::GetInstance(); |
| 6869 | ASSERT_TRUE(webrtc_event_log_manager); |
| 6870 | |
| 6871 | content::WebContents* web_contents = |
| 6872 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 6873 | int render_process_id = web_contents->GetMainFrame()->GetProcess()->GetID(); |
| 6874 | |
| 6875 | constexpr int kLid = 123; |
Elad Alon | 5b9d29d | 2019-03-01 22:28:29 | [diff] [blame] | 6876 | const std::string kSessionId = "id"; |
Elad Alon | 6bd69cb | 2018-08-06 18:20:45 | [diff] [blame] | 6877 | |
| 6878 | { |
| 6879 | base::RunLoop run_loop; |
| 6880 | webrtc_event_log_manager->PeerConnectionAdded( |
Elad Alon | 5b9d29d | 2019-03-01 22:28:29 | [diff] [blame] | 6881 | render_process_id, kLid, BlockingBoolExpectingReply(&run_loop, true)); |
| 6882 | run_loop.Run(); |
| 6883 | } |
| 6884 | |
| 6885 | { |
| 6886 | base::RunLoop run_loop; |
| 6887 | webrtc_event_log_manager->PeerConnectionSessionIdSet( |
| 6888 | render_process_id, kLid, kSessionId, |
Elad Alon | 6bd69cb | 2018-08-06 18:20:45 | [diff] [blame] | 6889 | BlockingBoolExpectingReply(&run_loop, true)); |
| 6890 | run_loop.Run(); |
| 6891 | } |
| 6892 | |
| 6893 | { |
| 6894 | constexpr size_t kMaxFileSizeBytes = 1000 * 1000; |
Elad Alon | a085b1d | 2018-12-08 23:55:58 | [diff] [blame] | 6895 | constexpr int kOutputPeriodMs = 1000; |
| 6896 | |
Elad Alon | 6bd69cb | 2018-08-06 18:20:45 | [diff] [blame] | 6897 | base::RunLoop run_loop; |
| 6898 | |
| 6899 | // Test focus - remote-bound logging allowed if and only if the policy |
| 6900 | // is configured to allow it. |
| 6901 | webrtc_event_log_manager->StartRemoteLogging( |
Elad Alon | 5b9d29d | 2019-03-01 22:28:29 | [diff] [blame] | 6902 | render_process_id, kSessionId, kMaxFileSizeBytes, kOutputPeriodMs, |
| 6903 | kWebAppId, |
Elad Alon | 6bd69cb | 2018-08-06 18:20:45 | [diff] [blame] | 6904 | BlockingBoolExpectingReplyWithExtras(&run_loop, |
| 6905 | remote_logging_allowed)); |
| 6906 | run_loop.Run(); |
| 6907 | } |
| 6908 | } |
| 6909 | |
Victor Costan | e5e9151 | 2019-02-13 08:24:02 | [diff] [blame] | 6910 | INSTANTIATE_TEST_SUITE_P(, |
| 6911 | WebRtcEventLogCollectionAllowedPolicyTest, |
| 6912 | ::testing::Values(BooleanPolicy::kNotConfigured, |
| 6913 | BooleanPolicy::kFalse, |
| 6914 | BooleanPolicy::kTrue)); |
Elad Alon | ef47943 | 2018-08-27 10:43:57 | [diff] [blame] | 6915 | #endif // !defined(OS_ANDROID) |
Greg Thompson | 146eef8c | 2018-06-26 09:30:54 | [diff] [blame] | 6916 | |
Kunihiko Sakamoto | f586da6 | 2019-03-28 03:03:04 | [diff] [blame] | 6917 | class SignedExchangePolicyTest : public PolicyTest { |
| 6918 | public: |
| 6919 | SignedExchangePolicyTest() {} |
| 6920 | ~SignedExchangePolicyTest() override {} |
| 6921 | |
| 6922 | void SetUp() override { |
| 6923 | embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data"); |
| 6924 | embedded_test_server()->RegisterRequestMonitor(base::BindRepeating( |
| 6925 | &SignedExchangePolicyTest::MonitorRequest, base::Unretained(this))); |
| 6926 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 6927 | |
| 6928 | sxg_test_helper_.SetUp(); |
| 6929 | PolicyTest::SetUp(); |
| 6930 | } |
| 6931 | |
| 6932 | void TearDownOnMainThread() override { |
| 6933 | PolicyTest::TearDownOnMainThread(); |
| 6934 | sxg_test_helper_.TearDownOnMainThread(); |
| 6935 | } |
| 6936 | |
| 6937 | protected: |
| 6938 | void SetSignedExchangePolicy(bool enabled) { |
| 6939 | PolicyMap policies; |
| 6940 | policies.Set(key::kSignedHTTPExchangeEnabled, POLICY_LEVEL_MANDATORY, |
| 6941 | POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
| 6942 | std::make_unique<base::Value>(enabled), nullptr); |
| 6943 | UpdateProviderPolicy(policies); |
| 6944 | } |
| 6945 | |
| 6946 | void InstallUrlInterceptor(const GURL& url, const std::string& data_path) { |
| 6947 | sxg_test_helper_.InstallUrlInterceptor(url, data_path); |
| 6948 | } |
| 6949 | |
| 6950 | bool HadSignedExchangeInAcceptHeader(const GURL& url) const { |
| 6951 | const auto it = url_accept_header_map_.find(url); |
| 6952 | if (it == url_accept_header_map_.end()) |
| 6953 | return false; |
| 6954 | return it->second.find("application/signed-exchange") != std::string::npos; |
| 6955 | } |
| 6956 | |
| 6957 | private: |
| 6958 | void MonitorRequest(const net::test_server::HttpRequest& request) { |
| 6959 | const auto it = request.headers.find("Accept"); |
| 6960 | if (it == request.headers.end()) |
| 6961 | return; |
| 6962 | url_accept_header_map_[request.base_url.Resolve(request.relative_url)] = |
| 6963 | it->second; |
| 6964 | } |
| 6965 | |
| 6966 | content::SignedExchangeBrowserTestHelper sxg_test_helper_; |
| 6967 | std::map<GURL, std::string> url_accept_header_map_; |
| 6968 | }; |
| 6969 | |
| 6970 | IN_PROC_BROWSER_TEST_F(SignedExchangePolicyTest, SignedExchangeDisabled) { |
| 6971 | SetSignedExchangePolicy(false); |
| 6972 | |
| 6973 | content::DownloadTestObserverTerminal download_observer( |
| 6974 | content::BrowserContext::GetDownloadManager(browser()->profile()), 1, |
| 6975 | content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY); |
| 6976 | |
| 6977 | GURL url = embedded_test_server()->GetURL("/sxg/test.example.org_test.sxg"); |
| 6978 | ui_test_utils::NavigateToURL(browser(), url); |
| 6979 | |
| 6980 | download_observer.WaitForFinished(); |
| 6981 | |
| 6982 | // Check that the SXG file was not loaded as a page, but downloaded. |
| 6983 | std::vector<download::DownloadItem*> downloads; |
| 6984 | content::BrowserContext::GetDownloadManager(browser()->profile()) |
| 6985 | ->GetAllDownloads(&downloads); |
| 6986 | ASSERT_EQ(1u, downloads.size()); |
| 6987 | EXPECT_EQ(downloads[0]->GetURL(), url); |
| 6988 | |
| 6989 | ASSERT_FALSE(HadSignedExchangeInAcceptHeader(url)); |
| 6990 | } |
| 6991 | |
| 6992 | IN_PROC_BROWSER_TEST_F(SignedExchangePolicyTest, SignedExchangeEnabled) { |
| 6993 | SetSignedExchangePolicy(true); |
| 6994 | |
| 6995 | InstallUrlInterceptor(GURL("https://test.example.org/test/"), |
| 6996 | "content/test/data/sxg/fallback.html"); |
| 6997 | |
| 6998 | GURL url = embedded_test_server()->GetURL("/sxg/test.example.org_test.sxg"); |
| 6999 | base::string16 title = base::ASCIIToUTF16("Fallback URL response"); |
| 7000 | content::TitleWatcher title_watcher( |
| 7001 | browser()->tab_strip_model()->GetActiveWebContents(), title); |
| 7002 | ui_test_utils::NavigateToURL(browser(), url); |
| 7003 | |
| 7004 | // Check that the SXG file was handled as a Signed Exchange, and the |
| 7005 | // navigation was redirected to the SXG's fallback URL. |
| 7006 | EXPECT_EQ(title, title_watcher.WaitAndGetTitle()); |
| 7007 | |
| 7008 | ASSERT_TRUE(HadSignedExchangeInAcceptHeader(url)); |
| 7009 | } |
| 7010 | |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 7011 | } // namespace policy |