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

Unified Diff: components/ntp_snippets/ntp_snippets_database_unittest.cc

Issue 2079833002: [NTP Snippets] Extend NTPSnippetsDatabase tests for images (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cache_images
Patch Set: review Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/ntp_snippets_database_unittest.cc
diff --git a/components/ntp_snippets/ntp_snippets_database_unittest.cc b/components/ntp_snippets/ntp_snippets_database_unittest.cc
index 5a7cf570240facbeb590a6c89fe3ab5c248147a7..1640d43e31344bdc49fb2f206bc13388a5eadcda 100644
--- a/components/ntp_snippets/ntp_snippets_database_unittest.cc
+++ b/components/ntp_snippets/ntp_snippets_database_unittest.cc
@@ -83,10 +83,11 @@ class NTPSnippetsDatabaseTest : public testing::Test {
void OnSnippetsLoaded(NTPSnippet::PtrVector snippets) {
OnSnippetsLoadedImpl(snippets);
}
-
MOCK_METHOD1(OnSnippetsLoadedImpl,
void(const NTPSnippet::PtrVector& snippets));
+ MOCK_METHOD1(OnImageLoaded, void(std::string));
+
private:
base::MessageLoop message_loop_;
base::ScopedTempDir database_dir_;
@@ -109,10 +110,15 @@ TEST_F(NTPSnippetsDatabaseTest, LoadBeforeInit) {
CreateDatabase();
EXPECT_FALSE(db()->IsInitialized());
+ // Start a snippet and image load before the DB is initialized.
db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
base::Unretained(this)));
+ db()->LoadImage("id", base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
+ base::Unretained(this)));
+ // They should be serviced once initialization finishes.
EXPECT_CALL(*this, OnSnippetsLoadedImpl(_));
+ EXPECT_CALL(*this, OnImageLoaded(_));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(db()->IsInitialized());
}
@@ -127,10 +133,12 @@ TEST_F(NTPSnippetsDatabaseTest, LoadAfterInit) {
Mock::VerifyAndClearExpectations(this);
+ EXPECT_CALL(*this, OnSnippetsLoadedImpl(_));
db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
base::Unretained(this)));
-
- EXPECT_CALL(*this, OnSnippetsLoadedImpl(_));
+ EXPECT_CALL(*this, OnImageLoaded(_));
+ db()->LoadImage("id", base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
+ base::Unretained(this)));
base::RunLoop().RunUntilIdle();
}
@@ -140,27 +148,52 @@ TEST_F(NTPSnippetsDatabaseTest, Save) {
ASSERT_TRUE(db()->IsInitialized());
std::unique_ptr<NTPSnippet> snippet = CreateTestSnippet();
+ std::string image_data("pretty image");
+ // Store a snippet and an image.
db()->SaveSnippet(*snippet);
- base::RunLoop().RunUntilIdle();
-
- db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
- base::Unretained(this)));
+ db()->SaveImage(snippet->id(), image_data);
+ // Make sure they're there.
EXPECT_CALL(*this,
OnSnippetsLoadedImpl(ElementsAre(SnippetEq(snippet.get()))));
+ db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
+ base::Unretained(this)));
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(this);
- // The snippet should still exist after recreating the database.
+ EXPECT_CALL(*this, OnImageLoaded(image_data));
+ db()->LoadImage(snippet->id(),
+ base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
+ base::Unretained(this)));
+ base::RunLoop().RunUntilIdle();
+}
+
+TEST_F(NTPSnippetsDatabaseTest, SavePersist) {
CreateDatabase();
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(db()->IsInitialized());
- db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
- base::Unretained(this)));
+ std::unique_ptr<NTPSnippet> snippet = CreateTestSnippet();
+ std::string image_data("pretty image");
+
+ // Store a snippet and an image.
+ db()->SaveSnippet(*snippet);
+ db()->SaveImage(snippet->id(), image_data);
+ base::RunLoop().RunUntilIdle();
+
+ // They should still exist after recreating the database.
+ CreateDatabase();
EXPECT_CALL(*this,
OnSnippetsLoadedImpl(ElementsAre(SnippetEq(snippet.get()))));
+ db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
+ base::Unretained(this)));
+ EXPECT_CALL(*this, OnImageLoaded(image_data));
+ db()->LoadImage(snippet->id(),
+ base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
+ base::Unretained(this)));
base::RunLoop().RunUntilIdle();
}
@@ -171,20 +204,19 @@ TEST_F(NTPSnippetsDatabaseTest, Update) {
std::unique_ptr<NTPSnippet> snippet = CreateTestSnippet();
+ // Store a snippet.
db()->SaveSnippet(*snippet);
- base::RunLoop().RunUntilIdle();
+ // Change it.
const std::string text("some text");
snippet->set_snippet(text);
-
db()->SaveSnippet(*snippet);
- base::RunLoop().RunUntilIdle();
-
- db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
- base::Unretained(this)));
+ // Make sure we get the updated version.
EXPECT_CALL(*this,
OnSnippetsLoadedImpl(ElementsAre(SnippetEq(snippet.get()))));
+ db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
+ base::Unretained(this)));
base::RunLoop().RunUntilIdle();
}
@@ -195,16 +227,62 @@ TEST_F(NTPSnippetsDatabaseTest, Delete) {
std::unique_ptr<NTPSnippet> snippet = CreateTestSnippet();
+ // Store a snippet.
db()->SaveSnippet(*snippet);
+
+ // Make sure it's there.
+ EXPECT_CALL(*this,
+ OnSnippetsLoadedImpl(ElementsAre(SnippetEq(snippet.get()))));
+ db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
+ base::Unretained(this)));
base::RunLoop().RunUntilIdle();
+ Mock::VerifyAndClearExpectations(this);
+
+ // Delete the snippet.
db()->DeleteSnippet(snippet->id());
+
+ // Make sure it's gone.
+ EXPECT_CALL(*this, OnSnippetsLoadedImpl(IsEmpty()));
+ db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
+ base::Unretained(this)));
base::RunLoop().RunUntilIdle();
+}
+TEST_F(NTPSnippetsDatabaseTest, DeleteSnippetAlsoDeletesImage) {
+ CreateDatabase();
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(db()->IsInitialized());
+
+ std::unique_ptr<NTPSnippet> snippet = CreateTestSnippet();
+ std::string image_data("pretty image");
+
+ // Store a snippet and image.
+ db()->SaveSnippet(*snippet);
+ db()->SaveImage(snippet->id(), image_data);
+ base::RunLoop().RunUntilIdle();
+
+ // Make sure they're there.
+ EXPECT_CALL(*this,
+ OnSnippetsLoadedImpl(ElementsAre(SnippetEq(snippet.get()))));
db()->LoadSnippets(base::Bind(&NTPSnippetsDatabaseTest::OnSnippetsLoaded,
base::Unretained(this)));
+ EXPECT_CALL(*this, OnImageLoaded(image_data));
+ db()->LoadImage(snippet->id(),
+ base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
+ base::Unretained(this)));
+ base::RunLoop().RunUntilIdle();
- EXPECT_CALL(*this, OnSnippetsLoadedImpl(IsEmpty()));
+ Mock::VerifyAndClearExpectations(this);
+
+ // Delete the snippet.
+ db()->DeleteSnippet(snippet->id());
+
+ // Make sure the image is gone.
+ EXPECT_CALL(*this, OnImageLoaded(std::string()));
+ db()->LoadImage(snippet->id(),
+ base::Bind(&NTPSnippetsDatabaseTest::OnImageLoaded,
+ base::Unretained(this)));
base::RunLoop().RunUntilIdle();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698