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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_tab_helper_unittest.cc

Issue 2166363003: Offline pages using NQE 2G Slow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tbansal nits (switching to consuming previews component) Created 4 years, 4 months 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/android/offline_pages/offline_page_tab_helper.h" 5 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/metrics/field_trial.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "base/test/histogram_tester.h" 16 #include "base/test/histogram_tester.h"
17 #include "base/test/simple_test_clock.h"
18 #include "base/time/clock.h"
19 #include "base/time/time.h"
16 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 20 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
17 #include "chrome/browser/android/offline_pages/offline_page_utils.h" 21 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
18 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h " 22 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h "
23 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
24 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
26 #include "chrome/test/base/testing_profile.h"
20 #include "components/offline_pages/client_namespace_constants.h" 27 #include "components/offline_pages/client_namespace_constants.h"
21 #include "components/offline_pages/offline_page_feature.h" 28 #include "components/offline_pages/offline_page_feature.h"
22 #include "components/offline_pages/offline_page_item.h" 29 #include "components/offline_pages/offline_page_item.h"
23 #include "components/offline_pages/offline_page_model.h" 30 #include "components/offline_pages/offline_page_model.h"
24 #include "components/offline_pages/offline_page_test_archiver.h" 31 #include "components/offline_pages/offline_page_test_archiver.h"
25 #include "components/offline_pages/offline_page_types.h" 32 #include "components/offline_pages/offline_page_types.h"
33 #include "components/variations/variations_associated_data.h"
26 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
27 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
28 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
29 #include "net/base/network_change_notifier.h" 37 #include "net/base/network_change_notifier.h"
38 #include "net/nqe/network_quality_estimator.h"
30 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
31 40
32 namespace offline_pages { 41 namespace offline_pages {
33 42
34 namespace { 43 namespace {
35 44
36 const GURL kTestPageUrl("http://test.org/page1"); 45 const GURL kTestPageUrl("http://test.org/page1");
37 const ClientId kTestClientId = ClientId(kBookmarkNamespace, "1234"); 46 const ClientId kTestClientId = ClientId(kBookmarkNamespace, "1234");
38 const int64_t kTestFileSize = 876543LL; 47 const int64_t kTestFileSize = 876543LL;
39 const char kRedirectResultHistogram[] = "OfflinePages.RedirectResult"; 48 const char kRedirectResultHistogram[] = "OfflinePages.RedirectResult";
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 RunUntilIdle(); 353 RunUntilIdle();
345 354
346 const OfflinePageItem* item = 355 const OfflinePageItem* item =
347 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); 356 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents());
348 EXPECT_EQ(expected_offline_id, item->offline_id); 357 EXPECT_EQ(expected_offline_id, item->offline_id);
349 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); 358 EXPECT_EQ(expected_offline_url, item->GetOfflineURL());
350 EXPECT_EQ(kLastNNamespace, item->client_id.name_space); 359 EXPECT_EQ(kLastNNamespace, item->client_id.name_space);
351 EXPECT_EQ(kTabId, item->client_id.id); 360 EXPECT_EQ(kTabId, item->client_id.id);
352 } 361 }
353 362
363 TEST_F(OfflinePageTabHelperTest, PageFor2GSlow) {
364 SimulateHasNetworkConnectivity(true);
365 TestingProfile* test_profile = profile();
366 UINetworkQualityEstimatorService* nqe_service =
367 UINetworkQualityEstimatorServiceFactory::GetForProfile(test_profile);
368 nqe_service->SetEffectiveConnectionTypeForTesting(
369 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
370
371 base::SimpleTestClock* clock = new base::SimpleTestClock();
372 clock->SetNow(base::Time::Now());
373 offline_page_tab_helper()->SetClockForTesting(base::WrapUnique(clock));
374
375 StartLoad(kTestPageUrl);
376 // Gives a chance to run delayed task to do redirection.
377 RunUntilIdle();
378
379 // This is not included in the field trial, so it should not cause a redirect.
380 const OfflinePageItem* item =
381 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents());
382 EXPECT_EQ(nullptr, item);
383
384 // Enable the field trial for using 2G slow.
385 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.
386 params["show_offline_pages"] = "1";
tbansal1 2016/07/26 20:12:48 s/1/true/
RyanSturm 2016/07/26 21:48:13 Acknowledged.
387 ASSERT_TRUE(variations::AssociateVariationParams(
388 "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.
389 base::FieldTrialList field_trial_list(nullptr);
390 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
391 "DataReductionProxyClientSideExperimentsFieldTrial", "Enabled"));
392
393 StartLoad(kTestPageUrl);
394 // Gives a chance to run delayed task to do redirection.
395 RunUntilIdle();
396
397 // This page should be fresh enough to cause a redirect.
398 item = OfflinePageUtils::GetOfflinePageFromWebContents(web_contents());
399 EXPECT_EQ(offline_url(), item->GetOfflineURL());
400 EXPECT_EQ(online_url(), item->url);
401
402 clock->Advance(base::TimeDelta::FromDays(2));
403 StartLoad(kTestPageUrl);
404 // Gives a chance to run delayed task to do redirection.
405 RunUntilIdle();
406
407 // This page should not be fresh enough to cause a redirect.
408 item = OfflinePageUtils::GetOfflinePageFromWebContents(web_contents());
409 EXPECT_EQ(nullptr, item);
410 }
411
354 // This test saves another copy of page from Async Loading namespace 412 // This test saves another copy of page from Async Loading namespace
355 // and verifies it is redirected to it (as it is more recent). 413 // and verifies it is redirected to it (as it is more recent).
356 TEST_F(OfflinePageTabHelperTest, SwitchToOfflineAsyncLoadedPageOnNoNetwork) { 414 TEST_F(OfflinePageTabHelperTest, SwitchToOfflineAsyncLoadedPageOnNoNetwork) {
357 // Saves an offline page. 415 // Saves an offline page.
358 OfflinePageModel* model = 416 OfflinePageModel* model =
359 OfflinePageModelFactory::GetForBrowserContext(browser_context()); 417 OfflinePageModelFactory::GetForBrowserContext(browser_context());
360 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( 418 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
361 kTestPageUrl, 419 kTestPageUrl,
362 base::FilePath(FILE_PATH_LITERAL("AsyncLoadedPage.mhtml")))); 420 base::FilePath(FILE_PATH_LITERAL("AsyncLoadedPage.mhtml"))));
363 421
(...skipping 12 matching lines...) Expand all
376 RunUntilIdle(); 434 RunUntilIdle();
377 435
378 const OfflinePageItem* item = 436 const OfflinePageItem* item =
379 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); 437 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents());
380 EXPECT_EQ(expected_offline_id, item->offline_id); 438 EXPECT_EQ(expected_offline_id, item->offline_id);
381 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); 439 EXPECT_EQ(expected_offline_url, item->GetOfflineURL());
382 EXPECT_EQ(kAsyncNamespace, item->client_id.name_space); 440 EXPECT_EQ(kAsyncNamespace, item->client_id.name_space);
383 } 441 }
384 442
385 } // namespace offline_pages 443 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698