OLD | NEW |
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 #import "ios/web/navigation/navigation_item_impl.h" | 5 #import "ios/web/navigation/navigation_item_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #import "testing/gtest_mac.h" | 13 #import "testing/gtest_mac.h" |
14 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
15 | 15 |
16 namespace web { | 16 namespace web { |
17 namespace { | 17 namespace { |
18 | 18 |
| 19 const char kItemURLString[] = "http://init.test"; |
19 static NSString* const kHTTPHeaderKey1 = @"key1"; | 20 static NSString* const kHTTPHeaderKey1 = @"key1"; |
20 static NSString* const kHTTPHeaderKey2 = @"key2"; | 21 static NSString* const kHTTPHeaderKey2 = @"key2"; |
21 static NSString* const kHTTPHeaderValue1 = @"value1"; | 22 static NSString* const kHTTPHeaderValue1 = @"value1"; |
22 static NSString* const kHTTPHeaderValue2 = @"value2"; | 23 static NSString* const kHTTPHeaderValue2 = @"value2"; |
23 | 24 |
24 class NavigationItemTest : public PlatformTest { | 25 class NavigationItemTest : public PlatformTest { |
25 protected: | 26 protected: |
26 void SetUp() override { | 27 void SetUp() override { |
27 item_.reset(new web::NavigationItemImpl()); | 28 item_.reset(new web::NavigationItemImpl()); |
28 item_->SetURL(GURL("http://init.test")); | 29 item_->SetOriginalRequestURL(GURL(kItemURLString)); |
| 30 item_->SetURL(GURL(kItemURLString)); |
29 item_->SetTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK); | 31 item_->SetTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK); |
30 item_->SetTimestamp(base::Time::Now()); | 32 item_->SetTimestamp(base::Time::Now()); |
31 item_->AddHttpRequestHeaders(@{kHTTPHeaderKey1 : kHTTPHeaderValue1}); | 33 item_->AddHttpRequestHeaders(@{kHTTPHeaderKey1 : kHTTPHeaderValue1}); |
32 item_->SetPostData([@"Test data" dataUsingEncoding:NSUTF8StringEncoding]); | 34 item_->SetPostData([@"Test data" dataUsingEncoding:NSUTF8StringEncoding]); |
33 } | 35 } |
34 | 36 |
35 // The NavigationItemImpl instance being tested. | 37 // The NavigationItemImpl instance being tested. |
36 std::unique_ptr<NavigationItemImpl> item_; | 38 std::unique_ptr<NavigationItemImpl> item_; |
37 }; | 39 }; |
38 | 40 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 EXPECT_NSEQ(httpHeaders, item_->GetHttpRequestHeaders()); | 104 EXPECT_NSEQ(httpHeaders, item_->GetHttpRequestHeaders()); |
103 | 105 |
104 item_->RemoveHttpRequestHeaderForKey(kHTTPHeaderKey1); | 106 item_->RemoveHttpRequestHeaderForKey(kHTTPHeaderKey1); |
105 EXPECT_NSEQ(@{kHTTPHeaderKey2 : kHTTPHeaderValue2}, | 107 EXPECT_NSEQ(@{kHTTPHeaderKey2 : kHTTPHeaderValue2}, |
106 item_->GetHttpRequestHeaders()); | 108 item_->GetHttpRequestHeaders()); |
107 | 109 |
108 item_->RemoveHttpRequestHeaderForKey(kHTTPHeaderKey2); | 110 item_->RemoveHttpRequestHeaderForKey(kHTTPHeaderKey2); |
109 EXPECT_FALSE(item_->GetHttpRequestHeaders()); | 111 EXPECT_FALSE(item_->GetHttpRequestHeaders()); |
110 } | 112 } |
111 | 113 |
| 114 // Tests the getter, setter, and copy constructor for the original request URL. |
| 115 TEST_F(NavigationItemTest, OriginalURL) { |
| 116 GURL original_url = GURL(kItemURLString); |
| 117 EXPECT_EQ(original_url, item_->GetOriginalRequestURL()); |
| 118 web::NavigationItemImpl copy(*item_); |
| 119 GURL new_url = GURL("http://new_url.test"); |
| 120 item_->SetOriginalRequestURL(new_url); |
| 121 EXPECT_EQ(new_url, item_->GetOriginalRequestURL()); |
| 122 EXPECT_EQ(original_url, copy.GetOriginalRequestURL()); |
| 123 } |
| 124 |
112 } // namespace | 125 } // namespace |
113 } // namespace web | 126 } // namespace web |
OLD | NEW |