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

Unified Diff: ios/web/public/serializable_user_data_manager_unittest.mm

Issue 2687353003: Created SerializableUserDataManager. (Closed)
Patch Set: Eugene's comments Created 3 years, 10 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 | « ios/web/public/serializable_user_data_manager.h ('k') | ios/web/public/test/fakes/test_web_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/public/serializable_user_data_manager_unittest.mm
diff --git a/ios/web/public/serializable_user_data_manager_unittest.mm b/ios/web/public/serializable_user_data_manager_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..90d4019faf4f2ebb334a37fe11f5c96d7d424c68
--- /dev/null
+++ b/ios/web/public/serializable_user_data_manager_unittest.mm
@@ -0,0 +1,64 @@
+// Copyright 2017 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.
+
+#import "ios/web/public/serializable_user_data_manager.h"
+
+#import "base/mac/scoped_nsobject.h"
+#import "ios/web/public/test/fakes/test_web_state.h"
+#import "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+
+namespace {
+// User Data and Key to use for tests.
+NSString* const kTestUserData = @"TestUserData";
+NSString* const kTestUserDataKey = @"TestUserDataKey";
+} // namespace
+
+class SerializableUserDataManagerTest : public PlatformTest {
+ protected:
+ // Convenience getter for the user data manager.
+ web::SerializableUserDataManager* manager() {
+ return web::SerializableUserDataManager::FromWebState(&web_state_);
+ }
+
+ web::TestWebState web_state_;
+};
+
+// Tests that serializable data can be successfully added and read.
+TEST_F(SerializableUserDataManagerTest, SetAndReadData) {
+ manager()->AddSerializableData(kTestUserData, kTestUserDataKey);
+ id value = manager()->GetValueForSerializationKey(kTestUserDataKey);
+ EXPECT_NSEQ(value, kTestUserData);
+}
+
+// Tests that SerializableUserData can successfully encode and decode.
+TEST_F(SerializableUserDataManagerTest, EncodeDecode) {
+ // Create a SerializableUserData instance for the test data.
+ manager()->AddSerializableData(kTestUserData, kTestUserDataKey);
+ std::unique_ptr<web::SerializableUserData> user_data =
+ manager()->CreateSerializableUserData();
+
+ // Archive the serializable user data.
+ base::scoped_nsobject<NSMutableData> data([[NSMutableData alloc] init]);
+ base::scoped_nsobject<NSKeyedArchiver> archiver(
+ [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]);
+ user_data->Encode(archiver);
+ [archiver finishEncoding];
+
+ // Create a new SerializableUserData by unarchiving.
+ base::scoped_nsobject<NSKeyedUnarchiver> unarchiver(
+ [[NSKeyedUnarchiver alloc] initForReadingWithData:data]);
+ std::unique_ptr<web::SerializableUserData> decoded_data =
+ web::SerializableUserData::Create();
+ decoded_data->Decode(unarchiver);
+
+ // Add the decoded user data to a new WebState and verify its contents.
+ web::TestWebState decoded_web_state;
+ web::SerializableUserDataManager* decoded_manager =
+ web::SerializableUserDataManager::FromWebState(&decoded_web_state);
+ decoded_manager->AddSerializableUserData(decoded_data.get());
+ id decoded_value =
+ decoded_manager->GetValueForSerializationKey(kTestUserDataKey);
+ EXPECT_NSEQ(decoded_value, kTestUserData);
+}
« no previous file with comments | « ios/web/public/serializable_user_data_manager.h ('k') | ios/web/public/test/fakes/test_web_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698