This source file includes following definitions.
- RegisterTestModule
- SetUp
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "base/strings/stringprintf.h"
#include "chrome/test/base/module_system_test.h"
#include "grit/renderer_resources.h"
namespace extensions {
namespace {
class MessagingUtilsUnittest : public ModuleSystemTest {
protected:
void RegisterTestModule(const char* code) {
RegisterModule("test", base::StringPrintf(
"var assert = requireNative('assert');\n"
"var AssertTrue = assert.AssertTrue;\n"
"var AssertFalse = assert.AssertFalse;\n"
"var messagingUtils = require('messaging_utils');\n"
"%s", code));
}
private:
virtual void SetUp() OVERRIDE {
ModuleSystemTest::SetUp();
RegisterModule("messaging_utils", IDR_MESSAGING_UTILS_JS);
}
};
TEST_F(MessagingUtilsUnittest, TestNothing) {
ExpectNoAssertionsMade();
}
TEST_F(MessagingUtilsUnittest, NoArguments) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var args = messagingUtils.alignSendMessageArguments();\n"
"AssertTrue(args === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, ZeroArguments) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var args = messagingUtils.alignSendMessageArguments([]);"
"AssertTrue(args === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, TooManyArgumentsNoOptions) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var args = messagingUtils.alignSendMessageArguments(\n"
" ['a', 'b', 'c', 'd']);\n"
"AssertTrue(args === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, TooManyArgumentsWithOptions) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var args = messagingUtils.alignSendMessageArguments(\n"
" ['a', 'b', 'c', 'd', 'e'], true);\n"
"AssertTrue(args === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, FinalArgumentIsNotAFunctionNoOptions) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var args = messagingUtils.alignSendMessageArguments(\n"
" ['a', 'b', 'c']);\n"
"AssertTrue(args === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, FinalArgumentIsNotAFunctionWithOptions) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var args = messagingUtils.alignSendMessageArguments(\n"
" ['a', 'b', 'c', 'd'], true);\n"
"AssertTrue(args === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, OneStringArgument) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var args = messagingUtils.alignSendMessageArguments(['a']);\n"
"AssertTrue(args.length == 3);\n"
"AssertTrue(args[0] === null);\n"
"AssertTrue(args[1] == 'a');\n"
"AssertTrue(args[2] === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, OneStringAndOneNullArgument) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var args = messagingUtils.alignSendMessageArguments(['a', null]);\n"
"AssertTrue(args.length == 3);\n"
"AssertTrue(args[0] == 'a');\n"
"AssertTrue(args[1] === null);\n"
"AssertTrue(args[2] === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, OneNullAndOneStringArgument) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var args = messagingUtils.alignSendMessageArguments([null, 'a']);\n"
"AssertTrue(args.length == 3);\n"
"AssertTrue(args[0] === null);\n"
"AssertTrue(args[1] == 'a');\n"
"AssertTrue(args[2] === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, OneStringAndOneFunctionArgument) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var cb = function() {};\n"
"var args = messagingUtils.alignSendMessageArguments(['a', cb]);\n"
"AssertTrue(args.length == 3);\n"
"AssertTrue(args[0] === null);\n"
"AssertTrue(args[1] == 'a');\n"
"AssertTrue(args[2] == cb);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, OneStringAndOneObjectArgument) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var obj = {'b': true};\n"
"var args = messagingUtils.alignSendMessageArguments(['a', obj], true);\n"
"AssertTrue(args.length == 4);\n"
"AssertTrue(args[0] == 'a');\n"
"AssertTrue(args[1] == obj);\n"
"AssertTrue(args[2] === null);\n"
"AssertTrue(args[3] === null);");
context_->module_system()->Require("test");
}
TEST_F(MessagingUtilsUnittest, TwoObjectArguments) {
ModuleSystem::NativesEnabledScope natives_enabled_scope(
context_->module_system());
RegisterTestModule(
"var obj1 = {'a': 'foo'};\n"
"var obj2 = {'b': 'bar'};\n"
"var args = messagingUtils.alignSendMessageArguments(\n"
" [obj1, obj2], true);\n"
"AssertTrue(args.length == 4);\n"
"AssertTrue(args[0] === null);\n"
"AssertTrue(args[1] == obj1);\n"
"AssertTrue(args[2] == obj2);\n"
"AssertTrue(args[3] === null);");
context_->module_system()->Require("test");
}
}
}