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

Side by Side Diff: trunk/src/chrome/browser/history/top_sites_impl_unittest.cc

Issue 19714004: Revert 213148 "Add asserts to TestingProfile::CreateHistoryServi..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 5 months 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 | Annotate | Revision Log
OLDNEW
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
142 class TopSitesImplTest : public HistoryUnitTestBase { 142 class TopSitesImplTest : public HistoryUnitTestBase {
143 public: 143 public:
144 TopSitesImplTest() 144 TopSitesImplTest()
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 data_path = data_path.AppendASCII("top_sites"); 353 data_path = data_path.AppendASCII("top_sites");
354 354
355 // Set up history and thumbnails as they would be before migration. 355 // Set up history and thumbnails as they would be before migration.
356 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( 356 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript(
357 data_path.AppendASCII("history.19.sql"), 357 data_path.AppendASCII("history.19.sql"),
358 profile()->GetPath().Append(chrome::kHistoryFilename))); 358 profile()->GetPath().Append(chrome::kHistoryFilename)));
359 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( 359 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript(
360 data_path.AppendASCII("thumbnails.3.sql"), 360 data_path.AppendASCII("thumbnails.3.sql"),
361 profile()->GetPath().Append(chrome::kThumbnailsFilename))); 361 profile()->GetPath().Append(chrome::kThumbnailsFilename)));
362 362
363 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); 363 profile()->CreateHistoryService(false, false);
364 profile()->CreateTopSites(); 364 profile()->CreateTopSites();
365 profile()->BlockUntilTopSitesLoaded(); 365 profile()->BlockUntilTopSitesLoaded();
366 } 366 }
367 367
368 // Returns true if history and top sites should be created in SetUp. 368 // Returns true if history and top sites should be created in SetUp.
369 virtual bool CreateHistoryAndTopSites() OVERRIDE { 369 virtual bool CreateHistoryAndTopSites() OVERRIDE {
370 return false; 370 return false;
371 } 371 }
372 372
373 protected: 373 protected:
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 907
908 // We need to wait for top sites and history to finish processing requests. 908 // We need to wait for top sites and history to finish processing requests.
909 WaitForTopSites(); 909 WaitForTopSites();
910 WaitForHistory(); 910 WaitForHistory();
911 911
912 // Make sure there is no longer a Thumbnails file on disk. 912 // Make sure there is no longer a Thumbnails file on disk.
913 ASSERT_FALSE(base::PathExists( 913 ASSERT_FALSE(base::PathExists(
914 profile()->GetPath().Append(chrome::kThumbnailsFilename))); 914 profile()->GetPath().Append(chrome::kThumbnailsFilename)));
915 915
916 // Recreate top sites and make sure everything is still there. 916 // Recreate top sites and make sure everything is still there.
917 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); 917 profile()->CreateHistoryService(false, false);
918 RecreateTopSitesAndBlock(); 918 RecreateTopSitesAndBlock();
919 919
920 ASSERT_NO_FATAL_FAILURE(MigrationAssertions()); 920 ASSERT_NO_FATAL_FAILURE(MigrationAssertions());
921 } 921 }
922 922
923 // Verifies that callbacks are notified correctly if requested before top sites 923 // Verifies that callbacks are notified correctly if requested before top sites
924 // has loaded. 924 // has loaded.
925 TEST_F(TopSitesImplTest, NotifyCallbacksWhenLoaded) { 925 TEST_F(TopSitesImplTest, NotifyCallbacksWhenLoaded) {
926 // Recreate top sites. It won't be loaded now. 926 // Recreate top sites. It won't be loaded now.
927 profile()->CreateTopSites(); 927 profile()->CreateTopSites();
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 // before TopSites is considered loaded. 1200 // before TopSites is considered loaded.
1201 sql::Connection::Delete( 1201 sql::Connection::Delete(
1202 profile()->GetPath().Append(chrome::kTopSitesFilename)); 1202 profile()->GetPath().Append(chrome::kTopSitesFilename));
1203 1203
1204 // Create TopSites, but not History. 1204 // Create TopSites, but not History.
1205 profile()->CreateTopSites(); 1205 profile()->CreateTopSites();
1206 WaitForTopSites(); 1206 WaitForTopSites();
1207 EXPECT_FALSE(IsTopSitesLoaded()); 1207 EXPECT_FALSE(IsTopSitesLoaded());
1208 1208
1209 // Load history, which should make TopSites finish loading too. 1209 // Load history, which should make TopSites finish loading too.
1210 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); 1210 profile()->CreateHistoryService(false, false);
1211 profile()->BlockUntilTopSitesLoaded(); 1211 profile()->BlockUntilTopSitesLoaded();
1212 EXPECT_TRUE(IsTopSitesLoaded()); 1212 EXPECT_TRUE(IsTopSitesLoaded());
1213 } 1213 }
1214 1214
1215 class TopSitesUnloadTest : public TopSitesImplTest { 1215 class TopSitesUnloadTest : public TopSitesImplTest {
1216 public: 1216 public:
1217 TopSitesUnloadTest() {} 1217 TopSitesUnloadTest() {}
1218 1218
1219 virtual bool CreateHistoryAndTopSites() OVERRIDE { 1219 virtual bool CreateHistoryAndTopSites() OVERRIDE {
1220 return false; 1220 return false;
1221 } 1221 }
1222 1222
1223 private: 1223 private:
1224 DISALLOW_COPY_AND_ASSIGN(TopSitesUnloadTest); 1224 DISALLOW_COPY_AND_ASSIGN(TopSitesUnloadTest);
1225 }; 1225 };
1226 1226
1227 // Makes sure if history is unloaded after topsites is loaded we don't hit any 1227 // Makes sure if history is unloaded after topsites is loaded we don't hit any
1228 // assertions. 1228 // assertions.
1229 TEST_F(TopSitesUnloadTest, UnloadHistoryTest) { 1229 TEST_F(TopSitesUnloadTest, UnloadHistoryTest) {
1230 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); 1230 profile()->CreateHistoryService(false, false);
1231 profile()->CreateTopSites(); 1231 profile()->CreateTopSites();
1232 profile()->BlockUntilTopSitesLoaded(); 1232 profile()->BlockUntilTopSitesLoaded();
1233 HistoryServiceFactory::GetForProfile( 1233 HistoryServiceFactory::GetForProfile(
1234 profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend(); 1234 profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend();
1235 profile()->BlockUntilHistoryProcessesPendingRequests(); 1235 profile()->BlockUntilHistoryProcessesPendingRequests();
1236 } 1236 }
1237 1237
1238 // Makes sure if history (with migration code) is unloaded after topsites is 1238 // Makes sure if history (with migration code) is unloaded after topsites is
1239 // loaded we don't hit any assertions. 1239 // loaded we don't hit any assertions.
1240 TEST_F(TopSitesUnloadTest, UnloadWithMigration) { 1240 TEST_F(TopSitesUnloadTest, UnloadWithMigration) {
1241 // Set up history and thumbnails as they would be before migration. 1241 // Set up history and thumbnails as they would be before migration.
1242 base::FilePath data_path; 1242 base::FilePath data_path;
1243 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); 1243 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
1244 data_path = data_path.AppendASCII("top_sites"); 1244 data_path = data_path.AppendASCII("top_sites");
1245 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( 1245 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript(
1246 data_path.AppendASCII("history.19.sql"), 1246 data_path.AppendASCII("history.19.sql"),
1247 profile()->GetPath().Append(chrome::kHistoryFilename))); 1247 profile()->GetPath().Append(chrome::kHistoryFilename)));
1248 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( 1248 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript(
1249 data_path.AppendASCII("thumbnails.3.sql"), 1249 data_path.AppendASCII("thumbnails.3.sql"),
1250 profile()->GetPath().Append(chrome::kThumbnailsFilename))); 1250 profile()->GetPath().Append(chrome::kThumbnailsFilename)));
1251 1251
1252 // Create history and block until it's loaded. 1252 // Create history and block until it's loaded.
1253 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); 1253 profile()->CreateHistoryService(false, false);
1254 profile()->BlockUntilHistoryProcessesPendingRequests(); 1254 profile()->BlockUntilHistoryProcessesPendingRequests();
1255 1255
1256 // Create top sites and unload history. 1256 // Create top sites and unload history.
1257 content::WindowedNotificationObserver observer( 1257 content::WindowedNotificationObserver observer(
1258 chrome::NOTIFICATION_TOP_SITES_LOADED, 1258 chrome::NOTIFICATION_TOP_SITES_LOADED,
1259 content::Source<Profile>(profile())); 1259 content::Source<Profile>(profile()));
1260 profile()->CreateTopSites(); 1260 profile()->CreateTopSites();
1261 HistoryServiceFactory::GetForProfile( 1261 HistoryServiceFactory::GetForProfile(
1262 profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend(); 1262 profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend();
1263 profile()->BlockUntilHistoryProcessesPendingRequests(); 1263 profile()->BlockUntilHistoryProcessesPendingRequests();
1264 observer.Wait(); 1264 observer.Wait();
1265 } 1265 }
1266 1266
1267 } // namespace history 1267 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698