2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2011 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.
|
|
|
|
|
2014-01-14 20:57:17 +01:00
|
|
|
#include <algorithm>
|
2012-12-30 12:17:49 +01:00
|
|
|
#include <list>
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_callback.h"
|
2023-05-25 13:15:06 +02:00
|
|
|
#include "include/cef_request_context.h"
|
|
|
|
#include "include/cef_request_context_handler.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_scheme.h"
|
2014-07-15 20:10:40 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2023-05-25 13:15:06 +02:00
|
|
|
#include "include/wrapper/cef_scoped_temp_dir.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"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
// Set to 1 to enable verbose debugging info logging.
|
|
|
|
#define VERBOSE_DEBUGGING 0
|
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
using client::ClientAppBrowser;
|
|
|
|
using client::ClientAppRenderer;
|
2015-01-23 20:09:34 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kHNav1[] = "https://tests-hnav.com/nav1.html";
|
|
|
|
const char kHNav2[] = "https://tests-hnav.com/nav2.html";
|
|
|
|
const char kHNav3[] = "https://tests-hnav.com/nav3.html";
|
2012-11-09 19:47:09 +01:00
|
|
|
const char kHistoryNavMsg[] = "NavigationTest.HistoryNav";
|
2019-10-03 16:17:58 +02:00
|
|
|
const char kHistoryNavTestCmdKey[] = "nav-history-test";
|
2012-11-09 19:47:09 +01:00
|
|
|
|
2020-02-14 22:58:58 +01:00
|
|
|
const cef_transition_type_t kTransitionExplicitLoad =
|
|
|
|
static_cast<cef_transition_type_t>(TT_EXPLICIT | TT_DIRECT_LOAD_FLAG);
|
|
|
|
|
|
|
|
// TT_FORWARD_BACK_FLAG is added to the original transition flags.
|
|
|
|
const cef_transition_type_t kTransitionExplicitForwardBack =
|
|
|
|
static_cast<cef_transition_type_t>(kTransitionExplicitLoad |
|
|
|
|
TT_FORWARD_BACK_FLAG);
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
enum NavAction { NA_LOAD = 1, NA_BACK, NA_FORWARD };
|
|
|
|
|
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
const char* NavActionString(NavAction action) {
|
|
|
|
switch (action) {
|
|
|
|
case NA_LOAD:
|
|
|
|
return "LOAD";
|
|
|
|
case NA_BACK:
|
|
|
|
return "BACK";
|
|
|
|
case NA_FORWARD:
|
|
|
|
return "FORWARD";
|
|
|
|
}
|
|
|
|
return "INVALID";
|
|
|
|
}
|
|
|
|
#endif // VERBOSE_DEBUGGING
|
|
|
|
|
|
|
|
bool ExpectResourceLoadEvents(NavAction action) {
|
|
|
|
if (IsSameSiteBFCacheEnabled()) {
|
|
|
|
return action == NA_LOAD;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
NavAction action; // What to do
|
|
|
|
const char* target; // Where to be after navigation
|
|
|
|
bool can_go_back; // After navigation, can go back?
|
|
|
|
bool can_go_forward; // After navigation, can go forward?
|
|
|
|
} NavListItem;
|
|
|
|
|
|
|
|
// Array of navigation actions: X = current page, . = history exists
|
2012-11-09 19:47:09 +01:00
|
|
|
static NavListItem kHNavList[] = {
|
2017-05-17 11:29:28 +02:00
|
|
|
// kHNav1 | kHNav2 | kHNav3
|
|
|
|
{NA_LOAD, kHNav1, false, false}, // X
|
|
|
|
{NA_LOAD, kHNav2, true, false}, // . X
|
|
|
|
{NA_BACK, kHNav1, false, true}, // X .
|
|
|
|
{NA_FORWARD, kHNav2, true, false}, // . X
|
|
|
|
{NA_LOAD, kHNav3, true, false}, // . . X
|
|
|
|
{NA_BACK, kHNav2, true, true}, // . X .
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
#define NAV_LIST_SIZE() (sizeof(kHNavList) / sizeof(NavListItem))
|
|
|
|
|
|
|
|
// Renderer side.
|
2015-01-31 05:41:36 +01:00
|
|
|
class HistoryNavRendererTest : public ClientAppRenderer::Delegate,
|
2013-09-13 01:36:54 +02:00
|
|
|
public CefLoadHandler {
|
2012-11-09 19:47:09 +01:00
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
HistoryNavRendererTest() = default;
|
2012-11-20 21:08:36 +01: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(kHistoryNavTestCmdKey);
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
2012-11-09 19:47:09 +01: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_) {
|
2020-01-15 14:34:01 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2013-09-13 01:36:54 +02:00
|
|
|
const NavListItem& item = kHNavList[nav_];
|
2022-04-05 19:22:32 +02:00
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
LOG(INFO) << "render nav=" << nav_ << " " << NavActionString(item.action)
|
|
|
|
<< " OnLoadingStateChange isLoading=" << isLoading;
|
|
|
|
#endif
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
const std::string& url = browser->GetMainFrame()->GetURL();
|
2018-02-20 19:51:59 +01:00
|
|
|
EXPECT_STREQ(item.target, url.c_str());
|
|
|
|
|
|
|
|
EXPECT_EQ(item.can_go_back, browser->CanGoBack())
|
|
|
|
<< "nav: " << nav_ << " isLoading: " << isLoading;
|
|
|
|
EXPECT_EQ(item.can_go_back, canGoBack)
|
|
|
|
<< "nav: " << nav_ << " isLoading: " << isLoading;
|
|
|
|
EXPECT_EQ(item.can_go_forward, browser->CanGoForward())
|
|
|
|
<< "nav: " << nav_ << " isLoading: " << isLoading;
|
|
|
|
EXPECT_EQ(item.can_go_forward, canGoForward)
|
|
|
|
<< "nav: " << nav_ << " isLoading: " << isLoading;
|
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
if (isLoading) {
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_FALSE(got_loading_state_start_);
|
2013-09-13 01:36:54 +02:00
|
|
|
got_loading_state_start_.yes();
|
|
|
|
} else {
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_FALSE(got_loading_state_end_);
|
2013-09-13 01:36:54 +02:00
|
|
|
got_loading_state_end_.yes();
|
2019-05-24 22:23:43 +02:00
|
|
|
SendTestResultsIfDone(browser, browser->GetMainFrame());
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
2016-07-12 17:59:42 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
2013-09-13 01:36:54 +02:00
|
|
|
const NavListItem& item = kHNavList[nav_];
|
2022-04-05 19:22:32 +02:00
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
LOG(INFO) << "render nav=" << nav_ << " " << NavActionString(item.action)
|
|
|
|
<< " OnLoadStart";
|
|
|
|
#endif
|
2013-09-13 01:36:54 +02:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_FALSE(got_load_start_);
|
2013-09-13 01:36:54 +02:00
|
|
|
got_load_start_.yes();
|
|
|
|
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
EXPECT_STREQ(item.target, url.c_str());
|
|
|
|
|
2016-07-12 17:59:42 +02:00
|
|
|
EXPECT_EQ(TT_EXPLICIT, transition_type);
|
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_EQ(item.can_go_back, browser->CanGoBack());
|
|
|
|
EXPECT_EQ(item.can_go_forward, browser->CanGoForward());
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2013-09-13 01:36:54 +02:00
|
|
|
const NavListItem& item = kHNavList[nav_];
|
2022-04-05 19:22:32 +02:00
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
LOG(INFO) << "render nav=" << nav_ << " " << NavActionString(item.action)
|
|
|
|
<< " OnLoadEnd";
|
|
|
|
#endif
|
2013-09-13 01:36:54 +02:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_FALSE(got_load_end_);
|
2013-09-13 01:36:54 +02:00
|
|
|
got_load_end_.yes();
|
|
|
|
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
EXPECT_STREQ(item.target, url.c_str());
|
|
|
|
|
|
|
|
EXPECT_EQ(item.can_go_back, browser->CanGoBack());
|
|
|
|
EXPECT_EQ(item.can_go_forward, browser->CanGoForward());
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
SendTestResultsIfDone(browser, frame);
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
protected:
|
2019-05-24 22:23:43 +02:00
|
|
|
void SendTestResultsIfDone(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (got_load_end_ && got_loading_state_end_) {
|
2019-05-24 22:23:43 +02:00
|
|
|
SendTestResults(browser, frame);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
// Send the test results.
|
2019-05-24 22:23:43 +02:00
|
|
|
void SendTestResults(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2022-04-05 19:22:32 +02:00
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
const NavListItem& item = kHNavList[nav_];
|
|
|
|
LOG(INFO) << "render nav=" << nav_ << " " << NavActionString(item.action)
|
|
|
|
<< " SendTestResults";
|
|
|
|
#endif
|
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_TRUE(got_loading_state_start_);
|
|
|
|
EXPECT_TRUE(got_loading_state_end_);
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_load_end_);
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
// Check if the test has failed.
|
|
|
|
bool result = !TestFailed();
|
|
|
|
|
|
|
|
// Return the result to the browser process.
|
|
|
|
CefRefPtr<CefProcessMessage> return_msg =
|
|
|
|
CefProcessMessage::Create(kHistoryNavMsg);
|
|
|
|
CefRefPtr<CefListValue> args = return_msg->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
EXPECT_TRUE(args->SetInt(0, nav_));
|
|
|
|
EXPECT_TRUE(args->SetBool(1, result));
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_BROWSER, return_msg);
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
// Reset the test results for the next navigation.
|
|
|
|
got_loading_state_start_.reset();
|
|
|
|
got_loading_state_end_.reset();
|
|
|
|
got_load_start_.reset();
|
|
|
|
got_load_end_.reset();
|
|
|
|
|
|
|
|
nav_++;
|
2012-11-09 19:47:09 +01:00
|
|
|
}
|
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
bool run_test_ = false;
|
|
|
|
int nav_ = 0;
|
2012-11-09 19:47:09 +01:00
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
TrackCallback got_loading_state_start_;
|
|
|
|
TrackCallback got_loading_state_end_;
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
IMPLEMENT_REFCOUNTING(HistoryNavRendererTest);
|
|
|
|
};
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-11-24 20:23:26 +01:00
|
|
|
class NavigationEntryVisitor : public CefNavigationEntryVisitor {
|
|
|
|
public:
|
|
|
|
NavigationEntryVisitor(int nav, TrackCallback* callback)
|
2024-01-20 18:00:09 +01:00
|
|
|
: nav_(nav), callback_(callback) {
|
2014-11-24 20:23:26 +01:00
|
|
|
// Determine the expected values.
|
|
|
|
for (int i = 0; i <= nav_; ++i) {
|
|
|
|
if (kHNavList[i].action == NA_LOAD) {
|
|
|
|
expected_total_++;
|
|
|
|
expected_current_index_++;
|
|
|
|
} else if (kHNavList[i].action == NA_BACK) {
|
|
|
|
expected_current_index_--;
|
2017-05-17 11:29:28 +02:00
|
|
|
} else if (kHNavList[i].action == NA_FORWARD) {
|
2014-11-24 20:23:26 +01:00
|
|
|
expected_current_index_++;
|
|
|
|
}
|
|
|
|
expected_forwardback_[expected_current_index_] =
|
|
|
|
(kHNavList[i].action != NA_LOAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~NavigationEntryVisitor() override {
|
|
|
|
EXPECT_EQ(callback_count_, expected_total_);
|
|
|
|
callback_->yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Visit(CefRefPtr<CefNavigationEntry> entry,
|
|
|
|
bool current,
|
|
|
|
int index,
|
|
|
|
int total) override {
|
|
|
|
// Only 3 loads total.
|
|
|
|
EXPECT_LT(index, 3);
|
|
|
|
EXPECT_LE(total, 3);
|
|
|
|
|
|
|
|
EXPECT_EQ((expected_current_index_ == index), current);
|
|
|
|
EXPECT_EQ(callback_count_, index);
|
|
|
|
EXPECT_EQ(expected_total_, total);
|
|
|
|
|
|
|
|
std::string expected_url;
|
|
|
|
std::string expected_title;
|
|
|
|
if (index == 0) {
|
|
|
|
expected_url = kHNav1;
|
|
|
|
expected_title = "Nav1";
|
|
|
|
} else if (index == 1) {
|
|
|
|
expected_url = kHNav2;
|
|
|
|
expected_title = "Nav2";
|
|
|
|
} else if (index == 2) {
|
|
|
|
expected_url = kHNav3;
|
|
|
|
expected_title = "Nav3";
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_TRUE(entry->IsValid());
|
|
|
|
EXPECT_STREQ(expected_url.c_str(), entry->GetURL().ToString().c_str());
|
|
|
|
EXPECT_STREQ(expected_url.c_str(),
|
|
|
|
entry->GetDisplayURL().ToString().c_str());
|
|
|
|
EXPECT_STREQ(expected_url.c_str(),
|
|
|
|
entry->GetOriginalURL().ToString().c_str());
|
|
|
|
EXPECT_STREQ(expected_title.c_str(), entry->GetTitle().ToString().c_str());
|
|
|
|
|
2020-02-14 22:58:58 +01:00
|
|
|
const auto transition_type = entry->GetTransitionType();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (expected_forwardback_[index]) {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitForwardBack, transition_type);
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-11-24 20:23:26 +01:00
|
|
|
|
|
|
|
EXPECT_FALSE(entry->HasPostData());
|
2022-05-31 22:28:43 +02:00
|
|
|
EXPECT_GT(CefTimeFrom(entry->GetCompletionTime()).GetTimeT(), 0);
|
2014-11-24 20:23:26 +01:00
|
|
|
EXPECT_EQ(200, entry->GetHttpStatusCode());
|
|
|
|
|
|
|
|
callback_count_++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int nav_;
|
|
|
|
TrackCallback* callback_;
|
2024-01-20 18:00:09 +01:00
|
|
|
int expected_total_ = 0;
|
|
|
|
int expected_current_index_ = -1;
|
|
|
|
bool expected_forwardback_[3] = {}; // Only 3 loads total.
|
|
|
|
int callback_count_ = 0;
|
2014-11-24 20:23:26 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(NavigationEntryVisitor);
|
|
|
|
};
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
// Browser side.
|
2012-04-03 03:34:16 +02:00
|
|
|
class HistoryNavTestHandler : public TestHandler {
|
|
|
|
public:
|
2022-04-05 19:22:32 +02:00
|
|
|
HistoryNavTestHandler() = default;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Add the resources that we will navigate to/from.
|
2017-05-17 11:29:28 +02:00
|
|
|
AddResource(
|
|
|
|
kHNav1,
|
2014-11-24 20:23:26 +01:00
|
|
|
"<html><head><title>Nav1</title></head><body>Nav1</body></html>",
|
|
|
|
"text/html");
|
|
|
|
AddResource(kHNav2,
|
2017-05-17 11:29:28 +02:00
|
|
|
"<html><head><title>Nav2</title><body>Nav2</body></html>",
|
|
|
|
"text/html");
|
2014-11-24 20:23:26 +01:00
|
|
|
AddResource(kHNav3,
|
2017-05-17 11:29:28 +02:00
|
|
|
"<html><head><title>Nav3</title><body>Nav3</body></html>",
|
|
|
|
"text/html");
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info = CefDictionaryValue::Create();
|
|
|
|
extra_info->SetBool(kHistoryNavTestCmdKey, true);
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Create the browser.
|
2020-01-15 14:34:01 +01:00
|
|
|
CreateBrowser(CefString(), nullptr, extra_info);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RunNav(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (nav_ == NAV_LIST_SIZE()) {
|
|
|
|
// End of the nav list.
|
|
|
|
DestroyTest();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
const NavListItem& item = kHNavList[nav_];
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Perform the action.
|
|
|
|
switch (item.action) {
|
2017-05-17 11:29:28 +02:00
|
|
|
case NA_LOAD:
|
|
|
|
browser->GetMainFrame()->LoadURL(item.target);
|
|
|
|
break;
|
|
|
|
case NA_BACK:
|
|
|
|
browser->GoBack();
|
|
|
|
break;
|
|
|
|
case NA_FORWARD:
|
|
|
|
browser->GoForward();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
void RunNextNavIfReady(CefRefPtr<CefBrowser> browser) {
|
2022-04-05 19:22:32 +02:00
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
LOG(INFO) << "browser nav=" << nav_
|
|
|
|
<< " load_end_confirmation_=" << load_end_confirmation_
|
|
|
|
<< " load_state_change_loaded_confirmation_="
|
|
|
|
<< load_state_change_loaded_confirmation_
|
|
|
|
<< " renderer_confirmation_=" << renderer_confirmation_;
|
|
|
|
#endif
|
|
|
|
|
2015-11-10 21:18:16 +01:00
|
|
|
if (load_end_confirmation_ && load_state_change_loaded_confirmation_ &&
|
|
|
|
renderer_confirmation_) {
|
2012-11-09 19:47:09 +01:00
|
|
|
load_end_confirmation_ = false;
|
2015-11-10 21:18:16 +01:00
|
|
|
load_state_change_loaded_confirmation_ = false;
|
2012-11-09 19:47:09 +01:00
|
|
|
renderer_confirmation_ = false;
|
|
|
|
nav_++;
|
|
|
|
RunNav(browser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
|
|
|
|
RunNav(browser);
|
|
|
|
}
|
|
|
|
|
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-12 19:44:54 +02:00
|
|
|
const NavListItem& item = kHNavList[nav_];
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
LOG(INFO) << "browser nav=" << nav_ << " " << NavActionString(item.action)
|
|
|
|
<< " OnBeforeBrowse";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXPECT_FALSE(got_before_browse_[nav_]);
|
2013-09-12 19:44:54 +02:00
|
|
|
got_before_browse_[nav_].yes();
|
|
|
|
|
|
|
|
std::string url = request->GetURL();
|
|
|
|
EXPECT_STREQ(item.target, url.c_str());
|
|
|
|
|
|
|
|
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
2020-02-14 22:58:58 +01:00
|
|
|
|
|
|
|
const auto transition_type = request->GetTransitionType();
|
2017-08-11 18:56:52 +02:00
|
|
|
if (item.action == NA_LOAD) {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
|
2017-08-11 18:56:52 +02:00
|
|
|
} else if (item.action == NA_BACK || item.action == NA_FORWARD) {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitForwardBack, transition_type);
|
2017-08-11 18:56:52 +02:00
|
|
|
}
|
2013-09-12 19:44:54 +02:00
|
|
|
|
|
|
|
if (nav_ > 0) {
|
|
|
|
const NavListItem& last_item = kHNavList[nav_ - 1];
|
|
|
|
EXPECT_EQ(last_item.can_go_back, browser->CanGoBack());
|
|
|
|
EXPECT_EQ(last_item.can_go_forward, browser->CanGoForward());
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(browser->CanGoBack());
|
|
|
|
EXPECT_FALSE(browser->CanGoForward());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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 {
|
2024-04-27 03:21:18 +02:00
|
|
|
if (request->GetResourceType() == RT_FAVICON) {
|
2020-09-25 03:40:47 +02:00
|
|
|
// Ignore favicon requests.
|
|
|
|
return RV_CANCEL;
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
const NavListItem& item = kHNavList[nav_];
|
2020-09-25 03:40:47 +02:00
|
|
|
const std::string& url = request->GetURL();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType())
|
|
|
|
<< "nav=" << nav_ << " url=" << url;
|
2020-02-14 22:58:58 +01:00
|
|
|
|
|
|
|
const auto transition_type = request->GetTransitionType();
|
2017-08-11 18:56:52 +02:00
|
|
|
if (item.action == NA_LOAD) {
|
2020-09-25 03:40:47 +02:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, transition_type)
|
|
|
|
<< "nav=" << nav_ << " url=" << url;
|
2017-08-11 18:56:52 +02:00
|
|
|
} else if (item.action == NA_BACK || item.action == NA_FORWARD) {
|
2020-09-25 03:40:47 +02:00
|
|
|
EXPECT_EQ(kTransitionExplicitForwardBack, transition_type)
|
|
|
|
<< "nav=" << nav_ << " url=" << url;
|
2017-08-11 18:56:52 +02:00
|
|
|
}
|
2013-09-10 21:42:53 +02:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_FALSE(got_before_resource_load_[nav_]);
|
2012-04-03 03:34:16 +02:00
|
|
|
got_before_resource_load_[nav_].yes();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url == item.target) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_correct_target_[nav_].yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
return RV_CONTINUE;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2012-11-09 19:47:09 +01:00
|
|
|
const NavListItem& item = kHNavList[nav_];
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
LOG(INFO) << "browser nav=" << nav_ << " " << NavActionString(item.action)
|
|
|
|
<< " OnLoadingStateChange isLoading=" << isLoading;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
EXPECT_FALSE(got_loading_state_change_loading_[nav_]);
|
|
|
|
got_loading_state_change_loading_[nav_].yes();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_FALSE(got_loading_state_change_loaded_[nav_]);
|
|
|
|
got_loading_state_change_loaded_[nav_].yes();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (item.can_go_back == canGoBack) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_correct_can_go_back_[nav_].yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (item.can_go_forward == canGoForward) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_correct_can_go_forward_[nav_].yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-10 21:18:16 +01:00
|
|
|
|
|
|
|
load_state_change_loaded_confirmation_ = true;
|
|
|
|
RunNextNavIfReady(browser);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
2016-07-12 17:59:42 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser->IsPopup() || !frame->IsMain()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
const NavListItem& item = kHNavList[nav_];
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
LOG(INFO) << "browser nav=" << nav_ << " " << NavActionString(item.action)
|
|
|
|
<< " OnLoadStart";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXPECT_FALSE(got_load_start_[nav_]);
|
2012-04-03 03:34:16 +02:00
|
|
|
got_load_start_[nav_].yes();
|
|
|
|
|
2017-08-11 18:56:52 +02:00
|
|
|
if (item.action == NA_LOAD) {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
|
2017-08-11 18:56:52 +02:00
|
|
|
} else if (item.action == NA_BACK || item.action == NA_FORWARD) {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitForwardBack, transition_type);
|
2017-08-11 18:56:52 +02:00
|
|
|
}
|
2016-07-12 17:59:42 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string url1 = browser->GetMainFrame()->GetURL();
|
|
|
|
std::string url2 = frame->GetURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url1 == item.target && url2 == item.target) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_correct_load_start_url_[nav_].yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +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 (browser->IsPopup() || !frame->IsMain()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
const NavListItem& item = kHNavList[nav_];
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
#if VERBOSE_DEBUGGING
|
|
|
|
LOG(INFO) << "browser nav=" << nav_ << " " << NavActionString(item.action)
|
|
|
|
<< " OnLoadEnd";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXPECT_FALSE(got_load_end_[nav_]);
|
2012-04-03 03:34:16 +02:00
|
|
|
got_load_end_[nav_].yes();
|
|
|
|
|
2014-11-24 20:23:26 +01:00
|
|
|
// Test that navigation entries are correct.
|
|
|
|
CefRefPtr<NavigationEntryVisitor> visitor =
|
|
|
|
new NavigationEntryVisitor(nav_, &got_correct_history_[nav_]);
|
|
|
|
browser->GetHost()->GetNavigationEntries(visitor.get(), false);
|
2020-01-15 14:34:01 +01:00
|
|
|
visitor = nullptr;
|
2014-11-24 20:23:26 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string url1 = browser->GetMainFrame()->GetURL();
|
|
|
|
std::string url2 = frame->GetURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url1 == item.target && url2 == item.target) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_correct_load_end_url_[nav_].yes();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
load_end_confirmation_ = true;
|
|
|
|
RunNextNavIfReady(browser);
|
|
|
|
}
|
|
|
|
|
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 {
|
2012-11-09 19:47:09 +01:00
|
|
|
if (message->GetName().ToString() == kHistoryNavMsg) {
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_FALSE(got_before_navigation_[nav_]);
|
2012-11-09 19:47:09 +01:00
|
|
|
got_before_navigation_[nav_].yes();
|
|
|
|
|
|
|
|
// Test that the renderer side succeeded.
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
EXPECT_EQ(nav_, args->GetInt(0));
|
|
|
|
EXPECT_TRUE(args->GetBool(1));
|
|
|
|
|
|
|
|
renderer_confirmation_ = true;
|
|
|
|
RunNextNavIfReady(browser);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message not handled.
|
|
|
|
return false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
int nav_ = 0;
|
|
|
|
bool load_end_confirmation_ = false;
|
|
|
|
bool load_state_change_loaded_confirmation_ = false;
|
|
|
|
bool renderer_confirmation_ = false;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-09-12 19:44:54 +02:00
|
|
|
TrackCallback got_before_browse_[NAV_LIST_SIZE()];
|
2012-11-09 19:47:09 +01:00
|
|
|
TrackCallback got_before_navigation_[NAV_LIST_SIZE()];
|
2012-04-03 03:34:16 +02:00
|
|
|
TrackCallback got_before_resource_load_[NAV_LIST_SIZE()];
|
|
|
|
TrackCallback got_correct_target_[NAV_LIST_SIZE()];
|
2022-04-05 19:22:32 +02:00
|
|
|
TrackCallback got_loading_state_change_loading_[NAV_LIST_SIZE()];
|
|
|
|
TrackCallback got_loading_state_change_loaded_[NAV_LIST_SIZE()];
|
2012-04-03 03:34:16 +02:00
|
|
|
TrackCallback got_correct_can_go_back_[NAV_LIST_SIZE()];
|
|
|
|
TrackCallback got_correct_can_go_forward_[NAV_LIST_SIZE()];
|
|
|
|
TrackCallback got_load_start_[NAV_LIST_SIZE()];
|
|
|
|
TrackCallback got_correct_load_start_url_[NAV_LIST_SIZE()];
|
|
|
|
TrackCallback got_load_end_[NAV_LIST_SIZE()];
|
2014-11-24 20:23:26 +01:00
|
|
|
TrackCallback got_correct_history_[NAV_LIST_SIZE()];
|
2012-04-03 03:34:16 +02:00
|
|
|
TrackCallback got_correct_load_end_url_[NAV_LIST_SIZE()];
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(HistoryNavTestHandler);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Verify history navigation.
|
|
|
|
TEST(NavigationTest, History) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<HistoryNavTestHandler> handler = new HistoryNavTestHandler();
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < NAV_LIST_SIZE(); ++i) {
|
2022-04-05 19:22:32 +02:00
|
|
|
if (ExpectResourceLoadEvents(kHNavList[i].action)) {
|
|
|
|
EXPECT_TRUE(handler->got_before_browse_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_before_resource_load_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_correct_target_[i]) << "i = " << i;
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(handler->got_before_browse_[i]) << "i = " << i;
|
|
|
|
EXPECT_FALSE(handler->got_before_resource_load_[i]) << "i = " << i;
|
|
|
|
EXPECT_FALSE(handler->got_correct_target_[i]) << "i = " << i;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_TRUE(handler->got_before_navigation_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_load_start_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_correct_load_start_url_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_load_end_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_correct_load_end_url_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_correct_history_[i]) << "i = " << i;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_TRUE(handler->got_loading_state_change_loading_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_loading_state_change_loaded_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_correct_can_go_back_[i]) << "i = " << i;
|
|
|
|
EXPECT_TRUE(handler->got_correct_can_go_forward_[i]) << "i = " << i;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 18:52:58 +01:00
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kDynIfrNav1[] = "https://tests-dynframe/nav1.html";
|
|
|
|
const char kDynIfrNav2[] = "https://tests-dynframe/nav2.html";
|
2016-11-04 18:52:58 +01:00
|
|
|
|
|
|
|
// Browser side.
|
|
|
|
class HistoryDynamicIFramesNavTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
HistoryDynamicIFramesNavTestHandler() = default;
|
2016-11-04 18:52:58 +01:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
// Add the resources that we will navigate to/from.
|
|
|
|
AddResource(kDynIfrNav1,
|
2017-05-17 11:29:28 +02:00
|
|
|
"<html>"
|
|
|
|
" <head>"
|
|
|
|
" <title>Nav1</title>"
|
|
|
|
" <script language='javascript'>"
|
|
|
|
" function onload() {"
|
|
|
|
" fr = Math.floor(Math.random() * 10);"
|
|
|
|
" if(fr == 0) "
|
|
|
|
" fr = 1;"
|
|
|
|
" console.log('fr=' + fr);"
|
|
|
|
" for(i = 1; i <= fr; i++) {"
|
|
|
|
" try {"
|
|
|
|
" var n = 'DYN_' + Math.floor(Math.random() * 10000);"
|
|
|
|
" "
|
|
|
|
" d = document.createElement('div');"
|
|
|
|
" d.id = 'sf' + i; "
|
|
|
|
" d.innerText = n; "
|
|
|
|
" document.body.appendChild(d); "
|
|
|
|
" "
|
|
|
|
" f = document.createElement('iframe'); "
|
|
|
|
" f.id = 'f_' + i; "
|
|
|
|
" f.name = n; "
|
|
|
|
" f.src = 'nav2.html'; "
|
|
|
|
" document.body.appendChild(f); "
|
|
|
|
" } catch(e) { "
|
|
|
|
" console.log('frame[' + i + ']: ' + e); "
|
|
|
|
" } "
|
|
|
|
" } "
|
|
|
|
" } "
|
|
|
|
" </script> "
|
|
|
|
" </head> "
|
|
|
|
" <body onload='onload();'> "
|
|
|
|
" Nav1 "
|
|
|
|
" </body> "
|
|
|
|
"</html>",
|
|
|
|
"text/html");
|
|
|
|
AddResource(
|
|
|
|
kDynIfrNav2,
|
2016-11-04 18:52:58 +01:00
|
|
|
"<html><head><title>Nav2</title></head><body>Nav2</body></html>",
|
|
|
|
"text/html");
|
|
|
|
|
|
|
|
// Create the browser.
|
|
|
|
CreateBrowser(CefString());
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunNav(CefRefPtr<CefBrowser> browser) {
|
|
|
|
EXPECT_LE(nav_, 3);
|
|
|
|
EXPECT_FALSE(got_load_start_[nav_]);
|
|
|
|
EXPECT_FALSE(got_load_end_[nav_]);
|
|
|
|
|
|
|
|
if (nav_ == 0) {
|
|
|
|
browser->GetMainFrame()->LoadURL(kDynIfrNav1);
|
|
|
|
} else if (nav_ == 1) {
|
|
|
|
browser->GetMainFrame()->LoadURL(kDynIfrNav2);
|
|
|
|
} else if (nav_ == 2) {
|
|
|
|
browser->GoBack();
|
|
|
|
} else if (nav_ == 3) {
|
|
|
|
browser->Reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
|
|
|
|
nav_ = 0;
|
|
|
|
RunNav(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!frame->IsMain()) {
|
2016-11-04 18:52:58 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-04 18:52:58 +01:00
|
|
|
got_load_start_[nav_].yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!frame->IsMain()) {
|
2016-11-04 18:52:58 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-04 18:52:58 +01:00
|
|
|
CefString url = browser->GetMainFrame()->GetURL();
|
|
|
|
got_load_end_[nav_].yes();
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
if (nav_ == 3) {
|
2016-11-04 18:52:58 +01:00
|
|
|
EXPECT_STREQ(url.ToString().c_str(), kDynIfrNav1);
|
|
|
|
DestroyTest();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nav_++;
|
|
|
|
RunNav(browser);
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
int nav_ = -1;
|
2016-11-04 18:52:58 +01:00
|
|
|
TrackCallback got_load_start_[4];
|
|
|
|
TrackCallback got_load_end_[4];
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(HistoryDynamicIFramesNavTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Verify history navigation of pages containing dynamically created iframes.
|
|
|
|
// See issue #2022 for background.
|
|
|
|
TEST(NavigationTest, HistoryDynamicIFrames) {
|
|
|
|
CefRefPtr<HistoryDynamicIFramesNavTestHandler> handler =
|
|
|
|
new HistoryDynamicIFramesNavTestHandler();
|
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
EXPECT_TRUE(handler->got_load_start_[i]);
|
|
|
|
EXPECT_TRUE(handler->got_load_end_[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kRNav1[] = "https://tests/nav1.html";
|
|
|
|
const char kRNav2[] = "https://tests/nav2.html";
|
|
|
|
const char kRNav3[] = "https://tests/nav3.html";
|
|
|
|
const char kRNav4[] = "https://tests/nav4.html";
|
2012-11-09 19:47:09 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool g_got_nav1_request = false;
|
|
|
|
bool g_got_nav3_request = false;
|
|
|
|
bool g_got_nav4_request = false;
|
|
|
|
bool g_got_invalid_request = false;
|
|
|
|
|
|
|
|
class RedirectSchemeHandler : public CefResourceHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
RedirectSchemeHandler() = default;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
bool Open(CefRefPtr<CefRequest> request,
|
|
|
|
bool& handle_request,
|
|
|
|
CefRefPtr<CefCallback> callback) override {
|
|
|
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
std::string url = request->GetURL();
|
2012-11-09 19:47:09 +01:00
|
|
|
if (url == kRNav1) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Redirect using HTTP 302
|
|
|
|
g_got_nav1_request = true;
|
|
|
|
status_ = 302;
|
2012-11-09 19:47:09 +01:00
|
|
|
location_ = kRNav2;
|
2012-04-03 03:34:16 +02:00
|
|
|
content_ = "<html><body>Redirected Nav1</body></html>";
|
2012-11-09 19:47:09 +01:00
|
|
|
} else if (url == kRNav3) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Redirect using redirectUrl
|
|
|
|
g_got_nav3_request = true;
|
|
|
|
status_ = -1;
|
2012-11-09 19:47:09 +01:00
|
|
|
location_ = kRNav4;
|
2012-04-03 03:34:16 +02:00
|
|
|
content_ = "<html><body>Redirected Nav3</body></html>";
|
2012-11-09 19:47:09 +01:00
|
|
|
} else if (url == kRNav4) {
|
2012-04-03 03:34:16 +02:00
|
|
|
g_got_nav4_request = true;
|
|
|
|
status_ = 200;
|
|
|
|
content_ = "<html><body>Nav4</body></html>";
|
|
|
|
}
|
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
handle_request = true;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
if (status_ != 0) {
|
2019-12-31 13:24:10 +01:00
|
|
|
// Continue request.
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
2019-12-31 13:24:10 +01:00
|
|
|
|
|
|
|
// Cancel request.
|
|
|
|
g_got_invalid_request = true;
|
|
|
|
return false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t& response_length,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefString& redirectUrl) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
EXPECT_NE(status_, 0);
|
|
|
|
|
|
|
|
response->SetStatus(status_);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response_length = content_.size();
|
|
|
|
|
|
|
|
if (status_ == 302) {
|
|
|
|
// Redirect using HTTP 302
|
|
|
|
EXPECT_GT(location_.size(), static_cast<size_t>(0));
|
|
|
|
response->SetStatusText("Found");
|
|
|
|
CefResponse::HeaderMap headers;
|
|
|
|
response->GetHeaderMap(headers);
|
|
|
|
headers.insert(std::make_pair("Location", location_));
|
|
|
|
response->SetHeaderMap(headers);
|
|
|
|
} else if (status_ == -1) {
|
|
|
|
// Rdirect using redirectUrl
|
|
|
|
EXPECT_GT(location_.size(), static_cast<size_t>(0));
|
|
|
|
redirectUrl = location_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void Cancel() override { EXPECT_TRUE(CefCurrentlyOn(TID_IO)); }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
bool Read(void* data_out,
|
|
|
|
int bytes_to_read,
|
|
|
|
int& bytes_read,
|
|
|
|
CefRefPtr<CefResourceReadCallback> callback) override {
|
|
|
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
bytes_read = 0;
|
|
|
|
bool has_data = false;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
size_t size = content_.size();
|
|
|
|
if (offset_ < size) {
|
|
|
|
int transfer_size =
|
|
|
|
std::min(bytes_to_read, static_cast<int>(size - offset_));
|
|
|
|
memcpy(data_out, content_.c_str() + offset_, transfer_size);
|
|
|
|
offset_ += transfer_size;
|
|
|
|
|
|
|
|
bytes_read = transfer_size;
|
2019-12-31 13:24:10 +01:00
|
|
|
has_data = true;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
return has_data;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string content_;
|
2024-01-20 18:00:09 +01:00
|
|
|
size_t offset_ = 0;
|
|
|
|
int status_ = 0;
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string location_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(RedirectSchemeHandler);
|
2019-12-31 13:24:10 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(RedirectSchemeHandler);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class RedirectSchemeHandlerFactory : public CefSchemeHandlerFactory {
|
|
|
|
public:
|
2016-07-08 21:28:53 +02:00
|
|
|
RedirectSchemeHandlerFactory() {
|
|
|
|
g_got_nav1_request = false;
|
|
|
|
g_got_nav3_request = false;
|
|
|
|
g_got_nav4_request = false;
|
|
|
|
g_got_invalid_request = false;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& scheme_name,
|
|
|
|
CefRefPtr<CefRequest> request) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
|
|
|
return new RedirectSchemeHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(RedirectSchemeHandlerFactory);
|
2019-12-31 13:24:10 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(RedirectSchemeHandlerFactory);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class RedirectTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
RedirectTestHandler() = default;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Create the browser.
|
2012-11-09 19:47:09 +01:00
|
|
|
CreateBrowser(kRNav1);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
2012-04-03 03:34:16 +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 {
|
2024-04-27 03:21:18 +02:00
|
|
|
if (request->GetResourceType() == RT_FAVICON) {
|
2020-09-25 03:40:47 +02:00
|
|
|
// Ignore favicon requests.
|
|
|
|
return RV_CANCEL;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Should be called for all but the second URL.
|
|
|
|
std::string url = request->GetURL();
|
|
|
|
|
2013-09-10 21:42:53 +02:00
|
|
|
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, request->GetTransitionType());
|
2013-09-10 21:42:53 +02:00
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
if (url == kRNav1) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_nav1_before_resource_load_.yes();
|
2012-11-09 19:47:09 +01:00
|
|
|
} else if (url == kRNav3) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_nav3_before_resource_load_.yes();
|
2012-11-09 19:47:09 +01:00
|
|
|
} else if (url == kRNav4) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_nav4_before_resource_load_.yes();
|
|
|
|
} else {
|
|
|
|
got_invalid_before_resource_load_.yes();
|
|
|
|
}
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
return RV_CONTINUE;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2015-03-11 19:44:11 +01:00
|
|
|
CefRefPtr<CefRequest> request,
|
2016-08-24 15:19:57 +02:00
|
|
|
CefRefPtr<CefResponse> response,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefString& new_url) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Should be called for each redirected URL.
|
|
|
|
|
2015-03-11 19:44:11 +01:00
|
|
|
const std::string& old_url = request->GetURL();
|
2012-11-09 19:47:09 +01:00
|
|
|
if (old_url == kRNav1 && new_url == kRNav2) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Called due to the nav1 redirect response.
|
|
|
|
got_nav1_redirect_.yes();
|
|
|
|
|
2016-08-24 15:19:57 +02:00
|
|
|
EXPECT_EQ(302, response->GetStatus());
|
|
|
|
EXPECT_STREQ("Found", response->GetStatusText().ToString().c_str());
|
2019-04-24 04:50:25 +02:00
|
|
|
EXPECT_STREQ("", response->GetMimeType().ToString().c_str());
|
2019-10-14 13:32:38 +02:00
|
|
|
EXPECT_STREQ(kRNav2,
|
|
|
|
response->GetHeaderByName("Location").ToString().c_str());
|
2016-08-24 15:19:57 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Change the redirect to the 3rd URL.
|
2012-11-09 19:47:09 +01:00
|
|
|
new_url = kRNav3;
|
|
|
|
} else if (old_url == kRNav1 && new_url == kRNav3) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Called due to the redirect change above.
|
|
|
|
got_nav2_redirect_.yes();
|
2016-08-24 15:19:57 +02:00
|
|
|
|
|
|
|
EXPECT_EQ(307, response->GetStatus());
|
|
|
|
EXPECT_STREQ("Internal Redirect",
|
|
|
|
response->GetStatusText().ToString().c_str());
|
|
|
|
EXPECT_TRUE(response->GetMimeType().empty());
|
2019-10-14 13:32:38 +02:00
|
|
|
EXPECT_STREQ(kRNav3,
|
|
|
|
response->GetHeaderByName("Location").ToString().c_str());
|
2012-11-09 19:47:09 +01:00
|
|
|
} else if (old_url == kRNav3 && new_url == kRNav4) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Called due to the nav3 redirect response.
|
|
|
|
got_nav3_redirect_.yes();
|
2016-08-24 15:19:57 +02:00
|
|
|
|
2019-07-29 23:27:12 +02:00
|
|
|
EXPECT_EQ(307, response->GetStatus());
|
|
|
|
EXPECT_STREQ("Temporary Redirect",
|
|
|
|
response->GetStatusText().ToString().c_str());
|
|
|
|
EXPECT_STREQ("", response->GetMimeType().ToString().c_str());
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
got_invalid_redirect_.yes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
2016-07-12 17:59:42 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Should only be called for the final loaded URL.
|
|
|
|
std::string url = frame->GetURL();
|
|
|
|
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
|
2016-07-12 17:59:42 +02:00
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
if (url == kRNav4) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_nav4_load_start_.yes();
|
|
|
|
} else {
|
|
|
|
got_invalid_load_start_.yes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Should only be called for the final loaded URL.
|
|
|
|
std::string url = frame->GetURL();
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
if (url == kRNav4) {
|
2012-04-03 03:34:16 +02:00
|
|
|
got_nav4_load_end_.yes();
|
|
|
|
DestroyTest();
|
|
|
|
} else {
|
|
|
|
got_invalid_load_end_.yes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackCallback got_nav1_before_resource_load_;
|
|
|
|
TrackCallback got_nav3_before_resource_load_;
|
|
|
|
TrackCallback got_nav4_before_resource_load_;
|
|
|
|
TrackCallback got_invalid_before_resource_load_;
|
|
|
|
TrackCallback got_nav4_load_start_;
|
|
|
|
TrackCallback got_invalid_load_start_;
|
|
|
|
TrackCallback got_nav4_load_end_;
|
|
|
|
TrackCallback got_invalid_load_end_;
|
|
|
|
TrackCallback got_nav1_redirect_;
|
|
|
|
TrackCallback got_nav2_redirect_;
|
|
|
|
TrackCallback got_nav3_redirect_;
|
|
|
|
TrackCallback got_invalid_redirect_;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(RedirectTestHandler);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
2016-07-08 21:28:53 +02:00
|
|
|
// Like above but destroy the WebContents while the redirect is in-progress.
|
|
|
|
class RedirectDestroyTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
RedirectDestroyTestHandler() = default;
|
2016-07-08 21:28:53 +02:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
// Create the browser.
|
|
|
|
CreateBrowser(kRNav1);
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefResponse> response,
|
|
|
|
CefString& new_url) override {
|
2016-07-08 21:28:53 +02:00
|
|
|
const std::string& old_url = request->GetURL();
|
|
|
|
if (old_url == kRNav1 && new_url == kRNav2) {
|
|
|
|
// Called due to the nav1 redirect response.
|
|
|
|
got_nav1_redirect_.yes();
|
|
|
|
|
|
|
|
new_url = "about:blank";
|
|
|
|
|
|
|
|
// Destroy the test (and the underlying WebContents) while the redirect
|
|
|
|
// is still pending.
|
|
|
|
DestroyTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackCallback got_nav1_redirect_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(RedirectDestroyTestHandler);
|
|
|
|
};
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Verify frame names and identifiers.
|
|
|
|
TEST(NavigationTest, Redirect) {
|
2023-04-29 00:17:03 +02:00
|
|
|
CefRegisterSchemeHandlerFactory("https", "tests",
|
2017-05-17 11:29:28 +02:00
|
|
|
new RedirectSchemeHandlerFactory());
|
2012-04-03 03:34:16 +02:00
|
|
|
WaitForIOThread();
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<RedirectTestHandler> handler = new RedirectTestHandler();
|
2012-04-03 03:34:16 +02:00
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
CefClearSchemeHandlerFactories();
|
|
|
|
WaitForIOThread();
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_TRUE(handler->got_nav1_before_resource_load_);
|
|
|
|
EXPECT_TRUE(handler->got_nav3_before_resource_load_);
|
|
|
|
EXPECT_TRUE(handler->got_nav4_before_resource_load_);
|
|
|
|
EXPECT_FALSE(handler->got_invalid_before_resource_load_);
|
|
|
|
EXPECT_TRUE(handler->got_nav4_load_start_);
|
|
|
|
EXPECT_FALSE(handler->got_invalid_load_start_);
|
|
|
|
EXPECT_TRUE(handler->got_nav4_load_end_);
|
|
|
|
EXPECT_FALSE(handler->got_invalid_load_end_);
|
|
|
|
EXPECT_TRUE(handler->got_nav1_redirect_);
|
|
|
|
EXPECT_FALSE(handler->got_nav2_redirect_);
|
|
|
|
EXPECT_TRUE(handler->got_nav3_redirect_);
|
|
|
|
EXPECT_FALSE(handler->got_invalid_redirect_);
|
|
|
|
EXPECT_TRUE(g_got_nav1_request);
|
|
|
|
EXPECT_TRUE(g_got_nav3_request);
|
|
|
|
EXPECT_TRUE(g_got_nav4_request);
|
|
|
|
EXPECT_FALSE(g_got_invalid_request);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2012-11-09 19:47:09 +01:00
|
|
|
|
2016-07-08 21:28:53 +02:00
|
|
|
// Verify that destroying the WebContents while the redirect is in-progress does
|
|
|
|
// not result in a crash.
|
|
|
|
TEST(NavigationTest, RedirectDestroy) {
|
2023-04-29 00:17:03 +02:00
|
|
|
CefRegisterSchemeHandlerFactory("https", "tests",
|
2017-05-17 11:29:28 +02:00
|
|
|
new RedirectSchemeHandlerFactory());
|
2016-07-08 21:28:53 +02:00
|
|
|
WaitForIOThread();
|
|
|
|
|
|
|
|
CefRefPtr<RedirectDestroyTestHandler> handler =
|
|
|
|
new RedirectDestroyTestHandler();
|
|
|
|
handler->ExecuteTest();
|
|
|
|
|
|
|
|
CefClearSchemeHandlerFactories();
|
|
|
|
WaitForIOThread();
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_TRUE(handler->got_nav1_redirect_);
|
|
|
|
EXPECT_TRUE(g_got_nav1_request);
|
|
|
|
EXPECT_FALSE(g_got_nav3_request);
|
|
|
|
EXPECT_FALSE(g_got_nav4_request);
|
|
|
|
EXPECT_FALSE(g_got_invalid_request);
|
2016-07-08 21:28:53 +02:00
|
|
|
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
2012-11-09 19:47:09 +01:00
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char KONav1[] = "https://tests-onav.com/nav1.html";
|
|
|
|
const char KONav2[] = "https://tests-onav.com/nav2.html";
|
2012-11-20 21:08:36 +01:00
|
|
|
const char kOrderNavMsg[] = "NavigationTest.OrderNav";
|
|
|
|
const char kOrderNavClosedMsg[] = "NavigationTest.OrderNavClosed";
|
2019-10-03 16:17:58 +02:00
|
|
|
const char kOrderNavTestCmdKey[] = "nav-order-test";
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
class OrderNavLoadState {
|
|
|
|
public:
|
|
|
|
OrderNavLoadState(bool is_popup, bool browser_side)
|
2017-05-17 11:29:28 +02:00
|
|
|
: is_popup_(is_popup), browser_side_(browser_side) {}
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) {
|
|
|
|
if (isLoading) {
|
|
|
|
EXPECT_TRUE(Verify(false, false, false, false));
|
|
|
|
|
|
|
|
got_loading_state_start_.yes();
|
|
|
|
} else {
|
2015-11-10 21:18:16 +01:00
|
|
|
EXPECT_TRUE(Verify(true, false, true, true));
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
got_loading_state_end_.yes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame) {
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_TRUE(Verify(true, false, false, false));
|
|
|
|
|
|
|
|
got_load_start_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) {
|
2015-11-10 21:18:16 +01:00
|
|
|
EXPECT_TRUE(Verify(true, false, true, false));
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
got_load_end_.yes();
|
|
|
|
}
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
bool IsStarted() const {
|
2017-05-17 11:29:28 +02:00
|
|
|
return got_loading_state_start_ || got_loading_state_end_ ||
|
|
|
|
got_load_start_ || got_load_end_;
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
bool IsDone() const {
|
2017-05-17 11:29:28 +02:00
|
|
|
return got_loading_state_start_ && got_loading_state_end_ &&
|
|
|
|
got_load_start_ && got_load_end_;
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Verify(bool got_loading_state_start,
|
|
|
|
bool got_loading_state_end,
|
|
|
|
bool got_load_start,
|
2017-11-29 00:00:50 +01:00
|
|
|
bool got_load_end) const {
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_EQ(got_loading_state_start, got_loading_state_start_)
|
2017-05-17 11:29:28 +02:00
|
|
|
<< "Popup: " << is_popup_ << "; Browser Side: " << browser_side_;
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_EQ(got_loading_state_end, got_loading_state_end_)
|
2017-05-17 11:29:28 +02:00
|
|
|
<< "Popup: " << is_popup_ << "; Browser Side: " << browser_side_;
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_EQ(got_load_start, got_load_start_)
|
2017-05-17 11:29:28 +02:00
|
|
|
<< "Popup: " << is_popup_ << "; Browser Side: " << browser_side_;
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_EQ(got_load_end, got_load_end_)
|
2017-05-17 11:29:28 +02:00
|
|
|
<< "Popup: " << is_popup_ << "; Browser Side: " << browser_side_;
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
return got_loading_state_start == got_loading_state_start_ &&
|
|
|
|
got_loading_state_end == got_loading_state_end_ &&
|
2017-05-17 11:29:28 +02:00
|
|
|
got_load_start == got_load_start_ && got_load_end == got_load_end_;
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
private:
|
2013-09-13 01:36:54 +02:00
|
|
|
bool is_popup_;
|
|
|
|
bool browser_side_;
|
|
|
|
|
|
|
|
TrackCallback got_loading_state_start_;
|
|
|
|
TrackCallback got_loading_state_end_;
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
};
|
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
// Renderer side.
|
2015-01-31 05:41:36 +01:00
|
|
|
class OrderNavRendererTest : public ClientAppRenderer::Delegate,
|
2013-09-13 01:36:54 +02:00
|
|
|
public CefLoadHandler {
|
2012-11-20 21:08:36 +01:00
|
|
|
public:
|
|
|
|
OrderNavRendererTest()
|
2024-01-20 18:00:09 +01:00
|
|
|
: state_main_(false, false), state_popup_(true, false) {}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
void OnWebKitInitialized(CefRefPtr<ClientAppRenderer> app) override {
|
2019-10-03 16:17:58 +02:00
|
|
|
EXPECT_FALSE(got_webkit_initialized_);
|
2012-11-20 21:08:36 +01:00
|
|
|
|
|
|
|
got_webkit_initialized_.yes();
|
|
|
|
}
|
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
void OnBrowserCreated(CefRefPtr<ClientAppRenderer> app,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info) override {
|
2021-05-14 18:58:55 +02:00
|
|
|
run_test_ = extra_info && extra_info->HasKey(kOrderNavTestCmdKey);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!run_test_) {
|
2012-11-20 21:08:36 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(got_webkit_initialized_);
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
EXPECT_FALSE(got_browser_created_popup_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_popup_);
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_FALSE(state_popup_.IsStarted());
|
2012-11-20 21:08:36 +01:00
|
|
|
|
|
|
|
got_browser_created_popup_.yes();
|
|
|
|
browser_id_popup_ = browser->GetIdentifier();
|
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(got_browser_created_main_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_main_);
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_FALSE(state_main_.IsStarted());
|
2012-11-20 21:08:36 +01:00
|
|
|
|
|
|
|
got_browser_created_main_.yes();
|
|
|
|
browser_id_main_ = browser->GetIdentifier();
|
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
|
|
|
|
browser_main_ = browser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
void OnBrowserDestroyed(CefRefPtr<ClientAppRenderer> app,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefBrowser> browser) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!run_test_) {
|
2012-11-20 21:08:36 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(got_webkit_initialized_);
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
EXPECT_TRUE(got_browser_created_popup_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_popup_);
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_TRUE(state_popup_.IsDone());
|
2012-11-20 21:08:36 +01:00
|
|
|
|
|
|
|
got_browser_destroyed_popup_.yes();
|
|
|
|
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
|
|
|
|
// Use |browser_main_| to send the message otherwise it will fail.
|
2019-05-24 22:23:43 +02:00
|
|
|
SendTestResults(browser_main_, browser_main_->GetMainFrame(),
|
|
|
|
kOrderNavClosedMsg);
|
2012-11-20 21:08:36 +01:00
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(got_browser_created_main_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_main_);
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_TRUE(state_main_.IsDone());
|
2012-11-20 21:08:36 +01:00
|
|
|
|
|
|
|
got_browser_destroyed_main_.yes();
|
|
|
|
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
|
2020-01-15 14:34:01 +01:00
|
|
|
browser_main_ = nullptr;
|
2012-11-20 21:08:36 +01: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_) {
|
2020-01-15 14:34:01 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2012-11-20 21:08:36 +01:00
|
|
|
EXPECT_TRUE(got_webkit_initialized_);
|
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
if (browser->IsPopup()) {
|
|
|
|
EXPECT_TRUE(got_browser_created_popup_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_popup_);
|
|
|
|
|
|
|
|
state_popup_.OnLoadingStateChange(browser, isLoading, canGoBack,
|
|
|
|
canGoForward);
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(got_browser_created_main_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_main_);
|
|
|
|
|
|
|
|
state_main_.OnLoadingStateChange(browser, isLoading, canGoBack,
|
|
|
|
canGoForward);
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!isLoading) {
|
2019-05-24 22:23:43 +02:00
|
|
|
SendTestResultsIfDone(browser, browser->GetMainFrame());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
2016-07-12 17:59:42 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_TRUE(got_webkit_initialized_);
|
2013-09-10 21:42:53 +02:00
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
if (browser->IsPopup()) {
|
|
|
|
EXPECT_TRUE(got_browser_created_popup_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_popup_);
|
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
state_popup_.OnLoadStart(browser, frame);
|
2012-11-20 21:08:36 +01:00
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(got_browser_created_main_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_main_);
|
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
state_main_.OnLoadStart(browser, frame);
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2013-09-13 01:36:54 +02:00
|
|
|
EXPECT_TRUE(got_webkit_initialized_);
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
if (browser->IsPopup()) {
|
|
|
|
EXPECT_TRUE(got_browser_created_popup_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_popup_);
|
|
|
|
|
|
|
|
state_popup_.OnLoadEnd(browser, frame, httpStatusCode);
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(got_browser_created_main_);
|
|
|
|
EXPECT_FALSE(got_browser_destroyed_main_);
|
|
|
|
|
|
|
|
state_main_.OnLoadEnd(browser, frame, httpStatusCode);
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
SendTestResultsIfDone(browser, frame);
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
|
|
|
ADD_FAILURE() << "renderer OnLoadError url: " << failedUrl.ToString()
|
|
|
|
<< " error: " << errorCode;
|
|
|
|
}
|
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
protected:
|
2019-05-24 22:23:43 +02:00
|
|
|
void SendTestResultsIfDone(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2013-09-13 01:36:54 +02:00
|
|
|
bool done = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser->IsPopup()) {
|
2013-09-13 01:36:54 +02:00
|
|
|
done = state_popup_.IsDone();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2013-09-13 01:36:54 +02:00
|
|
|
done = state_main_.IsDone();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-13 01:36:54 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (done) {
|
2019-05-24 22:23:43 +02:00
|
|
|
SendTestResults(browser, frame, kOrderNavMsg);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
// Send the test results.
|
2019-05-24 22:23:43 +02:00
|
|
|
void SendTestResults(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const char* msg_name) {
|
2012-11-20 21:08:36 +01:00
|
|
|
// Check if the test has failed.
|
|
|
|
bool result = !TestFailed();
|
|
|
|
|
|
|
|
// Return the result to the browser process.
|
|
|
|
CefRefPtr<CefProcessMessage> return_msg =
|
|
|
|
CefProcessMessage::Create(msg_name);
|
|
|
|
CefRefPtr<CefListValue> args = return_msg->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
EXPECT_TRUE(args->SetBool(0, result));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser->IsPopup()) {
|
2012-11-20 21:08:36 +01:00
|
|
|
EXPECT_TRUE(args->SetInt(1, browser_id_popup_));
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2012-11-20 21:08:36 +01:00
|
|
|
EXPECT_TRUE(args->SetInt(1, browser_id_main_));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_BROWSER, return_msg);
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
bool run_test_ = false;
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
int browser_id_main_ = 0;
|
|
|
|
int browser_id_popup_ = 0;
|
2012-11-20 21:08:36 +01:00
|
|
|
CefRefPtr<CefBrowser> browser_main_;
|
|
|
|
TrackCallback got_webkit_initialized_;
|
|
|
|
TrackCallback got_browser_created_main_;
|
|
|
|
TrackCallback got_browser_destroyed_main_;
|
|
|
|
TrackCallback got_browser_created_popup_;
|
|
|
|
TrackCallback got_browser_destroyed_popup_;
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
OrderNavLoadState state_main_;
|
|
|
|
OrderNavLoadState state_popup_;
|
2012-11-20 21:08:36 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(OrderNavRendererTest);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Browser side.
|
|
|
|
class OrderNavTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
OrderNavTestHandler() : state_main_(false, true), state_popup_(true, true) {}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
// Returns state that will be checked in the renderer process via
|
|
|
|
// OrderNavRendererTest::OnBrowserCreated.
|
|
|
|
CefRefPtr<CefDictionaryValue> GetExtraInfo() {
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info = CefDictionaryValue::Create();
|
|
|
|
extra_info->SetBool(kOrderNavTestCmdKey, true);
|
|
|
|
return extra_info;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2012-11-20 21:08:36 +01:00
|
|
|
// Add the resources that we will navigate to/from.
|
|
|
|
AddResource(KONav1, "<html>Nav1</html>", "text/html");
|
|
|
|
AddResource(KONav2, "<html>Nav2</html>", "text/html");
|
|
|
|
|
|
|
|
// Create the browser.
|
2020-01-15 14:34:01 +01:00
|
|
|
CreateBrowser(KONav1, nullptr, GetExtraInfo());
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContinueIfReady(CefRefPtr<CefBrowser> browser) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!got_message_) {
|
2013-09-13 01:36:54 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-13 01:36:54 +02:00
|
|
|
|
|
|
|
bool done = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser->IsPopup()) {
|
2013-09-13 01:36:54 +02:00
|
|
|
done = state_popup_.IsDone();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2013-09-13 01:36:54 +02:00
|
|
|
done = state_main_.IsDone();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!done) {
|
2012-11-20 21:08:36 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
|
|
|
got_message_ = false;
|
|
|
|
|
|
|
|
if (!browser->IsPopup()) {
|
2023-05-25 13:15:06 +02:00
|
|
|
GrantPopupPermission(browser->GetHost()->GetRequestContext(),
|
|
|
|
browser->GetMainFrame()->GetURL());
|
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
// Create the popup window.
|
|
|
|
browser->GetMainFrame()->ExecuteJavaScript(
|
|
|
|
"window.open('" + std::string(KONav2) + "');", CefString(), 0);
|
|
|
|
} else {
|
|
|
|
// Close the popup window.
|
2016-01-19 21:09:01 +01:00
|
|
|
CloseBrowser(browser_popup_, false);
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
bool OnBeforePopup(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& target_url,
|
|
|
|
const CefString& target_frame_name,
|
|
|
|
CefLifeSpanHandler::WindowOpenDisposition target_disposition,
|
|
|
|
bool user_gesture,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefDictionaryValue>& extra_info,
|
|
|
|
bool* no_javascript_access) override {
|
|
|
|
extra_info = GetExtraInfo();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
2012-11-20 21:08:36 +01:00
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
browser_id_popup_ = browser->GetIdentifier();
|
|
|
|
EXPECT_GT(browser_id_popup_, 0);
|
|
|
|
browser_popup_ = browser;
|
|
|
|
} else {
|
|
|
|
browser_id_main_ = browser->GetIdentifier();
|
|
|
|
EXPECT_GT(browser_id_main_, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-12 19:44:54 +02:00
|
|
|
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
EXPECT_EQ(TT_LINK, request->GetTransitionType());
|
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
|
|
|
got_before_browse_popup_.yes();
|
|
|
|
} else {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, request->GetTransitionType());
|
2013-09-12 19:44:54 +02:00
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
|
|
|
got_before_browse_main_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string url = request->GetURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url == KONav1) {
|
2013-09-12 19:44:54 +02:00
|
|
|
EXPECT_FALSE(browser->IsPopup());
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (url == KONav2) {
|
2013-09-12 19:44:54 +02:00
|
|
|
EXPECT_TRUE(browser->IsPopup());
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2013-09-12 19:44:54 +02:00
|
|
|
EXPECT_TRUE(false); // not reached
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-12 19:44:54 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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 {
|
2024-04-27 03:21:18 +02:00
|
|
|
if (request->GetResourceType() == RT_FAVICON) {
|
2020-09-25 03:40:47 +02:00
|
|
|
// Ignore favicon requests.
|
|
|
|
return RV_CANCEL;
|
|
|
|
}
|
|
|
|
|
2013-09-10 21:42:53 +02:00
|
|
|
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
if (browser->IsPopup()) {
|
2013-09-10 21:42:53 +02:00
|
|
|
EXPECT_EQ(TT_LINK, request->GetTransitionType());
|
2012-11-20 21:08:36 +01:00
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
|
|
|
} else {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, request->GetTransitionType());
|
2012-11-20 21:08:36 +01:00
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
return RV_CONTINUE;
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2013-09-13 01:36:54 +02:00
|
|
|
if (browser->IsPopup()) {
|
|
|
|
state_popup_.OnLoadingStateChange(browser, isLoading, canGoBack,
|
|
|
|
canGoForward);
|
|
|
|
} else {
|
|
|
|
state_main_.OnLoadingStateChange(browser, isLoading, canGoBack,
|
|
|
|
canGoForward);
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!isLoading) {
|
2013-09-13 01:36:54 +02:00
|
|
|
ContinueIfReady(browser);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
2016-07-12 17:59:42 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
2012-11-20 21:08:36 +01:00
|
|
|
if (browser->IsPopup()) {
|
2016-07-12 17:59:42 +02:00
|
|
|
EXPECT_EQ(TT_LINK, transition_type);
|
2013-09-13 01:36:54 +02:00
|
|
|
state_popup_.OnLoadStart(browser, frame);
|
2012-11-20 21:08:36 +01:00
|
|
|
} else {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
|
2013-09-13 01:36:54 +02:00
|
|
|
state_main_.OnLoadStart(browser, frame);
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2012-11-20 21:08:36 +01:00
|
|
|
if (browser->IsPopup()) {
|
2013-09-13 01:36:54 +02:00
|
|
|
state_popup_.OnLoadEnd(browser, frame, httpStatusCode);
|
2012-11-20 21:08:36 +01:00
|
|
|
} else {
|
2013-09-13 01:36:54 +02:00
|
|
|
state_main_.OnLoadEnd(browser, frame, httpStatusCode);
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ContinueIfReady(browser);
|
|
|
|
}
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
|
|
|
ADD_FAILURE() << "browser OnLoadError url: " << failedUrl.ToString()
|
|
|
|
<< " error: " << errorCode;
|
|
|
|
}
|
|
|
|
|
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 {
|
2012-11-20 21:08:36 +01:00
|
|
|
if (browser->IsPopup()) {
|
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
|
|
|
} else {
|
|
|
|
EXPECT_GT(browser->GetIdentifier(), 0);
|
|
|
|
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& msg_name = message->GetName();
|
|
|
|
if (msg_name == kOrderNavMsg || msg_name == kOrderNavClosedMsg) {
|
|
|
|
// Test that the renderer side succeeded.
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
EXPECT_TRUE(args->GetBool(0));
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
EXPECT_EQ(browser_id_popup_, args->GetInt(1));
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(browser_id_main_, args->GetInt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg_name == kOrderNavMsg) {
|
|
|
|
// Continue with the test.
|
|
|
|
got_message_ = true;
|
|
|
|
ContinueIfReady(browser);
|
|
|
|
} else {
|
|
|
|
// Popup was closed. End the test.
|
2020-01-15 14:34:01 +01:00
|
|
|
browser_popup_ = nullptr;
|
2012-11-20 21:08:36 +01:00
|
|
|
DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message not handled.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-11-12 20:25:15 +01:00
|
|
|
void DestroyTest() override {
|
2013-09-12 19:44:54 +02:00
|
|
|
// Verify test expectations.
|
|
|
|
EXPECT_TRUE(got_before_browse_main_);
|
|
|
|
EXPECT_TRUE(got_before_browse_popup_);
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
EXPECT_TRUE(state_main_.Verify(true, true, true, true));
|
|
|
|
EXPECT_TRUE(state_popup_.Verify(true, true, true, true));
|
|
|
|
|
2013-09-12 19:44:54 +02:00
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
int browser_id_main_ = 0;
|
|
|
|
int browser_id_popup_ = 0;
|
2012-11-20 21:08:36 +01:00
|
|
|
CefRefPtr<CefBrowser> browser_popup_;
|
|
|
|
|
2013-09-12 19:44:54 +02:00
|
|
|
TrackCallback got_before_browse_main_;
|
|
|
|
TrackCallback got_before_browse_popup_;
|
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
OrderNavLoadState state_main_;
|
|
|
|
OrderNavLoadState state_popup_;
|
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
bool got_message_ = false;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(OrderNavTestHandler);
|
2012-11-20 21:08:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Verify the order of navigation-related callbacks.
|
|
|
|
TEST(NavigationTest, Order) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<OrderNavTestHandler> handler = new OrderNavTestHandler();
|
2012-11-20 21:08:36 +01:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-11-20 21:08:36 +01:00
|
|
|
}
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kLoadNav1[] = "https://tests-conav1.com/nav1.html";
|
|
|
|
const char kLoadNavSameOrigin2[] = "https://tests-conav1.com/nav2.html";
|
|
|
|
const char kLoadNavCrossOrigin2[] = "https://tests-conav2.com/nav2.html";
|
2015-03-09 21:22:31 +01:00
|
|
|
const char kLoadNavMsg[] = "NavigationTest.LoadNav";
|
2019-10-03 16:17:58 +02:00
|
|
|
const char kLoadNavTestCmdKey[] = "nav-load-test";
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2023-12-18 19:26:31 +01:00
|
|
|
bool IsInitialUrl(const CefString& url) {
|
|
|
|
return url == kLoadNav1;
|
|
|
|
}
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
// Renderer side.
|
2015-03-09 21:22:31 +01:00
|
|
|
class LoadNavRendererTest : public ClientAppRenderer::Delegate,
|
|
|
|
public CefLoadHandler {
|
2012-12-30 12:17:49 +01:00
|
|
|
public:
|
2022-04-05 19:22:32 +02:00
|
|
|
LoadNavRendererTest() = default;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
void OnBrowserCreated(CefRefPtr<ClientAppRenderer> app,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info) override {
|
2021-05-14 18:58:55 +02:00
|
|
|
run_test_ = extra_info && extra_info->HasKey(kLoadNavTestCmdKey);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!run_test_) {
|
2012-12-30 12:17:49 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
// We'll get multiple calls to OnBrowserCreated for same-site navigations
|
|
|
|
// with same-site BFCache enabled.
|
|
|
|
const int new_browser_id = browser->GetIdentifier();
|
|
|
|
if (browser_id_ != 0) {
|
|
|
|
EXPECT_EQ(browser_id_, new_browser_id);
|
|
|
|
} else {
|
|
|
|
browser_id_ = new_browser_id;
|
|
|
|
EXPECT_GT(browser_id_, 0);
|
|
|
|
}
|
|
|
|
browser_created_ct_++;
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
void OnBrowserDestroyed(CefRefPtr<ClientAppRenderer> app,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefBrowser> browser) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!run_test_) {
|
2012-12-30 12:17:49 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_GT(load_ct_, 0);
|
|
|
|
EXPECT_GT(browser_created_ct_, 0);
|
2015-03-09 21:22:31 +01:00
|
|
|
EXPECT_EQ(browser_id_, browser->GetIdentifier());
|
2012-12-30 12:17:49 +01: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_) {
|
2020-01-15 14:34:01 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2013-09-13 01:36:54 +02:00
|
|
|
return this;
|
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2013-09-13 01:36:54 +02:00
|
|
|
if (!isLoading) {
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_GT(browser_created_ct_, 0);
|
2015-03-09 21:22:31 +01:00
|
|
|
EXPECT_EQ(browser_id_, browser->GetIdentifier());
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
load_ct_++;
|
2019-05-24 22:23:43 +02:00
|
|
|
SendTestResults(browser, browser->GetMainFrame());
|
2013-09-13 01:36:54 +02:00
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Send the test results.
|
2019-05-24 22:23:43 +02:00
|
|
|
void SendTestResults(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2012-12-30 12:17:49 +01:00
|
|
|
// Check if the test has failed.
|
|
|
|
bool result = !TestFailed();
|
|
|
|
|
|
|
|
// Return the result to the browser process.
|
|
|
|
CefRefPtr<CefProcessMessage> return_msg =
|
2015-03-09 21:22:31 +01:00
|
|
|
CefProcessMessage::Create(kLoadNavMsg);
|
2012-12-30 12:17:49 +01:00
|
|
|
CefRefPtr<CefListValue> args = return_msg->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
EXPECT_TRUE(args->SetBool(0, result));
|
|
|
|
EXPECT_TRUE(args->SetInt(1, browser->GetIdentifier()));
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_TRUE(args->SetInt(2, browser_created_ct_));
|
|
|
|
EXPECT_TRUE(args->SetInt(3, load_ct_));
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_BROWSER, return_msg);
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
bool run_test_ = false;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
int browser_id_ = 0;
|
|
|
|
int load_ct_ = 0;
|
|
|
|
int browser_created_ct_ = 0;
|
2015-03-09 21:22:31 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(LoadNavRendererTest);
|
|
|
|
};
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
// Browser side.
|
|
|
|
class LoadNavTestHandler : public TestHandler {
|
|
|
|
public:
|
|
|
|
enum TestMode {
|
|
|
|
LOAD,
|
|
|
|
LEFT_CLICK,
|
|
|
|
MIDDLE_CLICK,
|
|
|
|
CTRL_LEFT_CLICK,
|
2012-12-30 12:17:49 +01:00
|
|
|
};
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
LoadNavTestHandler(TestMode mode,
|
|
|
|
bool same_origin,
|
|
|
|
bool cancel_in_open_url = false)
|
|
|
|
: mode_(mode),
|
|
|
|
same_origin_(same_origin),
|
2022-04-05 19:22:32 +02:00
|
|
|
cancel_in_open_url_(cancel_in_open_url) {}
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
std::string GetURL2() const {
|
|
|
|
return same_origin_ ? kLoadNavSameOrigin2 : kLoadNavCrossOrigin2;
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
bool ExpectOpenURL() const {
|
|
|
|
return mode_ == MIDDLE_CLICK || mode_ == CTRL_LEFT_CLICK;
|
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2015-03-09 21:22:31 +01:00
|
|
|
const std::string& url2 = GetURL2();
|
|
|
|
std::string link;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (mode_ != LOAD) {
|
2015-03-09 21:22:31 +01:00
|
|
|
link = "<a href=\"" + url2 + "\">CLICK ME</a>";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-03-09 21:22:31 +01:00
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
// Add the resources that we will navigate to/from.
|
2017-05-17 11:29:28 +02:00
|
|
|
AddResource(kLoadNav1,
|
|
|
|
"<html><body><h1>" + link + "Nav1</h1></body></html>",
|
|
|
|
"text/html");
|
2015-03-09 21:22:31 +01:00
|
|
|
AddResource(url2, "<html>Nav2</html>", "text/html");
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info = CefDictionaryValue::Create();
|
|
|
|
extra_info->SetBool(kLoadNavTestCmdKey, true);
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
// Create the browser.
|
2020-01-15 14:34:01 +01:00
|
|
|
CreateBrowser(kLoadNav1, nullptr, extra_info);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContinueIfReady(CefRefPtr<CefBrowser> browser) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!got_message_ || !got_load_end_) {
|
2012-12-30 12:17:49 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2023-12-18 19:26:31 +01:00
|
|
|
if (IsInitialUrl(browser->GetMainFrame()->GetURL())) {
|
2015-03-09 21:22:31 +01:00
|
|
|
// Verify the behavior of the previous load.
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_before_resource_load_);
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_open_url_from_tab_);
|
|
|
|
|
|
|
|
got_before_browse_.reset();
|
|
|
|
got_before_resource_load_.reset();
|
|
|
|
got_load_start_.reset();
|
|
|
|
got_load_end_.reset();
|
|
|
|
got_message_.reset();
|
|
|
|
|
|
|
|
EXPECT_EQ(1, renderer_load_ct_);
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
// Load the next url.
|
2015-03-09 21:22:31 +01:00
|
|
|
if (mode_ == LOAD) {
|
|
|
|
browser->GetMainFrame()->LoadURL(GetURL2());
|
2017-05-17 11:29:28 +02:00
|
|
|
} else {
|
2015-03-09 21:22:31 +01:00
|
|
|
// Navigate to the URL by clicking a link.
|
|
|
|
CefMouseEvent mouse_event;
|
|
|
|
mouse_event.x = 20;
|
|
|
|
mouse_event.y = 20;
|
2020-08-29 00:39:23 +02:00
|
|
|
#if defined(OS_MAC)
|
2015-03-11 19:44:11 +01:00
|
|
|
// Use cmd instead of ctrl on OS X.
|
|
|
|
mouse_event.modifiers =
|
|
|
|
(mode_ == CTRL_LEFT_CLICK ? EVENTFLAG_COMMAND_DOWN : 0);
|
|
|
|
#else
|
2015-03-09 21:22:31 +01:00
|
|
|
mouse_event.modifiers =
|
|
|
|
(mode_ == CTRL_LEFT_CLICK ? EVENTFLAG_CONTROL_DOWN : 0);
|
2015-03-11 19:44:11 +01:00
|
|
|
#endif
|
2015-03-09 21:22:31 +01:00
|
|
|
|
|
|
|
cef_mouse_button_type_t button_type =
|
|
|
|
(mode_ == MIDDLE_CLICK ? MBT_MIDDLE : MBT_LEFT);
|
2023-02-06 22:26:20 +01:00
|
|
|
SendMouseClickEvent(browser, mouse_event, button_type);
|
2015-03-09 21:22:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cancel_in_open_url_) {
|
|
|
|
// The next navigation should not occur. Therefore call DestroyTest()
|
|
|
|
// after a reasonable timeout.
|
2017-05-17 11:29:28 +02:00
|
|
|
CefPostDelayedTask(
|
2021-06-19 21:54:45 +02:00
|
|
|
TID_UI, base::BindOnce(&LoadNavTestHandler::DestroyTest, this),
|
|
|
|
500);
|
2015-03-09 21:22:31 +01:00
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
} else {
|
|
|
|
// Done with the test.
|
|
|
|
DestroyTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
2012-12-30 12:17:49 +01:00
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
|
|
|
|
EXPECT_EQ(browser_id_current_, 0);
|
|
|
|
browser_id_current_ = browser->GetIdentifier();
|
|
|
|
EXPECT_GT(browser_id_current_, 0);
|
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
cef_transition_type_t ExpectedOpenURLTransitionType() const {
|
2024-04-17 18:01:26 +02:00
|
|
|
if (mode_ != LEFT_CLICK && !use_alloy_style_browser()) {
|
2020-09-25 03:40:47 +02:00
|
|
|
// Because we triggered the navigation with LoadURL in OnOpenURLFromTab.
|
|
|
|
return kTransitionExplicitLoad;
|
|
|
|
}
|
|
|
|
return TT_LINK;
|
|
|
|
}
|
|
|
|
|
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-12 19:44:54 +02:00
|
|
|
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
2023-12-18 19:26:31 +01:00
|
|
|
if (mode_ == LOAD || IsInitialUrl(request->GetURL())) {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, request->GetTransitionType());
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!use_alloy_style_browser()) {
|
2024-06-26 02:12:37 +02:00
|
|
|
// With Chrome style this is true on initial navigation via
|
2023-12-18 19:26:31 +01:00
|
|
|
// chrome::AddTabAt()
|
|
|
|
EXPECT_EQ(user_gesture, IsInitialUrl(request->GetURL()));
|
2021-04-03 00:07:43 +02:00
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(user_gesture);
|
|
|
|
}
|
2018-04-27 17:11:53 +02:00
|
|
|
} else {
|
2020-09-25 03:40:47 +02:00
|
|
|
EXPECT_EQ(ExpectedOpenURLTransitionType(), request->GetTransitionType());
|
2023-12-18 19:26:31 +01:00
|
|
|
EXPECT_EQ(user_gesture, mode_ == LEFT_CLICK);
|
2018-04-27 17:11:53 +02:00
|
|
|
}
|
|
|
|
|
2013-09-12 19:44:54 +02:00
|
|
|
EXPECT_GT(browser_id_current_, 0);
|
|
|
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
if (ExpectOpenURL() && request->GetURL() == GetURL2()) {
|
|
|
|
// OnOpenURLFromTab should be called first for the file URL navigation.
|
|
|
|
EXPECT_TRUE(got_open_url_from_tab_);
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(got_open_url_from_tab_);
|
|
|
|
}
|
|
|
|
|
|
|
|
got_before_browse_.yes();
|
|
|
|
|
2013-09-12 19:44:54 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
bool OnOpenURLFromTab(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& target_url,
|
|
|
|
cef_window_open_disposition_t target_disposition,
|
|
|
|
bool user_gesture) override {
|
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
|
|
|
|
|
|
|
|
EXPECT_GT(browser_id_current_, 0);
|
|
|
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
|
|
|
|
|
|
|
// OnOpenURLFromTab should only be called for the file URL.
|
|
|
|
EXPECT_STREQ(GetURL2().c_str(), target_url.ToString().c_str());
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (mode_ == LOAD) {
|
2015-03-09 21:22:31 +01:00
|
|
|
EXPECT_FALSE(user_gesture);
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2015-03-09 21:22:31 +01:00
|
|
|
EXPECT_TRUE(user_gesture);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-03-09 21:22:31 +01:00
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
EXPECT_EQ(CEF_WOD_NEW_BACKGROUND_TAB, target_disposition);
|
2015-03-09 21:22:31 +01:00
|
|
|
|
|
|
|
// OnOpenURLFromTab should be called before OnBeforeBrowse for the file URL.
|
|
|
|
EXPECT_FALSE(got_before_browse_);
|
|
|
|
|
|
|
|
got_open_url_from_tab_.yes();
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!cancel_in_open_url_ && !use_alloy_style_browser()) {
|
2024-06-26 02:12:37 +02:00
|
|
|
// Chrome style may create a new popup window, which is not the
|
|
|
|
// behavior that this test expects. Instead, match Alloy style
|
2020-09-25 03:40:47 +02:00
|
|
|
// behavior by navigating in the current window.
|
|
|
|
browser->GetMainFrame()->LoadURL(target_url);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
return cancel_in_open_url_;
|
|
|
|
}
|
|
|
|
|
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 {
|
2024-04-27 03:21:18 +02:00
|
|
|
if (request->GetResourceType() == RT_FAVICON) {
|
2020-09-25 03:40:47 +02:00
|
|
|
// Ignore favicon requests.
|
|
|
|
return RV_CANCEL;
|
|
|
|
}
|
|
|
|
|
2013-09-10 21:42:53 +02:00
|
|
|
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
|
2020-02-14 22:58:58 +01:00
|
|
|
|
|
|
|
const auto transition_type = request->GetTransitionType();
|
2023-12-18 19:26:31 +01:00
|
|
|
if (mode_ == LOAD || IsInitialUrl(request->GetURL())) {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
|
2020-09-25 03:40:47 +02:00
|
|
|
} else {
|
|
|
|
EXPECT_EQ(ExpectedOpenURLTransitionType(), transition_type);
|
|
|
|
}
|
2013-09-10 21:42:53 +02:00
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
EXPECT_GT(browser_id_current_, 0);
|
|
|
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
2015-03-09 21:22:31 +01:00
|
|
|
|
|
|
|
got_before_resource_load_.yes();
|
2015-04-02 17:21:46 +02:00
|
|
|
|
|
|
|
return RV_CONTINUE;
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
2016-07-12 17:59:42 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
2012-12-30 12:17:49 +01:00
|
|
|
EXPECT_GT(browser_id_current_, 0);
|
|
|
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
2015-03-09 21:22:31 +01:00
|
|
|
|
2023-12-18 19:26:31 +01:00
|
|
|
if (mode_ == LOAD || IsInitialUrl(frame->GetURL())) {
|
2020-02-14 22:58:58 +01:00
|
|
|
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
|
2020-09-25 03:40:47 +02:00
|
|
|
} else {
|
|
|
|
EXPECT_EQ(ExpectedOpenURLTransitionType(), transition_type);
|
|
|
|
}
|
2016-07-12 17:59:42 +02:00
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
got_load_start_.yes();
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2012-12-30 12:17:49 +01:00
|
|
|
EXPECT_GT(browser_id_current_, 0);
|
|
|
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
got_load_end_.yes();
|
2012-12-30 12:17:49 +01:00
|
|
|
ContinueIfReady(browser);
|
|
|
|
}
|
|
|
|
|
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 {
|
2012-12-30 12:17:49 +01:00
|
|
|
EXPECT_GT(browser_id_current_, 0);
|
|
|
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
|
|
|
|
|
|
|
const std::string& msg_name = message->GetName();
|
2015-03-09 21:22:31 +01:00
|
|
|
if (msg_name == kLoadNavMsg) {
|
2012-12-30 12:17:49 +01:00
|
|
|
// Test that the renderer side succeeded.
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
EXPECT_TRUE(args->GetBool(0));
|
|
|
|
|
|
|
|
EXPECT_EQ(browser_id_current_, args->GetInt(1));
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
renderer_browser_created_ct_ = args->GetInt(2);
|
|
|
|
EXPECT_GE(renderer_browser_created_ct_, 1);
|
|
|
|
renderer_load_ct_ = args->GetInt(3);
|
2015-03-09 21:22:31 +01:00
|
|
|
EXPECT_GE(renderer_load_ct_, 1);
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
// Continue with the test.
|
2015-03-09 21:22:31 +01:00
|
|
|
got_message_.yes();
|
2012-12-30 12:17:49 +01:00
|
|
|
ContinueIfReady(browser);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message not handled.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
void DestroyTest() override {
|
|
|
|
if (cancel_in_open_url_) {
|
|
|
|
EXPECT_FALSE(got_before_browse_);
|
|
|
|
EXPECT_FALSE(got_before_resource_load_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_message_);
|
|
|
|
|
|
|
|
// We should only navigate a single time if the 2nd load is canceled.
|
|
|
|
EXPECT_EQ(1, renderer_load_ct_);
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_EQ(1, renderer_browser_created_ct_);
|
2015-03-09 21:22:31 +01:00
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_before_resource_load_);
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_load_end_);
|
|
|
|
EXPECT_TRUE(got_message_);
|
|
|
|
|
|
|
|
if (same_origin_) {
|
|
|
|
// The renderer process should always be reused.
|
|
|
|
EXPECT_EQ(2, renderer_load_ct_);
|
2022-04-05 19:22:32 +02:00
|
|
|
if (IsSameSiteBFCacheEnabled()) {
|
|
|
|
// We expect multiple calls to OnBrowserCreated for same-site
|
|
|
|
// navigations with same-site BFCache enabled.
|
|
|
|
EXPECT_EQ(2, renderer_browser_created_ct_);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(1, renderer_browser_created_ct_);
|
|
|
|
}
|
2015-03-09 21:22:31 +01:00
|
|
|
} else {
|
2019-10-03 16:17:58 +02:00
|
|
|
// Each renderer process is only used for a single navigation.
|
|
|
|
EXPECT_EQ(1, renderer_load_ct_);
|
2022-04-05 19:22:32 +02:00
|
|
|
EXPECT_EQ(1, renderer_browser_created_ct_);
|
2015-03-09 21:22:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (ExpectOpenURL()) {
|
2015-03-09 21:22:31 +01:00
|
|
|
EXPECT_TRUE(got_open_url_from_tab_);
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2015-03-09 21:22:31 +01:00
|
|
|
EXPECT_FALSE(got_open_url_from_tab_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-03-09 21:22:31 +01:00
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
protected:
|
2015-03-09 21:22:31 +01:00
|
|
|
const TestMode mode_;
|
|
|
|
const bool same_origin_;
|
|
|
|
const bool cancel_in_open_url_;
|
|
|
|
|
2022-04-05 19:22:32 +02:00
|
|
|
int browser_id_current_ = 0;
|
|
|
|
int renderer_browser_created_ct_ = 0;
|
|
|
|
int renderer_load_ct_ = 0;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
TrackCallback got_before_browse_;
|
|
|
|
TrackCallback got_open_url_from_tab_;
|
|
|
|
TrackCallback got_before_resource_load_;
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_message_;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(LoadNavTestHandler);
|
2012-12-30 12:17:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
// Verify navigation-related callbacks when browsing same-origin via LoadURL().
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadSameOriginLoadURL) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::LOAD, true);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify navigation-related callbacks when browsing same-origin via left-click.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadSameOriginLeftClick) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::LEFT_CLICK, true);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify navigation-related callbacks when browsing same-origin via middle-
|
|
|
|
// click.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadSameOriginMiddleClick) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::MIDDLE_CLICK, true);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but cancel the 2nd navigation in OnOpenURLFromTab.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadSameOriginMiddleClickCancel) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::MIDDLE_CLICK, true, true);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify navigation-related callbacks when browsing same-origin via ctrl+left-
|
|
|
|
// click.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadSameOriginCtrlLeftClick) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::CTRL_LEFT_CLICK, true);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but cancel the 2nd navigation in OnOpenURLFromTab.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadSameOriginCtrlLeftClickCancel) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::CTRL_LEFT_CLICK, true, true);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify navigation-related callbacks when browsing cross-origin via LoadURL().
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadCrossOriginLoadURL) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::LOAD, false);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify navigation-related callbacks when browsing cross-origin via left-
|
|
|
|
// click.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadCrossOriginLeftClick) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::LEFT_CLICK, false);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify navigation-related callbacks when browsing cross-origin via middle-
|
|
|
|
// click.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadCrossOriginMiddleClick) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::MIDDLE_CLICK, false);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but cancel the 2nd navigation in OnOpenURLFromTab.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadCrossOriginMiddleClickCancel) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::MIDDLE_CLICK, false, true);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify navigation-related callbacks when browsing cross-origin via ctrl+left-
|
|
|
|
// click.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadCrossOriginCtrlLeftClick) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::CTRL_LEFT_CLICK, false);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but cancel the 2nd navigation in OnOpenURLFromTab.
|
2019-10-03 16:17:58 +02:00
|
|
|
TEST(NavigationTest, LoadCrossOriginCtrlLeftClickCancel) {
|
2015-03-09 21:22:31 +01:00
|
|
|
CefRefPtr<LoadNavTestHandler> handler =
|
|
|
|
new LoadNavTestHandler(LoadNavTestHandler::CTRL_LEFT_CLICK, false, true);
|
2012-12-30 12:17:49 +01:00
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2012-12-30 12:17:49 +01:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kSimultPopupMainUrl[] = "https://www.tests-sp.com/main.html";
|
|
|
|
const char kSimultPopupPopupUrl[] = "https://www.tests-sp.com/popup";
|
2015-11-17 19:20:13 +01:00
|
|
|
const size_t kSimultPopupCount = 5U;
|
|
|
|
|
|
|
|
// Test multiple popups simultaniously.
|
|
|
|
class PopupSimultaneousTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
explicit PopupSimultaneousTestHandler(bool same_url) : same_url_(same_url) {}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
std::string main_html = "<html><script>\n";
|
|
|
|
for (size_t i = 0; i < kSimultPopupCount; ++i) {
|
|
|
|
if (same_url_) {
|
|
|
|
popup_url_[i] = std::string(kSimultPopupPopupUrl) + ".html";
|
|
|
|
} else {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << kSimultPopupPopupUrl << i << ".html";
|
|
|
|
popup_url_[i] = ss.str();
|
|
|
|
}
|
|
|
|
main_html += "window.open('" + popup_url_[i] + "');\n";
|
|
|
|
AddResource(popup_url_[i], "<html>Popup " + popup_url_[i] + "</html>",
|
|
|
|
"text/html");
|
|
|
|
}
|
|
|
|
main_html += "</script></html>";
|
|
|
|
|
|
|
|
AddResource(kSimultPopupMainUrl, main_html, "text/html");
|
|
|
|
|
|
|
|
// Create the browser.
|
|
|
|
CreateBrowser(kSimultPopupMainUrl);
|
|
|
|
|
|
|
|
// 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,
|
2015-11-17 19:20:13 +01:00
|
|
|
bool* no_javascript_access) override {
|
|
|
|
const std::string& url = target_url;
|
|
|
|
EXPECT_LT(before_popup_ct_, kSimultPopupCount);
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_STREQ(popup_url_[before_popup_ct_].c_str(), url.c_str())
|
|
|
|
<< before_popup_ct_;
|
2015-11-17 19:20:13 +01:00
|
|
|
before_popup_ct_++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
EXPECT_LT(after_created_ct_, kSimultPopupCount);
|
|
|
|
browser_id_[after_created_ct_] = browser->GetIdentifier();
|
|
|
|
after_created_ct_++;
|
2023-05-25 13:15:06 +02:00
|
|
|
} else {
|
|
|
|
GrantPopupPermission(browser->GetHost()->GetRequestContext(),
|
|
|
|
kSimultPopupMainUrl);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (isLoading) {
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
const std::string& url = browser->GetMainFrame()->GetURL();
|
|
|
|
for (size_t i = 0; i < kSimultPopupCount; ++i) {
|
|
|
|
if (browser->GetIdentifier() == browser_id_[i]) {
|
|
|
|
EXPECT_STREQ(popup_url_[i].c_str(), url.c_str()) << i;
|
|
|
|
|
|
|
|
got_loading_state_change_[i].yes();
|
2016-01-19 21:09:01 +01:00
|
|
|
CloseBrowser(browser, true);
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPECT_FALSE(true); // Not reached.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnBeforeClose(CefRefPtr<CefBrowser> browser) override {
|
|
|
|
TestHandler::OnBeforeClose(browser);
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
const std::string& url = browser->GetMainFrame()->GetURL();
|
|
|
|
for (size_t i = 0; i < kSimultPopupCount; ++i) {
|
|
|
|
if (browser->GetIdentifier() == browser_id_[i]) {
|
2020-09-25 03:40:47 +02:00
|
|
|
EXPECT_TRUE(got_loading_state_change_[i]);
|
2015-11-17 19:20:13 +01:00
|
|
|
EXPECT_STREQ(popup_url_[i].c_str(), url.c_str()) << i;
|
|
|
|
|
|
|
|
got_before_close_[i].yes();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (++before_close_ct_ == kSimultPopupCount) {
|
2015-11-17 19:20:13 +01:00
|
|
|
DestroyTest();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPECT_FALSE(true); // Not reached.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DestroyTest() override {
|
|
|
|
EXPECT_EQ(kSimultPopupCount, before_popup_ct_);
|
|
|
|
EXPECT_EQ(kSimultPopupCount, after_created_ct_);
|
|
|
|
EXPECT_EQ(kSimultPopupCount, before_close_ct_);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < kSimultPopupCount; ++i) {
|
|
|
|
EXPECT_GT(browser_id_[i], 0) << i;
|
|
|
|
EXPECT_TRUE(got_loading_state_change_[i]) << i;
|
|
|
|
EXPECT_TRUE(got_before_close_[i]) << i;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool same_url_;
|
|
|
|
std::string popup_url_[kSimultPopupCount];
|
2024-01-20 18:00:09 +01:00
|
|
|
size_t before_popup_ct_ = 0U;
|
2015-11-17 19:20:13 +01:00
|
|
|
int browser_id_[kSimultPopupCount];
|
2024-01-20 18:00:09 +01:00
|
|
|
size_t after_created_ct_ = 0U;
|
2015-11-17 19:20:13 +01:00
|
|
|
TrackCallback got_loading_state_change_[kSimultPopupCount];
|
|
|
|
TrackCallback got_before_close_[kSimultPopupCount];
|
2024-01-20 18:00:09 +01:00
|
|
|
size_t before_close_ct_ = 0U;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(PopupSimultaneousTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test simultaneous popups with different URLs.
|
|
|
|
TEST(NavigationTest, PopupSimultaneousDifferentUrl) {
|
|
|
|
CefRefPtr<PopupSimultaneousTestHandler> handler =
|
|
|
|
new PopupSimultaneousTestHandler(false);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test simultaneous popups with the same URL.
|
|
|
|
TEST(NavigationTest, PopupSimultaneousSameUrl) {
|
|
|
|
CefRefPtr<PopupSimultaneousTestHandler> handler =
|
|
|
|
new PopupSimultaneousTestHandler(true);
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kPopupJSOpenMainUrl[] = "https://www.tests-pjso.com/main.html";
|
|
|
|
const char kPopupJSOpenPopupUrl[] = "https://www.tests-pjso.com/popup.html";
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// Test a popup where the URL is a JavaScript URI that opens another popup.
|
|
|
|
class PopupJSWindowOpenTestHandler : public TestHandler {
|
|
|
|
public:
|
2023-05-25 13:15:06 +02:00
|
|
|
PopupJSWindowOpenTestHandler(TestRequestContextMode mode,
|
|
|
|
const std::string& cache_path)
|
|
|
|
: mode_(mode), cache_path_(cache_path) {}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
AddResource(kPopupJSOpenMainUrl, "<html>Main</html>", "text/html");
|
|
|
|
AddResource(kPopupJSOpenPopupUrl, "<html>Popup</html>", "text/html");
|
|
|
|
|
2023-05-25 13:15:06 +02:00
|
|
|
// Create a new disk-based request context so that we can grant default
|
|
|
|
// popup permission (used for the popup without a valid URL) without
|
|
|
|
// impacting the global context.
|
2023-10-11 21:18:35 +02:00
|
|
|
CreateTestRequestContext(
|
|
|
|
mode_, cache_path_,
|
|
|
|
base::BindOnce(&PopupJSWindowOpenTestHandler::RunTestContinue, this));
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunTestContinue(CefRefPtr<CefRequestContext> request_context) {
|
|
|
|
EXPECT_UI_THREAD();
|
|
|
|
|
2023-05-25 13:15:06 +02:00
|
|
|
GrantPopupPermission(request_context, CefString());
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Create the browser.
|
2023-05-25 13:15:06 +02:00
|
|
|
CreateBrowser(kPopupJSOpenMainUrl, request_context);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2015-11-17 19:20:13 +01:00
|
|
|
bool* no_javascript_access) override {
|
|
|
|
before_popup_ct_++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
if (browser->IsPopup()) {
|
2015-11-17 19:20:13 +01:00
|
|
|
after_created_ct_++;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!popup1_) {
|
2017-11-29 00:00:50 +01:00
|
|
|
popup1_ = browser;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (!popup2_) {
|
2017-11-29 00:00:50 +01:00
|
|
|
popup2_ = browser;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2017-11-29 00:00:50 +01:00
|
|
|
ADD_FAILURE();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-11-29 00:00:50 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (isLoading) {
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
const std::string& url = browser->GetMainFrame()->GetURL();
|
2017-11-29 00:00:50 +01:00
|
|
|
if (url == kPopupJSOpenPopupUrl) {
|
|
|
|
EXPECT_TRUE(browser->IsSame(popup2_));
|
|
|
|
popup2_ = nullptr;
|
|
|
|
|
2018-02-13 00:01:43 +01:00
|
|
|
// OnLoadingStateChange is not currently called for browser-side
|
|
|
|
// navigations of empty popups. See https://crbug.com/789252.
|
|
|
|
// Explicitly close the empty popup here as a workaround.
|
|
|
|
CloseBrowser(popup1_, true);
|
|
|
|
popup1_ = nullptr;
|
2017-11-29 00:00:50 +01:00
|
|
|
} else {
|
|
|
|
// Empty popup.
|
2015-11-17 19:20:13 +01:00
|
|
|
EXPECT_TRUE(url.empty());
|
2017-11-29 00:00:50 +01:00
|
|
|
EXPECT_TRUE(browser->IsSame(popup1_));
|
|
|
|
popup1_ = nullptr;
|
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
load_end_ct_++;
|
2016-01-19 21:09:01 +01:00
|
|
|
CloseBrowser(browser, true);
|
2015-11-17 19:20:13 +01:00
|
|
|
} else if (browser->GetMainFrame()->GetURL() == kPopupJSOpenMainUrl) {
|
2023-05-25 13:15:06 +02:00
|
|
|
// For the popup that has a valid URL.
|
|
|
|
GrantPopupPermission(browser->GetHost()->GetRequestContext(),
|
|
|
|
kPopupJSOpenMainUrl);
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Load the problematic JS URI.
|
|
|
|
// This will result in 2 popups being created:
|
|
|
|
// - An empty popup
|
|
|
|
// - A popup that loads kPopupJSOpenPopupUrl
|
|
|
|
browser->GetMainFrame()->LoadURL(
|
|
|
|
"javascript:window.open(\"javascript:window.open('" +
|
|
|
|
std::string(kPopupJSOpenPopupUrl) + "')\")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
|
|
|
ADD_FAILURE() << "OnLoadError url: " << failedUrl.ToString()
|
|
|
|
<< " error: " << errorCode;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void OnBeforeClose(CefRefPtr<CefBrowser> browser) override {
|
|
|
|
TestHandler::OnBeforeClose(browser);
|
|
|
|
|
|
|
|
before_close_ct_++;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (before_close_ct_ == 2U) {
|
2015-11-17 19:20:13 +01:00
|
|
|
DestroyTest();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DestroyTest() override {
|
|
|
|
EXPECT_EQ(2U, before_popup_ct_);
|
|
|
|
EXPECT_EQ(2U, after_created_ct_);
|
|
|
|
EXPECT_EQ(2U, before_close_ct_);
|
|
|
|
|
2018-02-13 00:01:43 +01:00
|
|
|
// OnLoadingStateChange is not currently called for browser-side
|
|
|
|
// navigations of empty popups. See https://crbug.com/789252.
|
|
|
|
EXPECT_EQ(1U, load_end_ct_);
|
2017-11-29 00:00:50 +01:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
2023-05-25 13:15:06 +02:00
|
|
|
const TestRequestContextMode mode_;
|
|
|
|
const std::string cache_path_;
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
CefRefPtr<CefBrowser> popup1_;
|
|
|
|
CefRefPtr<CefBrowser> popup2_;
|
|
|
|
|
2023-05-25 13:15:06 +02:00
|
|
|
size_t before_popup_ct_ = 0U;
|
|
|
|
size_t after_created_ct_ = 0U;
|
|
|
|
size_t load_end_ct_ = 0U;
|
|
|
|
size_t before_close_ct_ = 0U;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(PopupJSWindowOpenTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test a popup where the URL is a JavaScript URI that opens another popup.
|
2023-05-25 13:15:06 +02:00
|
|
|
RC_TEST_SINGLE(NavigationTest,
|
|
|
|
PopupJSWindowOpen,
|
|
|
|
PopupJSWindowOpenTestHandler,
|
2023-10-11 21:18:35 +02:00
|
|
|
TEST_RC_MODE_CUSTOM_WITH_HANDLER,
|
2023-05-25 13:15:06 +02:00
|
|
|
/*with_cache_path*/ true)
|
2013-02-08 01:07:41 +01:00
|
|
|
|
2013-09-12 19:44:54 +02:00
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kPopupJSEmptyMainUrl[] = "https://www.tests-pjse.com/main.html";
|
2017-12-21 20:57:42 +01:00
|
|
|
|
|
|
|
// Test creation of a popup where the URL is empty.
|
|
|
|
class PopupJSWindowEmptyTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
PopupJSWindowEmptyTestHandler() = default;
|
2017-12-21 20:57:42 +01:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
AddResource(kPopupJSEmptyMainUrl, "<html>Main</html>", "text/html");
|
|
|
|
|
|
|
|
// Create the browser.
|
|
|
|
CreateBrowser(kPopupJSEmptyMainUrl);
|
|
|
|
|
|
|
|
// 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-12-21 20:57:42 +01:00
|
|
|
bool* no_javascript_access) override {
|
|
|
|
got_before_popup_.yes();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
got_after_created_popup_.yes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (isLoading) {
|
2017-12-21 20:57:42 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-12-21 20:57:42 +01:00
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
got_load_end_popup_.yes();
|
|
|
|
CloseBrowser(browser, true);
|
|
|
|
} else {
|
2023-05-25 13:15:06 +02:00
|
|
|
GrantPopupPermission(browser->GetHost()->GetRequestContext(),
|
|
|
|
browser->GetMainFrame()->GetURL());
|
|
|
|
|
2017-12-21 20:57:42 +01:00
|
|
|
browser->GetMainFrame()->LoadURL("javascript:window.open('')");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
|
|
|
ADD_FAILURE() << "OnLoadError url: " << failedUrl.ToString()
|
|
|
|
<< " error: " << errorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnBeforeClose(CefRefPtr<CefBrowser> browser) override {
|
|
|
|
TestHandler::OnBeforeClose(browser);
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
got_before_close_popup_.yes();
|
|
|
|
DestroyTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DestroyTest() override {
|
|
|
|
EXPECT_TRUE(got_before_popup_);
|
|
|
|
EXPECT_TRUE(got_after_created_popup_);
|
|
|
|
EXPECT_TRUE(got_load_end_popup_);
|
|
|
|
EXPECT_TRUE(got_before_close_popup_);
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackCallback got_before_popup_;
|
|
|
|
TrackCallback got_after_created_popup_;
|
|
|
|
TrackCallback got_load_end_popup_;
|
|
|
|
TrackCallback got_before_close_popup_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(PopupJSWindowEmptyTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test creation of a popup where the URL is empty.
|
|
|
|
TEST(NavigationTest, PopupJSWindowEmpty) {
|
|
|
|
CefRefPtr<PopupJSWindowEmptyTestHandler> handler =
|
|
|
|
new PopupJSWindowEmptyTestHandler();
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kBrowseNavPageUrl[] = "https://tests-browsenav/nav.html";
|
2013-09-12 19:44:54 +02:00
|
|
|
|
|
|
|
// Browser side.
|
|
|
|
class BrowseNavTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
explicit BrowseNavTestHandler(bool allow) : allow_(allow) {}
|
2013-09-12 19:44:54 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2015-01-10 00:40:26 +01:00
|
|
|
AddResource(kBrowseNavPageUrl, "<html>Test</html>", "text/html");
|
2013-09-12 19:44:54 +02:00
|
|
|
|
|
|
|
// Create the browser.
|
|
|
|
CreateBrowser(kBrowseNavPageUrl);
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
2015-01-10 00:40:26 +01:00
|
|
|
SetTestTimeout();
|
2013-09-12 19:44:54 +02:00
|
|
|
}
|
|
|
|
|
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-12 19:44:54 +02:00
|
|
|
const std::string& url = request->GetURL();
|
|
|
|
EXPECT_STREQ(kBrowseNavPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-09-12 19:44:54 +02:00
|
|
|
got_before_browse_.yes();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2013-09-12 19:44:54 +02:00
|
|
|
return !allow_;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
2016-07-12 17:59:42 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
2013-09-12 19:44:54 +02:00
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
EXPECT_STREQ(kBrowseNavPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_load_start_.yes();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2013-09-12 19:44:54 +02:00
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
EXPECT_STREQ(kBrowseNavPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_load_end_.yes();
|
|
|
|
DestroyTestIfDone();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
2013-09-12 19:44:54 +02:00
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
EXPECT_STREQ("", url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
EXPECT_EQ(ERR_ABORTED, errorCode);
|
|
|
|
EXPECT_STREQ(kBrowseNavPageUrl, failedUrl.ToString().c_str());
|
|
|
|
|
|
|
|
got_load_error_.yes();
|
|
|
|
DestroyTestIfDone();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2013-09-12 19:44:54 +02:00
|
|
|
const std::string& url = browser->GetMainFrame()->GetURL();
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
EXPECT_STREQ("", url.c_str());
|
|
|
|
|
|
|
|
got_loading_state_changed_start_.yes();
|
|
|
|
} else {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (allow_) {
|
2013-09-12 19:44:54 +02:00
|
|
|
EXPECT_STREQ(kBrowseNavPageUrl, url.c_str());
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2013-09-12 19:44:54 +02:00
|
|
|
EXPECT_STREQ("", url.c_str());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-12 19:44:54 +02:00
|
|
|
|
|
|
|
got_loading_state_changed_end_.yes();
|
|
|
|
DestroyTestIfDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DestroyTestIfDone() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (destroyed_) {
|
2013-09-12 19:44:54 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-12 19:44:54 +02:00
|
|
|
|
|
|
|
if (got_loading_state_changed_end_) {
|
|
|
|
if (allow_) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (got_load_end_) {
|
2013-09-12 19:44:54 +02:00
|
|
|
DestroyTest();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-12 19:44:54 +02:00
|
|
|
} else if (got_load_error_) {
|
|
|
|
DestroyTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void DestroyTest() override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (destroyed_) {
|
2013-09-12 19:44:54 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-12 19:44:54 +02:00
|
|
|
destroyed_ = true;
|
|
|
|
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
if (allow_) {
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_TRUE(got_load_error_);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool allow_;
|
2024-01-20 18:00:09 +01:00
|
|
|
bool destroyed_ = false;
|
2013-09-12 19:44:54 +02:00
|
|
|
|
|
|
|
TrackCallback got_before_browse_;
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_load_error_;
|
|
|
|
TrackCallback got_loading_state_changed_start_;
|
|
|
|
TrackCallback got_loading_state_changed_end_;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(BrowseNavTestHandler);
|
2013-09-12 19:44:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test allowing navigation.
|
|
|
|
TEST(NavigationTest, BrowseAllow) {
|
|
|
|
CefRefPtr<BrowseNavTestHandler> handler = new BrowseNavTestHandler(true);
|
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-09-12 19:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test denying navigation.
|
|
|
|
TEST(NavigationTest, BrowseDeny) {
|
|
|
|
CefRefPtr<BrowseNavTestHandler> handler = new BrowseNavTestHandler(false);
|
|
|
|
handler->ExecuteTest();
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler);
|
2013-09-12 19:44:54 +02:00
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kSameNavPageUrl[] = "https://tests-samenav/nav.html";
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
// Browser side.
|
|
|
|
class SameNavTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
SameNavTestHandler() = default;
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
AddResource(kSameNavPageUrl, "<html>Test</html>", "text/html");
|
|
|
|
|
|
|
|
// Create the browser.
|
|
|
|
expected_url_ = kSameNavPageUrl;
|
|
|
|
CreateBrowser(kSameNavPageUrl);
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2018-04-27 17:11:53 +02:00
|
|
|
bool user_gesture,
|
2017-03-03 23:37:23 +01:00
|
|
|
bool is_redirect) override {
|
|
|
|
const std::string& url = request->GetURL();
|
|
|
|
EXPECT_STREQ(expected_url_.c_str(), url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
got_before_browse_.yes();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
EXPECT_STREQ(expected_url_.c_str(), url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_load_start_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
EXPECT_STREQ(expected_url_.c_str(), url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_load_end_.yes();
|
|
|
|
ContinueTestIfDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
|
|
|
got_load_error_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
|
|
|
const std::string& url = browser->GetMainFrame()->GetURL();
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
// Verify the previous URL.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (step_ == 0) {
|
2017-03-03 23:37:23 +01:00
|
|
|
EXPECT_TRUE(url.empty());
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2017-03-03 23:37:23 +01:00
|
|
|
EXPECT_STREQ(kSameNavPageUrl, url.c_str());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
got_loading_state_changed_start_.yes();
|
|
|
|
} else {
|
|
|
|
EXPECT_STREQ(expected_url_.c_str(), url.c_str());
|
|
|
|
|
|
|
|
got_loading_state_changed_end_.yes();
|
|
|
|
ContinueTestIfDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ContinueTestIfDone() {
|
|
|
|
if (step_ == 0) {
|
|
|
|
// First navigation should trigger all callbacks except OnLoadError.
|
|
|
|
if (got_loading_state_changed_end_ && got_load_end_) {
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
|
|
|
|
got_before_browse_.reset();
|
|
|
|
got_loading_state_changed_start_.reset();
|
|
|
|
got_loading_state_changed_end_.reset();
|
|
|
|
got_load_start_.reset();
|
|
|
|
got_load_end_.reset();
|
|
|
|
|
|
|
|
step_++;
|
|
|
|
expected_url_ = kSameNavPageUrl + std::string("#fragment");
|
|
|
|
GetBrowser()->GetMainFrame()->LoadURL(expected_url_);
|
|
|
|
}
|
|
|
|
} else if (step_ == 1) {
|
|
|
|
step_++;
|
|
|
|
DestroyTest();
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(false); // Not reached.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyTest() override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (destroyed_) {
|
2017-03-03 23:37:23 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-03-03 23:37:23 +01:00
|
|
|
destroyed_ = true;
|
|
|
|
|
|
|
|
EXPECT_EQ(2, step_);
|
|
|
|
|
|
|
|
// Second (fragment) navigation should only trigger OnLoadingStateChange.
|
|
|
|
EXPECT_FALSE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_end_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
bool destroyed_ = false;
|
|
|
|
int step_ = 0;
|
2017-03-03 23:37:23 +01:00
|
|
|
std::string expected_url_;
|
|
|
|
|
|
|
|
TrackCallback got_before_browse_;
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_load_error_;
|
|
|
|
TrackCallback got_loading_state_changed_start_;
|
|
|
|
TrackCallback got_loading_state_changed_end_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(SameNavTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that same page navigation does not call OnLoadStart/OnLoadEnd.
|
|
|
|
TEST(NavigationTest, SamePage) {
|
|
|
|
CefRefPtr<SameNavTestHandler> handler = new SameNavTestHandler();
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kCancelPageUrl[] = "https://tests-cancelnav/nav.html";
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
// A scheme handler that never starts sending data.
|
|
|
|
class UnstartedSchemeHandler : public CefResourceHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
UnstartedSchemeHandler() = default;
|
2017-03-03 23:37:23 +01:00
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
bool Open(CefRefPtr<CefRequest> request,
|
|
|
|
bool& handle_request,
|
|
|
|
CefRefPtr<CefCallback> callback) override {
|
|
|
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
// Continue immediately.
|
|
|
|
handle_request = true;
|
2017-03-03 23:37:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t& response_length,
|
2017-03-03 23:37:23 +01:00
|
|
|
CefString& redirectUrl) override {
|
|
|
|
response->SetStatus(200);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response_length = 100;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void Cancel() override { callback_ = nullptr; }
|
2017-03-03 23:37:23 +01:00
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
bool Read(void* data_out,
|
|
|
|
int bytes_to_read,
|
|
|
|
int& bytes_read,
|
|
|
|
CefRefPtr<CefResourceReadCallback> callback) override {
|
|
|
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO));
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
callback_ = callback;
|
|
|
|
|
|
|
|
// Pretend that we'll provide the data later.
|
|
|
|
bytes_read = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-12-31 13:24:10 +01:00
|
|
|
CefRefPtr<CefResourceReadCallback> callback_;
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(UnstartedSchemeHandler);
|
2019-12-31 13:24:10 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(UnstartedSchemeHandler);
|
2017-03-03 23:37:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Browser side.
|
|
|
|
class CancelBeforeNavTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
CancelBeforeNavTestHandler() = default;
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
// Create the browser.
|
|
|
|
CreateBrowser(kCancelPageUrl);
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2018-04-27 17:11:53 +02:00
|
|
|
bool user_gesture,
|
2017-03-03 23:37:23 +01:00
|
|
|
bool is_redirect) override {
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_FALSE(got_before_browse_);
|
|
|
|
EXPECT_FALSE(got_get_resource_handler_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_cancel_load_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
|
|
|
EXPECT_STREQ(kCancelPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_before_browse_.yes();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefResourceHandler> GetResourceHandler(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request) override {
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_FALSE(got_get_resource_handler_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_cancel_load_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
|
|
|
EXPECT_STREQ(kCancelPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_get_resource_handler_.yes();
|
|
|
|
|
2019-04-16 16:38:48 +02:00
|
|
|
CefPostTask(TID_UI,
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&CancelBeforeNavTestHandler::CancelLoad, this));
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
return new UnstartedSchemeHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
|
|
|
EXPECT_TRUE(false); // Not reached.
|
|
|
|
got_load_start_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
|
|
|
EXPECT_TRUE(false); // Not reached.
|
|
|
|
got_load_end_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
2019-04-16 16:38:48 +02:00
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_STREQ("", frame->GetURL().ToString().c_str());
|
|
|
|
EXPECT_EQ(ERR_ABORTED, errorCode);
|
|
|
|
EXPECT_STREQ(kCancelPageUrl, failedUrl.ToString().c_str());
|
2017-03-03 23:37:23 +01:00
|
|
|
got_load_error_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
|
|
|
const std::string& url = browser->GetMainFrame()->GetURL();
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(url.empty());
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_FALSE(got_before_browse_);
|
|
|
|
EXPECT_FALSE(got_get_resource_handler_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_cancel_load_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
got_loading_state_changed_start_.yes();
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_get_resource_handler_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_cancel_load_);
|
2019-04-16 16:38:48 +02:00
|
|
|
EXPECT_TRUE(got_load_error_);
|
2017-03-03 23:37:23 +01:00
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
got_loading_state_changed_end_.yes();
|
|
|
|
|
|
|
|
DestroyTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void CancelLoad() {
|
|
|
|
got_cancel_load_.yes();
|
|
|
|
GetBrowser()->StopLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyTest() override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (destroyed_) {
|
2017-03-03 23:37:23 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-03-03 23:37:23 +01:00
|
|
|
destroyed_ = true;
|
|
|
|
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_get_resource_handler_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_cancel_load_);
|
2019-04-16 16:38:48 +02:00
|
|
|
EXPECT_TRUE(got_load_error_);
|
2017-03-03 23:37:23 +01:00
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
bool destroyed_ = false;
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
TrackCallback got_loading_state_changed_start_;
|
|
|
|
TrackCallback got_before_browse_;
|
|
|
|
TrackCallback got_get_resource_handler_;
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_cancel_load_;
|
|
|
|
TrackCallback got_load_error_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_loading_state_changed_end_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CancelBeforeNavTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that navigation canceled before commit does not call
|
|
|
|
// OnLoadStart/OnLoadEnd.
|
|
|
|
TEST(NavigationTest, CancelBeforeCommit) {
|
|
|
|
CefRefPtr<CancelBeforeNavTestHandler> handler =
|
|
|
|
new CancelBeforeNavTestHandler();
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// A scheme handler that stalls after writing some data.
|
|
|
|
class StalledSchemeHandler : public CefResourceHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
StalledSchemeHandler() = default;
|
2017-03-03 23:37:23 +01:00
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
bool Open(CefRefPtr<CefRequest> request,
|
|
|
|
bool& handle_request,
|
|
|
|
CefRefPtr<CefCallback> callback) override {
|
|
|
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
// Continue immediately.
|
|
|
|
handle_request = true;
|
2017-03-03 23:37:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t& response_length,
|
2017-03-03 23:37:23 +01:00
|
|
|
CefString& redirectUrl) override {
|
|
|
|
response->SetStatus(200);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
content_ = "<html><body>Test</body></html>";
|
|
|
|
// Write this number of bytes and then stall.
|
|
|
|
write_size_ = content_.size() / 2U;
|
|
|
|
response_length = content_.size();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void Cancel() override { callback_ = nullptr; }
|
2017-03-03 23:37:23 +01:00
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
bool Read(void* data_out,
|
|
|
|
int bytes_to_read,
|
|
|
|
int& bytes_read,
|
|
|
|
CefRefPtr<CefResourceReadCallback> callback) override {
|
|
|
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
bytes_read = 0;
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
size_t size = content_.size();
|
|
|
|
if (offset_ >= write_size_) {
|
|
|
|
// Now stall.
|
|
|
|
callback_ = callback;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
bool has_data = false;
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
if (offset_ < size) {
|
|
|
|
// Write up to |write_size_| bytes.
|
|
|
|
int transfer_size =
|
|
|
|
std::min(bytes_to_read, std::min(static_cast<int>(write_size_),
|
|
|
|
static_cast<int>(size - offset_)));
|
|
|
|
memcpy(data_out, content_.c_str() + offset_, transfer_size);
|
|
|
|
offset_ += transfer_size;
|
|
|
|
|
|
|
|
bytes_read = transfer_size;
|
2019-12-31 13:24:10 +01:00
|
|
|
has_data = true;
|
2017-03-03 23:37:23 +01:00
|
|
|
}
|
|
|
|
|
2019-12-31 13:24:10 +01:00
|
|
|
return has_data;
|
2017-03-03 23:37:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string content_;
|
2024-01-20 18:00:09 +01:00
|
|
|
size_t offset_ = 0;
|
|
|
|
size_t write_size_ = 0;
|
2019-12-31 13:24:10 +01:00
|
|
|
CefRefPtr<CefResourceReadCallback> callback_;
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(StalledSchemeHandler);
|
2019-12-31 13:24:10 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(StalledSchemeHandler);
|
2017-03-03 23:37:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Browser side.
|
|
|
|
class CancelAfterNavTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
CancelAfterNavTestHandler() = default;
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
// Create the browser.
|
|
|
|
CreateBrowser(kCancelPageUrl);
|
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2018-04-27 17:11:53 +02:00
|
|
|
bool user_gesture,
|
2017-03-03 23:37:23 +01:00
|
|
|
bool is_redirect) override {
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_FALSE(got_before_browse_);
|
|
|
|
EXPECT_FALSE(got_get_resource_handler_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_cancel_load_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
|
|
|
EXPECT_STREQ(kCancelPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_before_browse_.yes();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefResourceHandler> GetResourceHandler(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request) override {
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_FALSE(got_get_resource_handler_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_cancel_load_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
|
|
|
EXPECT_STREQ(kCancelPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_get_resource_handler_.yes();
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
// The required delay is longer when browser-side navigation is enabled.
|
2018-02-13 00:13:23 +01:00
|
|
|
CefPostDelayedTask(
|
2021-06-19 21:54:45 +02:00
|
|
|
TID_UI, base::BindOnce(&CancelAfterNavTestHandler::CancelLoad, this),
|
|
|
|
1000);
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
return new StalledSchemeHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
TransitionType transition_type) override {
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_get_resource_handler_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_cancel_load_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
EXPECT_STREQ(kCancelPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_load_start_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_get_resource_handler_);
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_cancel_load_);
|
|
|
|
EXPECT_TRUE(got_load_error_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
EXPECT_STREQ(kCancelPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_load_end_.yes();
|
|
|
|
DestroyTestIfDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) override {
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_get_resource_handler_);
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_cancel_load_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
const std::string& url = failedUrl;
|
|
|
|
EXPECT_STREQ(kCancelPageUrl, url.c_str());
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
EXPECT_TRUE(frame->IsMain());
|
|
|
|
|
|
|
|
got_load_error_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
|
|
|
const std::string& url = browser->GetMainFrame()->GetURL();
|
|
|
|
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_FALSE(got_before_browse_);
|
|
|
|
EXPECT_FALSE(got_get_resource_handler_);
|
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
EXPECT_FALSE(got_cancel_load_);
|
|
|
|
EXPECT_FALSE(got_load_error_);
|
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
EXPECT_TRUE(url.empty());
|
|
|
|
|
|
|
|
got_loading_state_changed_start_.yes();
|
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_get_resource_handler_);
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_cancel_load_);
|
|
|
|
EXPECT_TRUE(got_load_error_);
|
|
|
|
EXPECT_TRUE(got_load_end_);
|
|
|
|
EXPECT_FALSE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
EXPECT_STREQ(kCancelPageUrl, url.c_str());
|
|
|
|
|
|
|
|
got_loading_state_changed_end_.yes();
|
|
|
|
DestroyTestIfDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void CancelLoad() {
|
|
|
|
got_cancel_load_.yes();
|
|
|
|
GetBrowser()->StopLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyTestIfDone() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (got_loading_state_changed_end_ && got_load_end_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
DestroyTest();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-03-03 23:37:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyTest() override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (destroyed_) {
|
2017-03-03 23:37:23 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-03-03 23:37:23 +01:00
|
|
|
destroyed_ = true;
|
|
|
|
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_start_);
|
|
|
|
EXPECT_TRUE(got_before_browse_);
|
|
|
|
EXPECT_TRUE(got_get_resource_handler_);
|
|
|
|
EXPECT_TRUE(got_load_start_);
|
|
|
|
EXPECT_TRUE(got_cancel_load_);
|
|
|
|
EXPECT_TRUE(got_load_error_);
|
|
|
|
EXPECT_TRUE(got_load_end_);
|
|
|
|
EXPECT_TRUE(got_loading_state_changed_end_);
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
bool destroyed_ = false;
|
2017-03-03 23:37:23 +01:00
|
|
|
|
|
|
|
TrackCallback got_loading_state_changed_start_;
|
|
|
|
TrackCallback got_before_browse_;
|
|
|
|
TrackCallback got_get_resource_handler_;
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_cancel_load_;
|
|
|
|
TrackCallback got_load_error_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_loading_state_changed_end_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CancelAfterNavTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that navigation canceled after commit calls everything.
|
|
|
|
TEST(NavigationTest, CancelAfterCommit) {
|
|
|
|
CefRefPtr<CancelAfterNavTestHandler> handler =
|
|
|
|
new CancelAfterNavTestHandler();
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
2019-03-19 10:42:54 +01:00
|
|
|
namespace {
|
|
|
|
|
2023-04-29 00:17:03 +02:00
|
|
|
const char kExtraInfoUrl[] = "https://tests-extrainfonav.com/extra.html";
|
2019-03-19 10:42:54 +01:00
|
|
|
const char kExtraInfoPopupUrl[] =
|
2023-04-29 00:17:03 +02:00
|
|
|
"https://tests-extrainfonav.com/extra_popup.html";
|
2019-03-19 10:42:54 +01:00
|
|
|
const char kExtraInfoNavMsg[] = "NavigationTest.ExtraInfoNav";
|
2019-10-03 16:17:58 +02:00
|
|
|
const char kExtraInfoTestCmdKey[] = "nav-extra-info-test";
|
2019-03-19 10:42:54 +01:00
|
|
|
|
|
|
|
void SetBrowserExtraInfo(CefRefPtr<CefDictionaryValue> extra_info) {
|
2019-10-03 16:17:58 +02:00
|
|
|
// Necessary for identifying the test case.
|
|
|
|
extra_info->SetBool(kExtraInfoTestCmdKey, true);
|
|
|
|
|
2019-03-19 10:42:54 +01:00
|
|
|
// Arbitrary data for testing.
|
|
|
|
extra_info->SetBool("bool", true);
|
|
|
|
CefRefPtr<CefDictionaryValue> dict = CefDictionaryValue::Create();
|
|
|
|
dict->SetInt("key1", 5);
|
|
|
|
dict->SetString("key2", "test string");
|
|
|
|
extra_info->SetDictionary("dictionary", dict);
|
|
|
|
extra_info->SetDouble("double", 5.43322);
|
|
|
|
extra_info->SetString("string", "some string");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Renderer side
|
|
|
|
class ExtraInfoNavRendererTest : public ClientAppRenderer::Delegate {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
ExtraInfoNavRendererTest() = default;
|
2019-03-19 10:42:54 +01: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(kExtraInfoTestCmdKey);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!run_test_) {
|
2019-03-19 10:42:54 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-03-19 10:42:54 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefDictionaryValue> expected = CefDictionaryValue::Create();
|
|
|
|
SetBrowserExtraInfo(expected);
|
|
|
|
TestDictionaryEqual(expected, extra_info);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
SendTestResults(browser, browser->GetMainFrame());
|
2019-03-19 10:42:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Send the test results.
|
2019-05-24 22:23:43 +02:00
|
|
|
void SendTestResults(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2019-03-19 10:42:54 +01:00
|
|
|
// Check if the test has failed.
|
|
|
|
bool result = !TestFailed();
|
|
|
|
|
|
|
|
CefRefPtr<CefProcessMessage> return_msg =
|
|
|
|
CefProcessMessage::Create(kExtraInfoNavMsg);
|
|
|
|
CefRefPtr<CefListValue> args = return_msg->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
EXPECT_TRUE(args->SetBool(0, result));
|
|
|
|
EXPECT_TRUE(args->SetBool(1, browser->IsPopup()));
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_BROWSER, return_msg);
|
2019-03-19 10:42:54 +01:00
|
|
|
}
|
|
|
|
|
2024-01-20 18:00:09 +01:00
|
|
|
bool run_test_ = false;
|
2019-03-19 10:42:54 +01:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(ExtraInfoNavRendererTest);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ExtraInfoNavTestHandler : public TestHandler {
|
|
|
|
public:
|
2024-01-20 18:00:09 +01:00
|
|
|
ExtraInfoNavTestHandler() = default;
|
2019-03-19 10:42:54 +01:00
|
|
|
|
|
|
|
void RunTest() override {
|
|
|
|
AddResource(kExtraInfoUrl,
|
|
|
|
"<html><head></head><body>ExtraInfo</body></html>",
|
|
|
|
"text/html");
|
|
|
|
AddResource(kExtraInfoPopupUrl, "<html>ExtraInfoPopup</html>", "text/html");
|
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info = CefDictionaryValue::Create();
|
|
|
|
SetBrowserExtraInfo(extra_info);
|
2019-03-19 10:42:54 +01:00
|
|
|
|
|
|
|
// Create the browser.
|
2020-01-15 14:34:01 +01:00
|
|
|
CreateBrowser(kExtraInfoUrl, nullptr, extra_info);
|
2019-03-19 10:42:54 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
|
|
|
if (popup_opened_) {
|
|
|
|
DestroyTest();
|
|
|
|
} else {
|
2023-05-25 13:15:06 +02:00
|
|
|
GrantPopupPermission(browser->GetHost()->GetRequestContext(),
|
|
|
|
browser->GetMainFrame()->GetURL());
|
|
|
|
|
2019-03-19 10:42:54 +01:00
|
|
|
browser->GetMainFrame()->ExecuteJavaScript(
|
|
|
|
"window.open('" + std::string(kExtraInfoPopupUrl) + "');",
|
|
|
|
CefString(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
CefRefPtr<CefDictionaryValue>& extra_info,
|
|
|
|
bool* no_javascript_access) override {
|
|
|
|
const std::string& url = target_url;
|
|
|
|
EXPECT_FALSE(popup_opened_);
|
|
|
|
EXPECT_STREQ(kExtraInfoPopupUrl, url.c_str());
|
|
|
|
|
|
|
|
CefRefPtr<CefDictionaryValue> extra = CefDictionaryValue::Create();
|
|
|
|
SetBrowserExtraInfo(extra);
|
|
|
|
|
|
|
|
extra_info = extra;
|
|
|
|
|
|
|
|
popup_opened_ = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) override {
|
|
|
|
if (message->GetName().ToString() == kExtraInfoNavMsg) {
|
|
|
|
// Test that the renderer side succeeded.
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
EXPECT_TRUE(args->GetBool(0));
|
|
|
|
if (popup_opened_) {
|
|
|
|
EXPECT_TRUE(args->GetBool(1));
|
|
|
|
got_process_message_popup_.yes();
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(args->GetBool(1));
|
|
|
|
got_process_message_main_.yes();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message not handled.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2024-01-20 18:00:09 +01:00
|
|
|
bool popup_opened_ = false;
|
2019-03-19 10:42:54 +01:00
|
|
|
TrackCallback got_process_message_main_;
|
|
|
|
TrackCallback got_process_message_popup_;
|
|
|
|
|
|
|
|
void DestroyTest() override {
|
|
|
|
// Verify test expectations.
|
|
|
|
EXPECT_TRUE(got_process_message_main_);
|
|
|
|
EXPECT_TRUE(got_process_message_popup_);
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(ExtraInfoNavTestHandler);
|
|
|
|
};
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2019-03-19 10:42:54 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(NavigationTest, ExtraInfo) {
|
|
|
|
CefRefPtr<ExtraInfoNavTestHandler> handler = new ExtraInfoNavTestHandler();
|
|
|
|
handler->ExecuteTest();
|
|
|
|
ReleaseAndWaitForDestructor(handler);
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:47:09 +01:00
|
|
|
// Entry point for creating navigation renderer test objects.
|
|
|
|
// Called from client_app_delegates.cc.
|
2015-01-31 05:41:36 +01:00
|
|
|
void CreateNavigationRendererTests(ClientAppRenderer::DelegateSet& delegates) {
|
2012-11-09 19:47:09 +01:00
|
|
|
delegates.insert(new HistoryNavRendererTest);
|
2012-11-20 21:08:36 +01:00
|
|
|
delegates.insert(new OrderNavRendererTest);
|
2015-03-09 21:22:31 +01:00
|
|
|
delegates.insert(new LoadNavRendererTest);
|
2019-03-19 10:42:54 +01:00
|
|
|
delegates.insert(new ExtraInfoNavRendererTest);
|
2012-11-09 19:47:09 +01:00
|
|
|
}
|