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

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

Issue 1247853007: [Sync] Add auto-generated ModelType in Java. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add SYNC_EXPORT and rebase. Created 5 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" 12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
13 #include "chrome/browser/sync/profile_sync_service.h" 13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "chrome/browser/sync/profile_sync_service_android.h" 14 #include "chrome/browser/sync/profile_sync_service_android.h"
15 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" 15 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "components/signin/core/browser/profile_oauth2_token_service.h" 17 #include "components/signin/core/browser/profile_oauth2_token_service.h"
18 #include "components/sync_driver/data_type_controller.h" 18 #include "components/sync_driver/data_type_controller.h"
19 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "sync/internal_api/public/base/model_type.h" 20 #include "sync/internal_api/public/base/model_type.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace {
24
25 int NumberOfSetBits(jlong bitmask) {
26 int num = 0;
27 while (bitmask > 0) {
28 num += (bitmask & 1);
29 bitmask >>= 1;
30 }
31 return num;
32 }
33
34 } // namespace
35
36 class ProfileSyncServiceAndroidTest : public testing::Test { 23 class ProfileSyncServiceAndroidTest : public testing::Test {
37 public: 24 public:
38 ProfileSyncServiceAndroidTest() 25 ProfileSyncServiceAndroidTest()
39 : command_line_(base::CommandLine::NO_PROGRAM) {} 26 : command_line_(base::CommandLine::NO_PROGRAM) {}
40 ~ProfileSyncServiceAndroidTest() override {} 27 ~ProfileSyncServiceAndroidTest() override {}
41 28
42 void SetUp() override { 29 void SetUp() override {
43 ProfileOAuth2TokenService* token_service = 30 ProfileOAuth2TokenService* token_service =
44 ProfileOAuth2TokenServiceFactory::GetForProfile(&profile_); 31 ProfileOAuth2TokenServiceFactory::GetForProfile(&profile_);
45 ProfileSyncComponentsFactory* factory = 32 ProfileSyncComponentsFactory* factory =
(...skipping 24 matching lines...) Expand all
70 } 57 }
71 return model_types; 58 return model_types;
72 } 59 }
73 60
74 private: 61 private:
75 base::CommandLine command_line_; 62 base::CommandLine command_line_;
76 content::TestBrowserThreadBundle thread_bundle_; 63 content::TestBrowserThreadBundle thread_bundle_;
77 TestingProfile profile_; 64 TestingProfile profile_;
78 scoped_ptr<ProfileSyncService> sync_service_; 65 scoped_ptr<ProfileSyncService> sync_service_;
79 }; 66 };
80
81 TEST_F(ProfileSyncServiceAndroidTest, ModelTypesToInvalidationNames) {
82 syncer::ModelTypeSet model_types = GetRegisteredDataTypes();
83
84 jlong model_type_selection =
85 ProfileSyncServiceAndroid::ModelTypeSetToSelection(model_types);
86 // The number of set bits in the model type bitmask should be equal to the
87 // number of model types.
88 EXPECT_EQ(static_cast<int>(model_types.Size()),
89 NumberOfSetBits(model_type_selection));
90
91 std::vector<std::string> invalidation_names;
92 for (syncer::ModelTypeSet::Iterator it = model_types.First(); it.Good();
93 it.Inc()) {
94 std::string notification_type;
95 if (syncer::RealModelTypeToNotificationType(it.Get(), &notification_type))
96 invalidation_names.push_back(notification_type);
97 }
98
99 std::sort(invalidation_names.begin(), invalidation_names.end());
100 EXPECT_EQ(base::JoinString(invalidation_names, ", "),
101 ProfileSyncServiceAndroid::ModelTypeSelectionToStringForTest(
102 model_type_selection));
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698