[email protected] | 01239ea | 2012-02-19 00:11:10 | [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 | |
| 5 | #include "chrome/renderer/chrome_content_renderer_client.h" |
| 6 | |
avi | 2729e44 | 2015-12-26 05:27:45 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
megjablon | 050660f | 2016-11-02 20:11:31 | [diff] [blame] | 9 | #include <map> |
| 10 | #include <string> |
jdoerrie | 97df444 | 2017-05-17 16:29:34 | [diff] [blame] | 11 | #include <utility> |
[email protected] | 2309e91 | 2013-10-01 01:33:30 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
jdoerrie | 97df444 | 2017-05-17 16:29:34 | [diff] [blame] | 14 | #include "base/memory/ptr_util.h" |
kdsilva | af8d257 | 2016-08-09 17:22:20 | [diff] [blame] | 15 | #include "base/metrics/histogram_samples.h" |
[email protected] | abfd149 | 2013-06-07 21:23:26 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
kdsilva | af8d257 | 2016-08-09 17:22:20 | [diff] [blame] | 17 | #include "base/test/histogram_tester.h" |
jdoerrie | 97df444 | 2017-05-17 16:29:34 | [diff] [blame] | 18 | #include "base/values.h" |
avi | 2729e44 | 2015-12-26 05:27:45 | [diff] [blame] | 19 | #include "build/build_config.h" |
[email protected] | 2309e91 | 2013-10-01 01:33:30 | [diff] [blame] | 20 | #include "chrome/renderer/searchbox/search_bouncer.h" |
megjablon | 050660f | 2016-11-02 20:11:31 | [diff] [blame] | 21 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 22 | #include "content/public/common/webplugininfo.h" |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 23 | #include "extensions/features/features.h" |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 24 | #include "testing/gtest/include/gtest/gtest.h" |
megjablon | 050660f | 2016-11-02 20:11:31 | [diff] [blame] | 25 | #include "third_party/WebKit/public/platform/WebString.h" |
| 26 | #include "third_party/WebKit/public/platform/WebURLResponse.h" |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 27 | #include "url/gurl.h" |
| 28 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 29 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 30 | #include "extensions/common/extension.h" |
[email protected] | 22b7b2c | 2013-11-05 22:52:42 | [diff] [blame] | 31 | #include "extensions/common/extension_builder.h" |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 32 | #include "extensions/common/manifest_constants.h" |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | #if !defined(DISABLE_NACL) |
[email protected] | e48cf4f | 2013-05-30 12:40:12 | [diff] [blame] | 36 | #include "third_party/WebKit/public/platform/WebString.h" |
| 37 | #include "third_party/WebKit/public/platform/WebVector.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 38 | #include "third_party/WebKit/public/web/WebPluginParams.h" |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 39 | #endif |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 40 | |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 41 | #if !defined(DISABLE_NACL) |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 42 | using blink::WebPluginParams; |
| 43 | using blink::WebString; |
| 44 | using blink::WebVector; |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 45 | #endif |
| 46 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 47 | using content::WebPluginInfo; |
| 48 | using content::WebPluginMimeType; |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 49 | |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 50 | namespace { |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 51 | |
| 52 | #if !defined(DISABLE_NACL) |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 53 | const bool kNaClRestricted = false; |
| 54 | const bool kNaClUnrestricted = true; |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 55 | const bool kExtensionNotFromWebStore = false; |
| 56 | const bool kExtensionFromWebStore = true; |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 57 | #endif |
| 58 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 59 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 60 | const bool kNotHostedApp = false; |
| 61 | const bool kHostedApp = true; |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 62 | #endif |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 63 | |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 64 | #if !defined(DISABLE_NACL) |
[email protected] | e3cb452 | 2013-03-07 22:18:45 | [diff] [blame] | 65 | const char kExtensionUrl[] = "chrome-extension://extension_id/background.html"; |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 66 | |
qaz | 81dcbd6 | 2016-05-20 21:36:08 | [diff] [blame] | 67 | const char kChatManifestFS[] = "filesystem:https://talkgadget.google.com/foo"; |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 68 | #endif |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 69 | |
qaz | 81dcbd6 | 2016-05-20 21:36:08 | [diff] [blame] | 70 | const char kChatAppURL[] = "https://talkgadget.google.com/hangouts/foo"; |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 71 | |
| 72 | #if !defined(DISABLE_NACL) |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 73 | bool AllowsDevInterfaces(const WebPluginParams& params) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 74 | for (size_t i = 0; i < params.attribute_names.size(); ++i) { |
| 75 | if (params.attribute_names[i] == "@dev") |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 76 | return true; |
| 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | void AddFakeDevAttribute(WebPluginParams* params) { |
| 82 | WebVector<WebString> names(static_cast<size_t>(1)); |
| 83 | WebVector<WebString> values(static_cast<size_t>(1)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 84 | names[0] = WebString::FromUTF8("@dev"); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 85 | values[0] = WebString(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 86 | params->attribute_names.Swap(names); |
| 87 | params->attribute_values.Swap(values); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 88 | } |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 89 | #endif |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 90 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 91 | void AddContentTypeHandler(content::WebPluginInfo* info, |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 92 | const char* mime_type, |
| 93 | const char* manifest_url) { |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 94 | content::WebPluginMimeType mime_type_info; |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 95 | mime_type_info.mime_type = mime_type; |
[email protected] | c91b9d4 | 2013-12-25 00:53:42 | [diff] [blame] | 96 | mime_type_info.additional_param_names.push_back(base::UTF8ToUTF16("nacl")); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 97 | mime_type_info.additional_param_values.push_back( |
[email protected] | c91b9d4 | 2013-12-25 00:53:42 | [diff] [blame] | 98 | base::UTF8ToUTF16(manifest_url)); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 99 | info->mime_types.push_back(mime_type_info); |
| 100 | } |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 101 | |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 102 | } // namespace |
| 103 | |
| 104 | typedef testing::Test ChromeContentRendererClientTest; |
| 105 | |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 106 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 107 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 108 | scoped_refptr<const extensions::Extension> CreateTestExtension( |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 109 | extensions::Manifest::Location location, bool is_from_webstore, |
| 110 | bool is_hosted_app, const std::string& app_url) { |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 111 | int flags = is_from_webstore ? |
| 112 | extensions::Extension::FROM_WEBSTORE: |
| 113 | extensions::Extension::NO_FLAGS; |
| 114 | |
[email protected] | a371b4b | 2013-06-18 20:29:27 | [diff] [blame] | 115 | base::DictionaryValue manifest; |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 116 | manifest.SetString("name", "NaCl Extension"); |
| 117 | manifest.SetString("version", "1"); |
| 118 | manifest.SetInteger("manifest_version", 2); |
| 119 | if (is_hosted_app) { |
jdoerrie | 97df444 | 2017-05-17 16:29:34 | [diff] [blame] | 120 | auto url_list = base::MakeUnique<base::ListValue>(); |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 121 | url_list->AppendString(app_url); |
jdoerrie | 97df444 | 2017-05-17 16:29:34 | [diff] [blame] | 122 | manifest.Set(extensions::manifest_keys::kWebURLs, std::move(url_list)); |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 123 | manifest.SetString(extensions::manifest_keys::kLaunchWebURL, app_url); |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 124 | } |
| 125 | std::string error; |
| 126 | return extensions::Extension::Create(base::FilePath(), location, manifest, |
| 127 | flags, &error); |
| 128 | } |
| 129 | |
| 130 | scoped_refptr<const extensions::Extension> CreateExtension( |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 131 | bool is_from_webstore) { |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 132 | return CreateTestExtension( |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 133 | extensions::Manifest::INTERNAL, is_from_webstore, kNotHostedApp, |
| 134 | std::string()); |
| 135 | } |
| 136 | |
| 137 | scoped_refptr<const extensions::Extension> CreateExtensionWithLocation( |
| 138 | extensions::Manifest::Location location, bool is_from_webstore) { |
| 139 | return CreateTestExtension( |
| 140 | location, is_from_webstore, kNotHostedApp, std::string()); |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | scoped_refptr<const extensions::Extension> CreateHostedApp( |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 144 | bool is_from_webstore, const std::string& app_url) { |
| 145 | return CreateTestExtension(extensions::Manifest::INTERNAL, |
| 146 | is_from_webstore, |
| 147 | kHostedApp, |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 148 | app_url); |
| 149 | } |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 150 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 151 | |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 152 | TEST_F(ChromeContentRendererClientTest, NaClRestriction) { |
| 153 | // Unknown content types have no NaCl module. |
| 154 | { |
| 155 | WebPluginInfo info; |
| 156 | EXPECT_EQ(GURL(), |
| 157 | ChromeContentRendererClient::GetNaClContentHandlerURL( |
| 158 | "application/x-foo", info)); |
| 159 | } |
| 160 | // Known content types have a NaCl module. |
| 161 | { |
| 162 | WebPluginInfo info; |
| 163 | AddContentTypeHandler(&info, "application/x-foo", "www.foo.com"); |
| 164 | EXPECT_EQ(GURL("www.foo.com"), |
| 165 | ChromeContentRendererClient::GetNaClContentHandlerURL( |
| 166 | "application/x-foo", info)); |
| 167 | } |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 168 | #if !defined(DISABLE_NACL) |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 169 | // --enable-nacl allows all NaCl apps, with 'dev' interfaces. |
| 170 | { |
| 171 | WebPluginParams params; |
| 172 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 173 | GURL(), |
| 174 | GURL(), |
| 175 | kNaClUnrestricted, |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 176 | CreateExtension(kExtensionNotFromWebStore).get(), |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 177 | ¶ms)); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 178 | EXPECT_TRUE(AllowsDevInterfaces(params)); |
| 179 | } |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 180 | // Unpacked extensions are allowed without --enable-nacl, with |
| 181 | // 'dev' interfaces. |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 182 | { |
| 183 | WebPluginParams params; |
| 184 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 185 | GURL(), |
| 186 | GURL(kExtensionUrl), |
| 187 | kNaClRestricted, |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 188 | CreateExtensionWithLocation(extensions::Manifest::UNPACKED, |
| 189 | kExtensionNotFromWebStore).get(), |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 190 | ¶ms)); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 191 | EXPECT_TRUE(AllowsDevInterfaces(params)); |
| 192 | } |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 193 | // Component extensions are allowed without --enable-nacl, with |
| 194 | // 'dev' interfaces. |
| 195 | { |
| 196 | WebPluginParams params; |
| 197 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 198 | GURL(), |
| 199 | GURL(kExtensionUrl), |
| 200 | kNaClRestricted, |
| 201 | CreateExtensionWithLocation(extensions::Manifest::COMPONENT, |
| 202 | kExtensionNotFromWebStore).get(), |
| 203 | ¶ms)); |
| 204 | EXPECT_TRUE(AllowsDevInterfaces(params)); |
| 205 | } |
| 206 | { |
| 207 | WebPluginParams params; |
| 208 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 209 | GURL(), |
| 210 | GURL(kExtensionUrl), |
| 211 | kNaClRestricted, |
| 212 | CreateExtensionWithLocation(extensions::Manifest::EXTERNAL_COMPONENT, |
| 213 | kExtensionNotFromWebStore).get(), |
| 214 | ¶ms)); |
| 215 | EXPECT_TRUE(AllowsDevInterfaces(params)); |
| 216 | } |
| 217 | // Extensions that are force installed by policy are allowed without |
| 218 | // --enable-nacl, without 'dev' interfaces. |
| 219 | { |
| 220 | WebPluginParams params; |
| 221 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 222 | GURL(), |
| 223 | GURL(kExtensionUrl), |
| 224 | kNaClRestricted, |
| 225 | CreateExtensionWithLocation(extensions::Manifest::EXTERNAL_POLICY, |
| 226 | kExtensionNotFromWebStore).get(), |
| 227 | ¶ms)); |
| 228 | EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 229 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 230 | GURL(), |
| 231 | GURL(kExtensionUrl), |
| 232 | kNaClRestricted, |
| 233 | CreateExtensionWithLocation( |
| 234 | extensions::Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 235 | kExtensionNotFromWebStore).get(), |
| 236 | ¶ms)); |
| 237 | EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 238 | } |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 239 | // CWS extensions are allowed without --enable-nacl, without 'dev' |
[email protected] | e3cb452 | 2013-03-07 22:18:45 | [diff] [blame] | 240 | // interfaces if called from an extension url. |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 241 | { |
| 242 | WebPluginParams params; |
| 243 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 244 | GURL(), |
| 245 | GURL(kExtensionUrl), |
| 246 | kNaClRestricted, |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 247 | CreateExtension(kExtensionFromWebStore).get(), |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 248 | ¶ms)); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 249 | EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 250 | } |
| 251 | // CWS extensions can't get 'dev' interfaces with --enable-nacl. |
| 252 | { |
| 253 | WebPluginParams params; |
| 254 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 255 | GURL(), |
| 256 | GURL(kExtensionUrl), |
| 257 | kNaClUnrestricted, |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 258 | CreateExtension(kExtensionFromWebStore).get(), |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 259 | ¶ms)); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 260 | EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 261 | } |
| 262 | // CWS extensions can't get 'dev' interfaces by injecting a fake |
| 263 | // '@dev' attribute. |
| 264 | { |
| 265 | WebPluginParams params; |
| 266 | AddFakeDevAttribute(¶ms); |
| 267 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 268 | GURL(), |
| 269 | GURL(kExtensionUrl), |
| 270 | kNaClRestricted, |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 271 | CreateExtension(kExtensionFromWebStore).get(), |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 272 | ¶ms)); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 273 | EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 274 | } |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 275 | |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 276 | // Whitelisted URLs are allowed without --enable-nacl, without 'dev' |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 277 | // interfaces. There is a whitelist for the app URL and the manifest URL. |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 278 | { |
| 279 | WebPluginParams params; |
[email protected] | e533ae1 | 2013-09-17 16:04:45 | [diff] [blame] | 280 | // Whitelisted Chat app is allowed. |
| 281 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
qaz | 81dcbd6 | 2016-05-20 21:36:08 | [diff] [blame] | 282 | GURL(kChatManifestFS), |
| 283 | GURL(kChatAppURL), |
[email protected] | 1864d42 | 2013-12-16 13:06:00 | [diff] [blame] | 284 | kNaClRestricted, |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 285 | nullptr, |
[email protected] | 1864d42 | 2013-12-16 13:06:00 | [diff] [blame] | 286 | ¶ms)); |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 287 | |
| 288 | // Whitelisted manifest URL, bad app URLs, NOT allowed. |
[email protected] | a571620 | 2013-01-30 10:00:26 | [diff] [blame] | 289 | EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 290 | GURL(kChatManifestFS), |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 291 | GURL("http://plus.google.com/foo"), // http scheme |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 292 | kNaClRestricted, nullptr, ¶ms)); |
[email protected] | a571620 | 2013-01-30 10:00:26 | [diff] [blame] | 293 | EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 294 | GURL(kChatManifestFS), |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 295 | GURL("http://plus.sandbox.google.com/foo"), // http scheme |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 296 | kNaClRestricted, nullptr, ¶ms)); |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 297 | EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 298 | GURL(kChatManifestFS), |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 299 | GURL("https://plus.google.evil.com/foo"), // bad host |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 300 | kNaClRestricted, nullptr, ¶ms)); |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 301 | // Whitelisted app URL, bad manifest URL, NOT allowed. |
| 302 | EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
| 303 | GURL("http://ssl.gstatic.com/s2/oz/nacl/foo"), // http scheme |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 304 | GURL(kChatAppURL), kNaClRestricted, nullptr, ¶ms)); |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 305 | EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
| 306 | GURL("https://ssl.gstatic.evil.com/s2/oz/nacl/foo"), // bad host |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 307 | GURL(kChatAppURL), kNaClRestricted, nullptr, ¶ms)); |
[email protected] | 7ca58f2 | 2013-06-24 08:21:27 | [diff] [blame] | 308 | EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
| 309 | GURL("https://ssl.gstatic.com/wrong/s2/oz/nacl/foo"), // bad path |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 310 | GURL(kChatAppURL), kNaClRestricted, nullptr, ¶ms)); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 311 | } |
| 312 | // Whitelisted URLs can't get 'dev' interfaces with --enable-nacl. |
| 313 | { |
| 314 | WebPluginParams params; |
| 315 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 316 | GURL(kChatManifestFS), GURL(kChatAppURL), kNaClUnrestricted, nullptr, |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 317 | ¶ms)); |
| 318 | EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 319 | } |
| 320 | // Whitelisted URLs can't get 'dev' interfaces by injecting a fake |
| 321 | // '@dev' attribute. |
| 322 | { |
| 323 | WebPluginParams params; |
| 324 | AddFakeDevAttribute(¶ms); |
| 325 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
bradnelson | 52deea2a | 2017-02-27 18:06:29 | [diff] [blame] | 326 | GURL(kChatManifestFS), GURL(kChatAppURL), kNaClRestricted, nullptr, |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 327 | ¶ms)); |
| 328 | EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 329 | } |
| 330 | // Non-whitelisted URLs are blocked without --enable-nacl. |
| 331 | { |
| 332 | WebPluginParams params; |
| 333 | EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 334 | GURL(), |
| 335 | GURL("https://plus.google.com.evil.com/foo1"), |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 336 | kNaClRestricted, |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 337 | nullptr, |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 338 | ¶ms)); |
| 339 | } |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 340 | // Non chrome-extension:// URLs belonging to hosted apps are allowed for |
| 341 | // webstore installed hosted apps. |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 342 | { |
| 343 | WebPluginParams params; |
| 344 | EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 345 | GURL(), |
| 346 | GURL("http://example.com/test.html"), |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 347 | kNaClRestricted, |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 348 | CreateHostedApp(kExtensionFromWebStore, |
| 349 | "http://example.com/").get(), |
| 350 | ¶ms)); |
| 351 | EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
| 352 | GURL(), |
| 353 | GURL("http://example.com/test.html"), |
| 354 | kNaClRestricted, |
| 355 | CreateHostedApp(kExtensionNotFromWebStore, |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 356 | "http://example.com/").get(), |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 357 | ¶ms)); |
| 358 | EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 359 | GURL(), |
| 360 | GURL("http://example.evil.com/test.html"), |
[email protected] | 3aacd948 | 2013-03-19 09:49:36 | [diff] [blame] | 361 | kNaClRestricted, |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 362 | CreateHostedApp(kExtensionNotFromWebStore, |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 363 | "http://example.com/").get(), |
[email protected] | e3cb452 | 2013-03-07 22:18:45 | [diff] [blame] | 364 | ¶ms)); |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 365 | } |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 366 | #endif // !defined(DISABLE_NACL) |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 367 | } |
[email protected] | 01239ea | 2012-02-19 00:11:10 | [diff] [blame] | 368 | |
[email protected] | e533ae1 | 2013-09-17 16:04:45 | [diff] [blame] | 369 | TEST_F(ChromeContentRendererClientTest, AllowPepperMediaStreamAPI) { |
| 370 | ChromeContentRendererClient test; |
qaz | 81dcbd6 | 2016-05-20 21:36:08 | [diff] [blame] | 371 | #if defined(OS_ANDROID) |
| 372 | EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL))); |
[email protected] | e533ae1 | 2013-09-17 16:04:45 | [diff] [blame] | 373 | #else |
qaz | 81dcbd6 | 2016-05-20 21:36:08 | [diff] [blame] | 374 | EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL))); |
[email protected] | e533ae1 | 2013-09-17 16:04:45 | [diff] [blame] | 375 | #endif |
[email protected] | e533ae1 | 2013-09-17 16:04:45 | [diff] [blame] | 376 | } |
| 377 | |
[email protected] | 2309e91 | 2013-10-01 01:33:30 | [diff] [blame] | 378 | TEST_F(ChromeContentRendererClientTest, ShouldSuppressErrorPage) { |
| 379 | ChromeContentRendererClient client; |
bmcquade | fab65e3 | 2015-07-14 14:39:32 | [diff] [blame] | 380 | SearchBouncer::GetInstance()->OnSetSearchURLs( |
[email protected] | 2309e91 | 2013-10-01 01:33:30 | [diff] [blame] | 381 | std::vector<GURL>(), GURL("http://example.com/n")); |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 382 | EXPECT_FALSE(client.ShouldSuppressErrorPage(nullptr, |
[email protected] | 24a57cc | 2014-01-10 22:45:30 | [diff] [blame] | 383 | GURL("http://example.com"))); |
elijahtaylor | dea8f652 | 2015-06-23 18:52:50 | [diff] [blame] | 384 | EXPECT_TRUE(client.ShouldSuppressErrorPage(nullptr, |
[email protected] | 24a57cc | 2014-01-10 22:45:30 | [diff] [blame] | 385 | GURL("http://example.com/n"))); |
bmcquade | fab65e3 | 2015-07-14 14:39:32 | [diff] [blame] | 386 | SearchBouncer::GetInstance()->OnSetSearchURLs( |
| 387 | std::vector<GURL>(), GURL::EmptyGURL()); |
[email protected] | 2309e91 | 2013-10-01 01:33:30 | [diff] [blame] | 388 | } |
kdsilva | e013559 | 2016-08-09 17:08:11 | [diff] [blame] | 389 | |
megjablon | 050660f | 2016-11-02 20:11:31 | [diff] [blame] | 390 | TEST_F(ChromeContentRendererClientTest, AddImageContextMenuProperties) { |
| 391 | ChromeContentRendererClient client; |
| 392 | blink::WebURLResponse web_url_response; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 393 | web_url_response.AddHTTPHeaderField( |
| 394 | blink::WebString::FromUTF8( |
megjablon | 050660f | 2016-11-02 20:11:31 | [diff] [blame] | 395 | data_reduction_proxy::chrome_proxy_content_transform_header()), |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 396 | blink::WebString::FromUTF8( |
megjablon | 050660f | 2016-11-02 20:11:31 | [diff] [blame] | 397 | data_reduction_proxy::empty_image_directive())); |
| 398 | std::map<std::string, std::string> properties; |
| 399 | client.AddImageContextMenuProperties(web_url_response, &properties); |
| 400 | EXPECT_EQ( |
| 401 | data_reduction_proxy::empty_image_directive(), |
| 402 | properties |
| 403 | [data_reduction_proxy::chrome_proxy_content_transform_header()]); |
| 404 | } |
| 405 | |
kdsilva | 621478c | 2016-08-09 17:31:11 | [diff] [blame] | 406 | // These are tests that are common for both Android and desktop browsers. |
| 407 | TEST_F(ChromeContentRendererClientTest, RewriteEmbedCommon) { |
kdsilva | e013559 | 2016-08-09 17:08:11 | [diff] [blame] | 408 | struct TestData { |
| 409 | std::string original; |
| 410 | std::string expected; |
| 411 | } test_data[] = { |
| 412 | // { original, expected } |
| 413 | {"youtube.com", ""}, |
| 414 | {"www.youtube.com", ""}, |
| 415 | {"http://www.youtube.com", ""}, |
| 416 | {"https://www.youtube.com", ""}, |
| 417 | {"http://www.foo.youtube.com", ""}, |
| 418 | {"https://www.foo.youtube.com", ""}, |
| 419 | // Non-YouTube domains shouldn't be modified |
| 420 | {"http://www.plus.google.com", ""}, |
| 421 | // URL isn't using Flash |
| 422 | {"http://www.youtube.com/embed/deadbeef", ""}, |
| 423 | // URL isn't using Flash, no www |
| 424 | {"http://youtube.com/embed/deadbeef", ""}, |
kdsilva | e013559 | 2016-08-09 17:08:11 | [diff] [blame] | 425 | // URL isn't using Flash, invalid parameter construct |
| 426 | {"http://www.youtube.com/embed/deadbeef&start=4", ""}, |
| 427 | // URL is using Flash, no www |
| 428 | {"http://youtube.com/v/deadbeef", "http://youtube.com/embed/deadbeef"}, |
kdsilva | e013559 | 2016-08-09 17:08:11 | [diff] [blame] | 429 | // URL is using Flash, is valid, https |
| 430 | {"https://www.youtube.com/v/deadbeef", |
| 431 | "https://www.youtube.com/embed/deadbeef"}, |
| 432 | // URL is using Flash, is valid, http |
| 433 | {"http://www.youtube.com/v/deadbeef", |
| 434 | "http://www.youtube.com/embed/deadbeef"}, |
| 435 | // URL is using Flash, is valid, not a complete URL, no www or protocol |
| 436 | {"youtube.com/v/deadbeef", ""}, |
| 437 | // URL is using Flash, is valid, not a complete URL,or protocol |
| 438 | {"www.youtube.com/v/deadbeef", ""}, |
| 439 | // URL is using Flash, valid |
| 440 | {"https://www.foo.youtube.com/v/deadbeef", |
| 441 | "https://www.foo.youtube.com/embed/deadbeef"}, |
| 442 | // URL is using Flash, is valid, has one parameter |
| 443 | {"http://www.youtube.com/v/deadbeef?start=4", |
| 444 | "http://www.youtube.com/embed/deadbeef?start=4"}, |
| 445 | // URL is using Flash, is valid, has multiple parameters |
| 446 | {"http://www.youtube.com/v/deadbeef?start=4&fs=1", |
| 447 | "http://www.youtube.com/embed/deadbeef?start=4&fs=1"}, |
| 448 | // URL is using Flash, invalid parameter construct, has one parameter |
| 449 | {"http://www.youtube.com/v/deadbeef&start=4", |
| 450 | "http://www.youtube.com/embed/deadbeef?start=4"}, |
| 451 | // URL is using Flash, invalid parameter construct, has multiple |
| 452 | // parameters |
| 453 | {"http://www.youtube.com/v/deadbeef&start=4&fs=1?foo=bar", |
| 454 | "http://www.youtube.com/embed/deadbeef?start=4&fs=1&foo=bar"}, |
| 455 | // URL is using Flash, invalid parameter construct, has multiple |
| 456 | // parameters |
| 457 | {"http://www.youtube.com/v/deadbeef&start=4&fs=1", |
| 458 | "http://www.youtube.com/embed/deadbeef?start=4&fs=1"}, |
| 459 | // Invalid parameter construct |
| 460 | {"http://www.youtube.com/abcd/v/deadbeef", ""}, |
| 461 | // Invalid parameter construct |
| 462 | {"http://www.youtube.com/v/abcd/", "http://www.youtube.com/embed/abcd/"}, |
| 463 | // Invalid parameter construct |
| 464 | {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"}, |
| 465 | // youtube-nocookie.com |
| 466 | {"http://www.youtube-nocookie.com/v/123/", |
| 467 | "http://www.youtube-nocookie.com/embed/123/"}, |
| 468 | // youtube-nocookie.com, isn't using flash |
| 469 | {"http://www.youtube-nocookie.com/embed/123/", ""}, |
kdsilva | e013559 | 2016-08-09 17:08:11 | [diff] [blame] | 470 | // youtube-nocookie.com, has one parameter |
| 471 | {"http://www.youtube-nocookie.com/v/123?start=foo", |
| 472 | "http://www.youtube-nocookie.com/embed/123?start=foo"}, |
| 473 | // youtube-nocookie.com, has multiple parameters |
| 474 | {"http://www.youtube-nocookie.com/v/123?start=foo&bar=baz", |
| 475 | "http://www.youtube-nocookie.com/embed/123?start=foo&bar=baz"}, |
| 476 | // youtube-nocookie.com, invalid parameter construct, has one parameter |
| 477 | {"http://www.youtube-nocookie.com/v/123&start=foo", |
| 478 | "http://www.youtube-nocookie.com/embed/123?start=foo"}, |
| 479 | // youtube-nocookie.com, invalid parameter construct, has multiple |
| 480 | // parameters |
| 481 | {"http://www.youtube-nocookie.com/v/123&start=foo&bar=baz", |
| 482 | "http://www.youtube-nocookie.com/embed/123?start=foo&bar=baz"}, |
| 483 | // youtube-nocookie.com, https |
| 484 | {"https://www.youtube-nocookie.com/v/123/", |
| 485 | "https://www.youtube-nocookie.com/embed/123/"}, |
| 486 | }; |
| 487 | |
| 488 | ChromeContentRendererClient client; |
| 489 | |
| 490 | for (const auto& data : test_data) |
| 491 | EXPECT_EQ(GURL(data.expected), |
| 492 | client.OverrideFlashEmbedWithHTML(GURL(data.original))); |
| 493 | } |
kdsilva | af8d257 | 2016-08-09 17:22:20 | [diff] [blame] | 494 | |
kdsilva | 621478c | 2016-08-09 17:31:11 | [diff] [blame] | 495 | #if defined(OS_ANDROID) |
| 496 | TEST_F(ChromeContentRendererClientTest, RewriteEmbedAndroid) { |
| 497 | struct TestData { |
| 498 | std::string original; |
| 499 | std::string expected; |
| 500 | } test_data[] = { |
| 501 | // URL isn't using Flash, has JS API enabled |
| 502 | {"http://www.youtube.com/embed/deadbeef?enablejsapi=1", ""}, |
| 503 | // URL is using Flash, has JS API enabled |
| 504 | {"http://www.youtube.com/v/deadbeef?enablejsapi=1", |
| 505 | "http://www.youtube.com/embed/deadbeef?enablejsapi=1"}, |
| 506 | // youtube-nocookie.com, has JS API enabled |
| 507 | {"http://www.youtube-nocookie.com/v/123?enablejsapi=1", |
| 508 | "http://www.youtube-nocookie.com/embed/123?enablejsapi=1"}, |
| 509 | // URL is using Flash, has JS API enabled, invalid parameter construct |
| 510 | {"http://www.youtube.com/v/deadbeef&enablejsapi=1", |
| 511 | "http://www.youtube.com/embed/deadbeef?enablejsapi=1"}, |
| 512 | // URL is using Flash, has JS API enabled, invalid parameter construct, |
| 513 | // has multiple parameters |
| 514 | {"http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1", |
| 515 | "http://www.youtube.com/embed/deadbeef?start=4&enablejsapi=1"}, |
| 516 | }; |
| 517 | |
| 518 | ChromeContentRendererClient client; |
| 519 | |
| 520 | for (const auto& data : test_data) { |
| 521 | EXPECT_EQ(GURL(data.expected), |
| 522 | client.OverrideFlashEmbedWithHTML(GURL(data.original))); |
| 523 | } |
| 524 | } |
| 525 | #else |
| 526 | TEST_F(ChromeContentRendererClientTest, RewriteEmbedDesktop) { |
| 527 | struct TestData { |
| 528 | std::string original; |
| 529 | std::string expected; |
| 530 | } test_data[] = { |
| 531 | // URL isn't using Flash, has JS API enabled |
| 532 | {"http://www.youtube.com/embed/deadbeef?enablejsapi=1", ""}, |
| 533 | // URL is using Flash, has JS API enabled |
| 534 | {"http://www.youtube.com/v/deadbeef?enablejsapi=1", ""}, |
| 535 | // youtube-nocookie.com, has JS API enabled |
| 536 | {"http://www.youtube-nocookie.com/v/123?enablejsapi=1", ""}, |
| 537 | // URL is using Flash, has JS API enabled, invalid parameter construct |
| 538 | {"http://www.youtube.com/v/deadbeef&enablejsapi=1", ""}, |
| 539 | // URL is using Flash, has JS API enabled, invalid parameter construct, |
| 540 | // has multiple parameters |
| 541 | {"http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1", ""}, |
| 542 | }; |
| 543 | |
| 544 | ChromeContentRendererClient client; |
| 545 | |
| 546 | for (const auto& data : test_data) { |
| 547 | EXPECT_EQ(GURL(data.expected), |
| 548 | client.OverrideFlashEmbedWithHTML(GURL(data.original))); |
| 549 | } |
| 550 | } |
| 551 | #endif |
kdsilva | af8d257 | 2016-08-09 17:22:20 | [diff] [blame] | 552 | class ChromeContentRendererClientMetricsTest : public testing::Test { |
| 553 | public: |
| 554 | ChromeContentRendererClientMetricsTest() = default; |
| 555 | |
| 556 | std::unique_ptr<base::HistogramSamples> GetHistogramSamples() { |
| 557 | return histogram_tester_.GetHistogramSamplesSinceCreation( |
| 558 | internal::kFlashYouTubeRewriteUMA); |
| 559 | } |
| 560 | |
| 561 | void OverrideFlashEmbed(const GURL& gurl) { |
| 562 | client_.OverrideFlashEmbedWithHTML(gurl); |
| 563 | } |
| 564 | |
| 565 | private: |
| 566 | ChromeContentRendererClient client_; |
| 567 | base::HistogramTester histogram_tester_; |
| 568 | |
| 569 | DISALLOW_COPY_AND_ASSIGN(ChromeContentRendererClientMetricsTest); |
| 570 | }; |
| 571 | |
| 572 | TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedIneligibleURL) { |
| 573 | std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| 574 | EXPECT_EQ(0, samples->TotalCount()); |
| 575 | |
| 576 | const std::string test_data[] = { |
| 577 | // HTTP, www, no flash |
| 578 | "http://www.youtube.com", |
| 579 | // No flash, subdomain |
| 580 | "http://www.foo.youtube.com", |
| 581 | // No flash |
| 582 | "youtube.com", |
| 583 | // Not youtube |
| 584 | "http://www.plus.google.com", |
| 585 | // Already using HTML5 |
| 586 | "http://youtube.com/embed/deadbeef", |
| 587 | // Already using HTML5, enablejsapi=1 |
| 588 | "http://www.youtube.com/embed/deadbeef?enablejsapi=1"}; |
| 589 | |
| 590 | for (const auto& data : test_data) { |
| 591 | GURL gurl = GURL(data); |
| 592 | OverrideFlashEmbed(gurl); |
| 593 | samples = GetHistogramSamples(); |
| 594 | EXPECT_EQ(0, samples->GetCount(internal::SUCCESS)); |
| 595 | EXPECT_EQ(0, samples->TotalCount()); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccess) { |
| 600 | ChromeContentRendererClient client; |
| 601 | |
| 602 | std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| 603 | auto total_count = 0; |
| 604 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 605 | |
| 606 | const std::string test_data[] = { |
| 607 | // HTTP, www, flash |
| 608 | "http://www.youtube.com/v/deadbeef", |
| 609 | // HTTP, no www, flash |
| 610 | "http://youtube.com/v/deadbeef", |
| 611 | // HTTPS, www, flash |
| 612 | "https://www.youtube.com/v/deadbeef", |
| 613 | // HTTPS, no www, flash |
| 614 | "https://youtube.com/v/deadbeef", |
| 615 | // Invalid parameter construct |
| 616 | "http://www.youtube.com/v/abcd/", |
| 617 | // Invalid parameter construct |
| 618 | "http://www.youtube.com/v/1234/", |
| 619 | }; |
| 620 | |
| 621 | for (const auto& data : test_data) { |
| 622 | ++total_count; |
| 623 | GURL gurl = GURL(data); |
| 624 | OverrideFlashEmbed(gurl); |
| 625 | samples = GetHistogramSamples(); |
| 626 | EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS)); |
| 627 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 628 | } |
| 629 | |
| 630 | // Invalid parameter construct |
| 631 | GURL gurl = GURL("http://www.youtube.com/abcd/v/deadbeef"); |
| 632 | samples = GetHistogramSamples(); |
| 633 | EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS)); |
| 634 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 635 | } |
| 636 | |
| 637 | TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccessRewrite) { |
| 638 | ChromeContentRendererClient client; |
| 639 | |
| 640 | std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| 641 | auto total_count = 0; |
| 642 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 643 | |
| 644 | const std::string test_data[] = { |
| 645 | // Invalid parameter construct, one parameter |
| 646 | "http://www.youtube.com/v/deadbeef&start=4", |
| 647 | // Invalid parameter construct, has multiple parameters |
| 648 | "http://www.youtube.com/v/deadbeef&start=4&fs=1?foo=bar", |
| 649 | }; |
| 650 | |
| 651 | for (const auto& data : test_data) { |
| 652 | ++total_count; |
| 653 | GURL gurl = GURL(data); |
| 654 | client.OverrideFlashEmbedWithHTML(gurl); |
| 655 | samples = GetHistogramSamples(); |
| 656 | EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE)); |
| 657 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 658 | } |
| 659 | |
| 660 | // Invalid parameter construct, not flash |
| 661 | GURL gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4"); |
| 662 | OverrideFlashEmbed(gurl); |
| 663 | samples = GetHistogramSamples(); |
| 664 | EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE)); |
| 665 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 666 | } |
| 667 | |
kdsilva | 621478c | 2016-08-09 17:31:11 | [diff] [blame] | 668 | #if defined(OS_ANDROID) |
| 669 | TEST_F(ChromeContentRendererClientMetricsTest, |
| 670 | RewriteEmbedFailureJSAPIAndroid) { |
kdsilva | af8d257 | 2016-08-09 17:22:20 | [diff] [blame] | 671 | ChromeContentRendererClient client; |
| 672 | |
| 673 | std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| 674 | auto total_count = 0; |
| 675 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 676 | |
| 677 | const std::string test_data[] = { |
kdsilva | 621478c | 2016-08-09 17:31:11 | [diff] [blame] | 678 | // Valid parameter construct, one parameter |
| 679 | "http://www.youtube.com/v/deadbeef?enablejsapi=1", |
| 680 | // Valid parameter construct, has multiple parameters |
| 681 | "http://www.youtube.com/v/deadbeef?enablejsapi=1&foo=2", |
| 682 | // Invalid parameter construct, one parameter |
| 683 | "http://www.youtube.com/v/deadbeef&enablejsapi=1", |
| 684 | // Invalid parameter construct, has multiple parameters |
| 685 | "http://www.youtube.com/v/deadbeef&enablejsapi=1&foo=2"}; |
| 686 | |
| 687 | for (const auto& data : test_data) { |
| 688 | ++total_count; |
| 689 | GURL gurl = GURL(data); |
| 690 | OverrideFlashEmbed(gurl); |
| 691 | samples = GetHistogramSamples(); |
| 692 | EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_ENABLEJSAPI)); |
| 693 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | #else |
| 698 | TEST_F(ChromeContentRendererClientMetricsTest, |
| 699 | RewriteEmbedFailureJSAPIDesktop) { |
| 700 | ChromeContentRendererClient client; |
| 701 | |
| 702 | std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| 703 | auto total_count = 0; |
| 704 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 705 | |
| 706 | const std::string test_data[] = { |
| 707 | // Valid parameter construct, one parameter |
| 708 | "http://www.youtube.com/v/deadbeef?enablejsapi=1", |
kdsilva | af8d257 | 2016-08-09 17:22:20 | [diff] [blame] | 709 | // Invalid parameter construct, one parameter |
| 710 | "http://www.youtube.com/v/deadbeef&enablejsapi=1", |
| 711 | // Invalid parameter construct, has multiple parameters |
| 712 | "http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"}; |
| 713 | |
| 714 | for (const auto& data : test_data) { |
| 715 | ++total_count; |
| 716 | GURL gurl = GURL(data); |
| 717 | OverrideFlashEmbed(gurl); |
| 718 | samples = GetHistogramSamples(); |
| 719 | EXPECT_EQ(total_count, samples->GetCount(internal::FAILURE_ENABLEJSAPI)); |
| 720 | EXPECT_EQ(total_count, samples->TotalCount()); |
| 721 | } |
| 722 | } |
kdsilva | 621478c | 2016-08-09 17:31:11 | [diff] [blame] | 723 | #endif |