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

Side by Side Diff: chrome/browser/previews/previews_infobar_delegate_unittest.cc

Issue 2557113004: Seperate reloads when reporting previews infobar dismissal (Closed)
Patch Set: megjablon comments Created 4 years 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
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 EXPECT_EQ(0U, infobar_service()->infobar_count()); 133 EXPECT_EQ(0U, infobar_service()->infobar_count());
131 EXPECT_FALSE(user_opt_out_.value()); 134 EXPECT_FALSE(user_opt_out_.value());
132 135
133 tester.ExpectBucketCount( 136 tester.ExpectBucketCount(
134 kUMAPreviewsInfoBarActionLoFi, 137 kUMAPreviewsInfoBarActionLoFi,
135 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1); 138 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_NAVIGATION, 1);
136 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( 139 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
137 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); 140 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
138 } 141 }
139 142
143 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestReloadDismissal) {
144 base::HistogramTester tester;
145
146 // Navigate to test URL, so we can reload later.
147 content::WebContentsTester::For(web_contents())
148 ->NavigateAndCommit(GURL(kTestUrl));
149
150 CreateInfoBar(PreviewsInfoBarDelegate::LOFI);
151
152 // Try showing a second infobar. Another should not be shown since the page
153 // has not navigated.
154 PreviewsInfoBarDelegate::Create(
155 web_contents(), PreviewsInfoBarDelegate::LOFI,
156 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback());
157 EXPECT_EQ(1U, infobar_service()->infobar_count());
158
159 // Navigate to test URL as a reload to dismiss the infobar.
160 controller().LoadURL(GURL(kTestUrl), content::Referrer(),
161 ui::PAGE_TRANSITION_RELOAD, std::string());
162 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
163
164 EXPECT_EQ(0U, infobar_service()->infobar_count());
165 EXPECT_FALSE(user_opt_out_.value());
166
167 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi,
168 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD,
169 1);
170 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger(
171 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession));
172 }
173
140 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { 174 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) {
141 base::HistogramTester tester; 175 base::HistogramTester tester;
142 176
143 ConfirmInfoBarDelegate* infobar = 177 ConfirmInfoBarDelegate* infobar =
144 CreateInfoBar(PreviewsInfoBarDelegate::LOFI); 178 CreateInfoBar(PreviewsInfoBarDelegate::LOFI);
145 179
146 // Simulate dismissing the infobar. 180 // Simulate dismissing the infobar.
147 infobar->InfoBarDismissed(); 181 infobar->InfoBarDismissed();
148 infobar_service()->infobar_at(0)->RemoveSelf(); 182 infobar_service()->infobar_at(0)->RemoveSelf();
149 EXPECT_EQ(0U, infobar_service()->infobar_count()); 183 EXPECT_EQ(0U, infobar_service()->infobar_count());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE), 294 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE),
261 infobar->GetMessageText()); 295 infobar->GetMessageText());
262 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK), 296 ASSERT_EQ(l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK),
263 infobar->GetLinkText()); 297 infobar->GetLinkText());
264 #if defined(OS_ANDROID) 298 #if defined(OS_ANDROID)
265 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId()); 299 ASSERT_EQ(IDR_ANDROID_INFOBAR_PREVIEWS, infobar->GetIconId());
266 #else 300 #else
267 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId()); 301 ASSERT_EQ(PreviewsInfoBarDelegate::kNoIconID, infobar->GetIconId());
268 #endif 302 #endif
269 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698