| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/metrics/perf/perf_provider_chromeos.h" | 5 #include "chrome/browser/metrics/perf/perf_provider_chromeos.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | |
| 9 #include <string> | 8 #include <string> |
| 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "base/test/test_simple_task_runner.h" | 15 #include "base/test/test_simple_task_runner.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "chrome/browser/metrics/perf/windowed_incognito_observer.h" | 17 #include "chrome/browser/metrics/perf/windowed_incognito_observer.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "chromeos/login/login_state.h" | 19 #include "chromeos/login/login_state.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 class TestIncognitoObserver : public WindowedIncognitoObserver { | 108 class TestIncognitoObserver : public WindowedIncognitoObserver { |
| 109 public: | 109 public: |
| 110 // Factory function to create a TestIncognitoObserver object contained in a | 110 // Factory function to create a TestIncognitoObserver object contained in a |
| 111 // scoped_ptr<WindowedIncognitoObserver> object. |incognito_launched| | 111 // scoped_ptr<WindowedIncognitoObserver> object. |incognito_launched| |
| 112 // simulates the presence of an open incognito window, or the lack thereof. | 112 // simulates the presence of an open incognito window, or the lack thereof. |
| 113 // Used for passing observers to ParseOutputProtoIfValid(). | 113 // Used for passing observers to ParseOutputProtoIfValid(). |
| 114 static scoped_ptr<WindowedIncognitoObserver> CreateWithIncognitoLaunched( | 114 static scoped_ptr<WindowedIncognitoObserver> CreateWithIncognitoLaunched( |
| 115 bool incognito_launched) { | 115 bool incognito_launched) { |
| 116 scoped_ptr<TestIncognitoObserver> observer(new TestIncognitoObserver); | 116 scoped_ptr<TestIncognitoObserver> observer(new TestIncognitoObserver); |
| 117 observer->set_incognito_launched(incognito_launched); | 117 observer->set_incognito_launched(incognito_launched); |
| 118 return observer.Pass(); | 118 return std::move(observer); |
| 119 } | 119 } |
| 120 | 120 |
| 121 private: | 121 private: |
| 122 TestIncognitoObserver() {} | 122 TestIncognitoObserver() {} |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(TestIncognitoObserver); | 124 DISALLOW_COPY_AND_ASSIGN(TestIncognitoObserver); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 // Allows access to some private methods for testing. | 127 // Allows access to some private methods for testing. |
| 128 class TestPerfProvider : public PerfProvider { | 128 class TestPerfProvider : public PerfProvider { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 TestIncognitoObserver::CreateWithIncognitoLaunched(true)-> | 196 TestIncognitoObserver::CreateWithIncognitoLaunched(true)-> |
| 197 incognito_launched()); | 197 incognito_launched()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 TEST_F(PerfProviderTest, NoPerfData) { | 200 TEST_F(PerfProviderTest, NoPerfData) { |
| 201 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 201 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| 202 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 202 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
| 203 | 203 |
| 204 perf_provider_->ParseOutputProtoIfValid( | 204 perf_provider_->ParseOutputProtoIfValid( |
| 205 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 205 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 206 sampled_profile.Pass(), | 206 std::move(sampled_profile), kPerfSuccess, std::vector<uint8_t>(), |
| 207 kPerfSuccess, | |
| 208 std::vector<uint8_t>(), | |
| 209 std::vector<uint8_t>()); | 207 std::vector<uint8_t>()); |
| 210 | 208 |
| 211 std::vector<SampledProfile> stored_profiles; | 209 std::vector<SampledProfile> stored_profiles; |
| 212 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles)); | 210 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles)); |
| 213 } | 211 } |
| 214 | 212 |
| 215 TEST_F(PerfProviderTest, PerfDataProtoOnly) { | 213 TEST_F(PerfProviderTest, PerfDataProtoOnly) { |
| 216 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 214 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| 217 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 215 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
| 218 | 216 |
| 219 perf_provider_->ParseOutputProtoIfValid( | 217 perf_provider_->ParseOutputProtoIfValid( |
| 220 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 218 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 221 sampled_profile.Pass(), | 219 std::move(sampled_profile), kPerfSuccess, |
| 222 kPerfSuccess, | 220 SerializeMessageToVector(perf_data_proto_), std::vector<uint8_t>()); |
| 223 SerializeMessageToVector(perf_data_proto_), | |
| 224 std::vector<uint8_t>()); | |
| 225 | 221 |
| 226 std::vector<SampledProfile> stored_profiles; | 222 std::vector<SampledProfile> stored_profiles; |
| 227 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles)); | 223 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles)); |
| 228 ASSERT_EQ(1U, stored_profiles.size()); | 224 ASSERT_EQ(1U, stored_profiles.size()); |
| 229 | 225 |
| 230 const SampledProfile& profile = stored_profiles[0]; | 226 const SampledProfile& profile = stored_profiles[0]; |
| 231 EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile.trigger_event()); | 227 EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile.trigger_event()); |
| 232 EXPECT_TRUE(profile.has_ms_after_login()); | 228 EXPECT_TRUE(profile.has_ms_after_login()); |
| 233 | 229 |
| 234 ASSERT_TRUE(profile.has_perf_data()); | 230 ASSERT_TRUE(profile.has_perf_data()); |
| 235 EXPECT_FALSE(profile.has_perf_stat()); | 231 EXPECT_FALSE(profile.has_perf_stat()); |
| 236 EXPECT_EQ(SerializeMessageToVector(perf_data_proto_), | 232 EXPECT_EQ(SerializeMessageToVector(perf_data_proto_), |
| 237 SerializeMessageToVector(profile.perf_data())); | 233 SerializeMessageToVector(profile.perf_data())); |
| 238 } | 234 } |
| 239 | 235 |
| 240 TEST_F(PerfProviderTest, PerfStatProtoOnly) { | 236 TEST_F(PerfProviderTest, PerfStatProtoOnly) { |
| 241 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 237 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| 242 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 238 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
| 243 | 239 |
| 244 perf_provider_->ParseOutputProtoIfValid( | 240 perf_provider_->ParseOutputProtoIfValid( |
| 245 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 241 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 246 sampled_profile.Pass(), | 242 std::move(sampled_profile), kPerfSuccess, std::vector<uint8_t>(), |
| 247 kPerfSuccess, | |
| 248 std::vector<uint8_t>(), | |
| 249 SerializeMessageToVector(perf_stat_proto_)); | 243 SerializeMessageToVector(perf_stat_proto_)); |
| 250 | 244 |
| 251 std::vector<SampledProfile> stored_profiles; | 245 std::vector<SampledProfile> stored_profiles; |
| 252 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles)); | 246 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles)); |
| 253 ASSERT_EQ(1U, stored_profiles.size()); | 247 ASSERT_EQ(1U, stored_profiles.size()); |
| 254 | 248 |
| 255 const SampledProfile& profile = stored_profiles[0]; | 249 const SampledProfile& profile = stored_profiles[0]; |
| 256 EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile.trigger_event()); | 250 EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile.trigger_event()); |
| 257 EXPECT_TRUE(profile.has_ms_after_login()); | 251 EXPECT_TRUE(profile.has_ms_after_login()); |
| 258 | 252 |
| 259 EXPECT_FALSE(profile.has_perf_data()); | 253 EXPECT_FALSE(profile.has_perf_data()); |
| 260 ASSERT_TRUE(profile.has_perf_stat()); | 254 ASSERT_TRUE(profile.has_perf_stat()); |
| 261 EXPECT_EQ(SerializeMessageToVector(perf_stat_proto_), | 255 EXPECT_EQ(SerializeMessageToVector(perf_stat_proto_), |
| 262 SerializeMessageToVector(profile.perf_stat())); | 256 SerializeMessageToVector(profile.perf_stat())); |
| 263 } | 257 } |
| 264 | 258 |
| 265 TEST_F(PerfProviderTest, BothPerfDataProtoAndPerfStatProto) { | 259 TEST_F(PerfProviderTest, BothPerfDataProtoAndPerfStatProto) { |
| 266 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 260 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| 267 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 261 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
| 268 | 262 |
| 269 perf_provider_->ParseOutputProtoIfValid( | 263 perf_provider_->ParseOutputProtoIfValid( |
| 270 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 264 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 271 sampled_profile.Pass(), | 265 std::move(sampled_profile), kPerfSuccess, |
| 272 kPerfSuccess, | |
| 273 SerializeMessageToVector(perf_data_proto_), | 266 SerializeMessageToVector(perf_data_proto_), |
| 274 SerializeMessageToVector(perf_stat_proto_)); | 267 SerializeMessageToVector(perf_stat_proto_)); |
| 275 | 268 |
| 276 std::vector<SampledProfile> stored_profiles; | 269 std::vector<SampledProfile> stored_profiles; |
| 277 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles)); | 270 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles)); |
| 278 EXPECT_TRUE(stored_profiles.empty()); | 271 EXPECT_TRUE(stored_profiles.empty()); |
| 279 } | 272 } |
| 280 | 273 |
| 281 TEST_F(PerfProviderTest, InvalidPerfOutputResult) { | 274 TEST_F(PerfProviderTest, InvalidPerfOutputResult) { |
| 282 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 275 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| 283 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 276 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
| 284 | 277 |
| 285 perf_provider_->ParseOutputProtoIfValid( | 278 perf_provider_->ParseOutputProtoIfValid( |
| 286 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 279 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 287 sampled_profile.Pass(), | 280 std::move(sampled_profile), kPerfFailure, |
| 288 kPerfFailure, | 281 SerializeMessageToVector(perf_data_proto_), std::vector<uint8_t>()); |
| 289 SerializeMessageToVector(perf_data_proto_), | |
| 290 std::vector<uint8_t>()); | |
| 291 | 282 |
| 292 // Should not have been stored. | 283 // Should not have been stored. |
| 293 std::vector<SampledProfile> stored_profiles; | 284 std::vector<SampledProfile> stored_profiles; |
| 294 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles)); | 285 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles)); |
| 295 EXPECT_TRUE(stored_profiles.empty()); | 286 EXPECT_TRUE(stored_profiles.empty()); |
| 296 } | 287 } |
| 297 | 288 |
| 298 // Change |sampled_profile| between calls to ParseOutputProtoIfValid(). | 289 // Change |sampled_profile| between calls to ParseOutputProtoIfValid(). |
| 299 TEST_F(PerfProviderTest, MultipleCalls) { | 290 TEST_F(PerfProviderTest, MultipleCalls) { |
| 300 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 291 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| 301 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 292 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
| 302 | 293 |
| 303 perf_provider_->ParseOutputProtoIfValid( | 294 perf_provider_->ParseOutputProtoIfValid( |
| 304 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 295 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 305 sampled_profile.Pass(), | 296 std::move(sampled_profile), kPerfSuccess, |
| 306 kPerfSuccess, | 297 SerializeMessageToVector(perf_data_proto_), std::vector<uint8_t>()); |
| 307 SerializeMessageToVector(perf_data_proto_), | |
| 308 std::vector<uint8_t>()); | |
| 309 | 298 |
| 310 sampled_profile.reset(new SampledProfile); | 299 sampled_profile.reset(new SampledProfile); |
| 311 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); | 300 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); |
| 312 sampled_profile->set_ms_after_restore(3000); | 301 sampled_profile->set_ms_after_restore(3000); |
| 313 perf_provider_->ParseOutputProtoIfValid( | 302 perf_provider_->ParseOutputProtoIfValid( |
| 314 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 303 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 315 sampled_profile.Pass(), | 304 std::move(sampled_profile), kPerfSuccess, std::vector<uint8_t>(), |
| 316 kPerfSuccess, | |
| 317 std::vector<uint8_t>(), | |
| 318 SerializeMessageToVector(perf_stat_proto_)); | 305 SerializeMessageToVector(perf_stat_proto_)); |
| 319 | 306 |
| 320 sampled_profile.reset(new SampledProfile); | 307 sampled_profile.reset(new SampledProfile); |
| 321 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); | 308 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); |
| 322 sampled_profile->set_suspend_duration_ms(60000); | 309 sampled_profile->set_suspend_duration_ms(60000); |
| 323 sampled_profile->set_ms_after_resume(1500); | 310 sampled_profile->set_ms_after_resume(1500); |
| 324 perf_provider_->ParseOutputProtoIfValid( | 311 perf_provider_->ParseOutputProtoIfValid( |
| 325 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 312 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 326 sampled_profile.Pass(), | 313 std::move(sampled_profile), kPerfSuccess, |
| 327 kPerfSuccess, | 314 SerializeMessageToVector(perf_data_proto_), std::vector<uint8_t>()); |
| 328 SerializeMessageToVector(perf_data_proto_), | |
| 329 std::vector<uint8_t>()); | |
| 330 | 315 |
| 331 sampled_profile.reset(new SampledProfile); | 316 sampled_profile.reset(new SampledProfile); |
| 332 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 317 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
| 333 perf_provider_->ParseOutputProtoIfValid( | 318 perf_provider_->ParseOutputProtoIfValid( |
| 334 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 319 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 335 sampled_profile.Pass(), | 320 std::move(sampled_profile), kPerfSuccess, std::vector<uint8_t>(), |
| 336 kPerfSuccess, | |
| 337 std::vector<uint8_t>(), | |
| 338 SerializeMessageToVector(perf_stat_proto_)); | 321 SerializeMessageToVector(perf_stat_proto_)); |
| 339 | 322 |
| 340 std::vector<SampledProfile> stored_profiles; | 323 std::vector<SampledProfile> stored_profiles; |
| 341 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles)); | 324 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles)); |
| 342 ASSERT_EQ(4U, stored_profiles.size()); | 325 ASSERT_EQ(4U, stored_profiles.size()); |
| 343 | 326 |
| 344 const SampledProfile& profile1 = stored_profiles[0]; | 327 const SampledProfile& profile1 = stored_profiles[0]; |
| 345 EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile1.trigger_event()); | 328 EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile1.trigger_event()); |
| 346 EXPECT_TRUE(profile1.has_ms_after_login()); | 329 EXPECT_TRUE(profile1.has_ms_after_login()); |
| 347 ASSERT_TRUE(profile1.has_perf_data()); | 330 ASSERT_TRUE(profile1.has_perf_data()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 378 } | 361 } |
| 379 | 362 |
| 380 // Simulate opening and closing of incognito window in between calls to | 363 // Simulate opening and closing of incognito window in between calls to |
| 381 // ParseOutputProtoIfValid(). | 364 // ParseOutputProtoIfValid(). |
| 382 TEST_F(PerfProviderTest, IncognitoWindowOpened) { | 365 TEST_F(PerfProviderTest, IncognitoWindowOpened) { |
| 383 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 366 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| 384 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 367 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
| 385 | 368 |
| 386 perf_provider_->ParseOutputProtoIfValid( | 369 perf_provider_->ParseOutputProtoIfValid( |
| 387 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 370 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 388 sampled_profile.Pass(), | 371 std::move(sampled_profile), kPerfSuccess, |
| 389 kPerfSuccess, | 372 SerializeMessageToVector(perf_data_proto_), std::vector<uint8_t>()); |
| 390 SerializeMessageToVector(perf_data_proto_), | |
| 391 std::vector<uint8_t>()); | |
| 392 | 373 |
| 393 std::vector<SampledProfile> stored_profiles1; | 374 std::vector<SampledProfile> stored_profiles1; |
| 394 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles1)); | 375 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles1)); |
| 395 ASSERT_EQ(1U, stored_profiles1.size()); | 376 ASSERT_EQ(1U, stored_profiles1.size()); |
| 396 | 377 |
| 397 const SampledProfile& profile1 = stored_profiles1[0]; | 378 const SampledProfile& profile1 = stored_profiles1[0]; |
| 398 EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile1.trigger_event()); | 379 EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile1.trigger_event()); |
| 399 EXPECT_TRUE(profile1.has_ms_after_login()); | 380 EXPECT_TRUE(profile1.has_ms_after_login()); |
| 400 ASSERT_TRUE(profile1.has_perf_data()); | 381 ASSERT_TRUE(profile1.has_perf_data()); |
| 401 EXPECT_FALSE(profile1.has_perf_stat()); | 382 EXPECT_FALSE(profile1.has_perf_stat()); |
| 402 EXPECT_EQ(SerializeMessageToVector(perf_data_proto_), | 383 EXPECT_EQ(SerializeMessageToVector(perf_data_proto_), |
| 403 SerializeMessageToVector(profile1.perf_data())); | 384 SerializeMessageToVector(profile1.perf_data())); |
| 404 | 385 |
| 405 sampled_profile.reset(new SampledProfile); | 386 sampled_profile.reset(new SampledProfile); |
| 406 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); | 387 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); |
| 407 sampled_profile->set_ms_after_restore(3000); | 388 sampled_profile->set_ms_after_restore(3000); |
| 408 perf_provider_->ParseOutputProtoIfValid( | 389 perf_provider_->ParseOutputProtoIfValid( |
| 409 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 390 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 410 sampled_profile.Pass(), | 391 std::move(sampled_profile), kPerfSuccess, std::vector<uint8_t>(), |
| 411 kPerfSuccess, | |
| 412 std::vector<uint8_t>(), | |
| 413 SerializeMessageToVector(perf_stat_proto_)); | 392 SerializeMessageToVector(perf_stat_proto_)); |
| 414 | 393 |
| 415 std::vector<SampledProfile> stored_profiles2; | 394 std::vector<SampledProfile> stored_profiles2; |
| 416 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles2)); | 395 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles2)); |
| 417 ASSERT_EQ(1U, stored_profiles2.size()); | 396 ASSERT_EQ(1U, stored_profiles2.size()); |
| 418 | 397 |
| 419 const SampledProfile& profile2 = stored_profiles2[0]; | 398 const SampledProfile& profile2 = stored_profiles2[0]; |
| 420 EXPECT_EQ(SampledProfile::RESTORE_SESSION, profile2.trigger_event()); | 399 EXPECT_EQ(SampledProfile::RESTORE_SESSION, profile2.trigger_event()); |
| 421 EXPECT_TRUE(profile2.has_ms_after_login()); | 400 EXPECT_TRUE(profile2.has_ms_after_login()); |
| 422 EXPECT_EQ(3000, profile2.ms_after_restore()); | 401 EXPECT_EQ(3000, profile2.ms_after_restore()); |
| 423 EXPECT_FALSE(profile2.has_perf_data()); | 402 EXPECT_FALSE(profile2.has_perf_data()); |
| 424 ASSERT_TRUE(profile2.has_perf_stat()); | 403 ASSERT_TRUE(profile2.has_perf_stat()); |
| 425 EXPECT_EQ(SerializeMessageToVector(perf_stat_proto_), | 404 EXPECT_EQ(SerializeMessageToVector(perf_stat_proto_), |
| 426 SerializeMessageToVector(profile2.perf_stat())); | 405 SerializeMessageToVector(profile2.perf_stat())); |
| 427 | 406 |
| 428 sampled_profile.reset(new SampledProfile); | 407 sampled_profile.reset(new SampledProfile); |
| 429 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); | 408 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); |
| 430 // An incognito window opens. | 409 // An incognito window opens. |
| 431 perf_provider_->ParseOutputProtoIfValid( | 410 perf_provider_->ParseOutputProtoIfValid( |
| 432 TestIncognitoObserver::CreateWithIncognitoLaunched(true), | 411 TestIncognitoObserver::CreateWithIncognitoLaunched(true), |
| 433 sampled_profile.Pass(), | 412 std::move(sampled_profile), kPerfSuccess, |
| 434 kPerfSuccess, | 413 SerializeMessageToVector(perf_data_proto_), std::vector<uint8_t>()); |
| 435 SerializeMessageToVector(perf_data_proto_), | |
| 436 std::vector<uint8_t>()); | |
| 437 | 414 |
| 438 std::vector<SampledProfile> stored_profiles_empty; | 415 std::vector<SampledProfile> stored_profiles_empty; |
| 439 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles_empty)); | 416 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles_empty)); |
| 440 | 417 |
| 441 sampled_profile.reset(new SampledProfile); | 418 sampled_profile.reset(new SampledProfile); |
| 442 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 419 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
| 443 // Incognito window is still open. | 420 // Incognito window is still open. |
| 444 perf_provider_->ParseOutputProtoIfValid( | 421 perf_provider_->ParseOutputProtoIfValid( |
| 445 TestIncognitoObserver::CreateWithIncognitoLaunched(true), | 422 TestIncognitoObserver::CreateWithIncognitoLaunched(true), |
| 446 sampled_profile.Pass(), | 423 std::move(sampled_profile), kPerfSuccess, std::vector<uint8_t>(), |
| 447 kPerfSuccess, | |
| 448 std::vector<uint8_t>(), | |
| 449 SerializeMessageToVector(perf_stat_proto_)); | 424 SerializeMessageToVector(perf_stat_proto_)); |
| 450 | 425 |
| 451 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles_empty)); | 426 EXPECT_FALSE(perf_provider_->GetSampledProfiles(&stored_profiles_empty)); |
| 452 | 427 |
| 453 sampled_profile.reset(new SampledProfile); | 428 sampled_profile.reset(new SampledProfile); |
| 454 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); | 429 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); |
| 455 sampled_profile->set_suspend_duration_ms(60000); | 430 sampled_profile->set_suspend_duration_ms(60000); |
| 456 sampled_profile->set_ms_after_resume(1500); | 431 sampled_profile->set_ms_after_resume(1500); |
| 457 // Incognito window closes. | 432 // Incognito window closes. |
| 458 perf_provider_->ParseOutputProtoIfValid( | 433 perf_provider_->ParseOutputProtoIfValid( |
| 459 TestIncognitoObserver::CreateWithIncognitoLaunched(false), | 434 TestIncognitoObserver::CreateWithIncognitoLaunched(false), |
| 460 sampled_profile.Pass(), | 435 std::move(sampled_profile), kPerfSuccess, |
| 461 kPerfSuccess, | 436 SerializeMessageToVector(perf_data_proto_), std::vector<uint8_t>()); |
| 462 SerializeMessageToVector(perf_data_proto_), | |
| 463 std::vector<uint8_t>()); | |
| 464 | 437 |
| 465 std::vector<SampledProfile> stored_profiles3; | 438 std::vector<SampledProfile> stored_profiles3; |
| 466 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles3)); | 439 EXPECT_TRUE(perf_provider_->GetSampledProfiles(&stored_profiles3)); |
| 467 ASSERT_EQ(1U, stored_profiles3.size()); | 440 ASSERT_EQ(1U, stored_profiles3.size()); |
| 468 | 441 |
| 469 const SampledProfile& profile3 = stored_profiles3[0]; | 442 const SampledProfile& profile3 = stored_profiles3[0]; |
| 470 EXPECT_EQ(SampledProfile::RESUME_FROM_SUSPEND, profile3.trigger_event()); | 443 EXPECT_EQ(SampledProfile::RESUME_FROM_SUSPEND, profile3.trigger_event()); |
| 471 EXPECT_TRUE(profile3.has_ms_after_login()); | 444 EXPECT_TRUE(profile3.has_ms_after_login()); |
| 472 EXPECT_EQ(60000, profile3.suspend_duration_ms()); | 445 EXPECT_EQ(60000, profile3.suspend_duration_ms()); |
| 473 EXPECT_EQ(1500, profile3.ms_after_resume()); | 446 EXPECT_EQ(1500, profile3.ms_after_resume()); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 parsed_params.periodic_interval()); | 819 parsed_params.periodic_interval()); |
| 847 EXPECT_EQ(1, parsed_params.resume_from_suspend().sampling_factor()); | 820 EXPECT_EQ(1, parsed_params.resume_from_suspend().sampling_factor()); |
| 848 EXPECT_EQ(base::TimeDelta::FromSeconds(10), | 821 EXPECT_EQ(base::TimeDelta::FromSeconds(10), |
| 849 parsed_params.resume_from_suspend().max_collection_delay()); | 822 parsed_params.resume_from_suspend().max_collection_delay()); |
| 850 EXPECT_EQ(2, parsed_params.restore_session().sampling_factor()); | 823 EXPECT_EQ(2, parsed_params.restore_session().sampling_factor()); |
| 851 EXPECT_EQ(base::TimeDelta::FromSeconds(20), | 824 EXPECT_EQ(base::TimeDelta::FromSeconds(20), |
| 852 parsed_params.restore_session().max_collection_delay()); | 825 parsed_params.restore_session().max_collection_delay()); |
| 853 } | 826 } |
| 854 | 827 |
| 855 } // namespace metrics | 828 } // namespace metrics |
| OLD | NEW |