2014-09-24 17:38:11 +02:00
|
|
|
// Copyright (c) 2014 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.
|
|
|
|
|
|
|
|
#include "include/base/cef_bind.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "include/base/cef_scoped_ptr.h"
|
2014-09-24 17:38:11 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
|
|
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/test_handler.h"
|
2019-04-30 23:32:50 +02:00
|
|
|
#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"
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
using client::ClientAppBrowser;
|
|
|
|
using client::ClientAppRenderer;
|
2015-01-23 20:09:34 +01:00
|
|
|
|
2014-09-24 17:38:11 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// The frame navigation test harness work as follows:
|
|
|
|
//
|
|
|
|
// In the browser process:
|
|
|
|
// 1. TEST() function creates a new FrameNavTestHandler instance with a unique
|
|
|
|
// FrameNavFactoryId.
|
|
|
|
// 2. FrameNavTestHandler calls FrameNavExpectationsFactoryBrowser::FromID to
|
|
|
|
// create a new factory instance.
|
|
|
|
// 3. FrameNavTestHandler calls FrameNavExpectationsFactoryBrowser::Create to
|
|
|
|
// create a new FrameNavExpectationsBrowser instance for the current
|
|
|
|
// navigation.
|
|
|
|
// 4. FrameNavTestHandler retrieves the URL to load via
|
|
|
|
// FrameNavExpectationsBrowser::GetMainURL and calls either CreateBrowser
|
|
|
|
// (for the first navigation) or LoadURL (for the following navigations).
|
|
|
|
// 5. If the renderer process does not already exist CEF creates it with
|
|
|
|
// command-line arguments that specify the FrameNavFactoryId via
|
|
|
|
// FrameNavBrowserTest::OnBeforeChildProcessLaunch.
|
|
|
|
//
|
|
|
|
// In the renderer process:
|
|
|
|
// 6. If the renderer process is newly created FrameNavRendererTest calls
|
|
|
|
// FrameNavExpectationsFactoryRenderer::FromID to create a new factory
|
|
|
|
// instance.
|
|
|
|
// 7. FrameNavRendererTest calls FrameNavExpectationsFactoryRenderer::Create to
|
|
|
|
// create a new FrameNavExpectationsRenderer instance for the current
|
|
|
|
// navigation.
|
|
|
|
//
|
|
|
|
// In both processes:
|
|
|
|
// 8. Callback notifications are sent to the FrameNavExpectations* instances.
|
|
|
|
//
|
|
|
|
// In the renderer process:
|
|
|
|
// 9. When the FrameNavExpectationsRenderer instance determines that the
|
|
|
|
// renderer side of the test is complete it calls SignalComplete which
|
|
|
|
// finalizes and deletes the FrameNavExpectationsRenderer instance and
|
|
|
|
// sends an IPC message to the browser process.
|
|
|
|
//
|
|
|
|
// In the browser process:
|
|
|
|
// 11.FrameNavExpectationsBrowser::OnRendererComplete is called in response to
|
|
|
|
// renderer-side test completion message.
|
|
|
|
// 12.When the FrameNavExpectationsBrowser instance determines that the browser
|
|
|
|
// side of the test is complete it calls SignalComplete which finalizes and
|
|
|
|
// deletes the FrameNavExpectationsBrowser instance.
|
|
|
|
// 13.If FrameNavExpectationsFactoryBrowser::HasMoreNavigations returns false
|
|
|
|
// then DestroyTest is called and the test ends. Otherwise, the navigation
|
|
|
|
// count is incremented and the process repeats starting with step #3.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// To add a new test case:
|
|
|
|
// 1. Add a new value to the FrameNavFactoryId enumeration.
|
|
|
|
// 2. Provide implementations of FrameNavExpectations*.
|
|
|
|
// 3. Add a case for the new factory ID to FrameNavExpectationsFactory*::FromID.
|
|
|
|
// 4. Implement a TEST() function that creates a FrameNavTestHandler instance
|
|
|
|
// and passes the new factory ID.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Run with the `--single-process` command-line flag to see expectation failures
|
|
|
|
// from the renderer process.
|
2017-05-17 11:29:28 +02:00
|
|
|
//
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// All known factory IDs.
|
|
|
|
enum FrameNavFactoryId {
|
|
|
|
FNF_ID_INVALID = 0,
|
|
|
|
FNF_ID_SINGLE_NAV_HARNESS,
|
|
|
|
FNF_ID_SINGLE_NAV,
|
|
|
|
FNF_ID_MULTI_NAV_HARNESS,
|
|
|
|
FNF_ID_MULTI_NAV,
|
|
|
|
FNF_ID_NESTED_IFRAMES_SAME_ORIGIN,
|
|
|
|
FNF_ID_NESTED_IFRAMES_DIFF_ORIGIN,
|
|
|
|
};
|
|
|
|
|
|
|
|
// IPC message name.
|
|
|
|
const char kFrameNavMsg[] = "FrameTest.Navigation";
|
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
// Extra info parameter keys.
|
|
|
|
const char kFrameNavTestCmdKey[] = "frame-nav-test";
|
|
|
|
|
2014-09-24 17:38:11 +02:00
|
|
|
// Origins used in tests.
|
|
|
|
const char kFrameNavOrigin0[] = "http://tests-framenav0.com/";
|
|
|
|
const char kFrameNavOrigin1[] = "http://tests-framenav1.com/";
|
|
|
|
const char kFrameNavOrigin2[] = "http://tests-framenav2.com/";
|
2018-03-28 19:30:15 +02:00
|
|
|
const char kFrameNavOrigin3[] = "http://tests-framenav3.com/";
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Maximum number of navigations. Should be kept synchronized with the number
|
|
|
|
// of kFrameNavOrigin* values. Don't modify this value without checking the
|
|
|
|
// below use cases.
|
2018-03-28 19:30:15 +02:00
|
|
|
const int kMaxMultiNavNavigations = 4;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Abstract base class representing expectations that result from a navigation.
|
|
|
|
class FrameNavExpectations {
|
|
|
|
public:
|
2019-05-24 22:23:43 +02:00
|
|
|
typedef base::Callback<void(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>)>
|
|
|
|
CompletionCallback;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
FrameNavExpectations(int nav, bool renderer)
|
2017-05-17 11:29:28 +02:00
|
|
|
: nav_(nav), renderer_(renderer) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
virtual ~FrameNavExpectations() {}
|
|
|
|
|
|
|
|
// Browser and renderer notifications.
|
|
|
|
virtual bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
2017-05-17 11:29:28 +02:00
|
|
|
bool isLoading) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
virtual bool OnLoadStart(CefRefPtr<CefBrowser> browser,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefFrame> frame) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
virtual bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefFrame> frame) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Final expectations check before this object is deleted.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual bool Finalize() = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Signal that all expectations are completed. Should be called as a result of
|
|
|
|
// notifications.
|
2019-05-24 22:23:43 +02:00
|
|
|
void SignalComplete(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (!completion_callback_.is_null()) {
|
|
|
|
// Execute the callback asynchronously to avoid any issues with what's
|
|
|
|
// currently on the stack.
|
2017-05-17 11:29:28 +02:00
|
|
|
CefPostTask((renderer_ ? TID_RENDERER : TID_UI),
|
2019-05-24 22:23:43 +02:00
|
|
|
base::Bind(completion_callback_, browser, frame));
|
2014-09-24 17:38:11 +02:00
|
|
|
completion_callback_.Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the current navigation count. In the browser process this value
|
|
|
|
// increments over the life span of the FrameNavTestHandler instance. In the
|
|
|
|
// renderer process this value increments over the life span of a single
|
|
|
|
// renderer instance (i.e. cross-origin navigations will cause this value to
|
|
|
|
// reset).
|
|
|
|
int nav() const { return nav_; }
|
|
|
|
|
|
|
|
// Returns true if this is a renderer-side expectation object.
|
|
|
|
bool renderer() const { return renderer_; }
|
|
|
|
|
|
|
|
void set_completion_callback(const CompletionCallback& completion_callback) {
|
|
|
|
completion_callback_ = completion_callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int nav_;
|
|
|
|
bool renderer_;
|
|
|
|
CompletionCallback completion_callback_;
|
|
|
|
};
|
|
|
|
|
2018-03-28 19:30:15 +02:00
|
|
|
// Browser process expectations abstract base class.
|
2014-09-24 17:38:11 +02:00
|
|
|
class FrameNavExpectationsBrowser : public FrameNavExpectations {
|
|
|
|
public:
|
|
|
|
explicit FrameNavExpectationsBrowser(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: FrameNavExpectations(nav, false) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Loading information.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual std::string GetMainURL() = 0;
|
|
|
|
virtual std::string GetContentForURL(const std::string& url) = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Browser-only notifications.
|
2015-10-09 17:23:12 +02:00
|
|
|
virtual bool OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
|
|
|
EXPECT_TRUE(browser.get());
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
2015-10-09 17:23:12 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const std::string& url) {
|
|
|
|
EXPECT_TRUE(browser.get());
|
|
|
|
EXPECT_TRUE(frame.get());
|
|
|
|
EXPECT_FALSE(url.empty());
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
virtual bool GetResourceHandler(CefRefPtr<CefBrowser> browser,
|
2015-10-09 17:23:12 +02:00
|
|
|
CefRefPtr<CefFrame> frame) {
|
|
|
|
EXPECT_TRUE(browser.get());
|
|
|
|
EXPECT_TRUE(frame.get());
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Called when the renderer signals completion.
|
|
|
|
virtual bool OnRendererComplete(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-09-24 17:38:11 +02:00
|
|
|
int renderer_nav,
|
2017-05-17 11:29:28 +02:00
|
|
|
bool renderer_result) = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Renderer process expectations abstract base class.
|
|
|
|
class FrameNavExpectationsRenderer : public FrameNavExpectations {
|
|
|
|
public:
|
|
|
|
explicit FrameNavExpectationsRenderer(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: FrameNavExpectations(nav, true) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Abstract base class for the factory that creates expectations objects.
|
|
|
|
class FrameNavExpectationsFactory {
|
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactory() {}
|
|
|
|
virtual ~FrameNavExpectationsFactory() {}
|
|
|
|
|
|
|
|
// Returns the unique ID for this factory type.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual FrameNavFactoryId GetID() const = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Browser process expectations factory abstact base class.
|
|
|
|
class FrameNavExpectationsFactoryBrowser : public FrameNavExpectationsFactory {
|
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryBrowser() {}
|
|
|
|
|
|
|
|
// Create a new factory instance of the specified type.
|
2017-05-17 11:29:28 +02:00
|
|
|
static scoped_ptr<FrameNavExpectationsFactoryBrowser> FromID(
|
|
|
|
FrameNavFactoryId id);
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Returns true if there will be more navigations in the browser process
|
|
|
|
// handler.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual bool HasMoreNavigations() const = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Verify final expectations results.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual bool Finalize() = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsBrowser> Create(
|
2014-09-24 17:38:11 +02:00
|
|
|
int nav,
|
|
|
|
const FrameNavExpectations::CompletionCallback& completion_callback) {
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsBrowser> expectations;
|
2014-09-24 17:38:11 +02:00
|
|
|
expectations = Create(nav);
|
|
|
|
expectations->set_completion_callback(completion_callback);
|
2016-11-18 00:52:42 +01:00
|
|
|
return expectations.Pass();
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Implement in the test-specific factory instance.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual scoped_ptr<FrameNavExpectationsBrowser> Create(int nav) = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Renderer process expectations factory abstact base class.
|
|
|
|
class FrameNavExpectationsFactoryRenderer : public FrameNavExpectationsFactory {
|
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryRenderer() {}
|
|
|
|
|
|
|
|
// Create a new factory instance of the specified type.
|
2017-05-17 11:29:28 +02:00
|
|
|
static scoped_ptr<FrameNavExpectationsFactoryRenderer> FromID(
|
|
|
|
FrameNavFactoryId id);
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsRenderer> Create(
|
2014-09-24 17:38:11 +02:00
|
|
|
int nav,
|
|
|
|
const FrameNavExpectations::CompletionCallback& completion_callback) {
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsRenderer> expectations;
|
2014-09-24 17:38:11 +02:00
|
|
|
expectations = Create(nav);
|
|
|
|
expectations->set_completion_callback(completion_callback);
|
2016-11-18 00:52:42 +01:00
|
|
|
return expectations.Pass();
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Implement in the test-specific factory instance.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual scoped_ptr<FrameNavExpectationsRenderer> Create(int nav) = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Renderer side handler.
|
2015-01-31 05:41:36 +01:00
|
|
|
class FrameNavRendererTest : public ClientAppRenderer::Delegate,
|
2014-09-24 17:38:11 +02:00
|
|
|
public CefLoadHandler {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavRendererTest() : run_test_(false), nav_(0) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
void OnBrowserCreated(CefRefPtr<ClientAppRenderer> app,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info) override {
|
|
|
|
if (!extra_info->HasKey(kFrameNavTestCmdKey))
|
|
|
|
return;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
FrameNavFactoryId factory_id =
|
|
|
|
static_cast<FrameNavFactoryId>(extra_info->GetInt(kFrameNavTestCmdKey));
|
|
|
|
run_test_ = factory_id != FNF_ID_INVALID;
|
|
|
|
if (!run_test_)
|
|
|
|
return;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
factory_ = FrameNavExpectationsFactoryRenderer::FromID(factory_id);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefLoadHandler> GetLoadHandler(
|
2015-01-31 05:41:36 +01:00
|
|
|
CefRefPtr<ClientAppRenderer> app) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (!run_test_)
|
2020-01-15 14:34:01 +01:00
|
|
|
return nullptr;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
CreateExpectationsIfNecessary();
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_TRUE(expectations_->OnLoadingStateChange(browser, isLoading))
|
|
|
|
<< "isLoading = " << isLoading << ", nav = " << nav_;
|
2014-09-24 17:38:11 +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 {
|
2014-09-24 17:38:11 +02:00
|
|
|
CreateExpectationsIfNecessary();
|
|
|
|
EXPECT_TRUE(expectations_->OnLoadStart(browser, frame)) << "nav = " << nav_;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
CreateExpectationsIfNecessary();
|
|
|
|
EXPECT_TRUE(expectations_->OnLoadEnd(browser, frame)) << "nav = " << nav_;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Create a new expectations object if one does not already exist for the
|
|
|
|
// current navigation.
|
|
|
|
void CreateExpectationsIfNecessary() {
|
|
|
|
if (expectations_)
|
|
|
|
return;
|
|
|
|
expectations_ = factory_->Create(
|
2017-05-17 11:29:28 +02:00
|
|
|
nav_, base::Bind(&FrameNavRendererTest::SendTestResults, this));
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send the test results.
|
|
|
|
// Will be called via FrameNavExpectations::SignalComplete.
|
2019-05-24 22:23:43 +02:00
|
|
|
void SendTestResults(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2014-09-24 17:38:11 +02:00
|
|
|
// End of the current expectations object.
|
|
|
|
EXPECT_TRUE(expectations_->Finalize()) << "nav = " << nav_;
|
2020-01-15 14:34:01 +01:00
|
|
|
expectations_.reset(nullptr);
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Check if the test has failed.
|
|
|
|
bool result = !TestFailed();
|
|
|
|
|
|
|
|
// Return the result to the browser process.
|
|
|
|
CefRefPtr<CefProcessMessage> return_msg =
|
|
|
|
CefProcessMessage::Create(kFrameNavMsg);
|
|
|
|
CefRefPtr<CefListValue> args = return_msg->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
EXPECT_TRUE(args->SetInt(0, nav_));
|
|
|
|
EXPECT_TRUE(args->SetBool(1, result));
|
2019-06-19 16:53:31 +02:00
|
|
|
|
|
|
|
const int64 frame_id = frame->GetIdentifier();
|
|
|
|
EXPECT_TRUE(args->SetInt(2, CefInt64GetLow(frame_id)));
|
|
|
|
EXPECT_TRUE(args->SetInt(3, CefInt64GetHigh(frame_id)));
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
frame->SendProcessMessage(PID_BROWSER, return_msg);
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
nav_++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool run_test_;
|
|
|
|
int nav_;
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsFactoryRenderer> factory_;
|
|
|
|
scoped_ptr<FrameNavExpectationsRenderer> expectations_;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(FrameNavRendererTest);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Browser side handler.
|
|
|
|
class FrameNavTestHandler : public TestHandler {
|
|
|
|
public:
|
|
|
|
explicit FrameNavTestHandler(FrameNavFactoryId factory_id)
|
|
|
|
: nav_(0),
|
2019-10-03 16:17:58 +02:00
|
|
|
factory_(FrameNavExpectationsFactoryBrowser::FromID(factory_id)) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
~FrameNavTestHandler() override { EXPECT_TRUE(got_destroyed_); }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
// Create the first expectations object.
|
|
|
|
expectations_ = factory_->Create(
|
2017-05-17 11:29:28 +02:00
|
|
|
nav_, base::Bind(&FrameNavTestHandler::RunNextNav, this));
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2019-10-03 16:17:58 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info = CefDictionaryValue::Create();
|
|
|
|
extra_info->SetInt(kFrameNavTestCmdKey, factory_->GetID());
|
|
|
|
|
2014-09-24 17:38:11 +02:00
|
|
|
// Create the browser with the initial URL.
|
2020-01-15 14:34:01 +01:00
|
|
|
CreateBrowser(expectations_->GetMainURL(), nullptr, extra_info);
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
2018-03-28 19:30:15 +02:00
|
|
|
SetTestTimeout(15000);
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transition to the next navigation.
|
|
|
|
// Will be called via FrameNavExpectations::SignalComplete.
|
2019-05-24 22:23:43 +02:00
|
|
|
void RunNextNav(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame) {
|
2014-09-24 17:38:11 +02:00
|
|
|
// End of the current expectations object.
|
|
|
|
EXPECT_TRUE(expectations_->Finalize());
|
2020-01-15 14:34:01 +01:00
|
|
|
expectations_.reset(nullptr);
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
if (!factory_->HasMoreNavigations()) {
|
|
|
|
// End of the test.
|
|
|
|
DestroyTest();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nav_++;
|
|
|
|
|
|
|
|
// Create the next expectations object.
|
|
|
|
expectations_ = factory_->Create(
|
2017-05-17 11:29:28 +02:00
|
|
|
nav_, base::Bind(&FrameNavTestHandler::RunNextNav, this));
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Load the main URL.
|
|
|
|
browser->GetMainFrame()->LoadURL(expectations_->GetMainURL());
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
TestHandler::OnAfterCreated(browser);
|
|
|
|
|
|
|
|
EXPECT_TRUE(expectations_->OnAfterCreated(browser)) << "nav = " << nav_;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefResourceHandler> GetResourceHandler(
|
2014-09-24 17:38:11 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefRequest> request) override {
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_TRUE(expectations_->GetResourceHandler(browser, frame))
|
|
|
|
<< "nav = " << nav_;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
|
|
|
const std::string& content = expectations_->GetContentForURL(url);
|
|
|
|
EXPECT_TRUE(!content.empty()) << "nav = " << nav_;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForData(
|
|
|
|
static_cast<void*>(const_cast<char*>(content.c_str())),
|
|
|
|
content.length());
|
|
|
|
return new CefStreamResourceHandler("text/html", stream);
|
2014-09-24 17:38:11 +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 {
|
2015-10-09 17:23:12 +02:00
|
|
|
EXPECT_TRUE(
|
2017-05-17 11:29:28 +02:00
|
|
|
expectations_->OnBeforeBrowse(browser, frame, request->GetURL()))
|
|
|
|
<< "nav = " << nav_;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) override {
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_TRUE(expectations_->OnLoadingStateChange(browser, isLoading))
|
|
|
|
<< "isLoading = " << isLoading << ", nav = " << nav_;
|
|
|
|
;
|
2014-09-24 17:38:11 +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 {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(expectations_->OnLoadStart(browser, frame)) << "nav = " << nav_;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(expectations_->OnLoadEnd(browser, frame)) << "nav = " << nav_;
|
|
|
|
}
|
|
|
|
|
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 {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (message->GetName().ToString() == kFrameNavMsg) {
|
|
|
|
// Test that the renderer side succeeded.
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
EXPECT_TRUE(expectations_->OnRendererComplete(
|
|
|
|
browser, frame, args->GetInt(0), args->GetBool(1)))
|
2017-05-17 11:29:28 +02:00
|
|
|
<< "nav = " << nav_;
|
2019-06-19 16:53:31 +02:00
|
|
|
|
|
|
|
// Test that browser and render process frame IDs match.
|
|
|
|
const int64 frame_id = CefInt64Set(args->GetInt(2), args->GetInt(3));
|
|
|
|
EXPECT_EQ(frame->GetIdentifier(), frame_id);
|
|
|
|
|
2014-09-24 17:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message not handled.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void DestroyTest() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (got_destroyed_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
got_destroyed_.yes();
|
|
|
|
|
|
|
|
// The expectations should have been tested already.
|
|
|
|
EXPECT_FALSE(expectations_.get());
|
|
|
|
|
|
|
|
// Test that factory conditions we met.
|
|
|
|
EXPECT_TRUE(factory_->Finalize()) << "nav = " << nav_;
|
|
|
|
|
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
int nav_;
|
|
|
|
TrackCallback got_destroyed_;
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsFactoryBrowser> factory_;
|
|
|
|
scoped_ptr<FrameNavExpectationsBrowser> expectations_;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(FrameNavTestHandler);
|
2014-09-24 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Helper for defining frame tests.
|
2017-05-17 11:29:28 +02:00
|
|
|
#define FRAME_TEST(name, factory_id) \
|
|
|
|
TEST(FrameTest, name) { \
|
|
|
|
CefRefPtr<FrameNavTestHandler> handler = \
|
|
|
|
new FrameNavTestHandler(factory_id); \
|
|
|
|
handler->ExecuteTest(); \
|
|
|
|
ReleaseAndWaitForDestructor(handler); \
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Browser process expectations for a single navigation.
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsBrowserSingleNav
|
|
|
|
: public FrameNavExpectationsBrowser {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
explicit FrameNavExpectationsBrowserSingleNav(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: FrameNavExpectationsBrowser(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsBrowserSingleNav() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
2017-05-17 11:29:28 +02:00
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (isLoading) {
|
|
|
|
EXPECT_FALSE(got_loading_state_change_start_);
|
|
|
|
got_loading_state_change_start_.yes();
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(got_loading_state_change_end_);
|
|
|
|
got_loading_state_change_end_.yes();
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, browser->GetMainFrame());
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
got_load_start_.yes();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
got_load_end_.yes();
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_after_created_);
|
|
|
|
got_after_created_.yes();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
2015-10-09 17:23:12 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const std::string& url) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_before_browse_);
|
|
|
|
got_before_browse_.yes();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool GetResourceHandler(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_get_resource_handler_);
|
|
|
|
got_get_resource_handler_.yes();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnRendererComplete(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-11-12 20:25:15 +01:00
|
|
|
int renderer_nav,
|
|
|
|
bool renderer_result) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_EQ(nav(), renderer_nav);
|
|
|
|
EXPECT_TRUE(renderer_result);
|
|
|
|
EXPECT_FALSE(got_renderer_done_);
|
|
|
|
got_renderer_done_.yes();
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_load_start_);
|
|
|
|
V_EXPECT_TRUE(got_load_end_);
|
|
|
|
V_EXPECT_TRUE(got_loading_state_change_start_);
|
|
|
|
V_EXPECT_TRUE(got_loading_state_change_end_);
|
|
|
|
V_EXPECT_TRUE(got_renderer_done_);
|
|
|
|
V_EXPECT_TRUE(got_after_created_);
|
|
|
|
V_EXPECT_TRUE(got_before_browse_);
|
|
|
|
V_EXPECT_TRUE(got_get_resource_handler_);
|
|
|
|
V_EXPECT_FALSE(got_finalize_);
|
|
|
|
|
|
|
|
got_finalize_.yes();
|
|
|
|
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-05-24 22:23:43 +02:00
|
|
|
void SignalCompleteIfDone(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (got_renderer_done_ && got_load_end_ && got_loading_state_change_end_)
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalComplete(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_loading_state_change_start_;
|
|
|
|
TrackCallback got_loading_state_change_end_;
|
|
|
|
TrackCallback got_renderer_done_;
|
|
|
|
TrackCallback got_after_created_;
|
|
|
|
TrackCallback got_before_browse_;
|
|
|
|
TrackCallback got_get_resource_handler_;
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Renderer process expectations for a single navigation.
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsRendererSingleNav
|
|
|
|
: public FrameNavExpectationsRenderer {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
explicit FrameNavExpectationsRendererSingleNav(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: FrameNavExpectationsRenderer(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsRendererSingleNav() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (isLoading) {
|
|
|
|
EXPECT_FALSE(got_loading_state_change_start_);
|
|
|
|
got_loading_state_change_start_.yes();
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(got_loading_state_change_end_);
|
|
|
|
got_loading_state_change_end_.yes();
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, browser->GetMainFrame());
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_load_start_);
|
|
|
|
got_load_start_.yes();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
got_load_end_.yes();
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_load_start_);
|
|
|
|
V_EXPECT_TRUE(got_load_end_);
|
|
|
|
V_EXPECT_TRUE(got_loading_state_change_start_);
|
|
|
|
V_EXPECT_TRUE(got_loading_state_change_end_);
|
|
|
|
V_EXPECT_FALSE(got_finalize_);
|
|
|
|
|
|
|
|
got_finalize_.yes();
|
|
|
|
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-05-24 22:23:43 +02:00
|
|
|
void SignalCompleteIfDone(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (got_load_end_ && got_loading_state_change_end_)
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalComplete(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackCallback got_load_start_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_loading_state_change_start_;
|
|
|
|
TrackCallback got_loading_state_change_end_;
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the single nav harness works.
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsBrowserTestSingleNavHarness
|
|
|
|
: public FrameNavExpectationsBrowserSingleNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsBrowserSingleNav parent;
|
|
|
|
|
|
|
|
explicit FrameNavExpectationsBrowserTestSingleNavHarness(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: parent(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsBrowserTestSingleNavHarness() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetMainURL() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_get_main_url_);
|
|
|
|
got_get_main_url_.yes();
|
|
|
|
return kFrameNavOrigin0;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetContentForURL(const std::string& url) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_get_content_for_url_);
|
|
|
|
got_get_content_for_url_.yes();
|
|
|
|
EXPECT_STREQ(kFrameNavOrigin0, url.c_str());
|
|
|
|
return "<html><body>Nav</body></html>";
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_finalize_);
|
|
|
|
got_finalize_.yes();
|
|
|
|
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_get_main_url_);
|
|
|
|
V_EXPECT_TRUE(got_get_content_for_url_);
|
|
|
|
V_EXPECT_TRUE(parent::Finalize());
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TrackCallback got_get_main_url_;
|
|
|
|
TrackCallback got_get_content_for_url_;
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsRendererTestSingleNavHarness
|
|
|
|
: public FrameNavExpectationsRendererSingleNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsRendererSingleNav parent;
|
|
|
|
|
|
|
|
explicit FrameNavExpectationsRendererTestSingleNavHarness(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: parent(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsRendererTestSingleNavHarness() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_finalize_);
|
|
|
|
got_finalize_.yes();
|
|
|
|
return parent::Finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryBrowserTestSingleNavHarness
|
|
|
|
: public FrameNavExpectationsFactoryBrowser {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryBrowserTestSingleNavHarness() {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsFactoryBrowserTestSingleNavHarness() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavFactoryId GetID() const override { return FNF_ID_SINGLE_NAV_HARNESS; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool HasMoreNavigations() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_get_browser_navigation_count_);
|
|
|
|
got_get_browser_navigation_count_.yes();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_finalize_);
|
|
|
|
got_finalize_.yes();
|
|
|
|
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_get_browser_navigation_count_);
|
|
|
|
V_EXPECT_TRUE(got_create_);
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsBrowser> Create(int nav) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_create_);
|
|
|
|
got_create_.yes();
|
2016-11-18 00:52:42 +01:00
|
|
|
return scoped_ptr<FrameNavExpectationsBrowser>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsBrowserTestSingleNavHarness(nav));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable TrackCallback got_get_browser_navigation_count_;
|
|
|
|
TrackCallback got_create_;
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryRendererTestSingleNavHarness
|
|
|
|
: public FrameNavExpectationsFactoryRenderer {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryRendererTestSingleNavHarness() {}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavFactoryId GetID() const override { return FNF_ID_SINGLE_NAV_HARNESS; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsRenderer> Create(int nav) override {
|
|
|
|
return scoped_ptr<FrameNavExpectationsRenderer>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsRendererTestSingleNavHarness(nav));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that the single nav harness works.
|
|
|
|
FRAME_TEST(SingleNavHarness, FNF_ID_SINGLE_NAV_HARNESS)
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool VerifySingleBrowserFrame(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const std::string& expected_url) {
|
|
|
|
V_DECLARE();
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_TRUE(frame.get());
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(frame->IsValid());
|
2019-04-30 23:32:50 +02:00
|
|
|
const int64 frame_id = frame->GetIdentifier();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(frame_id > 0) << frame_id;
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(frame->IsValid());
|
|
|
|
V_EXPECT_TRUE(frame->IsMain());
|
|
|
|
V_EXPECT_TRUE(frame->IsFocused());
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_FALSE(frame->GetParent().get());
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(frame->GetName().empty());
|
|
|
|
V_EXPECT_TRUE(browser->GetIdentifier() ==
|
|
|
|
frame->GetBrowser()->GetIdentifier());
|
|
|
|
|
|
|
|
const std::string& frame_url = frame->GetURL();
|
2017-05-17 11:29:28 +02:00
|
|
|
V_EXPECT_TRUE(frame_url == expected_url)
|
|
|
|
<< "frame_url = " << frame_url << ", expected_url = " << expected_url;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VerifySingleBrowserFrames(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const std::string& expected_url) {
|
|
|
|
V_DECLARE();
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_TRUE(browser.get());
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2020-01-15 14:34:01 +01:00
|
|
|
// |frame| may be nullptr for callbacks that don't specify one.
|
2014-09-27 01:48:19 +02:00
|
|
|
if (frame.get()) {
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrame(browser, frame, expected_url));
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> main_frame = browser->GetMainFrame();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrame(browser, main_frame, expected_url));
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefFrame> focused_frame = browser->GetFocusedFrame();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrame(browser, focused_frame, expected_url));
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
size_t frame_count = browser->GetFrameCount();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(frame_count == 1U);
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
std::vector<int64> identifiers;
|
|
|
|
browser->GetFrameIdentifiers(identifiers);
|
|
|
|
V_EXPECT_TRUE(identifiers.size() == 1U);
|
|
|
|
if (identifiers.size() == 1U) {
|
|
|
|
V_EXPECT_TRUE(identifiers[0] == main_frame->GetIdentifier());
|
|
|
|
V_EXPECT_TRUE(identifiers[0] == focused_frame->GetIdentifier());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Names may be empty for callbacks that execute while the frame is loading.
|
|
|
|
std::vector<CefString> names;
|
|
|
|
browser->GetFrameNames(names);
|
|
|
|
V_EXPECT_TRUE(names.size() <= 1U);
|
|
|
|
if (names.size() == 1U) {
|
|
|
|
V_EXPECT_TRUE(names[0].ToString() == main_frame->GetName().ToString());
|
|
|
|
V_EXPECT_TRUE(names[0].ToString() == focused_frame->GetName().ToString());
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that single navigation works.
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsBrowserTestSingleNav
|
|
|
|
: public FrameNavExpectationsBrowserSingleNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsBrowserSingleNav parent;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit FrameNavExpectationsBrowserTestSingleNav(int nav) : parent(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
std::string GetMainURL() override { return kFrameNavOrigin0; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetContentForURL(const std::string& url) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return "<html><body>Nav</body></html>";
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(
|
2020-01-15 14:34:01 +01:00
|
|
|
browser, nullptr, isLoading ? std::string() : kFrameNavOrigin0));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadingStateChange(browser, isLoading));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, kFrameNavOrigin0));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadStart(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, kFrameNavOrigin0));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadEnd(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2020-01-15 14:34:01 +01:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, nullptr, std::string()));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnAfterCreated(browser));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
2015-10-09 17:23:12 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const std::string& url) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, std::string()));
|
2015-10-09 17:23:12 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnBeforeBrowse(browser, frame, url));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool GetResourceHandler(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, std::string()));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::GetResourceHandler(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnRendererComplete(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-11-12 20:25:15 +01:00
|
|
|
int renderer_nav,
|
|
|
|
bool renderer_result) override {
|
2019-05-24 22:23:43 +02:00
|
|
|
return parent::OnRendererComplete(browser, frame, renderer_nav,
|
|
|
|
renderer_result);
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool Finalize() override { return parent::Finalize(); }
|
2014-09-24 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsRendererTestSingleNav
|
|
|
|
: public FrameNavExpectationsRendererSingleNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsRendererSingleNav parent;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit FrameNavExpectationsRendererTestSingleNav(int nav) : parent(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
// A frame should always exist in the renderer process.
|
2020-01-15 14:34:01 +01:00
|
|
|
V_EXPECT_TRUE(
|
|
|
|
VerifySingleBrowserFrames(browser, nullptr, kFrameNavOrigin0));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadingStateChange(browser, isLoading));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, kFrameNavOrigin0));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadStart(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, kFrameNavOrigin0));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadEnd(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool Finalize() override { return parent::Finalize(); }
|
2014-09-24 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryBrowserTestSingleNav
|
|
|
|
: public FrameNavExpectationsFactoryBrowser {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryBrowserTestSingleNav() {}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavFactoryId GetID() const override { return FNF_ID_SINGLE_NAV; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool HasMoreNavigations() const override { return false; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool Finalize() override { return true; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsBrowser> Create(int nav) override {
|
|
|
|
return scoped_ptr<FrameNavExpectationsBrowser>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsBrowserTestSingleNav(nav));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryRendererTestSingleNav
|
|
|
|
: public FrameNavExpectationsFactoryRenderer {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryRendererTestSingleNav() {}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavFactoryId GetID() const override { return FNF_ID_SINGLE_NAV; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsRenderer> Create(int nav) override {
|
|
|
|
return scoped_ptr<FrameNavExpectationsRenderer>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsRendererTestSingleNav(nav));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that single navigation works.
|
|
|
|
FRAME_TEST(SingleNav, FNF_ID_SINGLE_NAV)
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Browser process expectations for a multiple navigations.
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsBrowserMultiNav : public FrameNavExpectationsBrowser {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
explicit FrameNavExpectationsBrowserMultiNav(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: FrameNavExpectationsBrowser(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsBrowserMultiNav() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if all navigation is done.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual bool IsNavigationDone() const = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (!isLoading)
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, browser->GetMainFrame());
|
2014-09-24 17:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnRendererComplete(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-11-12 20:25:15 +01:00
|
|
|
int renderer_nav,
|
|
|
|
bool renderer_result) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(renderer_result);
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_FALSE(got_finalize_);
|
|
|
|
|
|
|
|
got_finalize_.yes();
|
|
|
|
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-05-24 22:23:43 +02:00
|
|
|
void SignalCompleteIfDone(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (IsNavigationDone())
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalComplete(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Renderer process expectations for a multiple navigations.
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsRendererMultiNav
|
|
|
|
: public FrameNavExpectationsRenderer {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
explicit FrameNavExpectationsRendererMultiNav(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: FrameNavExpectationsRenderer(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsRendererMultiNav() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if all navigation is done.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual bool IsNavigationDone() const = 0;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (!isLoading)
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, browser->GetMainFrame());
|
2014-09-24 17:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalCompleteIfDone(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_FALSE(got_finalize_);
|
|
|
|
|
|
|
|
got_finalize_.yes();
|
|
|
|
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-05-24 22:23:43 +02:00
|
|
|
void SignalCompleteIfDone(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (IsNavigationDone())
|
2019-05-24 22:23:43 +02:00
|
|
|
SignalComplete(browser, frame);
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a URL containing the nav number.
|
|
|
|
std::string GetMultiNavURL(const std::string& origin, int nav) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << origin << "nav" << nav << ".html";
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the nav number from the URL.
|
|
|
|
int GetNavFromMultiNavURL(const std::string& url) {
|
2014-10-09 18:09:07 +02:00
|
|
|
const size_t start = url.find("/nav");
|
|
|
|
const size_t end = url.find(".html", start);
|
|
|
|
EXPECT_TRUE(start < end && start > 0U);
|
2014-09-24 17:38:11 +02:00
|
|
|
const std::string& nav = url.substr(start + 4, end - start - 4);
|
|
|
|
return atoi(nav.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the origin from the URL.
|
|
|
|
std::string GetOriginFromMultiNavURL(const std::string& url) {
|
2014-10-14 19:57:24 +02:00
|
|
|
const size_t pos = url.rfind("/");
|
|
|
|
EXPECT_TRUE(pos > 0U);
|
2014-09-24 17:38:11 +02:00
|
|
|
return url.substr(0, pos + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that the multi nav harness works.
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsBrowserTestMultiNavHarness
|
|
|
|
: public FrameNavExpectationsBrowserMultiNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsBrowserMultiNav parent;
|
|
|
|
|
|
|
|
explicit FrameNavExpectationsBrowserTestMultiNavHarness(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: parent(nav), navigation_done_count_(0) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsBrowserTestMultiNavHarness() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetMainURL() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_get_main_url_);
|
|
|
|
got_get_main_url_.yes();
|
|
|
|
return GetMultiNavURL(kFrameNavOrigin0, nav());
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetContentForURL(const std::string& url) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_get_content_for_url_);
|
|
|
|
got_get_content_for_url_.yes();
|
|
|
|
EXPECT_STREQ(GetMultiNavURL(kFrameNavOrigin0, nav()).c_str(), url.c_str());
|
|
|
|
return "<html><body>Nav</body></html>";
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsNavigationDone() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
navigation_done_count_++;
|
|
|
|
return got_load_state_change_done_ && got_load_end_ &&
|
|
|
|
got_renderer_complete_;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (!isLoading) {
|
|
|
|
EXPECT_FALSE(got_load_state_change_done_);
|
|
|
|
got_load_state_change_done_.yes();
|
|
|
|
}
|
|
|
|
return parent::OnLoadingStateChange(browser, isLoading);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
got_load_end_.yes();
|
|
|
|
return parent::OnLoadEnd(browser, frame);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_on_after_created_);
|
|
|
|
got_on_after_created_.yes();
|
|
|
|
return parent::OnAfterCreated(browser);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnRendererComplete(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-11-12 20:25:15 +01:00
|
|
|
int renderer_nav,
|
|
|
|
bool renderer_result) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_renderer_complete_);
|
|
|
|
got_renderer_complete_.yes();
|
|
|
|
EXPECT_EQ(nav(), renderer_nav);
|
2019-05-24 22:23:43 +02:00
|
|
|
return parent::OnRendererComplete(browser, frame, renderer_nav,
|
|
|
|
renderer_result);
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_finalize_);
|
|
|
|
got_finalize_.yes();
|
|
|
|
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_get_main_url_);
|
|
|
|
V_EXPECT_TRUE(got_get_content_for_url_);
|
|
|
|
V_EXPECT_TRUE(got_load_state_change_done_);
|
|
|
|
V_EXPECT_TRUE(got_load_end_);
|
|
|
|
if (nav() == 0) {
|
|
|
|
V_EXPECT_TRUE(got_on_after_created_);
|
|
|
|
} else {
|
|
|
|
V_EXPECT_FALSE(got_on_after_created_);
|
|
|
|
}
|
|
|
|
V_EXPECT_TRUE(got_renderer_complete_);
|
|
|
|
V_EXPECT_TRUE(navigation_done_count_ == 3);
|
|
|
|
V_EXPECT_TRUE(parent::Finalize());
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TrackCallback got_get_main_url_;
|
|
|
|
TrackCallback got_get_content_for_url_;
|
|
|
|
TrackCallback got_load_state_change_done_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_on_after_created_;
|
|
|
|
TrackCallback got_renderer_complete_;
|
|
|
|
mutable int navigation_done_count_;
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsRendererTestMultiNavHarness
|
|
|
|
: public FrameNavExpectationsRendererMultiNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsRendererMultiNav parent;
|
|
|
|
|
|
|
|
explicit FrameNavExpectationsRendererTestMultiNavHarness(int nav)
|
2017-05-17 11:29:28 +02:00
|
|
|
: parent(nav), navigation_done_count_(0) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsRendererTestMultiNavHarness() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsNavigationDone() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
navigation_done_count_++;
|
|
|
|
return got_load_state_change_done_ && got_load_end_;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (!isLoading) {
|
|
|
|
EXPECT_FALSE(got_load_state_change_done_);
|
|
|
|
got_load_state_change_done_.yes();
|
|
|
|
}
|
|
|
|
return parent::OnLoadingStateChange(browser, isLoading);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_load_end_);
|
|
|
|
got_load_end_.yes();
|
|
|
|
return parent::OnLoadEnd(browser, frame);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_finalize_);
|
|
|
|
got_finalize_.yes();
|
|
|
|
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_load_state_change_done_);
|
|
|
|
V_EXPECT_TRUE(got_load_end_);
|
|
|
|
V_EXPECT_TRUE(navigation_done_count_ == 2);
|
|
|
|
V_EXPECT_TRUE(parent::Finalize());
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TrackCallback got_load_state_change_done_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
mutable int navigation_done_count_;
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryBrowserTestMultiNavHarness
|
|
|
|
: public FrameNavExpectationsFactoryBrowser {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryBrowserTestMultiNavHarness()
|
2017-05-17 11:29:28 +02:00
|
|
|
: get_browser_navigation_count_(0), create_count_(0) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~FrameNavExpectationsFactoryBrowserTestMultiNavHarness() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_TRUE(got_finalize_);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavFactoryId GetID() const override { return FNF_ID_MULTI_NAV_HARNESS; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool HasMoreNavigations() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
get_browser_navigation_count_++;
|
|
|
|
return (get_browser_navigation_count_ < kMaxMultiNavNavigations);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
EXPECT_FALSE(got_finalize_);
|
|
|
|
got_finalize_.yes();
|
|
|
|
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(get_browser_navigation_count_ == kMaxMultiNavNavigations);
|
|
|
|
V_EXPECT_TRUE(create_count_ == kMaxMultiNavNavigations);
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsBrowser> Create(int nav) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
create_count_++;
|
2016-11-18 00:52:42 +01:00
|
|
|
return scoped_ptr<FrameNavExpectationsBrowser>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsBrowserTestMultiNavHarness(nav));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable int get_browser_navigation_count_;
|
|
|
|
int create_count_;
|
|
|
|
TrackCallback got_finalize_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryRendererTestMultiNavHarness
|
|
|
|
: public FrameNavExpectationsFactoryRenderer {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryRendererTestMultiNavHarness() {}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavFactoryId GetID() const override { return FNF_ID_MULTI_NAV_HARNESS; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsRenderer> Create(int nav) override {
|
|
|
|
return scoped_ptr<FrameNavExpectationsRenderer>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsRendererTestMultiNavHarness(nav));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that the multiple nav harness works.
|
|
|
|
FRAME_TEST(MultiNavHarness, FNF_ID_MULTI_NAV_HARNESS)
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Test that multiple navigation works.
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsBrowserTestMultiNav
|
|
|
|
: public FrameNavExpectationsBrowserMultiNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsBrowserMultiNav parent;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit FrameNavExpectationsBrowserTestMultiNav(int nav) : parent(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetMainURL() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return GetMultiNavURL(kFrameNavOrigin0, nav());
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetContentForURL(const std::string& url) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return "<html><body>Nav</body></html>";
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsNavigationDone() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return got_load_state_change_done_ && got_load_end_ &&
|
|
|
|
got_renderer_complete_;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (!isLoading)
|
|
|
|
got_load_state_change_done_.yes();
|
|
|
|
V_DECLARE();
|
|
|
|
if (isLoading && nav() == 0) {
|
2020-01-15 14:34:01 +01:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, nullptr, std::string()));
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (isLoading) {
|
|
|
|
// Expect the URL from the previous load.
|
2017-05-17 11:29:28 +02:00
|
|
|
V_EXPECT_TRUE(
|
2020-01-15 14:34:01 +01:00
|
|
|
VerifySingleBrowserFrames(browser, nullptr, GetPreviousMainURL()));
|
2014-09-24 17:38:11 +02:00
|
|
|
} else {
|
2020-01-15 14:34:01 +01:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, nullptr, GetMainURL()));
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
V_EXPECT_TRUE(parent::OnLoadingStateChange(browser, isLoading));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, GetMainURL()));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadStart(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
got_load_end_.yes();
|
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, GetMainURL()));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadEnd(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2020-01-15 14:34:01 +01:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, nullptr, std::string()));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnAfterCreated(browser));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
2015-10-09 17:23:12 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const std::string& url) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
std::string expected_url;
|
|
|
|
if (nav() > 0)
|
|
|
|
expected_url = GetPreviousMainURL();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, expected_url));
|
2015-10-09 17:23:12 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnBeforeBrowse(browser, frame, url));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool GetResourceHandler(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
std::string expected_url;
|
|
|
|
if (nav() > 0)
|
|
|
|
expected_url = GetPreviousMainURL();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, expected_url));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::GetResourceHandler(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnRendererComplete(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-11-12 20:25:15 +01:00
|
|
|
int renderer_nav,
|
|
|
|
bool renderer_result) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
got_renderer_complete_.yes();
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(nav() == renderer_nav);
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnRendererComplete(browser, frame, renderer_nav,
|
|
|
|
renderer_result));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_load_state_change_done_);
|
|
|
|
V_EXPECT_TRUE(got_load_end_);
|
|
|
|
V_EXPECT_TRUE(got_renderer_complete_);
|
|
|
|
V_EXPECT_TRUE(parent::Finalize());
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Helper for VerifySingleBrowserFrames.
|
|
|
|
std::string GetPreviousMainURL() {
|
|
|
|
EXPECT_GT(nav(), 0);
|
|
|
|
return GetMultiNavURL(kFrameNavOrigin0, nav() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackCallback got_load_state_change_done_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
TrackCallback got_renderer_complete_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsRendererTestMultiNav
|
|
|
|
: public FrameNavExpectationsRendererMultiNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsRendererMultiNav parent;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit FrameNavExpectationsRendererTestMultiNav(int nav) : parent(nav) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsNavigationDone() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return got_load_state_change_done_ && got_load_end_;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (!isLoading)
|
|
|
|
got_load_state_change_done_.yes();
|
|
|
|
V_DECLARE();
|
2020-01-15 14:34:01 +01:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, nullptr, GetMainURL()));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadingStateChange(browser, isLoading));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, GetMainURL()));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadStart(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
got_load_end_.yes();
|
|
|
|
V_DECLARE();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(VerifySingleBrowserFrames(browser, frame, GetMainURL()));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnLoadEnd(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_load_state_change_done_);
|
|
|
|
V_EXPECT_TRUE(got_load_end_);
|
|
|
|
V_EXPECT_TRUE(parent::Finalize());
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Helpers for calling VerifySingleBrowserFrames.
|
|
|
|
std::string GetMainURL() const {
|
|
|
|
return GetMultiNavURL(kFrameNavOrigin0, nav());
|
|
|
|
}
|
|
|
|
std::string GetPreviousMainURL() {
|
|
|
|
EXPECT_GT(nav(), 0);
|
|
|
|
return GetMultiNavURL(kFrameNavOrigin0, nav() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackCallback got_load_state_change_done_;
|
|
|
|
TrackCallback got_load_end_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryBrowserTestMultiNav
|
|
|
|
: public FrameNavExpectationsFactoryBrowser {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavExpectationsFactoryBrowserTestMultiNav() : nav_count_(0) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavFactoryId GetID() const override { return FNF_ID_MULTI_NAV; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool HasMoreNavigations() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return (nav_count_ < kMaxMultiNavNavigations);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(nav_count_ == kMaxMultiNavNavigations);
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsBrowser> Create(int nav) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
nav_count_++;
|
2016-11-18 00:52:42 +01:00
|
|
|
return scoped_ptr<FrameNavExpectationsBrowser>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsBrowserTestMultiNav(nav));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int nav_count_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryRendererTestMultiNav
|
|
|
|
: public FrameNavExpectationsFactoryRenderer {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryRendererTestMultiNav() {}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavFactoryId GetID() const override { return FNF_ID_MULTI_NAV; }
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsRenderer> Create(int nav) override {
|
|
|
|
return scoped_ptr<FrameNavExpectationsRenderer>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsRendererTestMultiNav(nav));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that multiple navigation works.
|
|
|
|
FRAME_TEST(MultiNav, FNF_ID_MULTI_NAV)
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const char kFrame0Name[] = "";
|
|
|
|
const char kFrame1Name[] = "nav2";
|
|
|
|
const char kFrame2Name[] = "<!--framePath //nav2/<!--frame0-->-->";
|
2018-03-28 19:30:15 +02:00
|
|
|
const char kFrame3Name[] = "nav3";
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
bool VerifyBrowserIframe(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const std::string& origin,
|
|
|
|
int frame_number) {
|
|
|
|
V_DECLARE();
|
|
|
|
|
2018-03-28 19:30:15 +02:00
|
|
|
// frame0 contains frame1 contains frame2, contains frame3.
|
|
|
|
CefRefPtr<CefFrame> frame0, frame1, frame2, frame3;
|
|
|
|
CefRefPtr<CefFrame> frame0b, frame1b, frame2b, frame3b;
|
|
|
|
int64 frame0id, frame1id, frame2id, frame3id;
|
|
|
|
std::string frame0url, frame1url, frame2url, frame3url;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Verify the GetFrameNames result.
|
|
|
|
std::set<std::string> expected_names = {kFrame0Name, kFrame1Name, kFrame2Name,
|
|
|
|
kFrame3Name};
|
|
|
|
|
|
|
|
std::vector<CefString> names;
|
|
|
|
browser->GetFrameNames(names);
|
|
|
|
V_EXPECT_TRUE(names.size() == expected_names.size())
|
|
|
|
<< "expected: " << expected_names.size() << " actual: " << names.size();
|
|
|
|
|
|
|
|
for (const auto& name : names) {
|
|
|
|
const std::string& nameStr = name;
|
|
|
|
auto it = expected_names.find(nameStr);
|
|
|
|
V_EXPECT_FALSE(it == expected_names.end())
|
|
|
|
<< "Unexpected name: \"" << nameStr << "\"";
|
|
|
|
if (it != expected_names.end())
|
|
|
|
expected_names.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& name : expected_names) {
|
|
|
|
V_EXPECT_FALSE(true) << "Missing name: \"" << name << "\"";
|
|
|
|
}
|
|
|
|
|
2014-09-24 17:38:11 +02:00
|
|
|
// Find frames by name.
|
|
|
|
frame0 = browser->GetFrame(kFrame0Name);
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_TRUE(frame0.get());
|
2014-09-24 17:38:11 +02:00
|
|
|
frame1 = browser->GetFrame(kFrame1Name);
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_TRUE(frame1.get());
|
2014-09-24 17:38:11 +02:00
|
|
|
frame2 = browser->GetFrame(kFrame2Name);
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_TRUE(frame2.get());
|
2018-03-28 19:30:15 +02:00
|
|
|
frame3 = browser->GetFrame(kFrame3Name);
|
|
|
|
V_EXPECT_TRUE(frame3.get());
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
if (!frame0 || !frame1 || !frame2 || !frame3) {
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-09-24 17:38:11 +02:00
|
|
|
// Verify that the name matches.
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame0->GetName().ToString() == kFrame0Name)
|
|
|
|
<< "expected: " << kFrame0Name
|
|
|
|
<< " actual: " << frame0->GetName().ToString();
|
|
|
|
V_EXPECT_TRUE(frame1->GetName().ToString() == kFrame1Name)
|
|
|
|
<< "expected: " << kFrame1Name
|
|
|
|
<< " actual: " << frame1->GetName().ToString();
|
|
|
|
V_EXPECT_TRUE(frame2->GetName().ToString() == kFrame2Name)
|
|
|
|
<< "expected: " << kFrame2Name
|
|
|
|
<< " actual: " << frame2->GetName().ToString();
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(frame3->GetName().ToString() == kFrame3Name)
|
|
|
|
<< "expected: " << kFrame3Name
|
|
|
|
<< " actual: " << frame3->GetName().ToString();
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Verify that the URL matches.
|
|
|
|
frame0url = GetMultiNavURL(origin, 0);
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame0->GetURL() == frame0url)
|
|
|
|
<< "expected: " << frame0url
|
|
|
|
<< " actual: " << frame0->GetURL().ToString();
|
2014-09-24 17:38:11 +02:00
|
|
|
frame1url = GetMultiNavURL(origin, 1);
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame1->GetURL() == frame1url)
|
|
|
|
<< "expected: " << frame1url
|
|
|
|
<< " actual: " << frame1->GetURL().ToString();
|
2014-09-24 17:38:11 +02:00
|
|
|
frame2url = GetMultiNavURL(origin, 2);
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame2->GetURL() == frame2url)
|
|
|
|
<< "expected: " << frame2url
|
|
|
|
<< " actual: " << frame2->GetURL().ToString();
|
2018-03-28 19:30:15 +02:00
|
|
|
frame3url = GetMultiNavURL(origin, 3);
|
|
|
|
V_EXPECT_TRUE(frame3->GetURL() == frame3url)
|
|
|
|
<< "expected: " << frame3url
|
|
|
|
<< " actual: " << frame3->GetURL().ToString();
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Verify that the frame id is valid.
|
|
|
|
frame0id = frame0->GetIdentifier();
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame0id > 0) << "actual: " << frame0id;
|
2014-09-24 17:38:11 +02:00
|
|
|
frame1id = frame1->GetIdentifier();
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame1id > 0) << "actual: " << frame1id;
|
2014-09-24 17:38:11 +02:00
|
|
|
frame2id = frame2->GetIdentifier();
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame2id > 0) << "actual: " << frame2id;
|
2018-03-28 19:30:15 +02:00
|
|
|
frame3id = frame3->GetIdentifier();
|
|
|
|
V_EXPECT_TRUE(frame3id > 0) << "actual: " << frame3id;
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2014-09-24 17:38:11 +02:00
|
|
|
// Verify that the current frame has the correct id.
|
|
|
|
if (frame_number == 0) {
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame->GetIdentifier() == frame0id)
|
|
|
|
<< "expected: " << frame0id << " actual: " << frame->GetIdentifier();
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 1) {
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame->GetIdentifier() == frame1id)
|
|
|
|
<< "expected: " << frame1id << " actual: " << frame->GetIdentifier();
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 2) {
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame->GetIdentifier() == frame2id)
|
|
|
|
<< "expected: " << frame2id << " actual: " << frame->GetIdentifier();
|
2018-03-28 19:30:15 +02:00
|
|
|
} else if (frame_number == 3) {
|
|
|
|
V_EXPECT_TRUE(frame->GetIdentifier() == frame3id)
|
|
|
|
<< "expected: " << frame3id << " actual: " << frame->GetIdentifier();
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find frames by id.
|
|
|
|
frame0b = browser->GetFrame(frame0->GetIdentifier());
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_TRUE(frame0b.get());
|
2014-09-24 17:38:11 +02:00
|
|
|
frame1b = browser->GetFrame(frame1->GetIdentifier());
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_TRUE(frame1b.get());
|
2014-09-24 17:38:11 +02:00
|
|
|
frame2b = browser->GetFrame(frame2->GetIdentifier());
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_TRUE(frame2b.get());
|
2018-03-28 19:30:15 +02:00
|
|
|
frame3b = browser->GetFrame(frame3->GetIdentifier());
|
|
|
|
V_EXPECT_TRUE(frame3b.get());
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
if (!frame0b || !frame1b || !frame2b || !frame3b) {
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-09-24 17:38:11 +02:00
|
|
|
// Verify that the id matches.
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame0b->GetIdentifier() == frame0id)
|
|
|
|
<< "expected: " << frame0id << " actual: " << frame0b->GetIdentifier();
|
|
|
|
V_EXPECT_TRUE(frame1b->GetIdentifier() == frame1id)
|
|
|
|
<< "expected: " << frame1id << " actual: " << frame1b->GetIdentifier();
|
|
|
|
V_EXPECT_TRUE(frame2b->GetIdentifier() == frame2id)
|
|
|
|
<< "expected: " << frame2id << " actual: " << frame2b->GetIdentifier();
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(frame3b->GetIdentifier() == frame3id)
|
|
|
|
<< "expected: " << frame3id << " actual: " << frame3b->GetIdentifier();
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2015-11-10 21:18:16 +01:00
|
|
|
size_t frame_count = browser->GetFrameCount();
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(frame_count == 4U) << " actual: " << frame_count;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Verify the GetFrameIdentifiers result.
|
2019-05-24 22:23:43 +02:00
|
|
|
std::set<int64> expected_idents = {frame0id, frame1id, frame2id, frame3id};
|
|
|
|
|
2014-09-24 17:38:11 +02:00
|
|
|
std::vector<int64> idents;
|
|
|
|
browser->GetFrameIdentifiers(idents);
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(idents.size() == expected_idents.size())
|
|
|
|
<< "expected: " << expected_idents.size() << " actual: " << idents.size();
|
|
|
|
|
|
|
|
for (const auto& ident : idents) {
|
|
|
|
auto it = expected_idents.find(ident);
|
|
|
|
V_EXPECT_FALSE(it == expected_idents.end()) << "Unexpected id: " << ident;
|
|
|
|
if (it != expected_idents.end())
|
|
|
|
expected_idents.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& ident : expected_idents) {
|
|
|
|
V_EXPECT_FALSE(true) << "Missing id: " << ident;
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
// Verify parent hierarchy.
|
2014-09-27 01:48:19 +02:00
|
|
|
V_EXPECT_FALSE(frame0->GetParent().get());
|
2017-11-29 00:00:50 +01:00
|
|
|
V_EXPECT_TRUE(frame1->GetParent()->GetIdentifier() == frame0id)
|
|
|
|
<< "expected: " << frame0id
|
|
|
|
<< " actual: " << frame1->GetParent()->GetIdentifier();
|
|
|
|
V_EXPECT_TRUE(frame2->GetParent()->GetIdentifier() == frame1id)
|
|
|
|
<< "expected: " << frame1id
|
|
|
|
<< " actual: " << frame2->GetParent()->GetIdentifier();
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(frame3->GetParent()->GetIdentifier() == frame2id)
|
|
|
|
<< "expected: " << frame2id
|
|
|
|
<< " actual: " << frame3->GetParent()->GetIdentifier();
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that nested iframes work.
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsBrowserTestNestedIframes
|
|
|
|
: public FrameNavExpectationsBrowserMultiNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsBrowserMultiNav parent;
|
|
|
|
|
|
|
|
FrameNavExpectationsBrowserTestNestedIframes(int nav, bool same_origin)
|
2017-05-17 11:29:28 +02:00
|
|
|
: parent(nav), same_origin_(same_origin) {
|
2014-09-24 17:38:11 +02:00
|
|
|
// In the browser process we can rely on the |nav| value to determine the
|
|
|
|
// origin.
|
|
|
|
if (same_origin) {
|
|
|
|
origin_ = kFrameNavOrigin0;
|
2017-05-17 11:29:28 +02:00
|
|
|
} else {
|
|
|
|
switch (nav) {
|
|
|
|
case 0:
|
|
|
|
origin_ = kFrameNavOrigin0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
origin_ = kFrameNavOrigin1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
origin_ = kFrameNavOrigin2;
|
|
|
|
break;
|
2018-03-28 19:30:15 +02:00
|
|
|
case 3:
|
|
|
|
origin_ = kFrameNavOrigin3;
|
|
|
|
break;
|
2017-05-17 11:29:28 +02:00
|
|
|
default:
|
|
|
|
EXPECT_TRUE(false); // Not reached.
|
|
|
|
break;
|
|
|
|
}
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetMainURL() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
// Load the first (main) frame.
|
|
|
|
return GetMultiNavURL(origin_, 0);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetContentForURL(const std::string& url) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
const int frame_number = GetNavFromMultiNavURL(url);
|
|
|
|
switch (frame_number) {
|
|
|
|
case 0:
|
|
|
|
// Frame 0. Contains a named iframe.
|
2017-05-17 11:29:28 +02:00
|
|
|
return "<html><body>Nav1<iframe src=\"" + GetMultiNavURL(origin_, 1) +
|
2014-09-24 17:38:11 +02:00
|
|
|
"\" name=\"nav2\"></body></html>";
|
|
|
|
case 1:
|
|
|
|
// Frame 1. Contains an unnamed iframe.
|
2017-05-17 11:29:28 +02:00
|
|
|
return "<html><body>Nav2<iframe src=\"" + GetMultiNavURL(origin_, 2) +
|
2014-09-24 17:38:11 +02:00
|
|
|
"\"></body></html>";
|
2018-03-28 19:30:15 +02:00
|
|
|
case 2: {
|
|
|
|
// Frame 2. Contains an named iframe created via javascript.
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "<html><script>"
|
|
|
|
<< " function createFrame() {"
|
|
|
|
<< " var f = document.createElement('iframe');"
|
|
|
|
<< " f.name = 'nav3';"
|
|
|
|
<< " f.src = '" << GetMultiNavURL(origin_, 3) << "';"
|
|
|
|
<< " document.body.appendChild(f);"
|
|
|
|
<< " }</script><body onload=\"createFrame()\">Nav3</body></html>";
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
// Frame 3.
|
|
|
|
return "<html><body>Nav4</body></html>";
|
2014-09-24 17:38:11 +02:00
|
|
|
default:
|
|
|
|
EXPECT_TRUE(false); // Not reached.
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsNavigationDone() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return got_load_state_change_done_ && got_renderer_complete_ &&
|
2018-03-28 19:30:15 +02:00
|
|
|
got_load_end_[0] && got_load_end_[1] && got_load_end_[2] &&
|
|
|
|
got_load_end_[3];
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const std::string& url) override {
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(frame.get());
|
|
|
|
const int frame_number = GetNavFromMultiNavURL(url);
|
|
|
|
if (frame_number == 0) {
|
|
|
|
// Main frame.
|
|
|
|
V_EXPECT_TRUE(frame->IsMain());
|
|
|
|
} else {
|
|
|
|
// Sub frame.
|
|
|
|
V_EXPECT_FALSE(frame->IsMain());
|
|
|
|
}
|
|
|
|
V_EXPECT_TRUE(parent::OnBeforeBrowse(browser, frame, url));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_FALSE(got_load_state_change_done_);
|
|
|
|
|
|
|
|
if (!isLoading) {
|
|
|
|
got_load_state_change_done_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
V_EXPECT_TRUE(parent::OnLoadingStateChange(browser, isLoading));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
const int frame_number = GetNavFromMultiNavURL(frame->GetURL());
|
|
|
|
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_FALSE(got_load_start_[frame_number]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[frame_number]);
|
|
|
|
|
|
|
|
// Notification should be received for parent frame before child frame.
|
|
|
|
if (frame_number == 0) {
|
|
|
|
V_EXPECT_FALSE(got_load_start_[1]);
|
|
|
|
V_EXPECT_FALSE(got_load_start_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_FALSE(got_load_start_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 1) {
|
|
|
|
V_EXPECT_TRUE(got_load_start_[0]);
|
|
|
|
V_EXPECT_FALSE(got_load_start_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_FALSE(got_load_start_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 2) {
|
|
|
|
V_EXPECT_TRUE(got_load_start_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[1]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_FALSE(got_load_start_[3]);
|
|
|
|
} else if (frame_number == 3) {
|
|
|
|
V_EXPECT_TRUE(got_load_start_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[1]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[2]);
|
2015-11-10 21:18:16 +01:00
|
|
|
} else {
|
|
|
|
V_EXPECT_TRUE(false); // Not reached.
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
got_load_start_[frame_number].yes();
|
|
|
|
|
|
|
|
V_EXPECT_TRUE(parent::OnLoadStart(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
const int frame_number = GetNavFromMultiNavURL(frame->GetURL());
|
|
|
|
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_load_start_[frame_number]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[frame_number]);
|
|
|
|
|
|
|
|
// Notification should be received for child frame before parent frame.
|
|
|
|
if (frame_number == 0) {
|
|
|
|
V_EXPECT_TRUE(got_load_end_[1]);
|
|
|
|
V_EXPECT_TRUE(got_load_end_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 1) {
|
|
|
|
V_EXPECT_FALSE(got_load_end_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_end_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 2) {
|
|
|
|
V_EXPECT_FALSE(got_load_end_[0]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[1]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[3]);
|
|
|
|
} else if (frame_number == 3) {
|
|
|
|
V_EXPECT_FALSE(got_load_end_[0]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[1]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[2]);
|
2015-11-10 21:18:16 +01:00
|
|
|
} else {
|
|
|
|
V_EXPECT_TRUE(false); // Not reached.
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
V_EXPECT_TRUE(VerifyBrowserIframe(browser, frame, origin_, frame_number))
|
|
|
|
<< "frame_number = " << frame_number;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
got_load_end_[frame_number].yes();
|
|
|
|
|
|
|
|
V_EXPECT_TRUE(parent::OnLoadEnd(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnRendererComplete(CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-11-12 20:25:15 +01:00
|
|
|
int renderer_nav,
|
|
|
|
bool renderer_result) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_FALSE(got_renderer_complete_);
|
|
|
|
if (same_origin_) {
|
|
|
|
V_EXPECT_TRUE(renderer_nav == nav());
|
|
|
|
} else {
|
|
|
|
// Because each navigation is in a new renderer process.
|
|
|
|
V_EXPECT_TRUE(renderer_nav == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
got_renderer_complete_.yes();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
V_EXPECT_TRUE(parent::OnRendererComplete(browser, frame, renderer_nav,
|
|
|
|
renderer_result));
|
2014-09-24 17:38:11 +02:00
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_load_state_change_done_);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[1]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_start_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_end_[1]);
|
|
|
|
V_EXPECT_TRUE(got_load_end_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(got_renderer_complete_);
|
|
|
|
V_EXPECT_TRUE(parent::Finalize());
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool same_origin_;
|
|
|
|
std::string origin_;
|
|
|
|
|
|
|
|
TrackCallback got_load_state_change_done_;
|
2018-03-28 19:30:15 +02:00
|
|
|
TrackCallback got_load_start_[4];
|
|
|
|
TrackCallback got_load_end_[4];
|
2014-09-24 17:38:11 +02:00
|
|
|
TrackCallback got_renderer_complete_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsRendererTestNestedIframes
|
|
|
|
: public FrameNavExpectationsRendererMultiNav {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
typedef FrameNavExpectationsRendererMultiNav parent;
|
|
|
|
|
|
|
|
FrameNavExpectationsRendererTestNestedIframes(int nav, bool same_origin)
|
2017-05-17 11:29:28 +02:00
|
|
|
: parent(nav) {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (same_origin)
|
|
|
|
origin_ = kFrameNavOrigin0;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsNavigationDone() const override {
|
2017-05-17 11:29:28 +02:00
|
|
|
return got_load_state_change_done_ && got_load_end_[0] &&
|
2018-03-28 19:30:15 +02:00
|
|
|
got_load_end_[1] && got_load_end_[2] && got_load_end_[3];
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_FALSE(got_load_state_change_done_);
|
|
|
|
|
|
|
|
if (!isLoading) {
|
|
|
|
got_load_state_change_done_.yes();
|
|
|
|
}
|
|
|
|
|
|
|
|
V_EXPECT_TRUE(parent::OnLoadingStateChange(browser, isLoading));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
if (origin_.empty()) {
|
|
|
|
// When navigating different origins we can't rely on the nav() value
|
|
|
|
// because each navigation creates a new renderer process. Get the origin
|
|
|
|
// by parsing the URL instead.
|
|
|
|
origin_ = GetOriginFromMultiNavURL(browser->GetMainFrame()->GetURL());
|
|
|
|
}
|
|
|
|
|
|
|
|
const int frame_number = GetNavFromMultiNavURL(frame->GetURL());
|
|
|
|
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_FALSE(got_load_start_[frame_number]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[frame_number]);
|
|
|
|
|
|
|
|
// Notification should be received for parent frame before child frame.
|
|
|
|
if (frame_number == 0) {
|
|
|
|
V_EXPECT_FALSE(got_load_start_[1]);
|
|
|
|
V_EXPECT_FALSE(got_load_start_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_FALSE(got_load_start_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 1) {
|
|
|
|
V_EXPECT_TRUE(got_load_start_[0]);
|
|
|
|
V_EXPECT_FALSE(got_load_start_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_FALSE(got_load_start_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 2) {
|
|
|
|
V_EXPECT_TRUE(got_load_start_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[1]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_FALSE(got_load_start_[3]);
|
|
|
|
} else if (frame_number == 3) {
|
|
|
|
V_EXPECT_TRUE(got_load_start_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[1]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[2]);
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
got_load_start_[frame_number].yes();
|
|
|
|
|
|
|
|
V_EXPECT_TRUE(parent::OnLoadStart(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
const int frame_number = GetNavFromMultiNavURL(frame->GetURL());
|
|
|
|
|
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_load_start_[frame_number]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[frame_number]);
|
|
|
|
|
|
|
|
// Notification should be received for child frame before parent frame.
|
|
|
|
if (frame_number == 0) {
|
|
|
|
V_EXPECT_TRUE(got_load_end_[1]);
|
|
|
|
V_EXPECT_TRUE(got_load_end_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 1) {
|
|
|
|
V_EXPECT_FALSE(got_load_end_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_end_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
} else if (frame_number == 2) {
|
|
|
|
V_EXPECT_FALSE(got_load_end_[0]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[1]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[3]);
|
|
|
|
} else if (frame_number == 3) {
|
|
|
|
V_EXPECT_FALSE(got_load_end_[0]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[1]);
|
|
|
|
V_EXPECT_FALSE(got_load_end_[2]);
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
V_EXPECT_TRUE(VerifyBrowserIframe(browser, frame, origin_, frame_number))
|
|
|
|
<< "frame_number = " << frame_number;
|
2014-09-24 17:38:11 +02:00
|
|
|
|
|
|
|
got_load_end_[frame_number].yes();
|
|
|
|
|
|
|
|
V_EXPECT_TRUE(parent::OnLoadEnd(browser, frame));
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(got_load_state_change_done_);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[1]);
|
|
|
|
V_EXPECT_TRUE(got_load_start_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_start_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[0]);
|
|
|
|
V_EXPECT_TRUE(got_load_end_[1]);
|
|
|
|
V_EXPECT_TRUE(got_load_end_[2]);
|
2018-03-28 19:30:15 +02:00
|
|
|
V_EXPECT_TRUE(got_load_end_[3]);
|
2014-09-24 17:38:11 +02:00
|
|
|
V_EXPECT_TRUE(parent::Finalize());
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string origin_;
|
|
|
|
|
|
|
|
TrackCallback got_load_state_change_done_;
|
2018-03-28 19:30:15 +02:00
|
|
|
TrackCallback got_load_start_[4];
|
|
|
|
TrackCallback got_load_end_[4];
|
2014-09-24 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryBrowserTestNestedIframesSameOrigin
|
|
|
|
: public FrameNavExpectationsFactoryBrowser {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryBrowserTestNestedIframesSameOrigin()
|
2017-05-17 11:29:28 +02:00
|
|
|
: create_count_(0) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
FrameNavFactoryId GetID() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return FNF_ID_NESTED_IFRAMES_SAME_ORIGIN;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool HasMoreNavigations() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return (create_count_ < kMaxMultiNavNavigations);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(create_count_ == kMaxMultiNavNavigations);
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsBrowser> Create(int nav) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
create_count_++;
|
2016-11-18 00:52:42 +01:00
|
|
|
return scoped_ptr<FrameNavExpectationsBrowser>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsBrowserTestNestedIframes(nav, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int create_count_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryRendererTestNestedIframesSameOrigin
|
|
|
|
: public FrameNavExpectationsFactoryRenderer {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryRendererTestNestedIframesSameOrigin() {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
FrameNavFactoryId GetID() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return FNF_ID_NESTED_IFRAMES_SAME_ORIGIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsRenderer> Create(int nav) override {
|
|
|
|
return scoped_ptr<FrameNavExpectationsRenderer>(
|
2017-05-17 11:29:28 +02:00
|
|
|
new FrameNavExpectationsRendererTestNestedIframes(nav, true));
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that nested iframes work.
|
|
|
|
FRAME_TEST(NestedIframesSameOrigin, FNF_ID_NESTED_IFRAMES_SAME_ORIGIN)
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryBrowserTestNestedIframesDiffOrigin
|
|
|
|
: public FrameNavExpectationsFactoryBrowser {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryBrowserTestNestedIframesDiffOrigin()
|
2017-05-17 11:29:28 +02:00
|
|
|
: create_count_(0) {}
|
2014-09-24 17:38:11 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
FrameNavFactoryId GetID() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return FNF_ID_NESTED_IFRAMES_DIFF_ORIGIN;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool HasMoreNavigations() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return (create_count_ < kMaxMultiNavNavigations);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Finalize() override {
|
2014-09-24 17:38:11 +02:00
|
|
|
V_DECLARE();
|
|
|
|
V_EXPECT_TRUE(create_count_ == kMaxMultiNavNavigations);
|
|
|
|
V_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsBrowser> Create(int nav) override {
|
2014-09-24 17:38:11 +02:00
|
|
|
create_count_++;
|
2016-11-18 00:52:42 +01:00
|
|
|
return scoped_ptr<FrameNavExpectationsBrowser>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsBrowserTestNestedIframes(nav, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int create_count_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class FrameNavExpectationsFactoryRendererTestNestedIframesDiffOrigin
|
|
|
|
: public FrameNavExpectationsFactoryRenderer {
|
2014-09-24 17:38:11 +02:00
|
|
|
public:
|
|
|
|
FrameNavExpectationsFactoryRendererTestNestedIframesDiffOrigin() {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
FrameNavFactoryId GetID() const override {
|
2014-09-24 17:38:11 +02:00
|
|
|
return FNF_ID_NESTED_IFRAMES_DIFF_ORIGIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsRenderer> Create(int nav) override {
|
|
|
|
return scoped_ptr<FrameNavExpectationsRenderer>(
|
2014-09-24 17:38:11 +02:00
|
|
|
new FrameNavExpectationsRendererTestNestedIframes(nav, false));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test that nested iframes work.
|
|
|
|
FRAME_TEST(NestedIframesDiffOrigin, FNF_ID_NESTED_IFRAMES_DIFF_ORIGIN)
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Returns a new factory in the browser or renderer process. All factory types
|
|
|
|
// must be listed here.
|
|
|
|
|
|
|
|
// static
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsFactoryBrowser>
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavExpectationsFactoryBrowser::FromID(FrameNavFactoryId id) {
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsFactoryBrowser> factory;
|
2014-09-24 17:38:11 +02:00
|
|
|
switch (id) {
|
|
|
|
case FNF_ID_SINGLE_NAV_HARNESS:
|
|
|
|
factory.reset(new FrameNavExpectationsFactoryBrowserTestSingleNavHarness);
|
|
|
|
break;
|
|
|
|
case FNF_ID_SINGLE_NAV:
|
|
|
|
factory.reset(new FrameNavExpectationsFactoryBrowserTestSingleNav);
|
|
|
|
break;
|
|
|
|
case FNF_ID_MULTI_NAV_HARNESS:
|
|
|
|
factory.reset(new FrameNavExpectationsFactoryBrowserTestMultiNavHarness);
|
|
|
|
break;
|
|
|
|
case FNF_ID_MULTI_NAV:
|
|
|
|
factory.reset(new FrameNavExpectationsFactoryBrowserTestMultiNav);
|
|
|
|
break;
|
|
|
|
case FNF_ID_NESTED_IFRAMES_SAME_ORIGIN:
|
|
|
|
factory.reset(
|
|
|
|
new FrameNavExpectationsFactoryBrowserTestNestedIframesSameOrigin);
|
|
|
|
break;
|
|
|
|
case FNF_ID_NESTED_IFRAMES_DIFF_ORIGIN:
|
|
|
|
factory.reset(
|
|
|
|
new FrameNavExpectationsFactoryBrowserTestNestedIframesDiffOrigin);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
EXPECT_TRUE(factory);
|
|
|
|
EXPECT_EQ(id, factory->GetID());
|
2016-11-18 00:52:42 +01:00
|
|
|
return factory.Pass();
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsFactoryRenderer>
|
2017-05-17 11:29:28 +02:00
|
|
|
FrameNavExpectationsFactoryRenderer::FromID(FrameNavFactoryId id) {
|
2016-11-18 00:52:42 +01:00
|
|
|
scoped_ptr<FrameNavExpectationsFactoryRenderer> factory;
|
2014-09-24 17:38:11 +02:00
|
|
|
switch (id) {
|
|
|
|
case FNF_ID_SINGLE_NAV_HARNESS:
|
|
|
|
factory.reset(
|
|
|
|
new FrameNavExpectationsFactoryRendererTestSingleNavHarness);
|
|
|
|
break;
|
|
|
|
case FNF_ID_SINGLE_NAV:
|
|
|
|
factory.reset(new FrameNavExpectationsFactoryRendererTestSingleNav);
|
|
|
|
break;
|
|
|
|
case FNF_ID_MULTI_NAV_HARNESS:
|
|
|
|
factory.reset(new FrameNavExpectationsFactoryRendererTestMultiNavHarness);
|
|
|
|
break;
|
|
|
|
case FNF_ID_MULTI_NAV:
|
|
|
|
factory.reset(new FrameNavExpectationsFactoryRendererTestMultiNav);
|
|
|
|
break;
|
|
|
|
case FNF_ID_NESTED_IFRAMES_SAME_ORIGIN:
|
|
|
|
factory.reset(
|
|
|
|
new FrameNavExpectationsFactoryRendererTestNestedIframesSameOrigin);
|
|
|
|
break;
|
|
|
|
case FNF_ID_NESTED_IFRAMES_DIFF_ORIGIN:
|
|
|
|
factory.reset(
|
|
|
|
new FrameNavExpectationsFactoryRendererTestNestedIframesDiffOrigin);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
EXPECT_TRUE(factory);
|
|
|
|
EXPECT_EQ(id, factory->GetID());
|
2016-11-18 00:52:42 +01:00
|
|
|
return factory.Pass();
|
2014-09-24 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Entry point for creating frame renderer test objects.
|
|
|
|
// Called from client_app_delegates.cc.
|
2015-01-31 05:41:36 +01:00
|
|
|
void CreateFrameRendererTests(ClientAppRenderer::DelegateSet& delegates) {
|
2014-09-24 17:38:11 +02:00
|
|
|
delegates.insert(new FrameNavRendererTest);
|
|
|
|
}
|