| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( | 165 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( |
| 166 browser_context(), BuildTestOfflinePageModel); | 166 browser_context(), BuildTestOfflinePageModel); |
| 167 RunUntilIdle(); | 167 RunUntilIdle(); |
| 168 | 168 |
| 169 // Saves an offline page. | 169 // Saves an offline page. |
| 170 OfflinePageModel* model = | 170 OfflinePageModel* model = |
| 171 OfflinePageModelFactory::GetForBrowserContext(browser_context()); | 171 OfflinePageModelFactory::GetForBrowserContext(browser_context()); |
| 172 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( | 172 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( |
| 173 kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); | 173 kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); |
| 174 model->SavePage( | 174 model->SavePage( |
| 175 kTestPageUrl, kTestClientId, std::move(archiver), | 175 kTestPageUrl, kTestClientId, 0ul, std::move(archiver), |
| 176 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); | 176 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); |
| 177 RunUntilIdle(); | 177 RunUntilIdle(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void OfflinePageTabHelperTest::TearDown() { | 180 void OfflinePageTabHelperTest::TearDown() { |
| 181 content::RenderViewHostTestHarness::TearDown(); | 181 content::RenderViewHostTestHarness::TearDown(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void OfflinePageTabHelperTest::RunUntilIdle() { | 184 void OfflinePageTabHelperTest::RunUntilIdle() { |
| 185 base::RunLoop().RunUntilIdle(); | 185 base::RunLoop().RunUntilIdle(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 TEST_F(OfflinePageTabHelperTest, SelectBestPageForCurrentTab) { | 336 TEST_F(OfflinePageTabHelperTest, SelectBestPageForCurrentTab) { |
| 337 // Saves an offline page. | 337 // Saves an offline page. |
| 338 OfflinePageModel* model = | 338 OfflinePageModel* model = |
| 339 OfflinePageModelFactory::GetForBrowserContext(browser_context()); | 339 OfflinePageModelFactory::GetForBrowserContext(browser_context()); |
| 340 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( | 340 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( |
| 341 kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page2.mhtml")))); | 341 kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page2.mhtml")))); |
| 342 | 342 |
| 343 // We expect this copy to be used later. | 343 // We expect this copy to be used later. |
| 344 ClientId client_id(kLastNNamespace, base::IntToString(kTabId)); | 344 ClientId client_id(kLastNNamespace, base::IntToString(kTabId)); |
| 345 model->SavePage( | 345 model->SavePage( |
| 346 kTestPageUrl, client_id, std::move(archiver), | 346 kTestPageUrl, client_id, 0ul, std::move(archiver), |
| 347 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); | 347 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); |
| 348 RunUntilIdle(); | 348 RunUntilIdle(); |
| 349 const int64_t expected_offline_id = offline_id(); | 349 const int64_t expected_offline_id = offline_id(); |
| 350 const GURL expected_offline_url = offline_url(); | 350 const GURL expected_offline_url = offline_url(); |
| 351 | 351 |
| 352 archiver = BuildArchiver(kTestPageUrl, | 352 archiver = BuildArchiver(kTestPageUrl, |
| 353 base::FilePath(FILE_PATH_LITERAL("page3.html"))); | 353 base::FilePath(FILE_PATH_LITERAL("page3.html"))); |
| 354 client_id.id = "39"; | 354 client_id.id = "39"; |
| 355 model->SavePage( | 355 model->SavePage( |
| 356 kTestPageUrl, client_id, std::move(archiver), | 356 kTestPageUrl, client_id, 0ul, std::move(archiver), |
| 357 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); | 357 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); |
| 358 RunUntilIdle(); | 358 RunUntilIdle(); |
| 359 | 359 |
| 360 SimulateHasNetworkConnectivity(false); | 360 SimulateHasNetworkConnectivity(false); |
| 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()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 // Saves an offline page. | 417 // Saves an offline page. |
| 418 OfflinePageModel* model = | 418 OfflinePageModel* model = |
| 419 OfflinePageModelFactory::GetForBrowserContext(browser_context()); | 419 OfflinePageModelFactory::GetForBrowserContext(browser_context()); |
| 420 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( | 420 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( |
| 421 kTestPageUrl, | 421 kTestPageUrl, |
| 422 base::FilePath(FILE_PATH_LITERAL("AsyncLoadedPage.mhtml")))); | 422 base::FilePath(FILE_PATH_LITERAL("AsyncLoadedPage.mhtml")))); |
| 423 | 423 |
| 424 // We expect this Async Loading Namespace copy to be used. | 424 // We expect this Async Loading Namespace copy to be used. |
| 425 ClientId client_id(kAsyncNamespace, base::IntToString(kTabId)); | 425 ClientId client_id(kAsyncNamespace, base::IntToString(kTabId)); |
| 426 model->SavePage( | 426 model->SavePage( |
| 427 kTestPageUrl, client_id, std::move(archiver), | 427 kTestPageUrl, client_id, 0ul, std::move(archiver), |
| 428 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); | 428 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); |
| 429 RunUntilIdle(); | 429 RunUntilIdle(); |
| 430 const int64_t expected_offline_id = offline_id(); | 430 const int64_t expected_offline_id = offline_id(); |
| 431 const GURL expected_offline_url = offline_url(); | 431 const GURL expected_offline_url = offline_url(); |
| 432 | 432 |
| 433 SimulateHasNetworkConnectivity(false); | 433 SimulateHasNetworkConnectivity(false); |
| 434 StartLoad(kTestPageUrl); | 434 StartLoad(kTestPageUrl); |
| 435 // Gives a chance to run delayed task to do redirection. | 435 // Gives a chance to run delayed task to do redirection. |
| 436 RunUntilIdle(); | 436 RunUntilIdle(); |
| 437 | 437 |
| 438 const OfflinePageItem* item = | 438 const OfflinePageItem* item = |
| 439 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); | 439 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| 440 EXPECT_EQ(expected_offline_id, item->offline_id); | 440 EXPECT_EQ(expected_offline_id, item->offline_id); |
| 441 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); | 441 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); |
| 442 EXPECT_EQ(kAsyncNamespace, item->client_id.name_space); | 442 EXPECT_EQ(kAsyncNamespace, item->client_id.name_space); |
| 443 } | 443 } |
| 444 | 444 |
| 445 } // namespace offline_pages | 445 } // namespace offline_pages |
| OLD | NEW |