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

Side by Side Diff: components/browsing_data_ui/history_notice_utils_unittest.cc

Issue 1983073002: Query the existence other forms of browsing history. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments, re-added protobuf Created 4 years, 6 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 "components/browsing_data_ui/history_notice_utils.h"
6
7 #include <memory>
8
9 #include "base/callback.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
12 #include "components/history/core/test/fake_web_history_service.h"
13 #include "components/signin/core/browser/account_tracker_service.h"
14 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
15 #include "components/signin/core/browser/fake_signin_manager.h"
16 #include "components/signin/core/browser/test_signin_client.h"
17 #include "components/sync_driver/fake_sync_service.h"
18 #include "components/version_info/version_info.h"
19 #include "net/http/http_status_code.h"
20 #include "net/url_request/url_request_test_util.h"
21 #include "sync/internal_api/public/base/model_type.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23
24 namespace browsing_data_ui {
25
26 namespace {
27
28 class TestSyncService : public sync_driver::FakeSyncService {
29 public:
30 // Getters (FakeSyncService implementation). ---------------------------------
31 bool IsSyncActive() const override {
32 return sync_active_;
33 }
34
35 syncer::ModelTypeSet GetActiveDataTypes() const override {
36 return data_types_;
37 }
38
39 bool IsUsingSecondaryPassphrase() const override {
40 return passphrase_;
41 }
42
43 // Setters. ------------------------------------------------------------------
44 void SetSyncActive(bool active) {
sdefresne 2016/05/24 08:32:29 nit, style: this should be "set_sync_active" as it
msramek 2016/05/24 12:03:00 Done. For consistency, I renamed the underlying va
45 sync_active_ = active;
46 }
47
48 void SetActiveDataTypes(syncer::ModelTypeSet data_types) {
sdefresne 2016/05/24 08:32:29 ditto
msramek 2016/05/24 12:03:00 Done.
49 data_types_ = data_types;
50 }
51
52 void SetUsingSecondaryPassphrase(bool passphrase) {
sdefresne 2016/05/24 08:32:29 ditto
msramek 2016/05/24 12:03:00 Done.
53 passphrase_ = passphrase;
54 }
55
56 private:
57 syncer::ModelTypeSet data_types_;
58 bool passphrase_ = false;
59 bool sync_active_ = false;
60 };
61
62 } // namespace
63
64
65 class HistoryNoticeUtilsTest : public ::testing::Test {
66 public:
67 HistoryNoticeUtilsTest()
68 : signin_client_(nullptr),
69 signin_manager_(&signin_client_, &account_tracker_) {
70 }
71
72 void SetUp() override {
73 sync_service_.reset(new TestSyncService());
74 history_service_.reset(new history::FakeWebHistoryService(
75 &oauth2_token_service_,
76 &signin_manager_,
77 url_request_context_));
78 history_service_->SetupFakeResponse(true /* success */, net::HTTP_OK);
79 }
80
81 TestSyncService* sync_service() {
82 return sync_service_.get();
83 }
84
85 history::FakeWebHistoryService* history_service() {
86 return history_service_.get();
87 }
88
89 void ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(
90 bool expected_test_case_result) {
91 bool got_result = false;
92
93 ShouldPopupDialogAboutOtherFormsOfBrowsingHistory(
94 sync_service_.get(),
95 history_service_.get(),
96 version_info::Channel::STABLE,
97 false /* is_tablet */,
98 base::Bind(
99 &HistoryNoticeUtilsTest::Callback,
100 base::Unretained(this),
101 base::Unretained(&got_result)));
102
103 if (!got_result) {
104 run_loop_.reset(new base::RunLoop());
105 run_loop_->Run();
106 }
107
108 // Process the DeleteSoon() called on MergeBooleanCallbacks, otherwise
109 // this it will be considered to be leaked.
110 base::MessageLoop::current()->RunUntilIdle();
111
112 EXPECT_EQ(expected_test_case_result, result_);
113 }
114
115 private:
116 void Callback(bool* got_result, bool result) {
117 *got_result = true;
118 result_ = result;
119
120 if (run_loop_)
121 run_loop_->Quit();
122 }
123
124 FakeProfileOAuth2TokenService oauth2_token_service_;
125 AccountTrackerService account_tracker_;
126 TestSigninClient signin_client_;
127 FakeSigninManagerBase signin_manager_;
128 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
129 std::unique_ptr<TestSyncService> sync_service_;
130 std::unique_ptr<history::FakeWebHistoryService> history_service_;
131
132 std::unique_ptr<base::RunLoop> run_loop_;
133 bool result_;
134
135 base::MessageLoop message_loop_;
136 };
137
138 TEST_F(HistoryNoticeUtilsTest, NotSyncing) {
139 ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
140 }
141
142 TEST_F(HistoryNoticeUtilsTest, SyncingWithWrongParameters) {
143 sync_service()->SetSyncActive(true);
144
145 // Regardless of the state of the web history...
146 history_service()->SetWebAndAppActivityEnabled(true);
147 history_service()->SetOtherFormsOfBrowsingHistoryPresent(true);
148
149 // ...the response is false if there's custom passphrase...
150 sync_service()->SetActiveDataTypes(syncer::ModelTypeSet::All());
151 sync_service()->SetUsingSecondaryPassphrase(true);
152 ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
153
154 // ...or even if there's no custom passphrase, but we're not syncing history.
155 syncer::ModelTypeSet only_passwords(syncer::PASSWORDS);
156 sync_service()->SetActiveDataTypes(only_passwords);
157 sync_service()->SetUsingSecondaryPassphrase(false);
158 ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
159 }
160
161 TEST_F(HistoryNoticeUtilsTest, WebHistoryStates) {
162 // If history Sync is active...
163 sync_service()->SetSyncActive(true);
164 sync_service()->SetActiveDataTypes(syncer::ModelTypeSet::All());
165
166 // ...the result is true if both web history queries return true...
167 history_service()->SetWebAndAppActivityEnabled(true);
168 history_service()->SetOtherFormsOfBrowsingHistoryPresent(true);
169 ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(true);
170
171 // ...but not otherwise.
172 history_service()->SetOtherFormsOfBrowsingHistoryPresent(false);
173 ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
174 history_service()->SetWebAndAppActivityEnabled(false);
175 ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
176 history_service()->SetOtherFormsOfBrowsingHistoryPresent(true);
177 ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
178
179 // Invalid responses from the web history are interpreted as false.
180 history_service()->SetWebAndAppActivityEnabled(true);
181 history_service()->SetOtherFormsOfBrowsingHistoryPresent(true);
182 history_service()->SetupFakeResponse(true, net::HTTP_INTERNAL_SERVER_ERROR);
183 ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
184 history_service()->SetupFakeResponse(false, net::HTTP_OK);
185 ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
186 }
187
188 } // namespace browsing_data_ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698