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

Unified Diff: chrome/browser/safe_browsing/incident_reporting/platform_state_store_unittest.cc

Issue 1243293003: Platform-specific prune state storage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prune1
Patch Set: moved uninstall cleanup to separate cl Created 5 years, 3 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
Index: chrome/browser/safe_browsing/incident_reporting/platform_state_store_unittest.cc
diff --git a/chrome/browser/safe_browsing/incident_reporting/platform_state_store_unittest.cc b/chrome/browser/safe_browsing/incident_reporting/platform_state_store_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9ee1faad45c8b2671ba830a72a26191258a44471
--- /dev/null
+++ b/chrome/browser/safe_browsing/incident_reporting/platform_state_store_unittest.cc
@@ -0,0 +1,77 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/safe_browsing/incident_reporting/platform_state_store.h"
+
+#if defined(USE_PLATFORM_STATE_STORE)
+
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace safe_browsing {
+namespace platform_state_store {
+
+namespace {
+
+// The serialized form of the dict created by CreateTestIncidentsSentPref.
+const uint8_t kTestData[] = {
+ 0x0a, 0x19, 0x08, 0x00, 0x12, 0x15, 0x0a, 0x09, 0x0a, 0x04, 0x77,
+ 0x68, 0x61, 0x3f, 0x10, 0x94, 0x4d, 0x0a, 0x08, 0x0a, 0x04, 0x77,
+ 0x68, 0x61, 0x61, 0x10, 0x00, 0x0a, 0x1a, 0x08, 0x02, 0x12, 0x16,
+ 0x0a, 0x09, 0x0a, 0x05, 0x62, 0x6c, 0x6f, 0x72, 0x66, 0x10, 0x05,
+ 0x0a, 0x09, 0x0a, 0x04, 0x73, 0x70, 0x61, 0x6d, 0x10, 0xd2, 0x09
+};
+
+// Returns a dict with some sample data in it.
+scoped_ptr<base::DictionaryValue> CreateTestIncidentsSentPref() {
+ scoped_ptr<base::DictionaryValue> incidents_sent(new base::DictionaryValue);
+
+ scoped_ptr<base::DictionaryValue> type_dict(new base::DictionaryValue);
+ type_dict->SetStringWithoutPathExpansion("spam", "1234");
+ type_dict->SetStringWithoutPathExpansion("blorf", "5");
+ incidents_sent->SetWithoutPathExpansion("2", type_dict.release());
+
+ type_dict.reset(new base::DictionaryValue);
+ type_dict->SetStringWithoutPathExpansion("whaa", "0");
+ type_dict->SetStringWithoutPathExpansion("wha?", "9876");
+ incidents_sent->SetWithoutPathExpansion("0", type_dict.release());
+
+ return incidents_sent.Pass();
+}
+
+} // namespace
+
+// Tests that DeserializeIncidentsSent handles an empty payload properly.
+TEST(PlatformStateStoreTest, DeserializeEmpty) {
+ scoped_ptr<base::DictionaryValue> deserialized(new base::DictionaryValue);
+ PlatformStateStoreLoadResult load_result =
+ DeserializeIncidentsSent(std::string(), deserialized.get());
+ ASSERT_EQ(PlatformStateStoreLoadResult::SUCCESS, load_result);
+ ASSERT_TRUE(deserialized->empty());
+}
+
+// Tests that serialize followed by deserialize doesn't lose data.
+TEST(PlatformStateStoreTest, RoundTrip) {
+ scoped_ptr<base::DictionaryValue> incidents_sent(
+ CreateTestIncidentsSentPref());
+ std::string data;
+
+ SerializeIncidentsSent(incidents_sent.get(), &data);
+
+ // Make sure the serialized data matches expectations to ensure compatibility.
+ ASSERT_EQ(std::string(reinterpret_cast<const char*>(&kTestData[0]),
+ sizeof(kTestData)), data);
+
+ scoped_ptr<base::DictionaryValue> deserialized(new base::DictionaryValue);
+ PlatformStateStoreLoadResult load_result =
+ DeserializeIncidentsSent(data, deserialized.get());
+ ASSERT_EQ(PlatformStateStoreLoadResult::SUCCESS, load_result);
+ ASSERT_TRUE(deserialized->Equals(incidents_sent.get()));
+}
+
+} // namespace platform_state_store
+} // namespace safe_browsing
+
+#endif // USE_PLATFORM_STATE_STORE

Powered by Google App Engine
This is Rietveld 408576698