Commit f24584ba authored by Lowell Manners's avatar Lowell Manners Committed by Commit Bot

[bfcache] Add tests for PasswordManager with BackForwardCache enabled.

Note that as part of adding these tests, a bug was discovered
(https://crbug.com/1012707).

Change-Id: Ib8fe265f673bf773efc6968c743445ad3c4eb7b0
Bug: 1012707
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1831803Reviewed-by: default avatarCamille Lamy <clamy@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Lowell Manners <lowell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705060}
parent 7bc9be8f
......@@ -58,8 +58,12 @@
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/test_utils.h"
#include "net/base/filename_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -89,6 +93,38 @@ class PasswordManagerBrowserTest : public PasswordManagerBrowserTestBase {
~PasswordManagerBrowserTest() override = default;
};
// Test class for testing password manager with the BackForwardCache feature
// enabled. More info about the BackForwardCache, see:
// http://doc/1YrBKX_eFMA9KoYof-eVThT35jcTqWcH_rRxYbR5RapU
class PasswordManagerBackForwardCacheBrowserTest
: public PasswordManagerBrowserTest {
public:
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
PasswordManagerBrowserTest ::SetUpOnMainThread();
}
bool IsGetCredentialsSuccessful() {
return "success" == content::EvalJs(WebContents()->GetMainFrame(), R"(
new Promise(resolve => {
navigator.credentials.get({password: true, unmediated: true })
.then(m => { resolve("success"); })
.catch(()=> { resolve("error"); });
});
)");
}
void SetUpCommandLine(base::CommandLine* command_line) override {
scoped_feature_list_.InitAndEnableFeatureWithParameters(
::features::kBackForwardCache,
{{"TimeToLiveInBackForwardCacheInSeconds", "3600"}});
PasswordManagerBrowserTest::SetUpCommandLine(command_line);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
class MockHttpAuthObserver : public password_manager::HttpAuthObserver {
public:
MOCK_METHOD2(OnAutofillDataAvailable,
......@@ -3924,5 +3960,68 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, ParserAnnotations) {
EXPECT_EQ("confirmation_password_element", cofirmation_password_annotation);
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBackForwardCacheBrowserTest,
SavePasswordOnRestoredPage) {
// Navigate to a page with a password form.
NavigateToFile("/password/password_form.html");
content::RenderFrameHost* rfh = WebContents()->GetMainFrame();
content::RenderFrameDeletedObserver rfh_deleted_observer(rfh);
// Navigate away so that the password form page is stored in the cache.
EXPECT_TRUE(NavigateToURL(
WebContents(), embedded_test_server()->GetURL("a.com", "/title1.html")));
EXPECT_FALSE(rfh_deleted_observer.deleted());
EXPECT_TRUE(content::IsInBackForwardCache(rfh));
// Restore the cached page.
WebContents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(WebContents()));
EXPECT_EQ(rfh, WebContents()->GetMainFrame());
// Fill out and submit the password form.
NavigationObserver observer(WebContents());
std::string fill_and_submit =
"document.getElementById('username_field').value = 'temp';"
"document.getElementById('password_field').value = 'random';"
"document.getElementById('input_submit_button').click()";
ASSERT_TRUE(content::ExecuteScript(WebContents(), fill_and_submit));
observer.Wait();
// Save the password and check the store.
BubbleObserver bubble_observer(WebContents());
EXPECT_TRUE(bubble_observer.IsSavePromptShownAutomatically());
bubble_observer.AcceptSavePrompt();
WaitForPasswordStore();
CheckThatCredentialsStored("temp", "random");
}
IN_PROC_BROWSER_TEST_F(PasswordManagerBackForwardCacheBrowserTest,
CallAPIOnRestoredPage) {
// Navigate to a page with a password form.
NavigateToFile("/password/password_form.html");
content::RenderFrameHost* rfh = WebContents()->GetMainFrame();
content::RenderFrameDeletedObserver rfh_deleted_observer(rfh);
// Make sure the password manager API works.
EXPECT_TRUE(IsGetCredentialsSuccessful());
// Navigate away so that the password form page is stored in the cache.
EXPECT_TRUE(NavigateToURL(
WebContents(), embedded_test_server()->GetURL("a.com", "/title1.html")));
EXPECT_FALSE(rfh_deleted_observer.deleted());
EXPECT_TRUE(content::IsInBackForwardCache(rfh));
// Restore the cached page.
WebContents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(WebContents()));
EXPECT_EQ(rfh, WebContents()->GetMainFrame());
// Make sure the password manager API still works now that the page has been
// stored/restored.
// TODO(https://crbug.com/1012707): This is currently broken.
EXPECT_FALSE(IsGetCredentialsSuccessful());
}
} // namespace
} // namespace password_manager
......@@ -13,6 +13,12 @@
namespace content {
bool IsInBackForwardCache(RenderFrameHost* render_frame_host) {
RenderFrameHostImpl* rfhi =
static_cast<RenderFrameHostImpl*>(render_frame_host);
return rfhi->is_in_back_forward_cache();
}
class BackForwardCacheDisabledTester::Impl
: public BackForwardCacheTestDelegate {
public:
......
......@@ -9,6 +9,12 @@
namespace content {
class BackForwardCacheImpl;
class RenderFrameHost;
// Returns true if |render_frame_host| is currently stored in the
// BackForwardCache.
bool IsInBackForwardCache(RenderFrameHost* render_frame_host)
WARN_UNUSED_RESULT;
// This is a helper class to check in the tests that back-forward cache
// was disabled for a particular reason.
......
......@@ -88,7 +88,6 @@
#include "content/public/test/test_fileapi_operation_waiter.h"
#include "content/public/test/test_launcher.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/test/did_commit_navigation_interceptor.h"
#include "ipc/ipc_security_test_util.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
......
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