Commit 7a3b5f03 authored by Carlos IL's avatar Carlos IL Committed by Commit Bot

Removed MergeSessionLoadPage.

As part of committed interstitials, the MergeSessionLoadPage interstitial was
removed, the wait for MergeSession now happens directly in the
MergeSessionNavigationThrottle.

Bug: 854628
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: Ib5c73824d08de8733b9b47e113587a552aa9a828
Reviewed-on: https://chromium-review.googlesource.com/1108186Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Carlos IL <carlosil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569682}
parent f3c2edb0
...@@ -465,7 +465,6 @@ ...@@ -465,7 +465,6 @@
<include name="IDR_MOBILE_SETUP_PAGE_HTML" file="resources\chromeos\mobile_setup.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_MOBILE_SETUP_PAGE_HTML" file="resources\chromeos\mobile_setup.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_MOBILE_SETUP_PORTAL_PAGE_HTML" file="resources\chromeos\mobile_setup_portal.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_MOBILE_SETUP_PORTAL_PAGE_HTML" file="resources\chromeos\mobile_setup_portal.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_ECHO_MANIFEST" file="resources\chromeos\echo\manifest.json" type="BINDATA" /> <include name="IDR_ECHO_MANIFEST" file="resources\chromeos\echo\manifest.json" type="BINDATA" />
<include name="IDR_MERGE_SESSION_LOAD_HTML" file="resources\chromeos\merge_session_load.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_OS_CREDITS_HTML" file="resources\chromeos\about_os_credits.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_OS_CREDITS_HTML" file="resources\chromeos\about_os_credits.html" flattenhtml="true" type="BINDATA" />
<if expr="optimize_webui"> <if expr="optimize_webui">
<then> <then>
......
...@@ -1114,8 +1114,6 @@ source_set("chromeos") { ...@@ -1114,8 +1114,6 @@ source_set("chromeos") {
"login/signin/auth_sync_observer.h", "login/signin/auth_sync_observer.h",
"login/signin/auth_sync_observer_factory.cc", "login/signin/auth_sync_observer_factory.cc",
"login/signin/auth_sync_observer_factory.h", "login/signin/auth_sync_observer_factory.h",
"login/signin/merge_session_load_page.cc",
"login/signin/merge_session_load_page.h",
"login/signin/merge_session_navigation_throttle.cc", "login/signin/merge_session_navigation_throttle.cc",
"login/signin/merge_session_navigation_throttle.h", "login/signin/merge_session_navigation_throttle.h",
"login/signin/merge_session_resource_throttle.cc", "login/signin/merge_session_resource_throttle.cc",
...@@ -2031,7 +2029,7 @@ source_set("unit_tests") { ...@@ -2031,7 +2029,7 @@ source_set("unit_tests") {
"login/saml/saml_offline_signin_limiter_unittest.cc", "login/saml/saml_offline_signin_limiter_unittest.cc",
"login/screens/update_screen_unittest.cc", "login/screens/update_screen_unittest.cc",
"login/screens/welcome_screen_unittest.cc", "login/screens/welcome_screen_unittest.cc",
"login/signin/merge_session_load_page_unittest.cc", "login/signin/merge_session_navigation_throttle_unittest.cc",
"login/signin_partition_manager_unittest.cc", "login/signin_partition_manager_unittest.cc",
"login/supervised/supervised_user_authentication_unittest.cc", "login/supervised/supervised_user_authentication_unittest.cc",
"login/users/affiliation_unittest.cc", "login/users/affiliation_unittest.cc",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/signin/merge_session_load_page.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_piece.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_preferences_util.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_icon_set.h"
#include "net/base/escape.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/jstemplate_builder.h"
#include "ui/base/webui/web_ui_util.h"
using content::BrowserThread;
using content::InterstitialPage;
using content::WebContents;
namespace {
// Delay time for showing interstitial page.
const int kShowDelayTimeMS = 1000;
// Maximum time for showing interstitial page.
const int kTotalWaitTimeMS = 10000;
} // namespace
namespace chromeos {
MergeSessionLoadPage::MergeSessionLoadPage(
WebContents* web_contents,
const GURL& url,
const merge_session_throttling_utils::CompletionCallback& callback)
: callback_(callback),
proceeded_(false),
web_contents_(web_contents),
url_(url) {
interstitial_page_ = InterstitialPage::Create(web_contents, true, url, this);
}
MergeSessionLoadPage::~MergeSessionLoadPage() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
void MergeSessionLoadPage::Show() {
OAuth2LoginManager* manager = GetOAuth2LoginManager();
if (manager && manager->ShouldBlockTabLoading()) {
manager->AddObserver(this);
interstitial_page_->Show();
} else {
interstitial_page_->Proceed();
}
}
std::string MergeSessionLoadPage::GetHTMLContents() {
base::DictionaryValue strings;
strings.SetString("title", web_contents_->GetTitle());
// Set the timeout to show the page.
strings.SetInteger("show_delay_time", kShowDelayTimeMS);
strings.SetInteger("total_wait_time", kTotalWaitTimeMS);
// TODO(zelidrag): Flip the message to IDS_MERGE_SESSION_LOAD_HEADLINE
// after merge.
strings.SetString("heading",
l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE));
const std::string& app_locale = g_browser_process->GetApplicationLocale();
webui::SetLoadTimeDataDefaults(app_locale, &strings);
base::StringPiece html(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_MERGE_SESSION_LOAD_HTML));
return webui::GetI18nTemplateHtml(html, &strings);
}
void MergeSessionLoadPage::OverrideRendererPrefs(
content::RendererPreferences* prefs) {
Profile* profile =
Profile::FromBrowserContext(web_contents_->GetBrowserContext());
renderer_preferences_util::UpdateFromSystemSettings(prefs, profile,
web_contents_);
}
void MergeSessionLoadPage::OnProceed() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
proceeded_ = true;
NotifyBlockingPageComplete();
}
void MergeSessionLoadPage::OnDontProceed() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Ignore if it's already proceeded.
if (proceeded_)
return;
NotifyBlockingPageComplete();
}
void MergeSessionLoadPage::CommandReceived(const std::string& cmd) {
std::string command(cmd);
// The Jasonified response has quotes, remove them.
if (command.length() > 1 && command[0] == '"')
command = command.substr(1, command.length() - 2);
if (command == "proceed") {
interstitial_page_->Proceed();
} else {
DVLOG(1) << "Unknown command:" << cmd;
}
}
void MergeSessionLoadPage::NotifyBlockingPageComplete() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
OAuth2LoginManager* manager = GetOAuth2LoginManager();
if (manager)
manager->RemoveObserver(this);
// Tell the MergeSessionNavigationThrottle to resume the navigation on the UI
// thread.
if (!callback_.is_null())
callback_.Run();
}
OAuth2LoginManager* MergeSessionLoadPage::GetOAuth2LoginManager() {
content::BrowserContext* browser_context = web_contents_->GetBrowserContext();
if (!browser_context)
return NULL;
Profile* profile = Profile::FromBrowserContext(browser_context);
if (!profile)
return NULL;
return OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile);
}
void MergeSessionLoadPage::OnSessionRestoreStateChanged(
Profile* user_profile,
OAuth2LoginManager::SessionRestoreState state) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
OAuth2LoginManager* manager = GetOAuth2LoginManager();
DVLOG(1) << "Merge session should "
<< (!manager->ShouldBlockTabLoading() ? " NOT " : "")
<< " be blocking now, " << state;
if (!manager->ShouldBlockTabLoading()) {
manager->RemoveObserver(this);
interstitial_page_->Proceed();
}
}
} // namespace chromeos
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_MERGE_SESSION_LOAD_PAGE_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_MERGE_SESSION_LOAD_PAGE_H_
#include <string>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
#include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
#include "content/public/browser/interstitial_page_delegate.h"
#include "url/gurl.h"
namespace content {
class InterstitialPage;
class WebContents;
} // namespace content
namespace chromeos {
// MergeSessionLoadPage class shows the interstitial page that is shown
// while we are trying to restore session containing tabs with Google properties
// during the process of exchanging OAuth2 refresh token for user cookies.
// It deletes itself when the interstitial page is closed.
class MergeSessionLoadPage : public content::InterstitialPageDelegate,
public OAuth2LoginManager::Observer {
public:
// Create a merge session load delay page for the |web_contents|.
// The |callback| will be run on the IO thread.
MergeSessionLoadPage(
content::WebContents* web_contents,
const GURL& url,
const merge_session_throttling_utils::CompletionCallback& callback);
void Show();
protected:
~MergeSessionLoadPage() override;
private:
friend class TestMergeSessionLoadPage;
// InterstitialPageDelegate implementation.
std::string GetHTMLContents() override;
void CommandReceived(const std::string& command) override;
void OverrideRendererPrefs(content::RendererPreferences* prefs) override;
void OnProceed() override;
void OnDontProceed() override;
// OAuth2LoginManager::Observer overrides.
void OnSessionRestoreStateChanged(
Profile* user_profile,
OAuth2LoginManager::SessionRestoreState state) override;
void NotifyBlockingPageComplete();
// Helper function to get OAuth2LoginManager out of |web_contents_|.
OAuth2LoginManager* GetOAuth2LoginManager();
merge_session_throttling_utils::CompletionCallback callback_;
// True if the proceed is chosen.
bool proceeded_;
content::WebContents* web_contents_;
GURL url_;
content::InterstitialPage* interstitial_page_; // Owns us.
DISALLOW_COPY_AND_ASSIGN(MergeSessionLoadPage);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_MERGE_SESSION_LOAD_PAGE_H_
...@@ -4,9 +4,32 @@ ...@@ -4,9 +4,32 @@
#include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h" #include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
#include "chrome/browser/chromeos/login/signin/merge_session_load_page.h" #include "base/time/time.h"
#include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
#include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
namespace {
// Maximum wait time for merge session process.
constexpr base::TimeDelta kTotalWaitTime = base::TimeDelta::FromSeconds(10);
chromeos::OAuth2LoginManager* GetOAuth2LoginManager(
content::WebContents* web_contents) {
content::BrowserContext* browser_context = web_contents->GetBrowserContext();
if (!browser_context)
return nullptr;
Profile* profile = Profile::FromBrowserContext(browser_context);
if (!profile)
return nullptr;
return chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile(
profile);
}
} // namespace
// static // static
std::unique_ptr<content::NavigationThrottle> std::unique_ptr<content::NavigationThrottle>
...@@ -17,7 +40,7 @@ MergeSessionNavigationThrottle::Create(content::NavigationHandle* handle) { ...@@ -17,7 +40,7 @@ MergeSessionNavigationThrottle::Create(content::NavigationHandle* handle) {
MergeSessionNavigationThrottle::MergeSessionNavigationThrottle( MergeSessionNavigationThrottle::MergeSessionNavigationThrottle(
content::NavigationHandle* handle) content::NavigationHandle* handle)
: NavigationThrottle(handle), weak_factory_(this) { : NavigationThrottle(handle) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
} }
...@@ -35,14 +58,10 @@ MergeSessionNavigationThrottle::WillStartRequest() { ...@@ -35,14 +58,10 @@ MergeSessionNavigationThrottle::WillStartRequest() {
return content::NavigationThrottle::PROCEED; return content::NavigationThrottle::PROCEED;
} }
// The MergeSessionLoadPage will be deleted by the interstitial page once it if (BeforeDefer())
// is closed. return content::NavigationThrottle::DEFER;
(new chromeos::MergeSessionLoadPage(
navigation_handle()->GetWebContents(), navigation_handle()->GetURL(), return content::NavigationThrottle::PROCEED;
base::Bind(&MergeSessionNavigationThrottle::OnBlockingPageComplete,
weak_factory_.GetWeakPtr())))
->Show();
return content::NavigationThrottle::DEFER;
} }
content::NavigationThrottle::ThrottleCheckResult content::NavigationThrottle::ThrottleCheckResult
...@@ -54,7 +73,34 @@ const char* MergeSessionNavigationThrottle::GetNameForLogging() { ...@@ -54,7 +73,34 @@ const char* MergeSessionNavigationThrottle::GetNameForLogging() {
return "MergeSessionNavigationThrottle"; return "MergeSessionNavigationThrottle";
} }
void MergeSessionNavigationThrottle::OnBlockingPageComplete() { void MergeSessionNavigationThrottle::OnSessionRestoreStateChanged(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); Profile* user_profile,
chromeos::OAuth2LoginManager::SessionRestoreState state) {
chromeos::OAuth2LoginManager* manager =
GetOAuth2LoginManager(navigation_handle()->GetWebContents());
if (!manager->ShouldBlockTabLoading()) {
Proceed();
}
}
bool MergeSessionNavigationThrottle::BeforeDefer() {
chromeos::OAuth2LoginManager* manager =
GetOAuth2LoginManager(navigation_handle()->GetWebContents());
if (manager && manager->ShouldBlockTabLoading()) {
manager->AddObserver(this);
proceed_timer_.Start(FROM_HERE, kTotalWaitTime, this,
&MergeSessionNavigationThrottle::Proceed);
return true;
}
return false;
}
void MergeSessionNavigationThrottle::Proceed() {
proceed_timer_.Stop();
chromeos::OAuth2LoginManager* manager =
GetOAuth2LoginManager(navigation_handle()->GetWebContents());
if (manager) {
manager->RemoveObserver(this);
}
Resume(); Resume();
} }
...@@ -9,16 +9,21 @@ ...@@ -9,16 +9,21 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
#include "content/public/browser/navigation_throttle.h" #include "content/public/browser/navigation_throttle.h"
namespace content { namespace content {
class NavigationHandle; class NavigationHandle;
} }
// Used to show an interstitial page while merge session process (cookie // Used to delay a navigation while merge session process (cookie
// reconstruction from OAuth2 refresh token in ChromeOS login) is still in // reconstruction from OAuth2 refresh token in ChromeOS login) is still in
// progress while we are attempting to load a google property. // progress while we are attempting to load a google property. It will resume
class MergeSessionNavigationThrottle : public content::NavigationThrottle { // the navigation once merge session is done, or after 10 seconds.
class MergeSessionNavigationThrottle
: public content::NavigationThrottle,
public chromeos::OAuth2LoginManager::Observer {
public: public:
static std::unique_ptr<content::NavigationThrottle> Create( static std::unique_ptr<content::NavigationThrottle> Create(
content::NavigationHandle* handle); content::NavigationHandle* handle);
...@@ -33,10 +38,21 @@ class MergeSessionNavigationThrottle : public content::NavigationThrottle { ...@@ -33,10 +38,21 @@ class MergeSessionNavigationThrottle : public content::NavigationThrottle {
override; override;
const char* GetNameForLogging() override; const char* GetNameForLogging() override;
// MergeSessionLoadPage callback. // OAuth2LoginManager::Observer implementation:
void OnBlockingPageComplete(); void OnSessionRestoreStateChanged(
Profile* user_profile,
chromeos::OAuth2LoginManager::SessionRestoreState state) override;
base::WeakPtrFactory<MergeSessionNavigationThrottle> weak_factory_; // Sets up timer and OAuth2LoginManager Observer, should be called before
// deferring. Returns true if the Observer was set up correctly and the
// navigation still needs to be delayed, false otherwise.
bool BeforeDefer();
// Cleans up timer and OAuth2LoginManager Observer, then resumes a deferred
// navigation.
void Proceed();
base::OneShotTimer proceed_timer_;
DISALLOW_COPY_AND_ASSIGN(MergeSessionNavigationThrottle); DISALLOW_COPY_AND_ASSIGN(MergeSessionNavigationThrottle);
}; };
......
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <stdint.h> #include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/chromeos/login/signin/merge_session_load_page.h" #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
#include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
#include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/interstitial_page.h" #include "components/user_manager/scoped_user_manager.h"
#include "content/public/browser/navigation_controller.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/navigation_simulator.h" #include "content/public/test/navigation_simulator.h"
#include "content/public/test/web_contents_tester.h"
using content::InterstitialPage;
using content::NavigationSimulator;
using content::WebContents;
using content::WebContentsTester;
namespace { namespace {
const char kURL1[] = "http://www.google.com/"; constexpr char kURL[] = "http://www.google.com/";
const char kURL2[] = "http://mail.google.com/"; constexpr int kSessionMergeTimeout = 60;
const int64_t kSessionMergeTimeout = 60;
} // namespace } // namespace
namespace chromeos { namespace chromeos {
// An MergeSessionLoadPage class that does not create windows. class MergeSessionNavigationThrottleTest
class TestMergeSessionLoadPage : public MergeSessionLoadPage { : public ChromeRenderViewHostTestHarness {
public: public:
TestMergeSessionLoadPage(WebContents* web_contents, const GURL& url) MergeSessionNavigationThrottleTest() = default;
: MergeSessionLoadPage(
web_contents,
url,
merge_session_throttling_utils::CompletionCallback()) {
interstitial_page_->DontCreateViewForTesting();
}
private:
DISALLOW_COPY_AND_ASSIGN(TestMergeSessionLoadPage);
};
class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness {
protected: protected:
void TearDown() override { ChromeRenderViewHostTestHarness::TearDown(); } void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp();
void ShowInterstitial(const char* url) { // This is needed since the global state is not cleared in
(new TestMergeSessionLoadPage(web_contents(), GURL(url)))->Show(); // merge_session_throttling_utils between tests, and tests can fail
// depending on the order they are run in otherwise due to the navigation
// throttle not being created for further navigations.
merge_session_throttling_utils::ResetAreAllSessionsMergedForTesting();
FakeChromeUserManager* fake_manager = new FakeChromeUserManager();
AccountId account_id(AccountId::FromUserEmail("user@example.com"));
fake_manager->AddUser(account_id);
fake_manager->LoginUser(account_id);
user_manager_ = std::make_unique<user_manager::ScopedUserManager>(
base::WrapUnique(std::move(fake_manager)));
} }
// Returns the MergeSessionLoadPage currently showing or NULL if none is void TearDown() override {
// showing. user_manager_.reset();
InterstitialPage* GetMergeSessionLoadPage() { base::RunLoop().RunUntilIdle();
return InterstitialPage::GetInterstitialPage(web_contents()); ChromeRenderViewHostTestHarness::TearDown();
} }
OAuth2LoginManager* GetOAuth2LoginManager() { OAuth2LoginManager* GetOAuth2LoginManager() {
content::BrowserContext* browser_context = content::BrowserContext* browser_context =
web_contents()->GetBrowserContext(); web_contents()->GetBrowserContext();
if (!browser_context) if (!browser_context)
return NULL; return nullptr;
Profile* profile = Profile::FromBrowserContext(browser_context); Profile* profile = Profile::FromBrowserContext(browser_context);
if (!profile) if (!profile)
return NULL; return nullptr;
OAuth2LoginManager* login_manager = OAuth2LoginManager* login_manager =
OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile); OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile);
...@@ -93,74 +79,43 @@ class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness { ...@@ -93,74 +79,43 @@ class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness {
} }
private: private:
ScopedTestDeviceSettingsService test_device_settings_service_; std::unique_ptr<user_manager::ScopedUserManager> user_manager_;
ScopedTestCrosSettings test_cros_settings_;
}; };
TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { // Tests navigations are not deferred when merge session is already done.
TEST_F(MergeSessionNavigationThrottleTest, NotThrottled) {
SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE); SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE);
// Start a load. auto navigation = content::NavigationSimulator::CreateBrowserInitiated(
NavigationSimulator::NavigateAndCommitFromBrowser(web_contents(), GURL(kURL), web_contents());
GURL(kURL1));
// Load next page.
auto navigation =
NavigationSimulator::CreateBrowserInitiated(GURL(kURL2), web_contents());
navigation->Start(); navigation->Start();
EXPECT_FALSE(navigation->IsDeferred());
// Simulate the load causing an merge session interstitial page
// to be shown.
InterstitialPage* interstitial = GetMergeSessionLoadPage();
EXPECT_FALSE(interstitial);
} }
TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShownOnTimeout) { // Tests navigations are deferred when merge session is in progress, and
// resumed once it's done.
TEST_F(MergeSessionNavigationThrottleTest, Throttled) {
SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS); SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS);
SetSessionRestoreStart(base::Time::Now() + base::TimeDelta::FromSeconds( SetSessionRestoreStart(base::Time::Now());
kSessionMergeTimeout + 1)); auto navigation = content::NavigationSimulator::CreateBrowserInitiated(
GURL(kURL), web_contents());
// Start a load. navigation->SetAutoAdvance(false);
NavigationSimulator::NavigateAndCommitFromBrowser(web_contents(),
GURL(kURL1));
// Load next page.
auto navigation =
NavigationSimulator::CreateBrowserInitiated(GURL(kURL2), web_contents());
navigation->Start(); navigation->Start();
EXPECT_TRUE(navigation->IsDeferred());
// Simulate the load causing an merge session interstitial page SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE);
// to be shown. navigation->Wait();
InterstitialPage* interstitial = GetMergeSessionLoadPage(); EXPECT_FALSE(navigation->IsDeferred());
EXPECT_FALSE(interstitial);
} }
TEST_F(MergeSessionLoadPageTest, MergeSessionPageShown) { // Tests navigations are not deferred if merge session started over 60
// seconds ago
TEST_F(MergeSessionNavigationThrottleTest, Timeout) {
SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS); SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS);
SetSessionRestoreStart(base::Time::Now() - base::TimeDelta::FromSeconds(
// Start a load. kSessionMergeTimeout + 1));
NavigationSimulator::NavigateAndCommitFromBrowser(web_contents(), auto navigation = content::NavigationSimulator::CreateBrowserInitiated(
GURL(kURL1)); GURL(kURL), web_contents());
// Load next page.
auto navigation =
NavigationSimulator::CreateBrowserInitiated(GURL(kURL2), web_contents());
navigation->Start(); navigation->Start();
EXPECT_FALSE(navigation->IsDeferred());
// Simulate the load causing an merge session interstitial page
// to be shown.
ShowInterstitial(kURL2);
InterstitialPage* interstitial = GetMergeSessionLoadPage();
ASSERT_TRUE(interstitial);
base::RunLoop().RunUntilIdle();
// Simulate merge session completion.
SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE);
base::RunLoop().RunUntilIdle();
// The URL remains to be URL2.
EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec());
// Commit navigation and the interstitial page is gone.
navigation->Commit();
EXPECT_FALSE(GetMergeSessionLoadPage());
} }
} // namespace chromeos } // namespace chromeos
...@@ -211,4 +211,21 @@ bool IsSessionRestorePending(Profile* profile) { ...@@ -211,4 +211,21 @@ bool IsSessionRestorePending(Profile* profile) {
return pending_session_restore; return pending_session_restore;
} }
void ResetAreAllSessionsMergedForTesting() {
if (AreAllSessionMergedAlready()) {
// This is safe for tests since it will only be called from SetUp() once per
// test and not concurrently.
int current_value = g_all_profiles_restored_.SubtleRefCountForDebug();
bool is_positive = current_value > 0;
if (!is_positive)
current_value *= -1;
for (int i = 0; i < current_value; i++) {
if (is_positive)
g_all_profiles_restored_.Decrement();
else
g_all_profiles_restored_.Increment();
}
}
}
} // namespace merge_session_throttling_utils } // namespace merge_session_throttling_utils
...@@ -50,6 +50,9 @@ bool ShouldDelayUrl(const GURL& url); ...@@ -50,6 +50,9 @@ bool ShouldDelayUrl(const GURL& url);
// True if session restore hasn't started or in progress. // True if session restore hasn't started or in progress.
bool IsSessionRestorePending(Profile* profile); bool IsSessionRestorePending(Profile* profile);
// Resets the merged session counter, should only be used in tests.
void ResetAreAllSessionsMergedForTesting();
} // namespace merge_session_throttling_utils } // namespace merge_session_throttling_utils
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_MERGE_SESSION_THROTTLING_UTILS_H_ #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_MERGE_SESSION_THROTTLING_UTILS_H_
...@@ -111,7 +111,7 @@ class OAuth2LoginManager : public KeyedService, ...@@ -111,7 +111,7 @@ class OAuth2LoginManager : public KeyedService,
bool ShouldBlockTabLoading() const; bool ShouldBlockTabLoading() const;
private: private:
friend class MergeSessionLoadPageTest; friend class MergeSessionNavigationThrottleTest;
friend class OAuth2Test; friend class OAuth2Test;
// Session restore outcomes (for UMA). // Session restore outcomes (for UMA).
......
<!doctype html>
<html i18n-values="dir:textdirection;lang:language">
<head>
<title i18n-content="title">
</title>
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<style>
html {
height: 100%;
}
body {
background: white;
color: #000;
display: -webkit-box;
height: 100%;
margin: 0;
padding: 0;
user-select: none;
visibility: hidden;
width: 100%;
}
.header {
padding: 3px;
width: 80%;
}
</style>
<script>
function sendCommand(cmd) {
window.domAutomationController.send(cmd);
}
// Show the interstitial page.
function showPage() {
document.body.style.visibility = 'visible';
}
// Show the interstitial page.
function forceLoad() {
sendCommand('proceed');
}
document.addEventListener('DOMContentLoaded', function() {
var showDelayTime = loadTimeData.getString('show_delay_time');
var totalWaitTime = loadTimeData.getString('total_wait_time');
window.setTimeout(showPage, showDelayTime);
window.setTimeout(forceLoad, totalWaitTime);
});
</script>
<body oncontextmenu="return false;">
<div class="header" i18n-content="heading" id="mgs">
</div>
</body>
</html>
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