| OLD | NEW |
| 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 Loading... |
| 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 factory->SetLocalDeviceInfoProvider( |
| 128 scoped_ptr<LocalDeviceInfoProvider>( |
| 129 new browser_sync::LocalDeviceInfoProviderMock( |
| 130 kSessionTags[0], |
| 131 "machine name", |
| 132 "Chromium 10k", |
| 133 "Chrome 10k", |
| 134 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, |
| 135 "device_id"))); |
| 136 |
| 137 return new ProfileSyncServiceMock( |
| 138 scoped_ptr<ProfileSyncComponentsFactory>(factory), |
| 139 static_cast<Profile*>(profile)); |
| 140 } |
| 141 |
| 116 void ExtensionSessionsTest::CreateTestProfileSyncService() { | 142 void ExtensionSessionsTest::CreateTestProfileSyncService() { |
| 117 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 143 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 118 base::FilePath path; | 144 base::FilePath path; |
| 119 PathService::Get(chrome::DIR_USER_DATA, &path); | 145 PathService::Get(chrome::DIR_USER_DATA, &path); |
| 120 path = path.AppendASCII("test_profile"); | 146 path = path.AppendASCII("test_profile"); |
| 121 if (!base::PathExists(path)) | 147 if (!base::PathExists(path)) |
| 122 CHECK(base::CreateDirectory(path)); | 148 CHECK(base::CreateDirectory(path)); |
| 123 Profile* profile = | 149 Profile* profile = |
| 124 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); | 150 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); |
| 125 profile_manager->RegisterTestingProfile(profile, true, false); | 151 profile_manager->RegisterTestingProfile(profile, true, false); |
| 126 ProfileSyncServiceMock* service = static_cast<ProfileSyncServiceMock*>( | 152 ProfileSyncServiceMock* service = static_cast<ProfileSyncServiceMock*>( |
| 127 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 153 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 128 profile, &ProfileSyncServiceMock::BuildMockProfileSyncService)); | 154 profile, &ExtensionSessionsTest::BuildProfileSyncService)); |
| 129 browser_ = new Browser(Browser::CreateParams( | 155 browser_ = new Browser(Browser::CreateParams( |
| 130 profile, chrome::HOST_DESKTOP_TYPE_NATIVE)); | 156 profile, chrome::HOST_DESKTOP_TYPE_NATIVE)); |
| 131 | 157 |
| 132 syncer::ModelTypeSet preferred_types; | 158 syncer::ModelTypeSet preferred_types; |
| 133 preferred_types.Put(syncer::SESSIONS); | 159 preferred_types.Put(syncer::SESSIONS); |
| 134 GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE); | 160 GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE); |
| 135 ON_CALL(*service, IsSessionsDataTypeControllerRunning()) | 161 ON_CALL(*service, IsSessionsDataTypeControllerRunning()) |
| 136 .WillByDefault(testing::Return(true)); | 162 .WillByDefault(testing::Return(true)); |
| 137 ON_CALL(*service, GetRegisteredDataTypes()) | 163 ON_CALL(*service, GetRegisteredDataTypes()) |
| 138 .WillByDefault(testing::Return(syncer::UserTypes())); | 164 .WillByDefault(testing::Return(syncer::UserTypes())); |
| 139 ON_CALL(*service, GetPreferredDataTypes()).WillByDefault( | 165 ON_CALL(*service, GetPreferredDataTypes()).WillByDefault( |
| 140 testing::Return(preferred_types)); | 166 testing::Return(preferred_types)); |
| 141 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly( | 167 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly( |
| 142 testing::ReturnRef(no_error)); | 168 testing::ReturnRef(no_error)); |
| 143 ON_CALL(*service, GetActiveDataTypes()).WillByDefault( | 169 ON_CALL(*service, GetActiveDataTypes()).WillByDefault( |
| 144 testing::Return(preferred_types)); | 170 testing::Return(preferred_types)); |
| 145 ON_CALL(*service, GetLocalDeviceInfoMock()).WillByDefault( | 171 |
| 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 "device_id"))); | |
| 153 ON_CALL(*service, GetLocalSyncCacheGUID()).WillByDefault( | |
| 154 testing::Return(std::string(kSessionTags[0]))); | |
| 155 EXPECT_CALL(*service, AddObserver(testing::_)).Times(testing::AnyNumber()); | 172 EXPECT_CALL(*service, AddObserver(testing::_)).Times(testing::AnyNumber()); |
| 156 EXPECT_CALL(*service, RemoveObserver(testing::_)).Times(testing::AnyNumber()); | 173 EXPECT_CALL(*service, RemoveObserver(testing::_)).Times(testing::AnyNumber()); |
| 157 | 174 |
| 158 service->Initialize(); | 175 service->Initialize(); |
| 159 } | 176 } |
| 160 | 177 |
| 161 void ExtensionSessionsTest::CreateTestExtension() { | 178 void ExtensionSessionsTest::CreateTestExtension() { |
| 162 scoped_ptr<base::DictionaryValue> test_extension_value( | 179 scoped_ptr<base::DictionaryValue> test_extension_value( |
| 163 utils::ParseDictionary( | 180 utils::ParseDictionary( |
| 164 "{\"name\": \"Test\", \"version\": \"1.0\", " | 181 "{\"name\": \"Test\", \"version\": \"1.0\", " |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 360 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 344 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 361 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| 345 return; | 362 return; |
| 346 #endif | 363 #endif |
| 347 | 364 |
| 348 ASSERT_TRUE(RunExtensionSubtest("sessions", | 365 ASSERT_TRUE(RunExtensionSubtest("sessions", |
| 349 "sessions.html")) << message_; | 366 "sessions.html")) << message_; |
| 350 } | 367 } |
| 351 | 368 |
| 352 } // namespace extensions | 369 } // namespace extensions |
| OLD | NEW |