Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/ntp_snippets/bookmark_last_visit_updater_unittest.cc

Issue 2603323002: Disable tracking of visits to bookmarks in incognito (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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
5 #include "chrome/browser/ntp_snippets/bookmark_last_visit_updater.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "components/bookmarks/browser/bookmark_model.h"
13 #include "components/bookmarks/test/bookmark_test_helpers.h"
14 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "content/public/test/test_web_contents_factory.h"
18 #include "content/public/test/web_contents_tester.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 using content::WebContents;
23 using content::WebContentsTester;
24 using content::TestBrowserThreadBundle;
25 using content::TestWebContentsFactory;
26 using testing::IsEmpty;
27 using testing::Not;
28
29 TEST(BookmarkLastVisitUpdaterTest, DoesNotCrashForNoBookmarkModel) {
30 TestBrowserThreadBundle thread_bundle;
31 TestingProfile profile;
32
33 // Create a tab with the BookmarkLastVisitUpdater (with no BookmarkModel*).
34 TestWebContentsFactory factory;
35 WebContents* tab = factory.CreateWebContents(&profile);
36 BookmarkLastVisitUpdater::MaybeCreateForWebContentsWithBookmarkModel(
37 tab, /*bookmark_model=*/nullptr);
38
39 // Visit a URL.
40 WebContentsTester* tester = WebContentsTester::For(tab);
41 tester->StartNavigation(GURL("http://foo.org/"));
42
43 // The only expectation is that it does not crash.
44 }
45
46 TEST(BookmarkLastVisitUpdaterTest, IsTrackingVisits) {
47 TestBrowserThreadBundle thread_bundle;
48 TestingProfile profile;
49 profile.CreateBookmarkModel(true);
50 bookmarks::BookmarkModel* bookmark_model =
51 BookmarkModelFactory::GetForBrowserContext(&profile);
52 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
53
54 // Create a bookmark.
55 GURL url = GURL("http://foo.org/");
56 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
57 base::string16(), url);
58
59 // Create a tab with the BookmarkLastVisitUpdater.
60 TestWebContentsFactory factory;
61 WebContents* tab = factory.CreateWebContents(&profile);
62 BookmarkLastVisitUpdater::MaybeCreateForWebContentsWithBookmarkModel(
63 tab, bookmark_model);
64
65 // Visit the bookmarked URL.
66 WebContentsTester* tester = WebContentsTester::For(tab);
67 tester->StartNavigation(url);
68
69 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks(
70 bookmark_model, 0, 2, base::Time::UnixEpoch(),
71 /*creation_date_fallback=*/false,
72 /*consider_visits_from_desktop=*/true),
73 Not(IsEmpty()));
74 }
75
76 TEST(BookmarkLastVisitUpdaterTest, IsNotTrackingIncognitoVisits) {
77 TestBrowserThreadBundle thread_bundle;
78 TestingProfile profile;
79 profile.CreateBookmarkModel(true);
80 bookmarks::BookmarkModel* bookmark_model =
81 BookmarkModelFactory::GetForBrowserContext(&profile);
82 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
83
84 // Create a couple of bookmarks.
85 GURL url = GURL("http://foo.org/");
86 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
87 base::string16(), url);
88
89 // Create an incognito tab with the BookmarkLastVisitUpdater.
90 Profile* incognito = profile.GetOffTheRecordProfile();
91 TestWebContentsFactory factory;
92 WebContents* tab = factory.CreateWebContents(incognito);
93 BookmarkLastVisitUpdater::MaybeCreateForWebContentsWithBookmarkModel(
94 tab, bookmark_model);
95
96 // Visit the bookmarked URL.
97 WebContentsTester* tester = WebContentsTester::For(tab);
98 tester->StartNavigation(url);
99
100 // The incognito visit should _not_ appear in recent bookmarks.
101 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks(
102 bookmark_model, 0, 2, base::Time::UnixEpoch(),
103 /*creation_date_fallback=*/false,
104 /*consider_visits_from_desktop=*/true),
105 IsEmpty());
106 }
OLDNEW
« no previous file with comments | « chrome/browser/ntp_snippets/bookmark_last_visit_updater.cc ('k') | chrome/browser/ui/tab_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698