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

Side by Side Diff: chrome/browser/sync/sync_ui_util_unittest.cc

Issue 1882243004: Convert //chrome/browser/sync from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include <set> 7 #include <set>
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 class SyncUIUtilTest : public testing::Test { 81 class SyncUIUtilTest : public testing::Test {
82 private: 82 private:
83 content::TestBrowserThreadBundle thread_bundle_; 83 content::TestBrowserThreadBundle thread_bundle_;
84 }; 84 };
85 85
86 #if !defined(OS_CHROMEOS) 86 #if !defined(OS_CHROMEOS)
87 // Test that GetStatusLabelsForSyncGlobalError returns an error if a 87 // Test that GetStatusLabelsForSyncGlobalError returns an error if a
88 // passphrase is required. 88 // passphrase is required.
89 TEST_F(SyncUIUtilTest, PassphraseGlobalError) { 89 TEST_F(SyncUIUtilTest, PassphraseGlobalError) {
90 scoped_ptr<Profile> profile = MakeSignedInTestingProfile(); 90 std::unique_ptr<Profile> profile = MakeSignedInTestingProfile();
91 ProfileSyncServiceMock service( 91 ProfileSyncServiceMock service(
92 CreateProfileSyncServiceParamsForTest(profile.get())); 92 CreateProfileSyncServiceParamsForTest(profile.get()));
93 browser_sync::SyncBackendHost::Status status; 93 browser_sync::SyncBackendHost::Status status;
94 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) 94 EXPECT_CALL(service, QueryDetailedSyncStatus(_))
95 .WillRepeatedly(Return(false)); 95 .WillRepeatedly(Return(false));
96 EXPECT_CALL(service, IsPassphraseRequired()) 96 EXPECT_CALL(service, IsPassphraseRequired())
97 .WillRepeatedly(Return(true)); 97 .WillRepeatedly(Return(true));
98 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) 98 EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
99 .WillRepeatedly(Return(true)); 99 .WillRepeatedly(Return(true));
100 100
101 VerifySyncGlobalErrorResult(&service, 101 VerifySyncGlobalErrorResult(&service,
102 GoogleServiceAuthError::NONE, 102 GoogleServiceAuthError::NONE,
103 true /* signed in */, 103 true /* signed in */,
104 true /* error */); 104 true /* error */);
105 } 105 }
106 106
107 // Test that GetStatusLabelsForSyncGlobalError returns an error if a 107 // Test that GetStatusLabelsForSyncGlobalError returns an error if a
108 // passphrase is required and not for auth errors. 108 // passphrase is required and not for auth errors.
109 TEST_F(SyncUIUtilTest, AuthAndPassphraseGlobalError) { 109 TEST_F(SyncUIUtilTest, AuthAndPassphraseGlobalError) {
110 scoped_ptr<Profile> profile(MakeSignedInTestingProfile()); 110 std::unique_ptr<Profile> profile(MakeSignedInTestingProfile());
111 ProfileSyncServiceMock service( 111 ProfileSyncServiceMock service(
112 CreateProfileSyncServiceParamsForTest(profile.get())); 112 CreateProfileSyncServiceParamsForTest(profile.get()));
113 browser_sync::SyncBackendHost::Status status; 113 browser_sync::SyncBackendHost::Status status;
114 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) 114 EXPECT_CALL(service, QueryDetailedSyncStatus(_))
115 .WillRepeatedly(Return(false)); 115 .WillRepeatedly(Return(false));
116 116
117 EXPECT_CALL(service, IsPassphraseRequired()) 117 EXPECT_CALL(service, IsPassphraseRequired())
118 .WillRepeatedly(Return(true)); 118 .WillRepeatedly(Return(true));
119 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) 119 EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
120 .WillRepeatedly(Return(true)); 120 .WillRepeatedly(Return(true));
121 EXPECT_CALL(service, IsFirstSetupComplete()).WillRepeatedly(Return(true)); 121 EXPECT_CALL(service, IsFirstSetupComplete()).WillRepeatedly(Return(true));
122 122
123 GoogleServiceAuthError auth_error( 123 GoogleServiceAuthError auth_error(
124 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 124 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
125 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); 125 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error));
126 base::string16 menu_label, label2, label3; 126 base::string16 menu_label, label2, label3;
127 sync_ui_util::GetStatusLabelsForSyncGlobalError( 127 sync_ui_util::GetStatusLabelsForSyncGlobalError(
128 &service, &menu_label, &label2, &label3); 128 &service, &menu_label, &label2, &label3);
129 // Make sure we are still displaying the passphrase error badge (don't show 129 // Make sure we are still displaying the passphrase error badge (don't show
130 // auth errors through SyncUIUtil). 130 // auth errors through SyncUIUtil).
131 EXPECT_EQ(menu_label, l10n_util::GetStringUTF16( 131 EXPECT_EQ(menu_label, l10n_util::GetStringUTF16(
132 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM)); 132 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM));
133 } 133 }
134 134
135 // Test that GetStatusLabelsForSyncGlobalError does not indicate errors for 135 // Test that GetStatusLabelsForSyncGlobalError does not indicate errors for
136 // auth errors (these are reported through SigninGlobalError). 136 // auth errors (these are reported through SigninGlobalError).
137 TEST_F(SyncUIUtilTest, AuthStateGlobalError) { 137 TEST_F(SyncUIUtilTest, AuthStateGlobalError) {
138 scoped_ptr<Profile> profile(MakeSignedInTestingProfile()); 138 std::unique_ptr<Profile> profile(MakeSignedInTestingProfile());
139 ProfileSyncService::InitParams init_params = 139 ProfileSyncService::InitParams init_params =
140 CreateProfileSyncServiceParamsForTest(profile.get()); 140 CreateProfileSyncServiceParamsForTest(profile.get());
141 NiceMock<ProfileSyncServiceMock> service(&init_params); 141 NiceMock<ProfileSyncServiceMock> service(&init_params);
142 142
143 browser_sync::SyncBackendHost::Status status; 143 browser_sync::SyncBackendHost::Status status;
144 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) 144 EXPECT_CALL(service, QueryDetailedSyncStatus(_))
145 .WillRepeatedly(Return(false)); 145 .WillRepeatedly(Return(false));
146 146
147 GoogleServiceAuthError::State table[] = { 147 GoogleServiceAuthError::State table[] = {
148 GoogleServiceAuthError::NONE, 148 GoogleServiceAuthError::NONE,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 NOTREACHED(); 330 NOTREACHED();
331 } 331 }
332 } 332 }
333 333
334 // This test ensures that a each distinctive ProfileSyncService statuses 334 // This test ensures that a each distinctive ProfileSyncService statuses
335 // will return a unique combination of status and link messages from 335 // will return a unique combination of status and link messages from
336 // GetStatusLabels(). 336 // GetStatusLabels().
337 TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { 337 TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
338 std::set<base::string16> messages; 338 std::set<base::string16> messages;
339 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { 339 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) {
340 scoped_ptr<Profile> profile(new TestingProfile()); 340 std::unique_ptr<Profile> profile(new TestingProfile());
341 ProfileSyncService::InitParams init_params = 341 ProfileSyncService::InitParams init_params =
342 CreateProfileSyncServiceParamsForTest(profile.get()); 342 CreateProfileSyncServiceParamsForTest(profile.get());
343 NiceMock<ProfileSyncServiceMock> service(&init_params); 343 NiceMock<ProfileSyncServiceMock> service(&init_params);
344 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); 344 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone();
345 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); 345 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
346 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); 346 FakeSigninManagerForSyncUIUtilTest signin(profile.get());
347 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); 347 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
348 scoped_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( 348 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider(
349 SigninErrorControllerFactory::GetForProfile(profile.get()))); 349 SigninErrorControllerFactory::GetForProfile(profile.get())));
350 GetDistinctCase(&service, &signin, provider.get(), idx); 350 GetDistinctCase(&service, &signin, provider.get(), idx);
351 base::string16 status_label; 351 base::string16 status_label;
352 base::string16 link_label; 352 base::string16 link_label;
353 sync_ui_util::GetStatusLabels(profile.get(), &service, signin, 353 sync_ui_util::GetStatusLabels(profile.get(), &service, signin,
354 sync_ui_util::WITH_HTML, &status_label, 354 sync_ui_util::WITH_HTML, &status_label,
355 &link_label); 355 &link_label);
356 // If the status and link message combination is already present in the set 356 // If the status and link message combination is already present in the set
357 // of messages already seen, this is a duplicate rather than a unique 357 // of messages already seen, this is a duplicate rather than a unique
358 // message, and the test has failed. 358 // message, and the test has failed.
359 EXPECT_FALSE(status_label.empty()) << 359 EXPECT_FALSE(status_label.empty()) <<
360 "Empty status label returned for case #" << idx; 360 "Empty status label returned for case #" << idx;
361 base::string16 combined_label = 361 base::string16 combined_label =
362 status_label + base::ASCIIToUTF16("#") + link_label; 362 status_label + base::ASCIIToUTF16("#") + link_label;
363 EXPECT_TRUE(messages.find(combined_label) == messages.end()) << 363 EXPECT_TRUE(messages.find(combined_label) == messages.end()) <<
364 "Duplicate message for case #" << idx << ": " << combined_label; 364 "Duplicate message for case #" << idx << ": " << combined_label;
365 messages.insert(combined_label); 365 messages.insert(combined_label);
366 testing::Mock::VerifyAndClearExpectations(&service); 366 testing::Mock::VerifyAndClearExpectations(&service);
367 testing::Mock::VerifyAndClearExpectations(&signin); 367 testing::Mock::VerifyAndClearExpectations(&signin);
368 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); 368 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
369 provider.reset(); 369 provider.reset();
370 signin.Shutdown(); 370 signin.Shutdown();
371 } 371 }
372 } 372 }
373 373
374 // This test ensures that the html_links parameter on GetStatusLabels() is 374 // This test ensures that the html_links parameter on GetStatusLabels() is
375 // honored. 375 // honored.
376 TEST_F(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { 376 TEST_F(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) {
377 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { 377 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) {
378 scoped_ptr<Profile> profile(MakeSignedInTestingProfile()); 378 std::unique_ptr<Profile> profile(MakeSignedInTestingProfile());
379 ProfileSyncService::InitParams init_params = 379 ProfileSyncService::InitParams init_params =
380 CreateProfileSyncServiceParamsForTest(profile.get()); 380 CreateProfileSyncServiceParamsForTest(profile.get());
381 NiceMock<ProfileSyncServiceMock> service(&init_params); 381 NiceMock<ProfileSyncServiceMock> service(&init_params);
382 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); 382 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone();
383 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); 383 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
384 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); 384 FakeSigninManagerForSyncUIUtilTest signin(profile.get());
385 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); 385 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
386 scoped_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( 386 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider(
387 SigninErrorControllerFactory::GetForProfile(profile.get()))); 387 SigninErrorControllerFactory::GetForProfile(profile.get())));
388 GetDistinctCase(&service, &signin, provider.get(), idx); 388 GetDistinctCase(&service, &signin, provider.get(), idx);
389 base::string16 status_label; 389 base::string16 status_label;
390 base::string16 link_label; 390 base::string16 link_label;
391 sync_ui_util::GetStatusLabels(profile.get(), &service, signin, 391 sync_ui_util::GetStatusLabels(profile.get(), &service, signin,
392 sync_ui_util::PLAIN_TEXT, &status_label, 392 sync_ui_util::PLAIN_TEXT, &status_label,
393 &link_label); 393 &link_label);
394 394
395 // Ensures a search for string 'href' (found in links, not a string to be 395 // Ensures a search for string 'href' (found in links, not a string to be
396 // found in an English language message) fails when links are excluded from 396 // found in an English language message) fails when links are excluded from
397 // the status label. 397 // the status label.
398 EXPECT_FALSE(status_label.empty()); 398 EXPECT_FALSE(status_label.empty());
399 EXPECT_EQ(status_label.find(base::ASCIIToUTF16("href")), 399 EXPECT_EQ(status_label.find(base::ASCIIToUTF16("href")),
400 base::string16::npos); 400 base::string16::npos);
401 testing::Mock::VerifyAndClearExpectations(&service); 401 testing::Mock::VerifyAndClearExpectations(&service);
402 testing::Mock::VerifyAndClearExpectations(&signin); 402 testing::Mock::VerifyAndClearExpectations(&signin);
403 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); 403 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
404 provider.reset(); 404 provider.reset();
405 signin.Shutdown(); 405 signin.Shutdown();
406 } 406 }
407 } 407 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_startup_tracker_unittest.cc ('k') | chrome/browser/sync/test/integration/bookmarks_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698