| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 browser()->tab_strip_model()->GetActiveWebContents(); | 71 browser()->tab_strip_model()->GetActiveWebContents(); |
| 72 contents_observer_.reset(new ContentsObserver(web_contents)); | 72 contents_observer_.reset(new ContentsObserver(web_contents)); |
| 73 favicon_loader_.reset(new LauncherFaviconLoader(this, web_contents)); | 73 favicon_loader_.reset(new LauncherFaviconLoader(this, web_contents)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // LauncherFaviconLoader::Delegate overrides: | 76 // LauncherFaviconLoader::Delegate overrides: |
| 77 void FaviconUpdated() override { favicon_updated_ = true; } | 77 void FaviconUpdated() override { favicon_updated_ = true; } |
| 78 | 78 |
| 79 protected: | 79 protected: |
| 80 bool NavigateTo(const char* url) { | 80 bool NavigateTo(const char* url) { |
| 81 std::string url_path = base::StringPrintf("files/ash/launcher/%s", url); | 81 std::string url_path = base::StringPrintf("/ash/launcher/%s", url); |
| 82 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(url_path)); | 82 ui_test_utils::NavigateToURL(browser(), |
| 83 embedded_test_server()->GetURL(url_path)); |
| 83 return true; | 84 return true; |
| 84 } | 85 } |
| 85 | 86 |
| 86 bool WaitForContentsLoaded() { | 87 bool WaitForContentsLoaded() { |
| 87 const int64 max_seconds = 10; | 88 const int64 max_seconds = 10; |
| 88 base::Time start_time = base::Time::Now(); | 89 base::Time start_time = base::Time::Now(); |
| 89 while (!(contents_observer_->loaded() && | 90 while (!(contents_observer_->loaded() && |
| 90 contents_observer_->got_favicons())) { | 91 contents_observer_->got_favicons())) { |
| 91 content::RunAllPendingInMessageLoop(); | 92 content::RunAllPendingInMessageLoop(); |
| 92 base::TimeDelta delta = base::Time::Now() - start_time; | 93 base::TimeDelta delta = base::Time::Now() - start_time; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 118 | 119 |
| 119 bool favicon_updated_; | 120 bool favicon_updated_; |
| 120 scoped_ptr<ContentsObserver> contents_observer_; | 121 scoped_ptr<ContentsObserver> contents_observer_; |
| 121 scoped_ptr<LauncherFaviconLoader> favicon_loader_; | 122 scoped_ptr<LauncherFaviconLoader> favicon_loader_; |
| 122 | 123 |
| 123 private: | 124 private: |
| 124 DISALLOW_COPY_AND_ASSIGN(LauncherFaviconLoaderBrowsertest); | 125 DISALLOW_COPY_AND_ASSIGN(LauncherFaviconLoaderBrowsertest); |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, SmallLauncherIcon) { | 128 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, SmallLauncherIcon) { |
| 128 ASSERT_TRUE(test_server()->Start()); | 129 ASSERT_TRUE(embedded_test_server()->Start()); |
| 129 ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html")); | 130 ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html")); |
| 130 EXPECT_TRUE(WaitForContentsLoaded()); | 131 EXPECT_TRUE(WaitForContentsLoaded()); |
| 131 EXPECT_TRUE(WaitForFaviconUpdated()); | 132 EXPECT_TRUE(WaitForFaviconUpdated()); |
| 132 | 133 |
| 133 // No large favicons specified, bitmap should be empty. | 134 // No large favicons specified, bitmap should be empty. |
| 134 EXPECT_TRUE(favicon_loader_->GetFavicon().empty()); | 135 EXPECT_TRUE(favicon_loader_->GetFavicon().empty()); |
| 135 } | 136 } |
| 136 | 137 |
| 137 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, LargeLauncherIcon) { | 138 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, LargeLauncherIcon) { |
| 138 ASSERT_TRUE(test_server()->Start()); | 139 ASSERT_TRUE(embedded_test_server()->Start()); |
| 139 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html")); | 140 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html")); |
| 140 EXPECT_TRUE(WaitForContentsLoaded()); | 141 EXPECT_TRUE(WaitForContentsLoaded()); |
| 141 EXPECT_TRUE(WaitForFaviconUpdated()); | 142 EXPECT_TRUE(WaitForFaviconUpdated()); |
| 142 | 143 |
| 143 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); | 144 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); |
| 144 EXPECT_EQ(128, favicon_loader_->GetFavicon().height()); | 145 EXPECT_EQ(128, favicon_loader_->GetFavicon().height()); |
| 145 } | 146 } |
| 146 | 147 |
| 147 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ManyLauncherIcons) { | 148 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ManyLauncherIcons) { |
| 148 ASSERT_TRUE(test_server()->Start()); | 149 ASSERT_TRUE(embedded_test_server()->Start()); |
| 149 ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html")); | 150 ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html")); |
| 150 EXPECT_TRUE(WaitForContentsLoaded()); | 151 EXPECT_TRUE(WaitForContentsLoaded()); |
| 151 EXPECT_TRUE(WaitForFaviconUpdated()); | 152 EXPECT_TRUE(WaitForFaviconUpdated()); |
| 152 | 153 |
| 153 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); | 154 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); |
| 154 // When multiple favicons are present, the correctly sized icon should be | 155 // When multiple favicons are present, the correctly sized icon should be |
| 155 // chosen. The icons are sized assuming ash::kShelfSize < 128. | 156 // chosen. The icons are sized assuming ash::kShelfSize < 128. |
| 156 EXPECT_GT(128, ash::kShelfSize); | 157 EXPECT_GT(128, ash::kShelfSize); |
| 157 EXPECT_EQ(48, favicon_loader_->GetFavicon().height()); | 158 EXPECT_EQ(48, favicon_loader_->GetFavicon().height()); |
| 158 } | 159 } |
| 159 | 160 |
| 160 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ChangeLauncherIcons) { | 161 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ChangeLauncherIcons) { |
| 161 ASSERT_TRUE(test_server()->Start()); | 162 ASSERT_TRUE(embedded_test_server()->Start()); |
| 162 ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html")); | 163 ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html")); |
| 163 EXPECT_TRUE(WaitForContentsLoaded()); | 164 EXPECT_TRUE(WaitForContentsLoaded()); |
| 164 EXPECT_TRUE(WaitForFaviconUpdated()); | 165 EXPECT_TRUE(WaitForFaviconUpdated()); |
| 165 | 166 |
| 166 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); | 167 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); |
| 167 EXPECT_EQ(48, favicon_loader_->GetFavicon().height()); | 168 EXPECT_EQ(48, favicon_loader_->GetFavicon().height()); |
| 168 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); | 169 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); |
| 169 | 170 |
| 170 ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html")); | 171 ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html")); |
| 171 ASSERT_TRUE(WaitForContentsLoaded()); | 172 ASSERT_TRUE(WaitForContentsLoaded()); |
| 172 EXPECT_TRUE(WaitForFaviconUpdated()); | 173 EXPECT_TRUE(WaitForFaviconUpdated()); |
| 173 | 174 |
| 174 EXPECT_TRUE(favicon_loader_->GetFavicon().empty()); | 175 EXPECT_TRUE(favicon_loader_->GetFavicon().empty()); |
| 175 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); | 176 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); |
| 176 | 177 |
| 177 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html")); | 178 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html")); |
| 178 ASSERT_TRUE(WaitForContentsLoaded()); | 179 ASSERT_TRUE(WaitForContentsLoaded()); |
| 179 EXPECT_TRUE(WaitForFaviconUpdated()); | 180 EXPECT_TRUE(WaitForFaviconUpdated()); |
| 180 | 181 |
| 181 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); | 182 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); |
| 182 EXPECT_EQ(128, favicon_loader_->GetFavicon().height()); | 183 EXPECT_EQ(128, favicon_loader_->GetFavicon().height()); |
| 183 } | 184 } |
| OLD | NEW |