| 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/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" |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 StartLoad(kTestPageUrl); | 361 StartLoad(kTestPageUrl); |
| 362 // Gives a chance to run delayed task to do redirection. | 362 // Gives a chance to run delayed task to do redirection. |
| 363 RunUntilIdle(); | 363 RunUntilIdle(); |
| 364 | 364 |
| 365 const OfflinePageItem* item = | 365 const OfflinePageItem* item = |
| 366 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); | 366 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| 367 EXPECT_EQ(expected_offline_id, item->offline_id); | 367 EXPECT_EQ(expected_offline_id, item->offline_id); |
| 368 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); | 368 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); |
| 369 EXPECT_EQ(kLastNNamespace, item->client_id.name_space); | 369 EXPECT_EQ(kLastNNamespace, item->client_id.name_space); |
| 370 EXPECT_EQ(base::IntToString(kTabId), item->client_id.id); | 370 EXPECT_EQ(base::IntToString(kTabId), item->client_id.id); |
| 371 EXPECT_FALSE(offline_page_tab_helper()->is_preview()); |
| 371 } | 372 } |
| 372 | 373 |
| 373 TEST_F(OfflinePageTabHelperTest, PageFor2GSlow) { | 374 TEST_F(OfflinePageTabHelperTest, PageFor2GSlow) { |
| 374 SimulateHasNetworkConnectivity(true); | 375 SimulateHasNetworkConnectivity(true); |
| 375 TestingProfile* test_profile = profile(); | 376 TestingProfile* test_profile = profile(); |
| 376 UINetworkQualityEstimatorService* nqe_service = | 377 UINetworkQualityEstimatorService* nqe_service = |
| 377 UINetworkQualityEstimatorServiceFactory::GetForProfile(test_profile); | 378 UINetworkQualityEstimatorServiceFactory::GetForProfile(test_profile); |
| 378 nqe_service->SetEffectiveConnectionTypeForTesting( | 379 nqe_service->SetEffectiveConnectionTypeForTesting( |
| 379 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); | 380 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
| 380 | 381 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 394 | 395 |
| 395 StartLoad(kTestPageUrl); | 396 StartLoad(kTestPageUrl); |
| 396 // Gives a chance to run delayed task to do redirection. | 397 // Gives a chance to run delayed task to do redirection. |
| 397 RunUntilIdle(); | 398 RunUntilIdle(); |
| 398 | 399 |
| 399 // This page should be fresh enough to cause a redirect. | 400 // This page should be fresh enough to cause a redirect. |
| 400 item = OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); | 401 item = OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| 401 EXPECT_EQ(offline_url(), item->GetOfflineURL()); | 402 EXPECT_EQ(offline_url(), item->GetOfflineURL()); |
| 402 EXPECT_EQ(online_url(), item->url); | 403 EXPECT_EQ(online_url(), item->url); |
| 403 | 404 |
| 405 EXPECT_TRUE(offline_page_tab_helper()->is_preview()); |
| 406 |
| 404 clock()->Advance(base::TimeDelta::FromDays(8)); | 407 clock()->Advance(base::TimeDelta::FromDays(8)); |
| 405 StartLoad(kTestPageUrl); | 408 StartLoad(kTestPageUrl); |
| 406 // Gives a chance to run delayed task to do redirection. | 409 // Gives a chance to run delayed task to do redirection. |
| 407 RunUntilIdle(); | 410 RunUntilIdle(); |
| 408 | 411 |
| 409 // This page should not be fresh enough to cause a redirect. | 412 // This page should not be fresh enough to cause a redirect. |
| 410 item = OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); | 413 item = OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| 411 EXPECT_EQ(nullptr, item); | 414 EXPECT_EQ(nullptr, item); |
| 415 EXPECT_FALSE(offline_page_tab_helper()->is_preview()); |
| 412 } | 416 } |
| 413 | 417 |
| 414 // This test saves another copy of page from Async Loading namespace | 418 // This test saves another copy of page from Async Loading namespace |
| 415 // and verifies it is redirected to it (as it is more recent). | 419 // and verifies it is redirected to it (as it is more recent). |
| 416 TEST_F(OfflinePageTabHelperTest, SwitchToOfflineAsyncLoadedPageOnNoNetwork) { | 420 TEST_F(OfflinePageTabHelperTest, SwitchToOfflineAsyncLoadedPageOnNoNetwork) { |
| 417 // Saves an offline page. | 421 // Saves an offline page. |
| 418 OfflinePageModel* model = | 422 OfflinePageModel* model = |
| 419 OfflinePageModelFactory::GetForBrowserContext(browser_context()); | 423 OfflinePageModelFactory::GetForBrowserContext(browser_context()); |
| 420 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( | 424 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( |
| 421 kTestPageUrl, | 425 kTestPageUrl, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 433 SimulateHasNetworkConnectivity(false); | 437 SimulateHasNetworkConnectivity(false); |
| 434 StartLoad(kTestPageUrl); | 438 StartLoad(kTestPageUrl); |
| 435 // Gives a chance to run delayed task to do redirection. | 439 // Gives a chance to run delayed task to do redirection. |
| 436 RunUntilIdle(); | 440 RunUntilIdle(); |
| 437 | 441 |
| 438 const OfflinePageItem* item = | 442 const OfflinePageItem* item = |
| 439 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); | 443 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| 440 EXPECT_EQ(expected_offline_id, item->offline_id); | 444 EXPECT_EQ(expected_offline_id, item->offline_id); |
| 441 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); | 445 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); |
| 442 EXPECT_EQ(kAsyncNamespace, item->client_id.name_space); | 446 EXPECT_EQ(kAsyncNamespace, item->client_id.name_space); |
| 447 EXPECT_FALSE(offline_page_tab_helper()->is_preview()); |
| 443 } | 448 } |
| 444 | 449 |
| 445 } // namespace offline_pages | 450 } // namespace offline_pages |
| OLD | NEW |