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

Side by Side Diff: chrome/browser/favicon/favicon_handler_unittest.cc

Issue 8956059: Rename NavigationController to NavigationControllerImpl and put it into the content namespace. Al... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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
« no previous file with comments | « chrome/browser/favicon/favicon_handler.cc ('k') | chrome/browser/favicon/favicon_tab_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/favicon/favicon_handler.h" 5 #include "chrome/browser/favicon/favicon_handler.h"
6 #include "chrome/browser/profiles/profile.h" 6 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
8 #include "content/browser/tab_contents/test_tab_contents.h" 8 #include "content/browser/tab_contents/test_tab_contents.h"
9 #include "content/public/browser/navigation_entry.h" 9 #include "content/public/browser/navigation_entry.h"
10 #include "content/public/browser/favicon_status.h" 10 #include "content/public/browser/favicon_status.h"
11 #include "ui/gfx/codec/png_codec.h" 11 #include "ui/gfx/codec/png_codec.h"
12 #include "ui/gfx/favicon_size.h" 12 #include "ui/gfx/favicon_size.h"
13 #include "ui/gfx/image/image.h" 13 #include "ui/gfx/image/image.h"
14 14
15 class TestFaviconHandler; 15 class TestFaviconHandler;
16 16
17 using content::NavigationEntry;
18
17 namespace { 19 namespace {
18 20
19 // Fill the given bmp with valid png data. 21 // Fill the given bmp with valid png data.
20 void FillDataToBitmap(int w, int h, SkBitmap* bmp) { 22 void FillDataToBitmap(int w, int h, SkBitmap* bmp) {
21 bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h); 23 bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h);
22 bmp->allocPixels(); 24 bmp->allocPixels();
23 25
24 unsigned char* src_data = 26 unsigned char* src_data =
25 reinterpret_cast<unsigned char*>(bmp->getAddr32(0, 0)); 27 reinterpret_cast<unsigned char*>(bmp->getAddr32(0, 0));
26 for (int i = 0; i < w * h; i++) { 28 for (int i = 0; i < w * h; i++) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // the various delegate methods. Most of these methods are actually never 129 // the various delegate methods. Most of these methods are actually never
128 // called. 130 // called.
129 // TODO(rohitrao): Refactor the tests to override these delegate methods instead 131 // TODO(rohitrao): Refactor the tests to override these delegate methods instead
130 // of subclassing. 132 // of subclassing.
131 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate { 133 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate {
132 public: 134 public:
133 explicit TestFaviconHandlerDelegate(TabContents* tab_contents) 135 explicit TestFaviconHandlerDelegate(TabContents* tab_contents)
134 : tab_contents_(tab_contents) { 136 : tab_contents_(tab_contents) {
135 } 137 }
136 138
137 virtual content::NavigationEntry* GetActiveEntry() { 139 virtual NavigationEntry* GetActiveEntry() {
138 ADD_FAILURE() << "TestFaviconHandlerDelegate::GetActiveEntry() " 140 ADD_FAILURE() << "TestFaviconHandlerDelegate::GetActiveEntry() "
139 << "should never be called in tests."; 141 << "should never be called in tests.";
140 return NULL; 142 return NULL;
141 } 143 }
142 144
143 virtual void StartDownload(int id, const GURL& url, int image_size) { 145 virtual void StartDownload(int id, const GURL& url, int image_size) {
144 ADD_FAILURE() << "TestFaviconHandlerDelegate::StartDownload() " 146 ADD_FAILURE() << "TestFaviconHandlerDelegate::StartDownload() "
145 << "should never be called in tests."; 147 << "should never be called in tests.";
146 } 148 }
147 149
148 virtual void NotifyFaviconUpdated() { 150 virtual void NotifyFaviconUpdated() {
149 tab_contents_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); 151 tab_contents_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB);
150 } 152 }
151 153
152 private: 154 private:
153 TabContents* tab_contents_; // weak 155 TabContents* tab_contents_; // weak
154 }; 156 };
155 157
156 // This class is used to catch the FaviconHandler's download and history 158 // This class is used to catch the FaviconHandler's download and history
157 // request, and also provide the methods to access the FaviconHandler internal. 159 // request, and also provide the methods to access the FaviconHandler internal.
158 class TestFaviconHandler : public FaviconHandler { 160 class TestFaviconHandler : public FaviconHandler {
159 public: 161 public:
160 TestFaviconHandler(const GURL& page_url, 162 TestFaviconHandler(const GURL& page_url,
161 Profile* profile, 163 Profile* profile,
162 FaviconHandlerDelegate* delegate, 164 FaviconHandlerDelegate* delegate,
163 Type type) 165 Type type)
164 : FaviconHandler(profile, delegate, type), 166 : FaviconHandler(profile, delegate, type),
165 download_image_size_(0), 167 download_image_size_(0),
166 entry_(content::NavigationEntry::Create()), 168 entry_(NavigationEntry::Create()),
167 download_id_(0) { 169 download_id_(0) {
168 entry_->SetURL(page_url); 170 entry_->SetURL(page_url);
169 } 171 }
170 172
171 virtual ~TestFaviconHandler() { 173 virtual ~TestFaviconHandler() {
172 } 174 }
173 175
174 HistoryRequestHandler* history_handler() { 176 HistoryRequestHandler* history_handler() {
175 return history_handler_.get(); 177 return history_handler_.get();
176 } 178 }
177 179
178 // This method will take the ownership of the given handler. 180 // This method will take the ownership of the given handler.
179 void set_history_handler(HistoryRequestHandler* handler) { 181 void set_history_handler(HistoryRequestHandler* handler) {
180 history_handler_.reset(handler); 182 history_handler_.reset(handler);
181 } 183 }
182 184
183 DownloadHandler* download_handler() { 185 DownloadHandler* download_handler() {
184 return download_handler_.get(); 186 return download_handler_.get();
185 } 187 }
186 188
187 // This method will take the ownership of the given download_handler. 189 // This method will take the ownership of the given download_handler.
188 void set_download_handler(DownloadHandler* download_handler) { 190 void set_download_handler(DownloadHandler* download_handler) {
189 download_handler_.reset(download_handler); 191 download_handler_.reset(download_handler);
190 } 192 }
191 193
192 virtual content::NavigationEntry* GetEntry() { 194 virtual NavigationEntry* GetEntry() {
193 return entry_.get(); 195 return entry_.get();
194 } 196 }
195 197
196 const std::vector<FaviconURL>& urls() { 198 const std::vector<FaviconURL>& urls() {
197 return urls_; 199 return urls_;
198 } 200 }
199 201
200 void FetchFavicon(const GURL& url) { 202 void FetchFavicon(const GURL& url) {
201 FaviconHandler::FetchFavicon(url); 203 FaviconHandler::FetchFavicon(url);
202 } 204 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { 268 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE {
267 return true; 269 return true;
268 } 270 }
269 271
270 GURL page_url_; 272 GURL page_url_;
271 273
272 GURL download_image_url_; 274 GURL download_image_url_;
273 int download_image_size_; 275 int download_image_size_;
274 276
275 private: 277 private:
276 scoped_ptr<content::NavigationEntry> entry_; 278 scoped_ptr<NavigationEntry> entry_;
277 279
278 // The unique id of a download request. It will be returned to a 280 // The unique id of a download request. It will be returned to a
279 // FaviconHandler. 281 // FaviconHandler.
280 int download_id_; 282 int download_id_;
281 283
282 scoped_ptr<DownloadHandler> download_handler_; 284 scoped_ptr<DownloadHandler> download_handler_;
283 scoped_ptr<HistoryRequestHandler> history_handler_; 285 scoped_ptr<HistoryRequestHandler> history_handler_;
284 286
285 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); 287 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler);
286 }; 288 };
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); 817 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
816 handler->favicon_data_.image_data = data; 818 handler->favicon_data_.image_data = data;
817 819
818 handler->InvokeCallback(); 820 handler->InvokeCallback();
819 821
820 // No download request. 822 // No download request.
821 EXPECT_FALSE(helper.download_handler()); 823 EXPECT_FALSE(helper.download_handler());
822 } 824 }
823 825
824 } // namespace. 826 } // namespace.
OLDNEW
« no previous file with comments | « chrome/browser/favicon/favicon_handler.cc ('k') | chrome/browser/favicon/favicon_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698