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

Side by Side Diff: chrome/browser/extensions/chrome_content_browser_client_extensions_part_unittest.cc

Issue 2787573003: Remove DumpWithoutCrashing from ShouldAllowOpenURL. (Closed)
Patch Set: Fix unit_tests compile error Created 3 years, 8 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
(Empty)
1 // Copyright 2017 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 <string>
6 #include <vector>
7
8 #include "base/test/histogram_tester.h"
9 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_par t.h"
10 #include "chrome/common/chrome_content_client.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace extensions {
14
15 typedef testing::Test ChromeContentBrowserClientExtensionsPartTest;
16
17 // Check that empty site URLs get recorded properly in ShouldAllowOpenURL
18 // failures.
19 TEST_F(ChromeContentBrowserClientExtensionsPartTest,
20 ShouldAllowOpenURLMetricsForEmptySiteURL) {
21 base::HistogramTester uma;
22
23 auto failure_reason = ChromeContentBrowserClientExtensionsPart::
24 FAILURE_SCHEME_NOT_HTTP_OR_HTTPS_OR_EXTENSION;
25 ChromeContentBrowserClientExtensionsPart::RecordShouldAllowOpenURLFailure(
26 failure_reason, GURL());
27 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure",
28 failure_reason, 1);
29 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure.Scheme",
30 1 /* SCHEME_EMPTY */, 1);
31 }
32
33 // Check that a non-exhaustive list of some known schemes get recorded properly
34 // in ShouldAllowOpenURL failures.
35 TEST_F(ChromeContentBrowserClientExtensionsPartTest,
36 ShouldAllowOpenURLMetricsForKnownSchemes) {
37 base::HistogramTester uma;
38
39 ChromeContentClient content_client;
40 content::ContentClient::Schemes schemes;
41 content_client.AddAdditionalSchemes(&schemes);
42
43 std::vector<std::string> test_schemes(schemes.savable_schemes);
44 test_schemes.insert(test_schemes.end(), schemes.secure_schemes.begin(),
45 schemes.secure_schemes.end());
46 test_schemes.insert(test_schemes.end(),
47 schemes.empty_document_schemes.begin(),
48 schemes.empty_document_schemes.end());
49 test_schemes.push_back(url::kHttpScheme);
50 test_schemes.push_back(url::kHttpsScheme);
51 test_schemes.push_back(url::kFileScheme);
52
53 auto failure_reason = ChromeContentBrowserClientExtensionsPart::
54 FAILURE_RESOURCE_NOT_WEB_ACCESSIBLE;
55 for (auto scheme : test_schemes) {
56 ChromeContentBrowserClientExtensionsPart::RecordShouldAllowOpenURLFailure(
57 failure_reason, GURL(scheme + "://foo.com/"));
58 }
59
60 // There should be no unknown schemes recorded.
61 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure",
62 failure_reason, test_schemes.size());
63 uma.ExpectTotalCount("Extensions.ShouldAllowOpenURL.Failure.Scheme",
64 test_schemes.size());
65 uma.ExpectBucketCount("Extensions.ShouldAllowOpenURL.Failure.Scheme",
66 0 /* SCHEME_UNKNOWN */, 0);
67 }
68
69 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698