| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "ios/web/public/crw_session_storage.h" | 5 #import "ios/web/public/crw_session_storage.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | |
| 8 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 9 #import "ios/web/navigation/navigation_item_impl.h" | 8 #import "ios/web/navigation/navigation_item_impl.h" |
| 10 #import "ios/web/navigation/navigation_item_storage_test_util.h" | 9 #import "ios/web/navigation/navigation_item_storage_test_util.h" |
| 11 #import "ios/web/navigation/serializable_user_data_manager_impl.h" | 10 #import "ios/web/navigation/serializable_user_data_manager_impl.h" |
| 12 #import "ios/web/public/crw_navigation_item_storage.h" | 11 #import "ios/web/public/crw_navigation_item_storage.h" |
| 13 #include "ios/web/public/referrer.h" | 12 #include "ios/web/public/referrer.h" |
| 14 #import "net/base/mac/url_conversions.h" | 13 #import "net/base/mac/url_conversions.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #import "testing/gtest_mac.h" | 15 #import "testing/gtest_mac.h" |
| 17 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
| 18 #include "third_party/ocmock/gtest_support.h" | 17 #include "third_party/ocmock/gtest_support.h" |
| 19 #include "ui/base/page_transition_types.h" | 18 #include "ui/base/page_transition_types.h" |
| 20 | 19 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." |
| 22 #endif |
| 23 |
| 21 namespace { | 24 namespace { |
| 22 // Checks for equality between the item storages in |items1| and |items2|. | 25 // Checks for equality between the item storages in |items1| and |items2|. |
| 23 BOOL ItemStorageListsAreEqual(NSArray* items1, NSArray* items2) { | 26 BOOL ItemStorageListsAreEqual(NSArray* items1, NSArray* items2) { |
| 24 __block BOOL items_are_equal = items1.count == items2.count; | 27 __block BOOL items_are_equal = items1.count == items2.count; |
| 25 if (!items_are_equal) | 28 if (!items_are_equal) |
| 26 return NO; | 29 return NO; |
| 27 [items1 enumerateObjectsUsingBlock:^(CRWNavigationItemStorage* item, | 30 [items1 enumerateObjectsUsingBlock:^(CRWNavigationItemStorage* item, |
| 28 NSUInteger idx, BOOL* stop) { | 31 NSUInteger idx, BOOL* stop) { |
| 29 items_are_equal &= web::ItemStoragesAreEqual(item, items2[idx]); | 32 items_are_equal &= web::ItemStoragesAreEqual(item, items2[idx]); |
| 30 *stop = !items_are_equal; | 33 *stop = !items_are_equal; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 57 | 60 |
| 58 class CRWNSessionStorageTest : public PlatformTest { | 61 class CRWNSessionStorageTest : public PlatformTest { |
| 59 protected: | 62 protected: |
| 60 CRWNSessionStorageTest() | 63 CRWNSessionStorageTest() |
| 61 : session_storage_([[CRWSessionStorage alloc] init]) { | 64 : session_storage_([[CRWSessionStorage alloc] init]) { |
| 62 // Set up |session_storage_|. | 65 // Set up |session_storage_|. |
| 63 [session_storage_ setHasOpener:YES]; | 66 [session_storage_ setHasOpener:YES]; |
| 64 [session_storage_ setLastCommittedItemIndex:4]; | 67 [session_storage_ setLastCommittedItemIndex:4]; |
| 65 [session_storage_ setPreviousItemIndex:3]; | 68 [session_storage_ setPreviousItemIndex:3]; |
| 66 // Create an item storage. | 69 // Create an item storage. |
| 67 base::scoped_nsobject<CRWNavigationItemStorage> item_storage( | 70 CRWNavigationItemStorage* item_storage = |
| 68 [[CRWNavigationItemStorage alloc] init]); | 71 [[CRWNavigationItemStorage alloc] init]; |
| 69 [item_storage setVirtualURL:GURL("http://init.test")]; | 72 [item_storage setVirtualURL:GURL("http://init.test")]; |
| 70 [item_storage setReferrer:web::Referrer(GURL("http://referrer.url"), | 73 [item_storage setReferrer:web::Referrer(GURL("http://referrer.url"), |
| 71 web::ReferrerPolicyDefault)]; | 74 web::ReferrerPolicyDefault)]; |
| 72 [item_storage setTimestamp:base::Time::Now()]; | 75 [item_storage setTimestamp:base::Time::Now()]; |
| 73 [item_storage setTitle:base::SysNSStringToUTF16(@"Title")]; | 76 [item_storage setTitle:base::SysNSStringToUTF16(@"Title")]; |
| 74 [item_storage | 77 [item_storage |
| 75 setDisplayState:web::PageDisplayState(0.0, 0.0, 0.0, 0.0, 0.0)]; | 78 setDisplayState:web::PageDisplayState(0.0, 0.0, 0.0, 0.0, 0.0)]; |
| 76 [item_storage | 79 [item_storage |
| 77 setPOSTData:[@"Test data" dataUsingEncoding:NSUTF8StringEncoding]]; | 80 setPOSTData:[@"Test data" dataUsingEncoding:NSUTF8StringEncoding]]; |
| 78 [item_storage setHTTPRequestHeaders:@{ @"HeaderKey" : @"HeaderValue" }]; | 81 [item_storage setHTTPRequestHeaders:@{ @"HeaderKey" : @"HeaderValue" }]; |
| 79 [session_storage_ setItemStorages:@[ item_storage ]]; | 82 [session_storage_ setItemStorages:@[ item_storage ]]; |
| 80 // Create serializable user data. | 83 // Create serializable user data. |
| 81 std::unique_ptr<web::SerializableUserDataImpl> user_data( | 84 std::unique_ptr<web::SerializableUserDataImpl> user_data( |
| 82 new web::SerializableUserDataImpl( | 85 new web::SerializableUserDataImpl( |
| 83 @{ @"key" : @"value" })); | 86 @{ @"key" : @"value" })); |
| 84 [session_storage_ setSerializableUserData:std::move(user_data)]; | 87 [session_storage_ setSerializableUserData:std::move(user_data)]; |
| 85 } | 88 } |
| 86 | 89 |
| 87 protected: | 90 protected: |
| 88 base::scoped_nsobject<CRWSessionStorage> session_storage_; | 91 CRWSessionStorage* session_storage_; |
| 89 }; | 92 }; |
| 90 | 93 |
| 91 // Tests that unarchiving CRWSessionStorage data results in an equivalent | 94 // Tests that unarchiving CRWSessionStorage data results in an equivalent |
| 92 // storage. | 95 // storage. |
| 93 TEST_F(CRWNSessionStorageTest, EncodeDecode) { | 96 TEST_F(CRWNSessionStorageTest, EncodeDecode) { |
| 94 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:session_storage_]; | 97 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:session_storage_]; |
| 95 id decoded = [NSKeyedUnarchiver unarchiveObjectWithData:data]; | 98 id decoded = [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
| 96 EXPECT_TRUE(SessionStoragesAreEqual(session_storage_, decoded)); | 99 EXPECT_TRUE(SessionStoragesAreEqual(session_storage_, decoded)); |
| 97 } | 100 } |
| OLD | NEW |