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

Side by Side Diff: chrome/browser/chromeos/customization/customization_wallpaper_downloader_browsertest.cc

Issue 2413503002: Cleanup mojo Wallpaper interfaces for mash. (Closed)
Patch Set: Sync and rebase again... Created 4 years, 2 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/common/wallpaper/wallpaper_controller.h" 9 #include "ash/common/wallpaper/wallpaper_controller.h"
10 #include "ash/common/wm_shell.h" 10 #include "ash/common/wm_shell.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 } // namespace 89 } // namespace
90 90
91 // This is helper class for net::FakeURLFetcherFactory. 91 // This is helper class for net::FakeURLFetcherFactory.
92 class TestWallpaperImageURLFetcherCallback { 92 class TestWallpaperImageURLFetcherCallback {
93 public: 93 public:
94 TestWallpaperImageURLFetcherCallback( 94 TestWallpaperImageURLFetcherCallback(
95 const GURL& url, 95 const GURL& url,
96 const size_t require_retries, 96 const size_t require_retries,
97 const std::vector<unsigned char>& jpeg_data_raw) 97 const std::vector<unsigned char>& jpeg_data_raw)
98 : url_(url), 98 : url_(url), require_retries_(require_retries), factory_(nullptr) {
99 require_retries_(require_retries),
100 factory_(NULL) {
101 jpeg_data_.resize(jpeg_data_raw.size()); 99 jpeg_data_.resize(jpeg_data_raw.size());
102 std::copy(jpeg_data_raw.begin(), jpeg_data_raw.end(), jpeg_data_.begin()); 100 std::copy(jpeg_data_raw.begin(), jpeg_data_raw.end(), jpeg_data_.begin());
103 } 101 }
104 102
105 std::unique_ptr<net::FakeURLFetcher> CreateURLFetcher( 103 std::unique_ptr<net::FakeURLFetcher> CreateURLFetcher(
106 const GURL& url, 104 const GURL& url,
107 net::URLFetcherDelegate* delegate, 105 net::URLFetcherDelegate* delegate,
108 const std::string& response_data, 106 const std::string& response_data,
109 net::HttpStatusCode response_code, 107 net::HttpStatusCode response_code,
110 net::URLRequestStatus::Status status) { 108 net::URLRequestStatus::Status status) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 int height, 190 int height,
193 SkColor color, 191 SkColor color,
194 const size_t require_retries) { 192 const size_t require_retries) {
195 std::vector<unsigned char> oem_wallpaper_; 193 std::vector<unsigned char> oem_wallpaper_;
196 ASSERT_TRUE(wallpaper_manager_test_utils::CreateJPEGImage( 194 ASSERT_TRUE(wallpaper_manager_test_utils::CreateJPEGImage(
197 width, height, color, &oem_wallpaper_)); 195 width, height, color, &oem_wallpaper_));
198 196
199 url_callback_.reset(new TestWallpaperImageURLFetcherCallback( 197 url_callback_.reset(new TestWallpaperImageURLFetcherCallback(
200 url, require_retries, oem_wallpaper_)); 198 url, require_retries, oem_wallpaper_));
201 fallback_fetcher_factory_.reset(new net::TestURLFetcherFactory); 199 fallback_fetcher_factory_.reset(new net::TestURLFetcherFactory);
202 net::URLFetcherImpl::set_factory(NULL); 200 net::URLFetcherImpl::set_factory(nullptr);
203 fetcher_factory_.reset(new net::FakeURLFetcherFactory( 201 fetcher_factory_.reset(new net::FakeURLFetcherFactory(
204 fallback_fetcher_factory_.get(), 202 fallback_fetcher_factory_.get(),
205 base::Bind(&TestWallpaperImageURLFetcherCallback::CreateURLFetcher, 203 base::Bind(&TestWallpaperImageURLFetcherCallback::CreateURLFetcher,
206 base::Unretained(url_callback_.get())))); 204 base::Unretained(url_callback_.get()))));
207 url_callback_->Initialize(fetcher_factory_.get()); 205 url_callback_->Initialize(fetcher_factory_.get());
208 } 206 }
209 207
210 std::unique_ptr<TestWallpaperImageURLFetcherCallback> url_callback_; 208 std::unique_ptr<TestWallpaperImageURLFetcherCallback> url_callback_;
211 209
212 // Use a test factory as a fallback so we don't have to deal with other 210 // Use a test factory as a fallback so we don't have to deal with other
213 // requests. 211 // requests.
214 std::unique_ptr<net::TestURLFetcherFactory> fallback_fetcher_factory_; 212 std::unique_ptr<net::TestURLFetcherFactory> fallback_fetcher_factory_;
215 std::unique_ptr<net::FakeURLFetcherFactory> fetcher_factory_; 213 std::unique_ptr<net::FakeURLFetcherFactory> fetcher_factory_;
216 214
217 DISALLOW_COPY_AND_ASSIGN(WallpaperImageFetcherFactory); 215 DISALLOW_COPY_AND_ASSIGN(WallpaperImageFetcherFactory);
218 }; 216 };
219 217
220 class CustomizationWallpaperDownloaderBrowserTest 218 class CustomizationWallpaperDownloaderBrowserTest
221 : public InProcessBrowserTest { 219 : public InProcessBrowserTest {
222 public: 220 public:
223 CustomizationWallpaperDownloaderBrowserTest() 221 CustomizationWallpaperDownloaderBrowserTest() {}
224 : controller_(NULL),
225 local_state_(NULL) {
226 }
227
228 ~CustomizationWallpaperDownloaderBrowserTest() override {} 222 ~CustomizationWallpaperDownloaderBrowserTest() override {}
229 223
230 void SetUpOnMainThread() override {
231 controller_ = ash::WmShell::Get()->wallpaper_controller();
232 local_state_ = g_browser_process->local_state();
233 }
234
235 void SetUpCommandLine(base::CommandLine* command_line) override { 224 void SetUpCommandLine(base::CommandLine* command_line) override {
236 command_line->AppendSwitch(chromeos::switches::kLoginManager); 225 command_line->AppendSwitch(chromeos::switches::kLoginManager);
237 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); 226 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
238 } 227 }
239 228
240 void TearDownOnMainThread() override { controller_ = NULL; }
241
242 protected: 229 protected:
243 void CreateCmdlineWallpapers() { 230 void CreateCmdlineWallpapers() {
244 cmdline_wallpaper_dir_.reset(new base::ScopedTempDir); 231 cmdline_wallpaper_dir_.reset(new base::ScopedTempDir);
245 ASSERT_TRUE(cmdline_wallpaper_dir_->CreateUniqueTempDir()); 232 ASSERT_TRUE(cmdline_wallpaper_dir_->CreateUniqueTempDir());
246 wallpaper_manager_test_utils::CreateCmdlineWallpapers( 233 wallpaper_manager_test_utils::CreateCmdlineWallpapers(
247 *cmdline_wallpaper_dir_, &wallpaper_manager_command_line_); 234 *cmdline_wallpaper_dir_, &wallpaper_manager_command_line_);
248 } 235 }
249 236
250 ash::WallpaperController* controller_;
251 PrefService* local_state_;
252 std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_; 237 std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_;
253 238
254 // Directory created by CreateCmdlineWallpapersAndSetFlags() to store default 239 // Directory created by CreateCmdlineWallpapersAndSetFlags() to store default
255 // wallpaper images. 240 // wallpaper images.
256 std::unique_ptr<base::ScopedTempDir> cmdline_wallpaper_dir_; 241 std::unique_ptr<base::ScopedTempDir> cmdline_wallpaper_dir_;
257 242
258 private: 243 private:
259 DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloaderBrowserTest); 244 DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloaderBrowserTest);
260 }; 245 };
261 246
262 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest, 247 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
263 OEMWallpaperIsPresent) { 248 OEMWallpaperIsPresent) {
264 CreateCmdlineWallpapers(); 249 CreateCmdlineWallpapers();
265 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); 250 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
266 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 251 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
267 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 252 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
268 controller_->GetWallpaper(), 253 ash::WmShell::Get()->wallpaper_controller()->GetWallpaper(),
269 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); 254 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
270 255
271 WallpaperImageFetcherFactory url_factory( 256 WallpaperImageFetcherFactory url_factory(
272 GURL(kOEMWallpaperURL), 257 GURL(kOEMWallpaperURL),
273 wallpaper_manager_test_utils::kWallpaperSize, 258 wallpaper_manager_test_utils::kWallpaperSize,
274 wallpaper_manager_test_utils::kWallpaperSize, 259 wallpaper_manager_test_utils::kWallpaperSize,
275 wallpaper_manager_test_utils::kCustomWallpaperColor, 260 wallpaper_manager_test_utils::kCustomWallpaperColor,
276 0 /* require_retries */); 261 0 /* require_retries */);
277 262
278 TestWallpaperObserver observer(WallpaperManager::Get()); 263 TestWallpaperObserver observer(WallpaperManager::Get());
279 chromeos::ServicesCustomizationDocument* customization = 264 chromeos::ServicesCustomizationDocument* customization =
280 chromeos::ServicesCustomizationDocument::GetInstance(); 265 chromeos::ServicesCustomizationDocument::GetInstance();
281 EXPECT_TRUE( 266 EXPECT_TRUE(
282 customization->LoadManifestFromString(std::string(kServicesManifest))); 267 customization->LoadManifestFromString(std::string(kServicesManifest)));
283 268
284 observer.WaitForWallpaperAnimationFinished(); 269 observer.WaitForWallpaperAnimationFinished();
285 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 270 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
286 controller_->GetWallpaper(), 271 ash::WmShell::Get()->wallpaper_controller()->GetWallpaper(),
287 wallpaper_manager_test_utils::kCustomWallpaperColor)); 272 wallpaper_manager_test_utils::kCustomWallpaperColor));
288 EXPECT_EQ(1U, url_factory.num_attempts()); 273 EXPECT_EQ(1U, url_factory.num_attempts());
289 } 274 }
290 275
291 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest, 276 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
292 OEMWallpaperRetryFetch) { 277 OEMWallpaperRetryFetch) {
293 CreateCmdlineWallpapers(); 278 CreateCmdlineWallpapers();
294 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); 279 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
295 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 280 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
296 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 281 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
297 controller_->GetWallpaper(), 282 ash::WmShell::Get()->wallpaper_controller()->GetWallpaper(),
298 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); 283 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
299 284
300 WallpaperImageFetcherFactory url_factory( 285 WallpaperImageFetcherFactory url_factory(
301 GURL(kOEMWallpaperURL), 286 GURL(kOEMWallpaperURL),
302 wallpaper_manager_test_utils::kWallpaperSize, 287 wallpaper_manager_test_utils::kWallpaperSize,
303 wallpaper_manager_test_utils::kWallpaperSize, 288 wallpaper_manager_test_utils::kWallpaperSize,
304 wallpaper_manager_test_utils::kCustomWallpaperColor, 289 wallpaper_manager_test_utils::kCustomWallpaperColor,
305 1 /* require_retries */); 290 1 /* require_retries */);
306 291
307 TestWallpaperObserver observer(WallpaperManager::Get()); 292 TestWallpaperObserver observer(WallpaperManager::Get());
308 chromeos::ServicesCustomizationDocument* customization = 293 chromeos::ServicesCustomizationDocument* customization =
309 chromeos::ServicesCustomizationDocument::GetInstance(); 294 chromeos::ServicesCustomizationDocument::GetInstance();
310 EXPECT_TRUE( 295 EXPECT_TRUE(
311 customization->LoadManifestFromString(std::string(kServicesManifest))); 296 customization->LoadManifestFromString(std::string(kServicesManifest)));
312 297
313 observer.WaitForWallpaperAnimationFinished(); 298 observer.WaitForWallpaperAnimationFinished();
314 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 299 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
315 controller_->GetWallpaper(), 300 ash::WmShell::Get()->wallpaper_controller()->GetWallpaper(),
316 wallpaper_manager_test_utils::kCustomWallpaperColor)); 301 wallpaper_manager_test_utils::kCustomWallpaperColor));
317 302
318 EXPECT_EQ(2U, url_factory.num_attempts()); 303 EXPECT_EQ(2U, url_factory.num_attempts());
319 } 304 }
320 305
321 } // namespace chromeos 306 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/chrome_interface_factory.cc ('k') | chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698