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

Side by Side Diff: ios/web/navigation/crw_navigation_item_storage_unittest.mm

Issue 2935983002: [ObjC ARC] Converts ios/web:ios_web_navigation_unittests to ARC. (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « ios/web/BUILD.gn ('k') | ios/web/navigation/crw_session_controller_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 11
12 #import "base/mac/scoped_nsobject.h"
13 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
14 #import "ios/web/navigation/navigation_item_impl.h" 13 #import "ios/web/navigation/navigation_item_impl.h"
15 #import "ios/web/navigation/navigation_item_storage_test_util.h" 14 #import "ios/web/navigation/navigation_item_storage_test_util.h"
16 #include "ios/web/public/referrer.h" 15 #include "ios/web/public/referrer.h"
17 #import "net/base/mac/url_conversions.h" 16 #import "net/base/mac/url_conversions.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 #import "testing/gtest_mac.h" 18 #import "testing/gtest_mac.h"
20 #include "testing/platform_test.h" 19 #include "testing/platform_test.h"
21 #include "third_party/ocmock/gtest_support.h" 20 #include "third_party/ocmock/gtest_support.h"
22 #include "ui/base/page_transition_types.h" 21 #include "ui/base/page_transition_types.h"
23 22
23 #if !defined(__has_feature) || !__has_feature(objc_arc)
24 #error "This file requires ARC support."
25 #endif
26
24 class CRWNavigationItemStorageTest : public PlatformTest { 27 class CRWNavigationItemStorageTest : public PlatformTest {
25 protected: 28 protected:
26 CRWNavigationItemStorageTest() 29 CRWNavigationItemStorageTest()
27 : item_storage_([[CRWNavigationItemStorage alloc] init]) { 30 : item_storage_([[CRWNavigationItemStorage alloc] init]) {
28 // Set up |item_storage_|. 31 // Set up |item_storage_|.
29 [item_storage_ setVirtualURL:GURL("http://init.test")]; 32 [item_storage_ setVirtualURL:GURL("http://init.test")];
30 [item_storage_ setReferrer:web::Referrer(GURL("http://referrer.url"), 33 [item_storage_ setReferrer:web::Referrer(GURL("http://referrer.url"),
31 web::ReferrerPolicyDefault)]; 34 web::ReferrerPolicyDefault)];
32 [item_storage_ setTimestamp:base::Time::Now()]; 35 [item_storage_ setTimestamp:base::Time::Now()];
33 [item_storage_ setTitle:base::SysNSStringToUTF16(@"Title")]; 36 [item_storage_ setTitle:base::SysNSStringToUTF16(@"Title")];
34 [item_storage_ 37 [item_storage_
35 setDisplayState:web::PageDisplayState(0.0, 0.0, 0.0, 0.0, 0.0)]; 38 setDisplayState:web::PageDisplayState(0.0, 0.0, 0.0, 0.0, 0.0)];
36 [item_storage_ 39 [item_storage_
37 setPOSTData:[@"Test data" dataUsingEncoding:NSUTF8StringEncoding]]; 40 setPOSTData:[@"Test data" dataUsingEncoding:NSUTF8StringEncoding]];
38 [item_storage_ setHTTPRequestHeaders:@{ @"HeaderKey" : @"HeaderValue" }]; 41 [item_storage_ setHTTPRequestHeaders:@{ @"HeaderKey" : @"HeaderValue" }];
39 [item_storage_ setUserAgentType:web::UserAgentType::DESKTOP]; 42 [item_storage_ setUserAgentType:web::UserAgentType::DESKTOP];
40 } 43 }
41 44
42 // Convenience getter to facilitate dot notation in tests. 45 // Convenience getter to facilitate dot notation in tests.
43 CRWNavigationItemStorage* item_storage() { return item_storage_; } 46 CRWNavigationItemStorage* item_storage() { return item_storage_; }
44 47
45 protected: 48 protected:
46 base::scoped_nsobject<CRWNavigationItemStorage> item_storage_; 49 CRWNavigationItemStorage* item_storage_;
47 }; 50 };
48 51
49 // Tests initializing with the legacy keys. 52 // Tests initializing with the legacy keys.
50 TEST_F(CRWNavigationItemStorageTest, InitWithCoderLegacy) { 53 TEST_F(CRWNavigationItemStorageTest, InitWithCoderLegacy) {
51 NSURL* virtualURL = net::NSURLWithGURL(item_storage().virtualURL); 54 NSURL* virtualURL = net::NSURLWithGURL(item_storage().virtualURL);
52 NSURL* referrerURL = net::NSURLWithGURL(item_storage().referrer.url); 55 NSURL* referrerURL = net::NSURLWithGURL(item_storage().referrer.url);
53 NSString* title = base::SysUTF16ToNSString(item_storage().title); 56 NSString* title = base::SysUTF16ToNSString(item_storage().title);
54 // Legacy NavigationItems don't persist timestamp. 57 // Legacy NavigationItems don't persist timestamp.
55 item_storage().timestamp = base::Time::FromCFAbsoluteTime(0); 58 item_storage().timestamp = base::Time::FromCFAbsoluteTime(0);
56 59
57 // Set up archiver and unarchiver. 60 // Set up archiver and unarchiver.
58 base::scoped_nsobject<NSMutableData> data([[NSMutableData alloc] init]); 61 NSMutableData* data = [[NSMutableData alloc] init];
59 base::scoped_nsobject<NSKeyedArchiver> archiver( 62 NSKeyedArchiver* archiver =
60 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]); 63 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
61 [archiver encodeObject:virtualURL 64 [archiver encodeObject:virtualURL
62 forKey:web::kNavigationItemStorageURLDeperecatedKey]; 65 forKey:web::kNavigationItemStorageURLDeperecatedKey];
63 [archiver encodeObject:referrerURL 66 [archiver encodeObject:referrerURL
64 forKey:web::kNavigationItemStorageReferrerURLDeprecatedKey]; 67 forKey:web::kNavigationItemStorageReferrerURLDeprecatedKey];
65 [archiver encodeObject:title forKey:web::kNavigationItemStorageTitleKey]; 68 [archiver encodeObject:title forKey:web::kNavigationItemStorageTitleKey];
66 NSDictionary* display_state_dict = 69 NSDictionary* display_state_dict =
67 item_storage().displayState.GetSerialization(); 70 item_storage().displayState.GetSerialization();
68 [archiver encodeObject:display_state_dict 71 [archiver encodeObject:display_state_dict
69 forKey:web::kNavigationItemStoragePageDisplayStateKey]; 72 forKey:web::kNavigationItemStoragePageDisplayStateKey];
70 [archiver 73 [archiver
71 encodeBool:YES 74 encodeBool:YES
72 forKey:web::kNavigationItemStorageUseDesktopUserAgentDeprecatedKey]; 75 forKey:web::kNavigationItemStorageUseDesktopUserAgentDeprecatedKey];
73 NSDictionary* request_headers = item_storage().HTTPRequestHeaders; 76 NSDictionary* request_headers = item_storage().HTTPRequestHeaders;
74 [archiver encodeObject:request_headers 77 [archiver encodeObject:request_headers
75 forKey:web::kNavigationItemStorageHTTPRequestHeadersKey]; 78 forKey:web::kNavigationItemStorageHTTPRequestHeadersKey];
76 [archiver encodeObject:item_storage().POSTData 79 [archiver encodeObject:item_storage().POSTData
77 forKey:web::kNavigationItemStoragePOSTDataKey]; 80 forKey:web::kNavigationItemStoragePOSTDataKey];
78 BOOL skip_repost_form_confirmation = 81 BOOL skip_repost_form_confirmation =
79 item_storage().shouldSkipRepostFormConfirmation; 82 item_storage().shouldSkipRepostFormConfirmation;
80 [archiver 83 [archiver
81 encodeBool:skip_repost_form_confirmation 84 encodeBool:skip_repost_form_confirmation
82 forKey:web::kNavigationItemStorageSkipRepostFormConfirmationKey]; 85 forKey:web::kNavigationItemStorageSkipRepostFormConfirmationKey];
83 [archiver finishEncoding]; 86 [archiver finishEncoding];
84 base::scoped_nsobject<NSKeyedUnarchiver> unarchiver( 87 NSKeyedUnarchiver* unarchiver =
85 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]); 88 [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
86 89
87 // Create a CRWNavigationItemStorage and verify that it is equivalent. 90 // Create a CRWNavigationItemStorage and verify that it is equivalent.
88 base::scoped_nsobject<CRWNavigationItemStorage> new_storage( 91 CRWNavigationItemStorage* new_storage =
89 [[CRWNavigationItemStorage alloc] initWithCoder:unarchiver]); 92 [[CRWNavigationItemStorage alloc] initWithCoder:unarchiver];
90 EXPECT_TRUE(web::ItemStoragesAreEqual(item_storage(), new_storage.get())); 93 EXPECT_TRUE(web::ItemStoragesAreEqual(item_storage(), new_storage));
91 } 94 }
92 95
93 // Tests that unarchiving CRWNavigationItemStorage data results in an equivalent 96 // Tests that unarchiving CRWNavigationItemStorage data results in an equivalent
94 // storage. 97 // storage.
95 TEST_F(CRWNavigationItemStorageTest, EncodeDecode) { 98 TEST_F(CRWNavigationItemStorageTest, EncodeDecode) {
96 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:item_storage()]; 99 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:item_storage()];
97 id decoded = [NSKeyedUnarchiver unarchiveObjectWithData:data]; 100 id decoded = [NSKeyedUnarchiver unarchiveObjectWithData:data];
98 EXPECT_TRUE(web::ItemStoragesAreEqual(item_storage(), decoded)); 101 EXPECT_TRUE(web::ItemStoragesAreEqual(item_storage(), decoded));
99 } 102 }
OLDNEW
« no previous file with comments | « ios/web/BUILD.gn ('k') | ios/web/navigation/crw_session_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698