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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/navigation/navigation_item_impl_unittest.mm
diff --git a/ios/web/navigation/navigation_item_impl_unittest.mm b/ios/web/navigation/navigation_item_impl_unittest.mm
index a326b5c9098f7e3fda03383092ffae94ec9d60d9..0189ea04c3a9be95a75a02c36ce1d1bcdb151e65 100644
--- a/ios/web/navigation/navigation_item_impl_unittest.mm
+++ b/ios/web/navigation/navigation_item_impl_unittest.mm
@@ -5,6 +5,7 @@
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
+#include "base/strings/sys_string_conversions.h"
#include "ios/web/navigation/navigation_item_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
@@ -13,10 +14,23 @@
namespace web {
namespace {
+static NSString* const kHTTPHeaderKey1 = @"key1";
+static NSString* const kHTTPHeaderKey2 = @"key2";
+static NSString* const kHTTPHeaderValue1 = @"value1";
+static NSString* const kHTTPHeaderValue2 = @"value2";
+
class NavigationItemTest : public PlatformTest {
protected:
- void SetUp() override { item_.reset(new NavigationItemImpl()); }
+ void SetUp() override {
+ item_.reset(new web::NavigationItemImpl());
+ item_->SetURL(GURL("http://init.test"));
+ item_->SetTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK);
+ item_->SetTimestamp(base::Time::Now());
+ item_->AddHttpRequestHeaders(@{kHTTPHeaderKey1 : kHTTPHeaderValue1});
+ item_->SetPostData([@"Test data" dataUsingEncoding:NSUTF8StringEncoding]);
+ }
+ // The NavigationItemImpl instance being tested.
scoped_ptr<NavigationItemImpl> item_;
};
@@ -27,5 +41,71 @@ TEST_F(NavigationItemTest, Dummy) {
EXPECT_TRUE(item_->GetURL().is_valid());
}
+// Tests that copied NavigationItemImpls create copies of data members that are
+// objects.
+TEST_F(NavigationItemTest, Copy) {
+ // Create objects to be copied.
+ NSString* postData0 = @"postData0";
+ NSMutableData* mutablePostData =
+ [[postData0 dataUsingEncoding:NSUTF8StringEncoding] mutableCopy];
+ item_->SetPostData(mutablePostData);
+ NSString* state0 = @"state0";
+ NSMutableString* mutableState = [state0 mutableCopy];
+ item_->SetSerializedStateObject(mutableState);
+
+ // Create copy.
+ web::NavigationItemImpl copy(*item_.get());
+
+ // Modify the objects.
+ NSString* postData1 = @"postData1";
+ [mutablePostData setData:[postData1 dataUsingEncoding:NSUTF8StringEncoding]];
+ NSString* state1 = @"state1";
+ [mutableState setString:state1];
+
+ // Check that changes occurred in |item_|, but not in |copy|.
+ EXPECT_NSEQ([postData1 dataUsingEncoding:NSUTF8StringEncoding],
+ item_->GetPostData());
+ EXPECT_NSEQ(state1, item_->GetSerializedStateObject());
+ EXPECT_NSEQ([postData0 dataUsingEncoding:NSUTF8StringEncoding],
+ copy.GetPostData());
+ EXPECT_NSEQ(state0, copy.GetSerializedStateObject());
+}
+
+// Tests whether |NavigationItem::AddHttpRequestHeaders()| adds the passed
+// headers to the item's request http headers.
+TEST_F(NavigationItemTest, AddHttpRequestHeaders) {
+ EXPECT_NSEQ(@{kHTTPHeaderKey1 : kHTTPHeaderValue1},
+ item_->GetHttpRequestHeaders());
+
+ item_->AddHttpRequestHeaders(@{kHTTPHeaderKey1 : kHTTPHeaderValue2});
+ EXPECT_NSEQ(@{kHTTPHeaderKey1 : kHTTPHeaderValue2},
+ item_->GetHttpRequestHeaders());
+
+ item_->AddHttpRequestHeaders(@{kHTTPHeaderKey2 : kHTTPHeaderValue1});
+ NSDictionary* expected = @{
+ kHTTPHeaderKey1 : kHTTPHeaderValue2,
+ kHTTPHeaderKey2 : kHTTPHeaderValue1
+ };
+ EXPECT_NSEQ(expected, item_->GetHttpRequestHeaders());
+}
+
+// Tests whether |NavigationItem::AddHttpRequestHeaders()| removes the header
+// value associated with the passed key from the item's request http headers.
+TEST_F(NavigationItemTest, RemoveHttpRequestHeaderForKey) {
+ NSDictionary* httpHeaders = @{
+ kHTTPHeaderKey1 : kHTTPHeaderValue1,
+ kHTTPHeaderKey2 : kHTTPHeaderValue2
+ };
+ item_->AddHttpRequestHeaders(httpHeaders);
+ EXPECT_NSEQ(httpHeaders, item_->GetHttpRequestHeaders());
+
+ item_->RemoveHttpRequestHeaderForKey(kHTTPHeaderKey1);
+ EXPECT_NSEQ(@{kHTTPHeaderKey2 : kHTTPHeaderValue2},
+ item_->GetHttpRequestHeaders());
+
+ item_->RemoveHttpRequestHeaderForKey(kHTTPHeaderKey2);
+ EXPECT_FALSE(item_->GetHttpRequestHeaders());
+}
+
} // namespace
} // namespace web
« 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