| 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 "base/metrics/histogram_samples.h" | 5 #include "base/metrics/histogram_samples.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h" | 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h" |
| 10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| 11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" | 11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "components/password_manager/content/common/credential_manager_types.h" | 13 #include "components/password_manager/content/common/credential_manager_types.h" |
| 14 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 14 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
| 15 #include "components/password_manager/core/common/password_manager_pref_names.h" | 15 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 16 #include "components/password_manager/core/common/password_manager_ui.h" | 16 #include "components/password_manager/core/common/password_manager_ui.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "content/public/test/web_contents_tester.h" | 18 #include "content/public/test/web_contents_tester.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 const char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason"; | 21 const char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason"; |
| 22 | 22 |
| 23 class ManagePasswordsBubbleModelTest : public testing::Test { | 23 class ManagePasswordsBubbleModelTest : public testing::Test { |
| 24 public: | 24 public: |
| 25 ManagePasswordsBubbleModelTest() | 25 ManagePasswordsBubbleModelTest() |
| 26 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 26 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 27 test_web_contents_( | 27 test_web_contents_( |
| 28 content::WebContentsTester::CreateTestWebContents(&profile_, | 28 content::WebContentsTester::CreateTestWebContents(&profile_, |
| 29 NULL)) {} | 29 nullptr)) {} |
| 30 | 30 |
| 31 void SetUp() override { | 31 void SetUp() override { |
| 32 // Create the test UIController here so that it's bound to | 32 // Create the test UIController here so that it's bound to |
| 33 // |test_web_contents_| and therefore accessible to the model. | 33 // |test_web_contents_| and therefore accessible to the model. |
| 34 new ManagePasswordsUIControllerMock(test_web_contents_.get()); | 34 new ManagePasswordsUIControllerMock(test_web_contents_.get()); |
| 35 | 35 |
| 36 model_.reset(new ManagePasswordsBubbleModel(test_web_contents_.get())); | 36 model_.reset(new ManagePasswordsBubbleModel(test_web_contents_.get())); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void TearDown() override { model_.reset(); } | 39 void TearDown() override { model_.reset(); } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 base::HistogramTester histogram_tester; | 105 base::HistogramTester histogram_tester; |
| 106 model_->OnBubbleHidden(); | 106 model_->OnBubbleHidden(); |
| 107 EXPECT_EQ(model_->dismissal_reason(), | 107 EXPECT_EQ(model_->dismissal_reason(), |
| 108 password_manager::metrics_util::NOT_DISPLAYED); | 108 password_manager::metrics_util::NOT_DISPLAYED); |
| 109 EXPECT_FALSE(controller()->saved_password()); | 109 EXPECT_FALSE(controller()->saved_password()); |
| 110 EXPECT_FALSE(controller()->never_saved_password()); | 110 EXPECT_FALSE(controller()->never_saved_password()); |
| 111 | 111 |
| 112 scoped_ptr<base::HistogramSamples> samples( | 112 scoped_ptr<base::HistogramSamples> samples( |
| 113 histogram_tester.GetHistogramSamplesSinceCreation( | 113 histogram_tester.GetHistogramSamplesSinceCreation( |
| 114 kUIDismissalReasonMetric)); | 114 kUIDismissalReasonMetric)); |
| 115 EXPECT_EQ(NULL, samples.get()); | 115 EXPECT_FALSE(samples); |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutInteraction) { | 118 TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutInteraction) { |
| 119 base::HistogramTester histogram_tester; | 119 base::HistogramTester histogram_tester; |
| 120 PretendPasswordWaiting(); | 120 PretendPasswordWaiting(); |
| 121 model_->OnBubbleHidden(); | 121 model_->OnBubbleHidden(); |
| 122 EXPECT_EQ(model_->dismissal_reason(), | 122 EXPECT_EQ(model_->dismissal_reason(), |
| 123 password_manager::metrics_util::NO_DIRECT_INTERACTION); | 123 password_manager::metrics_util::NO_DIRECT_INTERACTION); |
| 124 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, | 124 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, |
| 125 model_->state()); | 125 model_->state()); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 model_->OnAutoSignInToastTimeout(); | 295 model_->OnAutoSignInToastTimeout(); |
| 296 model_->OnBubbleHidden(); | 296 model_->OnBubbleHidden(); |
| 297 EXPECT_EQ(model_->dismissal_reason(), | 297 EXPECT_EQ(model_->dismissal_reason(), |
| 298 password_manager::metrics_util::AUTO_SIGNIN_TOAST_TIMEOUT); | 298 password_manager::metrics_util::AUTO_SIGNIN_TOAST_TIMEOUT); |
| 299 | 299 |
| 300 histogram_tester.ExpectUniqueSample( | 300 histogram_tester.ExpectUniqueSample( |
| 301 kUIDismissalReasonMetric, | 301 kUIDismissalReasonMetric, |
| 302 password_manager::metrics_util::AUTO_SIGNIN_TOAST_TIMEOUT, | 302 password_manager::metrics_util::AUTO_SIGNIN_TOAST_TIMEOUT, |
| 303 1); | 303 1); |
| 304 } | 304 } |
| OLD | NEW |