OLD | NEW |
1 // Copyright (c) 2012 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/stringprintf.h" |
8 #include "base/time.h" | 9 #include "base/time.h" |
9 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h" | 10 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h" |
10 #include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h" | 11 #include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h" |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_tabstrip.h" | 13 #include "chrome/browser/ui/browser_tabstrip.h" |
13 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
14 #include "chrome/common/favicon_url.h" | |
15 #include "chrome/common/icon_messages.h" | |
16 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
19 #include "content/public/browser/web_contents_delegate.h" | 18 #include "content/public/browser/web_contents_delegate.h" |
20 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 20 #include "content/public/common/favicon_url.h" |
21 #include "net/test/test_server.h" | 21 #include "net/test/test_server.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
| 24 using content::FaviconURL; |
| 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 // Observer class to determine when favicons have completed loading. | 28 // Observer class to determine when favicons have completed loading. |
27 class ContentsObserver : public content::WebContentsObserver { | 29 class ContentsObserver : public content::WebContentsObserver { |
28 public: | 30 public: |
29 explicit ContentsObserver(content::WebContents* web_contents) | 31 explicit ContentsObserver(content::WebContents* web_contents) |
30 : content::WebContentsObserver(web_contents), | 32 : content::WebContentsObserver(web_contents), |
31 got_favicons_(false) { | 33 got_favicons_(false) { |
32 } | 34 } |
33 | 35 |
34 virtual ~ContentsObserver() {} | 36 virtual ~ContentsObserver() {} |
35 | 37 |
36 bool got_favicons() const { return got_favicons_; } | 38 bool got_favicons() const { return got_favicons_; } |
37 void Reset() { | 39 void Reset() { |
38 got_favicons_ = false; | 40 got_favicons_ = false; |
39 } | 41 } |
40 | 42 |
41 // content::WebContentsObserver overrides. | 43 // content::WebContentsObserver overrides. |
42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 44 virtual void DidUpdateFaviconURL(int32 page_id, |
43 bool message_handled = false; // Allow other handlers to receive these. | 45 const std::vector<FaviconURL>& candidates) OVERRIDE { |
44 IPC_BEGIN_MESSAGE_MAP(ContentsObserver, message) | |
45 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | |
46 IPC_MESSAGE_UNHANDLED(message_handled = false) | |
47 IPC_END_MESSAGE_MAP() | |
48 return message_handled; | |
49 } | |
50 | |
51 private: | |
52 void OnUpdateFaviconURL(int32 page_id, | |
53 const std::vector<FaviconURL>& candidates) { | |
54 if (!candidates.empty()) | 46 if (!candidates.empty()) |
55 got_favicons_ = true; | 47 got_favicons_ = true; |
56 } | 48 } |
57 | 49 |
| 50 private: |
58 bool got_favicons_; | 51 bool got_favicons_; |
59 }; | 52 }; |
60 | 53 |
61 } // namespace | 54 } // namespace |
62 | 55 |
63 class LauncherFaviconLoaderBrowsertest : public InProcessBrowserTest { | 56 class LauncherFaviconLoaderBrowsertest : public InProcessBrowserTest { |
64 public: | 57 public: |
65 LauncherFaviconLoaderBrowsertest() | 58 LauncherFaviconLoaderBrowsertest() |
66 : panel_browser_(NULL), | 59 : panel_browser_(NULL), |
67 loader_(NULL), | 60 loader_(NULL), |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 NavigateTo("launcher-smallfavicon.html"); | 181 NavigateTo("launcher-smallfavicon.html"); |
189 EXPECT_TRUE(WaitForFaviconDownloads()); | 182 EXPECT_TRUE(WaitForFaviconDownloads()); |
190 EXPECT_TRUE(favicon_loader->GetFavicon().empty()); | 183 EXPECT_TRUE(favicon_loader->GetFavicon().empty()); |
191 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); | 184 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); |
192 | 185 |
193 NavigateTo("launcher-largefavicon.html"); | 186 NavigateTo("launcher-largefavicon.html"); |
194 EXPECT_TRUE(WaitForFaviconDownloads()); | 187 EXPECT_TRUE(WaitForFaviconDownloads()); |
195 EXPECT_FALSE(favicon_loader->GetFavicon().empty()); | 188 EXPECT_FALSE(favicon_loader->GetFavicon().empty()); |
196 EXPECT_EQ(128, favicon_loader->GetFavicon().height()); | 189 EXPECT_EQ(128, favicon_loader->GetFavicon().height()); |
197 } | 190 } |
OLD | NEW |