Commit 1fac246b authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

cros oobe: Introduce FakeEulaMixin

Mixin extracted from the Eula browsertests.
Mixin to be reused for the OobeEndToEnd tests.
Also removed DISABLED on MSAN code - covered by oobe msan filters.

Bug: 1032194, 1041188
Change-Id: I96e192dd86f59e4634779d824898c3097cf18d03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343074Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Auto-Submit: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796009}
parent 6de05b40
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/test/dialog_window_waiter.h" #include "chrome/browser/chromeos/login/test/dialog_window_waiter.h"
#include "chrome/browser/chromeos/login/test/fake_eula_mixin.h"
#include "chrome/browser/chromeos/login/test/js_checker.h" #include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/browser/chromeos/login/test/oobe_base_test.h" #include "chrome/browser/chromeos/login/test/oobe_base_test.h"
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
...@@ -43,33 +43,15 @@ ...@@ -43,33 +43,15 @@
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h" #include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "net/test/embedded_test_server/embedded_test_server.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" #include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h" #include "url/gurl.h"
using net::test_server::BasicHttpResponse;
using net::test_server::HttpRequest;
using net::test_server::HttpResponse;
using ::testing::ElementsAre; using ::testing::ElementsAre;
namespace chromeos { namespace chromeos {
namespace { namespace {
constexpr char kFakeOnlineEulaPath[] = "/intl/en-US/chrome/eula_text.html";
constexpr char kFakeOnlineEula[] = "No obligations at all";
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// See IDS_TERMS_HTML for the complete text.
constexpr char kOfflineEULAWarning[] =
"Google Chrome and Chrome OS Additional Terms of Service";
#else
// Placeholder text in terms_chromium.html.
constexpr char kOfflineEULAWarning[] =
"In official builds this space will show the terms of service.";
#endif
const test::UIPath kEulaWebview = {"oobe-eula-md", "crosEulaFrame"}; const test::UIPath kEulaWebview = {"oobe-eula-md", "crosEulaFrame"};
const test::UIPath kAcceptEulaButton = {"oobe-eula-md", "acceptButton"}; const test::UIPath kAcceptEulaButton = {"oobe-eula-md", "acceptButton"};
const test::UIPath kEulaTPMPassword = {"oobe-eula-md", "eula-password"}; const test::UIPath kEulaTPMPassword = {"oobe-eula-md", "eula-password"};
...@@ -128,33 +110,12 @@ class EulaTest : public OobeBaseTest { ...@@ -128,33 +110,12 @@ class EulaTest : public OobeBaseTest {
EulaTest() = default; EulaTest() = default;
~EulaTest() override = default; ~EulaTest() override = default;
// OobeBaseTest:
void SetUpCommandLine(base::CommandLine* command_line) override {
OobeBaseTest::SetUpCommandLine(command_line);
// Retrieve the URL from the embedded test server and override EULA URL.
std::string fake_eula_url =
embedded_test_server()->base_url().Resolve(kFakeOnlineEulaPath).spec();
command_line->AppendSwitchASCII(switches::kOobeEulaUrlForTests,
fake_eula_url);
}
// OobeBaseTest:
void RegisterAdditionalRequestHandlers() override {
embedded_test_server()->RegisterRequestHandler(
base::Bind(&EulaTest::HandleRequest, base::Unretained(this)));
}
void ShowEulaScreen() { void ShowEulaScreen() {
LoginDisplayHost::default_host()->StartWizard(EulaView::kScreenId); LoginDisplayHost::default_host()->StartWizard(EulaView::kScreenId);
OobeScreenWaiter(EulaView::kScreenId).Wait(); OobeScreenWaiter(EulaView::kScreenId).Wait();
} }
protected: protected:
// Used for customizing the response handler of the embedded server.
void set_force_http_unavailable(bool force_unavailable) {
force_http_unavailable_ = force_unavailable;
}
content::WebContents* FindEulaContents() { content::WebContents* FindEulaContents() {
// Tag the Eula webview in use with a unique name. // Tag the Eula webview in use with a unique name.
constexpr char kUniqueEulaWebviewName[] = "unique-eula-webview-name"; constexpr char kUniqueEulaWebviewName[] = "unique-eula-webview-name";
...@@ -239,34 +200,9 @@ class EulaTest : public OobeBaseTest { ...@@ -239,34 +200,9 @@ class EulaTest : public OobeBaseTest {
return consented; return consented;
} }
private: FakeEulaMixin fake_eula_{&mixin_host_, embedded_test_server()};
std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
const std::string request_path = request_url.path();
if (!base::EndsWith(request_path, "/eula_text.html",
base::CompareCase::SENSITIVE)) {
return std::unique_ptr<HttpResponse>();
}
std::unique_ptr<BasicHttpResponse> http_response =
std::make_unique<BasicHttpResponse>();
if (force_http_unavailable_) {
http_response->set_code(net::HTTP_SERVICE_UNAVAILABLE);
} else {
http_response->set_code(net::HTTP_OK);
http_response->set_content_type("text/html");
http_response->set_content(kFakeOnlineEula);
}
return std::move(http_response);
}
// The default behaviour for the embedded server is to service the
// online version properly. Offline tests may change this during construction
// of the class.
bool force_http_unavailable_ = false;
private:
DISALLOW_COPY_AND_ASSIGN(EulaTest); DISALLOW_COPY_AND_ASSIGN(EulaTest);
}; };
...@@ -274,7 +210,7 @@ class EulaTest : public OobeBaseTest { ...@@ -274,7 +210,7 @@ class EulaTest : public OobeBaseTest {
// embedded server have to be handled differently. // embedded server have to be handled differently.
class EulaOfflineTest : public EulaTest { class EulaOfflineTest : public EulaTest {
public: public:
EulaOfflineTest() { set_force_http_unavailable(true); } EulaOfflineTest() { fake_eula_.set_force_http_unavailable(true); }
~EulaOfflineTest() override = default; ~EulaOfflineTest() override = default;
}; };
...@@ -285,20 +221,13 @@ IN_PROC_BROWSER_TEST_F(EulaOfflineTest, LoadOffline) { ...@@ -285,20 +221,13 @@ IN_PROC_BROWSER_TEST_F(EulaOfflineTest, LoadOffline) {
ShowEulaScreen(); ShowEulaScreen();
WaitForLocalWebviewLoad(); WaitForLocalWebviewLoad();
EXPECT_TRUE( EXPECT_TRUE(test::GetWebViewContents(kEulaWebview)
test::GetWebViewContents(kEulaWebview).find(kOfflineEULAWarning) != .find(FakeEulaMixin::kOfflineEULAWarning) !=
std::string::npos); std::string::npos);
} }
#if defined(OS_CHROMEOS) && \
(defined(MEMORY_SANITIZER) || defined(LEAK_SANITIZER))
// TODO(http://crbug.com/1041188): flaky on ChromeOS MSAN and LSAN.
#define MAYBE_LoadOnline DISABLED_LoadOnline
#else
#define MAYBE_LoadOnline LoadOnline
#endif
// Tests that online version is shown when it is accessible. // Tests that online version is shown when it is accessible.
IN_PROC_BROWSER_TEST_F(EulaTest, MAYBE_LoadOnline) { IN_PROC_BROWSER_TEST_F(EulaTest, LoadOnline) {
ShowEulaScreen(); ShowEulaScreen();
// Wait until the webview has finished loading. // Wait until the webview has finished loading.
...@@ -310,7 +239,8 @@ IN_PROC_BROWSER_TEST_F(EulaTest, MAYBE_LoadOnline) { ...@@ -310,7 +239,8 @@ IN_PROC_BROWSER_TEST_F(EulaTest, MAYBE_LoadOnline) {
chromeos::test::OobeJS().CreateEnabledWaiter(true, kAcceptEulaButton)->Wait(); chromeos::test::OobeJS().CreateEnabledWaiter(true, kAcceptEulaButton)->Wait();
const std::string webview_contents = test::GetWebViewContents(kEulaWebview); const std::string webview_contents = test::GetWebViewContents(kEulaWebview);
EXPECT_TRUE(webview_contents.find(kFakeOnlineEula) != std::string::npos); EXPECT_TRUE(webview_contents.find(FakeEulaMixin::kFakeOnlineEula) !=
std::string::npos);
} }
// Tests that clicking on "System security settings" button opens a dialog // Tests that clicking on "System security settings" button opens a dialog
......
// Copyright 2020 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/test/fake_eula_mixin.h"
#include "base/bind.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chromeos/constants/chromeos_switches.h"
#include "url/gurl.h"
using net::test_server::BasicHttpResponse;
using net::test_server::HttpRequest;
using net::test_server::HttpResponse;
namespace chromeos {
namespace {
constexpr char kFakeOnlineEulaPath[] = "/intl/en-US/chrome/eula_text.html";
} // namespace
const char* FakeEulaMixin::kFakeOnlineEula = "No obligations at all";
const char* FakeEulaMixin::kOfflineEULAWarning =
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// See IDS_TERMS_HTML for the complete text.
"Google Chrome and Chrome OS Additional Terms of Service";
#else
// Placeholder text in terms_chromium.html.
"In official builds this space will show the terms of service.";
#endif
FakeEulaMixin::FakeEulaMixin(InProcessBrowserTestMixinHost* host,
net::EmbeddedTestServer* test_server)
: InProcessBrowserTestMixin(host), test_server_(test_server) {}
FakeEulaMixin::~FakeEulaMixin() = default;
void FakeEulaMixin::SetUp() {
test_server_->RegisterRequestHandler(base::BindRepeating(
&FakeEulaMixin::HandleRequest, base::Unretained(this)));
}
void FakeEulaMixin::SetUpCommandLine(base::CommandLine* command_line) {
// Retrieve the URL from the embedded test server and override EULA URL.
std::string fake_eula_url =
test_server_->base_url().Resolve(kFakeOnlineEulaPath).spec();
command_line->AppendSwitchASCII(switches::kOobeEulaUrlForTests,
fake_eula_url);
}
std::unique_ptr<HttpResponse> FakeEulaMixin::HandleRequest(
const HttpRequest& request) {
GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
const std::string request_path = request_url.path();
if (!base::EndsWith(request_path, "/eula_text.html",
base::CompareCase::SENSITIVE)) {
return nullptr;
}
std::unique_ptr<BasicHttpResponse> http_response =
std::make_unique<BasicHttpResponse>();
if (force_http_unavailable_) {
http_response->set_code(net::HTTP_SERVICE_UNAVAILABLE);
} else {
http_response->set_code(net::HTTP_OK);
http_response->set_content_type("text/html");
http_response->set_content(kFakeOnlineEula);
}
return std::move(http_response);
}
} // namespace chromeos
// Copyright 2020 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_TEST_FAKE_EULA_MIXIN_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_TEST_FAKE_EULA_MIXIN_H_
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
using net::test_server::HttpRequest;
using net::test_server::HttpResponse;
namespace chromeos {
// Mixin that serves fake eula for OOBE.
class FakeEulaMixin : public InProcessBrowserTestMixin {
public:
static const char* kFakeOnlineEula;
static const char* kOfflineEULAWarning;
FakeEulaMixin(InProcessBrowserTestMixinHost* host,
net::EmbeddedTestServer* test_server);
void SetUp() override;
void SetUpCommandLine(base::CommandLine* command_line) override;
~FakeEulaMixin() override;
// Used for customizing the response handler of the embedded server.
void set_force_http_unavailable(bool force_unavailable) {
force_http_unavailable_ = force_unavailable;
}
private:
std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request);
net::EmbeddedTestServer* test_server_;
// The default behaviour for the embedded server is to service the
// online version properly. Offline tests may change this during construction
// of the class.
bool force_http_unavailable_ = false;
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_TEST_FAKE_EULA_MIXIN_H_
...@@ -2361,6 +2361,8 @@ if (!is_android) { ...@@ -2361,6 +2361,8 @@ if (!is_android) {
"../browser/chromeos/login/test/enrollment_helper_mixin.h", "../browser/chromeos/login/test/enrollment_helper_mixin.h",
"../browser/chromeos/login/test/enrollment_ui_mixin.cc", "../browser/chromeos/login/test/enrollment_ui_mixin.cc",
"../browser/chromeos/login/test/enrollment_ui_mixin.h", "../browser/chromeos/login/test/enrollment_ui_mixin.h",
"../browser/chromeos/login/test/fake_eula_mixin.cc",
"../browser/chromeos/login/test/fake_eula_mixin.h",
"../browser/chromeos/login/test/fake_gaia_mixin.cc", "../browser/chromeos/login/test/fake_gaia_mixin.cc",
"../browser/chromeos/login/test/fake_gaia_mixin.h", "../browser/chromeos/login/test/fake_gaia_mixin.h",
"../browser/chromeos/login/test/guest_session_mixin.cc", "../browser/chromeos/login/test/guest_session_mixin.cc",
......
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