| 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" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 navigation->set_title("MyTitle"); | 83 navigation->set_title("MyTitle"); |
| 84 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED); | 84 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED); |
| 85 } | 85 } |
| 86 | 86 |
| 87 class ExtensionSessionsTest : public InProcessBrowserTest { | 87 class ExtensionSessionsTest : public InProcessBrowserTest { |
| 88 public: | 88 public: |
| 89 void SetUpCommandLine(base::CommandLine* command_line) override; | 89 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 90 void SetUpOnMainThread() override; | 90 void SetUpOnMainThread() override; |
| 91 | 91 |
| 92 protected: | 92 protected: |
| 93 static KeyedService* BuildProfileSyncService( | 93 static scoped_ptr<KeyedService> BuildProfileSyncService( |
| 94 content::BrowserContext* profile); | 94 content::BrowserContext* profile); |
| 95 | 95 |
| 96 void CreateTestProfileSyncService(); | 96 void CreateTestProfileSyncService(); |
| 97 void CreateTestExtension(); | 97 void CreateTestExtension(); |
| 98 void CreateSessionModels(); | 98 void CreateSessionModels(); |
| 99 | 99 |
| 100 template <class T> | 100 template <class T> |
| 101 scoped_refptr<T> CreateFunction(bool has_callback) { | 101 scoped_refptr<T> CreateFunction(bool has_callback) { |
| 102 scoped_refptr<T> fn(new T()); | 102 scoped_refptr<T> fn(new T()); |
| 103 fn->set_extension(extension_.get()); | 103 fn->set_extension(extension_.get()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 114 command_line->AppendSwitch( | 114 command_line->AppendSwitch( |
| 115 chromeos::switches::kIgnoreUserProfileMappingForTests); | 115 chromeos::switches::kIgnoreUserProfileMappingForTests); |
| 116 #endif | 116 #endif |
| 117 } | 117 } |
| 118 | 118 |
| 119 void ExtensionSessionsTest::SetUpOnMainThread() { | 119 void ExtensionSessionsTest::SetUpOnMainThread() { |
| 120 CreateTestProfileSyncService(); | 120 CreateTestProfileSyncService(); |
| 121 CreateTestExtension(); | 121 CreateTestExtension(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 KeyedService* ExtensionSessionsTest::BuildProfileSyncService( | 124 scoped_ptr<KeyedService> ExtensionSessionsTest::BuildProfileSyncService( |
| 125 content::BrowserContext* profile) { | 125 content::BrowserContext* context) { |
| 126 | 126 scoped_ptr<ProfileSyncComponentsFactoryMock> factory( |
| 127 ProfileSyncComponentsFactoryMock* factory = | 127 new ProfileSyncComponentsFactoryMock()); |
| 128 new ProfileSyncComponentsFactoryMock(); | |
| 129 | 128 |
| 130 factory->SetLocalDeviceInfoProvider( | 129 factory->SetLocalDeviceInfoProvider( |
| 131 scoped_ptr<sync_driver::LocalDeviceInfoProvider>( | 130 scoped_ptr<sync_driver::LocalDeviceInfoProvider>( |
| 132 new sync_driver::LocalDeviceInfoProviderMock( | 131 new sync_driver::LocalDeviceInfoProviderMock( |
| 133 kSessionTags[0], | 132 kSessionTags[0], |
| 134 "machine name", | 133 "machine name", |
| 135 "Chromium 10k", | 134 "Chromium 10k", |
| 136 "Chrome 10k", | 135 "Chrome 10k", |
| 137 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | 136 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, |
| 138 "device_id"))); | 137 "device_id"))); |
| 139 | 138 |
| 140 return new ProfileSyncServiceMock( | 139 return make_scoped_ptr(new ProfileSyncServiceMock( |
| 141 scoped_ptr<ProfileSyncComponentsFactory>(factory), | 140 factory.Pass(), static_cast<Profile*>(context))); |
| 142 static_cast<Profile*>(profile)); | |
| 143 } | 141 } |
| 144 | 142 |
| 145 void ExtensionSessionsTest::CreateTestProfileSyncService() { | 143 void ExtensionSessionsTest::CreateTestProfileSyncService() { |
| 146 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 144 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 147 base::FilePath path; | 145 base::FilePath path; |
| 148 PathService::Get(chrome::DIR_USER_DATA, &path); | 146 PathService::Get(chrome::DIR_USER_DATA, &path); |
| 149 path = path.AppendASCII("test_profile"); | 147 path = path.AppendASCII("test_profile"); |
| 150 if (!base::PathExists(path)) | 148 if (!base::PathExists(path)) |
| 151 CHECK(base::CreateDirectory(path)); | 149 CHECK(base::CreateDirectory(path)); |
| 152 Profile* profile = | 150 Profile* profile = |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 return; | 384 return; |
| 387 #endif | 385 #endif |
| 388 | 386 |
| 389 ASSERT_TRUE(RunExtensionSubtest("sessions", | 387 ASSERT_TRUE(RunExtensionSubtest("sessions", |
| 390 "sessions.html")) << message_; | 388 "sessions.html")) << message_; |
| 391 } | 389 } |
| 392 | 390 |
| 393 } // namespace | 391 } // namespace |
| 394 | 392 |
| 395 } // namespace extensions | 393 } // namespace extensions |
| OLD | NEW |