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

Side by Side Diff: components/ntp_snippets/ntp_snippets_database_unittest.cc

Issue 2355393002: New snippets now replace old snippets and do not merge (Closed)
Patch Set: Marc's comments #5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/ntp_snippets/ntp_snippets_database.h" 5 #include "components/ntp_snippets/ntp_snippets_database.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Delete the snippet. 242 // Delete the snippet.
243 db()->DeleteSnippet(snippet->id()); 243 db()->DeleteSnippet(snippet->id());
244 244
245 // Make sure it's gone. 245 // Make sure it's gone.
246 EXPECT_CALL(*this, OnSnippetsLoadedImpl(IsEmpty())); 246 EXPECT_CALL(*this, OnSnippetsLoadedImpl(IsEmpty()));
247 db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded, 247 db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
248 base::Unretained(this))); 248 base::Unretained(this)));
249 base::RunLoop().RunUntilIdle(); 249 base::RunLoop().RunUntilIdle();
250 } 250 }
251 251
252 TEST_F(NTPSnippetsDatabaseTest, DeleteSnippetAlsoDeletesImage) { 252 TEST_F(NTPSnippetsDatabaseTest, DeleteSnippetDoesNotDeleteImage) {
253 CreateDatabase(); 253 CreateDatabase();
254 base::RunLoop().RunUntilIdle(); 254 base::RunLoop().RunUntilIdle();
255 ASSERT_TRUE(db()->IsInitialized()); 255 ASSERT_TRUE(db()->IsInitialized());
256 256
257 std::unique_ptr<NTPSnippet> snippet = CreateTestSnippet(); 257 std::unique_ptr<NTPSnippet> snippet = CreateTestSnippet();
258 std::string image_data("pretty image"); 258 std::string image_data("pretty image");
259 259
260 // Store a snippet and image. 260 // Store a snippet and image.
261 db()->SaveSnippet(*snippet); 261 db()->SaveSnippet(*snippet);
262 db()->SaveImage(snippet->id(), image_data); 262 db()->SaveImage(snippet->id(), image_data);
263 base::RunLoop().RunUntilIdle(); 263 base::RunLoop().RunUntilIdle();
264 264
265 // Make sure they're there. 265 // Make sure they're there.
266 EXPECT_CALL(*this, 266 EXPECT_CALL(*this,
267 OnSnippetsLoadedImpl(ElementsAre(SnippetEq(snippet.get())))); 267 OnSnippetsLoadedImpl(ElementsAre(SnippetEq(snippet.get()))));
268 db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded, 268 db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
269 base::Unretained(this))); 269 base::Unretained(this)));
270 EXPECT_CALL(*this, OnImageLoaded(image_data)); 270 EXPECT_CALL(*this, OnImageLoaded(image_data));
271 db()->LoadImage(snippet->id(), 271 db()->LoadImage(snippet->id(),
272 base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded, 272 base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
273 base::Unretained(this))); 273 base::Unretained(this)));
274 base::RunLoop().RunUntilIdle(); 274 base::RunLoop().RunUntilIdle();
275 275
276 Mock::VerifyAndClearExpectations(this); 276 Mock::VerifyAndClearExpectations(this);
277 277
278 // Delete the snippet. 278 // Delete the snippet.
279 db()->DeleteSnippet(snippet->id()); 279 db()->DeleteSnippet(snippet->id());
280 280
281 // Make sure the image is still there.
282 EXPECT_CALL(*this, OnImageLoaded(image_data));
283 db()->LoadImage(snippet->id(),
284 base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
285 base::Unretained(this)));
286 base::RunLoop().RunUntilIdle();
287 }
288
289 TEST_F(NTPSnippetsDatabaseTest, DeleteImage) {
290 CreateDatabase();
291 base::RunLoop().RunUntilIdle();
292 ASSERT_TRUE(db()->IsInitialized());
293
294 std::unique_ptr<NTPSnippet> snippet = CreateTestSnippet();
295 std::string image_data("pretty image");
296
297 // Store the image.
298 db()->SaveImage(snippet->id(), image_data);
299 base::RunLoop().RunUntilIdle();
300
301 // Make sure the image is there.
302 EXPECT_CALL(*this, OnImageLoaded(image_data));
303 db()->LoadImage(snippet->id(),
304 base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
305 base::Unretained(this)));
306 base::RunLoop().RunUntilIdle();
307
308 Mock::VerifyAndClearExpectations(this);
309
310 // Delete the snippet.
311 db()->DeleteImage(snippet->id());
312
281 // Make sure the image is gone. 313 // Make sure the image is gone.
282 EXPECT_CALL(*this, OnImageLoaded(std::string())); 314 EXPECT_CALL(*this, OnImageLoaded(std::string()));
283 db()->LoadImage(snippet->id(), 315 db()->LoadImage(snippet->id(),
284 base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded, 316 base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
285 base::Unretained(this))); 317 base::Unretained(this)));
286 base::RunLoop().RunUntilIdle(); 318 base::RunLoop().RunUntilIdle();
287 } 319 }
288 320
289 } // namespace ntp_snippets 321 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_database.cc ('k') | components/ntp_snippets/ntp_snippets_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698