| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/performance_logger.h" | 5 #include "chrome/test/chromedriver/performance_logger.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 void ExpectCommand(FakeDevToolsClient& client, const std::string& method) { | 164 void ExpectCommand(FakeDevToolsClient& client, const std::string& method) { |
| 165 DevToolsCommand* cmd; | 165 DevToolsCommand* cmd; |
| 166 // Use ASSERT so that test fails if no command is returned. | 166 // Use ASSERT so that test fails if no command is returned. |
| 167 ASSERT_TRUE(client.PopSentCommand(&cmd)); | 167 ASSERT_TRUE(client.PopSentCommand(&cmd)); |
| 168 EXPECT_EQ(method, cmd->method); | 168 EXPECT_EQ(method, cmd->method); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void ExpectEnableDomains(FakeDevToolsClient& client) { | 171 void ExpectEnableDomains(FakeDevToolsClient& client) { |
| 172 ExpectCommand(client, "Network.enable"); | 172 ExpectCommand(client, "Network.enable"); |
| 173 ExpectCommand(client, "Page.enable"); | 173 ExpectCommand(client, "Page.enable"); |
| 174 ExpectCommand(client, "Timeline.start"); | |
| 175 } | 174 } |
| 176 | 175 |
| 177 } // namespace | 176 } // namespace |
| 178 | 177 |
| 179 TEST(PerformanceLogger, OneWebView) { | 178 TEST(PerformanceLogger, OneWebView) { |
| 180 FakeDevToolsClient client("webview-1"); | 179 FakeDevToolsClient client("webview-1"); |
| 181 FakeLog log; | 180 FakeLog log; |
| 182 Session session("test"); | 181 Session session("test"); |
| 183 PerformanceLogger logger(&log, &session); | 182 PerformanceLogger logger(&log, &session); |
| 184 | 183 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 208 logger.OnConnected(&client2); | 207 logger.OnConnected(&client2); |
| 209 ExpectEnableDomains(client1); | 208 ExpectEnableDomains(client1); |
| 210 ExpectEnableDomains(client2); | 209 ExpectEnableDomains(client2); |
| 211 // OnConnected sends the enable command only to that client, not others. | 210 // OnConnected sends the enable command only to that client, not others. |
| 212 client1.ConnectIfNecessary(); | 211 client1.ConnectIfNecessary(); |
| 213 ExpectEnableDomains(client1); | 212 ExpectEnableDomains(client1); |
| 214 DevToolsCommand* cmd; | 213 DevToolsCommand* cmd; |
| 215 ASSERT_FALSE(client2.PopSentCommand(&cmd)); | 214 ASSERT_FALSE(client2.PopSentCommand(&cmd)); |
| 216 | 215 |
| 217 ASSERT_EQ(kOk, client1.TriggerEvent("Page.gaga1").code()); | 216 ASSERT_EQ(kOk, client1.TriggerEvent("Page.gaga1").code()); |
| 218 ASSERT_EQ(kOk, client2.TriggerEvent("Timeline.gaga2").code()); | 217 ASSERT_EQ(kOk, client2.TriggerEvent("Network.gaga2").code()); |
| 219 | 218 |
| 220 ASSERT_EQ(2u, log.GetEntries().size()); | 219 ASSERT_EQ(2u, log.GetEntries().size()); |
| 221 ValidateLogEntry(log.GetEntries()[0], "webview-1", "Page.gaga1"); | 220 ValidateLogEntry(log.GetEntries()[0], "webview-1", "Page.gaga1"); |
| 222 ValidateLogEntry(log.GetEntries()[1], "webview-2", "Timeline.gaga2"); | 221 ValidateLogEntry(log.GetEntries()[1], "webview-2", "Network.gaga2"); |
| 223 } | 222 } |
| 224 | 223 |
| 225 TEST(PerformanceLogger, PerfLoggingPrefs) { | 224 TEST(PerformanceLogger, PerfLoggingPrefs) { |
| 226 FakeDevToolsClient client("webview-1"); | 225 FakeDevToolsClient client("webview-1"); |
| 227 FakeLog log; | 226 FakeLog log; |
| 228 Session session("test"); | 227 Session session("test"); |
| 229 PerfLoggingPrefs prefs; | 228 PerfLoggingPrefs prefs; |
| 230 EXPECT_EQ(PerfLoggingPrefs::InspectorDomainStatus::kDefaultEnabled, | 229 EXPECT_EQ(PerfLoggingPrefs::InspectorDomainStatus::kDefaultEnabled, |
| 231 prefs.network); | 230 prefs.network); |
| 232 prefs.network = PerfLoggingPrefs::InspectorDomainStatus::kExplicitlyDisabled; | 231 prefs.network = PerfLoggingPrefs::InspectorDomainStatus::kExplicitlyDisabled; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 std::string webview; | 372 std::string webview; |
| 374 EXPECT_TRUE(message->GetString("webview", &webview)); | 373 EXPECT_TRUE(message->GetString("webview", &webview)); |
| 375 EXPECT_EQ(DevToolsClientImpl::kBrowserwideDevToolsClientId, webview); | 374 EXPECT_EQ(DevToolsClientImpl::kBrowserwideDevToolsClientId, webview); |
| 376 std::string method; | 375 std::string method; |
| 377 EXPECT_TRUE(message->GetString("message.method", &method)); | 376 EXPECT_TRUE(message->GetString("message.method", &method)); |
| 378 EXPECT_EQ("Tracing.bufferUsage", method); | 377 EXPECT_EQ("Tracing.bufferUsage", method); |
| 379 base::DictionaryValue* actual_params; | 378 base::DictionaryValue* actual_params; |
| 380 EXPECT_TRUE(message->GetDictionary("message.params", &actual_params)); | 379 EXPECT_TRUE(message->GetDictionary("message.params", &actual_params)); |
| 381 EXPECT_TRUE(actual_params->HasKey("error")); | 380 EXPECT_TRUE(actual_params->HasKey("error")); |
| 382 } | 381 } |
| OLD | NEW |