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

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; do *not* use mojo in classic ash. 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"
10 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
11 #include "base/command_line.h" 10 #include "base/command_line.h"
12 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/run_loop.h" 13 #include "base/run_loop.h"
15 #include "base/time/time.h" 14 #include "base/time/time.h"
16 #include "chrome/browser/chromeos/customization/customization_document.h" 15 #include "chrome/browser/chromeos/customization/customization_document.h"
17 #include "chrome/browser/chromeos/customization/customization_wallpaper_download er.h" 16 #include "chrome/browser/chromeos/customization/customization_wallpaper_download er.h"
18 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
19 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_test_u tils.h" 18 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_test_u tils.h"
19 #include "chrome/browser/ui/ash/ash_util.h"
20 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/testing_browser_process.h" 21 #include "chrome/test/base/testing_browser_process.h"
22 #include "chromeos/chromeos_switches.h" 22 #include "chromeos/chromeos_switches.h"
23 #include "content/public/common/service_manager_connection.h"
23 #include "net/http/http_response_headers.h" 24 #include "net/http/http_response_headers.h"
24 #include "net/http/http_status_code.h" 25 #include "net/http/http_status_code.h"
25 #include "net/url_request/test_url_fetcher_factory.h" 26 #include "net/url_request/test_url_fetcher_factory.h"
26 #include "net/url_request/url_fetcher_impl.h" 27 #include "net/url_request/url_fetcher_impl.h"
28 #include "services/shell/public/cpp/connector.h"
27 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
28 30
29 namespace chromeos { 31 namespace chromeos {
30 32
31 namespace { 33 namespace {
32 34
33 const char kOEMWallpaperURL[] = "http://somedomain.com/image.png"; 35 const char kOEMWallpaperURL[] = "http://somedomain.com/image.png";
34 36
35 const char kServicesManifest[] = 37 const char kServicesManifest[] =
36 "{" 38 "{"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 base::RunLoop().Run(); 81 base::RunLoop().Run();
80 } 82 }
81 83
82 private: 84 private:
83 bool finished_; 85 bool finished_;
84 WallpaperManager* wallpaper_manager_; 86 WallpaperManager* wallpaper_manager_;
85 87
86 DISALLOW_COPY_AND_ASSIGN(TestWallpaperObserver); 88 DISALLOW_COPY_AND_ASSIGN(TestWallpaperObserver);
87 }; 89 };
88 90
91 // The callback used to retrieve the wallpaper from ash.
92 void GetWallpaperCallback(gfx::ImageSkia* image_out,
93 wallpaper::WallpaperLayout* layout_out,
94 base::Closure callback,
95 const SkBitmap& wallpaper,
96 wallpaper::WallpaperLayout layout) {
97 *image_out = gfx::ImageSkia::CreateFrom1xBitmap(wallpaper);
98 *layout_out = layout;
99 callback.Run();
100 }
101
102 // A helper to synchronously get the wallpaper from ash.
103 void GetWallpaper(gfx::ImageSkia* image_out,
104 wallpaper::WallpaperLayout* layout_out) {
105 auto connection = content::ServiceManagerConnection::GetForProcess();
106 auto connector = connection ? connection->GetConnector() : nullptr;
James Cook 2016/10/14 21:58:02 As before, I don't think these types are complex e
msw 2016/10/17 22:22:47 I reverted these test changes.
107 if (!connector)
108 return;
109
110 ash::mojom::WallpaperControllerPtr wallpaper_controller;
111 // Under mash the WallpaperController interface is in the ash process. In
James Cook 2016/10/14 21:58:02 So does this test no longer exercise the classic a
msw 2016/10/17 22:22:48 I restored the classic ash code path here.
112 // classic ash we provide it to ourself.
113 if (chrome::IsRunningInMash()) {
114 connector->ConnectToInterface("service:ash", &wallpaper_controller);
115 } else {
116 connector->ConnectToInterface("service:content_browser",
117 &wallpaper_controller);
118 }
119 base::RunLoop run_loop;
120 wallpaper_controller->GetWallpaper(base::Bind(
121 &GetWallpaperCallback, image_out, layout_out, run_loop.QuitClosure()));
122 run_loop.Run();
123 }
124
89 } // namespace 125 } // namespace
90 126
91 // This is helper class for net::FakeURLFetcherFactory. 127 // This is helper class for net::FakeURLFetcherFactory.
92 class TestWallpaperImageURLFetcherCallback { 128 class TestWallpaperImageURLFetcherCallback {
93 public: 129 public:
94 TestWallpaperImageURLFetcherCallback( 130 TestWallpaperImageURLFetcherCallback(
95 const GURL& url, 131 const GURL& url,
96 const size_t require_retries, 132 const size_t require_retries,
97 const std::vector<unsigned char>& jpeg_data_raw) 133 const std::vector<unsigned char>& jpeg_data_raw)
98 : url_(url), 134 : url_(url),
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // requests. 249 // requests.
214 std::unique_ptr<net::TestURLFetcherFactory> fallback_fetcher_factory_; 250 std::unique_ptr<net::TestURLFetcherFactory> fallback_fetcher_factory_;
215 std::unique_ptr<net::FakeURLFetcherFactory> fetcher_factory_; 251 std::unique_ptr<net::FakeURLFetcherFactory> fetcher_factory_;
216 252
217 DISALLOW_COPY_AND_ASSIGN(WallpaperImageFetcherFactory); 253 DISALLOW_COPY_AND_ASSIGN(WallpaperImageFetcherFactory);
218 }; 254 };
219 255
220 class CustomizationWallpaperDownloaderBrowserTest 256 class CustomizationWallpaperDownloaderBrowserTest
221 : public InProcessBrowserTest { 257 : public InProcessBrowserTest {
222 public: 258 public:
223 CustomizationWallpaperDownloaderBrowserTest() 259 CustomizationWallpaperDownloaderBrowserTest() {}
224 : controller_(NULL),
225 local_state_(NULL) {
226 }
227
228 ~CustomizationWallpaperDownloaderBrowserTest() override {} 260 ~CustomizationWallpaperDownloaderBrowserTest() override {}
229 261
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 { 262 void SetUpCommandLine(base::CommandLine* command_line) override {
236 command_line->AppendSwitch(chromeos::switches::kLoginManager); 263 command_line->AppendSwitch(chromeos::switches::kLoginManager);
237 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); 264 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
238 } 265 }
239 266
240 void TearDownOnMainThread() override { controller_ = NULL; }
241
242 protected: 267 protected:
243 void CreateCmdlineWallpapers() { 268 void CreateCmdlineWallpapers() {
244 cmdline_wallpaper_dir_.reset(new base::ScopedTempDir); 269 cmdline_wallpaper_dir_.reset(new base::ScopedTempDir);
245 ASSERT_TRUE(cmdline_wallpaper_dir_->CreateUniqueTempDir()); 270 ASSERT_TRUE(cmdline_wallpaper_dir_->CreateUniqueTempDir());
246 wallpaper_manager_test_utils::CreateCmdlineWallpapers( 271 wallpaper_manager_test_utils::CreateCmdlineWallpapers(
247 *cmdline_wallpaper_dir_, &wallpaper_manager_command_line_); 272 *cmdline_wallpaper_dir_, &wallpaper_manager_command_line_);
248 } 273 }
249 274
250 ash::WallpaperController* controller_;
251 PrefService* local_state_;
252 std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_; 275 std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_;
253 276
254 // Directory created by CreateCmdlineWallpapersAndSetFlags() to store default 277 // Directory created by CreateCmdlineWallpapersAndSetFlags() to store default
255 // wallpaper images. 278 // wallpaper images.
256 std::unique_ptr<base::ScopedTempDir> cmdline_wallpaper_dir_; 279 std::unique_ptr<base::ScopedTempDir> cmdline_wallpaper_dir_;
257 280
258 private: 281 private:
259 DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloaderBrowserTest); 282 DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloaderBrowserTest);
260 }; 283 };
261 284
262 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest, 285 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
263 OEMWallpaperIsPresent) { 286 OEMWallpaperIsPresent) {
264 CreateCmdlineWallpapers(); 287 CreateCmdlineWallpapers();
265 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); 288 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
266 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 289 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
290
291 gfx::ImageSkia image;
292 wallpaper::WallpaperLayout layout = wallpaper::NUM_WALLPAPER_LAYOUT;
293 GetWallpaper(&image, &layout);
267 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 294 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
268 controller_->GetWallpaper(), 295 image, wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
269 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
270
271 WallpaperImageFetcherFactory url_factory( 296 WallpaperImageFetcherFactory url_factory(
272 GURL(kOEMWallpaperURL), 297 GURL(kOEMWallpaperURL),
273 wallpaper_manager_test_utils::kWallpaperSize, 298 wallpaper_manager_test_utils::kWallpaperSize,
274 wallpaper_manager_test_utils::kWallpaperSize, 299 wallpaper_manager_test_utils::kWallpaperSize,
275 wallpaper_manager_test_utils::kCustomWallpaperColor, 300 wallpaper_manager_test_utils::kCustomWallpaperColor,
276 0 /* require_retries */); 301 0 /* require_retries */);
277 302
278 TestWallpaperObserver observer(WallpaperManager::Get()); 303 TestWallpaperObserver observer(WallpaperManager::Get());
279 chromeos::ServicesCustomizationDocument* customization = 304 chromeos::ServicesCustomizationDocument* customization =
280 chromeos::ServicesCustomizationDocument::GetInstance(); 305 chromeos::ServicesCustomizationDocument::GetInstance();
281 EXPECT_TRUE( 306 EXPECT_TRUE(
282 customization->LoadManifestFromString(std::string(kServicesManifest))); 307 customization->LoadManifestFromString(std::string(kServicesManifest)));
283 308
284 observer.WaitForWallpaperAnimationFinished(); 309 observer.WaitForWallpaperAnimationFinished();
310 GetWallpaper(&image, &layout);
285 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 311 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
286 controller_->GetWallpaper(), 312 image, wallpaper_manager_test_utils::kCustomWallpaperColor));
287 wallpaper_manager_test_utils::kCustomWallpaperColor));
288 EXPECT_EQ(1U, url_factory.num_attempts()); 313 EXPECT_EQ(1U, url_factory.num_attempts());
289 } 314 }
290 315
291 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest, 316 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
292 OEMWallpaperRetryFetch) { 317 OEMWallpaperRetryFetch) {
293 CreateCmdlineWallpapers(); 318 CreateCmdlineWallpapers();
294 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); 319 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
295 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 320 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
321
322 gfx::ImageSkia image;
323 wallpaper::WallpaperLayout layout = wallpaper::NUM_WALLPAPER_LAYOUT;
324 GetWallpaper(&image, &layout);
296 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 325 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
297 controller_->GetWallpaper(), 326 image, wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
298 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
299 327
300 WallpaperImageFetcherFactory url_factory( 328 WallpaperImageFetcherFactory url_factory(
301 GURL(kOEMWallpaperURL), 329 GURL(kOEMWallpaperURL),
302 wallpaper_manager_test_utils::kWallpaperSize, 330 wallpaper_manager_test_utils::kWallpaperSize,
303 wallpaper_manager_test_utils::kWallpaperSize, 331 wallpaper_manager_test_utils::kWallpaperSize,
304 wallpaper_manager_test_utils::kCustomWallpaperColor, 332 wallpaper_manager_test_utils::kCustomWallpaperColor,
305 1 /* require_retries */); 333 1 /* require_retries */);
306 334
307 TestWallpaperObserver observer(WallpaperManager::Get()); 335 TestWallpaperObserver observer(WallpaperManager::Get());
308 chromeos::ServicesCustomizationDocument* customization = 336 chromeos::ServicesCustomizationDocument* customization =
309 chromeos::ServicesCustomizationDocument::GetInstance(); 337 chromeos::ServicesCustomizationDocument::GetInstance();
310 EXPECT_TRUE( 338 EXPECT_TRUE(
311 customization->LoadManifestFromString(std::string(kServicesManifest))); 339 customization->LoadManifestFromString(std::string(kServicesManifest)));
312 340
313 observer.WaitForWallpaperAnimationFinished(); 341 observer.WaitForWallpaperAnimationFinished();
342 GetWallpaper(&image, &layout);
314 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 343 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
315 controller_->GetWallpaper(), 344 image, wallpaper_manager_test_utils::kCustomWallpaperColor));
316 wallpaper_manager_test_utils::kCustomWallpaperColor));
317 345
318 EXPECT_EQ(2U, url_factory.num_attempts()); 346 EXPECT_EQ(2U, url_factory.num_attempts());
319 } 347 }
320 348
321 } // namespace chromeos 349 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698