2016-11-07 20:14:09 +01:00
|
|
|
// Copyright 2016 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "include/cef_callback.h"
|
|
|
|
#include "include/cef_parser.h"
|
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/test_handler.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/gtest/include/gtest/gtest.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
typedef std::vector<std::string> UrlList;
|
|
|
|
|
|
|
|
class WebUITestHandler : public TestHandler {
|
|
|
|
public:
|
|
|
|
explicit WebUITestHandler(const UrlList& url_list)
|
2017-05-17 11:29:28 +02:00
|
|
|
: url_list_(url_list), url_index_(0U), expected_error_code_(ERR_NONE) {
|
2016-11-07 20:14:09 +01:00
|
|
|
CHECK(!url_list_.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_expected_url(const std::string& expected_url) {
|
|
|
|
expected_url_ = expected_url;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_expected_error_code(int error_code) {
|
|
|
|
expected_error_code_ = error_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
// Create the browser.
|
|
|
|
CreateBrowser(url_list_[0]);
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout((int(url_list_.size() / 5U) + 1) * 5000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NextNav() {
|
2021-06-19 21:54:45 +02:00
|
|
|
base::OnceClosure next_action;
|
2016-11-07 20:14:09 +01:00
|
|
|
|
2020-02-10 18:10:17 +01:00
|
|
|
if (++url_index_ < url_list_.size()) {
|
2021-06-19 21:54:45 +02:00
|
|
|
next_action = base::BindOnce(&WebUITestHandler::LoadURL, this,
|
|
|
|
url_list_[url_index_]);
|
2020-02-10 18:10:17 +01:00
|
|
|
} else {
|
2021-06-19 21:54:45 +02:00
|
|
|
next_action = base::BindOnce(&WebUITestHandler::DestroyTest, this);
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wait a bit for the WebUI content to finish loading before performing the
|
|
|
|
// next action.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostDelayedTask(TID_UI, std::move(next_action), 200);
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadURL(const std::string& url) {
|
|
|
|
GetBrowser()->GetMainFrame()->LoadURL(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
|
|
|
if (!isLoading) {
|
2018-03-20 21:15:08 +01:00
|
|
|
got_loading_state_done_.yes();
|
|
|
|
NextNavIfDone(browser->GetMainFrame()->GetURL());
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
|
|
|
got_load_error_.yes();
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_EQ(expected_error_code_, errorCode)
|
|
|
|
<< "failedUrl = " << failedUrl.ToString();
|
2018-03-20 21:15:08 +01:00
|
|
|
NextNavIfDone(failedUrl);
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyTest() override {
|
2018-03-20 21:15:08 +01:00
|
|
|
EXPECT_TRUE(got_loading_state_done_);
|
2016-11-07 20:14:09 +01:00
|
|
|
if (expected_error_code_ == ERR_NONE)
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
else
|
|
|
|
EXPECT_TRUE(got_load_error_);
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
private:
|
|
|
|
void NextNavIfDone(const std::string& url) {
|
|
|
|
bool done = false;
|
|
|
|
if (expected_error_code_ == ERR_NONE) {
|
|
|
|
if (got_loading_state_done_)
|
|
|
|
done = true;
|
|
|
|
} else if (got_load_error_ && got_loading_state_done_) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (done) {
|
|
|
|
// Verify that we navigated to the expected URL.
|
|
|
|
std::string expected_url = expected_url_;
|
2020-02-10 18:10:17 +01:00
|
|
|
if (expected_url.empty() && url_index_ < url_list_.size())
|
2018-03-20 21:15:08 +01:00
|
|
|
expected_url = url_list_[url_index_];
|
|
|
|
EXPECT_STREQ(expected_url.c_str(), url.c_str());
|
|
|
|
|
|
|
|
NextNav();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
UrlList url_list_;
|
|
|
|
size_t url_index_;
|
|
|
|
|
|
|
|
std::string expected_url_;
|
|
|
|
int expected_error_code_;
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
TrackCallback got_loading_state_done_;
|
2016-11-07 20:14:09 +01:00
|
|
|
TrackCallback got_load_error_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(WebUITestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test hosts with special behaviors.
|
|
|
|
|
|
|
|
// about:* URIs should redirect to chrome://*.
|
|
|
|
TEST(WebUITest, about) {
|
|
|
|
UrlList url_list;
|
|
|
|
url_list.push_back("about:license");
|
|
|
|
CefRefPtr<WebUITestHandler> handler = new WebUITestHandler(url_list);
|
|
|
|
handler->set_expected_url("chrome://license/");
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// chrome://network-error/X should generate network error X.
|
|
|
|
TEST(WebUITest, network_error) {
|
|
|
|
UrlList url_list;
|
|
|
|
// -310 is ERR_TOO_MANY_REDIRECTS
|
|
|
|
url_list.push_back("chrome://network-error/-310");
|
|
|
|
CefRefPtr<WebUITestHandler> handler = new WebUITestHandler(url_list);
|
|
|
|
handler->set_expected_error_code(ERR_TOO_MANY_REDIRECTS);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test hosts with a single URL.
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void RunWebUITest(const UrlList& url_list) {
|
|
|
|
CefRefPtr<WebUITestHandler> handler = new WebUITestHandler(url_list);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunWebUITest(const std::string& url) {
|
|
|
|
UrlList url_list;
|
|
|
|
url_list.push_back(url);
|
|
|
|
RunWebUITest(url_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define WEBUI_TEST(name) \
|
|
|
|
TEST(WebUITest, name) { \
|
|
|
|
std::string name_str = #name; \
|
2016-11-07 20:14:09 +01:00
|
|
|
std::replace(name_str.begin(), name_str.end(), '_', '-'); \
|
2017-05-17 11:29:28 +02:00
|
|
|
RunWebUITest("chrome://" + name_str + "/"); \
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
|
|
|
|
2019-03-13 22:27:37 +01:00
|
|
|
WEBUI_TEST(appcache_internals)
|
|
|
|
WEBUI_TEST(accessibility)
|
|
|
|
WEBUI_TEST(blob_internals)
|
|
|
|
WEBUI_TEST(extensions_support)
|
|
|
|
WEBUI_TEST(gpu)
|
|
|
|
WEBUI_TEST(histograms)
|
|
|
|
WEBUI_TEST(indexeddb_internals)
|
|
|
|
WEBUI_TEST(license)
|
|
|
|
WEBUI_TEST(media_internals)
|
|
|
|
WEBUI_TEST(net_export)
|
|
|
|
WEBUI_TEST(network_errors)
|
|
|
|
WEBUI_TEST(serviceworker_internals)
|
|
|
|
WEBUI_TEST(system)
|
|
|
|
WEBUI_TEST(tracing)
|
|
|
|
WEBUI_TEST(version)
|
|
|
|
WEBUI_TEST(webrtc_internals)
|
|
|
|
WEBUI_TEST(webui_hosts)
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
// Test hosts with multiple URLs.
|
|
|
|
|
|
|
|
TEST(WebUITest, net_internals) {
|
|
|
|
UrlList url_list;
|
|
|
|
url_list.push_back("chrome://net-internals/#events");
|
2018-10-02 14:14:11 +02:00
|
|
|
url_list.push_back("chrome://net-internals/#proxy");
|
2016-11-07 20:14:09 +01:00
|
|
|
url_list.push_back("chrome://net-internals/#dns");
|
|
|
|
url_list.push_back("chrome://net-internals/#sockets");
|
|
|
|
url_list.push_back("chrome://net-internals/#hsts");
|
|
|
|
|
|
|
|
RunWebUITest(url_list);
|
|
|
|
}
|