OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" | |
9 #include "content/public/browser/invalidate_type.h" | 8 #include "content/public/browser/invalidate_type.h" |
10 #include "content/public/browser/navigation_entry.h" | 9 #include "content/public/browser/navigation_entry.h" |
11 #include "content/public/browser/favicon_status.h" | 10 #include "content/public/browser/favicon_status.h" |
| 11 #include "content/public/browser/web_contents.h" |
12 #include "ui/gfx/codec/png_codec.h" | 12 #include "ui/gfx/codec/png_codec.h" |
13 #include "ui/gfx/favicon_size.h" | 13 #include "ui/gfx/favicon_size.h" |
14 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
15 | 15 |
16 class TestFaviconHandler; | 16 class TestFaviconHandler; |
17 | 17 |
18 using content::NavigationEntry; | 18 using content::NavigationEntry; |
| 19 using content::WebContents; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Fill the given bmp with valid png data. | 23 // Fill the given bmp with valid png data. |
23 void FillDataToBitmap(int w, int h, SkBitmap* bmp) { | 24 void FillDataToBitmap(int w, int h, SkBitmap* bmp) { |
24 bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h); | 25 bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
25 bmp->allocPixels(); | 26 bmp->allocPixels(); |
26 | 27 |
27 unsigned char* src_data = | 28 unsigned char* src_data = |
28 reinterpret_cast<unsigned char*>(bmp->getAddr32(0, 0)); | 29 reinterpret_cast<unsigned char*>(bmp->getAddr32(0, 0)); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } // namespace | 127 } // namespace |
127 | 128 |
128 | 129 |
129 // This class is used as a temporary hack to provide working implementations of | 130 // This class is used as a temporary hack to provide working implementations of |
130 // the various delegate methods. Most of these methods are actually never | 131 // the various delegate methods. Most of these methods are actually never |
131 // called. | 132 // called. |
132 // TODO(rohitrao): Refactor the tests to override these delegate methods instead | 133 // TODO(rohitrao): Refactor the tests to override these delegate methods instead |
133 // of subclassing. | 134 // of subclassing. |
134 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate { | 135 class TestFaviconHandlerDelegate : public FaviconHandlerDelegate { |
135 public: | 136 public: |
136 explicit TestFaviconHandlerDelegate(TabContents* tab_contents) | 137 explicit TestFaviconHandlerDelegate(WebContents* tab_contents) |
137 : tab_contents_(tab_contents) { | 138 : tab_contents_(tab_contents) { |
138 } | 139 } |
139 | 140 |
140 virtual NavigationEntry* GetActiveEntry() { | 141 virtual NavigationEntry* GetActiveEntry() { |
141 ADD_FAILURE() << "TestFaviconHandlerDelegate::GetActiveEntry() " | 142 ADD_FAILURE() << "TestFaviconHandlerDelegate::GetActiveEntry() " |
142 << "should never be called in tests."; | 143 << "should never be called in tests."; |
143 return NULL; | 144 return NULL; |
144 } | 145 } |
145 | 146 |
146 virtual void StartDownload(int id, const GURL& url, int image_size) { | 147 virtual void StartDownload(int id, const GURL& url, int image_size) { |
147 ADD_FAILURE() << "TestFaviconHandlerDelegate::StartDownload() " | 148 ADD_FAILURE() << "TestFaviconHandlerDelegate::StartDownload() " |
148 << "should never be called in tests."; | 149 << "should never be called in tests."; |
149 } | 150 } |
150 | 151 |
151 virtual void NotifyFaviconUpdated() { | 152 virtual void NotifyFaviconUpdated() { |
152 tab_contents_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 153 tab_contents_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
153 } | 154 } |
154 | 155 |
155 private: | 156 private: |
156 TabContents* tab_contents_; // weak | 157 WebContents* tab_contents_; // weak |
157 }; | 158 }; |
158 | 159 |
159 // This class is used to catch the FaviconHandler's download and history | 160 // This class is used to catch the FaviconHandler's download and history |
160 // request, and also provide the methods to access the FaviconHandler internal. | 161 // request, and also provide the methods to access the FaviconHandler internal. |
161 class TestFaviconHandler : public FaviconHandler { | 162 class TestFaviconHandler : public FaviconHandler { |
162 public: | 163 public: |
163 TestFaviconHandler(const GURL& page_url, | 164 TestFaviconHandler(const GURL& page_url, |
164 Profile* profile, | 165 Profile* profile, |
165 FaviconHandlerDelegate* delegate, | 166 FaviconHandlerDelegate* delegate, |
166 Type type) | 167 Type type) |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | 819 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
819 handler->favicon_data_.image_data = data; | 820 handler->favicon_data_.image_data = data; |
820 | 821 |
821 handler->InvokeCallback(); | 822 handler->InvokeCallback(); |
822 | 823 |
823 // No download request. | 824 // No download request. |
824 EXPECT_FALSE(helper.download_handler()); | 825 EXPECT_FALSE(helper.download_handler()); |
825 } | 826 } |
826 | 827 |
827 } // namespace. | 828 } // namespace. |
OLD | NEW |