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/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"
15#include "url/gurl.h"
16
17namespace {
18
19using leveldb_proto::test::FakeDB;
20using suggestions::ImageData;
21using suggestions::ImageManagerImpl;
22
23typedef base::hash_map<std::string, ImageData> EntryMap;
24
25const char kTestUrl[] = "http://go.com/";
26const char kTestImageUrl[] = "http://thumb.com/anchor_download_test.png";
27
28class ImageManagerImplTest : public testing::Test {
29 protected:
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());
36  }
37
38  content::TestBrowserThreadBundle thread_bundle_;
39  EntryMap db_model_;
40};
41
42}  // namespace
43
44namespace suggestions {
45
46TEST_F(ImageManagerImplTest, InitializeTest) {
47  SuggestionsProfile suggestions_profile;
48  ChromeSuggestion* suggestion = suggestions_profile.add_suggestions();
49  suggestion->set_url(kTestUrl);
50  suggestion->set_thumbnail(kTestImageUrl);
51
52  TestingProfile profile;
53  scoped_ptr<ImageManagerImpl> image_manager(
54      CreateImageManager(&profile));
55  image_manager->Initialize(suggestions_profile);
56
57  GURL output;
58  EXPECT_TRUE(image_manager->GetImageURL(GURL(kTestUrl), &output));
59  EXPECT_EQ(GURL(kTestImageUrl), output);
60
61  EXPECT_FALSE(image_manager->GetImageURL(GURL("http://b.com"), &output));
62}
63
64}  // namespace suggestions
65