Commit 75482757 authored by Eugene But's avatar Eugene But Committed by Commit Bot

CreateRestoreSessionUrl unit test for large sessions.

Slim Navigation Manager is implemented with assumption that session
restoration URL is not corrupted for the large sessions. This test
verifies that URL ref contains full session for 5k navigation items.

This test will be modified later to verify that the number of entries
is trimmed to 100 (which is max number of pushState calls allowed
by WKWebView in 30 seconds timeframe).

Bug: None
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I47e09cf90b5b9726c87d391a5cbba2e3f7b78f60
Reviewed-on: https://chromium-review.googlesource.com/1170039
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582668}
parent d50b3e15
......@@ -7,10 +7,15 @@
#include <memory>
#include <vector>
#include "base/json/json_reader.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#import "ios/web/navigation/navigation_item_impl.h"
#include "ios/web/test/test_url_constants.h"
#include "net/base/escape.h"
#import "net/base/mac/url_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
......@@ -57,6 +62,49 @@ TEST_F(WKNavigationUtilTest, CreateRestoreSessionUrl) {
session_json);
}
// Verifies that large session can be stored in NSURL. GURL is converted to
// NSURL, because NSURL is passed to WKWebView during the session restoration.
TEST_F(WKNavigationUtilTest, CreateRestoreSessionUrlForLargeSession) {
// Create restore session URL with large number of items.
const size_t kItemCount = 5000;
std::vector<std::unique_ptr<NavigationItem>> items;
for (size_t i = 0; i < kItemCount; i++) {
auto item = std::make_unique<NavigationItemImpl>();
item->SetURL(GURL(base::StringPrintf("http://www.%zu.com", i)));
item->SetTitle(base::ASCIIToUTF16(base::StringPrintf("Test%zu", i)));
items.push_back(std::move(item));
}
GURL restore_session_url =
CreateRestoreSessionUrl(/*last_committed_item_index=*/0, items);
ASSERT_TRUE(IsRestoreSessionUrl(restore_session_url));
// Extract session JSON from restoration URL.
NSString* fragment = net::NSURLWithGURL(restore_session_url).fragment;
NSString* encoded_session = [fragment substringFromIndex:strlen("session=")];
std::string session_json = net::UnescapeURLComponent(
base::SysNSStringToUTF8(encoded_session),
net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS);
// Parse JSON to get the session dictionary.
int error_code = 0;
std::unique_ptr<base::Value> session_value(
base::JSONReader::ReadAndReturnError(session_json, base::JSON_PARSE_RFC,
&error_code, nullptr));
ASSERT_EQ(0, error_code);
ASSERT_TRUE(session_value.get());
// Verify that all titles and URLs are present.
base::Value* titles_value = session_value->FindKey("titles");
ASSERT_TRUE(titles_value);
ASSERT_TRUE(titles_value->is_list());
ASSERT_EQ(kItemCount, titles_value->GetList().size());
base::Value* urls_value = session_value->FindKey("urls");
ASSERT_TRUE(urls_value);
ASSERT_TRUE(urls_value->is_list());
ASSERT_EQ(kItemCount, urls_value->GetList().size());
}
TEST_F(WKNavigationUtilTest, IsNotRestoreSessionUrl) {
EXPECT_FALSE(IsRestoreSessionUrl(GURL()));
EXPECT_FALSE(IsRestoreSessionUrl(GURL("file://somefile")));
......
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