Index: chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc |
diff --git a/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc b/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc |
index 4152ac08f64bd5d858dc5bc2f2dd3315359dda23..79995d59c9289797df38c1bfcc4c02d9bf02f221 100644 |
--- a/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc |
+++ b/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc |
@@ -3,9 +3,11 @@ |
// found in the LICENSE file. |
#include "chrome/browser/safe_browsing/chrome_password_protection_service.h" |
+#include "base/test/histogram_tester.h" |
#include "base/test/scoped_feature_list.h" |
#include "components/variations/variations_params_manager.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace safe_browsing { |
@@ -69,13 +71,18 @@ class ChromePasswordProtectionServiceTest : public testing::Test { |
content::TestBrowserThreadBundle thread_bundle_; |
variations::testing::VariationParamsManager params_manager_; |
base::test::ScopedFeatureList scoped_feature_list_; |
+ base::HistogramTester histograms_; |
}; |
TEST_F(ChromePasswordProtectionServiceTest, |
VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) { |
MockChromePasswordProtectionService service; |
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
// By default kPasswordFieldOnFocusPinging feature is disabled. |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(12, 1))); |
// Enables kPasswordFieldOnFocusPinging feature. |
scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging); |
@@ -93,29 +100,64 @@ TEST_F(ChromePasswordProtectionServiceTest, |
CreateParameters(false, false, true, false); |
SetFeatureParams(kPasswordFieldOnFocusPinging, "SBEROnlyNoIncognito", |
sber_and_no_incognito); |
+ |
service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
Nathan Parker
2017/05/11 23:36:31
How about a comment that says where the bucket val
Nathan Parker
2017/05/11 23:36:31
nit: Add up top
using testing:ElementsAre
using
Jialiu Lin
2017/05/12 02:12:32
Due to the code refactoring, no need to check hist
|
+ testing::ElementsAre(base::Bucket(12, 1), base::Bucket(13, 1))); |
+ |
service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(12, 1), base::Bucket(13, 2))); |
+ |
service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(12, 1), base::Bucket(13, 2))); |
+ |
service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(12, 1), base::Bucket(13, 2))); |
+ |
service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 1), base::Bucket(12, 1), |
+ base::Bucket(13, 2))); |
+ |
service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 2), base::Bucket(12, 1), |
+ base::Bucket(13, 2))); |
+ |
service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 3), base::Bucket(12, 1), |
+ base::Bucket(13, 2))); |
+ |
service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 4), base::Bucket(12, 1), |
+ base::Bucket(13, 2))); |
} |
TEST_F(ChromePasswordProtectionServiceTest, |
VerifyFinchControlForLowReputationPingSBERAndHistorySyncNoIncognito) { |
MockChromePasswordProtectionService service; |
- // By default kPasswordFieldOnFocusPinging feature is disabled. |
- EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
// Enables kPasswordFieldOnFocusPinging feature. |
scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging); |
@@ -135,27 +177,57 @@ TEST_F(ChromePasswordProtectionServiceTest, |
"SBERAndHistorySyncNoIncognito", sber_and_sync_no_incognito); |
service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(13, 1))); |
+ |
service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(13, 1))); |
+ |
service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(13, 1))); |
+ |
service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(13, 1))); |
+ |
service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 1), base::Bucket(13, 1))); |
+ |
service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 2), base::Bucket(13, 1))); |
+ |
service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 3), base::Bucket(13, 1))); |
+ |
service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 4), base::Bucket(13, 1))); |
} |
TEST_F(ChromePasswordProtectionServiceTest, |
VerifyFinchControlForLowReputationPingAllButNoIncognito) { |
MockChromePasswordProtectionService service; |
- // By default kPasswordFieldOnFocusPinging feature is disabled. |
- EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
// Enables kPasswordFieldOnFocusPinging feature. |
scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging); |
@@ -173,27 +245,49 @@ TEST_F(ChromePasswordProtectionServiceTest, |
all_users); |
service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
+ |
service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
+ |
service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
+ |
service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
+ |
service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 1))); |
+ |
service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 2))); |
+ |
service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 3))); |
+ |
service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); |
EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ EXPECT_THAT( |
+ histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
+ testing::ElementsAre(base::Bucket(7, 4))); |
} |
TEST_F(ChromePasswordProtectionServiceTest, |
VerifyFinchControlForLowReputationPingAll) { |
MockChromePasswordProtectionService service; |
- // By default kPasswordFieldOnFocusPinging feature is disabled. |
- EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
// Enables kPasswordFieldOnFocusPinging feature. |
scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging); |
@@ -224,6 +318,7 @@ TEST_F(ChromePasswordProtectionServiceTest, |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); |
EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging)); |
+ histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
} |
} // namespace safe_browsing |