summaryrefslogtreecommitdiffstats
path: root/extensions/common/stack_frame_unittest.cc
diff options
context:
space:
mode:
authorrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-01 23:05:06 +0000
committerrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-01 23:05:06 +0000
commit88b50b690f0d8a401c26a04c359b92f35c673bc2 (patch)
tree465646720a68f2b81a3c5012c568d322c022dad8 /extensions/common/stack_frame_unittest.cc
parent21160f0ea8f9f4a3f6be78d9c4331ecb748cf73a (diff)
downloadchromium_src-88b50b690f0d8a401c26a04c359b92f35c673bc2.zip
chromium_src-88b50b690f0d8a401c26a04c359b92f35c673bc2.tar.gz
chromium_src-88b50b690f0d8a401c26a04c359b92f35c673bc2.tar.bz2
Report Javascript Runtime Errors to the Error Console
TBR=brettw@chromium.org (moving DEPS file from extensions/common/matcher to extensions/common). BUG=21734 Review URL: https://chromiumcodereview.appspot.com/23007021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220753 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/common/stack_frame_unittest.cc')
-rw-r--r--extensions/common/stack_frame_unittest.cc85
1 files changed, 85 insertions, 0 deletions
diff --git a/extensions/common/stack_frame_unittest.cc b/extensions/common/stack_frame_unittest.cc
new file mode 100644
index 0000000..7dad047
--- /dev/null
+++ b/extensions/common/stack_frame_unittest.cc
@@ -0,0 +1,85 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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 = 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(UTF8ToUTF16(source), frame->source());
+ EXPECT_EQ(UTF8ToUTF16(function), frame->function());
+}
+
+void AssertStackFrameInvalid(const std::string& text) {
+ base::string16 utf16_text = UTF8ToUTF16(text);
+ scoped_ptr<StackFrame> frame = StackFrame::CreateFromText(utf16_text);
+ ASSERT_FALSE(frame.get()) << "Errantly created frame from '" << text << "'";
+}
+
+} // namespace
+
+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)");
+
+ // No delimiting ':' between line/column numbers.
+ AssertStackFrameInvalid(
+ "function_name (https://www.url.com/foo.html:100201)");
+ // No line number.
+ AssertStackFrameInvalid("function_name (https://www.url.com/foo.html::201)");
+ // No line number or delimiting ':'.
+ AssertStackFrameInvalid("function_name (https://www.url.com/foo.html201)");
+ // No leading '(' around url, line, column.
+ AssertStackFrameInvalid(
+ "function_name https://www.url.com/foo.html:100:201)");
+ // No trailing ')'.
+ AssertStackFrameInvalid(
+ "function_name (https://www.url.com/foo.html:100:201");
+ // Trailing ' '.
+ AssertStackFrameInvalid(
+ "function_name (https://www.url.com/foo.html:100:201) ");
+ // Invalid column number.
+ AssertStackFrameInvalid(
+ "function_name (https://www.url.com/foo.html:100:201a)");
+ // Negative column number.
+ AssertStackFrameInvalid(
+ "function_name (https://www.url.com/foo.html:100:-201)");
+ // Extra trailing ')'
+ AssertStackFrameInvalid(
+ "function_name (https://www.url.com/foo.html:100:201))");
+}
+
+} // namespace extensions