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

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

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

Powered by Google App Engine
This is Rietveld 408576698