[go: nahoru, domu]

blob: 461ebc625081f2020e794f83153695a72ed41a66 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2019 The Chromium Authors
Jesse McKenna855ae2662021-04-23 00:26:202// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/breadcrumbs/core/breadcrumb_manager_keyed_service.h"
6
Jesse McKenna558ca952022-09-20 23:49:557#include "components/breadcrumbs/core/breadcrumb_manager.h"
Jesse McKenna855ae2662021-04-23 00:26:208#include "testing/gtest/include/gtest/gtest.h"
9#include "testing/platform_test.h"
10
11namespace breadcrumbs {
12
13// Test fixture for testing BreadcrumbManagerKeyedService class.
14typedef PlatformTest BreadcrumbManagerKeyedServiceTest;
15
16// Tests that events logged to Normal and OffTheRecord BrowserStates are
17// separately identifiable.
18TEST_F(BreadcrumbManagerKeyedServiceTest, EventsLabeledWithBrowserState) {
19 std::unique_ptr<BreadcrumbManagerKeyedService> breadcrumb_manager_service =
20 std::make_unique<BreadcrumbManagerKeyedService>(
21 /*is_off_the_record=*/false);
22 breadcrumb_manager_service->AddEvent("event");
23
Jesse McKennaab2ad642022-10-05 17:35:4624 const std::string event =
25 BreadcrumbManager::GetInstance().GetEvents().front();
Jesse McKenna855ae2662021-04-23 00:26:2026
Jesse McKenna558ca952022-09-20 23:49:5527 BreadcrumbManager::GetInstance().ResetForTesting();
28
Jesse McKenna855ae2662021-04-23 00:26:2029 std::unique_ptr<BreadcrumbManagerKeyedService>
30 otr_breadcrumb_manager_service =
31 std::make_unique<BreadcrumbManagerKeyedService>(
32 /*is_off_the_record=*/true);
33 otr_breadcrumb_manager_service->AddEvent("event");
34
Jesse McKennab0ed2b6d2021-06-08 18:04:0735 const std::string off_the_record_event =
Jesse McKennaab2ad642022-10-05 17:35:4636 BreadcrumbManager::GetInstance().GetEvents().front();
Jesse McKenna855ae2662021-04-23 00:26:2037 // Event should indicate it was logged from an off-the-record "Incognito"
38 // browser state.
39 EXPECT_NE(std::string::npos, off_the_record_event.find(" I "));
40
41 EXPECT_STRNE(event.c_str(), off_the_record_event.c_str());
42}
43
44} // namespace breadcrumbs