| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 profile()->CreateTopSites(); | 1336 profile()->CreateTopSites(); |
| 1337 WaitForTopSites(); | 1337 WaitForTopSites(); |
| 1338 EXPECT_FALSE(IsTopSitesLoaded()); | 1338 EXPECT_FALSE(IsTopSitesLoaded()); |
| 1339 | 1339 |
| 1340 // Load history, which should make TopSites finish loading too. | 1340 // Load history, which should make TopSites finish loading too. |
| 1341 profile()->CreateHistoryService(false, false); | 1341 profile()->CreateHistoryService(false, false); |
| 1342 profile()->BlockUntilTopSitesLoaded(); | 1342 profile()->BlockUntilTopSitesLoaded(); |
| 1343 EXPECT_TRUE(IsTopSitesLoaded()); | 1343 EXPECT_TRUE(IsTopSitesLoaded()); |
| 1344 } | 1344 } |
| 1345 | 1345 |
| 1346 // Used for running the refresh method of TopSites synchronously. |
| 1347 class RefreshRunner { |
| 1348 public: |
| 1349 RefreshRunner() : number_of_callbacks_(0), waiting_(false) {} |
| 1350 |
| 1351 void Refresh(TopSites* top_sites) { |
| 1352 int start_number_of_callbacks = number_of_callbacks_; |
| 1353 top_sites->RefreshAndCallback(NewCallback(this, &RefreshRunner::OnRefresh)); |
| 1354 if (start_number_of_callbacks == number_of_callbacks_) { |
| 1355 waiting_ = true; |
| 1356 MessageLoop::current()->Run(); |
| 1357 } |
| 1358 } |
| 1359 |
| 1360 int number_of_callbacks() const { return number_of_callbacks_; } |
| 1361 |
| 1362 private: |
| 1363 // Callback for TopSites::RefreshAndCallback. |
| 1364 void OnRefresh() { |
| 1365 number_of_callbacks_++; |
| 1366 if (waiting_) { |
| 1367 MessageLoop::current()->Quit(); |
| 1368 waiting_ = false; |
| 1369 } |
| 1370 } |
| 1371 |
| 1372 int number_of_callbacks_; |
| 1373 bool waiting_; |
| 1374 |
| 1375 DISALLOW_COPY_AND_ASSIGN(RefreshRunner); |
| 1376 }; |
| 1377 |
| 1378 // This tests RefreshAndCallback, a method only used in higher-level testing. |
| 1379 TEST_F(TopSitesTest, RefreshCallbackInvoked) { |
| 1380 // Test that the callback is invoked. |
| 1381 RefreshRunner refresh_runner; |
| 1382 refresh_runner.Refresh(top_sites()); |
| 1383 ASSERT_EQ(1, refresh_runner.number_of_callbacks()); |
| 1384 |
| 1385 // Tests that the callback can be invoked again. |
| 1386 refresh_runner.Refresh(top_sites()); |
| 1387 ASSERT_EQ(2, refresh_runner.number_of_callbacks()); |
| 1388 |
| 1389 // Test that the callback is not invoked accidentally. |
| 1390 StartQueryForMostVisited(); |
| 1391 WaitForHistory(); |
| 1392 WaitForTopSites(); |
| 1393 |
| 1394 ASSERT_EQ(2, refresh_runner.number_of_callbacks()); |
| 1395 } |
| 1396 |
| 1397 // This tests RefreshAndCallback, a method only used in higher-level testing. |
| 1398 TEST_F(TopSitesTest, RefreshWorks) { |
| 1399 GURL google("http://google.com/"); |
| 1400 AddPageToHistory(google); |
| 1401 RefreshRunner refresh_runner; |
| 1402 refresh_runner.Refresh(top_sites()); |
| 1403 |
| 1404 TopSitesQuerier querier; |
| 1405 querier.QueryTopSites(top_sites(), true); |
| 1406 |
| 1407 ASSERT_EQ(1u + GetPrepopulatePages().size(), querier.urls().size()); |
| 1408 } |
| 1409 |
| 1346 } // namespace history | 1410 } // namespace history |
| OLD | NEW |