Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: content/common/content_debug_logging_unittest.cc

Issue 10908130: Revert 155122 - Code to collect issue 97285 debugging info for crash reports. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/content_debug_logging.cc ('k') | content/common/plugin_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/public/common/content_debug_logging.h"
6
7 #include <map>
8 #include <string>
9 #include <vector>
10
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14
15 // Makes sure that the handlers are cleared during teardown.
16 class ContentDebugLoggingTest : public testing::Test {
17 public:
18 ContentDebugLoggingTest() {}
19 virtual ~ContentDebugLoggingTest() {}
20
21 void SetUp() {
22 messages = &messages_storage;
23 content::debug::RegisterMessageHandlers(
24 ContentDebugLoggingTest::RecordMsg,
25 ContentDebugLoggingTest::GetMessages);
26 }
27
28 void TearDown() {
29 // Clean up side effects.
30 content::debug::RegisterMessageHandlers(NULL, NULL);
31 messages = NULL;
32 }
33
34 static void RecordMsg(int bug_id, const std::string& msg) {
35 if (messages)
36 (*messages)[bug_id].push_back(msg);
37 }
38
39 static bool GetMessages(int bug_id, std::vector<std::string>* msgs) {
40 if (!messages) {
41 msgs->clear();
42 return false;
43 }
44
45 *msgs = (*messages)[bug_id];
46 return true;
47 }
48
49 // bug_id -> messages for that id.
50 typedef std::map<int, std::vector<std::string> > MessageMap;
51 MessageMap messages_storage;
52
53 // Points to messages_storage while running tests.
54 static MessageMap* messages;
55 };
56
57 // static
58 ContentDebugLoggingTest::MessageMap* ContentDebugLoggingTest::messages = NULL;
59
60 TEST_F(ContentDebugLoggingTest, NullLogging) {
61 content::debug::RegisterMessageHandlers(NULL, NULL);
62
63 const std::string kMessage("This is a test");
64 const int kBug = 1;
65 content::debug::RecordMsg(kBug, kMessage);
66
67 // Cannot get the message back.
68 std::vector<std::string> bug_messages;
69 EXPECT_FALSE(content::debug::GetMessages(kBug, &bug_messages));
70 EXPECT_EQ(bug_messages.size(), 0u);
71 }
72
73 TEST_F(ContentDebugLoggingTest, BasicLogging) {
74 const std::string kMessage1("This is a test");
75 const std::string kMessage2("That was a test");
76 const int kBug = 1;
77
78 // Distinguish ability to retrieve messages from presence of
79 // messages.
80 std::vector<std::string> bug_messages;
81 EXPECT_TRUE(content::debug::GetMessages(kBug, &bug_messages));
82 EXPECT_EQ(bug_messages.size(), 0u);
83
84 // Message is stored and can be retrieved.
85 content::debug::RecordMsg(kBug, kMessage1);
86 EXPECT_TRUE(content::debug::GetMessages(kBug, &bug_messages));
87 ASSERT_EQ(bug_messages.size(), 1u);
88 EXPECT_EQ(bug_messages[0], kMessage1);
89
90 // Messages are returned in recorded order.
91 content::debug::RecordMsg(kBug, kMessage2);
92 EXPECT_TRUE(content::debug::GetMessages(kBug, &bug_messages));
93 ASSERT_EQ(bug_messages.size(), 2u);
94 EXPECT_EQ(bug_messages[0], kMessage1);
95 EXPECT_EQ(bug_messages[1], kMessage2);
96 }
97
98 TEST_F(ContentDebugLoggingTest, SeparateBugs) {
99 const std::string kMessage("This is a test");
100 const int kBug = 1;
101 content::debug::RecordMsg(kBug, kMessage);
102 content::debug::RecordMsg(17, std::string("Some other message"));
103
104 // Only get the message for this bug back.
105 std::vector<std::string> bug_messages;
106 EXPECT_TRUE(content::debug::GetMessages(kBug, &bug_messages));
107 ASSERT_EQ(bug_messages.size(), 1u);
108 EXPECT_EQ(bug_messages[0], kMessage);
109
110 // There are messages for multiple bugs, though.
111 EXPECT_EQ(messages->size(), 2u);
112 }
113
114 } // namespace
OLDNEW
« no previous file with comments | « content/common/content_debug_logging.cc ('k') | content/common/plugin_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698