This source file includes following definitions.
- AssertStackFrameValid
- AssertStackFrameInvalid
- TEST
#include "extensions/common/stack_frame.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::UTF8ToUTF16;
namespace extensions {
namespace {
void AssertStackFrameValid(const std::string& text,
size_t line,
size_t column,
const std::string& source,
const std::string& function) {
base::string16 utf16_text = base::UTF8ToUTF16(text);
scoped_ptr<StackFrame> frame = StackFrame::CreateFromText(utf16_text);
ASSERT_TRUE(frame.get()) << "Failed to create frame from '" << text << "'";
EXPECT_EQ(line, frame->line_number());
EXPECT_EQ(column, frame->column_number());
EXPECT_EQ(base::UTF8ToUTF16(source), frame->source());
EXPECT_EQ(base::UTF8ToUTF16(function), frame->function());
}
void AssertStackFrameInvalid(const std::string& text) {
base::string16 utf16_text = base::UTF8ToUTF16(text);
scoped_ptr<StackFrame> frame = StackFrame::CreateFromText(utf16_text);
ASSERT_FALSE(frame.get()) << "Errantly created frame from '" << text << "'";
}
}
TEST(StackFrameUnitTest, ParseStackFramesFromText) {
AssertStackFrameValid(
"function_name (https://www.url.com/foo.html:100:201)",
100u, 201u, "https://www.url.com/foo.html", "function_name");
AssertStackFrameValid(
"(anonymous function) (https://www.url.com/foo.html:100:201)",
100u, 201u, "https://www.url.com/foo.html", "(anonymous function)");
AssertStackFrameValid(
"Function.target.(anonymous function) (internals::SafeBuiltins:19:14)",
19u, 14u, "internals::SafeBuiltins",
"Function.target.(anonymous function)");
AssertStackFrameValid(
"internal-item:://fpgohbggpmcpeedljibghijiclejiklo/script.js:6:12",
6u, 12u, "internal-item:://fpgohbggpmcpeedljibghijiclejiklo/script.js",
"(anonymous function)");
AssertStackFrameInvalid(
"function_name (https://www.url.com/foo.html:100201)");
AssertStackFrameInvalid("function_name (https://www.url.com/foo.html::201)");
AssertStackFrameInvalid("function_name (https://www.url.com/foo.html201)");
AssertStackFrameInvalid(
"function_name https://www.url.com/foo.html:100:201)");
AssertStackFrameInvalid(
"function_name (https://www.url.com/foo.html:100:201");
AssertStackFrameInvalid(
"function_name (https://www.url.com/foo.html:100:201) ");
AssertStackFrameInvalid(
"function_name (https://www.url.com/foo.html:100:201a)");
AssertStackFrameInvalid(
"function_name (https://www.url.com/foo.html:100:-201)");
AssertStackFrameInvalid(
"function_name (https://www.url.com/foo.html:100:201))");
}
}