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

Unified Diff: ios/web/navigation/crw_navigation_item_storage_unittest.mm

Issue 2664113003: Moved serialization out of CRWSessionEntry. (Closed)
Patch Set: Eugene's comments Created 3 years, 11 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/BUILD.gn ('k') | ios/web/navigation/crw_session_entry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/navigation/crw_navigation_item_storage_unittest.mm
diff --git a/ios/web/navigation/crw_navigation_item_storage_unittest.mm b/ios/web/navigation/crw_navigation_item_storage_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..e89049d88a4e6a8459635af09455b8903f25b1ef
--- /dev/null
+++ b/ios/web/navigation/crw_navigation_item_storage_unittest.mm
@@ -0,0 +1,116 @@
+// 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/crw_navigation_item_storage.h"
+
+#import <Foundation/Foundation.h>
+#include <stdint.h>
+
+#include <utility>
+
+#import "base/mac/scoped_nsobject.h"
+#include "base/strings/sys_string_conversions.h"
+#import "ios/web/navigation/navigation_item_impl.h"
+#include "ios/web/public/referrer.h"
+#import "net/base/mac/url_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#import "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+#include "third_party/ocmock/gtest_support.h"
+#include "ui/base/page_transition_types.h"
+
+namespace {
+
+// Checks equality between item1 and item2.
+BOOL ItemStoragesAreEqual(CRWNavigationItemStorage* item1,
+ CRWNavigationItemStorage* item2) {
+ return item1.virtualURL == item2.virtualURL &&
+ item1.referrer.url == item2.referrer.url &&
+ item1.referrer.policy == item2.referrer.policy &&
+ item1.timestamp == item2.timestamp && item1.title == item2.title &&
+ item1.displayState == item2.displayState &&
+ item1.shouldSkipRepostFormConfirmation ==
+ item2.shouldSkipRepostFormConfirmation &&
+ item1.overridingUserAgent == item2.overridingUserAgent &&
+ [item1.POSTData isEqualToData:item2.POSTData] &&
+ [item1.HTTPRequestHeaders
+ isEqualToDictionary:item2.HTTPRequestHeaders];
+}
+} // namespace
+
+class CRWNavigationItemStorageTest : public PlatformTest {
+ protected:
+ CRWNavigationItemStorageTest()
+ : item_storage_([[CRWNavigationItemStorage alloc] init]) {
+ // Set up |item_storage_|.
+ [item_storage_ setVirtualURL:GURL("http://init.test")];
+ [item_storage_ setReferrer:web::Referrer(GURL("http://referrer.url"),
+ web::ReferrerPolicyDefault)];
+ [item_storage_ setTimestamp:base::Time::Now()];
+ [item_storage_ setTitle:base::SysNSStringToUTF16(@"Title")];
+ [item_storage_
+ setDisplayState:web::PageDisplayState(0.0, 0.0, 0.0, 0.0, 0.0)];
+ [item_storage_
+ setPOSTData:[@"Test data" dataUsingEncoding:NSUTF8StringEncoding]];
+ [item_storage_ setHTTPRequestHeaders:@{ @"HeaderKey" : @"HeaderValue" }];
+ }
+
+ // Convenience getter to facilitate dot notation in tests.
+ CRWNavigationItemStorage* item_storage() { return item_storage_; }
+
+ protected:
+ base::scoped_nsobject<CRWNavigationItemStorage> item_storage_;
+};
+
+// Tests initializing with the legacy keys.
+TEST_F(CRWNavigationItemStorageTest, InitWithCoderLegacy) {
+ NSURL* virtualURL = net::NSURLWithGURL(item_storage().virtualURL);
+ NSURL* referrerURL = net::NSURLWithGURL(item_storage().referrer.url);
+ NSString* title = base::SysUTF16ToNSString(item_storage().title);
+ // Legacy NavigationItems don't persist timestamp.
+ item_storage().timestamp = base::Time::FromCFAbsoluteTime(0);
+
+ // Set up archiver and unarchiver.
+ base::scoped_nsobject<NSMutableData> data([[NSMutableData alloc] init]);
+ base::scoped_nsobject<NSKeyedArchiver> archiver(
+ [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]);
+ [archiver encodeObject:virtualURL
+ forKey:web::kNavigationItemStorageURLDeperecatedKey];
+ [archiver encodeObject:referrerURL
+ forKey:web::kNavigationItemStorageReferrerURLDeprecatedKey];
+ [archiver encodeObject:title forKey:web::kNavigationItemStorageTitleKey];
+ NSDictionary* display_state_dict =
+ item_storage().displayState.GetSerialization();
+ [archiver encodeObject:display_state_dict
+ forKey:web::kNavigationItemStoragePageDisplayStateKey];
+ BOOL overriding_user_agent = item_storage().overridingUserAgent;
+ [archiver encodeBool:overriding_user_agent
+ forKey:web::kNavigationItemStorageUseDesktopUserAgentKey];
+ NSDictionary* request_headers = item_storage().HTTPRequestHeaders;
+ [archiver encodeObject:request_headers
+ forKey:web::kNavigationItemStorageHTTPRequestHeadersKey];
+ [archiver encodeObject:item_storage().POSTData
+ forKey:web::kNavigationItemStoragePOSTDataKey];
+ BOOL skip_repost_form_confirmation =
+ item_storage().shouldSkipRepostFormConfirmation;
+ [archiver
+ encodeBool:skip_repost_form_confirmation
+ forKey:web::kNavigationItemStorageSkipRepostFormConfirmationKey];
+ [archiver finishEncoding];
+ base::scoped_nsobject<NSKeyedUnarchiver> unarchiver(
+ [[NSKeyedUnarchiver alloc] initForReadingWithData:data]);
+
+ // Create a CRWNavigationItemStorage and verify that it is equivalent.
+ base::scoped_nsobject<CRWNavigationItemStorage> new_storage(
+ [[CRWNavigationItemStorage alloc] initWithCoder:unarchiver]);
+ EXPECT_TRUE(ItemStoragesAreEqual(item_storage(), new_storage.get()));
+}
+
+// Tests that unarchiving CRWNavigationItemStorage data results in an equivalent
+// storage.
+TEST_F(CRWNavigationItemStorageTest, EncodeDecode) {
+ NSData* data = [NSKeyedArchiver archivedDataWithRootObject:item_storage()];
+ id decoded = [NSKeyedUnarchiver unarchiveObjectWithData:data];
+ EXPECT_TRUE(ItemStoragesAreEqual(item_storage(), decoded));
+}
« no previous file with comments | « ios/web/BUILD.gn ('k') | ios/web/navigation/crw_session_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698