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 namespace { | 24 namespace { |
25 | 25 |
26 // Observer class to determine when favicons have completed loading. | 26 // Observer class to determine when favicons have completed loading. |
27 class ContentsObserver : public content::WebContentsObserver { | 27 class ContentsObserver : public content::WebContentsObserver { |
28 public: | 28 public: |
29 explicit ContentsObserver(content::WebContents* web_contents) | 29 explicit ContentsObserver(content::WebContents* web_contents) |
30 : content::WebContentsObserver(web_contents), | 30 : content::WebContentsObserver(web_contents), |
31 got_favicons_(false) { | 31 got_favicons_(false) { |
32 } | 32 } |
33 | 33 |
34 virtual ~ContentsObserver() {} | 34 virtual ~ContentsObserver() {} |
35 | 35 |
36 bool got_favicons() const { return got_favicons_; } | 36 bool got_favicons() const { return got_favicons_; } |
37 void Reset() { | 37 void Reset() { |
38 got_favicons_ = false; | 38 got_favicons_ = false; |
39 } | 39 } |
40 | 40 |
41 // content::WebContentsObserver overrides. | 41 // content::WebContentsObserver overrides. |
42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 42 virtual void DidUpdateFaviconURL(int32 page_id, |
43 bool message_handled = false; // Allow other handlers to receive these. | 43 const std::vector<content::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()) | 44 if (!candidates.empty()) |
55 got_favicons_ = true; | 45 got_favicons_ = true; |
56 } | 46 } |
57 | 47 |
| 48 private: |
58 bool got_favicons_; | 49 bool got_favicons_; |
59 }; | 50 }; |
60 | 51 |
61 } // namespace | 52 } // namespace |
62 | 53 |
63 class LauncherFaviconLoaderBrowsertest : public InProcessBrowserTest { | 54 class LauncherFaviconLoaderBrowsertest : public InProcessBrowserTest { |
64 public: | 55 public: |
65 LauncherFaviconLoaderBrowsertest() | 56 LauncherFaviconLoaderBrowsertest() |
66 : panel_browser_(NULL), | 57 : panel_browser_(NULL), |
67 loader_(NULL), | 58 loader_(NULL), |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 NavigateTo("launcher-smallfavicon.html"); | 179 NavigateTo("launcher-smallfavicon.html"); |
189 EXPECT_TRUE(WaitForFaviconDownloads()); | 180 EXPECT_TRUE(WaitForFaviconDownloads()); |
190 EXPECT_TRUE(favicon_loader->GetFavicon().empty()); | 181 EXPECT_TRUE(favicon_loader->GetFavicon().empty()); |
191 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); | 182 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); |
192 | 183 |
193 NavigateTo("launcher-largefavicon.html"); | 184 NavigateTo("launcher-largefavicon.html"); |
194 EXPECT_TRUE(WaitForFaviconDownloads()); | 185 EXPECT_TRUE(WaitForFaviconDownloads()); |
195 EXPECT_FALSE(favicon_loader->GetFavicon().empty()); | 186 EXPECT_FALSE(favicon_loader->GetFavicon().empty()); |
196 EXPECT_EQ(128, favicon_loader->GetFavicon().height()); | 187 EXPECT_EQ(128, favicon_loader->GetFavicon().height()); |
197 } | 188 } |
OLD | NEW |