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

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

Issue 1473043002: [Offline pages] Fixing a crash in URL change, when offline copy not present (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding tests for 2 crashing bugs 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"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "components/bookmarks/browser/bookmark_node.h"
18 #include "components/offline_pages/offline_page_item.h" 19 #include "components/offline_pages/offline_page_item.h"
19 #include "components/offline_pages/offline_page_metadata_store.h" 20 #include "components/offline_pages/offline_page_metadata_store.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult; 24 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult;
24 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult; 25 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult;
25 26
26 namespace offline_pages { 27 namespace offline_pages {
27 28
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED) 944 OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)
944 .Pass()); 945 .Pass());
945 model()->SavePage( 946 model()->SavePage(
946 kTestUrl2, kTestPageBookmarkId2, archiver3.Pass(), 947 kTestUrl2, kTestPageBookmarkId2, archiver3.Pass(),
947 base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr())); 948 base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
948 PumpLoop(); 949 PumpLoop();
949 EXPECT_EQ(1UL, model()->GetAllPages().size()); 950 EXPECT_EQ(1UL, model()->GetAllPages().size());
950 EXPECT_EQ(1UL, GetStore()->offline_pages().size()); 951 EXPECT_EQ(1UL, GetStore()->offline_pages().size());
951 } 952 }
952 953
954 TEST_F(OfflinePageModelTest, BookmarkNodeChangesUrl) {
955 scoped_ptr<OfflinePageTestArchiver> archiver(
956 BuildArchiver(kTestUrl,
957 OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED)
958 .Pass());
959 model()->SavePage(
960 kTestUrl, kTestPageBookmarkId1, archiver.Pass(),
961 base::Bind(&OfflinePageModelTest::OnSavePageDone, AsWeakPtr()));
962 PumpLoop();
963
964 EXPECT_EQ(1UL, model()->GetAllPages().size());
965
966 bookmarks::BookmarkNode bookmark_node(kTestPageBookmarkId1, kTestUrl2);
967 model()->BookmarkNodeChanged(nullptr, &bookmark_node);
968 PumpLoop();
969
970 // Offline copy should be removed. Chrome should not crash.
971 // http://crbug.com/558929
972 EXPECT_EQ(0UL, model()->GetAllPages().size());
973
974 // Chrome should not crash when a bookmark with no offline copy is changed.
975 // http://crbug.com/560518
976 bookmark_node.set_url(kTestUrl);
977 model()->BookmarkNodeChanged(nullptr, &bookmark_node);
978 PumpLoop();
979 EXPECT_EQ(0UL, model()->GetAllPages().size());
980 }
981
953 } // namespace offline_pages 982 } // 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