[email protected] | 4d245165 | 2012-02-14 23:54:26 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 038d52e1 | 2009-10-14 16:53:41 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | #include <stdint.h> |
| 7 | |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 10 | #include "base/base_switches.h" |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 13 | #include "base/files/file_util.h" |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 14 | #include "base/path_service.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 16 | #include "base/strings/stringprintf.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 17 | #include "build/build_config.h" |
[email protected] | 9ea0cd3 | 2013-07-12 01:50:36 | [diff] [blame] | 18 | #include "chrome/browser/chrome_notification_types.h" |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_browsertest.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 22 | #include "chrome/browser/extensions/shared_user_script_master.h" |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 23 | #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 24 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 7b5dc00 | 2010-11-16 23:08:10 | [diff] [blame] | 25 | #include "chrome/browser/ui/browser.h" |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 26 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 27 | #include "chrome/common/chrome_constants.h" |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 28 | #include "chrome/common/chrome_paths.h" |
| 29 | #include "chrome/common/chrome_switches.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 30 | #include "chrome/test/base/in_process_browser_test.h" |
[email protected] | 89dbb177 | 2012-07-17 13:47:25 | [diff] [blame] | 31 | #include "chrome/test/base/testing_profile.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 32 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 33 | #include "content/public/browser/notification_details.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 34 | #include "content/public/browser/notification_service.h" |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 35 | #include "content/public/browser/web_contents.h" |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 36 | #include "content/public/common/content_switches.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 37 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 38 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 39 | #include "extensions/browser/extension_system.h" |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 40 | #include "extensions/common/extension.h" |
| 41 | #include "extensions/common/extension_set.h" |
[email protected] | 5ef835a | 2013-11-08 20:42:57 | [diff] [blame] | 42 | #include "extensions/common/feature_switch.h" |
emaxx | 35e8b82 | 2017-04-11 02:04:29 | [diff] [blame] | 43 | #include "extensions/common/manifest.h" |
[email protected] | d96cf75 | 2014-04-09 04:05:28 | [diff] [blame] | 44 | #include "net/base/filename_util.h" |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 45 | |
emaxx | 35e8b82 | 2017-04-11 02:04:29 | [diff] [blame] | 46 | #if defined(OS_CHROMEOS) |
| 47 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 48 | #endif |
| 49 | |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 50 | using extensions::FeatureSwitch; |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 51 | using extensions::ExtensionRegistry; |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 52 | |
[email protected] | 17c4f3c | 2009-07-04 16:36:25 | [diff] [blame] | 53 | // This file contains high-level startup tests for the extensions system. We've |
| 54 | // had many silly bugs where command line flags did not get propagated correctly |
| 55 | // into the services, so we didn't start correctly. |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 56 | |
[email protected] | 3e59bac | 2010-04-08 16:16:55 | [diff] [blame] | 57 | class ExtensionStartupTestBase : public InProcessBrowserTest { |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 58 | public: |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 59 | ExtensionStartupTestBase() : unauthenticated_load_allowed_(true) { |
[email protected] | fe13bf6 | 2010-08-26 14:33:19 | [diff] [blame] | 60 | num_expected_extensions_ = 3; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | protected: |
| 64 | // InProcessBrowserTest |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 65 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 66 | if (load_extensions_.empty()) { |
| 67 | // If no |load_extensions_| were specified, allow unauthenticated |
| 68 | // extension settings to be loaded from Preferences as if they had been |
| 69 | // authenticated correctly before they were handed to the ExtensionSystem. |
| 70 | command_line->AppendSwitchASCII( |
| 71 | switches::kForceFieldTrials, |
| 72 | base::StringPrintf( |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 73 | "%s/%s/", chrome_prefs::internals::kSettingsEnforcementTrialName, |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 74 | chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement)); |
proberge | 2562e6f | 2017-04-10 17:46:57 | [diff] [blame] | 75 | #if defined(OFFICIAL_BUILD) && (defined(OS_WIN) || defined(OS_MACOSX)) |
| 76 | // In Windows and MacOS official builds, it is not possible to disable |
| 77 | // settings enforcement. |
[email protected] | 55274dd | 2014-06-23 21:51:18 | [diff] [blame] | 78 | unauthenticated_load_allowed_ = false; |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 79 | #endif |
| 80 | } else { |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 81 | base::FilePath::StringType paths = base::JoinString( |
| 82 | load_extensions_, base::FilePath::StringType(1, ',')); |
| 83 | command_line->AppendSwitchNative(switches::kLoadExtension, paths); |
[email protected] | 10f6b14 | 2012-04-14 19:22:43 | [diff] [blame] | 84 | command_line->AppendSwitch(switches::kDisableExtensionsFileAccessCheck); |
| 85 | } |
| 86 | } |
| 87 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 88 | bool SetUpUserDataDirectory() override { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 89 | base::FilePath profile_dir; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 90 | PathService::Get(chrome::DIR_USER_DATA, &profile_dir); |
[email protected] | 89dbb177 | 2012-07-17 13:47:25 | [diff] [blame] | 91 | profile_dir = profile_dir.AppendASCII(TestingProfile::kTestUserProfileDir); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 92 | base::CreateDirectory(profile_dir); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 93 | |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 94 | preferences_file_ = profile_dir.Append(chrome::kPreferencesFilename); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 95 | user_scripts_dir_ = profile_dir.AppendASCII("User Scripts"); |
| 96 | extensions_dir_ = profile_dir.AppendASCII("Extensions"); |
| 97 | |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 98 | if (load_extensions_.empty()) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 99 | base::FilePath src_dir; |
[email protected] | 10f6b14 | 2012-04-14 19:22:43 | [diff] [blame] | 100 | PathService::Get(chrome::DIR_TEST_DATA, &src_dir); |
| 101 | src_dir = src_dir.AppendASCII("extensions").AppendASCII("good"); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 102 | |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 103 | base::CopyFile(src_dir.Append(chrome::kPreferencesFilename), |
| 104 | preferences_file_); |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 105 | base::CopyDirectory(src_dir.AppendASCII("Extensions"), profile_dir, |
| 106 | true); // recursive |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 107 | } |
[email protected] | 10f6b14 | 2012-04-14 19:22:43 | [diff] [blame] | 108 | return true; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 109 | } |
| 110 | |
gab | bcdefd0cc | 2015-02-17 18:12:40 | [diff] [blame] | 111 | void SetUpInProcessBrowserTestFixture() override { |
| 112 | InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 113 | |
| 114 | // Bots are on a domain, turn off the domain check for settings hardening in |
| 115 | // order to be able to test all SettingsEnforcement groups. |
| 116 | chrome_prefs::DisableDomainCheckForTesting(); |
| 117 | } |
| 118 | |
dcheng | 7219181 | 2014-10-28 20:49:56 | [diff] [blame] | 119 | void TearDown() override { |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 120 | EXPECT_TRUE(base::DeleteFile(preferences_file_, false)); |
[email protected] | 020f49e | 2010-04-08 19:51:12 | [diff] [blame] | 121 | |
| 122 | // TODO(phajdan.jr): Check return values of the functions below, carefully. |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 123 | base::DeleteFile(user_scripts_dir_, true); |
| 124 | base::DeleteFile(extensions_dir_, true); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 125 | |
| 126 | InProcessBrowserTest::TearDown(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 127 | } |
| 128 | |
emaxx | 35e8b82 | 2017-04-11 02:04:29 | [diff] [blame] | 129 | static int GetNonComponentEnabledExtensionCount(Profile* profile) { |
| 130 | extensions::ExtensionRegistry* registry = |
| 131 | extensions::ExtensionRegistry::Get(profile); |
| 132 | int found_extensions = 0; |
| 133 | for (const auto& extension : registry->enabled_extensions()) { |
| 134 | if (!extensions::Manifest::IsComponentLocation(extension->location())) |
| 135 | ++found_extensions; |
| 136 | } |
| 137 | return found_extensions; |
| 138 | } |
| 139 | |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 140 | void WaitForServicesToStart(int num_expected_extensions, |
| 141 | bool expect_extensions_enabled) { |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 142 | if (!unauthenticated_load_allowed_) |
| 143 | num_expected_extensions = 0; |
emaxx | 35e8b82 | 2017-04-11 02:04:29 | [diff] [blame] | 144 | ASSERT_EQ(num_expected_extensions, |
| 145 | GetNonComponentEnabledExtensionCount(browser()->profile())); |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 146 | |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 147 | ExtensionService* service = |
| 148 | extensions::ExtensionSystem::Get(browser()->profile()) |
| 149 | ->extension_service(); |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 150 | ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled()); |
| 151 | |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 152 | content::WindowedNotificationObserver user_scripts_observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 153 | extensions::NOTIFICATION_USER_SCRIPTS_UPDATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 154 | content::NotificationService::AllSources()); |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 155 | extensions::SharedUserScriptMaster* master = |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 156 | extensions::ExtensionSystem::Get(browser()->profile()) |
| 157 | ->shared_user_script_master(); |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 158 | if (!master->scripts_ready()) |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 159 | user_scripts_observer.Wait(); |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 160 | ASSERT_TRUE(master->scripts_ready()); |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | void TestInjection(bool expect_css, bool expect_script) { |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 164 | if (!unauthenticated_load_allowed_) { |
| 165 | expect_css = false; |
| 166 | expect_script = false; |
| 167 | } |
| 168 | |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 169 | // Load a page affected by the content script and test to see the effect. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 170 | base::FilePath test_file; |
[email protected] | 6277144 | 2009-11-22 02:25:04 | [diff] [blame] | 171 | PathService::Get(chrome::DIR_TEST_DATA, &test_file); |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 172 | test_file = |
| 173 | test_file.AppendASCII("extensions").AppendASCII("test_file.html"); |
[email protected] | 6277144 | 2009-11-22 02:25:04 | [diff] [blame] | 174 | |
| 175 | ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file)); |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 176 | |
| 177 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 178 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 179 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 180 | "window.domAutomationController.send(" |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 181 | " document.defaultView.getComputedStyle(document.body, null)." |
| 182 | " getPropertyValue('background-color') == 'rgb(245, 245, 220)')", |
[email protected] | 9fabbf7 | 2010-09-30 21:50:05 | [diff] [blame] | 183 | &result)); |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 184 | EXPECT_EQ(expect_css, result); |
| 185 | |
| 186 | result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 187 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 188 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 189 | "window.domAutomationController.send(document.title == 'Modified')", |
[email protected] | 9fabbf7 | 2010-09-30 21:50:05 | [diff] [blame] | 190 | &result)); |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 191 | EXPECT_EQ(expect_script, result); |
| 192 | } |
| 193 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 194 | base::FilePath preferences_file_; |
| 195 | base::FilePath extensions_dir_; |
| 196 | base::FilePath user_scripts_dir_; |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 197 | // True unless unauthenticated extension settings are not allowed to be |
| 198 | // loaded in this configuration. |
| 199 | bool unauthenticated_load_allowed_; |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 200 | // Extensions to load from the command line. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 201 | std::vector<base::FilePath::StringType> load_extensions_; |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 202 | |
| 203 | int num_expected_extensions_; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | |
| 207 | // ExtensionsStartupTest |
| 208 | // Ensures that we can startup the browser with --enable-extensions and some |
| 209 | // extensions installed and see them run and do basic things. |
[email protected] | 60f7d7a | 2014-04-03 07:15:11 | [diff] [blame] | 210 | typedef ExtensionStartupTestBase ExtensionsStartupTest; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 211 | |
Nico Weber | 9ce471d4 | 2015-04-13 20:52:39 | [diff] [blame] | 212 | // Broken in official builds, http://crbug.com/474659 |
| 213 | IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, DISABLED_Test) { |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 214 | WaitForServicesToStart(num_expected_extensions_, true); |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 215 | TestInjection(true, true); |
| 216 | } |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 217 | |
Nico Weber | 9ce471d4 | 2015-04-13 20:52:39 | [diff] [blame] | 218 | // Broken in official builds, http://crbug.com/474659 |
[email protected] | b2f665f5 | 2010-07-02 01:32:09 | [diff] [blame] | 219 | // Sometimes times out on Mac. http://crbug.com/48151 |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 220 | // Tests that disallowing file access on an extension prevents it from injecting |
| 221 | // script into a page with a file URL. |
Nico Weber | 9ce471d4 | 2015-04-13 20:52:39 | [diff] [blame] | 222 | IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, DISABLED_NoFileAccess) { |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 223 | WaitForServicesToStart(num_expected_extensions_, true); |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 224 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 225 | // Keep a separate list of extensions for which to disable file access, since |
| 226 | // doing so reloads them. |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 227 | std::vector<const extensions::Extension*> extension_list; |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 228 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 229 | extensions::ExtensionRegistry* registry = |
| 230 | extensions::ExtensionRegistry::Get(browser()->profile()); |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 231 | for (extensions::ExtensionSet::const_iterator it = |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 232 | registry->enabled_extensions().begin(); |
| 233 | it != registry->enabled_extensions().end(); ++it) { |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 234 | if ((*it)->location() == extensions::Manifest::COMPONENT) |
[email protected] | fe13bf6 | 2010-08-26 14:33:19 | [diff] [blame] | 235 | continue; |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 236 | if (extensions::util::AllowFileAccess((*it)->id(), browser()->profile())) |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 237 | extension_list.push_back(it->get()); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | for (size_t i = 0; i < extension_list.size(); ++i) { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 241 | content::WindowedNotificationObserver user_scripts_observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 242 | extensions::NOTIFICATION_USER_SCRIPTS_UPDATED, |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 243 | content::NotificationService::AllSources()); |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 244 | extensions::util::SetAllowFileAccess(extension_list[i]->id(), |
| 245 | browser()->profile(), false); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 246 | user_scripts_observer.Wait(); |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | TestInjection(false, false); |
| 250 | } |
| 251 | |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 252 | // ExtensionsLoadTest |
| 253 | // Ensures that we can startup the browser with --load-extension and see them |
| 254 | // run. |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 255 | class ExtensionsLoadTest : public ExtensionStartupTestBase { |
| 256 | public: |
| 257 | ExtensionsLoadTest() { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 258 | base::FilePath one_extension_path; |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 259 | PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path); |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 260 | one_extension_path = one_extension_path.AppendASCII("extensions") |
| 261 | .AppendASCII("good") |
| 262 | .AppendASCII("Extensions") |
| 263 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 264 | .AppendASCII("1.0.0.0"); |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 265 | load_extensions_.push_back(one_extension_path.value()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 266 | } |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 267 | }; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 268 | |
[email protected] | dc12802 | 2012-02-17 23:14:58 | [diff] [blame] | 269 | IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Test) { |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 270 | WaitForServicesToStart(1, true); |
[email protected] | 919ddc8 | 2009-07-15 04:30:12 | [diff] [blame] | 271 | TestInjection(true, true); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 272 | } |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 273 | |
emaxx | 35e8b82 | 2017-04-11 02:04:29 | [diff] [blame] | 274 | #if defined(OS_CHROMEOS) |
| 275 | |
emaxx | b4c388b | 2017-05-11 18:11:24 | [diff] [blame] | 276 | IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, |
Maksim Ivanov | 8646d439 | 2017-05-11 20:18:54 | [diff] [blame^] | 277 | SigninProfileCommandLineExtensionsDontLoad) { |
emaxx | 35e8b82 | 2017-04-11 02:04:29 | [diff] [blame] | 278 | // The --load-extension command line flag should not be applied to the sign-in |
| 279 | // profile. |
| 280 | EXPECT_EQ(0, GetNonComponentEnabledExtensionCount( |
| 281 | chromeos::ProfileHelper::GetSigninProfile())); |
| 282 | } |
| 283 | |
| 284 | #endif // defined(OS_CHROMEOS) |
| 285 | |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 286 | // ExtensionsLoadMultipleTest |
| 287 | // Ensures that we can startup the browser with multiple extensions |
| 288 | // via --load-extension=X1,X2,X3. |
| 289 | class ExtensionsLoadMultipleTest : public ExtensionStartupTestBase { |
| 290 | public: |
| 291 | ExtensionsLoadMultipleTest() { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 292 | base::FilePath one_extension_path; |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 293 | PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path); |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 294 | one_extension_path = one_extension_path.AppendASCII("extensions") |
| 295 | .AppendASCII("good") |
| 296 | .AppendASCII("Extensions") |
| 297 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 298 | .AppendASCII("1.0.0.0"); |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 299 | load_extensions_.push_back(one_extension_path.value()); |
| 300 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 301 | base::FilePath second_extension_path; |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 302 | PathService::Get(chrome::DIR_TEST_DATA, &second_extension_path); |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 303 | second_extension_path = |
| 304 | second_extension_path.AppendASCII("extensions").AppendASCII("app"); |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 305 | load_extensions_.push_back(second_extension_path.value()); |
| 306 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 307 | base::FilePath third_extension_path; |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 308 | PathService::Get(chrome::DIR_TEST_DATA, &third_extension_path); |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 309 | third_extension_path = |
| 310 | third_extension_path.AppendASCII("extensions").AppendASCII("app1"); |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 311 | load_extensions_.push_back(third_extension_path.value()); |
| 312 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 313 | base::FilePath fourth_extension_path; |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 314 | PathService::Get(chrome::DIR_TEST_DATA, &fourth_extension_path); |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 315 | fourth_extension_path = |
| 316 | fourth_extension_path.AppendASCII("extensions").AppendASCII("app2"); |
[email protected] | bfc9356 | 2011-12-14 19:40:04 | [diff] [blame] | 317 | load_extensions_.push_back(fourth_extension_path.value()); |
| 318 | } |
| 319 | }; |
| 320 | |
| 321 | IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) { |
| 322 | WaitForServicesToStart(4, true); |
| 323 | TestInjection(true, true); |
| 324 | } |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 325 | |
catmullings | 1cc8fc7 | 2016-12-05 23:39:23 | [diff] [blame] | 326 | // TODO(catmullings): Remove test in future chrome release, perhaps M59. |
| 327 | class DeprecatedLoadComponentExtensionSwitchBrowserTest |
| 328 | : public ExtensionBrowserTest { |
| 329 | public: |
| 330 | DeprecatedLoadComponentExtensionSwitchBrowserTest() {} |
| 331 | |
| 332 | void SetUpCommandLine(base::CommandLine* command_line) override; |
| 333 | |
| 334 | ExtensionRegistry* GetExtensionRegistry() { |
| 335 | return ExtensionRegistry::Get(browser()->profile()); |
| 336 | } |
| 337 | }; |
| 338 | |
| 339 | void DeprecatedLoadComponentExtensionSwitchBrowserTest::SetUpCommandLine( |
| 340 | base::CommandLine* command_line) { |
| 341 | ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 342 | base::FilePath fp1(test_data_dir_.AppendASCII("app_dot_com_app/")); |
| 343 | base::FilePath fp2(test_data_dir_.AppendASCII("app/")); |
| 344 | |
| 345 | command_line->AppendSwitchASCII( |
| 346 | "load-component-extension", |
| 347 | fp1.AsUTF8Unsafe() + "," + fp2.AsUTF8Unsafe()); |
| 348 | } |
| 349 | |
| 350 | // Tests that the --load-component-extension flag is not supported. |
| 351 | IN_PROC_BROWSER_TEST_F(DeprecatedLoadComponentExtensionSwitchBrowserTest, |
| 352 | DefunctLoadComponentExtensionFlag) { |
| 353 | EXPECT_TRUE(extension_service()->extensions_enabled()); |
| 354 | |
| 355 | // Checks that the extensions loaded with the --load-component-extension flag |
| 356 | // are not installed. |
| 357 | bool is_app_dot_com_extension_installed = false; |
| 358 | bool is_app_test_extension_installed = false; |
| 359 | for (const scoped_refptr<const extensions::Extension>& extension : |
| 360 | GetExtensionRegistry()->enabled_extensions()) { |
| 361 | if (extension->name() == "App Dot Com: The App") { |
| 362 | is_app_dot_com_extension_installed = true; |
| 363 | } else if (extension->name() == "App Test") { |
| 364 | is_app_test_extension_installed = true; |
| 365 | } else { |
| 366 | EXPECT_TRUE( |
| 367 | extensions::Manifest::IsComponentLocation(extension->location())); |
| 368 | } |
| 369 | } |
| 370 | EXPECT_FALSE(is_app_dot_com_extension_installed); |
| 371 | EXPECT_FALSE(is_app_test_extension_installed); |
| 372 | } |
| 373 | |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 374 | class DisableExtensionsExceptBrowserTest : public ExtensionBrowserTest { |
| 375 | public: |
| 376 | DisableExtensionsExceptBrowserTest() {} |
| 377 | |
| 378 | void SetUpCommandLine(base::CommandLine* command_line) override; |
| 379 | |
| 380 | ExtensionRegistry* GetExtensionRegistry() { |
| 381 | return ExtensionRegistry::Get(browser()->profile()); |
| 382 | } |
| 383 | }; |
| 384 | |
| 385 | void DisableExtensionsExceptBrowserTest::SetUpCommandLine( |
| 386 | base::CommandLine* command_line) { |
| 387 | ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 388 | base::FilePath fp1(test_data_dir_.AppendASCII("app_dot_com_app/")); |
| 389 | base::FilePath fp2(test_data_dir_.AppendASCII("app/")); |
| 390 | |
| 391 | command_line->AppendSwitchASCII( |
| 392 | switches::kDisableExtensionsExcept, |
| 393 | fp1.AsUTF8Unsafe() + "," + fp2.AsUTF8Unsafe()); |
antrim | 5876956 | 2016-11-14 14:48:41 | [diff] [blame] | 394 | |
| 395 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // Tests disabling all extensions except those listed |
| 399 | // (--disable-extensions-except). |
| 400 | IN_PROC_BROWSER_TEST_F(DisableExtensionsExceptBrowserTest, |
| 401 | DisableExtensionsExceptFlag) { |
| 402 | EXPECT_FALSE(extension_service()->extensions_enabled()); |
| 403 | |
| 404 | // Checks that the extensions loaded with the --disable-extensions-except flag |
| 405 | // are enabled. |
| 406 | bool is_app_dot_com_extension_enabled = false; |
| 407 | bool is_app_test_extension_enabled = false; |
| 408 | for (const scoped_refptr<const extensions::Extension>& extension : |
| 409 | GetExtensionRegistry()->enabled_extensions()) { |
| 410 | if (extension->name() == "App Dot Com: The App") { |
| 411 | is_app_dot_com_extension_enabled = true; |
| 412 | } else if (extension->name() == "App Test") { |
| 413 | is_app_test_extension_enabled = true; |
| 414 | } else { |
| 415 | EXPECT_TRUE( |
| 416 | extensions::Manifest::IsComponentLocation(extension->location())); |
| 417 | } |
| 418 | } |
| 419 | EXPECT_TRUE(is_app_dot_com_extension_enabled); |
| 420 | EXPECT_TRUE(is_app_test_extension_enabled); |
| 421 | } |