Commit 7e8619e1 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Fix UserAgent of restored sessions

When the sessions are being restored, the UserAgent is wrongly restored
because the AUTOMATIC description wasn't added to the list of string
describing the different UserAgent.

Fixed: 1097794
Change-Id: Idf6d4e68a2e7b1ae634809deba2c7e03f3a2ac88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2256216
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Auto-Submit: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarAli Juma <ajuma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781851}
parent 11f8ce83
...@@ -71,6 +71,8 @@ UserAgentType GetUserAgentTypeWithDescription(const std::string& description) { ...@@ -71,6 +71,8 @@ UserAgentType GetUserAgentTypeWithDescription(const std::string& description) {
return UserAgentType::MOBILE; return UserAgentType::MOBILE;
if (description == std::string(kUserAgentTypeDesktopDescription)) if (description == std::string(kUserAgentTypeDesktopDescription))
return UserAgentType::DESKTOP; return UserAgentType::DESKTOP;
if (description == std::string(kUserAgentTypeAutomaticDescription))
return UserAgentType::AUTOMATIC;
return UserAgentType::NONE; return UserAgentType::NONE;
} }
......
...@@ -37,8 +37,12 @@ using UserAgentTest = PlatformTest; ...@@ -37,8 +37,12 @@ using UserAgentTest = PlatformTest;
// Tests conversions between UserAgentType values and their descriptions // Tests conversions between UserAgentType values and their descriptions
TEST_F(UserAgentTest, UserAgentTypeDescription) { TEST_F(UserAgentTest, UserAgentTypeDescription) {
base::test::ScopedFeatureList feature;
feature.InitAndEnableFeature(features::kUseDefaultUserAgentInWebClient);
const std::string kMobileDescription("MOBILE"); const std::string kMobileDescription("MOBILE");
const std::string kDesktopDescription("DESKTOP"); const std::string kDesktopDescription("DESKTOP");
const std::string kAutomaticDescription("AUTOMATIC");
const std::string kNoneDescription("NONE"); const std::string kNoneDescription("NONE");
const std::string kInvalidDescription( const std::string kInvalidDescription(
"not returned by GetUserAgentTypeDescription()"); "not returned by GetUserAgentTypeDescription()");
...@@ -46,11 +50,15 @@ TEST_F(UserAgentTest, UserAgentTypeDescription) { ...@@ -46,11 +50,15 @@ TEST_F(UserAgentTest, UserAgentTypeDescription) {
GetUserAgentTypeDescription(UserAgentType::MOBILE)); GetUserAgentTypeDescription(UserAgentType::MOBILE));
EXPECT_EQ(kDesktopDescription, EXPECT_EQ(kDesktopDescription,
GetUserAgentTypeDescription(UserAgentType::DESKTOP)); GetUserAgentTypeDescription(UserAgentType::DESKTOP));
EXPECT_EQ(kAutomaticDescription,
GetUserAgentTypeDescription(UserAgentType::AUTOMATIC));
EXPECT_EQ(kNoneDescription, GetUserAgentTypeDescription(UserAgentType::NONE)); EXPECT_EQ(kNoneDescription, GetUserAgentTypeDescription(UserAgentType::NONE));
EXPECT_EQ(UserAgentType::MOBILE, EXPECT_EQ(UserAgentType::MOBILE,
GetUserAgentTypeWithDescription(kMobileDescription)); GetUserAgentTypeWithDescription(kMobileDescription));
EXPECT_EQ(UserAgentType::DESKTOP, EXPECT_EQ(UserAgentType::DESKTOP,
GetUserAgentTypeWithDescription(kDesktopDescription)); GetUserAgentTypeWithDescription(kDesktopDescription));
EXPECT_EQ(UserAgentType::AUTOMATIC,
GetUserAgentTypeWithDescription(kAutomaticDescription));
EXPECT_EQ(UserAgentType::NONE, EXPECT_EQ(UserAgentType::NONE,
GetUserAgentTypeWithDescription(kNoneDescription)); GetUserAgentTypeWithDescription(kNoneDescription));
EXPECT_EQ(UserAgentType::NONE, EXPECT_EQ(UserAgentType::NONE,
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#import "ios/web/public/session/crw_session_storage.h" #import "ios/web/public/session/crw_session_storage.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "ios/web/common/features.h"
#import "ios/web/navigation/navigation_item_impl.h" #import "ios/web/navigation/navigation_item_impl.h"
#import "ios/web/navigation/navigation_item_storage_test_util.h" #import "ios/web/navigation/navigation_item_storage_test_util.h"
#import "ios/web/navigation/serializable_user_data_manager_impl.h" #import "ios/web/navigation/serializable_user_data_manager_impl.h"
...@@ -106,3 +108,21 @@ TEST_F(CRWNSessionStorageTest, EncodeDecode) { ...@@ -106,3 +108,21 @@ TEST_F(CRWNSessionStorageTest, EncodeDecode) {
id decoded = [unarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey]; id decoded = [unarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey];
EXPECT_TRUE(SessionStoragesAreEqual(session_storage_, decoded)); EXPECT_TRUE(SessionStoragesAreEqual(session_storage_, decoded));
} }
// Tests that unarchiving CRWSessionStorage data results in an equivalent
// storage when the user agent is automatic.
TEST_F(CRWNSessionStorageTest, EncodeDecodeAutomatic) {
base::test::ScopedFeatureList feature;
feature.InitAndEnableFeature(web::features::kUseDefaultUserAgentInWebClient);
session_storage_.userAgentType = web::UserAgentType::AUTOMATIC;
NSKeyedArchiver* archiver =
[[NSKeyedArchiver alloc] initRequiringSecureCoding:NO];
[archiver encodeObject:session_storage_ forKey:NSKeyedArchiveRootObjectKey];
[archiver finishEncoding];
NSData* data = [archiver encodedData];
NSKeyedUnarchiver* unarchiver =
[[NSKeyedUnarchiver alloc] initForReadingFromData:data error:nil];
unarchiver.requiresSecureCoding = NO;
id decoded = [unarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey];
EXPECT_TRUE(SessionStoragesAreEqual(session_storage_, decoded));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment