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

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

Issue 1106963003: Re-sync ios/web with downstream version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add forgotten file Created 5 years, 8 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/navigation/navigation_item_impl.mm ('k') | ios/web/public/DEPS » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "base/mac/scoped_nsobject.h" 6 #include "base/mac/scoped_nsobject.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/sys_string_conversions.h"
8 #include "ios/web/navigation/navigation_item_impl.h" 9 #include "ios/web/navigation/navigation_item_impl.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/gtest_mac.h" 11 #include "testing/gtest_mac.h"
11 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
12 13
13 namespace web { 14 namespace web {
14 namespace { 15 namespace {
15 16
17 static NSString* const kHTTPHeaderKey1 = @"key1";
18 static NSString* const kHTTPHeaderKey2 = @"key2";
19 static NSString* const kHTTPHeaderValue1 = @"value1";
20 static NSString* const kHTTPHeaderValue2 = @"value2";
21
16 class NavigationItemTest : public PlatformTest { 22 class NavigationItemTest : public PlatformTest {
17 protected: 23 protected:
18 void SetUp() override { item_.reset(new NavigationItemImpl()); } 24 void SetUp() override {
25 item_.reset(new web::NavigationItemImpl());
26 item_->SetURL(GURL("http://init.test"));
27 item_->SetTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK);
28 item_->SetTimestamp(base::Time::Now());
29 item_->AddHttpRequestHeaders(@{kHTTPHeaderKey1 : kHTTPHeaderValue1});
30 item_->SetPostData([@"Test data" dataUsingEncoding:NSUTF8StringEncoding]);
31 }
19 32
33 // The NavigationItemImpl instance being tested.
20 scoped_ptr<NavigationItemImpl> item_; 34 scoped_ptr<NavigationItemImpl> item_;
21 }; 35 };
22 36
23 // TODO(rohitrao): Add and adapt tests from NavigationEntryImpl. 37 // TODO(rohitrao): Add and adapt tests from NavigationEntryImpl.
24 TEST_F(NavigationItemTest, Dummy) { 38 TEST_F(NavigationItemTest, Dummy) {
25 const GURL url("http://init.test"); 39 const GURL url("http://init.test");
26 item_->SetURL(url); 40 item_->SetURL(url);
27 EXPECT_TRUE(item_->GetURL().is_valid()); 41 EXPECT_TRUE(item_->GetURL().is_valid());
28 } 42 }
29 43
44 // Tests that copied NavigationItemImpls create copies of data members that are
45 // objects.
46 TEST_F(NavigationItemTest, Copy) {
47 // Create objects to be copied.
48 NSString* postData0 = @"postData0";
49 NSMutableData* mutablePostData =
50 [[postData0 dataUsingEncoding:NSUTF8StringEncoding] mutableCopy];
51 item_->SetPostData(mutablePostData);
52 NSString* state0 = @"state0";
53 NSMutableString* mutableState = [state0 mutableCopy];
54 item_->SetSerializedStateObject(mutableState);
55
56 // Create copy.
57 web::NavigationItemImpl copy(*item_.get());
58
59 // Modify the objects.
60 NSString* postData1 = @"postData1";
61 [mutablePostData setData:[postData1 dataUsingEncoding:NSUTF8StringEncoding]];
62 NSString* state1 = @"state1";
63 [mutableState setString:state1];
64
65 // Check that changes occurred in |item_|, but not in |copy|.
66 EXPECT_NSEQ([postData1 dataUsingEncoding:NSUTF8StringEncoding],
67 item_->GetPostData());
68 EXPECT_NSEQ(state1, item_->GetSerializedStateObject());
69 EXPECT_NSEQ([postData0 dataUsingEncoding:NSUTF8StringEncoding],
70 copy.GetPostData());
71 EXPECT_NSEQ(state0, copy.GetSerializedStateObject());
72 }
73
74 // Tests whether |NavigationItem::AddHttpRequestHeaders()| adds the passed
75 // headers to the item's request http headers.
76 TEST_F(NavigationItemTest, AddHttpRequestHeaders) {
77 EXPECT_NSEQ(@{kHTTPHeaderKey1 : kHTTPHeaderValue1},
78 item_->GetHttpRequestHeaders());
79
80 item_->AddHttpRequestHeaders(@{kHTTPHeaderKey1 : kHTTPHeaderValue2});
81 EXPECT_NSEQ(@{kHTTPHeaderKey1 : kHTTPHeaderValue2},
82 item_->GetHttpRequestHeaders());
83
84 item_->AddHttpRequestHeaders(@{kHTTPHeaderKey2 : kHTTPHeaderValue1});
85 NSDictionary* expected = @{
86 kHTTPHeaderKey1 : kHTTPHeaderValue2,
87 kHTTPHeaderKey2 : kHTTPHeaderValue1
88 };
89 EXPECT_NSEQ(expected, item_->GetHttpRequestHeaders());
90 }
91
92 // Tests whether |NavigationItem::AddHttpRequestHeaders()| removes the header
93 // value associated with the passed key from the item's request http headers.
94 TEST_F(NavigationItemTest, RemoveHttpRequestHeaderForKey) {
95 NSDictionary* httpHeaders = @{
96 kHTTPHeaderKey1 : kHTTPHeaderValue1,
97 kHTTPHeaderKey2 : kHTTPHeaderValue2
98 };
99 item_->AddHttpRequestHeaders(httpHeaders);
100 EXPECT_NSEQ(httpHeaders, item_->GetHttpRequestHeaders());
101
102 item_->RemoveHttpRequestHeaderForKey(kHTTPHeaderKey1);
103 EXPECT_NSEQ(@{kHTTPHeaderKey2 : kHTTPHeaderValue2},
104 item_->GetHttpRequestHeaders());
105
106 item_->RemoveHttpRequestHeaderForKey(kHTTPHeaderKey2);
107 EXPECT_FALSE(item_->GetHttpRequestHeaders());
108 }
109
30 } // namespace 110 } // namespace
31 } // namespace web 111 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/navigation/navigation_item_impl.mm ('k') | ios/web/public/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698