OLD | NEW |
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/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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), |
99 require_retries_(require_retries), | 99 require_retries_(require_retries), |
100 factory_(NULL) { | 100 factory_(NULL) { |
101 jpeg_data_.resize(jpeg_data_raw.size()); | 101 jpeg_data_.resize(jpeg_data_raw.size()); |
102 std::copy(jpeg_data_raw.begin(), jpeg_data_raw.end(), jpeg_data_.begin()); | 102 std::copy(jpeg_data_raw.begin(), jpeg_data_raw.end(), jpeg_data_.begin()); |
103 } | 103 } |
104 | 104 |
105 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher( | 105 std::unique_ptr<net::FakeURLFetcher> CreateURLFetcher( |
106 const GURL& url, | 106 const GURL& url, |
107 net::URLFetcherDelegate* delegate, | 107 net::URLFetcherDelegate* delegate, |
108 const std::string& response_data, | 108 const std::string& response_data, |
109 net::HttpStatusCode response_code, | 109 net::HttpStatusCode response_code, |
110 net::URLRequestStatus::Status status) { | 110 net::URLRequestStatus::Status status) { |
111 chromeos::ServicesCustomizationDocument* customization = | 111 chromeos::ServicesCustomizationDocument* customization = |
112 chromeos::ServicesCustomizationDocument::GetInstance(); | 112 chromeos::ServicesCustomizationDocument::GetInstance(); |
113 customization->wallpaper_downloader_for_testing() | 113 customization->wallpaper_downloader_for_testing() |
114 ->set_retry_delay_for_testing( | 114 ->set_retry_delay_for_testing( |
115 base::TimeDelta::FromMilliseconds(kDownloadRetryIntervalMS)); | 115 base::TimeDelta::FromMilliseconds(kDownloadRetryIntervalMS)); |
(...skipping 11 matching lines...) Expand all Loading... |
127 << "Retry too fast. Actual interval " << current_delay.InSecondsF() | 127 << "Retry too fast. Actual interval " << current_delay.InSecondsF() |
128 << " seconds, but expected at least " << base_interval | 128 << " seconds, but expected at least " << base_interval |
129 << " * (retry=" << retry | 129 << " * (retry=" << retry |
130 << " * retry)= " << base_interval * retry * retry << " seconds."; | 130 << " * retry)= " << base_interval * retry * retry << " seconds."; |
131 } | 131 } |
132 if (attempts_.size() > require_retries_) { | 132 if (attempts_.size() > require_retries_) { |
133 response_code = net::HTTP_OK; | 133 response_code = net::HTTP_OK; |
134 status = net::URLRequestStatus::SUCCESS; | 134 status = net::URLRequestStatus::SUCCESS; |
135 factory_->SetFakeResponse(url, response_data, response_code, status); | 135 factory_->SetFakeResponse(url, response_data, response_code, status); |
136 } | 136 } |
137 scoped_ptr<net::FakeURLFetcher> fetcher(new net::FakeURLFetcher( | 137 std::unique_ptr<net::FakeURLFetcher> fetcher(new net::FakeURLFetcher( |
138 url, delegate, response_data, response_code, status)); | 138 url, delegate, response_data, response_code, status)); |
139 scoped_refptr<net::HttpResponseHeaders> download_headers = | 139 scoped_refptr<net::HttpResponseHeaders> download_headers = |
140 new net::HttpResponseHeaders(std::string()); | 140 new net::HttpResponseHeaders(std::string()); |
141 download_headers->AddHeader("Content-Type: image/jpeg"); | 141 download_headers->AddHeader("Content-Type: image/jpeg"); |
142 fetcher->set_response_headers(download_headers); | 142 fetcher->set_response_headers(download_headers); |
143 return fetcher; | 143 return fetcher; |
144 } | 144 } |
145 | 145 |
146 void Initialize(net::FakeURLFetcherFactory* factory) { | 146 void Initialize(net::FakeURLFetcherFactory* factory) { |
147 factory_ = factory; | 147 factory_ = factory; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 url, require_retries, oem_wallpaper_)); | 200 url, require_retries, oem_wallpaper_)); |
201 fallback_fetcher_factory_.reset(new net::TestURLFetcherFactory); | 201 fallback_fetcher_factory_.reset(new net::TestURLFetcherFactory); |
202 net::URLFetcherImpl::set_factory(NULL); | 202 net::URLFetcherImpl::set_factory(NULL); |
203 fetcher_factory_.reset(new net::FakeURLFetcherFactory( | 203 fetcher_factory_.reset(new net::FakeURLFetcherFactory( |
204 fallback_fetcher_factory_.get(), | 204 fallback_fetcher_factory_.get(), |
205 base::Bind(&TestWallpaperImageURLFetcherCallback::CreateURLFetcher, | 205 base::Bind(&TestWallpaperImageURLFetcherCallback::CreateURLFetcher, |
206 base::Unretained(url_callback_.get())))); | 206 base::Unretained(url_callback_.get())))); |
207 url_callback_->Initialize(fetcher_factory_.get()); | 207 url_callback_->Initialize(fetcher_factory_.get()); |
208 } | 208 } |
209 | 209 |
210 scoped_ptr<TestWallpaperImageURLFetcherCallback> url_callback_; | 210 std::unique_ptr<TestWallpaperImageURLFetcherCallback> url_callback_; |
211 | 211 |
212 // Use a test factory as a fallback so we don't have to deal with other | 212 // Use a test factory as a fallback so we don't have to deal with other |
213 // requests. | 213 // requests. |
214 scoped_ptr<net::TestURLFetcherFactory> fallback_fetcher_factory_; | 214 std::unique_ptr<net::TestURLFetcherFactory> fallback_fetcher_factory_; |
215 scoped_ptr<net::FakeURLFetcherFactory> fetcher_factory_; | 215 std::unique_ptr<net::FakeURLFetcherFactory> fetcher_factory_; |
216 | 216 |
217 DISALLOW_COPY_AND_ASSIGN(WallpaperImageFetcherFactory); | 217 DISALLOW_COPY_AND_ASSIGN(WallpaperImageFetcherFactory); |
218 }; | 218 }; |
219 | 219 |
220 class CustomizationWallpaperDownloaderBrowserTest | 220 class CustomizationWallpaperDownloaderBrowserTest |
221 : public InProcessBrowserTest { | 221 : public InProcessBrowserTest { |
222 public: | 222 public: |
223 CustomizationWallpaperDownloaderBrowserTest() | 223 CustomizationWallpaperDownloaderBrowserTest() |
224 : controller_(NULL), | 224 : controller_(NULL), |
225 local_state_(NULL) { | 225 local_state_(NULL) { |
(...skipping 16 matching lines...) Expand all Loading... |
242 protected: | 242 protected: |
243 void CreateCmdlineWallpapers() { | 243 void CreateCmdlineWallpapers() { |
244 cmdline_wallpaper_dir_.reset(new base::ScopedTempDir); | 244 cmdline_wallpaper_dir_.reset(new base::ScopedTempDir); |
245 ASSERT_TRUE(cmdline_wallpaper_dir_->CreateUniqueTempDir()); | 245 ASSERT_TRUE(cmdline_wallpaper_dir_->CreateUniqueTempDir()); |
246 wallpaper_manager_test_utils::CreateCmdlineWallpapers( | 246 wallpaper_manager_test_utils::CreateCmdlineWallpapers( |
247 *cmdline_wallpaper_dir_, &wallpaper_manager_command_line_); | 247 *cmdline_wallpaper_dir_, &wallpaper_manager_command_line_); |
248 } | 248 } |
249 | 249 |
250 ash::DesktopBackgroundController* controller_; | 250 ash::DesktopBackgroundController* controller_; |
251 PrefService* local_state_; | 251 PrefService* local_state_; |
252 scoped_ptr<base::CommandLine> wallpaper_manager_command_line_; | 252 std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_; |
253 | 253 |
254 // Directory created by CreateCmdlineWallpapersAndSetFlags() to store default | 254 // Directory created by CreateCmdlineWallpapersAndSetFlags() to store default |
255 // wallpaper images. | 255 // wallpaper images. |
256 scoped_ptr<base::ScopedTempDir> cmdline_wallpaper_dir_; | 256 std::unique_ptr<base::ScopedTempDir> cmdline_wallpaper_dir_; |
257 | 257 |
258 private: | 258 private: |
259 DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloaderBrowserTest); | 259 DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloaderBrowserTest); |
260 }; | 260 }; |
261 | 261 |
262 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest, | 262 IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest, |
263 OEMWallpaperIsPresent) { | 263 OEMWallpaperIsPresent) { |
264 CreateCmdlineWallpapers(); | 264 CreateCmdlineWallpapers(); |
265 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); | 265 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); |
266 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 266 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 312 |
313 observer.WaitForWallpaperAnimationFinished(); | 313 observer.WaitForWallpaperAnimationFinished(); |
314 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | 314 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( |
315 controller_->GetWallpaper(), | 315 controller_->GetWallpaper(), |
316 wallpaper_manager_test_utils::kCustomWallpaperColor)); | 316 wallpaper_manager_test_utils::kCustomWallpaperColor)); |
317 | 317 |
318 EXPECT_EQ(2U, url_factory.num_attempts()); | 318 EXPECT_EQ(2U, url_factory.num_attempts()); |
319 } | 319 } |
320 | 320 |
321 } // namespace chromeos | 321 } // namespace chromeos |
OLD | NEW |