[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [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 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 7 | #include <memory> |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 8 | #include <string> |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 9 | #include <utility> |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 10 | |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 11 | #include "base/command_line.h" |
thestig | c9e38a2 | 2014-09-13 01:02:11 | [diff] [blame] | 12 | #include "base/files/file_util.h" |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 13 | #include "base/path_service.h" |
fdoray | cb32419d | 2016-06-23 15:52:55 | [diff] [blame] | 14 | #include "base/run_loop.h" |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 15 | #include "base/stl_util.h" |
[email protected] | 774cebd | 2013-09-26 04:55:01 | [diff] [blame] | 16 | #include "base/strings/string_number_conversions.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 17 | #include "base/strings/string_util.h" |
Karandeep Bhatia | ab489a4d | 2018-11-28 21:56:06 | [diff] [blame] | 18 | #include "base/test/power_monitor_test_base.h" |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 19 | #include "base/test/test_file_util.h" |
Devlin Cronin | c3f8807 | 2018-01-30 02:10:11 | [diff] [blame] | 20 | #include "base/test/values_test_util.h" |
[email protected] | 06492ed | 2013-03-24 22:13:14 | [diff] [blame] | 21 | #include "base/values.h" |
Kevin Marshall | 4cab5af | 2019-01-14 20:27:14 | [diff] [blame] | 22 | #include "build/build_config.h" |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 23 | #include "chrome/browser/extensions/chrome_content_verifier_delegate.h" |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 24 | #include "chrome/common/chrome_paths.h" |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 25 | #include "chrome/common/chrome_switches.h" |
| 26 | #include "chrome/test/base/testing_profile.h" |
| 27 | #include "components/crx_file/id_util.h" |
Matt Falkenhagen | ae65b29 | 2018-04-25 16:03:27 | [diff] [blame] | 28 | #include "content/public/browser/render_process_host.h" |
megjablon | caf312f | 2017-01-12 18:47:49 | [diff] [blame] | 29 | #include "content/public/common/previews_state.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 30 | #include "content/public/test/browser_task_environment.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 31 | #include "content/public/test/test_renderer_host.h" |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 32 | #include "content/public/test/test_utils.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 33 | #include "content/public/test/web_contents_tester.h" |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 34 | #include "extensions/browser/content_verifier.h" |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 35 | #include "extensions/browser/content_verifier/test_utils.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 36 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 37 | #include "extensions/browser/extension_protocols.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 38 | #include "extensions/browser/extension_registry.h" |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 39 | #include "extensions/browser/extension_system.h" |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 40 | #include "extensions/browser/info_map.h" |
Devlin Cronin | c9c4efe | 2020-01-07 21:04:05 | [diff] [blame] | 41 | #include "extensions/browser/unloaded_extension_reason.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 42 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 43 | #include "extensions/common/extension.h" |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 44 | #include "extensions/common/extension_builder.h" |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 45 | #include "extensions/common/extension_paths.h" |
asargent | a093ec3 | 2016-02-13 01:36:43 | [diff] [blame] | 46 | #include "extensions/common/file_util.h" |
Devlin Cronin | 1fa235b6 | 2018-04-12 14:04:07 | [diff] [blame] | 47 | #include "extensions/common/value_builder.h" |
Devlin Cronin | c3f8807 | 2018-01-30 02:10:11 | [diff] [blame] | 48 | #include "extensions/test/test_extension_dir.h" |
Julie Jeongeun Kim | 917c19790 | 2019-11-26 03:36:14 | [diff] [blame] | 49 | #include "mojo/public/cpp/bindings/pending_remote.h" |
rhalavati | 04b9338 | 2017-04-07 19:00:54 | [diff] [blame] | 50 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 51 | #include "services/network/test/test_url_loader_client.h" |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 52 | #include "testing/gtest/include/gtest/gtest.h" |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 53 | #include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h" |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 54 | |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 55 | using blink::mojom::ResourceType; |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 56 | using extensions::ExtensionRegistry; |
| 57 | using network::mojom::URLLoader; |
[email protected] | 7491ad0 | 2014-07-05 19:10:07 | [diff] [blame] | 58 | |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 59 | namespace extensions { |
jamescook | 8816ae5 | 2014-09-05 17:02:37 | [diff] [blame] | 60 | namespace { |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 61 | |
asargent | a093ec3 | 2016-02-13 01:36:43 | [diff] [blame] | 62 | base::FilePath GetTestPath(const std::string& name) { |
| 63 | base::FilePath path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 64 | EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &path)); |
asargent | a093ec3 | 2016-02-13 01:36:43 | [diff] [blame] | 65 | return path.AppendASCII("extensions").AppendASCII(name); |
| 66 | } |
| 67 | |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 68 | base::FilePath GetContentVerifierTestPath() { |
| 69 | base::FilePath path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 70 | EXPECT_TRUE(base::PathService::Get(extensions::DIR_TEST_DATA, &path)); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 71 | return path.AppendASCII("content_hash_fetcher") |
| 72 | .AppendASCII("different_sized_files"); |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 73 | } |
| 74 | |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 75 | scoped_refptr<Extension> CreateTestExtension(const std::string& name, |
| 76 | bool incognito_split_mode) { |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 77 | base::DictionaryValue manifest; |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 78 | manifest.SetString("name", name); |
| 79 | manifest.SetString("version", "1"); |
[email protected] | b109bdd | 2013-11-04 18:08:43 | [diff] [blame] | 80 | manifest.SetInteger("manifest_version", 2); |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 81 | manifest.SetString("incognito", incognito_split_mode ? "split" : "spanning"); |
| 82 | |
asargent | a093ec3 | 2016-02-13 01:36:43 | [diff] [blame] | 83 | base::FilePath path = GetTestPath("response_headers"); |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 84 | |
| 85 | std::string error; |
| 86 | scoped_refptr<Extension> extension( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 87 | Extension::Create(path, Manifest::INTERNAL, manifest, |
[email protected] | ed3b9b1 | 2012-05-31 18:37:51 | [diff] [blame] | 88 | Extension::NO_FLAGS, &error)); |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 89 | EXPECT_TRUE(extension.get()) << error; |
| 90 | return extension; |
| 91 | } |
| 92 | |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 93 | scoped_refptr<Extension> CreateWebStoreExtension() { |
Devlin Cronin | f43c331 | 2018-03-27 19:54:17 | [diff] [blame] | 94 | std::unique_ptr<base::DictionaryValue> manifest = |
| 95 | DictionaryBuilder() |
| 96 | .Set("name", "WebStore") |
| 97 | .Set("version", "1") |
| 98 | .Set("manifest_version", 2) |
| 99 | .Set("icons", |
| 100 | DictionaryBuilder().Set("16", "webstore_icon_16.png").Build()) |
| 101 | .Set("web_accessible_resources", |
| 102 | ListBuilder().Append("webstore_icon_16.png").Build()) |
| 103 | .Build(); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 104 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 105 | base::FilePath path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 106 | EXPECT_TRUE(base::PathService::Get(chrome::DIR_RESOURCES, &path)); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 107 | path = path.AppendASCII("web_store"); |
| 108 | |
| 109 | std::string error; |
Devlin Cronin | f43c331 | 2018-03-27 19:54:17 | [diff] [blame] | 110 | scoped_refptr<Extension> extension(Extension::Create( |
| 111 | path, Manifest::COMPONENT, *manifest, Extension::NO_FLAGS, &error)); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 112 | EXPECT_TRUE(extension.get()) << error; |
| 113 | return extension; |
| 114 | } |
| 115 | |
Devlin Cronin | 8e5892f | 2018-10-04 00:13:43 | [diff] [blame] | 116 | scoped_refptr<const Extension> CreateTestResponseHeaderExtension() { |
Devlin Cronin | 1fa235b6 | 2018-04-12 14:04:07 | [diff] [blame] | 117 | return ExtensionBuilder("An extension with web-accessible resources") |
Devlin Cronin | 98cd658 | 2018-05-08 19:18:12 | [diff] [blame] | 118 | .SetManifestKey("web_accessible_resources", |
| 119 | ListBuilder().Append("test.dat").Build()) |
Devlin Cronin | 1fa235b6 | 2018-04-12 14:04:07 | [diff] [blame] | 120 | .SetPath(GetTestPath("response_headers")) |
| 121 | .Build(); |
[email protected] | 6f7d706 | 2013-06-04 03:49:33 | [diff] [blame] | 122 | } |
| 123 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 124 | // Helper function to create a |ResourceRequest| for testing purposes. |
| 125 | network::ResourceRequest CreateResourceRequest(const std::string& method, |
| 126 | ResourceType resource_type, |
| 127 | const GURL& url) { |
| 128 | network::ResourceRequest request; |
| 129 | request.method = method; |
| 130 | request.url = url; |
Maks Orlovich | 5d02d9e0 | 2019-12-15 22:14:10 | [diff] [blame] | 131 | request.site_for_cookies = |
| 132 | net::SiteForCookies::FromUrl(url); // bypass third-party cookie blocking. |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 133 | request.request_initiator = |
| 134 | url::Origin::Create(url); // ensure initiator set. |
| 135 | request.referrer_policy = content::Referrer::GetDefaultReferrerPolicy(); |
Daniel Cheng | 57541be | 2019-05-07 07:51:07 | [diff] [blame] | 136 | request.resource_type = static_cast<int>(resource_type); |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 137 | request.is_main_frame = |
| 138 | resource_type == blink::mojom::ResourceType::kMainFrame; |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 139 | return request; |
| 140 | } |
| 141 | |
| 142 | // The result of either a URLRequest of a URLLoader response (but not both) |
| 143 | // depending on the on test type. |
| 144 | class GetResult { |
| 145 | public: |
Lucas Furukawa Gadani | 0690260 | 2019-09-27 20:44:27 | [diff] [blame] | 146 | GetResult(network::mojom::URLResponseHeadPtr response, int result) |
| 147 | : response_(std::move(response)), result_(result) {} |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 148 | GetResult(GetResult&& other) : result_(other.result_) {} |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 149 | ~GetResult() = default; |
| 150 | |
| 151 | std::string GetResponseHeaderByName(const std::string& name) const { |
| 152 | std::string value; |
Lucas Furukawa Gadani | 0690260 | 2019-09-27 20:44:27 | [diff] [blame] | 153 | if (response_ && response_->headers) |
| 154 | response_->headers->GetNormalizedHeader(name, &value); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 155 | return value; |
| 156 | } |
| 157 | |
| 158 | int result() const { return result_; } |
| 159 | |
| 160 | private: |
Lucas Furukawa Gadani | 0690260 | 2019-09-27 20:44:27 | [diff] [blame] | 161 | network::mojom::URLResponseHeadPtr response_; |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 162 | int result_; |
| 163 | |
| 164 | DISALLOW_COPY_AND_ASSIGN(GetResult); |
| 165 | }; |
| 166 | |
jamescook | 8816ae5 | 2014-09-05 17:02:37 | [diff] [blame] | 167 | } // namespace |
| 168 | |
| 169 | // This test lives in src/chrome instead of src/extensions because it tests |
| 170 | // functionality delegated back to Chrome via ChromeExtensionsBrowserClient. |
lfg | 048201a | 2014-09-16 19:09:36 | [diff] [blame] | 171 | // See chrome/browser/extensions/chrome_url_request_util.cc. |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 172 | class ExtensionProtocolsTestBase : public testing::Test { |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 173 | public: |
Alexey Baskakov | f0f9d8f | 2019-01-19 02:31:54 | [diff] [blame] | 174 | explicit ExtensionProtocolsTestBase(bool force_incognito) |
Gabriel Charette | 798fde7 | 2019-08-20 22:24:04 | [diff] [blame] | 175 | : task_environment_(content::BrowserTaskEnvironment::IO_MAINLOOP), |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 176 | rvh_test_enabler_(new content::RenderViewHostTestEnabler()), |
Alexey Baskakov | f0f9d8f | 2019-01-19 02:31:54 | [diff] [blame] | 177 | force_incognito_(force_incognito) {} |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 178 | |
dcheng | 7219181 | 2014-10-28 20:49:56 | [diff] [blame] | 179 | void SetUp() override { |
[email protected] | 06492ed | 2013-03-24 22:13:14 | [diff] [blame] | 180 | testing::Test::SetUp(); |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 181 | testing_profile_ = TestingProfile::Builder().Build(); |
Erik Chen | 5bab499 | 2018-05-05 15:19:53 | [diff] [blame] | 182 | contents_ = CreateTestWebContents(); |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 183 | |
| 184 | // Set up content verification. |
| 185 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 186 | command_line->AppendSwitchASCII( |
| 187 | switches::kExtensionContentVerification, |
| 188 | switches::kExtensionContentVerificationEnforce); |
| 189 | content_verifier_ = new ContentVerifier( |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 190 | browser_context(), |
| 191 | std::make_unique<ChromeContentVerifierDelegate>(browser_context())); |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 192 | info_map()->SetContentVerifier(content_verifier_.get()); |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 193 | } |
| 194 | |
dcheng | 7219181 | 2014-10-28 20:49:56 | [diff] [blame] | 195 | void TearDown() override { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 196 | loader_factory_.reset(); |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 197 | content_verifier_->Shutdown(); |
Matt Menke | db9fc40b | 2019-06-19 17:57:35 | [diff] [blame] | 198 | // Shut down the PowerMonitor if initialized. |
| 199 | base::PowerMonitor::ShutdownForTesting(); |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 200 | } |
| 201 | |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 202 | void SetProtocolHandler(bool is_incognito) { |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 203 | loader_factory_ = extensions::CreateExtensionNavigationURLLoaderFactory( |
| 204 | browser_context(), false); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 205 | } |
| 206 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 207 | GetResult RequestOrLoad(const GURL& url, ResourceType resource_type) { |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 208 | return LoadURL(url, resource_type); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void AddExtension(const scoped_refptr<const Extension>& extension, |
| 212 | bool incognito_enabled, |
| 213 | bool notifications_disabled) { |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 214 | info_map()->AddExtension(extension.get(), base::Time::Now(), |
| 215 | incognito_enabled, notifications_disabled); |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 216 | EXPECT_TRUE(extension_registry()->AddEnabled(extension)); |
| 217 | ExtensionPrefs::Get(browser_context()) |
| 218 | ->SetIsIncognitoEnabled(extension->id(), incognito_enabled); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void RemoveExtension(const scoped_refptr<const Extension>& extension, |
| 222 | const UnloadedExtensionReason reason) { |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 223 | info_map()->RemoveExtension(extension->id(), reason); |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 224 | EXPECT_TRUE(extension_registry()->RemoveEnabled(extension->id())); |
| 225 | if (reason == UnloadedExtensionReason::DISABLE) |
| 226 | EXPECT_TRUE(extension_registry()->AddDisabled(extension)); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Helper method to create a URL request/loader, call RequestOrLoad on it, and |
| 230 | // return the result. If |extension| hasn't already been added to |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 231 | // info_map(), this will add it. |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 232 | GetResult DoRequestOrLoad(const scoped_refptr<Extension> extension, |
| 233 | const std::string& relative_path) { |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 234 | if (!info_map()->extensions().Contains(extension->id())) { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 235 | AddExtension(extension.get(), |
| 236 | /*incognito_enabled=*/false, |
| 237 | /*notifications_disabled=*/false); |
| 238 | } |
| 239 | return RequestOrLoad(extension->GetResourceURL(relative_path), |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 240 | blink::mojom::ResourceType::kMainFrame); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | ExtensionRegistry* extension_registry() { |
| 244 | return ExtensionRegistry::Get(browser_context()); |
| 245 | } |
| 246 | |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 247 | InfoMap* info_map() { |
| 248 | return ExtensionSystem::Get(browser_context())->info_map(); |
| 249 | } |
| 250 | |
Alexey Baskakov | f0f9d8f | 2019-01-19 02:31:54 | [diff] [blame] | 251 | content::BrowserContext* browser_context() { |
| 252 | return force_incognito_ ? testing_profile_->GetOffTheRecordProfile() |
| 253 | : testing_profile_.get(); |
| 254 | } |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 255 | |
Karandeep Bhatia | ab489a4d | 2018-11-28 21:56:06 | [diff] [blame] | 256 | void SimulateSystemSuspendForRequests() { |
| 257 | power_monitor_source_ = new base::PowerMonitorTestSource(); |
Matt Menke | db9fc40b | 2019-06-19 17:57:35 | [diff] [blame] | 258 | base::PowerMonitor::Initialize( |
Karandeep Bhatia | ab489a4d | 2018-11-28 21:56:06 | [diff] [blame] | 259 | std::unique_ptr<base::PowerMonitorSource>(power_monitor_source_)); |
| 260 | } |
| 261 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 262 | protected: |
| 263 | scoped_refptr<ContentVerifier> content_verifier_; |
| 264 | |
| 265 | private: |
| 266 | GetResult LoadURL(const GURL& url, ResourceType resource_type) { |
| 267 | constexpr int32_t kRoutingId = 81; |
| 268 | constexpr int32_t kRequestId = 28; |
| 269 | |
Julie Jeongeun Kim | 917c19790 | 2019-11-26 03:36:14 | [diff] [blame] | 270 | mojo::PendingRemote<network::mojom::URLLoader> loader; |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 271 | network::TestURLLoaderClient client; |
| 272 | loader_factory_->CreateLoaderAndStart( |
Julie Jeongeun Kim | 917c19790 | 2019-11-26 03:36:14 | [diff] [blame] | 273 | loader.InitWithNewPipeAndPassReceiver(), kRoutingId, kRequestId, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 274 | network::mojom::kURLLoadOptionNone, |
Julie Jeongeun Kim | 6dd4c7b | 2019-11-18 05:56:30 | [diff] [blame] | 275 | CreateResourceRequest("GET", resource_type, url), client.CreateRemote(), |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 277 | |
Karandeep Bhatia | ab489a4d | 2018-11-28 21:56:06 | [diff] [blame] | 278 | if (power_monitor_source_) { |
| 279 | power_monitor_source_->GenerateSuspendEvent(); |
| 280 | power_monitor_source_->GenerateResumeEvent(); |
| 281 | } |
| 282 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 283 | client.RunUntilComplete(); |
Lucas Furukawa Gadani | 0690260 | 2019-09-27 20:44:27 | [diff] [blame] | 284 | return GetResult(client.response_head().Clone(), |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 285 | client.completion_status().error_code); |
| 286 | } |
| 287 | |
Erik Chen | 5bab499 | 2018-05-05 15:19:53 | [diff] [blame] | 288 | std::unique_ptr<content::WebContents> CreateTestWebContents() { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 289 | auto site_instance = content::SiteInstance::Create(browser_context()); |
| 290 | return content::WebContentsTester::CreateTestWebContents( |
| 291 | browser_context(), std::move(site_instance)); |
asargent | a093ec3 | 2016-02-13 01:36:43 | [diff] [blame] | 292 | } |
| 293 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 294 | content::WebContents* web_contents() { return contents_.get(); } |
| 295 | |
| 296 | content::RenderFrameHost* main_rfh() { |
| 297 | return web_contents()->GetMainFrame(); |
| 298 | } |
| 299 | |
Gabriel Charette | 798fde7 | 2019-08-20 22:24:04 | [diff] [blame] | 300 | content::BrowserTaskEnvironment task_environment_; |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 301 | std::unique_ptr<content::RenderViewHostTestEnabler> rvh_test_enabler_; |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 302 | std::unique_ptr<network::mojom::URLLoaderFactory> loader_factory_; |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 303 | std::unique_ptr<TestingProfile> testing_profile_; |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 304 | std::unique_ptr<content::WebContents> contents_; |
Alexey Baskakov | f0f9d8f | 2019-01-19 02:31:54 | [diff] [blame] | 305 | const bool force_incognito_; |
Karandeep Bhatia | ab489a4d | 2018-11-28 21:56:06 | [diff] [blame] | 306 | |
Matt Menke | db9fc40b | 2019-06-19 17:57:35 | [diff] [blame] | 307 | // |power_monitor_source_| is owned by the global PowerMonitor. |
Karandeep Bhatia | ab489a4d | 2018-11-28 21:56:06 | [diff] [blame] | 308 | base::PowerMonitorTestSource* power_monitor_source_ = nullptr; |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 309 | }; |
| 310 | |
Alexey Baskakov | f0f9d8f | 2019-01-19 02:31:54 | [diff] [blame] | 311 | class ExtensionProtocolsTest : public ExtensionProtocolsTestBase { |
| 312 | public: |
| 313 | ExtensionProtocolsTest() |
| 314 | : ExtensionProtocolsTestBase(false /*force_incognito*/) {} |
| 315 | }; |
| 316 | |
| 317 | class ExtensionProtocolsIncognitoTest : public ExtensionProtocolsTestBase { |
| 318 | public: |
| 319 | ExtensionProtocolsIncognitoTest() |
| 320 | : ExtensionProtocolsTestBase(true /*force_incognito*/) {} |
| 321 | }; |
| 322 | |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 323 | // Tests that making a chrome-extension request in an incognito context is |
| 324 | // only allowed under the right circumstances (if the extension is allowed |
| 325 | // in incognito, and it's either a non-main-frame request or a split-mode |
| 326 | // extension). |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 327 | TEST_F(ExtensionProtocolsIncognitoTest, IncognitoRequest) { |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 328 | // Register an incognito extension protocol handler. |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 329 | SetProtocolHandler(true); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 330 | |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 331 | struct TestCase { |
| 332 | // Inputs. |
| 333 | std::string name; |
| 334 | bool incognito_split_mode; |
| 335 | bool incognito_enabled; |
| 336 | |
| 337 | // Expected results. |
| 338 | bool should_allow_main_frame_load; |
| 339 | bool should_allow_sub_frame_load; |
| 340 | } cases[] = { |
| 341 | {"spanning disabled", false, false, false, false}, |
| 342 | {"split disabled", true, false, false, false}, |
nasko | 5cf9d45 | 2016-06-01 05:34:56 | [diff] [blame] | 343 | {"spanning enabled", false, true, false, false}, |
| 344 | {"split enabled", true, true, true, false}, |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 345 | }; |
| 346 | |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 347 | for (size_t i = 0; i < base::size(cases); ++i) { |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 348 | scoped_refptr<Extension> extension = |
| 349 | CreateTestExtension(cases[i].name, cases[i].incognito_split_mode); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 350 | AddExtension(extension, cases[i].incognito_enabled, false); |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 351 | |
| 352 | // First test a main frame request. |
| 353 | { |
| 354 | // It doesn't matter that the resource doesn't exist. If the resource |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 355 | // is blocked, we should see BLOCKED_BY_CLIENT. Otherwise, the request |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 356 | // should just fail because the file doesn't exist. |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 357 | auto get_result = RequestOrLoad(extension->GetResourceURL("404.html"), |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 358 | blink::mojom::ResourceType::kMainFrame); |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 359 | |
| 360 | if (cases[i].should_allow_main_frame_load) { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 361 | EXPECT_EQ(net::ERR_FILE_NOT_FOUND, get_result.result()) |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 362 | << cases[i].name; |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 363 | } else { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 364 | EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, get_result.result()) |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 365 | << cases[i].name; |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
John Abd-El-Malek | 2305cdc | 2018-02-14 20:26:28 | [diff] [blame] | 369 | // Subframe navigation requests are blocked in ExtensionNavigationThrottle |
| 370 | // which isn't added in this unit test. This is tested in an integration |
| 371 | // test in ExtensionResourceRequestPolicyTest.IframeNavigateToInaccessible. |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 372 | RemoveExtension(extension, UnloadedExtensionReason::UNINSTALL); |
[email protected] | 5e212ed | 2012-03-21 23:29:15 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 376 | void CheckForContentLengthHeader(const GetResult& get_result) { |
| 377 | std::string content_length = get_result.GetResponseHeaderByName( |
| 378 | net::HttpRequestHeaders::kContentLength); |
| 379 | |
[email protected] | 774cebd | 2013-09-26 04:55:01 | [diff] [blame] | 380 | EXPECT_FALSE(content_length.empty()); |
| 381 | int length_value = 0; |
| 382 | EXPECT_TRUE(base::StringToInt(content_length, &length_value)); |
| 383 | EXPECT_GT(length_value, 0); |
| 384 | } |
| 385 | |
dstockwell | 944d1888 | 2019-04-09 04:25:58 | [diff] [blame] | 386 | #if defined(OS_CHROMEOS) |
| 387 | // Tests getting a resource for a component extension works correctly where |
| 388 | // there is no mime type. Such a resource currently only exists for Chrome OS |
| 389 | // build. |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 390 | TEST_F(ExtensionProtocolsTest, ComponentResourceRequestNoMimeType) { |
dstockwell | 944d1888 | 2019-04-09 04:25:58 | [diff] [blame] | 391 | SetProtocolHandler(false); |
| 392 | std::unique_ptr<base::DictionaryValue> manifest = |
| 393 | DictionaryBuilder() |
| 394 | .Set("name", "pdf") |
| 395 | .Set("version", "1") |
| 396 | .Set("manifest_version", 2) |
| 397 | .Set("web_accessible_resources", |
| 398 | // Registered by chrome_component_extension_resource_manager.cc |
| 399 | ListBuilder().Append("ink/glcore_base.js.mem").Build()) |
| 400 | .Build(); |
| 401 | |
| 402 | base::FilePath path; |
| 403 | EXPECT_TRUE(base::PathService::Get(chrome::DIR_RESOURCES, &path)); |
| 404 | path = path.AppendASCII("pdf"); |
| 405 | |
| 406 | std::string error; |
| 407 | scoped_refptr<Extension> extension(Extension::Create( |
| 408 | path, Manifest::COMPONENT, *manifest, Extension::NO_FLAGS, &error)); |
| 409 | EXPECT_TRUE(extension.get()) << error; |
| 410 | AddExtension(extension, false, false); |
| 411 | |
| 412 | auto get_result = |
| 413 | RequestOrLoad(extension->GetResourceURL("ink/glcore_base.js.mem"), |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 414 | blink::mojom::ResourceType::kXhr); |
dstockwell | 944d1888 | 2019-04-09 04:25:58 | [diff] [blame] | 415 | EXPECT_EQ(net::OK, get_result.result()); |
| 416 | CheckForContentLengthHeader(get_result); |
| 417 | EXPECT_EQ("", get_result.GetResponseHeaderByName( |
| 418 | net::HttpRequestHeaders::kContentType)); |
| 419 | } |
| 420 | #endif |
| 421 | |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 422 | // Tests getting a resource for a component extension works correctly, both when |
| 423 | // the extension is enabled and when it is disabled. |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 424 | TEST_F(ExtensionProtocolsTest, ComponentResourceRequest) { |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 425 | // Register a non-incognito extension protocol handler. |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 426 | SetProtocolHandler(false); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 427 | |
| 428 | scoped_refptr<Extension> extension = CreateWebStoreExtension(); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 429 | AddExtension(extension, false, false); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 430 | |
| 431 | // First test it with the extension enabled. |
| 432 | { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 433 | auto get_result = |
| 434 | RequestOrLoad(extension->GetResourceURL("webstore_icon_16.png"), |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 435 | blink::mojom::ResourceType::kMedia); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 436 | EXPECT_EQ(net::OK, get_result.result()); |
| 437 | CheckForContentLengthHeader(get_result); |
| 438 | EXPECT_EQ("image/png", get_result.GetResponseHeaderByName( |
| 439 | net::HttpRequestHeaders::kContentType)); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | // And then test it with the extension disabled. |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 443 | RemoveExtension(extension, UnloadedExtensionReason::DISABLE); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 444 | { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 445 | auto get_result = |
| 446 | RequestOrLoad(extension->GetResourceURL("webstore_icon_16.png"), |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 447 | blink::mojom::ResourceType::kMedia); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 448 | EXPECT_EQ(net::OK, get_result.result()); |
| 449 | CheckForContentLengthHeader(get_result); |
| 450 | EXPECT_EQ("image/png", get_result.GetResponseHeaderByName( |
| 451 | net::HttpRequestHeaders::kContentType)); |
[email protected] | 93ac047a | 2012-12-13 02:53:49 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
[email protected] | 6f7d706 | 2013-06-04 03:49:33 | [diff] [blame] | 455 | // Tests that a URL request for resource from an extension returns a few |
| 456 | // expected response headers. |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 457 | TEST_F(ExtensionProtocolsTest, ResourceRequestResponseHeaders) { |
[email protected] | 6f7d706 | 2013-06-04 03:49:33 | [diff] [blame] | 458 | // Register a non-incognito extension protocol handler. |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 459 | SetProtocolHandler(false); |
[email protected] | 6f7d706 | 2013-06-04 03:49:33 | [diff] [blame] | 460 | |
Devlin Cronin | 8e5892f | 2018-10-04 00:13:43 | [diff] [blame] | 461 | scoped_refptr<const Extension> extension = |
| 462 | CreateTestResponseHeaderExtension(); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 463 | AddExtension(extension, false, false); |
[email protected] | 6f7d706 | 2013-06-04 03:49:33 | [diff] [blame] | 464 | |
| 465 | { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 466 | auto get_result = RequestOrLoad(extension->GetResourceURL("test.dat"), |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 467 | blink::mojom::ResourceType::kMedia); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 468 | EXPECT_EQ(net::OK, get_result.result()); |
[email protected] | 6f7d706 | 2013-06-04 03:49:33 | [diff] [blame] | 469 | |
| 470 | // Check that cache-related headers are set. |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 471 | std::string etag = get_result.GetResponseHeaderByName("ETag"); |
brettw | 66d1b81b | 2015-07-06 19:29:40 | [diff] [blame] | 472 | EXPECT_TRUE(base::StartsWith(etag, "\"", base::CompareCase::SENSITIVE)); |
| 473 | EXPECT_TRUE(base::EndsWith(etag, "\"", base::CompareCase::SENSITIVE)); |
[email protected] | 6f7d706 | 2013-06-04 03:49:33 | [diff] [blame] | 474 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 475 | std::string revalidation_header = |
| 476 | get_result.GetResponseHeaderByName("cache-control"); |
[email protected] | 6f7d706 | 2013-06-04 03:49:33 | [diff] [blame] | 477 | EXPECT_EQ("no-cache", revalidation_header); |
| 478 | |
| 479 | // We set test.dat as web-accessible, so it should have a CORS header. |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 480 | std::string access_control = |
| 481 | get_result.GetResponseHeaderByName("Access-Control-Allow-Origin"); |
[email protected] | 6f7d706 | 2013-06-04 03:49:33 | [diff] [blame] | 482 | EXPECT_EQ("*", access_control); |
| 483 | } |
| 484 | } |
| 485 | |
[email protected] | b109bdd | 2013-11-04 18:08:43 | [diff] [blame] | 486 | // Tests that a URL request for main frame or subframe from an extension |
| 487 | // succeeds, but subresources fail. See http://crbug.com/312269. |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 488 | TEST_F(ExtensionProtocolsTest, AllowFrameRequests) { |
[email protected] | b109bdd | 2013-11-04 18:08:43 | [diff] [blame] | 489 | // Register a non-incognito extension protocol handler. |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 490 | SetProtocolHandler(false); |
[email protected] | b109bdd | 2013-11-04 18:08:43 | [diff] [blame] | 491 | |
| 492 | scoped_refptr<Extension> extension = CreateTestExtension("foo", false); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 493 | AddExtension(extension, false, false); |
[email protected] | b109bdd | 2013-11-04 18:08:43 | [diff] [blame] | 494 | |
nasko | 5cf9d45 | 2016-06-01 05:34:56 | [diff] [blame] | 495 | // All MAIN_FRAME requests should succeed. SUB_FRAME requests that are not |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 496 | // explicitly listed in web_accessible_resources or same-origin to the parent |
nasko | 5cf9d45 | 2016-06-01 05:34:56 | [diff] [blame] | 497 | // should not succeed. |
[email protected] | b109bdd | 2013-11-04 18:08:43 | [diff] [blame] | 498 | { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 499 | auto get_result = RequestOrLoad(extension->GetResourceURL("test.dat"), |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 500 | blink::mojom::ResourceType::kMainFrame); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 501 | EXPECT_EQ(net::OK, get_result.result()); |
[email protected] | b109bdd | 2013-11-04 18:08:43 | [diff] [blame] | 502 | } |
John Abd-El-Malek | 2305cdc | 2018-02-14 20:26:28 | [diff] [blame] | 503 | |
| 504 | // Subframe navigation requests are blocked in ExtensionNavigationThrottle |
| 505 | // which isn't added in this unit test. This is tested in an integration test |
| 506 | // in ExtensionResourceRequestPolicyTest.IframeNavigateToInaccessible. |
[email protected] | b109bdd | 2013-11-04 18:08:43 | [diff] [blame] | 507 | |
| 508 | // And subresource types, such as media, should fail. |
| 509 | { |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 510 | auto get_result = RequestOrLoad(extension->GetResourceURL("test.dat"), |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 511 | blink::mojom::ResourceType::kMedia); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 512 | EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, get_result.result()); |
[email protected] | b109bdd | 2013-11-04 18:08:43 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 516 | TEST_F(ExtensionProtocolsTest, MetadataFolder) { |
asargent | a093ec3 | 2016-02-13 01:36:43 | [diff] [blame] | 517 | SetProtocolHandler(false); |
| 518 | |
| 519 | base::FilePath extension_dir = GetTestPath("metadata_folder"); |
| 520 | std::string error; |
| 521 | scoped_refptr<Extension> extension = |
| 522 | file_util::LoadExtension(extension_dir, Manifest::INTERNAL, |
| 523 | Extension::NO_FLAGS, &error); |
| 524 | ASSERT_NE(extension.get(), nullptr) << "error: " << error; |
| 525 | |
| 526 | // Loading "/test.html" should succeed. |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 527 | EXPECT_EQ(net::OK, DoRequestOrLoad(extension, "test.html").result()); |
asargent | a093ec3 | 2016-02-13 01:36:43 | [diff] [blame] | 528 | |
| 529 | // Loading "/_metadata/verified_contents.json" should fail. |
| 530 | base::FilePath relative_path = |
| 531 | base::FilePath(kMetadataFolder).Append(kVerifiedContentsFilename); |
| 532 | EXPECT_TRUE(base::PathExists(extension_dir.Append(relative_path))); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 533 | EXPECT_NE(net::OK, |
| 534 | DoRequestOrLoad(extension, relative_path.AsUTF8Unsafe()).result()); |
asargent | a093ec3 | 2016-02-13 01:36:43 | [diff] [blame] | 535 | |
| 536 | // Loading "/_metadata/a.txt" should also fail. |
| 537 | relative_path = base::FilePath(kMetadataFolder).AppendASCII("a.txt"); |
| 538 | EXPECT_TRUE(base::PathExists(extension_dir.Append(relative_path))); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 539 | EXPECT_NE(net::OK, |
| 540 | DoRequestOrLoad(extension, relative_path.AsUTF8Unsafe()).result()); |
asargent | a093ec3 | 2016-02-13 01:36:43 | [diff] [blame] | 541 | } |
| 542 | |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 543 | // Tests that unreadable files and deleted files correctly go through |
| 544 | // ContentVerifyJob. |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 545 | TEST_F(ExtensionProtocolsTest, VerificationSeenForFileAccessErrors) { |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 546 | SetProtocolHandler(false); |
| 547 | |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 548 | // Unzip extension containing verification hashes to a temporary directory. |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 549 | base::ScopedTempDir temp_dir; |
| 550 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 551 | base::FilePath unzipped_path = temp_dir.GetPath(); |
| 552 | scoped_refptr<Extension> extension = |
| 553 | content_verifier_test_utils::UnzipToDirAndLoadExtension( |
| 554 | GetContentVerifierTestPath().AppendASCII("source.zip"), |
| 555 | unzipped_path); |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 556 | ASSERT_TRUE(extension.get()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 557 | ExtensionId extension_id = extension->id(); |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 558 | |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 559 | const std::string kJs("1024.js"); |
| 560 | base::FilePath kRelativePath(FILE_PATH_LITERAL("1024.js")); |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 561 | |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 562 | // Valid and readable 1024.js. |
| 563 | { |
Istiaque Ahmed | 584fe14 | 2018-03-13 09:19:04 | [diff] [blame] | 564 | TestContentVerifySingleJobObserver observer(extension_id, kRelativePath); |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 565 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 566 | content_verifier_->OnExtensionLoaded(browser_context(), extension.get()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 567 | // Wait for PostTask to ContentVerifierIOData::AddData() to finish. |
| 568 | content::RunAllPendingInMessageLoop(); |
| 569 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 570 | EXPECT_EQ(net::OK, DoRequestOrLoad(extension, kJs).result()); |
Istiaque Ahmed | 1dec1d4 | 2018-02-02 00:01:36 | [diff] [blame] | 571 | EXPECT_EQ(ContentVerifyJob::NONE, observer.WaitForJobFinished()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | // chmod -r 1024.js. |
| 575 | { |
Oleg Davydov | b755945 | 2020-02-07 15:01:25 | [diff] [blame] | 576 | TestContentVerifySingleJobObserver observer(extension_id, kRelativePath); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 577 | base::FilePath file_path = unzipped_path.AppendASCII(kJs); |
| 578 | ASSERT_TRUE(base::MakeFileUnreadable(file_path)); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 579 | EXPECT_EQ(net::ERR_ACCESS_DENIED, DoRequestOrLoad(extension, kJs).result()); |
Istiaque Ahmed | 1dec1d4 | 2018-02-02 00:01:36 | [diff] [blame] | 580 | EXPECT_EQ(ContentVerifyJob::HASH_MISMATCH, observer.WaitForJobFinished()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 581 | // NOTE: In production, hash mismatch would have disabled |extension|, but |
| 582 | // since UnzipToDirAndLoadExtension() doesn't add the extension to |
| 583 | // ExtensionRegistry, ChromeContentVerifierDelegate won't disable it. |
| 584 | // TODO(lazyboy): We may want to update this to more closely reflect the |
| 585 | // real flow. |
| 586 | } |
| 587 | |
| 588 | // Delete 1024.js. |
| 589 | { |
Istiaque Ahmed | 584fe14 | 2018-03-13 09:19:04 | [diff] [blame] | 590 | TestContentVerifySingleJobObserver observer(extension_id, kRelativePath); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 591 | base::FilePath file_path = unzipped_path.AppendASCII(kJs); |
| 592 | ASSERT_TRUE(base::DieFileDie(file_path, false)); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 593 | EXPECT_EQ(net::ERR_FILE_NOT_FOUND, |
| 594 | DoRequestOrLoad(extension, kJs).result()); |
Istiaque Ahmed | 1dec1d4 | 2018-02-02 00:01:36 | [diff] [blame] | 595 | EXPECT_EQ(ContentVerifyJob::HASH_MISMATCH, observer.WaitForJobFinished()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 596 | } |
lazyboy | d6dbb26 | 2017-03-30 00:57:30 | [diff] [blame] | 597 | } |
| 598 | |
lazyboy | e83ab9c6 | 2017-03-30 03:18:26 | [diff] [blame] | 599 | // Tests that zero byte files correctly go through ContentVerifyJob. |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 600 | TEST_F(ExtensionProtocolsTest, VerificationSeenForZeroByteFile) { |
lazyboy | e83ab9c6 | 2017-03-30 03:18:26 | [diff] [blame] | 601 | SetProtocolHandler(false); |
| 602 | |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 603 | const std::string kEmptyJs("empty.js"); |
lazyboy | e83ab9c6 | 2017-03-30 03:18:26 | [diff] [blame] | 604 | base::ScopedTempDir temp_dir; |
| 605 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 606 | base::FilePath unzipped_path = temp_dir.GetPath(); |
lazyboy | e83ab9c6 | 2017-03-30 03:18:26 | [diff] [blame] | 607 | |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 608 | scoped_refptr<Extension> extension = |
| 609 | content_verifier_test_utils::UnzipToDirAndLoadExtension( |
| 610 | GetContentVerifierTestPath().AppendASCII("source.zip"), |
| 611 | unzipped_path); |
| 612 | ASSERT_TRUE(extension.get()); |
| 613 | |
| 614 | base::FilePath kRelativePath(FILE_PATH_LITERAL("empty.js")); |
| 615 | ExtensionId extension_id = extension->id(); |
| 616 | |
| 617 | // Sanity check empty.js. |
| 618 | base::FilePath file_path = unzipped_path.AppendASCII(kEmptyJs); |
lazyboy | e83ab9c6 | 2017-03-30 03:18:26 | [diff] [blame] | 619 | int64_t foo_file_size = -1; |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 620 | ASSERT_TRUE(base::GetFileSize(file_path, &foo_file_size)); |
lazyboy | e83ab9c6 | 2017-03-30 03:18:26 | [diff] [blame] | 621 | ASSERT_EQ(0, foo_file_size); |
| 622 | |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 623 | // Request empty.js. |
| 624 | { |
Istiaque Ahmed | 584fe14 | 2018-03-13 09:19:04 | [diff] [blame] | 625 | TestContentVerifySingleJobObserver observer(extension_id, kRelativePath); |
lazyboy | e83ab9c6 | 2017-03-30 03:18:26 | [diff] [blame] | 626 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 627 | content_verifier_->OnExtensionLoaded(browser_context(), extension.get()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 628 | // Wait for PostTask to ContentVerifierIOData::AddData() to finish. |
| 629 | content::RunAllPendingInMessageLoop(); |
lazyboy | e83ab9c6 | 2017-03-30 03:18:26 | [diff] [blame] | 630 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 631 | EXPECT_EQ(net::OK, DoRequestOrLoad(extension, kEmptyJs).result()); |
Istiaque Ahmed | 1dec1d4 | 2018-02-02 00:01:36 | [diff] [blame] | 632 | EXPECT_EQ(ContentVerifyJob::NONE, observer.WaitForJobFinished()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | // chmod -r empty.js. |
| 636 | // Unreadable empty file doesn't generate hash mismatch. Note that this is the |
| 637 | // current behavior of ContentVerifyJob. |
| 638 | // TODO(lazyboy): The behavior is probably incorrect. |
| 639 | { |
Oleg Davydov | b755945 | 2020-02-07 15:01:25 | [diff] [blame] | 640 | TestContentVerifySingleJobObserver observer(extension_id, kRelativePath); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 641 | base::FilePath file_path = unzipped_path.AppendASCII(kEmptyJs); |
| 642 | ASSERT_TRUE(base::MakeFileUnreadable(file_path)); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 643 | EXPECT_EQ(net::ERR_ACCESS_DENIED, |
| 644 | DoRequestOrLoad(extension, kEmptyJs).result()); |
Istiaque Ahmed | 1dec1d4 | 2018-02-02 00:01:36 | [diff] [blame] | 645 | EXPECT_EQ(ContentVerifyJob::NONE, observer.WaitForJobFinished()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | // rm empty.js. |
| 649 | // Deleted empty file doesn't generate hash mismatch. Note that this is the |
| 650 | // current behavior of ContentVerifyJob. |
| 651 | // TODO(lazyboy): The behavior is probably incorrect. |
| 652 | { |
Istiaque Ahmed | 584fe14 | 2018-03-13 09:19:04 | [diff] [blame] | 653 | TestContentVerifySingleJobObserver observer(extension_id, kRelativePath); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 654 | base::FilePath file_path = unzipped_path.AppendASCII(kEmptyJs); |
| 655 | ASSERT_TRUE(base::DieFileDie(file_path, false)); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 656 | EXPECT_EQ(net::ERR_FILE_NOT_FOUND, |
| 657 | DoRequestOrLoad(extension, kEmptyJs).result()); |
Istiaque Ahmed | 1dec1d4 | 2018-02-02 00:01:36 | [diff] [blame] | 658 | EXPECT_EQ(ContentVerifyJob::NONE, observer.WaitForJobFinished()); |
Istiaque Ahmed | 72816eaa | 2018-01-30 22:37:06 | [diff] [blame] | 659 | } |
lazyboy | e83ab9c6 | 2017-03-30 03:18:26 | [diff] [blame] | 660 | } |
| 661 | |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 662 | TEST_F(ExtensionProtocolsTest, VerifyScriptListedAsIcon) { |
proberge | 4f9644c | 2018-03-27 23:01:54 | [diff] [blame] | 663 | SetProtocolHandler(false); |
| 664 | |
| 665 | const std::string kBackgroundJs("background.js"); |
| 666 | base::ScopedTempDir temp_dir; |
| 667 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 668 | base::FilePath unzipped_path = temp_dir.GetPath(); |
| 669 | |
| 670 | base::FilePath path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 671 | EXPECT_TRUE(base::PathService::Get(extensions::DIR_TEST_DATA, &path)); |
proberge | 4f9644c | 2018-03-27 23:01:54 | [diff] [blame] | 672 | |
| 673 | scoped_refptr<Extension> extension = |
| 674 | content_verifier_test_utils::UnzipToDirAndLoadExtension( |
| 675 | path.AppendASCII("content_hash_fetcher") |
| 676 | .AppendASCII("manifest_mislabeled_script") |
| 677 | .AppendASCII("source.zip"), |
| 678 | unzipped_path); |
| 679 | ASSERT_TRUE(extension.get()); |
| 680 | |
| 681 | base::FilePath kRelativePath(FILE_PATH_LITERAL("background.js")); |
| 682 | ExtensionId extension_id = extension->id(); |
| 683 | |
| 684 | // Request background.js. |
| 685 | { |
| 686 | TestContentVerifySingleJobObserver observer(extension_id, kRelativePath); |
| 687 | |
| 688 | content_verifier_->OnExtensionLoaded(browser_context(), extension.get()); |
| 689 | // Wait for PostTask to ContentVerifierIOData::AddData() to finish. |
| 690 | base::RunLoop().RunUntilIdle(); |
| 691 | |
| 692 | EXPECT_EQ(net::OK, DoRequestOrLoad(extension, kBackgroundJs).result()); |
| 693 | EXPECT_EQ(ContentVerifyJob::NONE, observer.WaitForJobFinished()); |
| 694 | } |
| 695 | |
| 696 | // Modify background.js and request it. |
| 697 | { |
| 698 | base::FilePath file_path = unzipped_path.AppendASCII("background.js"); |
| 699 | const std::string content = "new content"; |
Lei Zhang | a5bd23f1 | 2020-05-07 05:50:15 | [diff] [blame^] | 700 | EXPECT_TRUE(base::WriteFile(file_path, content)); |
proberge | 4f9644c | 2018-03-27 23:01:54 | [diff] [blame] | 701 | TestContentVerifySingleJobObserver observer(extension_id, kRelativePath); |
| 702 | |
| 703 | content_verifier_->OnExtensionLoaded(browser_context(), extension.get()); |
| 704 | // Wait for PostTask to ContentVerifierIOData::AddData() to finish. |
| 705 | base::RunLoop().RunUntilIdle(); |
| 706 | |
| 707 | EXPECT_EQ(net::OK, DoRequestOrLoad(extension, kBackgroundJs).result()); |
| 708 | EXPECT_EQ(ContentVerifyJob::HASH_MISMATCH, observer.WaitForJobFinished()); |
| 709 | } |
| 710 | } |
| 711 | |
Devlin Cronin | c3f8807 | 2018-01-30 02:10:11 | [diff] [blame] | 712 | // Tests that mime types are properly set for returned extension resources. |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 713 | TEST_F(ExtensionProtocolsTest, MimeTypesForKnownFiles) { |
Devlin Cronin | c3f8807 | 2018-01-30 02:10:11 | [diff] [blame] | 714 | // Register a non-incognito extension protocol handler. |
| 715 | SetProtocolHandler(false); |
| 716 | |
| 717 | TestExtensionDir test_dir; |
| 718 | constexpr char kManifest[] = R"( |
| 719 | { |
| 720 | "name": "Test Ext", |
| 721 | "description": "A test extension", |
| 722 | "manifest_version": 2, |
| 723 | "version": "0.1", |
| 724 | "web_accessible_resources": ["*"] |
| 725 | })"; |
| 726 | test_dir.WriteManifest(kManifest); |
| 727 | std::unique_ptr<base::DictionaryValue> manifest = |
Lei Zhang | 9b9d579 | 2019-02-20 07:24:42 | [diff] [blame] | 728 | base::DictionaryValue::From(base::test::ParseJsonDeprecated(kManifest)); |
Devlin Cronin | c3f8807 | 2018-01-30 02:10:11 | [diff] [blame] | 729 | ASSERT_TRUE(manifest); |
| 730 | |
| 731 | test_dir.WriteFile(FILE_PATH_LITERAL("json_file.json"), "{}"); |
| 732 | test_dir.WriteFile(FILE_PATH_LITERAL("js_file.js"), "function() {}"); |
| 733 | |
| 734 | base::FilePath unpacked_path = test_dir.UnpackedPath(); |
| 735 | ASSERT_TRUE(base::PathExists(unpacked_path.AppendASCII("json_file.json"))); |
| 736 | std::string error; |
| 737 | scoped_refptr<const Extension> extension = |
| 738 | ExtensionBuilder() |
| 739 | .SetManifest(std::move(manifest)) |
| 740 | .SetPath(unpacked_path) |
| 741 | .SetLocation(Manifest::INTERNAL) |
| 742 | .Build(); |
| 743 | ASSERT_TRUE(extension); |
| 744 | |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 745 | AddExtension(extension.get(), false, false); |
Devlin Cronin | c3f8807 | 2018-01-30 02:10:11 | [diff] [blame] | 746 | |
| 747 | struct { |
| 748 | const char* file_name; |
| 749 | const char* expected_mime_type; |
| 750 | } test_cases[] = { |
dstockwell | 0067793 | 2019-04-09 02:12:08 | [diff] [blame] | 751 | {"json_file.json", "application/json"}, |
| 752 | {"js_file.js", "text/javascript"}, |
| 753 | {"mem_file.mem", ""}, |
Devlin Cronin | c3f8807 | 2018-01-30 02:10:11 | [diff] [blame] | 754 | }; |
| 755 | |
| 756 | for (const auto& test_case : test_cases) { |
| 757 | SCOPED_TRACE(test_case.file_name); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 758 | auto result = RequestOrLoad(extension->GetResourceURL(test_case.file_name), |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 759 | blink::mojom::ResourceType::kSubResource); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 760 | EXPECT_EQ( |
| 761 | test_case.expected_mime_type, |
| 762 | result.GetResponseHeaderByName(net::HttpRequestHeaders::kContentType)); |
Devlin Cronin | c3f8807 | 2018-01-30 02:10:11 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
Kevin Marshall | 4cab5af | 2019-01-14 20:27:14 | [diff] [blame] | 766 | #if defined(OS_WIN) |
| 767 | #define MAYBE_ExtensionRequestsNotAborted DISABLED_ExtensionRequestsNotAborted |
| 768 | #else |
| 769 | #define MAYBE_ExtensionRequestsNotAborted ExtensionRequestsNotAborted |
| 770 | #endif |
Karandeep Bhatia | ab489a4d | 2018-11-28 21:56:06 | [diff] [blame] | 771 | // Tests that requests for extension resources (including the generated |
| 772 | // background page) are not aborted on system suspend. |
Kevin Marshall | 4cab5af | 2019-01-14 20:27:14 | [diff] [blame] | 773 | // |
| 774 | // Flaky on Windows. |
| 775 | // TODO(https://crbug.com/921687): Investigate and fix. |
Clark DuVall | c7e3b469 | 2019-06-13 22:07:11 | [diff] [blame] | 776 | TEST_F(ExtensionProtocolsTest, MAYBE_ExtensionRequestsNotAborted) { |
Karandeep Bhatia | ab489a4d | 2018-11-28 21:56:06 | [diff] [blame] | 777 | // Register a non-incognito extension protocol handler. |
| 778 | SetProtocolHandler(false); |
| 779 | |
| 780 | base::FilePath extension_dir = |
| 781 | GetTestPath("common").AppendASCII("background_script"); |
| 782 | std::string error; |
| 783 | scoped_refptr<Extension> extension = file_util::LoadExtension( |
| 784 | extension_dir, Manifest::INTERNAL, Extension::NO_FLAGS, &error); |
| 785 | ASSERT_TRUE(extension.get()) << error; |
| 786 | |
| 787 | SimulateSystemSuspendForRequests(); |
| 788 | |
| 789 | // Request the generated background page. Ensure the request completes |
| 790 | // successfully. |
| 791 | EXPECT_EQ(net::OK, |
| 792 | DoRequestOrLoad(extension.get(), kGeneratedBackgroundPageFilename) |
| 793 | .result()); |
| 794 | |
| 795 | // Request the background.js file. Ensure the request completes successfully. |
| 796 | EXPECT_EQ(net::OK, DoRequestOrLoad(extension.get(), "background.js").result()); |
| 797 | } |
| 798 | |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 799 | } // namespace extensions |