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

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 ExtensionSessionsTest test failures 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.
rlarocque 2014/07/08 18:25:37 (This comment is unrelated to this file but there'
stanisc 2014/07/09 21:58:36 Done.
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, CreateLocalDeviceInfoProvider()).WillByDefault(
rlarocque 2014/07/08 18:25:37 We would normally discourage the use of GMock in n
stanisc 2014/07/09 21:58:36 Done.
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(factory, static_cast<Profile*>(profile));
136 }
137
116 void ExtensionSessionsTest::CreateTestProfileSyncService() { 138 void ExtensionSessionsTest::CreateTestProfileSyncService() {
117 ProfileManager* profile_manager = g_browser_process->profile_manager(); 139 ProfileManager* profile_manager = g_browser_process->profile_manager();
118 base::FilePath path; 140 base::FilePath path;
119 PathService::Get(chrome::DIR_USER_DATA, &path); 141 PathService::Get(chrome::DIR_USER_DATA, &path);
120 path = path.AppendASCII("test_profile"); 142 path = path.AppendASCII("test_profile");
121 if (!base::PathExists(path)) 143 if (!base::PathExists(path))
122 CHECK(base::CreateDirectory(path)); 144 CHECK(base::CreateDirectory(path));
123 Profile* profile = 145 Profile* profile =
124 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); 146 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
125 profile_manager->RegisterTestingProfile(profile, true, false); 147 profile_manager->RegisterTestingProfile(profile, true, false);
126 ProfileSyncServiceMock* service = static_cast<ProfileSyncServiceMock*>( 148 ProfileSyncServiceMock* service = static_cast<ProfileSyncServiceMock*>(
127 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 149 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
128 profile, &ProfileSyncServiceMock::BuildMockProfileSyncService)); 150 profile, &ExtensionSessionsTest::BuildProfileSyncService));
129 browser_ = new Browser(Browser::CreateParams( 151 browser_ = new Browser(Browser::CreateParams(
130 profile, chrome::HOST_DESKTOP_TYPE_NATIVE)); 152 profile, chrome::HOST_DESKTOP_TYPE_NATIVE));
131 153
132 syncer::ModelTypeSet preferred_types; 154 syncer::ModelTypeSet preferred_types;
133 preferred_types.Put(syncer::SESSIONS); 155 preferred_types.Put(syncer::SESSIONS);
134 GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE); 156 GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE);
135 ON_CALL(*service, IsSessionsDataTypeControllerRunning()) 157 ON_CALL(*service, IsSessionsDataTypeControllerRunning())
136 .WillByDefault(testing::Return(true)); 158 .WillByDefault(testing::Return(true));
137 ON_CALL(*service, GetRegisteredDataTypes()) 159 ON_CALL(*service, GetRegisteredDataTypes())
138 .WillByDefault(testing::Return(syncer::UserTypes())); 160 .WillByDefault(testing::Return(syncer::UserTypes()));
139 ON_CALL(*service, GetPreferredDataTypes()).WillByDefault( 161 ON_CALL(*service, GetPreferredDataTypes()).WillByDefault(
140 testing::Return(preferred_types)); 162 testing::Return(preferred_types));
141 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly( 163 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(
142 testing::ReturnRef(no_error)); 164 testing::ReturnRef(no_error));
143 ON_CALL(*service, GetActiveDataTypes()).WillByDefault( 165 ON_CALL(*service, GetActiveDataTypes()).WillByDefault(
144 testing::Return(preferred_types)); 166 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()); 167 EXPECT_CALL(*service, AddObserver(testing::_)).Times(testing::AnyNumber());
155 EXPECT_CALL(*service, RemoveObserver(testing::_)).Times(testing::AnyNumber()); 168 EXPECT_CALL(*service, RemoveObserver(testing::_)).Times(testing::AnyNumber());
156 169
157 service->Initialize(); 170 service->Initialize();
158 } 171 }
159 172
160 void ExtensionSessionsTest::CreateTestExtension() { 173 void ExtensionSessionsTest::CreateTestExtension() {
161 scoped_ptr<base::DictionaryValue> test_extension_value( 174 scoped_ptr<base::DictionaryValue> test_extension_value(
162 utils::ParseDictionary( 175 utils::ParseDictionary(
163 "{\"name\": \"Test\", \"version\": \"1.0\", " 176 "{\"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). 355 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
343 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 356 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
344 return; 357 return;
345 #endif 358 #endif
346 359
347 ASSERT_TRUE(RunExtensionSubtest("sessions", 360 ASSERT_TRUE(RunExtensionSubtest("sessions",
348 "sessions.html")) << message_; 361 "sessions.html")) << message_;
349 } 362 }
350 363
351 } // namespace extensions 364 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698