Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
17 18
18 using content::WebContents; 19 using content::WebContents;
19 using content::WebContentsObserver; 20 using content::WebContentsObserver;
20 21
21 namespace { 22 namespace {
22 23
23 // Observer class to determine when favicons have completed loading. 24 // Observer class to determine when favicons have completed loading.
24 class ContentsObserver : public WebContentsObserver { 25 class ContentsObserver : public WebContentsObserver {
25 public: 26 public:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 browser()->tab_strip_model()->GetActiveWebContents(); 72 browser()->tab_strip_model()->GetActiveWebContents();
72 contents_observer_.reset(new ContentsObserver(web_contents)); 73 contents_observer_.reset(new ContentsObserver(web_contents));
73 favicon_loader_.reset(new LauncherFaviconLoader(this, web_contents)); 74 favicon_loader_.reset(new LauncherFaviconLoader(this, web_contents));
74 } 75 }
75 76
76 // LauncherFaviconLoader::Delegate overrides: 77 // LauncherFaviconLoader::Delegate overrides:
77 void FaviconUpdated() override { favicon_updated_ = true; } 78 void FaviconUpdated() override { favicon_updated_ = true; }
78 79
79 protected: 80 protected:
80 bool NavigateTo(const char* url) { 81 bool NavigateTo(const char* url) {
81 std::string url_path = base::StringPrintf("files/ash/launcher/%s", url); 82 std::string url_path = base::StringPrintf("/ash/launcher/%s", url);
82 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(url_path)); 83 ui_test_utils::NavigateToURL(browser(),
84 embedded_test_server()->GetURL(url_path));
83 return true; 85 return true;
84 } 86 }
85 87
86 bool WaitForContentsLoaded() { 88 bool WaitForContentsLoaded() {
87 const int64 max_seconds = 10; 89 const int64 max_seconds = 10;
88 base::Time start_time = base::Time::Now(); 90 base::Time start_time = base::Time::Now();
89 while (!(contents_observer_->loaded() && 91 while (!(contents_observer_->loaded() &&
90 contents_observer_->got_favicons())) { 92 contents_observer_->got_favicons())) {
91 content::RunAllPendingInMessageLoop(); 93 content::RunAllPendingInMessageLoop();
92 base::TimeDelta delta = base::Time::Now() - start_time; 94 base::TimeDelta delta = base::Time::Now() - start_time;
(...skipping 25 matching lines...) Expand all
118 120
119 bool favicon_updated_; 121 bool favicon_updated_;
120 scoped_ptr<ContentsObserver> contents_observer_; 122 scoped_ptr<ContentsObserver> contents_observer_;
121 scoped_ptr<LauncherFaviconLoader> favicon_loader_; 123 scoped_ptr<LauncherFaviconLoader> favicon_loader_;
122 124
123 private: 125 private:
124 DISALLOW_COPY_AND_ASSIGN(LauncherFaviconLoaderBrowsertest); 126 DISALLOW_COPY_AND_ASSIGN(LauncherFaviconLoaderBrowsertest);
125 }; 127 };
126 128
127 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, SmallLauncherIcon) { 129 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, SmallLauncherIcon) {
128 ASSERT_TRUE(test_server()->Start()); 130 ASSERT_TRUE(embedded_test_server()->Start());
129 ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html")); 131 ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html"));
130 EXPECT_TRUE(WaitForContentsLoaded()); 132 EXPECT_TRUE(WaitForContentsLoaded());
131 EXPECT_TRUE(WaitForFaviconUpdated()); 133 EXPECT_TRUE(WaitForFaviconUpdated());
132 134
133 // No large favicons specified, bitmap should be empty. 135 // No large favicons specified, bitmap should be empty.
134 EXPECT_TRUE(favicon_loader_->GetFavicon().empty()); 136 EXPECT_TRUE(favicon_loader_->GetFavicon().empty());
135 } 137 }
136 138
137 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, LargeLauncherIcon) { 139 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, LargeLauncherIcon) {
138 ASSERT_TRUE(test_server()->Start()); 140 ASSERT_TRUE(embedded_test_server()->Start());
139 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html")); 141 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html"));
140 EXPECT_TRUE(WaitForContentsLoaded()); 142 EXPECT_TRUE(WaitForContentsLoaded());
141 EXPECT_TRUE(WaitForFaviconUpdated()); 143 EXPECT_TRUE(WaitForFaviconUpdated());
142 144
143 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); 145 EXPECT_FALSE(favicon_loader_->GetFavicon().empty());
144 EXPECT_EQ(128, favicon_loader_->GetFavicon().height()); 146 EXPECT_EQ(128, favicon_loader_->GetFavicon().height());
145 } 147 }
146 148
147 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ManyLauncherIcons) { 149 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ManyLauncherIcons) {
148 ASSERT_TRUE(test_server()->Start()); 150 ASSERT_TRUE(embedded_test_server()->Start());
149 ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html")); 151 ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html"));
150 EXPECT_TRUE(WaitForContentsLoaded()); 152 EXPECT_TRUE(WaitForContentsLoaded());
151 EXPECT_TRUE(WaitForFaviconUpdated()); 153 EXPECT_TRUE(WaitForFaviconUpdated());
152 154
153 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); 155 EXPECT_FALSE(favicon_loader_->GetFavicon().empty());
154 // When multiple favicons are present, the correctly sized icon should be 156 // When multiple favicons are present, the correctly sized icon should be
155 // chosen. The icons are sized assuming ash::kShelfSize < 128. 157 // chosen. The icons are sized assuming ash::kShelfSize < 128.
156 EXPECT_GT(128, ash::kShelfSize); 158 EXPECT_GT(128, ash::kShelfSize);
157 EXPECT_EQ(48, favicon_loader_->GetFavicon().height()); 159 EXPECT_EQ(48, favicon_loader_->GetFavicon().height());
158 } 160 }
159 161
160 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ChangeLauncherIcons) { 162 IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ChangeLauncherIcons) {
161 ASSERT_TRUE(test_server()->Start()); 163 ASSERT_TRUE(embedded_test_server()->Start());
162 ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html")); 164 ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html"));
163 EXPECT_TRUE(WaitForContentsLoaded()); 165 EXPECT_TRUE(WaitForContentsLoaded());
164 EXPECT_TRUE(WaitForFaviconUpdated()); 166 EXPECT_TRUE(WaitForFaviconUpdated());
165 167
166 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); 168 EXPECT_FALSE(favicon_loader_->GetFavicon().empty());
167 EXPECT_EQ(48, favicon_loader_->GetFavicon().height()); 169 EXPECT_EQ(48, favicon_loader_->GetFavicon().height());
168 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); 170 ASSERT_NO_FATAL_FAILURE(ResetDownloads());
169 171
170 ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html")); 172 ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html"));
171 ASSERT_TRUE(WaitForContentsLoaded()); 173 ASSERT_TRUE(WaitForContentsLoaded());
172 EXPECT_TRUE(WaitForFaviconUpdated()); 174 EXPECT_TRUE(WaitForFaviconUpdated());
173 175
174 EXPECT_TRUE(favicon_loader_->GetFavicon().empty()); 176 EXPECT_TRUE(favicon_loader_->GetFavicon().empty());
175 ASSERT_NO_FATAL_FAILURE(ResetDownloads()); 177 ASSERT_NO_FATAL_FAILURE(ResetDownloads());
176 178
177 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html")); 179 ASSERT_TRUE(NavigateTo("launcher-largefavicon.html"));
178 ASSERT_TRUE(WaitForContentsLoaded()); 180 ASSERT_TRUE(WaitForContentsLoaded());
179 EXPECT_TRUE(WaitForFaviconUpdated()); 181 EXPECT_TRUE(WaitForFaviconUpdated());
180 182
181 EXPECT_FALSE(favicon_loader_->GetFavicon().empty()); 183 EXPECT_FALSE(favicon_loader_->GetFavicon().empty());
182 EXPECT_EQ(128, favicon_loader_->GetFavicon().height()); 184 EXPECT_EQ(128, favicon_loader_->GetFavicon().height());
183 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698