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.
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/search/suggestions/image_manager_impl.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"
19 using leveldb_proto::test::FakeDB;
20 using suggestions::ImageData;
21 using suggestions::ImageManagerImpl;
23 typedef base::hash_map<std::string, ImageData> EntryMap;
25 const char kTestUrl[] = "http://go.com/";
26 const char kTestImageUrl[] = "http://thumb.com/anchor_download_test.png";
28 class ImageManagerImplTest : public testing::Test {
30 ImageManagerImpl* CreateImageManager(Profile* profile) {
31 FakeDB<ImageData>* fake_db = new FakeDB<ImageData>(&db_model_);
32 return new ImageManagerImpl(
33 profile->GetRequestContext(),
34 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> >(fake_db),
35 FakeDB<ImageData>::DirectoryForTestDB());
38 content::TestBrowserThreadBundle thread_bundle_;
44 namespace suggestions {
46 TEST_F(ImageManagerImplTest, InitializeTest) {
47 SuggestionsProfile suggestions_profile;
48 ChromeSuggestion* suggestion = suggestions_profile.add_suggestions();
49 suggestion->set_url(kTestUrl);
50 suggestion->set_thumbnail(kTestImageUrl);
52 TestingProfile profile;
53 scoped_ptr<ImageManagerImpl> image_manager(
54 CreateImageManager(&profile));
55 image_manager->Initialize(suggestions_profile);
58 EXPECT_TRUE(image_manager->GetImageURL(GURL(kTestUrl), &output));
59 EXPECT_EQ(GURL(kTestImageUrl), output);
61 EXPECT_FALSE(image_manager->GetImageURL(GURL("http://b.com"), &output));
64 } // namespace suggestions