| 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/android/offline_pages/background_loader_offliner.h" | 5 #include "chrome/browser/android/offline_pages/background_loader_offliner.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
| 10 #include "base/test/scoped_feature_list.h" |
| 10 #include "base/test/scoped_mock_time_message_loop_task_runner.h" | 11 #include "base/test/scoped_mock_time_message_loop_task_runner.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "chrome/browser/android/offline_pages/offliner_helper.h" | 13 #include "chrome/browser/android/offline_pages/offliner_helper.h" |
| 13 #include "chrome/browser/net/prediction_options.h" | 14 #include "chrome/browser/net/prediction_options.h" |
| 14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "components/content_settings/core/common/pref_names.h" | 17 #include "components/content_settings/core/common/pref_names.h" |
| 17 #include "components/offline_pages/content/background_loader/background_loader_c
ontents_stub.h" | 18 #include "components/offline_pages/content/background_loader/background_loader_c
ontents_stub.h" |
| 18 #include "components/offline_pages/core/background/offliner.h" | 19 #include "components/offline_pages/core/background/offliner.h" |
| 19 #include "components/offline_pages/core/background/offliner_policy.h" | 20 #include "components/offline_pages/core/background/offliner_policy.h" |
| 20 #include "components/offline_pages/core/background/save_page_request.h" | 21 #include "components/offline_pages/core/background/save_page_request.h" |
| 22 #include "components/offline_pages/core/offline_page_feature.h" |
| 21 #include "components/offline_pages/core/stub_offline_page_model.h" | 23 #include "components/offline_pages/core/stub_offline_page_model.h" |
| 22 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
| 25 #include "content/public/browser/mhtml_extra_parts.h" |
| 23 #include "content/public/browser/navigation_handle.h" | 26 #include "content/public/browser/navigation_handle.h" |
| 24 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
| 26 #include "content/public/test/web_contents_tester.h" | 29 #include "content/public/test/web_contents_tester.h" |
| 27 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 32 |
| 30 namespace offline_pages { | 33 namespace offline_pages { |
| 31 | 34 |
| 32 namespace { | 35 namespace { |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 kUserRequested); | 556 kUserRequested); |
| 554 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), | 557 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), |
| 555 progress_callback())); | 558 progress_callback())); |
| 556 // Sets lowbar. | 559 // Sets lowbar. |
| 557 offliner()->DocumentAvailableInMainFrame(); | 560 offliner()->DocumentAvailableInMainFrame(); |
| 558 // Timeout | 561 // Timeout |
| 559 EXPECT_FALSE(offliner()->HandleTimeout(request)); | 562 EXPECT_FALSE(offliner()->HandleTimeout(request)); |
| 560 EXPECT_FALSE(SaveInProgress()); | 563 EXPECT_FALSE(SaveInProgress()); |
| 561 } | 564 } |
| 562 | 565 |
| 566 TEST_F(BackgroundLoaderOfflinerTest, SignalCollectionDisabled) { |
| 567 // Ensure feature flag for Signal collection is off, |
| 568 EXPECT_FALSE(offline_pages::IsOfflinePagesLoadSignalCollectingEnabled()); |
| 569 |
| 570 base::Time creation_time = base::Time::Now(); |
| 571 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, |
| 572 kUserRequested); |
| 573 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), |
| 574 progress_callback())); |
| 575 |
| 576 CompleteLoading(); |
| 577 PumpLoop(); |
| 578 |
| 579 // No extra parts should be added if the flag is off. |
| 580 content::MHTMLExtraParts* extra_parts = |
| 581 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents()); |
| 582 EXPECT_EQ(extra_parts->size(), 0); |
| 583 } |
| 584 |
| 585 TEST_F(BackgroundLoaderOfflinerTest, SignalCollectionEnabled) { |
| 586 // Ensure feature flag for signal collection is on. |
| 587 base::test::ScopedFeatureList scoped_feature_list; |
| 588 scoped_feature_list.InitAndEnableFeature( |
| 589 kOfflinePagesLoadSignalCollectingFeature); |
| 590 EXPECT_TRUE(IsOfflinePagesLoadSignalCollectingEnabled()); |
| 591 |
| 592 base::Time creation_time = base::Time::Now(); |
| 593 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, |
| 594 kUserRequested); |
| 595 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), |
| 596 progress_callback())); |
| 597 |
| 598 CompleteLoading(); |
| 599 PumpLoop(); |
| 600 |
| 601 // One extra part should be added if the flag is on. |
| 602 content::MHTMLExtraParts* extra_parts = |
| 603 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents()); |
| 604 EXPECT_EQ(extra_parts->size(), 1); |
| 605 } |
| 606 |
| 563 } // namespace offline_pages | 607 } // namespace offline_pages |
| OLD | NEW |