Skip to content

Commit

Permalink
chore: move to window_test.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Jan 19, 2022
1 parent 057125e commit b5d4a69
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 20 additions & 0 deletions bridge/bindings/qjs/bom/window_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,23 @@ cancelAnimationFrame(id);
bridge->evaluateScript(code.c_str(), code.size(), "vm://", 0);
TEST_runLoop(bridge->getContext());
}

TEST(Window, postMessage) {
auto bridge = TEST_init();
static bool logCalled = false;
kraken::KrakenPage::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) {
logCalled = true;
EXPECT_STREQ(message.c_str(), "{\"data\":1234} ");
};

std::string code = std::string(R"(
window.onmessage = (message) => {
console.log(JSON.stringify(message.data), message.origin);
};
window.postMessage({
data: 1234
}, '*');
)");
bridge->evaluateScript(code.c_str(), code.size(), "vm://", 0);
EXPECT_EQ(logCalled, true);
}
20 changes: 0 additions & 20 deletions bridge/bindings/qjs/js_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ TEST(Context, isValid) {
EXPECT_EQ(bridge->getContext()->isValid(), true);
}

TEST(Context, postMessage) {
auto bridge = TEST_init();
static bool logCalled = false;
kraken::KrakenPage::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) {
logCalled = true;
EXPECT_STREQ(message.c_str(), "{\"data\":1234} ");
};

std::string code = std::string(R"(
window.onmessage = (message) => {
console.log(JSON.stringify(message.data), message.origin);
};
window.postMessage({
data: 1234
}, '*');
)");
bridge->evaluateScript(code.c_str(), code.size(), "vm://", 0);
EXPECT_EQ(logCalled, true);
}

TEST(Context, evalWithError) {
static bool errorHandlerExecuted = false;
auto errorHandler = [](int32_t contextId, const char* errmsg) {
Expand Down

0 comments on commit b5d4a69

Please sign in to comment.