Chromium Code Reviews| Index: chrome/browser/android/offline_pages/offline_page_tab_helper_unittest.cc |
| diff --git a/chrome/browser/android/offline_pages/offline_page_tab_helper_unittest.cc b/chrome/browser/android/offline_pages/offline_page_tab_helper_unittest.cc |
| index 919ddbff6b14278ddf244b520feefa599dd95dc7..7de6fcefb2cab4b99a1841f662d816eba1ceff33 100644 |
| --- a/chrome/browser/android/offline_pages/offline_page_tab_helper_unittest.cc |
| +++ b/chrome/browser/android/offline_pages/offline_page_tab_helper_unittest.cc |
| @@ -4,36 +4,45 @@ |
| #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
| #include <memory> |
| #include "base/bind.h" |
| #include "base/feature_list.h" |
| #include "base/files/file_path.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "base/metrics/field_trial.h" |
| #include "base/run_loop.h" |
| #include "base/test/histogram_tester.h" |
| +#include "base/test/simple_test_clock.h" |
| +#include "base/time/clock.h" |
| +#include "base/time/time.h" |
| #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
| #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h" |
| +#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" |
| +#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| +#include "chrome/test/base/testing_profile.h" |
| #include "components/offline_pages/client_namespace_constants.h" |
| #include "components/offline_pages/offline_page_feature.h" |
| #include "components/offline_pages/offline_page_item.h" |
| #include "components/offline_pages/offline_page_model.h" |
| #include "components/offline_pages/offline_page_test_archiver.h" |
| #include "components/offline_pages/offline_page_types.h" |
| +#include "components/variations/variations_associated_data.h" |
| #include "content/public/browser/navigation_entry.h" |
| #include "content/public/browser/web_contents.h" |
| #include "net/base/net_errors.h" |
| #include "net/base/network_change_notifier.h" |
| +#include "net/nqe/network_quality_estimator.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace offline_pages { |
| namespace { |
| const GURL kTestPageUrl("http://test.org/page1"); |
| const ClientId kTestClientId = ClientId(kBookmarkNamespace, "1234"); |
| const int64_t kTestFileSize = 876543LL; |
| const char kRedirectResultHistogram[] = "OfflinePages.RedirectResult"; |
| @@ -344,20 +353,69 @@ TEST_F(OfflinePageTabHelperTest, SelectBestPageForCurrentTab) { |
| RunUntilIdle(); |
| const OfflinePageItem* item = |
| OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| EXPECT_EQ(expected_offline_id, item->offline_id); |
| EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); |
| EXPECT_EQ(kLastNNamespace, item->client_id.name_space); |
| EXPECT_EQ(kTabId, item->client_id.id); |
| } |
| +TEST_F(OfflinePageTabHelperTest, PageFor2GSlow) { |
| + SimulateHasNetworkConnectivity(true); |
| + TestingProfile* test_profile = profile(); |
| + UINetworkQualityEstimatorService* nqe_service = |
| + UINetworkQualityEstimatorServiceFactory::GetForProfile(test_profile); |
| + nqe_service->SetEffectiveConnectionTypeForTesting( |
| + net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
| + |
| + base::SimpleTestClock* clock = new base::SimpleTestClock(); |
| + clock->SetNow(base::Time::Now()); |
| + offline_page_tab_helper()->SetClockForTesting(base::WrapUnique(clock)); |
| + |
| + StartLoad(kTestPageUrl); |
| + // Gives a chance to run delayed task to do redirection. |
| + RunUntilIdle(); |
| + |
| + // This is not included in the field trial, so it should not cause a redirect. |
| + const OfflinePageItem* item = |
| + OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| + EXPECT_EQ(nullptr, item); |
| + |
| + // Enable the field trial for using 2G slow. |
| + std::map<std::string, std::string> params; |
|
tbansal1
2016/07/26 20:12:48
#include <map>
#include <string>
RyanSturm
2016/07/26 21:48:13
Acknowledged.
|
| + params["show_offline_pages"] = "1"; |
|
tbansal1
2016/07/26 20:12:48
s/1/true/
RyanSturm
2016/07/26 21:48:13
Acknowledged.
|
| + ASSERT_TRUE(variations::AssociateVariationParams( |
| + "DataReductionProxyClientSideExperimentsFieldTrial", "Enabled", params)); |
|
tbansal1
2016/07/26 20:12:48
You can expose this from the previews component, a
RyanSturm
2016/07/26 21:48:13
Done.
|
| + base::FieldTrialList field_trial_list(nullptr); |
| + ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| + "DataReductionProxyClientSideExperimentsFieldTrial", "Enabled")); |
| + |
| + StartLoad(kTestPageUrl); |
| + // Gives a chance to run delayed task to do redirection. |
| + RunUntilIdle(); |
| + |
| + // This page should be fresh enough to cause a redirect. |
| + item = OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| + EXPECT_EQ(offline_url(), item->GetOfflineURL()); |
| + EXPECT_EQ(online_url(), item->url); |
| + |
| + clock->Advance(base::TimeDelta::FromDays(2)); |
| + StartLoad(kTestPageUrl); |
| + // Gives a chance to run delayed task to do redirection. |
| + RunUntilIdle(); |
| + |
| + // This page should not be fresh enough to cause a redirect. |
| + item = OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| + EXPECT_EQ(nullptr, item); |
| +} |
| + |
| // This test saves another copy of page from Async Loading namespace |
| // and verifies it is redirected to it (as it is more recent). |
| TEST_F(OfflinePageTabHelperTest, SwitchToOfflineAsyncLoadedPageOnNoNetwork) { |
| // Saves an offline page. |
| OfflinePageModel* model = |
| OfflinePageModelFactory::GetForBrowserContext(browser_context()); |
| std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( |
| kTestPageUrl, |
| base::FilePath(FILE_PATH_LITERAL("AsyncLoadedPage.mhtml")))); |