graph_features_unittest.cc 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2020 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. #include "components/performance_manager/embedder/graph_features.h"
  5. #include "build/build_config.h"
  6. #include "components/performance_manager/public/decorators/page_live_state_decorator.h"
  7. #include "components/performance_manager/public/execution_context/execution_context_registry.h"
  8. #include "components/performance_manager/test_support/graph_test_harness.h"
  9. #include "components/performance_manager/v8_memory/v8_context_tracker.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. namespace performance_manager {
  12. TEST(GraphFeaturesTest, ConfigureGraph) {
  13. GraphFeatures features;
  14. EXPECT_FALSE(features.flags().execution_context_registry);
  15. EXPECT_FALSE(features.flags().v8_context_tracker);
  16. features.EnableV8ContextTracker();
  17. EXPECT_TRUE(features.flags().execution_context_registry);
  18. EXPECT_TRUE(features.flags().v8_context_tracker);
  19. TestGraphImpl graph;
  20. graph.SetUp();
  21. EXPECT_FALSE(v8_memory::V8ContextTracker::GetFromGraph(&graph));
  22. features.ConfigureGraph(&graph);
  23. EXPECT_TRUE(v8_memory::V8ContextTracker::GetFromGraph(&graph));
  24. graph.TearDown();
  25. }
  26. TEST(GraphFeaturesTest, EnableDefault) {
  27. GraphFeatures features;
  28. TestGraphImpl graph;
  29. graph.SetUp();
  30. EXPECT_EQ(0u, graph.GraphOwnedCountForTesting());
  31. EXPECT_EQ(0u, graph.GraphRegisteredCountForTesting());
  32. EXPECT_EQ(0u, graph.NodeDataDescriberCountForTesting());
  33. EXPECT_FALSE(
  34. execution_context::ExecutionContextRegistry::GetFromGraph(&graph));
  35. EXPECT_FALSE(v8_memory::V8ContextTracker::GetFromGraph(&graph));
  36. // An empty config should install nothing.
  37. features.ConfigureGraph(&graph);
  38. EXPECT_EQ(0u, graph.GraphOwnedCountForTesting());
  39. EXPECT_EQ(0u, graph.GraphRegisteredCountForTesting());
  40. EXPECT_EQ(0u, graph.NodeDataDescriberCountForTesting());
  41. EXPECT_FALSE(
  42. execution_context::ExecutionContextRegistry::GetFromGraph(&graph));
  43. EXPECT_FALSE(v8_memory::V8ContextTracker::GetFromGraph(&graph));
  44. size_t graph_owned_count = 12;
  45. #if !BUILDFLAG(IS_ANDROID)
  46. // The SiteDataRecorder is not available on Android.
  47. graph_owned_count++;
  48. #endif
  49. // Validate that the default configuration works as expected.
  50. features.EnableDefault();
  51. features.ConfigureGraph(&graph);
  52. EXPECT_EQ(graph_owned_count, graph.GraphOwnedCountForTesting());
  53. EXPECT_EQ(3u, graph.GraphRegisteredCountForTesting());
  54. EXPECT_EQ(8u, graph.NodeDataDescriberCountForTesting());
  55. // Ensure the GraphRegistered objects can be queried directly.
  56. EXPECT_TRUE(
  57. execution_context::ExecutionContextRegistry::GetFromGraph(&graph));
  58. EXPECT_TRUE(v8_memory::V8ContextTracker::GetFromGraph(&graph));
  59. graph.TearDown();
  60. }
  61. TEST(GraphFeaturesTest, StandardConfigurations) {
  62. GraphFeatures features;
  63. EXPECT_EQ(features.flags().flags, GraphFeatures::WithNone().flags().flags);
  64. features.EnableMinimal();
  65. EXPECT_EQ(features.flags().flags, GraphFeatures::WithMinimal().flags().flags);
  66. // This test will fail if Default is not a superset of Minimal, since it does
  67. // not remove the Minimal flags. That's a good thing to test since it would
  68. // be confusing for Minimal to include features that Default doesn't.
  69. features.EnableDefault();
  70. EXPECT_EQ(features.flags().flags, GraphFeatures::WithDefault().flags().flags);
  71. }
  72. } // namespace performance_manager