| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked( | 75 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked( |
| 76 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 76 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 class ContentSettingsMixedScriptIgnoreCertErrorsTest | 79 class ContentSettingsMixedScriptIgnoreCertErrorsTest |
| 80 : public ContentSettingBubbleModelMixedScriptTest { | 80 : public ContentSettingBubbleModelMixedScriptTest { |
| 81 protected: | 81 protected: |
| 82 void SetUpCommandLine(base::CommandLine* command_line) override { | 82 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 83 command_line->AppendSwitch(switches::kIgnoreCertificateErrors); | 83 command_line->AppendSwitch(switches::kIgnoreCertificateErrors); |
| 84 } | 84 } |
| 85 |
| 86 void SetUpOnMainThread() override { |
| 87 ContentSettingBubbleModelMixedScriptTest::SetUpOnMainThread(); |
| 88 // Rappor treats local hostnames a little bit special (e.g. records |
| 89 // "127.0.0.1" as "localhost"), so use a non-local hostname for |
| 90 // convenience. |
| 91 host_resolver()->AddRule("*", "127.0.0.1"); |
| 92 } |
| 85 }; | 93 }; |
| 86 | 94 |
| 87 // Tests that a MIXEDSCRIPT type ContentSettingBubbleModel records UMA | 95 // Tests that a MIXEDSCRIPT type ContentSettingBubbleModel records UMA |
| 88 // and Rappor metrics when the content is allowed to run. | 96 // and Rappor metrics when the content is allowed to run. |
| 89 // | 97 // |
| 90 // This test fixture sets up the browser to ignore certificate errors, | 98 // This test fixture sets up the browser to ignore certificate errors, |
| 91 // so that a non-matching, non-local hostname can be used for the | 99 // so that a non-matching, non-local hostname can be used for the |
| 92 // test. This is because Rappor treats local hostnames as slightly | 100 // test. This is because Rappor treats local hostnames as slightly |
| 93 // special, so it's a little nicer to test with a non-local hostname. | 101 // special, so it's a little nicer to test with a non-local hostname. |
| 94 IN_PROC_BROWSER_TEST_F(ContentSettingsMixedScriptIgnoreCertErrorsTest, | 102 IN_PROC_BROWSER_TEST_F(ContentSettingsMixedScriptIgnoreCertErrorsTest, |
| 95 MainFrameMetrics) { | 103 MainFrameMetrics) { |
| 96 GURL url(https_server_->GetURL("/content_setting_bubble/mixed_script.html")); | 104 GURL url(https_server_->GetURL("/content_setting_bubble/mixed_script.html")); |
| 97 | 105 |
| 98 // Rappor treats local hostnames a little bit special (e.g. records | |
| 99 // "127.0.0.1" as "localhost"), so use a non-local hostname for | |
| 100 // convenience. | |
| 101 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 102 GURL::Replacements replace_host; | 106 GURL::Replacements replace_host; |
| 103 replace_host.SetHostStr("example.test"); | 107 replace_host.SetHostStr("example.test"); |
| 104 url = url.ReplaceComponents(replace_host); | 108 url = url.ReplaceComponents(replace_host); |
| 105 | 109 |
| 106 rappor::TestRapporServiceImpl rappor_service; | 110 rappor::TestRapporServiceImpl rappor_service; |
| 107 EXPECT_EQ(0, rappor_service.GetReportsCount()); | 111 EXPECT_EQ(0, rappor_service.GetReportsCount()); |
| 108 base::HistogramTester histograms; | 112 base::HistogramTester histograms; |
| 109 histograms.ExpectTotalCount("ContentSettings.MixedScript", 0); | 113 histograms.ExpectTotalCount("ContentSettings.MixedScript", 0); |
| 110 | 114 |
| 111 // Load a page with mixed content and do quick verification by looking at | 115 // Load a page with mixed content and do quick verification by looking at |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 content_settings::POPUPS_ACTION_CLICKED_MANAGE_POPUPS_BLOCKING, 1); | 279 content_settings::POPUPS_ACTION_CLICKED_MANAGE_POPUPS_BLOCKING, 1); |
| 276 | 280 |
| 277 model->OnRadioClicked(model->kAllowButtonIndex); | 281 model->OnRadioClicked(model->kAllowButtonIndex); |
| 278 delete model.release(); | 282 delete model.release(); |
| 279 histograms.ExpectBucketCount( | 283 histograms.ExpectBucketCount( |
| 280 "ContentSettings.Popups", | 284 "ContentSettings.Popups", |
| 281 content_settings::POPUPS_ACTION_SELECTED_ALWAYS_ALLOW_POPUPS_FROM, 1); | 285 content_settings::POPUPS_ACTION_SELECTED_ALWAYS_ALLOW_POPUPS_FROM, 1); |
| 282 | 286 |
| 283 histograms.ExpectTotalCount("ContentSettings.Popups", 5); | 287 histograms.ExpectTotalCount("ContentSettings.Popups", 5); |
| 284 } | 288 } |
| OLD | NEW |