Commit 5fd0e6ed authored by Renato Silva's avatar Renato Silva Committed by Commit Bot

Fix browser test EulaTest.LoadOffline

This commit improves the reliability of the EULA browser test
EulaTest.LoadOffline. This test was disabled due to its flakiness
in the past and is now enabled again.

Tested locally. Ran 100 tests under stress without any errors.

Bug: 1015948
Change-Id: I59bc8612da9f5be526a2aa28d13ee70400dbb01e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1892775Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Commit-Queue: Renato Silva <rrsilva@google.com>
Cr-Commit-Position: refs/heads/master@{#712516}
parent 36348bf0
......@@ -72,8 +72,10 @@ class WebContentsLoadFinishedWaiter : public content::WebContentsObserver {
~WebContentsLoadFinishedWaiter() override = default;
void Wait() {
if (!web_contents()->IsLoading())
if (!web_contents()->IsLoading() &&
web_contents()->GetLastCommittedURL() != GURL::EmptyGURL()) {
return;
}
run_loop_ = std::make_unique<base::RunLoop>();
run_loop_->Run();
......@@ -107,26 +109,23 @@ class EulaTest : public OobeBaseTest {
EulaTest() = default;
~EulaTest() override = default;
void SetUpOnMainThread() override {
// Retrieve the URL from the embedded test server and override EULA URL.
fake_eula_url_ =
embedded_test_server()->base_url().Resolve(kFakeOnlineEulaPath).spec();
EulaScreenHandler::set_eula_url_for_testing(fake_eula_url_.c_str());
OobeBaseTest::SetUpOnMainThread();
}
// OobeBaseTest:
void RegisterAdditionalRequestHandlers() override {
embedded_test_server()->RegisterRequestHandler(
base::Bind(&EulaTest::HandleRequest, base::Unretained(this)));
}
void OverrideOnlineEulaUrl() {
// Override with the embedded test server's base url. Otherwise, the load
// would not hit the embedded test server.
const GURL fake_eula_url =
embedded_test_server()->base_url().Resolve(kFakeOnlineEulaPath);
test::OobeJS().Evaluate(
base::StringPrintf("loadTimeData.overrideValues({eulaOnlineUrl: '%s'});"
"Oobe.updateLocalizedContent();",
fake_eula_url.spec().c_str()));
}
void ShowEulaScreen() {
LoginDisplayHost::default_host()->StartWizard(EulaView::kScreenId);
OverrideOnlineEulaUrl();
OobeScreenWaiter(EulaView::kScreenId).Wait();
}
......@@ -230,6 +229,9 @@ class EulaTest : public OobeBaseTest {
bool allow_online_eula_ = false;
// URL used for testing. Retrieved from the embedded server.
std::string fake_eula_url_;
DISALLOW_COPY_AND_ASSIGN(EulaTest);
};
......@@ -247,8 +249,7 @@ IN_PROC_BROWSER_TEST_F(EulaTest, DISABLED_LoadOnline) {
// Tests that offline version is shown when the online version is not
// accessible.
// Disable due to flaky crbug.com/1015948
IN_PROC_BROWSER_TEST_F(EulaTest, DISABLED_LoadOffline) {
IN_PROC_BROWSER_TEST_F(EulaTest, LoadOffline) {
set_allow_online_eula(false);
ShowEulaScreen();
......@@ -261,8 +262,14 @@ IN_PROC_BROWSER_TEST_F(EulaTest, DISABLED_LoadOffline) {
WebContentsLoadFinishedWaiter(eula_contents).Wait();
}
EXPECT_TRUE(test::GetWebViewContents({"oobe-eula-md", "crosEulaFrame"})
.find(kOfflineEULAWarning) != std::string::npos);
// Wait until the Accept button on the EULA frame becomes enabled.
chromeos::test::OobeJS()
.CreateEnabledWaiter(true, {"oobe-eula-md", "acceptButton"})
->Wait();
const std::string webview_contents =
test::GetWebViewContents({"oobe-eula-md", "crosEulaFrame"});
EXPECT_TRUE(webview_contents.find(kOfflineEULAWarning) != std::string::npos);
}
// Tests that clicking on "System security settings" button opens a dialog
......
......@@ -120,6 +120,7 @@ Polymer({
*/
updateLocalizedContent: function(event) {
// This forces frame to reload.
this.acceptButtonDisabled = true;
this.screen.loadEulaToWebview_(this.$.crosEulaFrame);
this.i18nUpdateLocale();
},
......
......@@ -29,6 +29,8 @@ namespace chromeos {
constexpr StaticOobeScreenId EulaView::kScreenId;
const char* EulaScreenHandler::eula_url_for_testing_ = nullptr;
EulaScreenHandler::EulaScreenHandler(JSCallsContainer* js_calls_container,
CoreOobeView* core_oobe_view)
: BaseScreenHandler(kScreenId, js_calls_container),
......@@ -64,6 +66,15 @@ void EulaScreenHandler::Unbind() {
BaseScreenHandler::SetBaseScreen(nullptr);
}
std::string EulaScreenHandler::GetEulaOnlineUrl() {
if (EulaScreenHandler::eula_url_for_testing_) {
return std::string(EulaScreenHandler::eula_url_for_testing_);
}
return base::StringPrintf(chrome::kOnlineEulaURLPath,
g_browser_process->GetApplicationLocale().c_str());
}
void EulaScreenHandler::DeclareLocalizedValues(
::login::LocalizedValuesBuilder* builder) {
builder->Add("eulaScreenAccessibleTitle", IDS_EULA_SCREEN_ACCESSIBLE_TITLE);
......@@ -94,10 +105,8 @@ void EulaScreenHandler::DeclareLocalizedValues(
IDS_SHORT_PRODUCT_OS_NAME);
#endif
builder->Add(
"eulaOnlineUrl",
base::StringPrintf(chrome::kOnlineEulaURLPath,
g_browser_process->GetApplicationLocale().c_str()));
// Online URL to use. May be overridden by tests.
builder->Add("eulaOnlineUrl", GetEulaOnlineUrl());
/* MD-OOBE */
builder->Add("oobeEulaSectionTitle", IDS_OOBE_EULA_SECTION_TITLE);
......
......@@ -62,12 +62,21 @@ class EulaScreenHandler : public EulaView, public BaseScreenHandler {
void GetAdditionalParameters(base::DictionaryValue* dict) override;
void Initialize() override;
// Allows the EULA URL to be overridden by tests.
static void set_eula_url_for_testing(const char* eula_test_url) {
eula_url_for_testing_ = eula_test_url;
}
private:
// JS messages handlers.
void HandleOnLearnMore();
void HandleOnInstallationSettingsPopupOpened();
void HandleUsageStatsEnabled(bool enabled);
// Determines the online URL to use.
std::string GetEulaOnlineUrl();
static const char* eula_url_for_testing_;
void UpdateLocalizedValues(::login::SecureModuleUsed secure_module_used);
EulaScreen* screen_ = nullptr;
......
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