Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: chrome/browser/search/suggestions/thumbnail_manager_browsertest.cc

Issue 299713007: [Suggestions] Adding a Thumbnail Manager for the Suggestions Service (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/files/file_path.h"
8 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h"
9 #include "chrome/browser/search/suggestions/thumbnail_manager.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "content/public/test/test_utils.h"
15 #include "net/test/spawned_test_server/spawned_test_server.h"
16 #include "net/url_request/url_request_test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/image/image_skia.h"
19 #include "url/gurl.h"
20
21 namespace {
22
23 const char kTestUrl1[] = "http://go.com/";
24 const char kTestUrl2[] = "http://goal.com/";
25 const char kTestImagePath[] = "files/image_decoding/droids.png";
26 const char kInvalidImagePath[] = "files/DOESNOTEXIST";
27
28 const base::FilePath::CharType kDocRoot[] =
29 FILE_PATH_LITERAL("chrome/test/data");
30
31 using content::BrowserThread;
32
33 class ThumbnailManagerBrowserTest : public InProcessBrowserTest {
34 public:
35 ThumbnailManagerBrowserTest()
36 : num_callback_null_called_(0),
37 num_callback_valid_called_(0),
38 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
39 test_server_(net::SpawnedTestServer::TYPE_HTTP,
40 net::SpawnedTestServer::kLocalhost,
41 base::FilePath(kDocRoot)) {}
42
43 virtual void SetUp() OVERRIDE {
44 ASSERT_TRUE(test_server_.Start());
45
46 context_ = new net::TestURLRequestContextGetter(
47 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
48 context_->AddRef();
49 }
50
51 virtual void TearDown() OVERRIDE {
52 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, context_);
53 }
54
55 void OnThumbnailAvailable(const GURL& url, const SkBitmap* bitmap) {
56 if (bitmap) {
57 num_callback_valid_called_++;
58 } else {
59 num_callback_null_called_++;
60 }
61 }
62 int num_callback_null_called_;
63 int num_callback_valid_called_;
64 content::TestBrowserThreadBundle thread_bundle_;
65 net::SpawnedTestServer test_server_;
66 net::TestURLRequestContextGetter* context_;
67 };
68
69 } // namespace.
huangs 2014/05/22 06:17:35 NIT: don't need period at end.
Mathieu 2014/05/22 15:45:51 Done.
70
71 namespace suggestions {
72
73 IN_PROC_BROWSER_TEST_F(ThumbnailManagerBrowserTest, FetchThumbnails) {
74 SuggestionsProfile suggestions_profile;
75 ChromeSuggestion* suggestion = suggestions_profile.add_suggestions();
76 suggestion->set_url(kTestUrl1);
77 suggestion->set_thumbnail(test_server_.GetURL(kTestImagePath).spec());
78
79 TestingProfile profile;
80 ThumbnailManager thumbnail_manager(&profile);
81 thumbnail_manager.InitializeThumbnailMap(suggestions_profile);
82 thumbnail_manager.set_request_context(context_);
83
84 thumbnail_manager.GetURLThumbnail(
85 GURL(kTestUrl1),
86 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable,
87 base::Unretained(this)));
88
89 content::RunMessageLoop();
90
91 EXPECT_EQ(0, num_callback_null_called_);
92 EXPECT_EQ(1, num_callback_valid_called_);
93
94 thumbnail_manager.GetURLThumbnail(
95 GURL(kTestUrl2),
96 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable,
97 base::Unretained(this)));
98
99 content::RunMessageLoop();
100
101 EXPECT_EQ(1, num_callback_null_called_);
102 EXPECT_EQ(1, num_callback_valid_called_);
103 }
104
105 IN_PROC_BROWSER_TEST_F(ThumbnailManagerBrowserTest, FetchThumbnailsMultiple) {
106 SuggestionsProfile suggestions_profile;
107 ChromeSuggestion* suggestion = suggestions_profile.add_suggestions();
108 suggestion->set_url(kTestUrl1);
109 suggestion->set_thumbnail(test_server_.GetURL(kTestImagePath).spec());
110
111 TestingProfile profile;
112 ThumbnailManager thumbnail_manager(&profile);
113 thumbnail_manager.InitializeThumbnailMap(suggestions_profile);
114 thumbnail_manager.set_request_context(context_);
115
116 thumbnail_manager.GetURLThumbnail(
117 GURL(kTestUrl1),
118 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable,
119 base::Unretained(this)));
120 thumbnail_manager.GetURLThumbnail(
121 GURL(kTestUrl1),
122 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable,
123 base::Unretained(this)));
124 thumbnail_manager.GetURLThumbnail(
125 GURL(kTestUrl1),
126 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable,
127 base::Unretained(this)));
128
129 content::RunMessageLoop();
130
131 EXPECT_EQ(0, num_callback_null_called_);
132 EXPECT_EQ(3, num_callback_valid_called_);
133 }
134
135 IN_PROC_BROWSER_TEST_F(ThumbnailManagerBrowserTest, FetchThumbnailsInvalid) {
136 SuggestionsProfile suggestions_profile;
137 ChromeSuggestion* suggestion = suggestions_profile.add_suggestions();
138 suggestion->set_url(kTestUrl1);
139 suggestion->set_thumbnail(test_server_.GetURL(kInvalidImagePath).spec());
140
141 TestingProfile profile;
142 ThumbnailManager thumbnail_manager(&profile);
143 thumbnail_manager.InitializeThumbnailMap(suggestions_profile);
144 thumbnail_manager.set_request_context(context_);
145
146 thumbnail_manager.GetURLThumbnail(
147 GURL(kTestUrl1),
148 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable,
149 base::Unretained(this)));
150
151 content::RunMessageLoop();
152
153 EXPECT_EQ(1, num_callback_null_called_);
154 EXPECT_EQ(0, num_callback_valid_called_);
155 }
156
157 } // namespace suggestions.
huangs 2014/05/22 06:17:35 No period at end.
Mathieu 2014/05/22 15:45:51 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698