Change the GuiManager tests to use promises
This commit is contained in:
parent
b28b2343d8
commit
883f093cb9
@ -0,0 +1,4 @@
|
|||||||
|
function init()
|
||||||
|
{
|
||||||
|
return new Promise(resolve => global.closePage = resolve);
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<objects>
|
||||||
|
<script file="gui/regainFocus/emptyPage.js"/>
|
||||||
|
</objects>
|
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<page>
|
<page>
|
||||||
<include>common/styles.xml</include>
|
<include>common/styles.xml</include>
|
||||||
|
<include>regainFocus/emptyPage.xml</include>
|
||||||
</page>
|
</page>
|
||||||
|
@ -1 +1,4 @@
|
|||||||
Engine.PushGuiPage("regainFocus/page_emptyPage.xml").then(Engine.PopGuiPage);
|
function init()
|
||||||
|
{
|
||||||
|
return Engine.PushGuiPage("regainFocus/page_emptyPage.xml");
|
||||||
|
}
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<page>
|
||||||
|
<include>common/styles.xml</include>
|
||||||
|
<include>resolveReject/resolveReject.xml</include>
|
||||||
|
</page>
|
@ -0,0 +1,5 @@
|
|||||||
|
async function init(reject)
|
||||||
|
{
|
||||||
|
if (reject)
|
||||||
|
throw undefined;
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<objects>
|
||||||
|
<script file="gui/resolveReject/resolveReject.js"/>
|
||||||
|
</objects>
|
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<page>
|
||||||
|
<include>common/styles.xml</include>
|
||||||
|
<include>sequential/sequential.xml</include>
|
||||||
|
</page>
|
@ -0,0 +1,5 @@
|
|||||||
|
async function init()
|
||||||
|
{
|
||||||
|
await Engine.PushGuiPage("regainFocus/page_emptyPage.xml");
|
||||||
|
await Engine.PushGuiPage("regainFocus/page_emptyPage.xml");
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<objects>
|
||||||
|
<script file="gui/sequential/sequential.js"/>
|
||||||
|
</objects>
|
@ -26,12 +26,14 @@
|
|||||||
#include "ps/GameSetup/GameSetup.h"
|
#include "ps/GameSetup/GameSetup.h"
|
||||||
#include "ps/Hotkey.h"
|
#include "ps/Hotkey.h"
|
||||||
#include "ps/XML/Xeromyces.h"
|
#include "ps/XML/Xeromyces.h"
|
||||||
|
#include "scriptinterface/FunctionWrapper.h"
|
||||||
#include "scriptinterface/ScriptContext.h"
|
#include "scriptinterface/ScriptContext.h"
|
||||||
#include "scriptinterface/ScriptRequest.h"
|
#include "scriptinterface/ScriptRequest.h"
|
||||||
#include "scriptinterface/ScriptInterface.h"
|
#include "scriptinterface/ScriptInterface.h"
|
||||||
#include "scriptinterface/StructuredClone.h"
|
#include "scriptinterface/StructuredClone.h"
|
||||||
#include "scriptinterface/Object.h"
|
#include "scriptinterface/Object.h"
|
||||||
|
|
||||||
|
#include "js/Promise.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@ -204,37 +206,69 @@ public:
|
|||||||
|
|
||||||
static void CloseTopmostPage()
|
static void CloseTopmostPage()
|
||||||
{
|
{
|
||||||
g_GUI->PopPage(JS::NullHandleValue);
|
ScriptRequest rq{g_GUI->GetActiveGUI()->GetScriptInterface()};
|
||||||
|
JS::RootedValue global{rq.cx, rq.globalValue()};
|
||||||
|
TS_ASSERT(ScriptFunction::CallVoid(rq, global, "closePage"));
|
||||||
|
// Check if some promise are setteled and flush the promise-jobQueue.
|
||||||
g_GUI->TickObjects();
|
g_GUI->TickObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_PageRegainedFocusEvent()
|
void test_PageRegainedFocusEvent()
|
||||||
{
|
{
|
||||||
// Load up a test page.
|
|
||||||
ScriptRequest rq{g_GUI->GetScriptInterface()};
|
ScriptRequest rq{g_GUI->GetScriptInterface()};
|
||||||
JS::RootedValue val(rq.cx);
|
const Script::StructuredClone undefined{
|
||||||
Script::CreateObject(rq, &val);
|
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue)};
|
||||||
|
|
||||||
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 0);
|
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 0);
|
||||||
Script::StructuredClone data = Script::WriteStructuredClone(rq, JS::NullHandleValue);
|
g_GUI->PushPage(L"regainFocus/page_emptyPage.xml", undefined);
|
||||||
g_GUI->PushPage(L"regainFocus/page_emptyPage.xml", data);
|
|
||||||
|
|
||||||
const ScriptInterface& pageScriptInterface = *(g_GUI->GetActiveGUI()->GetScriptInterface());
|
|
||||||
ScriptRequest prq(pageScriptInterface);
|
|
||||||
JS::RootedValue global(prq.cx, prq.globalValue());
|
|
||||||
|
|
||||||
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 1);
|
|
||||||
g_GUI->PushPage(L"regainFocus/page_emptyPage.xml", data);
|
|
||||||
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 2);
|
|
||||||
CloseTopmostPage();
|
|
||||||
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 1);
|
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 1);
|
||||||
|
|
||||||
// This page instantly pushes an empty page with a callback that pops another page again.
|
// This page instantly pushes an empty page with a callback that pops another page again.
|
||||||
g_GUI->PushPage(L"regainFocus/page_pushWithPopOnInit.xml", data);
|
g_GUI->PushPage(L"regainFocus/page_pushWithPopOnInit.xml", undefined);
|
||||||
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 3);
|
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 3);
|
||||||
|
|
||||||
// Pop the empty page
|
// Pop the empty page and execute the continuation.
|
||||||
CloseTopmostPage();
|
CloseTopmostPage();
|
||||||
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 1);
|
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 1);
|
||||||
|
|
||||||
|
CloseTopmostPage();
|
||||||
|
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_ResolveReject()
|
||||||
|
{
|
||||||
|
TestLogger logger;
|
||||||
|
constexpr std::array<std::tuple<bool, JS::PromiseState>, 2> testSteps{{
|
||||||
|
{false, JS::PromiseState::Fulfilled},
|
||||||
|
{true, JS::PromiseState::Rejected}}};
|
||||||
|
|
||||||
|
const ScriptRequest rq{g_GUI->GetScriptInterface()};
|
||||||
|
|
||||||
|
const Script::StructuredClone undefined{
|
||||||
|
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue)};
|
||||||
|
g_GUI->PushPage(L"regainFocus/page_emptyPage.xml", undefined);
|
||||||
|
|
||||||
|
|
||||||
|
for (const auto& [reject, result] : testSteps)
|
||||||
|
{
|
||||||
|
const JS::RootedValue value{rq.cx, JS::BooleanValue(reject)};
|
||||||
|
const Script::StructuredClone clonedValue{Script::WriteStructuredClone(rq, value)};
|
||||||
|
|
||||||
|
const JS::RootedValue promise{rq.cx,
|
||||||
|
g_GUI->PushPage(L"resolveReject/page_resolveReject.xml", clonedValue)};
|
||||||
|
|
||||||
|
// Check if some promise are setteled and flush the promise-jobQueue.
|
||||||
|
g_GUI->TickObjects();
|
||||||
|
const JS::RootedObject promiseObject{rq.cx, &promise.toObject()};
|
||||||
|
TS_ASSERT_EQUALS(JS::GetPromiseState(promiseObject), result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_Sequential()
|
||||||
|
{
|
||||||
|
const ScriptRequest rq{g_GUI->GetScriptInterface()};
|
||||||
|
const Script::StructuredClone undefined{
|
||||||
|
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue)};
|
||||||
|
g_GUI->PushPage(L"sequential/page_sequential.xml", undefined);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user