2013-07-15 22:25:59 +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.
|
|
|
|
|
2015-12-05 03:58:56 +01:00
|
|
|
#include <algorithm>
|
2016-11-16 21:24:13 +01:00
|
|
|
#include <cmath>
|
2021-06-17 22:08:01 +02:00
|
|
|
#include <memory>
|
2016-11-14 19:28:05 +01:00
|
|
|
#include <sstream>
|
2015-12-05 03:58:56 +01:00
|
|
|
#include <string>
|
2019-05-24 22:23:43 +02:00
|
|
|
#include <vector>
|
2015-12-05 03:58:56 +01:00
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2013-07-15 22:25:59 +02:00
|
|
|
#include "include/cef_cookie.h"
|
2019-04-24 04:50:25 +02:00
|
|
|
#include "include/cef_request_context_handler.h"
|
2014-07-15 20:10:40 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2015-03-11 19:44:11 +01:00
|
|
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/test_handler.h"
|
|
|
|
#include "tests/ceftests/test_util.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/gtest/include/gtest/gtest.h"
|
|
|
|
#include "tests/shared/browser/client_app_browser.h"
|
|
|
|
#include "tests/shared/renderer/client_app_renderer.h"
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
using client::ClientAppBrowser;
|
|
|
|
using client::ClientAppRenderer;
|
2015-01-23 20:09:34 +01:00
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum NetNotifyTestType {
|
|
|
|
NNTT_NONE = 0,
|
|
|
|
NNTT_NORMAL,
|
|
|
|
NNTT_DELAYED_RENDERER,
|
|
|
|
NNTT_DELAYED_BROWSER,
|
|
|
|
};
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kNetNotifyOrigin1[] = "https://tests-netnotify1/";
|
|
|
|
const char kNetNotifyOrigin2[] = "https://tests-netnotify2/";
|
2013-07-15 22:25:59 +02:00
|
|
|
const char kNetNotifyMsg[] = "RequestHandlerTest.NetNotify";
|
2019-10-03 16:17:58 +02:00
|
|
|
const char kNetNotifyTestCmdKey[] = "rh-net-notify-test";
|
2013-09-16 17:26:08 +02:00
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
// Browser side.
|
|
|
|
class NetNotifyTestHandler : public TestHandler {
|
|
|
|
public:
|
|
|
|
NetNotifyTestHandler(CompletionState* completion_state,
|
|
|
|
NetNotifyTestType test_type,
|
|
|
|
bool same_origin)
|
|
|
|
: TestHandler(completion_state),
|
|
|
|
test_type_(test_type),
|
|
|
|
same_origin_(same_origin) {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void SetupTest() override {
|
2016-11-14 19:28:05 +01:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << kNetNotifyOrigin1 << "nav1.html?t=" << test_type_;
|
|
|
|
url1_ = ss.str();
|
|
|
|
ss.str("");
|
2017-05-17 11:29:28 +02:00
|
|
|
ss << (same_origin_ ? kNetNotifyOrigin1 : kNetNotifyOrigin2)
|
|
|
|
<< "nav2.html?t=" << test_type_;
|
2016-11-14 19:28:05 +01:00
|
|
|
url2_ = ss.str();
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2015-12-04 19:59:14 +01:00
|
|
|
const std::string& resource1 =
|
2013-07-15 22:25:59 +02:00
|
|
|
"<html>"
|
|
|
|
"<head><script>document.cookie='name1=value1';</script></head>"
|
|
|
|
"<body>Nav1</body>"
|
2015-12-04 19:59:14 +01:00
|
|
|
"</html>";
|
2023-06-01 16:06:15 +02:00
|
|
|
response_length1_ = static_cast<int64_t>(resource1.size());
|
2015-12-04 19:59:14 +01:00
|
|
|
AddResource(url1_, resource1, "text/html");
|
|
|
|
|
|
|
|
const std::string& resource2 =
|
2013-07-15 22:25:59 +02:00
|
|
|
"<html>"
|
|
|
|
"<head><script>document.cookie='name2=value2';</script></head>"
|
|
|
|
"<body>Nav2</body>"
|
2015-12-04 19:59:14 +01:00
|
|
|
"</html>";
|
2023-06-01 16:06:15 +02:00
|
|
|
response_length2_ = static_cast<int64_t>(resource2.size());
|
2015-12-04 19:59:14 +01:00
|
|
|
AddResource(url2_, resource2, "text/html");
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Create the request context that will use an in-memory cache.
|
|
|
|
CefRequestContextSettings settings;
|
|
|
|
CefRefPtr<CefRequestContext> request_context =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(settings, nullptr);
|
|
|
|
cookie_manager_ = request_context->GetCookieManager(nullptr);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info = CefDictionaryValue::Create();
|
|
|
|
extra_info->SetBool(kNetNotifyTestCmdKey, true);
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
// Create browser that loads the 1st URL.
|
2019-10-03 16:17:58 +02:00
|
|
|
CreateBrowser(url1_, request_context, extra_info);
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2013-07-15 22:25:59 +02:00
|
|
|
// Navigate to the 2nd URL.
|
|
|
|
GetBrowser()->GetMainFrame()->LoadURL(url2_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
cef_return_value_t OnBeforeResourceLoad(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2021-09-27 11:09:45 +02:00
|
|
|
CefRefPtr<CefCallback> callback) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (IgnoreURL(url)) {
|
2021-04-10 04:24:44 +02:00
|
|
|
return RV_CONTINUE;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-10 04:24:44 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url.find(url1_) == 0) {
|
2013-07-15 22:25:59 +02:00
|
|
|
got_before_resource_load1_.yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (url.find(url2_) == 0) {
|
2013-07-15 22:25:59 +02:00
|
|
|
got_before_resource_load2_.yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2013-07-15 22:25:59 +02:00
|
|
|
EXPECT_TRUE(false); // Not reached
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
return RV_CONTINUE;
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefResourceHandler> GetResourceHandler(
|
2013-07-15 22:25:59 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefRequest> request) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (IgnoreURL(url)) {
|
2021-04-10 04:24:44 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-10 04:24:44 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url.find(url1_) == 0) {
|
2013-07-15 22:25:59 +02:00
|
|
|
got_get_resource_handler1_.yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (url.find(url2_) == 0) {
|
2013-07-15 22:25:59 +02:00
|
|
|
got_get_resource_handler2_.yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2013-07-15 22:25:59 +02:00
|
|
|
EXPECT_TRUE(false); // Not reached
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
return TestHandler::GetResourceHandler(browser, frame, request);
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2015-12-04 19:59:14 +01:00
|
|
|
void OnResourceLoadComplete(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefResponse> response,
|
|
|
|
URLRequestStatus status,
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t received_content_length) override {
|
2015-12-04 19:59:14 +01:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (IgnoreURL(url)) {
|
2021-04-10 04:24:44 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-10 04:24:44 +02:00
|
|
|
|
|
|
|
EXPECT_EQ(UR_SUCCESS, status);
|
2015-12-04 19:59:14 +01:00
|
|
|
if (url.find(url1_) == 0) {
|
|
|
|
got_resource_load_complete1_.yes();
|
|
|
|
EXPECT_EQ(response_length1_, received_content_length);
|
|
|
|
} else if (url.find(url2_) == 0) {
|
|
|
|
got_resource_load_complete2_.yes();
|
|
|
|
EXPECT_EQ(response_length2_, received_content_length);
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(false); // Not reached
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2018-04-27 17:11:53 +02:00
|
|
|
bool user_gesture,
|
2014-11-12 20:25:15 +01:00
|
|
|
bool is_redirect) override {
|
2013-09-16 17:26:08 +02:00
|
|
|
std::string url = request->GetURL();
|
|
|
|
|
|
|
|
// Check if the load has already been delayed.
|
|
|
|
bool delay_loaded = (url.find("delayed=true") != std::string::npos);
|
|
|
|
|
|
|
|
if (url.find(url1_) == 0) {
|
|
|
|
got_before_browse1_.yes();
|
|
|
|
EXPECT_FALSE(delay_loaded);
|
|
|
|
} else if (url.find(url2_) == 0) {
|
|
|
|
got_before_browse2_.yes();
|
|
|
|
if (delay_loaded) {
|
|
|
|
got_before_browse2_delayed_.yes();
|
|
|
|
} else if (test_type_ == NNTT_DELAYED_RENDERER ||
|
|
|
|
test_type_ == NNTT_DELAYED_BROWSER) {
|
|
|
|
got_before_browse2_will_delay_.yes();
|
|
|
|
|
|
|
|
// Navigating cross-origin from the browser process will cause a new
|
|
|
|
// render process to be created. We therefore need some information in
|
|
|
|
// the request itself to tell us that the navigation has already been
|
|
|
|
// delayed.
|
2019-10-03 16:17:58 +02:00
|
|
|
// Navigating cross-origin from the renderer process will cause the
|
|
|
|
// process to be terminated with "bad IPC message" reason
|
|
|
|
// INVALID_INITIATOR_ORIGIN (213).
|
2013-09-16 17:26:08 +02:00
|
|
|
url += "&delayed=true";
|
|
|
|
|
|
|
|
if (test_type_ == NNTT_DELAYED_RENDERER) {
|
|
|
|
// Load the URL from the render process.
|
|
|
|
CefRefPtr<CefProcessMessage> message =
|
|
|
|
CefProcessMessage::Create(kNetNotifyMsg);
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
args->SetInt(0, test_type_);
|
|
|
|
args->SetString(1, url);
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_RENDERER, message);
|
2013-09-16 17:26:08 +02:00
|
|
|
} else {
|
|
|
|
// Load the URL from the browser process.
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->LoadURL(url);
|
2013-09-16 17:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel the load.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(false); // Not reached
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow the load to continue.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
if (url.find(url1_) == 0) {
|
|
|
|
got_load_end1_.yes();
|
2013-09-16 17:26:08 +02:00
|
|
|
SetupCompleteIfDone();
|
2013-07-15 22:25:59 +02:00
|
|
|
} else if (url.find(url2_) == 0) {
|
|
|
|
got_load_end2_.yes();
|
2013-09-16 17:26:08 +02:00
|
|
|
FinishTestIfDone();
|
2013-07-15 22:25:59 +02:00
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(false); // Not reached
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
if (message->GetName().ToString() == kNetNotifyMsg) {
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
std::string url = args->GetString(0);
|
|
|
|
if (url.find(url1_) == 0) {
|
2013-07-15 22:25:59 +02:00
|
|
|
got_process_message1_.yes();
|
2013-09-16 17:26:08 +02:00
|
|
|
SetupCompleteIfDone();
|
|
|
|
} else if (url.find(url2_) == 0) {
|
2013-07-15 22:25:59 +02:00
|
|
|
got_process_message2_.yes();
|
2013-09-16 17:26:08 +02:00
|
|
|
FinishTestIfDone();
|
2013-07-15 22:25:59 +02:00
|
|
|
} else {
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_TRUE(false); // Not reached
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
2013-09-16 17:26:08 +02:00
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message not handled.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
|
|
|
|
TerminationStatus status) override {
|
|
|
|
got_process_terminated_ct_++;
|
|
|
|
|
|
|
|
// Termination is expected for cross-origin requests initiated from the
|
|
|
|
// renderer process.
|
|
|
|
if (!(test_type_ == NNTT_DELAYED_RENDERER && !same_origin_)) {
|
|
|
|
TestHandler::OnRenderProcessTerminated(browser, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
FinishTest();
|
|
|
|
}
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
protected:
|
2013-09-16 17:26:08 +02:00
|
|
|
void SetupCompleteIfDone() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (got_load_end1_ && got_process_message1_) {
|
2013-09-16 17:26:08 +02:00
|
|
|
SetupComplete();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-16 17:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void FinishTestIfDone() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (got_load_end2_ && got_process_message2_) {
|
2013-09-16 17:26:08 +02:00
|
|
|
FinishTest();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-16 17:26:08 +02:00
|
|
|
}
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
void FinishTest() {
|
2013-09-16 17:26:08 +02:00
|
|
|
// Verify that cookies were set correctly.
|
2013-07-15 22:25:59 +02:00
|
|
|
class TestVisitor : public CefCookieVisitor {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit TestVisitor(NetNotifyTestHandler* handler) : handler_(handler) {}
|
2014-11-12 20:25:15 +01:00
|
|
|
~TestVisitor() override {
|
2013-07-15 22:25:59 +02:00
|
|
|
// Destroy the test.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&NetNotifyTestHandler::DestroyTest,
|
|
|
|
handler_));
|
2013-07-15 22:25:59 +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-07-15 22:25:59 +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-07-15 22:25:59 +02:00
|
|
|
handler_->got_cookie1_.yes();
|
2019-03-22 23:11:51 +01:00
|
|
|
deleteCookie = true;
|
|
|
|
} else if (name == "name2" && value == "value2") {
|
2013-07-15 22:25:59 +02:00
|
|
|
handler_->got_cookie2_.yes();
|
2019-03-22 23:11:51 +01:00
|
|
|
deleteCookie = true;
|
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
NetNotifyTestHandler* handler_;
|
|
|
|
IMPLEMENT_REFCOUNTING(TestVisitor);
|
|
|
|
};
|
|
|
|
|
|
|
|
cookie_manager_->VisitAllCookies(new TestVisitor(this));
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void DestroyTest() override {
|
2013-07-15 22:25:59 +02:00
|
|
|
int browser_id = GetBrowser()->GetIdentifier();
|
|
|
|
|
|
|
|
// Verify test expectations.
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_TRUE(got_before_browse1_) << " browser " << browser_id;
|
2013-07-15 22:25:59 +02:00
|
|
|
EXPECT_TRUE(got_load_end1_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_before_resource_load1_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_get_resource_handler1_) << " browser " << browser_id;
|
2015-12-04 19:59:14 +01:00
|
|
|
EXPECT_TRUE(got_resource_load_complete1_) << " browser " << browser_id;
|
2013-07-15 22:25:59 +02:00
|
|
|
EXPECT_TRUE(got_cookie1_) << " browser " << browser_id;
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_TRUE(got_process_message1_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_before_browse2_) << " browser " << browser_id;
|
2019-10-03 16:17:58 +02:00
|
|
|
|
|
|
|
if (test_type_ == NNTT_DELAYED_RENDERER && !same_origin_) {
|
|
|
|
EXPECT_EQ(1, got_process_terminated_ct_) << " browser " << browser_id;
|
|
|
|
EXPECT_FALSE(got_load_end2_) << " browser " << browser_id;
|
|
|
|
EXPECT_FALSE(got_before_resource_load2_) << " browser " << browser_id;
|
|
|
|
EXPECT_FALSE(got_get_resource_handler2_) << " browser " << browser_id;
|
|
|
|
EXPECT_FALSE(got_resource_load_complete2_) << " browser " << browser_id;
|
|
|
|
EXPECT_FALSE(got_cookie2_) << " browser " << browser_id;
|
|
|
|
EXPECT_FALSE(got_process_message2_) << " browser " << browser_id;
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(0, got_process_terminated_ct_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_load_end2_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_before_resource_load2_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_get_resource_handler2_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_resource_load_complete2_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_cookie2_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_process_message2_) << " browser " << browser_id;
|
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
|
|
|
if (test_type_ == NNTT_DELAYED_RENDERER ||
|
|
|
|
test_type_ == NNTT_DELAYED_BROWSER) {
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_TRUE(got_before_browse2_will_delay_) << " browser " << browser_id;
|
2019-10-03 16:17:58 +02:00
|
|
|
if (test_type_ == NNTT_DELAYED_RENDERER && !same_origin_) {
|
|
|
|
EXPECT_FALSE(got_before_browse2_delayed_) << " browser " << browser_id;
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(got_before_browse2_delayed_) << " browser " << browser_id;
|
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
} else {
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_FALSE(got_before_browse2_will_delay_) << " browser " << browser_id;
|
|
|
|
EXPECT_FALSE(got_before_browse2_delayed_) << " browser " << browser_id;
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:34:01 +01:00
|
|
|
cookie_manager_ = nullptr;
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
NetNotifyTestType test_type_;
|
|
|
|
bool same_origin_;
|
|
|
|
std::string url1_;
|
|
|
|
std::string url2_;
|
|
|
|
|
|
|
|
CefRefPtr<CefCookieManager> cookie_manager_;
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
TrackCallback got_before_browse1_;
|
2013-07-15 22:25:59 +02:00
|
|
|
TrackCallback got_load_end1_;
|
|
|
|
TrackCallback got_before_resource_load1_;
|
|
|
|
TrackCallback got_get_resource_handler1_;
|
2015-12-04 19:59:14 +01:00
|
|
|
TrackCallback got_resource_load_complete1_;
|
2013-07-15 22:25:59 +02:00
|
|
|
TrackCallback got_cookie1_;
|
|
|
|
TrackCallback got_process_message1_;
|
2013-09-16 17:26:08 +02:00
|
|
|
TrackCallback got_before_browse2_;
|
2013-07-15 22:25:59 +02:00
|
|
|
TrackCallback got_load_end2_;
|
|
|
|
TrackCallback got_before_resource_load2_;
|
|
|
|
TrackCallback got_get_resource_handler2_;
|
2015-12-04 19:59:14 +01:00
|
|
|
TrackCallback got_resource_load_complete2_;
|
2013-07-15 22:25:59 +02:00
|
|
|
TrackCallback got_cookie2_;
|
|
|
|
TrackCallback got_process_message2_;
|
2013-09-16 17:26:08 +02:00
|
|
|
TrackCallback got_before_browse2_will_delay_;
|
|
|
|
TrackCallback got_before_browse2_delayed_;
|
2019-10-03 16:17:58 +02:00
|
|
|
int got_process_terminated_ct_ = 0;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t response_length1_;
|
|
|
|
int64_t response_length2_;
|
2015-12-04 19:59:14 +01:00
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(NetNotifyTestHandler);
|
2013-07-15 22:25:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Renderer side.
|
2015-01-31 05:41:36 +01:00
|
|
|
class NetNotifyRendererTest : public ClientAppRenderer::Delegate,
|
2013-09-16 17:26:08 +02:00
|
|
|
public CefLoadHandler {
|
2013-07-15 22:25:59 +02:00
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
NetNotifyRendererTest() : run_test_(false) {}
|
2013-09-16 17:26:08 +02:00
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
void OnBrowserCreated(CefRefPtr<ClientAppRenderer> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info) override {
|
2021-05-14 18:58:55 +02:00
|
|
|
run_test_ = extra_info && extra_info->HasKey(kNetNotifyTestCmdKey);
|
2013-09-16 17:26:08 +02:00
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefLoadHandler> GetLoadHandler(
|
2015-01-31 05:41:36 +01:00
|
|
|
CefRefPtr<ClientAppRenderer> app) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (run_test_) {
|
2013-09-16 17:26:08 +02:00
|
|
|
return this;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-01-15 14:34:01 +01:00
|
|
|
return nullptr;
|
2013-09-16 17:26:08 +02:00
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!run_test_) {
|
2013-09-16 17:26:08 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
const std::string& url = frame->GetURL();
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
// Continue in the browser process.
|
|
|
|
CefRefPtr<CefProcessMessage> message =
|
|
|
|
CefProcessMessage::Create(kNetNotifyMsg);
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
args->SetString(0, url);
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_BROWSER, message);
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool OnProcessMessageReceived(CefRefPtr<ClientAppRenderer> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
if (message->GetName().ToString() == kNetNotifyMsg) {
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
|
|
|
|
NetNotifyTestType test_type =
|
|
|
|
static_cast<NetNotifyTestType>(args->GetInt(0));
|
|
|
|
EXPECT_EQ(test_type, NNTT_DELAYED_RENDERER);
|
|
|
|
|
|
|
|
const std::string& url = args->GetString(1);
|
|
|
|
|
|
|
|
// Load the URL from the render process.
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->LoadURL(url);
|
2013-07-15 22:25:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message not handled.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
private:
|
|
|
|
bool run_test_;
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(NetNotifyRendererTest);
|
|
|
|
};
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void RunNetNotifyTest(NetNotifyTestType test_type,
|
|
|
|
bool same_origin,
|
|
|
|
size_t count = 3U) {
|
2019-10-21 15:34:46 +02:00
|
|
|
TestHandler::CompletionState completion_state(static_cast<int>(count));
|
2013-07-15 22:25:59 +02:00
|
|
|
TestHandler::Collection collection(&completion_state);
|
2019-05-24 22:23:43 +02:00
|
|
|
|
|
|
|
std::vector<CefRefPtr<NetNotifyTestHandler>> handlers;
|
|
|
|
for (size_t i = 0U; i < count; ++i) {
|
|
|
|
CefRefPtr<NetNotifyTestHandler> handler =
|
|
|
|
new NetNotifyTestHandler(&completion_state, test_type, same_origin);
|
2021-06-17 22:08:01 +02:00
|
|
|
collection.AddTestHandler(handler.get());
|
2019-05-24 22:23:43 +02:00
|
|
|
handlers.push_back(handler);
|
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
|
|
|
collection.ExecuteTests();
|
2013-09-16 17:26:08 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
while (!handlers.empty()) {
|
|
|
|
auto handler = handlers.front();
|
|
|
|
handlers.erase(handlers.begin());
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from the same origin and is not delayed.
|
|
|
|
TEST(RequestHandlerTest, NotificationsSameOriginDirect) {
|
|
|
|
RunNetNotifyTest(NNTT_NORMAL, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from the same origin and is continued asynchronously from the
|
|
|
|
// render process.
|
|
|
|
TEST(RequestHandlerTest, NotificationsSameOriginDelayedRenderer) {
|
|
|
|
RunNetNotifyTest(NNTT_DELAYED_RENDERER, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from the same origin and is continued asynchronously from the
|
|
|
|
// browser process.
|
|
|
|
TEST(RequestHandlerTest, NotificationsSameOriginDelayedBrowser) {
|
|
|
|
RunNetNotifyTest(NNTT_DELAYED_BROWSER, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from a different origin and is not delayed.
|
|
|
|
TEST(RequestHandlerTest, NotificationsCrossOriginDirect) {
|
|
|
|
RunNetNotifyTest(NNTT_NORMAL, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from a different origin and is continued asynchronously from
|
|
|
|
// the render process.
|
|
|
|
TEST(RequestHandlerTest, NotificationsCrossOriginDelayedRenderer) {
|
|
|
|
RunNetNotifyTest(NNTT_DELAYED_RENDERER, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from a different origin and is continued asynchronously from
|
|
|
|
// the browser process.
|
|
|
|
TEST(RequestHandlerTest, NotificationsCrossOriginDelayedBrowser) {
|
|
|
|
RunNetNotifyTest(NNTT_DELAYED_BROWSER, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Entry point for creating request handler renderer test objects.
|
|
|
|
// Called from client_app_delegates.cc.
|
|
|
|
void CreateRequestHandlerRendererTests(
|
2015-01-31 05:41:36 +01:00
|
|
|
ClientAppRenderer::DelegateSet& delegates) {
|
2013-07-15 22:25:59 +02:00
|
|
|
delegates.insert(new NetNotifyRendererTest);
|
|
|
|
}
|