OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // History unit tests come in two flavors: | 5 // History unit tests come in two flavors: |
6 // | 6 // |
7 // 1. The more complicated style is that the unit test creates a full history | 7 // 1. The more complicated style is that the unit test creates a full history |
8 // service. This spawns a background thread for the history backend, and | 8 // service. This spawns a background thread for the history backend, and |
9 // all communication is asynchronous. This is useful for testing more | 9 // all communication is asynchronous. This is useful for testing more |
10 // complicated things or end-to-end behavior. | 10 // complicated things or end-to-end behavior. |
11 // | 11 // |
12 // 2. The simpler style is to create a history backend on this thread and | 12 // 2. The simpler style is to create a history backend on this thread and |
13 // access it directly without a HistoryService object. This is much simpler | 13 // access it directly without a HistoryService object. This is much simpler |
14 // because communication is synchronous. Generally, sets should go through | 14 // because communication is synchronous. Generally, sets should go through |
15 // the history backend (since there is a lot of logic) but gets can come | 15 // the history backend (since there is a lot of logic) but gets can come |
16 // directly from the HistoryDatabase. This is because the backend generally | 16 // directly from the HistoryDatabase. This is because the backend generally |
17 // has no logic in the getter except threading stuff, which we don't want | 17 // has no logic in the getter except threading stuff, which we don't want |
18 // to run. | 18 // to run. |
19 | 19 |
20 #include <time.h> | 20 #include <time.h> |
21 #include <algorithm> | 21 #include <algorithm> |
22 | 22 |
| 23 #include "app/gfx/codec/jpeg_codec.h" |
23 #include "app/sql/connection.h" | 24 #include "app/sql/connection.h" |
24 #include "app/sql/statement.h" | 25 #include "app/sql/statement.h" |
25 #include "base/basictypes.h" | 26 #include "base/basictypes.h" |
26 #include "base/file_path.h" | 27 #include "base/file_path.h" |
27 #include "base/file_util.h" | 28 #include "base/file_util.h" |
28 #include "base/gfx/jpeg_codec.h" | |
29 #include "base/message_loop.h" | 29 #include "base/message_loop.h" |
30 #include "base/path_service.h" | 30 #include "base/path_service.h" |
31 #include "base/scoped_vector.h" | 31 #include "base/scoped_vector.h" |
32 #include "base/string_util.h" | 32 #include "base/string_util.h" |
33 #include "base/task.h" | 33 #include "base/task.h" |
34 #include "chrome/browser/browser_process.h" | 34 #include "chrome/browser/browser_process.h" |
35 #include "chrome/browser/download/download_manager.h" | 35 #include "chrome/browser/download/download_manager.h" |
36 #include "chrome/browser/history/history.h" | 36 #include "chrome/browser/history/history.h" |
37 #include "chrome/browser/history/history_backend.h" | 37 #include "chrome/browser/history/history_backend.h" |
38 #include "chrome/browser/history/history_database.h" | 38 #include "chrome/browser/history/history_database.h" |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 } | 661 } |
662 | 662 |
663 // This just tests history system -> thumbnail database integration, the actual | 663 // This just tests history system -> thumbnail database integration, the actual |
664 // thumbnail tests are in its own file. | 664 // thumbnail tests are in its own file. |
665 TEST_F(HistoryTest, Thumbnails) { | 665 TEST_F(HistoryTest, Thumbnails) { |
666 scoped_refptr<HistoryService> history(new HistoryService); | 666 scoped_refptr<HistoryService> history(new HistoryService); |
667 history_service_ = history; | 667 history_service_ = history; |
668 ASSERT_TRUE(history->Init(history_dir_, NULL)); | 668 ASSERT_TRUE(history->Init(history_dir_, NULL)); |
669 | 669 |
670 scoped_ptr<SkBitmap> thumbnail( | 670 scoped_ptr<SkBitmap> thumbnail( |
671 JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); | 671 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); |
672 static const double boringness = 0.25; | 672 static const double boringness = 0.25; |
673 | 673 |
674 const GURL url("http://www.google.com/thumbnail_test/"); | 674 const GURL url("http://www.google.com/thumbnail_test/"); |
675 history->AddPage(url); // Must be visited before adding a thumbnail. | 675 history->AddPage(url); // Must be visited before adding a thumbnail. |
676 history->SetPageThumbnail(url, *thumbnail, | 676 history->SetPageThumbnail(url, *thumbnail, |
677 ThumbnailScore(boringness, true, true)); | 677 ThumbnailScore(boringness, true, true)); |
678 | 678 |
679 // Make sure we get the correct thumbnail data. | 679 // Make sure we get the correct thumbnail data. |
680 EXPECT_TRUE(history->GetPageThumbnail(url, &consumer_, | 680 EXPECT_TRUE(history->GetPageThumbnail(url, &consumer_, |
681 NewCallback(static_cast<HistoryTest*>(this), | 681 NewCallback(static_cast<HistoryTest*>(this), |
682 &HistoryTest::OnThumbnailDataAvailable))); | 682 &HistoryTest::OnThumbnailDataAvailable))); |
683 thumbnail_data_.clear(); | 683 thumbnail_data_.clear(); |
684 MessageLoop::current()->Run(); | 684 MessageLoop::current()->Run(); |
685 // Make sure we got a valid JPEG back. This isn't equivalent to | 685 // Make sure we got a valid JPEG back. This isn't equivalent to |
686 // being correct, but when we're roundtripping through JPEG | 686 // being correct, but when we're roundtripping through JPEG |
687 // compression and we don't have a similarity measure. | 687 // compression and we don't have a similarity measure. |
688 EXPECT_TRUE(thumbnail_data_.size()); | 688 EXPECT_TRUE(thumbnail_data_.size()); |
689 scoped_ptr<SkBitmap> decoded_thumbnail( | 689 scoped_ptr<SkBitmap> decoded_thumbnail( |
690 JPEGCodec::Decode(&thumbnail_data_[0], thumbnail_data_.size())); | 690 gfx::JPEGCodec::Decode(&thumbnail_data_[0], thumbnail_data_.size())); |
691 EXPECT_TRUE(decoded_thumbnail.get()); | 691 EXPECT_TRUE(decoded_thumbnail.get()); |
692 | 692 |
693 // Request a nonexistent thumbnail and make sure we get | 693 // Request a nonexistent thumbnail and make sure we get |
694 // a callback and no data. | 694 // a callback and no data. |
695 EXPECT_TRUE(history->GetPageThumbnail(GURL("http://asdfasdf.com/"), | 695 EXPECT_TRUE(history->GetPageThumbnail(GURL("http://asdfasdf.com/"), |
696 &consumer_, | 696 &consumer_, |
697 NewCallback(static_cast<HistoryTest*>(this), | 697 NewCallback(static_cast<HistoryTest*>(this), |
698 &HistoryTest::OnThumbnailDataAvailable))); | 698 &HistoryTest::OnThumbnailDataAvailable))); |
699 thumbnail_data_.clear(); | 699 thumbnail_data_.clear(); |
700 MessageLoop::current()->Run(); | 700 MessageLoop::current()->Run(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 history_service_ = history; | 834 history_service_ = history; |
835 history->ScheduleDBTask(task.get(), &request_consumer); | 835 history->ScheduleDBTask(task.get(), &request_consumer); |
836 request_consumer.CancelAllRequests(); | 836 request_consumer.CancelAllRequests(); |
837 CleanupHistoryService(); | 837 CleanupHistoryService(); |
838 // WARNING: history has now been deleted. | 838 // WARNING: history has now been deleted. |
839 history = NULL; | 839 history = NULL; |
840 ASSERT_FALSE(task->done_invoked); | 840 ASSERT_FALSE(task->done_invoked); |
841 } | 841 } |
842 | 842 |
843 } // namespace history | 843 } // namespace history |
OLD | NEW |