OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/common/stack_frame.h" | 5 #include "extensions/common/stack_frame.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 using base::UTF8ToUTF16; | 16 using base::UTF8ToUTF16; |
16 | 17 |
17 namespace extensions { | 18 namespace extensions { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 void AssertStackFrameValid(const std::string& text, | 22 void AssertStackFrameValid(const std::string& text, |
22 size_t line, | 23 size_t line, |
23 size_t column, | 24 size_t column, |
24 const std::string& source, | 25 const std::string& source, |
25 const std::string& function) { | 26 const std::string& function) { |
26 base::string16 utf16_text = base::UTF8ToUTF16(text); | 27 base::string16 utf16_text = base::UTF8ToUTF16(text); |
27 scoped_ptr<StackFrame> frame = StackFrame::CreateFromText(utf16_text); | 28 std::unique_ptr<StackFrame> frame = StackFrame::CreateFromText(utf16_text); |
28 | 29 |
29 ASSERT_TRUE(frame.get()) << "Failed to create frame from '" << text << "'"; | 30 ASSERT_TRUE(frame.get()) << "Failed to create frame from '" << text << "'"; |
30 EXPECT_EQ(line, frame->line_number); | 31 EXPECT_EQ(line, frame->line_number); |
31 EXPECT_EQ(column, frame->column_number); | 32 EXPECT_EQ(column, frame->column_number); |
32 EXPECT_EQ(base::UTF8ToUTF16(source), frame->source); | 33 EXPECT_EQ(base::UTF8ToUTF16(source), frame->source); |
33 EXPECT_EQ(base::UTF8ToUTF16(function), frame->function); | 34 EXPECT_EQ(base::UTF8ToUTF16(function), frame->function); |
34 } | 35 } |
35 | 36 |
36 void AssertStackFrameInvalid(const std::string& text) { | 37 void AssertStackFrameInvalid(const std::string& text) { |
37 base::string16 utf16_text = base::UTF8ToUTF16(text); | 38 base::string16 utf16_text = base::UTF8ToUTF16(text); |
38 scoped_ptr<StackFrame> frame = StackFrame::CreateFromText(utf16_text); | 39 std::unique_ptr<StackFrame> frame = StackFrame::CreateFromText(utf16_text); |
39 ASSERT_FALSE(frame.get()) << "Errantly created frame from '" << text << "'"; | 40 ASSERT_FALSE(frame.get()) << "Errantly created frame from '" << text << "'"; |
40 } | 41 } |
41 | 42 |
42 } // namespace | 43 } // namespace |
43 | 44 |
44 TEST(StackFrameUnitTest, ParseStackFramesFromText) { | 45 TEST(StackFrameUnitTest, ParseStackFramesFromText) { |
45 AssertStackFrameValid( | 46 AssertStackFrameValid( |
46 "function_name (https://www.url.com/foo.html:100:201)", | 47 "function_name (https://www.url.com/foo.html:100:201)", |
47 100u, 201u, "https://www.url.com/foo.html", "function_name"); | 48 100u, 201u, "https://www.url.com/foo.html", "function_name"); |
48 AssertStackFrameValid( | 49 AssertStackFrameValid( |
(...skipping 29 matching lines...) Expand all Loading... |
78 "function_name (https://www.url.com/foo.html:100:201a)"); | 79 "function_name (https://www.url.com/foo.html:100:201a)"); |
79 // Negative column number. | 80 // Negative column number. |
80 AssertStackFrameInvalid( | 81 AssertStackFrameInvalid( |
81 "function_name (https://www.url.com/foo.html:100:-201)"); | 82 "function_name (https://www.url.com/foo.html:100:-201)"); |
82 // Extra trailing ')' | 83 // Extra trailing ')' |
83 AssertStackFrameInvalid( | 84 AssertStackFrameInvalid( |
84 "function_name (https://www.url.com/foo.html:100:201))"); | 85 "function_name (https://www.url.com/foo.html:100:201))"); |
85 } | 86 } |
86 | 87 |
87 } // namespace extensions | 88 } // namespace extensions |
OLD | NEW |