2013-09-03 18:43:31 +02:00
|
|
|
// Copyright (c) 2013 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-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "include/cef_request_context.h"
|
|
|
|
#include "include/cef_request_context_handler.h"
|
2014-07-15 20:10:40 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2016-11-15 18:56:02 +01:00
|
|
|
#include "include/wrapper/cef_scoped_temp_dir.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/test_handler.h"
|
2017-12-22 22:05:32 +01:00
|
|
|
#include "tests/ceftests/test_util.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/gtest/include/gtest/gtest.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, BasicGetGlobal) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefRequestContext> context1 = CefRequestContext::GetGlobalContext();
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_TRUE(context1.get());
|
|
|
|
EXPECT_TRUE(context1->IsGlobal());
|
|
|
|
EXPECT_TRUE(context1->IsSame(context1));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context1));
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefRequestContext> context2 = CefRequestContext::GetGlobalContext();
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_TRUE(context2.get());
|
|
|
|
EXPECT_TRUE(context2->IsGlobal());
|
|
|
|
EXPECT_TRUE(context2->IsSame(context2));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context2));
|
2013-09-03 18:43:31 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(context1->IsSame(context2));
|
|
|
|
EXPECT_TRUE(context2->IsSame(context1));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context2));
|
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context1));
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, BasicCreate) {
|
2013-09-03 18:43:31 +02:00
|
|
|
class Handler : public CefRequestContextHandler {
|
|
|
|
public:
|
|
|
|
Handler() {}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
private:
|
|
|
|
IMPLEMENT_REFCOUNTING(Handler);
|
|
|
|
};
|
|
|
|
|
2013-09-03 21:12:22 +02:00
|
|
|
CefRefPtr<CefRequestContextHandler> handler = new Handler();
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextSettings settings;
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefRequestContext> context1 =
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContext::CreateContext(settings, handler.get());
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_TRUE(context1.get());
|
|
|
|
EXPECT_FALSE(context1->IsGlobal());
|
|
|
|
EXPECT_TRUE(context1->IsSame(context1));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context1));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_EQ(context1->GetHandler().get(), handler.get());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefRequestContext> context2 =
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContext::CreateContext(settings, handler.get());
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_TRUE(context2.get());
|
|
|
|
EXPECT_FALSE(context2->IsGlobal());
|
|
|
|
EXPECT_TRUE(context2->IsSame(context2));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context2));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_EQ(context2->GetHandler().get(), handler.get());
|
|
|
|
|
|
|
|
EXPECT_FALSE(context1->IsSame(context2));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context1->IsSharingWith(context2));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_FALSE(context2->IsSame(context1));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context2->IsSharingWith(context1));
|
2017-05-17 11:29:28 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> context3 = CefRequestContext::GetGlobalContext();
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_TRUE(context3.get());
|
|
|
|
EXPECT_FALSE(context3->IsSame(context1));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context3->IsSharingWith(context1));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_FALSE(context3->IsSame(context2));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context3->IsSharingWith(context2));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_FALSE(context1->IsSame(context3));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context1->IsSharingWith(context3));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_FALSE(context2->IsSame(context3));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context2->IsSharingWith(context3));
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, BasicCreateNoHandler) {
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextSettings settings;
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefRequestContext> context1 =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(settings, nullptr);
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_TRUE(context1.get());
|
|
|
|
EXPECT_FALSE(context1->IsGlobal());
|
|
|
|
EXPECT_TRUE(context1->IsSame(context1));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context1));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_FALSE(context1->GetHandler().get());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefRequestContext> context2 =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(settings, nullptr);
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_TRUE(context2.get());
|
|
|
|
EXPECT_FALSE(context2->IsGlobal());
|
|
|
|
EXPECT_TRUE(context2->IsSame(context2));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context2));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_FALSE(context2->GetHandler().get());
|
|
|
|
|
|
|
|
EXPECT_FALSE(context1->IsSame(context2));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context1->IsSharingWith(context2));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_FALSE(context2->IsSame(context1));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context2->IsSharingWith(context1));
|
2017-05-17 11:29:28 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> context3 = CefRequestContext::GetGlobalContext();
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_TRUE(context3.get());
|
|
|
|
EXPECT_FALSE(context3->IsSame(context1));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context3->IsSharingWith(context1));
|
|
|
|
EXPECT_FALSE(context3->IsSame(context2));
|
|
|
|
EXPECT_FALSE(context3->IsSharingWith(context2));
|
|
|
|
EXPECT_FALSE(context1->IsSame(context3));
|
|
|
|
EXPECT_FALSE(context1->IsSharingWith(context3));
|
|
|
|
EXPECT_FALSE(context2->IsSame(context3));
|
|
|
|
EXPECT_FALSE(context2->IsSharingWith(context3));
|
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, BasicCreateSharedGlobal) {
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextSettings settings;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefRequestContext> context1 = CefRequestContext::GetGlobalContext();
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context1.get());
|
|
|
|
EXPECT_TRUE(context1->IsGlobal());
|
|
|
|
EXPECT_TRUE(context1->IsSame(context1));
|
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context1));
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
// Returns the same global context.
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefRequestContext> context2 =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(context1, nullptr);
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context2.get());
|
2017-05-04 23:53:27 +02:00
|
|
|
EXPECT_TRUE(context2->IsGlobal());
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context2->IsSame(context2));
|
2017-05-04 23:53:27 +02:00
|
|
|
EXPECT_TRUE(context2->IsSame(context1));
|
|
|
|
EXPECT_TRUE(context1->IsSame(context2));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context2));
|
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context1));
|
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context2));
|
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, BasicCreateSharedOnDisk) {
|
2016-11-15 18:56:02 +01:00
|
|
|
CefScopedTempDir tempdir;
|
2021-04-07 00:09:45 +02:00
|
|
|
EXPECT_TRUE(tempdir.CreateUniqueTempDirUnderPath(
|
|
|
|
CefTestSuite::GetInstance()->root_cache_path()));
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
CefRequestContextSettings settings;
|
2016-11-15 18:56:02 +01:00
|
|
|
CefString(&settings.cache_path) = tempdir.GetPath();
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> context1 =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(settings, nullptr);
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context1.get());
|
|
|
|
EXPECT_FALSE(context1->IsGlobal());
|
|
|
|
EXPECT_TRUE(context1->IsSame(context1));
|
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context1));
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> context2 =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(context1, nullptr);
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context2.get());
|
|
|
|
EXPECT_FALSE(context2->IsGlobal());
|
|
|
|
EXPECT_TRUE(context2->IsSame(context2));
|
|
|
|
EXPECT_FALSE(context2->IsSame(context1));
|
|
|
|
EXPECT_FALSE(context1->IsSame(context2));
|
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context2));
|
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context1));
|
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context2));
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> context3 =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(context2, nullptr);
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context3.get());
|
|
|
|
EXPECT_FALSE(context3->IsGlobal());
|
|
|
|
EXPECT_TRUE(context3->IsSame(context3));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_FALSE(context3->IsSame(context2));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_FALSE(context3->IsSame(context1));
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_FALSE(context1->IsSame(context3));
|
|
|
|
EXPECT_FALSE(context2->IsSame(context3));
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context3->IsSharingWith(context3));
|
|
|
|
EXPECT_TRUE(context3->IsSharingWith(context2));
|
|
|
|
EXPECT_TRUE(context3->IsSharingWith(context1));
|
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context3));
|
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context3));
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> context4 =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(context1, nullptr);
|
2015-03-02 21:25:14 +01:00
|
|
|
EXPECT_TRUE(context4.get());
|
|
|
|
EXPECT_FALSE(context4->IsGlobal());
|
|
|
|
EXPECT_TRUE(context4->IsSame(context4));
|
|
|
|
EXPECT_FALSE(context4->IsSame(context3));
|
|
|
|
EXPECT_FALSE(context4->IsSame(context2));
|
|
|
|
EXPECT_FALSE(context4->IsSame(context1));
|
|
|
|
EXPECT_FALSE(context1->IsSame(context4));
|
|
|
|
EXPECT_FALSE(context2->IsSame(context4));
|
|
|
|
EXPECT_FALSE(context3->IsSame(context4));
|
|
|
|
EXPECT_TRUE(context4->IsSharingWith(context4));
|
|
|
|
EXPECT_TRUE(context4->IsSharingWith(context3));
|
|
|
|
EXPECT_TRUE(context4->IsSharingWith(context2));
|
|
|
|
EXPECT_TRUE(context4->IsSharingWith(context1));
|
|
|
|
EXPECT_TRUE(context1->IsSharingWith(context4));
|
|
|
|
EXPECT_TRUE(context2->IsSharingWith(context4));
|
|
|
|
EXPECT_TRUE(context3->IsSharingWith(context4));
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class PopupTestHandler : public TestHandler {
|
|
|
|
public:
|
|
|
|
enum Mode {
|
|
|
|
MODE_WINDOW_OPEN,
|
|
|
|
MODE_TARGETED_LINK,
|
|
|
|
MODE_NOREFERRER_LINK,
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
PopupTestHandler(bool same_origin, Mode mode) : mode_(mode) {
|
2013-09-03 18:43:31 +02:00
|
|
|
url_ = "http://tests-simple-rch1.com/nav1.html";
|
2023-01-02 23:59:03 +01:00
|
|
|
if (same_origin) {
|
2013-09-03 18:43:31 +02:00
|
|
|
popup_url_ = "http://tests-simple-rch1.com/pop1.html";
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2013-09-03 18:43:31 +02:00
|
|
|
popup_url_ = "http://tests-simple-rch2.com/pop1.html";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2013-09-03 18:43:31 +02:00
|
|
|
std::string link;
|
|
|
|
if (mode_ == MODE_TARGETED_LINK) {
|
|
|
|
link = "<a href=\"" + std::string(popup_url_) +
|
2017-05-17 11:29:28 +02:00
|
|
|
"\" target=\"mytarget\"\">CLICK ME</a>";
|
2013-09-03 18:43:31 +02:00
|
|
|
} else if (mode_ == MODE_NOREFERRER_LINK) {
|
|
|
|
link = "<a href=\"" + std::string(popup_url_) +
|
2017-05-17 11:29:28 +02:00
|
|
|
"\" rel=\"noreferrer\" target=\"_blank\"\">CLICK ME</a>";
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AddResource(url_,
|
2017-05-17 11:29:28 +02:00
|
|
|
"<html>"
|
|
|
|
"<head><script>document.cookie='name1=value1';"
|
|
|
|
"function doPopup() { window.open('" +
|
|
|
|
std::string(popup_url_) +
|
|
|
|
"'); }"
|
|
|
|
"</script></head>"
|
|
|
|
"<body><h1>" +
|
|
|
|
link +
|
|
|
|
"</h1></body>"
|
|
|
|
"</html>",
|
|
|
|
"text/html");
|
2013-09-03 18:43:31 +02:00
|
|
|
|
|
|
|
AddResource(popup_url_,
|
2017-05-17 11:29:28 +02:00
|
|
|
"<html>"
|
|
|
|
"<head><script>document.cookie='name2=value2';</script></head>"
|
|
|
|
"<body>Nav1</body>"
|
|
|
|
"</html>",
|
|
|
|
"text/html");
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextSettings settings;
|
|
|
|
|
2020-01-15 14:34:01 +01:00
|
|
|
context_ = CefRequestContext::CreateContext(settings, nullptr);
|
|
|
|
cookie_manager_ = context_->GetCookieManager(nullptr);
|
2013-09-03 18:43:31 +02:00
|
|
|
|
|
|
|
// Create browser that loads the 1st URL.
|
|
|
|
CreateBrowser(url_, context_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefRequestContext> context =
|
|
|
|
browser->GetHost()->GetRequestContext();
|
2013-09-03 18:43:31 +02:00
|
|
|
EXPECT_TRUE(context.get());
|
|
|
|
EXPECT_TRUE(context->IsSame(context_));
|
|
|
|
EXPECT_FALSE(context->IsGlobal());
|
|
|
|
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
if (url == url_) {
|
|
|
|
got_load_end1_.yes();
|
|
|
|
LaunchPopup(browser);
|
2017-05-17 11:29:28 +02:00
|
|
|
} else if (url == popup_url_) {
|
2013-09-03 18:43:31 +02:00
|
|
|
got_load_end2_.yes();
|
|
|
|
EXPECT_TRUE(browser->IsPopup());
|
|
|
|
// Close the popup window.
|
2016-01-19 21:09:01 +01:00
|
|
|
CloseBrowser(browser, true);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& target_url,
|
|
|
|
const CefString& target_frame_name,
|
2015-03-09 21:22:31 +01:00
|
|
|
cef_window_open_disposition_t target_disposition,
|
2015-03-06 22:38:38 +01:00
|
|
|
bool user_gesture,
|
2014-11-12 20:25:15 +01:00
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue>& extra_info,
|
2014-11-12 20:25:15 +01:00
|
|
|
bool* no_javascript_access) override {
|
2013-09-03 18:43:31 +02:00
|
|
|
got_on_before_popup_.yes();
|
|
|
|
|
|
|
|
const std::string& url = target_url;
|
|
|
|
EXPECT_STREQ(url.c_str(), popup_url_.c_str());
|
2015-03-06 22:38:38 +01:00
|
|
|
|
|
|
|
EXPECT_EQ(WOD_NEW_FOREGROUND_TAB, target_disposition);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (mode_ == MODE_WINDOW_OPEN) {
|
2015-03-06 22:38:38 +01:00
|
|
|
EXPECT_FALSE(user_gesture);
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2015-03-06 22:38:38 +01:00
|
|
|
EXPECT_TRUE(user_gesture);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-03-06 22:38:38 +01:00
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnBeforeClose(CefRefPtr<CefBrowser> browser) override {
|
2013-09-03 18:43:31 +02:00
|
|
|
TestHandler::OnBeforeClose(browser);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser->IsPopup()) {
|
2013-09-03 18:43:31 +02:00
|
|
|
FinishTest();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void LaunchPopup(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (mode_ == MODE_WINDOW_OPEN) {
|
|
|
|
browser->GetMainFrame()->ExecuteJavaScript("doPopup()", url_, 0);
|
2017-05-17 11:29:28 +02:00
|
|
|
} else if (mode_ == MODE_TARGETED_LINK || mode_ == MODE_NOREFERRER_LINK) {
|
2013-09-03 18:43:31 +02:00
|
|
|
CefMouseEvent mouse_event;
|
|
|
|
mouse_event.x = 20;
|
|
|
|
mouse_event.y = 20;
|
|
|
|
mouse_event.modifiers = 0;
|
2021-09-20 11:06:23 +02:00
|
|
|
|
|
|
|
// Add some delay to avoid having events dropped or rate limited.
|
|
|
|
CefPostDelayedTask(
|
|
|
|
TID_UI,
|
|
|
|
base::BindOnce(&CefBrowserHost::SendMouseClickEvent,
|
|
|
|
browser->GetHost(), mouse_event, MBT_LEFT, false, 1),
|
|
|
|
50);
|
|
|
|
CefPostDelayedTask(
|
|
|
|
TID_UI,
|
|
|
|
base::BindOnce(&CefBrowserHost::SendMouseClickEvent,
|
|
|
|
browser->GetHost(), mouse_event, MBT_LEFT, true, 1),
|
|
|
|
100);
|
2013-09-03 18:43:31 +02:00
|
|
|
} else {
|
2021-09-20 11:06:23 +02:00
|
|
|
ADD_FAILURE(); // Not reached.
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinishTest() {
|
|
|
|
// Verify that the cookies were set correctly.
|
|
|
|
class TestVisitor : public CefCookieVisitor {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit TestVisitor(PopupTestHandler* handler) : handler_(handler) {}
|
2014-11-12 20:25:15 +01:00
|
|
|
~TestVisitor() override {
|
2013-09-03 18:43:31 +02:00
|
|
|
// Destroy the test.
|
|
|
|
CefPostTask(TID_UI,
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&PopupTestHandler::DestroyTest, handler_));
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool Visit(const CefCookie& cookie,
|
|
|
|
int count,
|
|
|
|
int total,
|
2014-11-12 20:25:15 +01:00
|
|
|
bool& deleteCookie) override {
|
2013-09-03 18:43:31 +02:00
|
|
|
const std::string& name = CefString(&cookie.name);
|
|
|
|
const std::string& value = CefString(&cookie.value);
|
2019-03-22 23:11:51 +01:00
|
|
|
if (name == "name1" && value == "value1") {
|
2013-09-03 18:43:31 +02:00
|
|
|
handler_->got_cookie1_.yes();
|
2019-03-22 23:11:51 +01:00
|
|
|
deleteCookie = true;
|
|
|
|
} else if (name == "name2" && value == "value2") {
|
2013-09-03 18:43:31 +02:00
|
|
|
handler_->got_cookie2_.yes();
|
2019-03-22 23:11:51 +01:00
|
|
|
deleteCookie = true;
|
|
|
|
}
|
2013-09-03 18:43:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PopupTestHandler* handler_;
|
|
|
|
IMPLEMENT_REFCOUNTING(TestVisitor);
|
|
|
|
};
|
|
|
|
|
|
|
|
cookie_manager_->VisitAllCookies(new TestVisitor(this));
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void DestroyTest() override {
|
2013-09-03 18:43:31 +02:00
|
|
|
// Verify test expectations.
|
|
|
|
EXPECT_TRUE(got_load_end1_);
|
|
|
|
EXPECT_TRUE(got_on_before_popup_);
|
|
|
|
EXPECT_TRUE(got_load_end2_);
|
|
|
|
EXPECT_TRUE(got_cookie1_);
|
|
|
|
EXPECT_TRUE(got_cookie2_);
|
2020-01-15 14:34:01 +01:00
|
|
|
context_ = nullptr;
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string url_;
|
|
|
|
std::string popup_url_;
|
|
|
|
Mode mode_;
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> context_;
|
|
|
|
CefRefPtr<CefCookieManager> cookie_manager_;
|
|
|
|
|
|
|
|
TrackCallback got_load_end1_;
|
|
|
|
TrackCallback got_on_before_popup_;
|
|
|
|
TrackCallback got_load_end2_;
|
|
|
|
TrackCallback got_cookie1_;
|
|
|
|
TrackCallback got_cookie2_;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(PopupTestHandler);
|
2013-09-03 18:43:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that a popup created using window.open() will get the same request
|
|
|
|
// context as the parent browser.
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, PopupBasicWindowOpenSameOrigin) {
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<PopupTestHandler> handler =
|
2017-05-17 11:29:28 +02:00
|
|
|
new PopupTestHandler(true, PopupTestHandler::MODE_WINDOW_OPEN);
|
2013-09-03 18:43:31 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, PopupBasicWindowOpenDifferentOrigin) {
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<PopupTestHandler> handler =
|
2017-05-17 11:29:28 +02:00
|
|
|
new PopupTestHandler(false, PopupTestHandler::MODE_WINDOW_OPEN);
|
2013-09-03 18:43:31 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a popup created using a targeted link will get the same request
|
|
|
|
// context as the parent browser.
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, PopupBasicTargetedLinkSameOrigin) {
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<PopupTestHandler> handler =
|
2017-05-17 11:29:28 +02:00
|
|
|
new PopupTestHandler(true, PopupTestHandler::MODE_TARGETED_LINK);
|
2013-09-03 18:43:31 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, PopupBasicTargetedLinkDifferentOrigin) {
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<PopupTestHandler> handler =
|
2017-05-17 11:29:28 +02:00
|
|
|
new PopupTestHandler(false, PopupTestHandler::MODE_TARGETED_LINK);
|
2013-09-03 18:43:31 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a popup created using a noreferrer link will get the same
|
|
|
|
// request context as the parent browser. A new render process will
|
|
|
|
// be created for the popup browser.
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, PopupBasicNoReferrerLinkSameOrigin) {
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<PopupTestHandler> handler =
|
2017-05-17 11:29:28 +02:00
|
|
|
new PopupTestHandler(true, PopupTestHandler::MODE_NOREFERRER_LINK);
|
2013-09-03 18:43:31 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
TEST(RequestContextTest, PopupBasicNoReferrerLinkDifferentOrigin) {
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<PopupTestHandler> handler =
|
2017-05-17 11:29:28 +02:00
|
|
|
new PopupTestHandler(false, PopupTestHandler::MODE_NOREFERRER_LINK);
|
2013-09-03 18:43:31 +02:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
2016-02-23 20:29:18 +01:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const char kPopupNavPageUrl[] = "http://tests-popup.com/page.html";
|
|
|
|
const char kPopupNavPopupUrl[] = "http://tests-popup.com/popup.html";
|
|
|
|
const char kPopupNavPopupUrl2[] = "http://tests-popup2.com/popup.html";
|
|
|
|
const char kPopupNavPopupName[] = "my_popup";
|
|
|
|
|
|
|
|
// Browser side.
|
|
|
|
class PopupNavTestHandler : public TestHandler {
|
|
|
|
public:
|
2017-12-22 22:05:32 +01:00
|
|
|
enum TestMode {
|
2017-05-04 23:53:27 +02:00
|
|
|
ALLOW_CLOSE_POPUP_FIRST,
|
|
|
|
ALLOW_CLOSE_POPUP_LAST,
|
|
|
|
DENY,
|
|
|
|
NAVIGATE_AFTER_CREATION,
|
2017-05-09 22:45:57 +02:00
|
|
|
DESTROY_PARENT_BEFORE_CREATION,
|
|
|
|
DESTROY_PARENT_BEFORE_CREATION_FORCE,
|
|
|
|
DESTROY_PARENT_DURING_CREATION,
|
|
|
|
DESTROY_PARENT_DURING_CREATION_FORCE,
|
|
|
|
DESTROY_PARENT_AFTER_CREATION,
|
|
|
|
DESTROY_PARENT_AFTER_CREATION_FORCE,
|
2017-05-04 23:53:27 +02:00
|
|
|
};
|
|
|
|
|
2017-12-22 22:05:32 +01:00
|
|
|
PopupNavTestHandler(TestMode test_mode,
|
|
|
|
TestRequestContextMode rc_mode,
|
|
|
|
const std::string& rc_cache_path)
|
|
|
|
: mode_(test_mode), rc_mode_(rc_mode), rc_cache_path_(rc_cache_path) {}
|
2017-05-04 23:53:27 +02:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
// Add the resources that we will navigate to/from.
|
|
|
|
std::string page = "<html><script>function doPopup() { window.open('" +
|
|
|
|
std::string(kPopupNavPopupUrl) + "', '" +
|
|
|
|
std::string(kPopupNavPopupName) +
|
|
|
|
"'); }</script>Page</html>";
|
|
|
|
AddResource(kPopupNavPageUrl, page, "text/html");
|
|
|
|
AddResource(kPopupNavPopupUrl, "<html>Popup</html>", "text/html");
|
2023-01-02 23:59:03 +01:00
|
|
|
if (mode_ == NAVIGATE_AFTER_CREATION) {
|
2017-05-04 23:53:27 +02:00
|
|
|
AddResource(kPopupNavPopupUrl2, "<html>Popup2</html>", "text/html");
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-04 23:53:27 +02:00
|
|
|
|
2017-12-22 22:05:32 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context =
|
|
|
|
CreateTestRequestContext(rc_mode_, rc_cache_path_);
|
2017-05-04 23:53:27 +02:00
|
|
|
|
|
|
|
// Create the browser.
|
|
|
|
CreateBrowser(kPopupNavPageUrl, request_context);
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& target_url,
|
|
|
|
const CefString& target_frame_name,
|
|
|
|
cef_window_open_disposition_t target_disposition,
|
|
|
|
bool user_gesture,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue>& extra_info,
|
2017-05-04 23:53:27 +02:00
|
|
|
bool* no_javascript_access) override {
|
|
|
|
EXPECT_FALSE(got_on_before_popup_);
|
|
|
|
got_on_before_popup_.yes();
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
|
2017-05-04 23:53:27 +02:00
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_STREQ(kPopupNavPageUrl, frame->GetURL().ToString().c_str());
|
|
|
|
EXPECT_STREQ(kPopupNavPopupUrl, target_url.ToString().c_str());
|
|
|
|
EXPECT_STREQ(kPopupNavPopupName, target_frame_name.ToString().c_str());
|
|
|
|
EXPECT_EQ(WOD_NEW_FOREGROUND_TAB, target_disposition);
|
|
|
|
EXPECT_FALSE(user_gesture);
|
|
|
|
EXPECT_FALSE(*no_javascript_access);
|
|
|
|
|
2017-05-09 22:45:57 +02:00
|
|
|
if (mode_ == DESTROY_PARENT_DURING_CREATION ||
|
|
|
|
mode_ == DESTROY_PARENT_DURING_CREATION_FORCE) {
|
|
|
|
// Destroy the main (parent) browser while popup creation is pending.
|
|
|
|
CloseBrowser(browser, mode_ == DESTROY_PARENT_DURING_CREATION_FORCE);
|
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
return (mode_ == DENY); // Return true to cancel the popup.
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
if (browser->IsPopup() && (mode_ == DESTROY_PARENT_AFTER_CREATION ||
|
|
|
|
mode_ == DESTROY_PARENT_AFTER_CREATION_FORCE)) {
|
2017-05-09 22:45:57 +02:00
|
|
|
// Destroy the main (parent) browser immediately after the popup is
|
|
|
|
// created.
|
|
|
|
CloseBrowser(GetBrowser(), mode_ == DESTROY_PARENT_AFTER_CREATION_FORCE);
|
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
if (mode_ == NAVIGATE_AFTER_CREATION && browser->IsPopup()) {
|
|
|
|
// Navigate to the 2nd popup URL instead of the 1st popup URL.
|
|
|
|
browser->GetMainFrame()->LoadURL(kPopupNavPopupUrl2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
if (url == kPopupNavPageUrl) {
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
got_load_start_.yes();
|
|
|
|
} else if (url == kPopupNavPopupUrl) {
|
|
|
|
EXPECT_FALSE(got_popup_load_start_);
|
|
|
|
got_popup_load_start_.yes();
|
|
|
|
} else if (url == kPopupNavPopupUrl2) {
|
|
|
|
EXPECT_FALSE(got_popup_load_start2_);
|
|
|
|
got_popup_load_start2_.yes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
|
|
|
if (failedUrl == kPopupNavPageUrl) {
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
got_load_error_.yes();
|
|
|
|
} else if (failedUrl == kPopupNavPopupUrl) {
|
|
|
|
EXPECT_FALSE(got_popup_load_error_);
|
|
|
|
got_popup_load_error_.yes();
|
|
|
|
} else if (failedUrl == kPopupNavPopupUrl2) {
|
|
|
|
EXPECT_FALSE(got_popup_load_error2_);
|
|
|
|
got_popup_load_error2_.yes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
if (url == kPopupNavPageUrl) {
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
got_load_end_.yes();
|
|
|
|
|
|
|
|
frame->ExecuteJavaScript("doPopup()", kPopupNavPageUrl, 0);
|
|
|
|
|
2017-05-09 22:45:57 +02:00
|
|
|
if (mode_ == DESTROY_PARENT_BEFORE_CREATION ||
|
|
|
|
mode_ == DESTROY_PARENT_BEFORE_CREATION_FORCE) {
|
|
|
|
// Destroy the main (parent) browser immediately before the popup is
|
|
|
|
// created.
|
|
|
|
CloseBrowser(browser, mode_ == DESTROY_PARENT_BEFORE_CREATION_FORCE);
|
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
if (mode_ == DENY) {
|
|
|
|
// Wait a bit to make sure the popup window isn't created.
|
2017-05-17 11:29:28 +02:00
|
|
|
CefPostDelayedTask(
|
2021-06-19 21:54:45 +02:00
|
|
|
TID_UI, base::BindOnce(&PopupNavTestHandler::DestroyTest, this),
|
|
|
|
200);
|
2017-05-04 23:53:27 +02:00
|
|
|
}
|
|
|
|
} else if (url == kPopupNavPopupUrl) {
|
|
|
|
EXPECT_FALSE(got_popup_load_end_);
|
|
|
|
got_popup_load_end_.yes();
|
|
|
|
|
|
|
|
if (mode_ == ALLOW_CLOSE_POPUP_FIRST) {
|
|
|
|
// Close the popup browser first.
|
|
|
|
CloseBrowser(browser, false);
|
|
|
|
} else if (mode_ == ALLOW_CLOSE_POPUP_LAST) {
|
|
|
|
// Close the main browser first.
|
|
|
|
CloseBrowser(GetBrowser(), false);
|
|
|
|
} else if (mode_ != NAVIGATE_AFTER_CREATION) {
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_FALSE(true); // Not reached.
|
2017-05-04 23:53:27 +02:00
|
|
|
}
|
|
|
|
} else if (url == kPopupNavPopupUrl2) {
|
|
|
|
EXPECT_FALSE(got_popup_load_end2_);
|
|
|
|
got_popup_load_end2_.yes();
|
|
|
|
|
|
|
|
if (mode_ == NAVIGATE_AFTER_CREATION) {
|
|
|
|
// Close the popup browser first.
|
|
|
|
CloseBrowser(browser, false);
|
|
|
|
} else {
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_FALSE(true); // Not reached.
|
2017-05-04 23:53:27 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_FALSE(true); // Not reached.
|
2017-05-04 23:53:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnBeforeClose(CefRefPtr<CefBrowser> browser) override {
|
|
|
|
TestHandler::OnBeforeClose(browser);
|
|
|
|
|
|
|
|
bool destroy_test = false;
|
|
|
|
if (mode_ == ALLOW_CLOSE_POPUP_FIRST || mode_ == NAVIGATE_AFTER_CREATION) {
|
|
|
|
// Destroy the test after the popup browser closes.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser->IsPopup()) {
|
2017-05-04 23:53:27 +02:00
|
|
|
destroy_test = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-09 22:45:57 +02:00
|
|
|
} else if (mode_ == ALLOW_CLOSE_POPUP_LAST ||
|
|
|
|
mode_ == DESTROY_PARENT_BEFORE_CREATION ||
|
|
|
|
mode_ == DESTROY_PARENT_BEFORE_CREATION_FORCE ||
|
|
|
|
mode_ == DESTROY_PARENT_DURING_CREATION ||
|
|
|
|
mode_ == DESTROY_PARENT_DURING_CREATION_FORCE ||
|
|
|
|
mode_ == DESTROY_PARENT_AFTER_CREATION ||
|
|
|
|
mode_ == DESTROY_PARENT_AFTER_CREATION_FORCE) {
|
2017-05-04 23:53:27 +02:00
|
|
|
// Destroy the test after the main browser closes.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser->IsPopup()) {
|
2017-05-04 23:53:27 +02:00
|
|
|
destroy_test = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-04 23:53:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (destroy_test) {
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::BindOnce(&PopupNavTestHandler::DestroyTest, this));
|
2017-05-04 23:53:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DestroyTest() override {
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
EXPECT_TRUE(got_load_end_);
|
2017-05-09 22:45:57 +02:00
|
|
|
|
|
|
|
// OnBeforePopup may come before or after browser destruction with the
|
|
|
|
// DESTROY_PARENT_BEFORE_CREATION* tests.
|
|
|
|
if (mode_ != DESTROY_PARENT_BEFORE_CREATION &&
|
|
|
|
mode_ != DESTROY_PARENT_BEFORE_CREATION_FORCE) {
|
|
|
|
EXPECT_TRUE(got_on_before_popup_);
|
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
if (mode_ == ALLOW_CLOSE_POPUP_FIRST || mode_ == ALLOW_CLOSE_POPUP_LAST) {
|
|
|
|
EXPECT_TRUE(got_popup_load_start_);
|
|
|
|
EXPECT_FALSE(got_popup_load_error_);
|
|
|
|
EXPECT_TRUE(got_popup_load_end_);
|
|
|
|
EXPECT_FALSE(got_popup_load_start2_);
|
|
|
|
EXPECT_FALSE(got_popup_load_error2_);
|
|
|
|
EXPECT_FALSE(got_popup_load_end2_);
|
2017-05-17 11:29:28 +02:00
|
|
|
} else if (mode_ == DENY || mode_ == DESTROY_PARENT_BEFORE_CREATION ||
|
2017-05-09 22:45:57 +02:00
|
|
|
mode_ == DESTROY_PARENT_BEFORE_CREATION_FORCE ||
|
|
|
|
mode_ == DESTROY_PARENT_DURING_CREATION ||
|
|
|
|
mode_ == DESTROY_PARENT_DURING_CREATION_FORCE ||
|
|
|
|
mode_ == DESTROY_PARENT_AFTER_CREATION ||
|
|
|
|
mode_ == DESTROY_PARENT_AFTER_CREATION_FORCE) {
|
2017-05-04 23:53:27 +02:00
|
|
|
EXPECT_FALSE(got_popup_load_start_);
|
|
|
|
EXPECT_FALSE(got_popup_load_error_);
|
|
|
|
EXPECT_FALSE(got_popup_load_end_);
|
|
|
|
EXPECT_FALSE(got_popup_load_start2_);
|
|
|
|
EXPECT_FALSE(got_popup_load_error2_);
|
|
|
|
EXPECT_FALSE(got_popup_load_end2_);
|
|
|
|
} else if (mode_ == NAVIGATE_AFTER_CREATION) {
|
|
|
|
EXPECT_FALSE(got_popup_load_start_);
|
2018-02-13 00:01:43 +01:00
|
|
|
|
|
|
|
// With browser-side navigation we will never actually begin the
|
|
|
|
// navigation to the 1st popup URL, so there will be no load error.
|
|
|
|
EXPECT_FALSE(got_popup_load_error_);
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
EXPECT_FALSE(got_popup_load_end_);
|
|
|
|
EXPECT_TRUE(got_popup_load_start2_);
|
|
|
|
EXPECT_FALSE(got_popup_load_error2_);
|
|
|
|
EXPECT_TRUE(got_popup_load_end2_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Will trigger destruction of all remaining browsers.
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
2017-12-22 22:05:32 +01:00
|
|
|
const TestMode mode_;
|
|
|
|
const TestRequestContextMode rc_mode_;
|
|
|
|
const std::string rc_cache_path_;
|
2017-05-04 23:53:27 +02:00
|
|
|
|
|
|
|
TrackCallback got_on_before_popup_;
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_load_error_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_popup_load_start_;
|
|
|
|
TrackCallback got_popup_load_error_;
|
|
|
|
TrackCallback got_popup_load_end_;
|
|
|
|
TrackCallback got_popup_load_start2_;
|
|
|
|
TrackCallback got_popup_load_error2_;
|
|
|
|
TrackCallback got_popup_load_end2_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(PopupNavTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
2019-04-24 04:50:25 +02:00
|
|
|
#define POPUP_TEST_GROUP(test_name, test_mode) \
|
|
|
|
RC_TEST_GROUP_IN_MEMORY(RequestContextTest, PopupNav##test_name, \
|
2017-12-22 22:05:32 +01:00
|
|
|
PopupNavTestHandler, test_mode)
|
2017-05-04 23:53:27 +02:00
|
|
|
|
|
|
|
// Test allowing popups and closing the popup browser first.
|
2019-03-13 22:27:37 +01:00
|
|
|
POPUP_TEST_GROUP(AllowClosePopupFirst, ALLOW_CLOSE_POPUP_FIRST)
|
2017-05-04 23:53:27 +02:00
|
|
|
|
2017-12-22 22:05:32 +01:00
|
|
|
// Test allowing popups and closing the main browser first to verify
|
|
|
|
// that internal objects are tracked correctly (see issue #2162).
|
2019-03-13 22:27:37 +01:00
|
|
|
POPUP_TEST_GROUP(AllowClosePopupLast, ALLOW_CLOSE_POPUP_LAST)
|
2017-05-04 23:53:27 +02:00
|
|
|
|
|
|
|
// Test denying popups.
|
2019-03-13 22:27:37 +01:00
|
|
|
POPUP_TEST_GROUP(Deny, DENY)
|
2017-05-04 23:53:27 +02:00
|
|
|
|
2017-12-22 22:05:32 +01:00
|
|
|
// Test navigation to a different origin after popup creation to
|
|
|
|
// verify that internal objects are tracked correctly (see issue
|
|
|
|
// #1392).
|
2019-03-13 22:27:37 +01:00
|
|
|
POPUP_TEST_GROUP(NavigateAfterCreation, NAVIGATE_AFTER_CREATION)
|
2017-05-04 23:53:27 +02:00
|
|
|
|
2017-12-22 22:05:32 +01:00
|
|
|
// Test destroying the parent browser during or immediately after
|
|
|
|
// popup creation to verify that internal objects are tracked
|
|
|
|
// correctly (see issue #2041).
|
2019-03-13 22:27:37 +01:00
|
|
|
POPUP_TEST_GROUP(DestroyParentBeforeCreation, DESTROY_PARENT_BEFORE_CREATION)
|
2017-05-09 22:45:57 +02:00
|
|
|
POPUP_TEST_GROUP(DestroyParentBeforeCreationForce,
|
2019-03-13 22:27:37 +01:00
|
|
|
DESTROY_PARENT_BEFORE_CREATION_FORCE)
|
|
|
|
POPUP_TEST_GROUP(DestroyParentDuringCreation, DESTROY_PARENT_DURING_CREATION)
|
2017-05-09 22:45:57 +02:00
|
|
|
POPUP_TEST_GROUP(DestroyParentDuringCreationForce,
|
2019-03-13 22:27:37 +01:00
|
|
|
DESTROY_PARENT_DURING_CREATION_FORCE)
|
|
|
|
POPUP_TEST_GROUP(DestroyParentAfterCreation, DESTROY_PARENT_AFTER_CREATION)
|
2017-05-09 22:45:57 +02:00
|
|
|
POPUP_TEST_GROUP(DestroyParentAfterCreationForce,
|
2019-03-13 22:27:37 +01:00
|
|
|
DESTROY_PARENT_AFTER_CREATION_FORCE)
|
2017-05-09 22:45:57 +02:00
|
|
|
|
2016-02-23 20:29:18 +01:00
|
|
|
namespace {
|
|
|
|
|
2016-02-24 00:27:05 +01:00
|
|
|
const char kResolveOrigin[] = "http://www.google.com";
|
|
|
|
|
2016-02-23 20:29:18 +01:00
|
|
|
class MethodTestHandler : public TestHandler {
|
|
|
|
public:
|
|
|
|
enum Method {
|
|
|
|
METHOD_CLEAR_CERTIFICATE_EXCEPTIONS,
|
|
|
|
METHOD_CLOSE_ALL_CONNECTIONS,
|
2016-02-24 00:27:05 +01:00
|
|
|
METHOD_RESOLVE_HOST,
|
2016-02-23 20:29:18 +01:00
|
|
|
};
|
|
|
|
|
2016-02-24 00:27:05 +01:00
|
|
|
class CompletionCallback : public CefCompletionCallback,
|
|
|
|
public CefResolveCallback {
|
2016-02-23 20:29:18 +01:00
|
|
|
public:
|
2016-02-24 00:27:05 +01:00
|
|
|
CompletionCallback(MethodTestHandler* test_handler,
|
|
|
|
CefRefPtr<CefBrowser> browser)
|
2017-05-17 11:29:28 +02:00
|
|
|
: test_handler_(test_handler), browser_(browser) {}
|
2016-02-23 20:29:18 +01:00
|
|
|
|
|
|
|
~CompletionCallback() override {
|
|
|
|
// OnComplete should be executed.
|
|
|
|
EXPECT_FALSE(test_handler_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnComplete() override {
|
|
|
|
EXPECT_UI_THREAD();
|
|
|
|
|
|
|
|
// OnComplete should be executed only one time.
|
|
|
|
EXPECT_TRUE(test_handler_);
|
2016-02-24 00:27:05 +01:00
|
|
|
test_handler_->OnCompleteCallback(browser_);
|
2016-02-23 20:29:18 +01:00
|
|
|
test_handler_ = nullptr;
|
2016-02-24 00:27:05 +01:00
|
|
|
browser_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnResolveCompleted(
|
|
|
|
cef_errorcode_t result,
|
|
|
|
const std::vector<CefString>& resolved_ips) override {
|
|
|
|
EXPECT_EQ(ERR_NONE, result);
|
|
|
|
EXPECT_TRUE(!resolved_ips.empty());
|
|
|
|
OnComplete();
|
2016-02-23 20:29:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MethodTestHandler* test_handler_;
|
2016-02-24 00:27:05 +01:00
|
|
|
CefRefPtr<CefBrowser> browser_;
|
2016-02-23 20:29:18 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CompletionCallback);
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
MethodTestHandler(bool global_context, Method method)
|
|
|
|
: global_context_(global_context), method_(method) {}
|
2016-02-23 20:29:18 +01:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
const char kUrl[] = "http://tests/method.html";
|
|
|
|
|
|
|
|
AddResource(kUrl, "<html><body>Method</body></html>", "text/html");
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> request_context;
|
|
|
|
if (!global_context_) {
|
|
|
|
CefRequestContextSettings settings;
|
|
|
|
request_context = CefRequestContext::CreateContext(settings, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateBrowser(kUrl, request_context);
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
|
|
|
CefRefPtr<CefRequestContext> context =
|
|
|
|
browser->GetHost()->GetRequestContext();
|
2016-02-24 00:27:05 +01:00
|
|
|
CefRefPtr<CompletionCallback> callback =
|
|
|
|
new CompletionCallback(this, browser);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (method_ == METHOD_CLEAR_CERTIFICATE_EXCEPTIONS) {
|
2016-02-23 20:29:18 +01:00
|
|
|
context->ClearCertificateExceptions(callback);
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (method_ == METHOD_CLOSE_ALL_CONNECTIONS) {
|
2016-02-23 20:29:18 +01:00
|
|
|
context->CloseAllConnections(callback);
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (method_ == METHOD_RESOLVE_HOST) {
|
2016-02-24 00:27:05 +01:00
|
|
|
context->ResolveHost(kResolveOrigin, callback);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-02-23 20:29:18 +01:00
|
|
|
}
|
|
|
|
|
2016-02-24 00:27:05 +01:00
|
|
|
void OnCompleteCallback(CefRefPtr<CefBrowser> browser) {
|
2016-02-23 20:29:18 +01:00
|
|
|
EXPECT_UI_THREAD();
|
|
|
|
EXPECT_FALSE(got_completion_callback_);
|
|
|
|
got_completion_callback_.yes();
|
2016-02-24 00:27:05 +01:00
|
|
|
|
2019-03-13 22:27:37 +01:00
|
|
|
DestroyTest();
|
2016-02-23 20:29:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DestroyTest() override {
|
|
|
|
EXPECT_TRUE(got_completion_callback_);
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool global_context_;
|
|
|
|
const Method method_;
|
|
|
|
|
|
|
|
TrackCallback got_completion_callback_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(MethodTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-12-22 22:05:32 +01:00
|
|
|
// Test CefRequestContext::ClearCertificateExceptions with the global
|
|
|
|
// context.
|
2016-02-23 20:29:18 +01:00
|
|
|
TEST(RequestContextTest, ClearCertificateExceptionsGlobal) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<MethodTestHandler> handler = new MethodTestHandler(
|
|
|
|
true, MethodTestHandler::METHOD_CLEAR_CERTIFICATE_EXCEPTIONS);
|
2016-02-23 20:29:18 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
2017-12-22 22:05:32 +01:00
|
|
|
// Test CefRequestContext::ClearCertificateExceptions with a custom
|
|
|
|
// context.
|
2016-02-23 20:29:18 +01:00
|
|
|
TEST(RequestContextTest, ClearCertificateExceptionsCustom) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<MethodTestHandler> handler = new MethodTestHandler(
|
|
|
|
false, MethodTestHandler::METHOD_CLEAR_CERTIFICATE_EXCEPTIONS);
|
2016-02-23 20:29:18 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
2017-12-22 22:05:32 +01:00
|
|
|
// Test CefRequestContext::CloseAllConnections with the global
|
|
|
|
// context.
|
2016-02-23 20:29:18 +01:00
|
|
|
TEST(RequestContextTest, CloseAllConnectionsGlobal) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<MethodTestHandler> handler = new MethodTestHandler(
|
|
|
|
true, MethodTestHandler::METHOD_CLOSE_ALL_CONNECTIONS);
|
2016-02-23 20:29:18 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test CefRequestContext::CloseAllConnections with a custom context.
|
|
|
|
TEST(RequestContextTest, CloseAllConnectionsCustom) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<MethodTestHandler> handler = new MethodTestHandler(
|
|
|
|
false, MethodTestHandler::METHOD_CLOSE_ALL_CONNECTIONS);
|
2016-02-23 20:29:18 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2016-02-24 00:27:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test CefRequestContext::ResolveHost with the global context.
|
|
|
|
TEST(RequestContextTest, ResolveHostGlobal) {
|
|
|
|
CefRefPtr<MethodTestHandler> handler =
|
2017-05-17 11:29:28 +02:00
|
|
|
new MethodTestHandler(true, MethodTestHandler::METHOD_RESOLVE_HOST);
|
2016-02-24 00:27:05 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test CefRequestContext::ResolveHost with a custom context.
|
|
|
|
TEST(RequestContextTest, ResolveHostCustom) {
|
|
|
|
CefRefPtr<MethodTestHandler> handler =
|
2017-05-17 11:29:28 +02:00
|
|
|
new MethodTestHandler(false, MethodTestHandler::METHOD_RESOLVE_HOST);
|
2016-02-24 00:27:05 +01:00
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|