| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // Gives a chance to run delayed task to do redirection. | 343 // Gives a chance to run delayed task to do redirection. |
| 344 RunUntilIdle(); | 344 RunUntilIdle(); |
| 345 | 345 |
| 346 const OfflinePageItem* item = | 346 const OfflinePageItem* item = |
| 347 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); | 347 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| 348 EXPECT_EQ(expected_offline_id, item->offline_id); | 348 EXPECT_EQ(expected_offline_id, item->offline_id); |
| 349 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); | 349 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); |
| 350 EXPECT_EQ(kLastNNamespace, item->client_id.name_space); | 350 EXPECT_EQ(kLastNNamespace, item->client_id.name_space); |
| 351 EXPECT_EQ(kTabId, item->client_id.id); | 351 EXPECT_EQ(kTabId, item->client_id.id); |
| 352 } | 352 } |
| 353 |
| 354 // This test saves another copy of page from Async Loading namespace |
| 355 // and verifies it is redirected to it (as it is more recent). |
| 356 TEST_F(OfflinePageTabHelperTest, SwitchToOfflineAsyncLoadedPageOnNoNetwork) { |
| 357 // Saves an offline page. |
| 358 OfflinePageModel* model = |
| 359 OfflinePageModelFactory::GetForBrowserContext(browser_context()); |
| 360 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( |
| 361 kTestPageUrl, |
| 362 base::FilePath(FILE_PATH_LITERAL("AsyncLoadedPage.mhtml")))); |
| 363 |
| 364 // We expect this Async Loading Namespace copy to be used. |
| 365 ClientId client_id(kAsyncNamespace, kTabId); |
| 366 model->SavePage( |
| 367 kTestPageUrl, client_id, std::move(archiver), |
| 368 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); |
| 369 RunUntilIdle(); |
| 370 const int64_t expected_offline_id = offline_id(); |
| 371 const GURL expected_offline_url = offline_url(); |
| 372 |
| 373 SimulateHasNetworkConnectivity(false); |
| 374 StartLoad(kTestPageUrl); |
| 375 // Gives a chance to run delayed task to do redirection. |
| 376 RunUntilIdle(); |
| 377 |
| 378 const OfflinePageItem* item = |
| 379 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); |
| 380 EXPECT_EQ(expected_offline_id, item->offline_id); |
| 381 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); |
| 382 EXPECT_EQ(kAsyncNamespace, item->client_id.name_space); |
| 383 } |
| 384 |
| 353 } // namespace offline_pages | 385 } // namespace offline_pages |
| OLD | NEW |