OLD | NEW |
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 #import "chrome/browser/ui/cocoa/browser/password_generation_bubble_controller.h
" | 5 #import "chrome/browser/ui/cocoa/browser/password_generation_bubble_controller.h
" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "base/test/statistics_delta_reader.h" | 11 #include "base/test/histogram_tester.h" |
12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
13 #include "components/autofill/core/browser/password_generator.h" | 13 #include "components/autofill/core/browser/password_generator.h" |
14 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
15 #include "testing/gtest_mac.h" | 15 #include "testing/gtest_mac.h" |
16 | 16 |
17 const char kHistogramName[] = "PasswordGeneration.UserActions"; | 17 const char kHistogramName[] = "PasswordGeneration.UserActions"; |
18 | 18 |
19 class PasswordGenerationBubbleControllerTest : public CocoaProfileTest { | 19 class PasswordGenerationBubbleControllerTest : public CocoaProfileTest { |
20 public: | 20 public: |
21 PasswordGenerationBubbleControllerTest() | 21 PasswordGenerationBubbleControllerTest() |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 [textfield simulateIconClick]; | 74 [textfield simulateIconClick]; |
75 | 75 |
76 // Make sure that the password has changed. Technically this will fail | 76 // Make sure that the password has changed. Technically this will fail |
77 // about once every 1e28 times, but not something we really need to worry | 77 // about once every 1e28 times, but not something we really need to worry |
78 // about. | 78 // about. |
79 NSString* after = [textfield stringValue]; | 79 NSString* after = [textfield stringValue]; |
80 EXPECT_FALSE([before isEqualToString:after]); | 80 EXPECT_FALSE([before isEqualToString:after]); |
81 } | 81 } |
82 | 82 |
83 TEST_F(PasswordGenerationBubbleControllerTest, UMALogging) { | 83 TEST_F(PasswordGenerationBubbleControllerTest, UMALogging) { |
84 base::StatisticsDeltaReader statistics_delta_reader; | 84 base::HistogramTester histogram_tester; |
85 [controller() showWindow:nil]; | 85 [controller() showWindow:nil]; |
86 | 86 |
87 // Do nothing. | 87 // Do nothing. |
88 CloseController(); | 88 CloseController(); |
89 | 89 |
90 scoped_ptr<base::HistogramSamples> samples( | 90 histogram_tester.ExpectUniqueSample( |
91 statistics_delta_reader.GetHistogramSamplesSinceCreation(kHistogramName)); | 91 kHistogramName, autofill::password_generation::IGNORE_FEATURE, 1); |
92 EXPECT_EQ( | |
93 1, | |
94 samples->GetCount(autofill::password_generation::IGNORE_FEATURE)); | |
95 EXPECT_EQ( | |
96 0, | |
97 samples->GetCount(autofill::password_generation::ACCEPT_AFTER_EDITING)); | |
98 EXPECT_EQ( | |
99 0, | |
100 samples->GetCount( | |
101 autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD)); | |
102 | 92 |
103 SetUpController(); | 93 SetUpController(); |
104 | 94 |
105 // Pretend like the user changed the password and accepted it. | 95 // Pretend like the user changed the password and accepted it. |
106 [controller() controlTextDidChange:nil]; | 96 [controller() controlTextDidChange:nil]; |
107 [controller() fillPassword:nil]; | 97 [controller() fillPassword:nil]; |
108 CloseController(); | 98 CloseController(); |
109 | 99 |
110 samples = | 100 histogram_tester.ExpectBucketCount( |
111 statistics_delta_reader.GetHistogramSamplesSinceCreation(kHistogramName); | 101 kHistogramName, autofill::password_generation::IGNORE_FEATURE, 1); |
112 EXPECT_EQ( | 102 histogram_tester.ExpectBucketCount( |
113 1, | 103 kHistogramName, autofill::password_generation::ACCEPT_AFTER_EDITING, 1); |
114 samples->GetCount(autofill::password_generation::IGNORE_FEATURE)); | 104 histogram_tester.ExpectTotalCount(kHistogramName, 2); |
115 EXPECT_EQ( | |
116 1, | |
117 samples->GetCount(autofill::password_generation::ACCEPT_AFTER_EDITING)); | |
118 EXPECT_EQ( | |
119 0, | |
120 samples->GetCount( | |
121 autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD)); | |
122 | 105 |
123 SetUpController(); | 106 SetUpController(); |
124 | 107 |
125 // Just accept the password | 108 // Just accept the password |
126 [controller() fillPassword:nil]; | 109 [controller() fillPassword:nil]; |
127 CloseController(); | 110 CloseController(); |
128 | 111 |
129 samples = | 112 histogram_tester.ExpectBucketCount( |
130 statistics_delta_reader.GetHistogramSamplesSinceCreation(kHistogramName); | 113 kHistogramName, autofill::password_generation::IGNORE_FEATURE, 1); |
131 EXPECT_EQ( | 114 histogram_tester.ExpectBucketCount( |
132 1, | 115 kHistogramName, autofill::password_generation::ACCEPT_AFTER_EDITING, 1); |
133 samples->GetCount(autofill::password_generation::IGNORE_FEATURE)); | 116 histogram_tester.ExpectBucketCount( |
134 EXPECT_EQ( | 117 kHistogramName, |
135 1, | 118 autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD, |
136 samples->GetCount(autofill::password_generation::ACCEPT_AFTER_EDITING)); | 119 1); |
137 EXPECT_EQ( | 120 histogram_tester.ExpectTotalCount(kHistogramName, 3); |
138 1, | |
139 samples->GetCount( | |
140 autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD)); | |
141 } | 121 } |
OLD | NEW |