Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/content_settings/content_settings_browsertest.cc

Issue 2048303002: Fix broken mixed script Rappor metric and add browser test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/content_settings/cookie_settings_factory.h" 11 #include "chrome/browser/content_settings/cookie_settings_factory.h"
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
14 #include "chrome/browser/net/url_request_mock_util.h" 14 #include "chrome/browser/net/url_request_mock_util.h"
15 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 15 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_commands.h" 18 #include "chrome/browser/ui/browser_commands.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/test_launcher_utils.h" 22 #include "chrome/test/base/test_launcher_utils.h"
23 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
24 #include "components/content_settings/core/browser/cookie_settings.h" 24 #include "components/content_settings/core/browser/cookie_settings.h"
25 #include "components/content_settings/core/browser/host_content_settings_map.h" 25 #include "components/content_settings/core/browser/host_content_settings_map.h"
26 #include "components/network_session_configurator/switches.h"
27 #include "components/rappor/test_rappor_service.h"
26 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_observer.h" 29 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/plugin_service.h" 31 #include "content/public/browser/plugin_service.h"
30 #include "content/public/browser/render_frame_host.h" 32 #include "content/public/browser/render_frame_host.h"
31 #include "content/public/browser/render_process_host.h" 33 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/render_view_host.h" 34 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
34 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
35 #include "content/public/test/browser_test_utils.h" 37 #include "content/public/test/browser_test_utils.h"
36 #include "content/public/test/test_utils.h" 38 #include "content/public/test/test_utils.h"
37 #include "media/cdm/cdm_paths.h" 39 #include "media/cdm/cdm_paths.h"
38 #include "net/dns/mock_host_resolver.h" 40 #include "net/dns/mock_host_resolver.h"
39 #include "net/test/embedded_test_server/embedded_test_server.h" 41 #include "net/test/embedded_test_server/embedded_test_server.h"
42 #include "net/test/embedded_test_server/request_handler_util.h"
40 #include "net/test/url_request/url_request_mock_http_job.h" 43 #include "net/test/url_request/url_request_mock_http_job.h"
41 44
42 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 45 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
43 46
44 #if defined(OS_MACOSX) 47 #if defined(OS_MACOSX)
45 #include "base/mac/scoped_nsautorelease_pool.h" 48 #include "base/mac/scoped_nsautorelease_pool.h"
46 #endif 49 #endif
47 50
48 #if defined(ENABLE_PEPPER_CDMS) 51 #if defined(ENABLE_PEPPER_CDMS)
49 #include "chrome/browser/media/pepper_cdm_test_constants.h" 52 #include "chrome/browser/media/pepper_cdm_test_constants.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 243
241 content::WebContents* web_contents = 244 content::WebContents* web_contents =
242 browser()->tab_strip_model()->GetActiveWebContents(); 245 browser()->tab_strip_model()->GetActiveWebContents();
243 ASSERT_EQ(base::UTF8ToUTF16(test_url.spec() + " failed to load"), 246 ASSERT_EQ(base::UTF8ToUTF16(test_url.spec() + " failed to load"),
244 web_contents->GetTitle()); 247 web_contents->GetTitle());
245 248
246 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> 249 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)->
247 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); 250 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
248 } 251 }
249 252
253 class ContentSettingsIgnoreCertErrorsTest : public ContentSettingsTest {
254 protected:
255 void SetUpCommandLine(base::CommandLine* command_line) override {
256 command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
257 }
258 };
259
260 // Tests that a RAPPOR metric is recorded when mixed script is
261 // blocked. Regression test for https://crbug.com/536975.
262 //
263 // This test fixture sets up the browser to ignore certificate errors,
264 // so that a non-matching, non-local hostname can be used for the
265 // test. This is because Rappor treats local hostnames as slightly
266 // special, so it's a little nicer to test with a non-local hostname.
267 IN_PROC_BROWSER_TEST_F(ContentSettingsIgnoreCertErrorsTest,
268 MixedScriptRapporMetric) {
269 host_resolver()->AddRule("*", "127.0.0.1");
270 ASSERT_TRUE(https_server_.Start());
271 ASSERT_TRUE(embedded_test_server()->Start());
272 std::string replacement_path;
273 base::StringPairs replacement_text;
274 replacement_text.push_back(
275 make_pair("REPLACE_WITH_HOST_AND_PORT",
276 embedded_test_server()->host_port_pair().ToString()));
277 net::test_server::GetFilePathWithReplacements(
278 "/ssl/page_runs_insecure_content.html", replacement_text,
279 &replacement_path);
280 GURL url = https_server_.GetURL(replacement_path);
281
282 // Rappor treats local hostnames a little bit special (e.g. records
283 // "127.0.0.1" as "localhost"), so use a non-local hostname for
284 // convenience.
285 GURL::Replacements replace_host;
286 replace_host.SetHostStr("example.test");
287 url = url.ReplaceComponents(replace_host);
288
289 rappor::TestRapporService rappor_service;
290 TabSpecificContentSettings* tab_specific_content_settings =
291 TabSpecificContentSettings::FromWebContents(
292 browser()->tab_strip_model()->GetWebContentsAt(0));
293 tab_specific_content_settings->SetRapporServiceForTesting(&rappor_service);
294 EXPECT_EQ(0, rappor_service.GetReportsCount());
295
296 ui_test_utils::NavigateToURL(browser(), url);
297
298 EXPECT_EQ(1, rappor_service.GetReportsCount());
299 std::string sample;
300 rappor::RapporType type;
301 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
302 "ContentSettings.MixedScript.DisplayedShield", &sample, &type));
303 EXPECT_EQ(url.host(), sample);
304 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
305 }
306
250 // TODO(jww): This should be removed after strict secure cookies is enabled for 307 // TODO(jww): This should be removed after strict secure cookies is enabled for
251 // all and this test should be moved into ContentSettingsTest above. 308 // all and this test should be moved into ContentSettingsTest above.
252 class ContentSettingsStrictSecureCookiesBrowserTest 309 class ContentSettingsStrictSecureCookiesBrowserTest
253 : public ContentSettingsTest { 310 : public ContentSettingsTest {
254 protected: 311 protected:
255 void SetUpCommandLine(base::CommandLine* cmd) override { 312 void SetUpCommandLine(base::CommandLine* cmd) override {
256 cmd->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); 313 cmd->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures);
257 } 314 }
258 }; 315 };
259 316
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 #endif // defined(ENABLE_PEPPER_CDMS) 574 #endif // defined(ENABLE_PEPPER_CDMS)
518 575
519 #if !defined(DISABLE_NACL) 576 #if !defined(DISABLE_NACL)
520 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, 577 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest,
521 NaCl) { 578 NaCl) {
522 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); 579 RunJavaScriptBlockedTest("load_nacl_no_js.html", true);
523 } 580 }
524 #endif // !defined(DISABLE_NACL) 581 #endif // !defined(DISABLE_NACL)
525 582
526 #endif // defined(ENABLE_PLUGINS) 583 #endif // defined(ENABLE_PLUGINS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698