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 "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h" |
6 | 6 |
7 #include "ash/shelf/shelf_constants.h" | 7 #include "ash/shelf/shelf_constants.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // Observer class to determine when favicons have completed loading. | 23 // Observer class to determine when favicons have completed loading. |
24 class ContentsObserver : public WebContentsObserver { | 24 class ContentsObserver : public WebContentsObserver { |
25 public: | 25 public: |
26 explicit ContentsObserver(WebContents* web_contents) | 26 explicit ContentsObserver(WebContents* web_contents) |
27 : WebContentsObserver(web_contents), | 27 : WebContentsObserver(web_contents), |
28 loaded_(false), | 28 loaded_(false), |
29 got_favicons_(false) { | 29 got_favicons_(false) { |
30 } | 30 } |
31 | 31 |
32 virtual ~ContentsObserver() {} | 32 ~ContentsObserver() override {} |
33 | 33 |
34 void Reset() { | 34 void Reset() { |
35 got_favicons_ = false; | 35 got_favicons_ = false; |
36 } | 36 } |
37 | 37 |
38 bool loaded() const { return loaded_; } | 38 bool loaded() const { return loaded_; } |
39 bool got_favicons() const { return got_favicons_; } | 39 bool got_favicons() const { return got_favicons_; } |
40 | 40 |
41 // WebContentsObserver overrides. | 41 // WebContentsObserver overrides. |
42 virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 42 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
43 const GURL& validated_url) override { | 43 const GURL& validated_url) override { |
44 loaded_ = true; | 44 loaded_ = true; |
45 } | 45 } |
46 | 46 |
47 virtual void DidUpdateFaviconURL( | 47 void DidUpdateFaviconURL( |
48 const std::vector<content::FaviconURL>& candidates) override { | 48 const std::vector<content::FaviconURL>& candidates) override { |
49 if (!candidates.empty()) | 49 if (!candidates.empty()) |
50 got_favicons_ = true; | 50 got_favicons_ = true; |
51 } | 51 } |
52 | 52 |
53 private: | 53 private: |
54 bool loaded_; | 54 bool loaded_; |
55 bool got_favicons_; | 55 bool got_favicons_; |
56 }; | 56 }; |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 class LauncherFaviconLoaderBrowsertest | 60 class LauncherFaviconLoaderBrowsertest |
61 : public InProcessBrowserTest, | 61 : public InProcessBrowserTest, |
62 public LauncherFaviconLoader::Delegate { | 62 public LauncherFaviconLoader::Delegate { |
63 public: | 63 public: |
64 LauncherFaviconLoaderBrowsertest() : favicon_updated_(false) { | 64 LauncherFaviconLoaderBrowsertest() : favicon_updated_(false) { |
65 } | 65 } |
66 | 66 |
67 virtual ~LauncherFaviconLoaderBrowsertest() { | 67 ~LauncherFaviconLoaderBrowsertest() override {} |
68 } | |
69 | 68 |
70 virtual void SetUpOnMainThread() override { | 69 void SetUpOnMainThread() override { |
71 WebContents* web_contents = | 70 WebContents* web_contents = |
72 browser()->tab_strip_model()->GetActiveWebContents(); | 71 browser()->tab_strip_model()->GetActiveWebContents(); |
73 contents_observer_.reset(new ContentsObserver(web_contents)); | 72 contents_observer_.reset(new ContentsObserver(web_contents)); |
74 favicon_loader_.reset(new LauncherFaviconLoader(this, web_contents)); | 73 favicon_loader_.reset(new LauncherFaviconLoader(this, web_contents)); |
75 } | 74 } |
76 | 75 |
77 // LauncherFaviconLoader::Delegate overrides: | 76 // LauncherFaviconLoader::Delegate overrides: |
78 virtual void FaviconUpdated() override { | 77 void FaviconUpdated() override { favicon_updated_ = true; } |
79 favicon_updated_ = true; | |
80 } | |
81 | 78 |
82 protected: | 79 protected: |
83 bool NavigateTo(const char* url) { | 80 bool NavigateTo(const char* url) { |
84 std::string url_path = base::StringPrintf("files/ash/launcher/%s", url); | 81 std::string url_path = base::StringPrintf("files/ash/launcher/%s", url); |
85 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(url_path)); | 82 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(url_path)); |
86 return true; | 83 return true; |
87 } | 84 } |
88 | 85 |
89 bool WaitForContentsLoaded() { | 86 bool WaitForContentsLoaded() { |
90 const int64 max_seconds = 10; | 87 const int64 max_seconds = 10; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 EXPECT_TRUE(favicon_loader_->GetFavicon().empty()); | 174 EXPECT_TRUE(favicon_loader_->GetFavicon().empty()); |
178 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); | 175 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); |
179 | 176 |
180 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html")); | 177 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html")); |
181 ASSERT_TRUE(WaitForContentsLoaded()); | 178 ASSERT_TRUE(WaitForContentsLoaded()); |
182 EXPECT_TRUE(WaitForFaviconUpdated()); | 179 EXPECT_TRUE(WaitForFaviconUpdated()); |
183 | 180 |
184 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); | 181 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); |
185 EXPECT_EQ(128, favicon_loader_->GetFavicon().height()); | 182 EXPECT_EQ(128, favicon_loader_->GetFavicon().height()); |
186 } | 183 } |
OLD | NEW |