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_navigation_item_storage.h" | 5 #import "ios/web/public/crw_navigation_item_storage.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 18 matching lines...) Expand all Loading... |
29 [item_storage_ setVirtualURL:GURL("http://init.test")]; | 29 [item_storage_ setVirtualURL:GURL("http://init.test")]; |
30 [item_storage_ setReferrer:web::Referrer(GURL("http://referrer.url"), | 30 [item_storage_ setReferrer:web::Referrer(GURL("http://referrer.url"), |
31 web::ReferrerPolicyDefault)]; | 31 web::ReferrerPolicyDefault)]; |
32 [item_storage_ setTimestamp:base::Time::Now()]; | 32 [item_storage_ setTimestamp:base::Time::Now()]; |
33 [item_storage_ setTitle:base::SysNSStringToUTF16(@"Title")]; | 33 [item_storage_ setTitle:base::SysNSStringToUTF16(@"Title")]; |
34 [item_storage_ | 34 [item_storage_ |
35 setDisplayState:web::PageDisplayState(0.0, 0.0, 0.0, 0.0, 0.0)]; | 35 setDisplayState:web::PageDisplayState(0.0, 0.0, 0.0, 0.0, 0.0)]; |
36 [item_storage_ | 36 [item_storage_ |
37 setPOSTData:[@"Test data" dataUsingEncoding:NSUTF8StringEncoding]]; | 37 setPOSTData:[@"Test data" dataUsingEncoding:NSUTF8StringEncoding]]; |
38 [item_storage_ setHTTPRequestHeaders:@{ @"HeaderKey" : @"HeaderValue" }]; | 38 [item_storage_ setHTTPRequestHeaders:@{ @"HeaderKey" : @"HeaderValue" }]; |
| 39 [item_storage_ setUserAgentType:web::UserAgentType::DESKTOP]; |
39 } | 40 } |
40 | 41 |
41 // Convenience getter to facilitate dot notation in tests. | 42 // Convenience getter to facilitate dot notation in tests. |
42 CRWNavigationItemStorage* item_storage() { return item_storage_; } | 43 CRWNavigationItemStorage* item_storage() { return item_storage_; } |
43 | 44 |
44 protected: | 45 protected: |
45 base::scoped_nsobject<CRWNavigationItemStorage> item_storage_; | 46 base::scoped_nsobject<CRWNavigationItemStorage> item_storage_; |
46 }; | 47 }; |
47 | 48 |
48 // Tests initializing with the legacy keys. | 49 // Tests initializing with the legacy keys. |
(...skipping 10 matching lines...) Expand all Loading... |
59 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]); | 60 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]); |
60 [archiver encodeObject:virtualURL | 61 [archiver encodeObject:virtualURL |
61 forKey:web::kNavigationItemStorageURLDeperecatedKey]; | 62 forKey:web::kNavigationItemStorageURLDeperecatedKey]; |
62 [archiver encodeObject:referrerURL | 63 [archiver encodeObject:referrerURL |
63 forKey:web::kNavigationItemStorageReferrerURLDeprecatedKey]; | 64 forKey:web::kNavigationItemStorageReferrerURLDeprecatedKey]; |
64 [archiver encodeObject:title forKey:web::kNavigationItemStorageTitleKey]; | 65 [archiver encodeObject:title forKey:web::kNavigationItemStorageTitleKey]; |
65 NSDictionary* display_state_dict = | 66 NSDictionary* display_state_dict = |
66 item_storage().displayState.GetSerialization(); | 67 item_storage().displayState.GetSerialization(); |
67 [archiver encodeObject:display_state_dict | 68 [archiver encodeObject:display_state_dict |
68 forKey:web::kNavigationItemStoragePageDisplayStateKey]; | 69 forKey:web::kNavigationItemStoragePageDisplayStateKey]; |
69 BOOL overriding_user_agent = item_storage().overridingUserAgent; | 70 [archiver |
70 [archiver encodeBool:overriding_user_agent | 71 encodeBool:YES |
71 forKey:web::kNavigationItemStorageUseDesktopUserAgentKey]; | 72 forKey:web::kNavigationItemStorageUseDesktopUserAgentDeprecatedKey]; |
72 NSDictionary* request_headers = item_storage().HTTPRequestHeaders; | 73 NSDictionary* request_headers = item_storage().HTTPRequestHeaders; |
73 [archiver encodeObject:request_headers | 74 [archiver encodeObject:request_headers |
74 forKey:web::kNavigationItemStorageHTTPRequestHeadersKey]; | 75 forKey:web::kNavigationItemStorageHTTPRequestHeadersKey]; |
75 [archiver encodeObject:item_storage().POSTData | 76 [archiver encodeObject:item_storage().POSTData |
76 forKey:web::kNavigationItemStoragePOSTDataKey]; | 77 forKey:web::kNavigationItemStoragePOSTDataKey]; |
77 BOOL skip_repost_form_confirmation = | 78 BOOL skip_repost_form_confirmation = |
78 item_storage().shouldSkipRepostFormConfirmation; | 79 item_storage().shouldSkipRepostFormConfirmation; |
79 [archiver | 80 [archiver |
80 encodeBool:skip_repost_form_confirmation | 81 encodeBool:skip_repost_form_confirmation |
81 forKey:web::kNavigationItemStorageSkipRepostFormConfirmationKey]; | 82 forKey:web::kNavigationItemStorageSkipRepostFormConfirmationKey]; |
82 [archiver finishEncoding]; | 83 [archiver finishEncoding]; |
83 base::scoped_nsobject<NSKeyedUnarchiver> unarchiver( | 84 base::scoped_nsobject<NSKeyedUnarchiver> unarchiver( |
84 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]); | 85 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]); |
85 | 86 |
86 // Create a CRWNavigationItemStorage and verify that it is equivalent. | 87 // Create a CRWNavigationItemStorage and verify that it is equivalent. |
87 base::scoped_nsobject<CRWNavigationItemStorage> new_storage( | 88 base::scoped_nsobject<CRWNavigationItemStorage> new_storage( |
88 [[CRWNavigationItemStorage alloc] initWithCoder:unarchiver]); | 89 [[CRWNavigationItemStorage alloc] initWithCoder:unarchiver]); |
89 EXPECT_TRUE(web::ItemStoragesAreEqual(item_storage(), new_storage.get())); | 90 EXPECT_TRUE(web::ItemStoragesAreEqual(item_storage(), new_storage.get())); |
90 } | 91 } |
91 | 92 |
92 // Tests that unarchiving CRWNavigationItemStorage data results in an equivalent | 93 // Tests that unarchiving CRWNavigationItemStorage data results in an equivalent |
93 // storage. | 94 // storage. |
94 TEST_F(CRWNavigationItemStorageTest, EncodeDecode) { | 95 TEST_F(CRWNavigationItemStorageTest, EncodeDecode) { |
95 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:item_storage()]; | 96 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:item_storage()]; |
96 id decoded = [NSKeyedUnarchiver unarchiveObjectWithData:data]; | 97 id decoded = [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
97 EXPECT_TRUE(web::ItemStoragesAreEqual(item_storage(), decoded)); | 98 EXPECT_TRUE(web::ItemStoragesAreEqual(item_storage(), decoded)); |
98 } | 99 } |
OLD | NEW |