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

Side by Side Diff: chrome/browser/extensions/api/sessions/sessions_apitest.cc

Issue 367153005: Sync: Refactoring of DEVICE_INFO syncable type - Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed scoped_ptr issue in ProfileSyncService constructor Created 6 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/extensions/api/sessions/sessions_api.h" 5 #include "chrome/browser/extensions/api/sessions/sessions_api.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/extensions/api/tabs/tabs_api.h" 10 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
11 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/browser/extensions/extension_function_test_utils.h" 12 #include "chrome/browser/extensions/extension_function_test_utils.h"
13 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/sync/glue/local_device_info_provider_mock.h"
14 #include "chrome/browser/sync/open_tabs_ui_delegate.h" 15 #include "chrome/browser/sync/open_tabs_ui_delegate.h"
16 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
15 #include "chrome/browser/sync/profile_sync_service.h" 17 #include "chrome/browser/sync/profile_sync_service.h"
16 #include "chrome/browser/sync/profile_sync_service_factory.h" 18 #include "chrome/browser/sync/profile_sync_service_factory.h"
17 #include "chrome/browser/sync/profile_sync_service_mock.h" 19 #include "chrome/browser/sync/profile_sync_service_mock.h"
18 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
20 #include "chrome/test/base/in_process_browser_test.h" 22 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/test_switches.h" 23 #include "chrome/test/base/test_switches.h"
22 #include "chrome/test/base/testing_browser_process.h" 24 #include "chrome/test/base/testing_browser_process.h"
23 #include "sync/api/attachments/attachment_id.h" 25 #include "sync/api/attachments/attachment_id.h"
24 #include "sync/api/attachments/attachment_service_proxy_for_test.h" 26 #include "sync/api/attachments/attachment_service_proxy_for_test.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED); 80 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED);
79 } 81 }
80 82
81 } // namespace 83 } // namespace
82 84
83 class ExtensionSessionsTest : public InProcessBrowserTest { 85 class ExtensionSessionsTest : public InProcessBrowserTest {
84 public: 86 public:
85 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; 87 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
86 virtual void SetUpOnMainThread() OVERRIDE; 88 virtual void SetUpOnMainThread() OVERRIDE;
87 protected: 89 protected:
90 static KeyedService* BuildProfileSyncService(
91 content::BrowserContext* profile);
92
88 void CreateTestProfileSyncService(); 93 void CreateTestProfileSyncService();
89 void CreateTestExtension(); 94 void CreateTestExtension();
90 void CreateSessionModels(); 95 void CreateSessionModels();
91 96
92 template <class T> 97 template <class T>
93 scoped_refptr<T> CreateFunction(bool has_callback) { 98 scoped_refptr<T> CreateFunction(bool has_callback) {
94 scoped_refptr<T> fn(new T()); 99 scoped_refptr<T> fn(new T());
95 fn->set_extension(extension_.get()); 100 fn->set_extension(extension_.get());
96 fn->set_has_callback(has_callback); 101 fn->set_has_callback(has_callback);
97 return fn; 102 return fn;
98 }; 103 };
99 104
100 Browser* browser_; 105 Browser* browser_;
101 scoped_refptr<extensions::Extension> extension_; 106 scoped_refptr<extensions::Extension> extension_;
102 }; 107 };
103 108
104 void ExtensionSessionsTest::SetUpCommandLine(CommandLine* command_line) { 109 void ExtensionSessionsTest::SetUpCommandLine(CommandLine* command_line) {
105 #if defined(OS_CHROMEOS) 110 #if defined(OS_CHROMEOS)
106 command_line->AppendSwitch( 111 command_line->AppendSwitch(
107 chromeos::switches::kIgnoreUserProfileMappingForTests); 112 chromeos::switches::kIgnoreUserProfileMappingForTests);
108 #endif 113 #endif
109 } 114 }
110 115
111 void ExtensionSessionsTest::SetUpOnMainThread() { 116 void ExtensionSessionsTest::SetUpOnMainThread() {
112 CreateTestProfileSyncService(); 117 CreateTestProfileSyncService();
113 CreateTestExtension(); 118 CreateTestExtension();
114 } 119 }
115 120
121 KeyedService* ExtensionSessionsTest::BuildProfileSyncService(
122 content::BrowserContext* profile) {
123
124 ProfileSyncComponentsFactoryMock* factory =
125 new ProfileSyncComponentsFactoryMock();
126
127 ON_CALL(*factory, CreateLocalDeviceInfoProviderMock()).WillByDefault(
128 testing::Return(new browser_sync::LocalDeviceInfoProviderMock(
129 kSessionTags[0],
130 "machine name",
131 "Chromium 10k",
132 "Chrome 10k",
133 sync_pb::SyncEnums_DeviceType_TYPE_LINUX)));
134
135 return new ProfileSyncServiceMock(
136 scoped_ptr<ProfileSyncComponentsFactory>(factory),
137 static_cast<Profile*>(profile));
138 }
139
116 void ExtensionSessionsTest::CreateTestProfileSyncService() { 140 void ExtensionSessionsTest::CreateTestProfileSyncService() {
117 ProfileManager* profile_manager = g_browser_process->profile_manager(); 141 ProfileManager* profile_manager = g_browser_process->profile_manager();
118 base::FilePath path; 142 base::FilePath path;
119 PathService::Get(chrome::DIR_USER_DATA, &path); 143 PathService::Get(chrome::DIR_USER_DATA, &path);
120 path = path.AppendASCII("test_profile"); 144 path = path.AppendASCII("test_profile");
121 if (!base::PathExists(path)) 145 if (!base::PathExists(path))
122 CHECK(base::CreateDirectory(path)); 146 CHECK(base::CreateDirectory(path));
123 Profile* profile = 147 Profile* profile =
124 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); 148 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
125 profile_manager->RegisterTestingProfile(profile, true, false); 149 profile_manager->RegisterTestingProfile(profile, true, false);
126 ProfileSyncServiceMock* service = static_cast<ProfileSyncServiceMock*>( 150 ProfileSyncServiceMock* service = static_cast<ProfileSyncServiceMock*>(
127 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 151 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
128 profile, &ProfileSyncServiceMock::BuildMockProfileSyncService)); 152 profile, &ExtensionSessionsTest::BuildProfileSyncService));
129 browser_ = new Browser(Browser::CreateParams( 153 browser_ = new Browser(Browser::CreateParams(
130 profile, chrome::HOST_DESKTOP_TYPE_NATIVE)); 154 profile, chrome::HOST_DESKTOP_TYPE_NATIVE));
131 155
132 syncer::ModelTypeSet preferred_types; 156 syncer::ModelTypeSet preferred_types;
133 preferred_types.Put(syncer::SESSIONS); 157 preferred_types.Put(syncer::SESSIONS);
134 GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE); 158 GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE);
135 ON_CALL(*service, IsSessionsDataTypeControllerRunning()) 159 ON_CALL(*service, IsSessionsDataTypeControllerRunning())
136 .WillByDefault(testing::Return(true)); 160 .WillByDefault(testing::Return(true));
137 ON_CALL(*service, GetRegisteredDataTypes()) 161 ON_CALL(*service, GetRegisteredDataTypes())
138 .WillByDefault(testing::Return(syncer::UserTypes())); 162 .WillByDefault(testing::Return(syncer::UserTypes()));
139 ON_CALL(*service, GetPreferredDataTypes()).WillByDefault( 163 ON_CALL(*service, GetPreferredDataTypes()).WillByDefault(
140 testing::Return(preferred_types)); 164 testing::Return(preferred_types));
141 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly( 165 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(
142 testing::ReturnRef(no_error)); 166 testing::ReturnRef(no_error));
143 ON_CALL(*service, GetActiveDataTypes()).WillByDefault( 167 ON_CALL(*service, GetActiveDataTypes()).WillByDefault(
144 testing::Return(preferred_types)); 168 testing::Return(preferred_types));
145 ON_CALL(*service, GetLocalDeviceInfoMock()).WillByDefault(
146 testing::Return(new browser_sync::DeviceInfo(
147 std::string(kSessionTags[0]),
148 "machine name",
149 "Chromium 10k",
150 "Chrome 10k",
151 sync_pb::SyncEnums_DeviceType_TYPE_LINUX)));
152 ON_CALL(*service, GetLocalSyncCacheGUID()).WillByDefault(
153 testing::Return(std::string(kSessionTags[0])));
154 EXPECT_CALL(*service, AddObserver(testing::_)).Times(testing::AnyNumber()); 169 EXPECT_CALL(*service, AddObserver(testing::_)).Times(testing::AnyNumber());
155 EXPECT_CALL(*service, RemoveObserver(testing::_)).Times(testing::AnyNumber()); 170 EXPECT_CALL(*service, RemoveObserver(testing::_)).Times(testing::AnyNumber());
156 171
157 service->Initialize(); 172 service->Initialize();
158 } 173 }
159 174
160 void ExtensionSessionsTest::CreateTestExtension() { 175 void ExtensionSessionsTest::CreateTestExtension() {
161 scoped_ptr<base::DictionaryValue> test_extension_value( 176 scoped_ptr<base::DictionaryValue> test_extension_value(
162 utils::ParseDictionary( 177 utils::ParseDictionary(
163 "{\"name\": \"Test\", \"version\": \"1.0\", " 178 "{\"name\": \"Test\", \"version\": \"1.0\", "
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 357 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
343 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 358 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
344 return; 359 return;
345 #endif 360 #endif
346 361
347 ASSERT_TRUE(RunExtensionSubtest("sessions", 362 ASSERT_TRUE(RunExtensionSubtest("sessions",
348 "sessions.html")) << message_; 363 "sessions.html")) << message_;
349 } 364 }
350 365
351 } // namespace extensions 366 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698