| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/previews/previews_infobar_delegate.h" | 5 #include "chrome/browser/previews/previews_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 11 #include "base/optional.h" | 12 #include "base/optional.h" |
| 12 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
| 13 #include "chrome/browser/android/android_theme_resources.h" | 14 #include "chrome/browser/android/android_theme_resources.h" |
| 14 #include "chrome/browser/infobars/infobar_service.h" | 15 #include "chrome/browser/infobars/infobar_service.h" |
| 15 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 16 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 16 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 17 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
| 17 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 18 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
| 18 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
| 21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
| 22 #include "components/infobars/core/confirm_infobar_delegate.h" | 23 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 23 #include "components/infobars/core/infobar.h" | 24 #include "components/infobars/core/infobar.h" |
| 24 #include "components/infobars/core/infobar_delegate.h" | 25 #include "components/infobars/core/infobar_delegate.h" |
| 25 #include "components/prefs/pref_registry_simple.h" | 26 #include "components/prefs/pref_registry_simple.h" |
| 26 #include "components/proxy_config/proxy_config_pref_names.h" | 27 #include "components/proxy_config/proxy_config_pref_names.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/referrer.h" |
| 28 #include "content/public/test/web_contents_tester.h" | 30 #include "content/public/test/web_contents_tester.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/page_transition_types.h" |
| 30 #include "ui/base/window_open_disposition.h" | 33 #include "ui/base/window_open_disposition.h" |
| 31 | 34 |
| 32 namespace { | 35 namespace { |
| 33 | 36 |
| 34 const char kTestUrl[] = "http://www.test.com/"; | 37 const char kTestUrl[] = "http://www.test.com/"; |
| 35 | 38 |
| 36 // Key of the UMA Previews.InfoBarAction.LoFi histogram. | 39 // Key of the UMA Previews.InfoBarAction.LoFi histogram. |
| 37 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; | 40 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; |
| 38 | 41 |
| 39 // Key of the UMA Previews.InfoBarAction.Offline histogram. | 42 // Key of the UMA Previews.InfoBarAction.Offline histogram. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 135 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 133 EXPECT_FALSE(user_opt_out_.value()); | 136 EXPECT_FALSE(user_opt_out_.value()); |
| 134 | 137 |
| 135 tester.ExpectBucketCount( | 138 tester.ExpectBucketCount( |
| 136 kUMAPreviewsInfoBarActionLoFi, | 139 kUMAPreviewsInfoBarActionLoFi, |
| 137 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); | 140 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); |
| 138 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 141 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
| 139 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 142 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
| 140 } | 143 } |
| 141 | 144 |
| 145 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) { |
| 146 base::HistogramTester tester; |
| 147 |
| 148 // Navigate to test URL, so we can reload later. |
| 149 content::WebContentsTester::For(web_contents()) |
| 150 ->NavigateAndCommit(GURL(kTestUrl)); |
| 151 |
| 152 CreateInfoBar(PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); |
| 153 |
| 154 // Try showing a second infobar. Another should not be shown since the page |
| 155 // has not navigated. |
| 156 PreviewsInfoBarDelegate::Create( |
| 157 web_contents(), PreviewsInfoBarDelegate::LOFI, |
| 158 true /* is_data_saver_user */, |
| 159 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
| 160 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 161 |
| 162 // Navigate to test URL as a reload to dismiss the infobar. |
| 163 controller().LoadURL(GURL(kTestUrl), content::Referrer(), |
| 164 ui::PAGE_TRANSITION_RELOAD, std::string()); |
| 165 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 166 |
| 167 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 168 EXPECT_FALSE(user_opt_out_.value()); |
| 169 |
| 170 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, |
| 171 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD, |
| 172 1); |
| 173 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
| 174 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
| 175 } |
| 176 |
| 142 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { | 177 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { |
| 143 base::HistogramTester tester; | 178 base::HistogramTester tester; |
| 144 | 179 |
| 145 ConfirmInfoBarDelegate* infobar = CreateInfoBar( | 180 ConfirmInfoBarDelegate* infobar = CreateInfoBar( |
| 146 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); | 181 PreviewsInfoBarDelegate::LOFI, true /* is_data_saver_user */); |
| 147 | 182 |
| 148 // Simulate dismissing the infobar. | 183 // Simulate dismissing the infobar. |
| 149 infobar->InfoBarDismissed(); | 184 infobar->InfoBarDismissed(); |
| 150 infobar_service()->infobar_at(0)->RemoveSelf(); | 185 infobar_service()->infobar_at(0)->RemoveSelf(); |
| 151 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 186 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), | 322 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE), |
| 288 infobar->GetMessageText()); | 323 infobar->GetMessageText()); |
| 289 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), | 324 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), |
| 290 infobar->GetLinkText()); | 325 infobar->GetLinkText()); |
| 291 #if defined(OS_ANDROID) | 326 #if defined(OS_ANDROID) |
| 292 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); | 327 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); |
| 293 #else | 328 #else |
| 294 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); | 329 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); |
| 295 #endif | 330 #endif |
| 296 } | 331 } |
| OLD | NEW |