Files
tubestation/toolkit/components/extensions/webidl-api/ExtensionTest.h
Luca Greco 4900365b51 Bug 1724183 - Add ExtensionTest::AssertMatchInternal to provide the logic to be shared between AssertThrows and AssertRejects. r=baku,sfink
This patch introduce a new AssertMatchInternal to ExtensionTest, this method isn't exposed to
js callers through the webidl definition, it is meant to be used internally by the
AssertThrows and AssertRejects methods (which are instead both methods part of the ExtensionTest
webidl).

This patch also introduces small changes to ExtensionAPIRequestForwarder and RequestWorkerRunnable,
to allow AssertMatchInternal to accept as an optional parameter a serialized caller stack trace
(to be sent as part of the APIRequest forwarded from the worker thread to the main thread),
which is needed for AssertRejects (to include the strack trace retrieved when AssertRejects is
called, and then after the promise parameter has been rejected or resolved to send it as part
of the forwarded aPI request).

Differential Revision: https://phabricator.services.mozilla.com/D122033
2021-10-12 18:32:27 +00:00

83 lines
2.6 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_extensions_ExtensionTest_h
#define mozilla_extensions_ExtensionTest_h
#include "js/TypeDecls.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/SerializedStackHolder.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsWrapperCache.h"
#include "ExtensionAPIBase.h"
#include "ExtensionBrowser.h"
class nsIGlobalObject;
namespace mozilla {
namespace extensions {
class ExtensionEventManager;
bool IsInAutomation(JSContext* aCx, JSObject* aGlobal);
class ExtensionTest final : public nsISupports,
public nsWrapperCache,
public ExtensionAPINamespace {
nsCOMPtr<nsIGlobalObject> mGlobal;
RefPtr<ExtensionBrowser> mExtensionBrowser;
RefPtr<ExtensionEventManager> mOnMessageEventMgr;
~ExtensionTest() = default;
public:
ExtensionTest(nsIGlobalObject* aGlobal, ExtensionBrowser* aExtensionBrowser);
// ExtensionAPIBase methods
nsIGlobalObject* GetGlobalObject() const override { return mGlobal; }
ExtensionBrowser* GetExtensionBrowser() const override {
return mExtensionBrowser;
}
nsString GetAPINamespace() const override { return u"test"_ns; }
// nsWrapperCache interface methods
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// DOM bindings methods
static bool IsAllowed(JSContext* aCx, JSObject* aGlobal);
nsIGlobalObject* GetParentObject() const;
void CallWebExtMethodAssertEq(JSContext* aCx, const nsAString& aApiMethod,
const dom::Sequence<JS::Value>& aArgs,
ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT bool AssertMatchInternal(
JSContext* aCx, const JS::HandleValue aActualValue,
const JS::HandleValue aExpectedMatchValue, const nsAString& aMessagePre,
const dom::Optional<nsAString>& aMessage,
UniquePtr<dom::SerializedStackHolder> aSerializedCallerStack,
ErrorResult& aRv);
ExtensionEventManager* OnMessage();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ExtensionTest)
};
} // namespace extensions
} // namespace mozilla
#endif // mozilla_extensions_ExtensionTest_h