This source file includes following definitions.
- TEST_F
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/extension_api_unittest.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "extensions/browser/api/test/test_api.h"
namespace extensions {
namespace {
const char kTestMessage[] = "test message";
const char kTestMessage2[] = "test message 2";
const char kFailureMessage[] = "failure";
}
class ExtensionTestMessageListenerUnittest : public ExtensionApiUnittest {};
TEST_F(ExtensionTestMessageListenerUnittest, BasicTestExtensionMessageTest) {
{
ExtensionTestMessageListener listener(kTestMessage, false);
EXPECT_FALSE(listener.was_satisfied());
RunFunction(new TestSendMessageFunction,
base::StringPrintf("[\"%s\"]", kTestMessage));
EXPECT_TRUE(listener.was_satisfied());
EXPECT_EQ(kTestMessage, listener.message());
}
{
ExtensionTestMessageListener listener(false);
EXPECT_FALSE(listener.was_satisfied());
RunFunction(new TestSendMessageFunction,
base::StringPrintf("[\"%s\"]", kTestMessage2));
EXPECT_TRUE(listener.was_satisfied());
EXPECT_EQ(kTestMessage2, listener.message());
}
{
ExtensionTestMessageListener listener(false);
EXPECT_FALSE(listener.was_satisfied());
RunFunction(new TestSendMessageFunction,
base::StringPrintf("[\"%s\"]", kTestMessage));
EXPECT_EQ(kTestMessage, listener.message());
EXPECT_TRUE(listener.was_satisfied());
listener.Reset();
EXPECT_FALSE(listener.was_satisfied());
EXPECT_EQ(base::EmptyString(), listener.message());
RunFunction(new TestSendMessageFunction,
base::StringPrintf("[\"%s\"]", kTestMessage2));
EXPECT_TRUE(listener.was_satisfied());
EXPECT_EQ(kTestMessage2, listener.message());
}
{
ExtensionTestMessageListener listener(kTestMessage, false);
listener.set_failure_message(kFailureMessage);
RunFunction(new TestSendMessageFunction,
base::StringPrintf("[\"%s\"]", kTestMessage));
EXPECT_TRUE(listener.WaitUntilSatisfied());
EXPECT_EQ(kTestMessage, listener.message());
listener.Reset();
RunFunction(new TestSendMessageFunction,
base::StringPrintf("[\"%s\"]", kFailureMessage));
EXPECT_FALSE(listener.WaitUntilSatisfied());
EXPECT_EQ(kFailureMessage, listener.message());
}
}
}