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/utf_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 const char kItemURLString[] = "http://init.test"; |
20 static NSString* const kHTTPHeaderKey1 = @"key1"; | 20 static NSString* const kHTTPHeaderKey1 = @"key1"; |
21 static NSString* const kHTTPHeaderKey2 = @"key2"; | 21 static NSString* const kHTTPHeaderKey2 = @"key2"; |
(...skipping 16 matching lines...) Expand all Loading... |
38 std::unique_ptr<NavigationItemImpl> item_; | 38 std::unique_ptr<NavigationItemImpl> item_; |
39 }; | 39 }; |
40 | 40 |
41 // TODO(rohitrao): Add and adapt tests from NavigationEntryImpl. | 41 // TODO(rohitrao): Add and adapt tests from NavigationEntryImpl. |
42 TEST_F(NavigationItemTest, Dummy) { | 42 TEST_F(NavigationItemTest, Dummy) { |
43 const GURL url("http://init.test"); | 43 const GURL url("http://init.test"); |
44 item_->SetURL(url); | 44 item_->SetURL(url); |
45 EXPECT_TRUE(item_->GetURL().is_valid()); | 45 EXPECT_TRUE(item_->GetURL().is_valid()); |
46 } | 46 } |
47 | 47 |
| 48 #ifndef NDEBUG |
| 49 // Tests that the debug description is as expected. |
| 50 TEST_F(NavigationItemTest, Description) { |
| 51 item_->SetTitle(base::UTF8ToUTF16("Title")); |
| 52 EXPECT_NSEQ(@"url:http://init.test/ originalurl:http://init.test/ " |
| 53 @"title:Title transition:2 displayState:{ scrollOffset:(nan, " |
| 54 @"nan), zoomScaleRange:(nan, nan), zoomScale:nan } " |
| 55 @"userAgentType:MOBILE", |
| 56 item_->GetDescription()); |
| 57 } |
| 58 #endif |
| 59 |
48 // Tests that copied NavigationItemImpls create copies of data members that are | 60 // Tests that copied NavigationItemImpls create copies of data members that are |
49 // objects. | 61 // objects. |
50 TEST_F(NavigationItemTest, Copy) { | 62 TEST_F(NavigationItemTest, Copy) { |
51 // Create objects to be copied. | 63 // Create objects to be copied. |
52 NSString* postData0 = @"postData0"; | 64 NSString* postData0 = @"postData0"; |
53 NSMutableData* mutablePostData = | 65 NSMutableData* mutablePostData = |
54 [[postData0 dataUsingEncoding:NSUTF8StringEncoding] mutableCopy]; | 66 [[postData0 dataUsingEncoding:NSUTF8StringEncoding] mutableCopy]; |
55 item_->SetPostData(mutablePostData); | 67 item_->SetPostData(mutablePostData); |
56 NSString* state0 = @"state0"; | 68 NSString* state0 = @"state0"; |
57 NSMutableString* mutableState = [state0 mutableCopy]; | 69 NSMutableString* mutableState = [state0 mutableCopy]; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 TEST_F(NavigationItemTest, OriginalURL) { | 127 TEST_F(NavigationItemTest, OriginalURL) { |
116 GURL original_url = GURL(kItemURLString); | 128 GURL original_url = GURL(kItemURLString); |
117 EXPECT_EQ(original_url, item_->GetOriginalRequestURL()); | 129 EXPECT_EQ(original_url, item_->GetOriginalRequestURL()); |
118 web::NavigationItemImpl copy(*item_); | 130 web::NavigationItemImpl copy(*item_); |
119 GURL new_url = GURL("http://new_url.test"); | 131 GURL new_url = GURL("http://new_url.test"); |
120 item_->SetOriginalRequestURL(new_url); | 132 item_->SetOriginalRequestURL(new_url); |
121 EXPECT_EQ(new_url, item_->GetOriginalRequestURL()); | 133 EXPECT_EQ(new_url, item_->GetOriginalRequestURL()); |
122 EXPECT_EQ(original_url, copy.GetOriginalRequestURL()); | 134 EXPECT_EQ(original_url, copy.GetOriginalRequestURL()); |
123 } | 135 } |
124 | 136 |
| 137 // Tests the behavior of GetVirtualURL(). |
| 138 TEST_F(NavigationItemTest, VirtualURLTest) { |
| 139 // Ensure that GetVirtualURL() returns GetURL() when not set to a custom |
| 140 // value. |
| 141 GURL original_url = item_->GetURL(); |
| 142 EXPECT_EQ(original_url, item_->GetVirtualURL()); |
| 143 // Set the virtual URL and check that the correct value is reported and that |
| 144 // GetURL() still reports the original URL. |
| 145 GURL new_virtual_url = GURL("http://new_url.test"); |
| 146 item_->SetVirtualURL(new_virtual_url); |
| 147 EXPECT_EQ(new_virtual_url, item_->GetVirtualURL()); |
| 148 EXPECT_EQ(original_url, item_->GetURL()); |
| 149 } |
| 150 |
125 } // namespace | 151 } // namespace |
126 } // namespace web | 152 } // namespace web |
OLD | NEW |