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

Side by Side Diff: components/offline_pages/offline_page_model_unittest.cc

Issue 1487913002: [Offline pages] Fixing crashes caused by access to offline pages marked for deletion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 5 years 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
« no previous file with comments | « components/offline_pages/offline_page_model.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/offline_pages/offline_page_model.h" 5 #include "components/offline_pages/offline_page_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 TEST_F(OfflinePageModelTest, MarkPageForDeletion) { 593 TEST_F(OfflinePageModelTest, MarkPageForDeletion) {
594 scoped_ptr<OfflinePageTestArchiver> archiver( 594 scoped_ptr<OfflinePageTestArchiver> archiver(
595 BuildArchiver(kTestUrl, 595 BuildArchiver(kTestUrl,
596 OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED) 596 OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)
597 .Pass()); 597 .Pass());
598 model()->SavePage( 598 model()->SavePage(
599 kTestUrl, kTestPageBookmarkId1, archiver.Pass(), 599 kTestUrl, kTestPageBookmarkId1, archiver.Pass(),
600 base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr())); 600 base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
601 PumpLoop(); 601 PumpLoop();
602 602
603 GURL offline_url = model()->GetAllPages().begin()->GetOfflineURL();
604
603 // Delete the page with undo tiggerred. 605 // Delete the page with undo tiggerred.
604 model()->MarkPageForDeletion( 606 model()->MarkPageForDeletion(
605 kTestPageBookmarkId1, 607 kTestPageBookmarkId1,
606 base::Bind(&OfflinePageModelTest::OnDeletePageDone, AsWeakPtr())); 608 base::Bind(&OfflinePageModelTest::OnDeletePageDone, AsWeakPtr()));
607 PumpLoop(); 609 PumpLoop();
608 610
609 // GetAllPages will not return the page that is marked for deletion. 611 // GetAllPages will not return the page that is marked for deletion.
610 const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages(); 612 const std::vector<OfflinePageItem>& offline_pages = model()->GetAllPages();
611 EXPECT_EQ(0UL, offline_pages.size()); 613 EXPECT_EQ(0UL, offline_pages.size());
612 614
615 EXPECT_FALSE(model()->HasOfflinePages());
616 EXPECT_EQ(nullptr, model()->GetPageByOnlineURL(kTestUrl));
617 EXPECT_EQ(nullptr, model()->GetPageByBookmarkId(kTestPageBookmarkId1));
618 EXPECT_EQ(nullptr, model()->GetPageByOfflineURL(offline_url));
619
613 // Undo the deletion. 620 // Undo the deletion.
614 model()->UndoPageDeletion(kTestPageBookmarkId1); 621 model()->UndoPageDeletion(kTestPageBookmarkId1);
615 base::RunLoop().RunUntilIdle(); 622 base::RunLoop().RunUntilIdle();
616 623
617 // GetAllPages will now return the restored page. 624 // GetAllPages will now return the restored page.
618 const std::vector<OfflinePageItem>& offline_pages_after_undo = 625 const std::vector<OfflinePageItem>& offline_pages_after_undo =
619 model()->GetAllPages(); 626 model()->GetAllPages();
620 EXPECT_EQ(1UL, offline_pages_after_undo.size()); 627 EXPECT_EQ(1UL, offline_pages_after_undo.size());
621 } 628 }
622 629
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 1015
1009 // Chrome should not crash when a bookmark with no offline copy is changed. 1016 // Chrome should not crash when a bookmark with no offline copy is changed.
1010 // http://crbug.com/560518 1017 // http://crbug.com/560518
1011 bookmark_node.set_url(kTestUrl); 1018 bookmark_node.set_url(kTestUrl);
1012 model()->BookmarkNodeChanged(nullptr, &bookmark_node); 1019 model()->BookmarkNodeChanged(nullptr, &bookmark_node);
1013 PumpLoop(); 1020 PumpLoop();
1014 EXPECT_EQ(0UL, model()->GetAllPages().size()); 1021 EXPECT_EQ(0UL, model()->GetAllPages().size());
1015 } 1022 }
1016 1023
1017 } // namespace offline_pages 1024 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698