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 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/field_trial_params.h" | 15 #include "base/metrics/field_trial_params.h" |
| 16 #include "base/metrics/metrics_hashes.h" |
16 #include "base/optional.h" | 17 #include "base/optional.h" |
17 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
18 #include "base/test/scoped_feature_list.h" | 19 #include "base/test/scoped_feature_list.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
21 #include "chrome/browser/android/android_theme_resources.h" | 22 #include "chrome/browser/android/android_theme_resources.h" |
22 #include "chrome/browser/infobars/infobar_service.h" | 23 #include "chrome/browser/infobars/infobar_service.h" |
23 #include "chrome/browser/loader/chrome_navigation_data.h" | 24 #include "chrome/browser/loader/chrome_navigation_data.h" |
24 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 25 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
25 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 26 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
| 27 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
| 28 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" |
26 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 29 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
27 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
28 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 31 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
29 #include "chrome/test/base/testing_browser_process.h" | 32 #include "chrome/test/base/testing_browser_process.h" |
30 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_test_utils.h" | 33 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_test_utils.h" |
31 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" | 34 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" |
32 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping
back_client.h" | 35 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping
back_client.h" |
33 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" | 36 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
34 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" | 37 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" |
35 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 38 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
36 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 39 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
37 #include "components/infobars/core/confirm_infobar_delegate.h" | 40 #include "components/infobars/core/confirm_infobar_delegate.h" |
38 #include "components/infobars/core/infobar.h" | 41 #include "components/infobars/core/infobar.h" |
39 #include "components/infobars/core/infobar_delegate.h" | 42 #include "components/infobars/core/infobar_delegate.h" |
40 #include "components/network_time/network_time_test_utils.h" | 43 #include "components/network_time/network_time_test_utils.h" |
41 #include "components/prefs/pref_registry_simple.h" | 44 #include "components/prefs/pref_registry_simple.h" |
42 #include "components/previews/core/previews_experiments.h" | 45 #include "components/previews/core/previews_experiments.h" |
43 #include "components/previews/core/previews_features.h" | 46 #include "components/previews/core/previews_features.h" |
44 #include "components/proxy_config/proxy_config_pref_names.h" | 47 #include "components/proxy_config/proxy_config_pref_names.h" |
| 48 #include "components/ukm/test_ukm_recorder.h" |
| 49 #include "components/ukm/ukm_source.h" |
45 #include "components/variations/variations_associated_data.h" | 50 #include "components/variations/variations_associated_data.h" |
46 #include "content/public/browser/navigation_entry.h" | 51 #include "content/public/browser/navigation_entry.h" |
47 #include "content/public/browser/navigation_handle.h" | 52 #include "content/public/browser/navigation_handle.h" |
48 #include "content/public/browser/reload_type.h" | 53 #include "content/public/browser/reload_type.h" |
49 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
50 #include "content/public/browser/web_contents_observer.h" | 55 #include "content/public/browser/web_contents_observer.h" |
51 #include "content/public/browser/web_contents_user_data.h" | 56 #include "content/public/browser/web_contents_user_data.h" |
52 #include "content/public/common/referrer.h" | 57 #include "content/public/common/referrer.h" |
53 #include "content/public/test/test_renderer_host.h" | 58 #include "content/public/test/test_renderer_host.h" |
54 #include "content/public/test/web_contents_tester.h" | 59 #include "content/public/test/web_contents_tester.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 115 |
111 private: | 116 private: |
112 content::ReloadType last_navigation_reload_type_; | 117 content::ReloadType last_navigation_reload_type_; |
113 bool should_have_page_id_; | 118 bool should_have_page_id_; |
114 }; | 119 }; |
115 | 120 |
116 } // namespace | 121 } // namespace |
117 | 122 |
118 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TestPreviewsWebContentsObserver); | 123 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TestPreviewsWebContentsObserver); |
119 | 124 |
120 class PreviewsInfoBarDelegateUnitTest : public ChromeRenderViewHostTestHarness { | 125 class PreviewsInfoBarDelegateUnitTest |
| 126 : public page_load_metrics::PageLoadMetricsObserverTestHarness { |
121 protected: | 127 protected: |
122 PreviewsInfoBarDelegateUnitTest() | 128 PreviewsInfoBarDelegateUnitTest() |
123 : field_trial_list_(new base::FieldTrialList(nullptr)) {} | 129 : field_trial_list_(new base::FieldTrialList(nullptr)) {} |
124 | 130 |
125 void SetUp() override { | 131 void SetUp() override { |
126 ChromeRenderViewHostTestHarness::SetUp(); | 132 PageLoadMetricsObserverTestHarness::SetUp(); |
127 InfoBarService::CreateForWebContents(web_contents()); | 133 InfoBarService::CreateForWebContents(web_contents()); |
128 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents()); | 134 PreviewsInfoBarTabHelper::CreateForWebContents(web_contents()); |
129 TestPreviewsWebContentsObserver::CreateForWebContents(web_contents()); | 135 TestPreviewsWebContentsObserver::CreateForWebContents(web_contents()); |
130 | 136 |
131 drp_test_context_ = | 137 drp_test_context_ = |
132 data_reduction_proxy::DataReductionProxyTestContext::Builder() | 138 data_reduction_proxy::DataReductionProxyTestContext::Builder() |
133 .WithMockConfig() | 139 .WithMockConfig() |
134 .SkipSettingsInitialization() | 140 .SkipSettingsInitialization() |
135 .Build(); | 141 .Build(); |
136 | 142 |
(...skipping 10 matching lines...) Expand all Loading... |
147 data_reduction_proxy_settings->InitDataReductionProxySettings( | 153 data_reduction_proxy_settings->InitDataReductionProxySettings( |
148 drp_test_context_->io_data(), drp_test_context_->pref_service(), | 154 drp_test_context_->io_data(), drp_test_context_->pref_service(), |
149 drp_test_context_->request_context_getter(), | 155 drp_test_context_->request_context_getter(), |
150 base::WrapUnique(new data_reduction_proxy::DataStore()), | 156 base::WrapUnique(new data_reduction_proxy::DataStore()), |
151 base::ThreadTaskRunnerHandle::Get(), | 157 base::ThreadTaskRunnerHandle::Get(), |
152 base::ThreadTaskRunnerHandle::Get()); | 158 base::ThreadTaskRunnerHandle::Get()); |
153 | 159 |
154 TestingBrowserProcess::GetGlobal()->SetLocalState( | 160 TestingBrowserProcess::GetGlobal()->SetLocalState( |
155 drp_test_context_->pref_service()); | 161 drp_test_context_->pref_service()); |
156 network_time::NetworkTimeTracker::RegisterPrefs(registry); | 162 network_time::NetworkTimeTracker::RegisterPrefs(registry); |
| 163 |
| 164 TestingBrowserProcess::GetGlobal()->SetUkmRecorder(&test_ukm_recorder_); |
157 } | 165 } |
158 | 166 |
159 void TearDown() override { | 167 void TearDown() override { |
160 drp_test_context_->DestroySettings(); | 168 drp_test_context_->DestroySettings(); |
161 ChromeRenderViewHostTestHarness::TearDown(); | 169 ChromeRenderViewHostTestHarness::TearDown(); |
162 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); | 170 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); |
163 } | 171 } |
164 | 172 |
165 PreviewsInfoBarDelegate* CreateInfoBar(previews::PreviewsType type, | 173 PreviewsInfoBarDelegate* CreateInfoBar(previews::PreviewsType type, |
166 base::Time previews_freshness, | 174 base::Time previews_freshness, |
(...skipping 30 matching lines...) Expand all Loading... |
197 scoped_feature_list_.InitWithFeatureList(std::move(feature_list)); | 205 scoped_feature_list_.InitWithFeatureList(std::move(feature_list)); |
198 } | 206 } |
199 | 207 |
200 void OnDismissPreviewsInfobar(bool user_opt_out) { | 208 void OnDismissPreviewsInfobar(bool user_opt_out) { |
201 user_opt_out_ = user_opt_out; | 209 user_opt_out_ = user_opt_out; |
202 } | 210 } |
203 | 211 |
204 InfoBarService* infobar_service() { | 212 InfoBarService* infobar_service() { |
205 return InfoBarService::FromWebContents(web_contents()); | 213 return InfoBarService::FromWebContents(web_contents()); |
206 } | 214 } |
| 215 size_t ukm_source_count() { return test_ukm_recorder_.sources_count(); } |
| 216 |
| 217 size_t ukm_entry_count() { return test_ukm_recorder_.entries_count(); } |
| 218 |
| 219 const ukm::UkmSource* GetUkmSourceForUrl(const char* url) { |
| 220 return test_ukm_recorder_.GetSourceForUrl(url); |
| 221 } |
| 222 |
| 223 const ukm::mojom::UkmEntry* GetUkmEntry(size_t entry_index) { |
| 224 return test_ukm_recorder_.GetEntry(entry_index); |
| 225 } |
| 226 |
| 227 std::vector<const ukm::mojom::UkmEntry*> GetUkmEntriesForSourceID( |
| 228 ukm::SourceId source_id) { |
| 229 std::vector<const ukm::mojom::UkmEntry*> entries; |
| 230 for (size_t i = 0; i < ukm_entry_count(); ++i) { |
| 231 const ukm::mojom::UkmEntry* entry = GetUkmEntry(i); |
| 232 if (entry->source_id == source_id) |
| 233 entries.push_back(entry); |
| 234 } |
| 235 return entries; |
| 236 } |
| 237 |
| 238 ukm::mojom::UkmEntryPtr GetMergedEntry( |
| 239 const std::vector<const ukm::mojom::UkmEntry*>& entries) { |
| 240 ukm::mojom::UkmEntryPtr merged_entry = ukm::mojom::UkmEntry::New(); |
| 241 for (const auto* entry : entries) { |
| 242 if (merged_entry->event_hash) { |
| 243 EXPECT_EQ(merged_entry->source_id, entry->source_id); |
| 244 EXPECT_EQ(merged_entry->event_hash, entry->event_hash); |
| 245 } else { |
| 246 merged_entry->event_hash = entry->event_hash; |
| 247 merged_entry->source_id = entry->source_id; |
| 248 } |
| 249 for (const auto& metric : entry->metrics) { |
| 250 merged_entry->metrics.emplace_back(metric->Clone()); |
| 251 } |
| 252 } |
| 253 return merged_entry; |
| 254 } |
| 255 |
| 256 ukm::mojom::UkmEntryPtr GetMergedEntryForSourceID(ukm::SourceId source_id) { |
| 257 ukm::mojom::UkmEntryPtr entry = |
| 258 GetMergedEntry(GetUkmEntriesForSourceID(source_id)); |
| 259 return entry; |
| 260 } |
| 261 |
| 262 void ExpectOptOutUKM(bool expect, ukm::SourceId source_id) { |
| 263 ukm::mojom::UkmEntryPtr entry = GetMergedEntryForSourceID(source_id); |
| 264 const ukm::mojom::UkmMetric* metric = |
| 265 ukm::TestUkmRecorder::FindMetric(entry.get(), "opt_out"); |
| 266 if (!expect) { |
| 267 EXPECT_FALSE(metric); |
| 268 } else { |
| 269 EXPECT_EQ(entry->source_id, source_id); |
| 270 EXPECT_TRUE(metric->value); |
| 271 EXPECT_EQ(entry->event_hash, base::HashMetricName("Previews")); |
| 272 } |
| 273 } |
207 | 274 |
208 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> | 275 std::unique_ptr<data_reduction_proxy::DataReductionProxyTestContext> |
209 drp_test_context_; | 276 drp_test_context_; |
210 | 277 |
211 base::Optional<bool> user_opt_out_; | 278 base::Optional<bool> user_opt_out_; |
212 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 279 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
213 base::test::ScopedFeatureList scoped_feature_list_; | 280 base::test::ScopedFeatureList scoped_feature_list_; |
| 281 |
| 282 ukm::TestUkmRecorder test_ukm_recorder_; |
214 }; | 283 }; |
215 | 284 |
216 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { | 285 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestNavigationDismissal) { |
217 base::HistogramTester tester; | 286 base::HistogramTester tester; |
218 | 287 |
219 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 288 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
220 true /* is_data_saver_user */); | 289 true /* is_data_saver_user */); |
221 | 290 |
222 // Try showing a second infobar. Another should not be shown since the page | 291 // Try showing a second infobar. Another should not be shown since the page |
223 // has not navigated. | 292 // has not navigated. |
(...skipping 30 matching lines...) Expand all Loading... |
254 web_contents(), previews::PreviewsType::LOFI, | 323 web_contents(), previews::PreviewsType::LOFI, |
255 base::Time() /* previews_freshness */, true /* is_data_saver_user */, | 324 base::Time() /* previews_freshness */, true /* is_data_saver_user */, |
256 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 325 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); |
257 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 326 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
258 | 327 |
259 // Navigate to test URL as a reload to dismiss the infobar. | 328 // Navigate to test URL as a reload to dismiss the infobar. |
260 controller().LoadURL(GURL(kTestUrl), content::Referrer(), | 329 controller().LoadURL(GURL(kTestUrl), content::Referrer(), |
261 ui::PAGE_TRANSITION_RELOAD, std::string()); | 330 ui::PAGE_TRANSITION_RELOAD, std::string()); |
262 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 331 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
263 | 332 |
| 333 ukm::SourceId source_id = |
| 334 page_load_metrics::MetricsWebContentsObserver::FromWebContents( |
| 335 web_contents()) |
| 336 ->GetUKMSourceForCommittedLoad() |
| 337 .value(); |
| 338 |
264 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 339 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
265 EXPECT_FALSE(user_opt_out_.value()); | 340 EXPECT_FALSE(user_opt_out_.value()); |
266 | 341 |
267 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, | 342 tester.ExpectBucketCount(kUMAPreviewsInfoBarActionLoFi, |
268 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD, | 343 PreviewsInfoBarDelegate::INFOBAR_DISMISSED_BY_RELOAD, |
269 1); | 344 1); |
270 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( | 345 EXPECT_EQ(0, drp_test_context_->pref_service()->GetInteger( |
271 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 346 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
272 | 347 |
273 auto* data_reduction_proxy_settings = | 348 auto* data_reduction_proxy_settings = |
274 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 349 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
275 web_contents()->GetBrowserContext()); | 350 web_contents()->GetBrowserContext()); |
276 | 351 |
277 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() | 352 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
278 ->pingback_client() | 353 ->pingback_client() |
279 ->OptOutsSizeForTesting()); | 354 ->OptOutsSizeForTesting()); |
| 355 |
| 356 ExpectOptOutUKM(false, source_id); |
280 } | 357 } |
281 | 358 |
282 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { | 359 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestUserDismissal) { |
283 base::HistogramTester tester; | 360 base::HistogramTester tester; |
284 | 361 |
285 ConfirmInfoBarDelegate* infobar = | 362 ConfirmInfoBarDelegate* infobar = |
286 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 363 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
287 true /* is_data_saver_user */); | 364 true /* is_data_saver_user */); |
288 | 365 |
289 // Simulate dismissing the infobar. | 366 // Simulate dismissing the infobar. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 field_trial_list_.reset(); | 406 field_trial_list_.reset(); |
330 field_trial_list_.reset(new base::FieldTrialList(nullptr)); | 407 field_trial_list_.reset(new base::FieldTrialList(nullptr)); |
331 if (test.using_previews_blacklist) { | 408 if (test.using_previews_blacklist) { |
332 base::FieldTrialList::CreateFieldTrial( | 409 base::FieldTrialList::CreateFieldTrial( |
333 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); | 410 "DataReductionProxyPreviewsBlackListTransition", "Enabled_"); |
334 } | 411 } |
335 base::HistogramTester tester; | 412 base::HistogramTester tester; |
336 // Call Reload and CommitPendingNavigation to force DidFinishNavigation. | 413 // Call Reload and CommitPendingNavigation to force DidFinishNavigation. |
337 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); | 414 web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); |
338 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 415 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 416 ukm::SourceId source_id = |
| 417 page_load_metrics::MetricsWebContentsObserver::FromWebContents( |
| 418 web_contents()) |
| 419 ->GetUKMSourceForCommittedLoad() |
| 420 .value(); |
339 | 421 |
340 ConfirmInfoBarDelegate* infobar = | 422 ConfirmInfoBarDelegate* infobar = |
341 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 423 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
342 true /* is_data_saver_user */); | 424 true /* is_data_saver_user */); |
343 | 425 |
344 // Simulate clicking the infobar link. | 426 // Simulate clicking the infobar link. |
345 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 427 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
346 infobar_service()->infobar_at(0)->RemoveSelf(); | 428 infobar_service()->infobar_at(0)->RemoveSelf(); |
347 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 429 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
348 | 430 |
349 tester.ExpectBucketCount( | 431 tester.ExpectBucketCount( |
350 kUMAPreviewsInfoBarActionLoFi, | 432 kUMAPreviewsInfoBarActionLoFi, |
351 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); | 433 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); |
352 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1, | 434 EXPECT_EQ(test.using_previews_blacklist ? 0 : 1, |
353 drp_test_context_->pref_service()->GetInteger( | 435 drp_test_context_->pref_service()->GetInteger( |
354 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); | 436 data_reduction_proxy::prefs::kLoFiLoadImagesPerSession)); |
355 EXPECT_TRUE(user_opt_out_.value()); | 437 EXPECT_TRUE(user_opt_out_.value()); |
356 | 438 |
357 auto* data_reduction_proxy_settings = | 439 auto* data_reduction_proxy_settings = |
358 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 440 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
359 web_contents()->GetBrowserContext()); | 441 web_contents()->GetBrowserContext()); |
360 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() | 442 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
361 ->pingback_client() | 443 ->pingback_client() |
362 ->OptOutsSizeForTesting()); | 444 ->OptOutsSizeForTesting()); |
| 445 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
| 446 ->pingback_client() |
| 447 ->OptOutsSizeForTesting()); |
| 448 |
| 449 ExpectOptOutUKM(true, source_id); |
363 } | 450 } |
364 } | 451 } |
365 | 452 |
366 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { | 453 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestClickLinkLitePage) { |
367 base::HistogramTester tester; | 454 base::HistogramTester tester; |
368 | 455 |
369 NavigateAndCommit(GURL(kTestUrl)); | 456 NavigateAndCommit(GURL(kTestUrl)); |
| 457 ukm::SourceId source_id = |
| 458 page_load_metrics::MetricsWebContentsObserver::FromWebContents( |
| 459 web_contents()) |
| 460 ->GetUKMSourceForCommittedLoad() |
| 461 .value(); |
370 | 462 |
371 ConfirmInfoBarDelegate* infobar = | 463 ConfirmInfoBarDelegate* infobar = |
372 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), | 464 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), |
373 true /* is_data_saver_user */); | 465 true /* is_data_saver_user */); |
374 | 466 |
375 // Simulate clicking the infobar link. | 467 // Simulate clicking the infobar link. |
376 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 468 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
377 infobar_service()->infobar_at(0)->RemoveSelf(); | 469 infobar_service()->infobar_at(0)->RemoveSelf(); |
378 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 470 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
379 | 471 |
380 tester.ExpectBucketCount( | 472 tester.ExpectBucketCount( |
381 kUMAPreviewsInfoBarActionLitePage, | 473 kUMAPreviewsInfoBarActionLitePage, |
382 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); | 474 PreviewsInfoBarDelegate::INFOBAR_LOAD_ORIGINAL_CLICKED, 1); |
383 | 475 |
384 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 476 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
385 | 477 |
386 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, | 478 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, |
387 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 479 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
388 ->last_navigation_reload_type()); | 480 ->last_navigation_reload_type()); |
389 | 481 |
390 auto* data_reduction_proxy_settings = | 482 auto* data_reduction_proxy_settings = |
391 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 483 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
392 web_contents()->GetBrowserContext()); | 484 web_contents()->GetBrowserContext()); |
393 | 485 |
394 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() | 486 EXPECT_EQ(1u, data_reduction_proxy_settings->data_reduction_proxy_service() |
395 ->pingback_client() | 487 ->pingback_client() |
396 ->OptOutsSizeForTesting()); | 488 ->OptOutsSizeForTesting()); |
| 489 ExpectOptOutUKM(true, source_id); |
397 } | 490 } |
398 | 491 |
399 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) { | 492 TEST_F(PreviewsInfoBarDelegateUnitTest, InfobarTestShownOncePerNavigation) { |
400 ConfirmInfoBarDelegate* infobar = | 493 ConfirmInfoBarDelegate* infobar = |
401 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), | 494 CreateInfoBar(previews::PreviewsType::LOFI, base::Time(), |
402 true /* is_data_saver_user */); | 495 true /* is_data_saver_user */); |
403 | 496 |
404 // Simulate dismissing the infobar. | 497 // Simulate dismissing the infobar. |
405 infobar->InfoBarDismissed(); | 498 infobar->InfoBarDismissed(); |
406 infobar_service()->infobar_at(0)->RemoveSelf(); | 499 infobar_service()->infobar_at(0)->RemoveSelf(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 #endif | 615 #endif |
523 } | 616 } |
524 | 617 |
525 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) { | 618 TEST_F(PreviewsInfoBarDelegateUnitTest, OfflineInfobarDisablesLoFi) { |
526 base::HistogramTester tester; | 619 base::HistogramTester tester; |
527 | 620 |
528 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 621 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
529 ->set_should_have_page_id(false); | 622 ->set_should_have_page_id(false); |
530 | 623 |
531 NavigateAndCommit(GURL(kTestUrl)); | 624 NavigateAndCommit(GURL(kTestUrl)); |
| 625 ukm::SourceId source_id = |
| 626 page_load_metrics::MetricsWebContentsObserver::FromWebContents( |
| 627 web_contents()) |
| 628 ->GetUKMSourceForCommittedLoad() |
| 629 .value(); |
532 | 630 |
533 ConfirmInfoBarDelegate* infobar = | 631 ConfirmInfoBarDelegate* infobar = |
534 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), | 632 CreateInfoBar(previews::PreviewsType::OFFLINE, base::Time(), |
535 true /* is_data_saver_user */); | 633 true /* is_data_saver_user */); |
536 | 634 |
537 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, | 635 tester.ExpectUniqueSample(kUMAPreviewsInfoBarActionOffline, |
538 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); | 636 PreviewsInfoBarDelegate::INFOBAR_SHOWN, 1); |
539 | 637 |
540 // Simulate clicking the infobar link. | 638 // Simulate clicking the infobar link. |
541 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) | 639 if (infobar->LinkClicked(WindowOpenDisposition::CURRENT_TAB)) |
542 infobar_service()->infobar_at(0)->RemoveSelf(); | 640 infobar_service()->infobar_at(0)->RemoveSelf(); |
543 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 641 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
544 | 642 |
545 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 643 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
546 | 644 |
547 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, | 645 EXPECT_EQ(content::ReloadType::DISABLE_LOFI_MODE, |
548 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) | 646 TestPreviewsWebContentsObserver::FromWebContents(web_contents()) |
549 ->last_navigation_reload_type()); | 647 ->last_navigation_reload_type()); |
550 | 648 |
551 auto* data_reduction_proxy_settings = | 649 auto* data_reduction_proxy_settings = |
552 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 650 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
553 web_contents()->GetBrowserContext()); | 651 web_contents()->GetBrowserContext()); |
554 | 652 |
555 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() | 653 EXPECT_EQ(0u, data_reduction_proxy_settings->data_reduction_proxy_service() |
556 ->pingback_client() | 654 ->pingback_client() |
557 ->OptOutsSizeForTesting()); | 655 ->OptOutsSizeForTesting()); |
| 656 |
| 657 ExpectOptOutUKM(false, source_id); |
558 } | 658 } |
559 | 659 |
560 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) { | 660 TEST_F(PreviewsInfoBarDelegateUnitTest, PingbackClientClearedTabClosed) { |
561 base::HistogramTester tester; | 661 base::HistogramTester tester; |
562 | 662 |
563 NavigateAndCommit(GURL(kTestUrl)); | 663 NavigateAndCommit(GURL(kTestUrl)); |
564 | 664 |
565 ConfirmInfoBarDelegate* infobar = | 665 ConfirmInfoBarDelegate* infobar = |
566 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), | 666 CreateInfoBar(previews::PreviewsType::LITE_PAGE, base::Time(), |
567 true /* is_data_saver_user */); | 667 true /* is_data_saver_user */); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 | 745 |
646 PreviewsInfoBarDelegate* infobar = CreateInfoBar( | 746 PreviewsInfoBarDelegate* infobar = CreateInfoBar( |
647 previews::PreviewsType::LITE_PAGE, | 747 previews::PreviewsType::LITE_PAGE, |
648 base::Time::Now() - base::TimeDelta::FromHours(staleness_in_hours), | 748 base::Time::Now() - base::TimeDelta::FromHours(staleness_in_hours), |
649 true /* is_data_saver_user */); | 749 true /* is_data_saver_user */); |
650 | 750 |
651 ASSERT_EQ(l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, | 751 ASSERT_EQ(l10n_util::GetStringFUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, |
652 base::IntToString16(staleness_in_hours)), | 752 base::IntToString16(staleness_in_hours)), |
653 infobar->GetTimestampText()); | 753 infobar->GetTimestampText()); |
654 } | 754 } |
OLD | NEW |