breadcrumb_manager_keyed_service_unittest.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2019 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/breadcrumbs/core/breadcrumb_manager_keyed_service.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. #include "testing/platform_test.h"
  7. namespace breadcrumbs {
  8. // Test fixture for testing BreadcrumbManagerKeyedService class.
  9. typedef PlatformTest BreadcrumbManagerKeyedServiceTest;
  10. // Tests that events logged to Normal and OffTheRecord BrowserStates are
  11. // separately identifiable.
  12. TEST_F(BreadcrumbManagerKeyedServiceTest, EventsLabeledWithBrowserState) {
  13. std::unique_ptr<BreadcrumbManagerKeyedService> breadcrumb_manager_service =
  14. std::make_unique<BreadcrumbManagerKeyedService>(
  15. /*is_off_the_record=*/false);
  16. breadcrumb_manager_service->AddEvent("event");
  17. const std::string event = breadcrumb_manager_service->GetEvents(0).front();
  18. std::unique_ptr<BreadcrumbManagerKeyedService>
  19. otr_breadcrumb_manager_service =
  20. std::make_unique<BreadcrumbManagerKeyedService>(
  21. /*is_off_the_record=*/true);
  22. otr_breadcrumb_manager_service->AddEvent("event");
  23. const std::string off_the_record_event =
  24. otr_breadcrumb_manager_service->GetEvents(0).front();
  25. // Event should indicate it was logged from an off-the-record "Incognito"
  26. // browser state.
  27. EXPECT_NE(std::string::npos, off_the_record_event.find(" I "));
  28. EXPECT_STRNE(event.c_str(), off_the_record_event.c_str());
  29. }
  30. } // namespace breadcrumbs