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

Side by Side Diff: chrome/test/chromedriver/logging_unittest.cc

Issue 14591005: C++ readability review from original change https://chromiumcodereview.appspot.com/14263024/ (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Rewrite ConsoleLogger::OnEvent from stringstream to printf. Created 7 years, 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/test/chromedriver/logging.h" 5 #include "chrome/test/chromedriver/logging.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/test/chromedriver/capabilities.h" 8 #include "chrome/test/chromedriver/capabilities.h"
9 #include "chrome/test/chromedriver/chrome/devtools_event_listener.h" 9 #include "chrome/test/chromedriver/chrome/devtools_event_listener.h"
10 #include "chrome/test/chromedriver/chrome/status.h" 10 #include "chrome/test/chromedriver/chrome/status.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace { 13 namespace {
14 14
15 static const char* kAllWdLevels[] = { 15 static const char* kAllWdLevels[] = {
jdennett 2013/05/23 03:44:24 +const
klm 2013/05/23 15:21:39 Done.
16 "ALL", "DEBUG", "INFO", "WARNING", "SEVERE", "OFF" 16 "ALL", "DEBUG", "INFO", "WARNING", "SEVERE", "OFF"
17 }; 17 };
18 18
19 } 19 }
20 20
21 TEST(Logging, NameLevelConversionHappy) { 21 TEST(Logging, NameLevelConversionHappy) {
22 // All names map to a valid enum value. 22 // All names map to a valid enum value.
23 for (int i = 0; static_cast<size_t>(i) < arraysize(kAllWdLevels); ++i) { 23 for (int i = 0; static_cast<size_t>(i) < arraysize(kAllWdLevels); ++i) {
24 WebDriverLog::WebDriverLevel level = 24 WebDriverLog::WebDriverLevel level =
25 static_cast<WebDriverLog::WebDriverLevel>(-1); 25 static_cast<WebDriverLog::WebDriverLevel>(-1);
(...skipping 13 matching lines...) Expand all
39 EXPECT_FALSE(WebDriverLog::NameToLevel("T", &level)); 39 EXPECT_FALSE(WebDriverLog::NameToLevel("T", &level));
40 EXPECT_FALSE(WebDriverLog::NameToLevel("Z", &level)); 40 EXPECT_FALSE(WebDriverLog::NameToLevel("Z", &level));
41 // The level variable was never modified. 41 // The level variable was never modified.
42 EXPECT_EQ(static_cast<WebDriverLog::WebDriverLevel>(-1), level); 42 EXPECT_EQ(static_cast<WebDriverLog::WebDriverLevel>(-1), level);
43 } 43 }
44 44
45 namespace { 45 namespace {
46 46
47 void ValidateLogEntry(base::ListValue *entries, 47 void ValidateLogEntry(base::ListValue *entries,
48 int index, 48 int index,
49 const char* expect_level, 49 const char* expected_level,
50 const char* expect_message) { 50 const char* expected_message) {
51 const base::DictionaryValue *entry; 51 const base::DictionaryValue *entry;
52 ASSERT_TRUE(entries->GetDictionary(index, &entry)); 52 ASSERT_TRUE(entries->GetDictionary(index, &entry));
53 std::string level; 53 std::string level;
54 EXPECT_TRUE(entry->GetString("level", &level)); 54 EXPECT_TRUE(entry->GetString("level", &level));
55 EXPECT_STREQ(expect_level, level.c_str()); 55 EXPECT_EQ(expected_level, level);
56 std::string message; 56 std::string message;
57 ASSERT_TRUE(entry->GetString("message", &message)); 57 ASSERT_TRUE(entry->GetString("message", &message));
58 EXPECT_STREQ(expect_message, message.c_str()); 58 EXPECT_EQ(expected_message, message);
59 double timestamp = 0; 59 double timestamp = 0;
60 EXPECT_TRUE(entry->GetDouble("timestamp", &timestamp)); 60 EXPECT_TRUE(entry->GetDouble("timestamp", &timestamp));
61 EXPECT_LT(0, timestamp); 61 EXPECT_LT(0, timestamp);
62 } 62 }
63 63
64 } 64 }
65 65
66 TEST(WebDriverLog, Levels) { 66 TEST(WebDriverLog, Levels) {
67 WebDriverLog log("type", WebDriverLog::kWdInfo); 67 WebDriverLog log("type", WebDriverLog::kWdInfo);
68 log.AddEntry(Log::kLog, std::string("info message")); 68 log.AddEntry(Log::kLog, std::string("info message"));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 Capabilities capabilities; 102 Capabilities capabilities;
103 capabilities.logging_prefs.reset(new base::DictionaryValue()); 103 capabilities.logging_prefs.reset(new base::DictionaryValue());
104 capabilities.logging_prefs->SetString("performance", "INFO"); 104 capabilities.logging_prefs->SetString("performance", "INFO");
105 105
106 ScopedVector<DevToolsEventListener> listeners; 106 ScopedVector<DevToolsEventListener> listeners;
107 ScopedVector<WebDriverLog> logs; 107 ScopedVector<WebDriverLog> logs;
108 Status status = CreateLogs(capabilities, &logs, &listeners); 108 Status status = CreateLogs(capabilities, &logs, &listeners);
109 ASSERT_TRUE(status.IsOk()); 109 ASSERT_TRUE(status.IsOk());
110 ASSERT_EQ(2u, logs.size()); 110 ASSERT_EQ(2u, logs.size());
111 ASSERT_EQ(2u, listeners.size()); 111 ASSERT_EQ(2u, listeners.size());
112 ASSERT_STREQ("performance", logs[0]->GetType().c_str()); 112 ASSERT_EQ("performance", logs[0]->GetType());
113 ASSERT_STREQ("browser", logs[1]->GetType().c_str()); // Always created. 113 ASSERT_EQ("browser", logs[1]->GetType()); // Always created.
114 } 114 }
115 115
116 TEST(Logging, CreateBrowserLogOff) { 116 TEST(Logging, CreateBrowserLogOff) {
117 Capabilities capabilities; 117 Capabilities capabilities;
118 capabilities.logging_prefs.reset(new base::DictionaryValue()); 118 capabilities.logging_prefs.reset(new base::DictionaryValue());
119 capabilities.logging_prefs->SetString("browser", "OFF"); 119 capabilities.logging_prefs->SetString("browser", "OFF");
120 120
121 ScopedVector<DevToolsEventListener> listeners; 121 ScopedVector<DevToolsEventListener> listeners;
122 ScopedVector<WebDriverLog> logs; 122 ScopedVector<WebDriverLog> logs;
123 Status status = CreateLogs(capabilities, &logs, &listeners); 123 Status status = CreateLogs(capabilities, &logs, &listeners);
124 ASSERT_TRUE(status.IsOk()); 124 ASSERT_TRUE(status.IsOk());
125 ASSERT_EQ(1u, logs.size()); 125 ASSERT_EQ(1u, logs.size());
126 ASSERT_EQ(0u, listeners.size()); 126 ASSERT_EQ(0u, listeners.size());
127 ASSERT_STREQ("browser", logs[0]->GetType().c_str()); 127 ASSERT_EQ("browser", logs[0]->GetType());
128 128
129 // Verify the created log is "OFF" -- drops all messages. 129 // Verify the created log is "OFF" -- drops all messages.
130 logs[0]->AddEntry(Log::kError, "drop even errors"); 130 logs[0]->AddEntry(Log::kError, "drop even errors");
131 scoped_ptr<base::ListValue> entries(logs[0]->GetAndClearEntries()); 131 scoped_ptr<base::ListValue> entries(logs[0]->GetAndClearEntries());
132 ASSERT_EQ(0u, entries->GetSize()); 132 ASSERT_EQ(0u, entries->GetSize());
133 } 133 }
134 134
135 TEST(Logging, IgnoreUnknownLogType) { 135 TEST(Logging, IgnoreUnknownLogType) {
136 Capabilities capabilities; 136 Capabilities capabilities;
137 capabilities.logging_prefs.reset(new base::DictionaryValue()); 137 capabilities.logging_prefs.reset(new base::DictionaryValue());
138 capabilities.logging_prefs->SetString("gaga", "INFO"); 138 capabilities.logging_prefs->SetString("gaga", "INFO");
139 139
140 ScopedVector<DevToolsEventListener> listeners; 140 ScopedVector<DevToolsEventListener> listeners;
141 ScopedVector<WebDriverLog> logs; 141 ScopedVector<WebDriverLog> logs;
142 Status status = CreateLogs(capabilities, &logs, &listeners); 142 Status status = CreateLogs(capabilities, &logs, &listeners);
143 EXPECT_TRUE(status.IsOk()); 143 EXPECT_TRUE(status.IsOk());
144 ASSERT_EQ(1u, logs.size()); 144 ASSERT_EQ(1u, logs.size());
145 ASSERT_EQ(1u, listeners.size()); 145 ASSERT_EQ(1u, listeners.size());
146 ASSERT_STREQ("browser", logs[0]->GetType().c_str()); 146 ASSERT_EQ("browser", logs[0]->GetType());
147 } 147 }
148 148
149 TEST(Logging, BrowserLogCreatedWithoutLoggingPrefs) { 149 TEST(Logging, BrowserLogCreatedWithoutLoggingPrefs) {
150 Capabilities capabilities; 150 Capabilities capabilities;
151 151
152 ScopedVector<DevToolsEventListener> listeners; 152 ScopedVector<DevToolsEventListener> listeners;
153 ScopedVector<WebDriverLog> logs; 153 ScopedVector<WebDriverLog> logs;
154 Status status = CreateLogs(capabilities, &logs, &listeners); 154 Status status = CreateLogs(capabilities, &logs, &listeners);
155 EXPECT_TRUE(status.IsOk()); 155 EXPECT_TRUE(status.IsOk());
156 ASSERT_EQ(1u, logs.size()); 156 ASSERT_EQ(1u, logs.size());
157 ASSERT_EQ(1u, listeners.size()); 157 ASSERT_EQ(1u, listeners.size());
158 ASSERT_STREQ("browser", logs[0]->GetType().c_str()); 158 ASSERT_EQ("browser", logs[0]->GetType());
159 159
160 // Verify the created "browser" log is "INFO" level. 160 // Verify the created "browser" log is "INFO" level.
161 logs[0]->AddEntry(Log::kLog, "info message"); 161 logs[0]->AddEntry(Log::kLog, "info message");
162 logs[0]->AddEntry(Log::kDebug, "drop debug message"); 162 logs[0]->AddEntry(Log::kDebug, "drop debug message");
163 scoped_ptr<base::ListValue> entries(logs[0]->GetAndClearEntries()); 163 scoped_ptr<base::ListValue> entries(logs[0]->GetAndClearEntries());
164 ASSERT_EQ(1u, entries->GetSize()); 164 ASSERT_EQ(1u, entries->GetSize());
165 ValidateLogEntry(entries.get(), 0, "INFO", "info message"); 165 ValidateLogEntry(entries.get(), 0, "INFO", "info message");
166 } 166 }
OLDNEW
« chrome/test/chromedriver/logging.cc ('K') | « chrome/test/chromedriver/logging.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698