| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "chrome/browser/search/suggestions/thumbnail_manager.h" | |
| 9 #include "chrome/test/base/testing_profile.h" | |
| 10 #include "components/leveldb_proto/proto_database.h" | |
| 11 #include "components/leveldb_proto/testing/fake_db.h" | |
| 12 #include "components/suggestions/proto/suggestions.pb.h" | |
| 13 #include "content/public/test/test_browser_thread_bundle.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 using leveldb_proto::test::FakeDB; | |
| 20 using suggestions::ThumbnailData; | |
| 21 using suggestions::ThumbnailManager; | |
| 22 | |
| 23 typedef base::hash_map<std::string, ThumbnailData> EntryMap; | |
| 24 | |
| 25 const char kTestUrl[] = "http://go.com/"; | |
| 26 const char kTestThumbnailUrl[] = "http://thumb.com/anchor_download_test.png"; | |
| 27 | |
| 28 class ThumbnailManagerTest : public testing::Test { | |
| 29 protected: | |
| 30 ThumbnailManager* CreateThumbnailManager(Profile* profile) { | |
| 31 FakeDB<ThumbnailData>* fake_db = new FakeDB<ThumbnailData>(&db_model_); | |
| 32 return new ThumbnailManager( | |
| 33 profile->GetRequestContext(), | |
| 34 scoped_ptr<leveldb_proto::ProtoDatabase<ThumbnailData> >(fake_db), | |
| 35 FakeDB<ThumbnailData>::DirectoryForTestDB()); | |
| 36 } | |
| 37 | |
| 38 content::TestBrowserThreadBundle thread_bundle_; | |
| 39 EntryMap db_model_; | |
| 40 }; | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 44 namespace suggestions { | |
| 45 | |
| 46 TEST_F(ThumbnailManagerTest, InitializeTest) { | |
| 47 SuggestionsProfile suggestions_profile; | |
| 48 ChromeSuggestion* suggestion = suggestions_profile.add_suggestions(); | |
| 49 suggestion->set_url(kTestUrl); | |
| 50 suggestion->set_thumbnail(kTestThumbnailUrl); | |
| 51 | |
| 52 TestingProfile profile; | |
| 53 scoped_ptr<ThumbnailManager> thumbnail_manager( | |
| 54 CreateThumbnailManager(&profile)); | |
| 55 thumbnail_manager->Initialize(suggestions_profile); | |
| 56 | |
| 57 GURL output; | |
| 58 EXPECT_TRUE(thumbnail_manager->GetThumbnailURL(GURL(kTestUrl), &output)); | |
| 59 EXPECT_EQ(GURL(kTestThumbnailUrl), output); | |
| 60 | |
| 61 EXPECT_FALSE( | |
| 62 thumbnail_manager->GetThumbnailURL(GURL("http://b.com"), &output)); | |
| 63 } | |
| 64 | |
| 65 } // namespace suggestions | |
| OLD | NEW |