Commit 5a17d33c authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Prerender] Move more prerender tests..

Move the tests that verify how clearing browsing history works with
NoStatePrefetch.

Please see this spreadsheet for details:

https://docs.google.com/spreadsheets/d/1LFPB4UhPWQkBRz481lz49zmS25znhjSDUtagtTTSPQo/edit?usp=sharing

Bug: 898955
Change-Id: I56e057d29e318cf33f6cfe4799dbfac3d3b208c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283344
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785742}
parent 1cb6c6dc
......@@ -30,9 +30,10 @@
#include "base/test/simple_test_tick_clock.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
//#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
//#include
//"chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
......@@ -92,7 +93,7 @@
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browsing_data_remover.h"
//#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
......@@ -106,7 +107,7 @@
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/browsing_data_remover_test_util.h"
//#include "content/public/test/browsing_data_remover_test_util.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
#include "content/public/test/ppapi_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
......@@ -210,18 +211,6 @@ std::string CreateServerRedirect(const std::string& dest_url) {
return kServerRedirectBase + net::EscapeQueryParamValue(dest_url, false);
}
// Clears the specified data using BrowsingDataRemover.
void ClearBrowsingData(Browser* browser, uint64_t remove_mask) {
content::BrowsingDataRemover* remover =
content::BrowserContext::GetBrowsingDataRemover(browser->profile());
content::BrowsingDataRemoverCompletionObserver observer(remover);
remover->RemoveAndReply(
base::Time(), base::Time::Max(), remove_mask,
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &observer);
observer.BlockUntilCompletion();
// BrowsingDataRemover deletes itself.
}
// Returns true if the prerender is expected to abort on its own, before
// attempting to swap it.
bool ShouldAbortPrerenderBeforeSwap(FinalStatus status) {
......@@ -690,18 +679,6 @@ class PrerenderBrowserTest : public test_utils::PrerenderInProcessBrowserTest {
return GetPrerenderLinkManager()->CountRunningPrerenders();
}
// Returns length of |prerender_manager_|'s history, or SIZE_MAX on failure.
size_t GetHistoryLength() const {
std::unique_ptr<base::DictionaryValue> prerender_dict =
GetPrerenderManager()->CopyAsValue();
if (!prerender_dict)
return std::numeric_limits<size_t>::max();
base::ListValue* history_list;
if (!prerender_dict->GetList("history", &history_list))
return std::numeric_limits<size_t>::max();
return history_list->GetSize();
}
void SetLoaderHostOverride(const std::string& host) {
loader_host_override_ = host;
}
......@@ -1104,37 +1081,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderFavicon) {
EXPECT_TRUE(favicon_driver->FaviconIsValid());
}
// Checks that when the history is cleared, prerendering is cancelled and
// prerendering history is cleared.
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearHistory) {
std::unique_ptr<TestPrerender> prerender =
PrerenderTestURL("/prerender/prerender_page.html",
FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, 1);
ClearBrowsingData(current_browser(),
ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY);
prerender->WaitForStop();
// Make sure prerender history was cleared.
EXPECT_EQ(0U, GetHistoryLength());
}
// Checks that when the cache is cleared, prerenders are cancelled but
// prerendering history is not cleared.
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearCache) {
std::unique_ptr<TestPrerender> prerender =
PrerenderTestURL("/prerender/prerender_page.html",
FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, 1);
ClearBrowsingData(current_browser(),
content::BrowsingDataRemover::DATA_TYPE_CACHE);
prerender->WaitForStop();
// Make sure prerender history was not cleared. Not a vital behavior, but
// used to compare with PrerenderClearHistory test.
EXPECT_EQ(1U, GetHistoryLength());
}
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCancelAll) {
std::unique_ptr<TestPrerender> prerender = PrerenderTestURL(
"/prerender/prerender_page.html", FINAL_STATUS_CANCELLED, 1);
......
......@@ -17,7 +17,9 @@
#include "base/test/bind_test_util.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/threading/platform_thread.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/history_test_utils.h"
#include "chrome/browser/prerender/prerender_handle.h"
......@@ -38,6 +40,7 @@
#include "content/public/browser/appcache_service.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
......@@ -45,6 +48,7 @@
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/browsing_data_remover_test_util.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
#include "content/public/test/url_loader_interceptor.h"
#include "content/public/test/url_loader_monitor.h"
......@@ -188,6 +192,30 @@ class NoStatePrefetchBrowserTest
expected_final_status);
}
// Returns length of |prerender_manager_|'s history, or SIZE_MAX on failure.
size_t GetHistoryLength() const {
std::unique_ptr<base::DictionaryValue> prerender_dict =
GetPrerenderManager()->CopyAsValue();
if (!prerender_dict)
return std::numeric_limits<size_t>::max();
base::ListValue* history_list;
if (!prerender_dict->GetList("history", &history_list))
return std::numeric_limits<size_t>::max();
return history_list->GetSize();
}
// Clears the specified data using BrowsingDataRemover.
void ClearBrowsingData(Browser* browser, uint64_t remove_mask) {
content::BrowsingDataRemover* remover =
content::BrowserContext::GetBrowsingDataRemover(browser->profile());
content::BrowsingDataRemoverCompletionObserver observer(remover);
remover->RemoveAndReply(
base::Time(), base::Time::Max(), remove_mask,
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &observer);
observer.BlockUntilCompletion();
// BrowsingDataRemover deletes itself.
}
base::SimpleTestTickClock clock_;
private:
......@@ -1386,4 +1414,32 @@ IN_PROC_BROWSER_TEST_F(NoStatePrefetchIncognitoBrowserTest,
WaitForRequestCount(src_server()->GetURL(kPrefetchScript2), 0);
}
// Checks that when the history is cleared, NoStatePrefetch history is cleared.
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, ClearHistory) {
std::unique_ptr<TestPrerender> test_prerender = PrefetchFromFile(
"/prerender/prerender_page.html", FINAL_STATUS_NOSTATE_PREFETCH_FINISHED);
ClearBrowsingData(current_browser(),
ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY);
test_prerender->WaitForStop();
// Make sure prerender history was cleared.
EXPECT_EQ(0U, GetHistoryLength());
}
// Checks that when the cache is cleared, NoStatePrefetch history is not
// cleared.
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, ClearCache) {
std::unique_ptr<TestPrerender> prerender = PrefetchFromFile(
"/prerender/prerender_page.html", FINAL_STATUS_NOSTATE_PREFETCH_FINISHED);
ClearBrowsingData(current_browser(),
content::BrowsingDataRemover::DATA_TYPE_CACHE);
prerender->WaitForStop();
// Make sure prerender history was not cleared. Not a vital behavior, but
// used to compare with PrerenderClearHistory test.
EXPECT_EQ(1U, GetHistoryLength());
}
} // namespace prerender
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