OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 class TopSitesLikelyImplTest : public HistoryUnitTestBase { | 142 class TopSitesLikelyImplTest : public HistoryUnitTestBase { |
143 public: | 143 public: |
144 TopSitesLikelyImplTest() | 144 TopSitesLikelyImplTest() |
145 : ui_thread_(BrowserThread::UI, &message_loop_), | 145 : ui_thread_(BrowserThread::UI, &message_loop_), |
146 db_thread_(BrowserThread::DB, &message_loop_) { | 146 db_thread_(BrowserThread::DB, &message_loop_) { |
147 } | 147 } |
148 | 148 |
149 virtual void SetUp() { | 149 virtual void SetUp() { |
150 profile_.reset(new TestingProfile); | 150 profile_.reset(new TestingProfile); |
151 if (CreateHistoryAndTopSites()) { | 151 if (CreateHistoryAndTopSites()) { |
152 ASSERT_TRUE(profile_->CreateHistoryService(false, false)); | 152 profile_->CreateHistoryService(false, false); |
153 profile_->CreateTopSites(); | 153 profile_->CreateTopSites(); |
154 profile_->BlockUntilTopSitesLoaded(); | 154 profile_->BlockUntilTopSitesLoaded(); |
155 } | 155 } |
156 } | 156 } |
157 | 157 |
158 virtual void TearDown() { | 158 virtual void TearDown() { |
159 profile_.reset(); | 159 profile_.reset(); |
160 } | 160 } |
161 | 161 |
162 // Returns true if history and top sites should be created in SetUp. | 162 // Returns true if history and top sites should be created in SetUp. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 data_path = data_path.AppendASCII("top_sites"); | 354 data_path = data_path.AppendASCII("top_sites"); |
355 | 355 |
356 // Set up history and thumbnails as they would be before migration. | 356 // Set up history and thumbnails as they would be before migration. |
357 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( | 357 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( |
358 data_path.AppendASCII("history.19.sql"), | 358 data_path.AppendASCII("history.19.sql"), |
359 profile()->GetPath().Append(chrome::kHistoryFilename))); | 359 profile()->GetPath().Append(chrome::kHistoryFilename))); |
360 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( | 360 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( |
361 data_path.AppendASCII("thumbnails.3.sql"), | 361 data_path.AppendASCII("thumbnails.3.sql"), |
362 profile()->GetPath().Append(chrome::kThumbnailsFilename))); | 362 profile()->GetPath().Append(chrome::kThumbnailsFilename))); |
363 | 363 |
364 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); | 364 profile()->CreateHistoryService(false, false); |
365 profile()->CreateTopSites(); | 365 profile()->CreateTopSites(); |
366 profile()->BlockUntilTopSitesLoaded(); | 366 profile()->BlockUntilTopSitesLoaded(); |
367 } | 367 } |
368 | 368 |
369 // Returns true if history and top sites should be created in SetUp. | 369 // Returns true if history and top sites should be created in SetUp. |
370 virtual bool CreateHistoryAndTopSites() OVERRIDE { | 370 virtual bool CreateHistoryAndTopSites() OVERRIDE { |
371 return false; | 371 return false; |
372 } | 372 } |
373 | 373 |
374 protected: | 374 protected: |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 | 908 |
909 // We need to wait for top sites and history to finish processing requests. | 909 // We need to wait for top sites and history to finish processing requests. |
910 WaitForTopSites(); | 910 WaitForTopSites(); |
911 WaitForHistory(); | 911 WaitForHistory(); |
912 | 912 |
913 // Make sure there is no longer a Thumbnails file on disk. | 913 // Make sure there is no longer a Thumbnails file on disk. |
914 ASSERT_FALSE(base::PathExists( | 914 ASSERT_FALSE(base::PathExists( |
915 profile()->GetPath().Append(chrome::kThumbnailsFilename))); | 915 profile()->GetPath().Append(chrome::kThumbnailsFilename))); |
916 | 916 |
917 // Recreate top sites and make sure everything is still there. | 917 // Recreate top sites and make sure everything is still there. |
918 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); | 918 profile()->CreateHistoryService(false, false); |
919 RecreateTopSitesAndBlock(); | 919 RecreateTopSitesAndBlock(); |
920 | 920 |
921 ASSERT_NO_FATAL_FAILURE(MigrationAssertions()); | 921 ASSERT_NO_FATAL_FAILURE(MigrationAssertions()); |
922 } | 922 } |
923 | 923 |
924 // Verifies that callbacks are notified correctly if requested before top sites | 924 // Verifies that callbacks are notified correctly if requested before top sites |
925 // has loaded. | 925 // has loaded. |
926 TEST_F(TopSitesLikelyImplTest, NotifyCallbacksWhenLoaded) { | 926 TEST_F(TopSitesLikelyImplTest, NotifyCallbacksWhenLoaded) { |
927 // Recreate top sites. It won't be loaded now. | 927 // Recreate top sites. It won't be loaded now. |
928 profile()->CreateTopSites(); | 928 profile()->CreateTopSites(); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 // before TopSites is considered loaded. | 1201 // before TopSites is considered loaded. |
1202 sql::Connection::Delete( | 1202 sql::Connection::Delete( |
1203 profile()->GetPath().Append(chrome::kTopSitesFilename)); | 1203 profile()->GetPath().Append(chrome::kTopSitesFilename)); |
1204 | 1204 |
1205 // Create TopSites, but not History. | 1205 // Create TopSites, but not History. |
1206 profile()->CreateTopSites(); | 1206 profile()->CreateTopSites(); |
1207 WaitForTopSites(); | 1207 WaitForTopSites(); |
1208 EXPECT_FALSE(IsTopSitesLoaded()); | 1208 EXPECT_FALSE(IsTopSitesLoaded()); |
1209 | 1209 |
1210 // Load history, which should make TopSites finish loading too. | 1210 // Load history, which should make TopSites finish loading too. |
1211 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); | 1211 profile()->CreateHistoryService(false, false); |
1212 profile()->BlockUntilTopSitesLoaded(); | 1212 profile()->BlockUntilTopSitesLoaded(); |
1213 EXPECT_TRUE(IsTopSitesLoaded()); | 1213 EXPECT_TRUE(IsTopSitesLoaded()); |
1214 } | 1214 } |
1215 | 1215 |
1216 class TopSitesLikelyUnloadTest : public TopSitesLikelyImplTest { | 1216 class TopSitesLikelyUnloadTest : public TopSitesLikelyImplTest { |
1217 public: | 1217 public: |
1218 TopSitesLikelyUnloadTest() {} | 1218 TopSitesLikelyUnloadTest() {} |
1219 | 1219 |
1220 virtual bool CreateHistoryAndTopSites() OVERRIDE { | 1220 virtual bool CreateHistoryAndTopSites() OVERRIDE { |
1221 return false; | 1221 return false; |
1222 } | 1222 } |
1223 | 1223 |
1224 private: | 1224 private: |
1225 DISALLOW_COPY_AND_ASSIGN(TopSitesLikelyUnloadTest); | 1225 DISALLOW_COPY_AND_ASSIGN(TopSitesLikelyUnloadTest); |
1226 }; | 1226 }; |
1227 | 1227 |
1228 // Makes sure if history is unloaded after topsites is loaded we don't hit any | 1228 // Makes sure if history is unloaded after topsites is loaded we don't hit any |
1229 // assertions. | 1229 // assertions. |
1230 TEST_F(TopSitesLikelyUnloadTest, UnloadHistoryTest) { | 1230 TEST_F(TopSitesLikelyUnloadTest, UnloadHistoryTest) { |
1231 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); | 1231 profile()->CreateHistoryService(false, false); |
1232 profile()->CreateTopSites(); | 1232 profile()->CreateTopSites(); |
1233 profile()->BlockUntilTopSitesLoaded(); | 1233 profile()->BlockUntilTopSitesLoaded(); |
1234 HistoryServiceFactory::GetForProfile( | 1234 HistoryServiceFactory::GetForProfile( |
1235 profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend(); | 1235 profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend(); |
1236 profile()->BlockUntilHistoryProcessesPendingRequests(); | 1236 profile()->BlockUntilHistoryProcessesPendingRequests(); |
1237 } | 1237 } |
1238 | 1238 |
1239 // Makes sure if history (with migration code) is unloaded after topsites is | 1239 // Makes sure if history (with migration code) is unloaded after topsites is |
1240 // loaded we don't hit any assertions. | 1240 // loaded we don't hit any assertions. |
1241 TEST_F(TopSitesLikelyUnloadTest, UnloadWithMigration) { | 1241 TEST_F(TopSitesLikelyUnloadTest, UnloadWithMigration) { |
1242 // Set up history and thumbnails as they would be before migration. | 1242 // Set up history and thumbnails as they would be before migration. |
1243 base::FilePath data_path; | 1243 base::FilePath data_path; |
1244 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 1244 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
1245 data_path = data_path.AppendASCII("top_sites"); | 1245 data_path = data_path.AppendASCII("top_sites"); |
1246 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( | 1246 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( |
1247 data_path.AppendASCII("history.19.sql"), | 1247 data_path.AppendASCII("history.19.sql"), |
1248 profile()->GetPath().Append(chrome::kHistoryFilename))); | 1248 profile()->GetPath().Append(chrome::kHistoryFilename))); |
1249 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( | 1249 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( |
1250 data_path.AppendASCII("thumbnails.3.sql"), | 1250 data_path.AppendASCII("thumbnails.3.sql"), |
1251 profile()->GetPath().Append(chrome::kThumbnailsFilename))); | 1251 profile()->GetPath().Append(chrome::kThumbnailsFilename))); |
1252 | 1252 |
1253 // Create history and block until it's loaded. | 1253 // Create history and block until it's loaded. |
1254 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); | 1254 profile()->CreateHistoryService(false, false); |
1255 profile()->BlockUntilHistoryProcessesPendingRequests(); | 1255 profile()->BlockUntilHistoryProcessesPendingRequests(); |
1256 | 1256 |
1257 // Create top sites and unload history. | 1257 // Create top sites and unload history. |
1258 content::WindowedNotificationObserver observer( | 1258 content::WindowedNotificationObserver observer( |
1259 chrome::NOTIFICATION_TOP_SITES_LOADED, | 1259 chrome::NOTIFICATION_TOP_SITES_LOADED, |
1260 content::Source<Profile>(profile())); | 1260 content::Source<Profile>(profile())); |
1261 profile()->CreateTopSites(); | 1261 profile()->CreateTopSites(); |
1262 HistoryServiceFactory::GetForProfile( | 1262 HistoryServiceFactory::GetForProfile( |
1263 profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend(); | 1263 profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend(); |
1264 profile()->BlockUntilHistoryProcessesPendingRequests(); | 1264 profile()->BlockUntilHistoryProcessesPendingRequests(); |
1265 observer.Wait(); | 1265 observer.Wait(); |
1266 } | 1266 } |
1267 | 1267 |
1268 } // namespace history | 1268 } // namespace history |
OLD | NEW |