Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / sessions / sessions_apitest.cc
index 6d0a7f1..28cb25e 100644 (file)
@@ -11,7 +11,9 @@
 #include "chrome/browser/extensions/extension_apitest.h"
 #include "chrome/browser/extensions/extension_function_test_utils.h"
 #include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/sync/glue/local_device_info_provider_mock.h"
 #include "chrome/browser/sync/open_tabs_ui_delegate.h"
+#include "chrome/browser/sync/profile_sync_components_factory_mock.h"
 #include "chrome/browser/sync/profile_sync_service.h"
 #include "chrome/browser/sync/profile_sync_service_factory.h"
 #include "chrome/browser/sync/profile_sync_service_mock.h"
 #include "chrome/test/base/test_switches.h"
 #include "chrome/test/base/testing_browser_process.h"
 #include "sync/api/attachments/attachment_id.h"
-#include "sync/api/attachments/attachment_service_proxy_for_test.h"
 #include "sync/api/fake_sync_change_processor.h"
 #include "sync/api/sync_error_factory_mock.h"
+#include "sync/internal_api/public/attachments/attachment_service_proxy_for_test.h"
+
+#if defined(OS_CHROMEOS)
+#include "chromeos/chromeos_switches.h"
+#endif
 
 namespace utils = extension_function_test_utils;
 
@@ -78,8 +84,12 @@ void BuildTabSpecifics(const std::string& tag, int window_id, int tab_id,
 
 class ExtensionSessionsTest : public InProcessBrowserTest {
  public:
+  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
   virtual void SetUpOnMainThread() OVERRIDE;
  protected:
+  static KeyedService* BuildProfileSyncService(
+      content::BrowserContext* profile);
+
   void CreateTestProfileSyncService();
   void CreateTestExtension();
   void CreateSessionModels();
@@ -96,11 +106,39 @@ class ExtensionSessionsTest : public InProcessBrowserTest {
   scoped_refptr<extensions::Extension> extension_;
 };
 
+void ExtensionSessionsTest::SetUpCommandLine(CommandLine* command_line) {
+#if defined(OS_CHROMEOS)
+  command_line->AppendSwitch(
+      chromeos::switches::kIgnoreUserProfileMappingForTests);
+#endif
+}
+
 void ExtensionSessionsTest::SetUpOnMainThread() {
   CreateTestProfileSyncService();
   CreateTestExtension();
 }
 
+KeyedService* ExtensionSessionsTest::BuildProfileSyncService(
+    content::BrowserContext* profile) {
+
+  ProfileSyncComponentsFactoryMock* factory =
+      new ProfileSyncComponentsFactoryMock();
+
+  factory->SetLocalDeviceInfoProvider(
+      scoped_ptr<sync_driver::LocalDeviceInfoProvider>(
+          new browser_sync::LocalDeviceInfoProviderMock(
+              kSessionTags[0],
+              "machine name",
+              "Chromium 10k",
+              "Chrome 10k",
+              sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
+              "device_id")));
+
+  return new ProfileSyncServiceMock(
+      scoped_ptr<ProfileSyncComponentsFactory>(factory),
+      static_cast<Profile*>(profile));
+}
+
 void ExtensionSessionsTest::CreateTestProfileSyncService() {
   ProfileManager* profile_manager = g_browser_process->profile_manager();
   base::FilePath path;
@@ -113,14 +151,14 @@ void ExtensionSessionsTest::CreateTestProfileSyncService() {
   profile_manager->RegisterTestingProfile(profile, true, false);
   ProfileSyncServiceMock* service = static_cast<ProfileSyncServiceMock*>(
       ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
-      profile, &ProfileSyncServiceMock::BuildMockProfileSyncService));
+      profile, &ExtensionSessionsTest::BuildProfileSyncService));
   browser_ = new Browser(Browser::CreateParams(
       profile, chrome::HOST_DESKTOP_TYPE_NATIVE));
 
   syncer::ModelTypeSet preferred_types;
   preferred_types.Put(syncer::SESSIONS);
   GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE);
-  ON_CALL(*service, IsSessionsDataTypeControllerRunning())
+  ON_CALL(*service, IsDataTypeControllerRunning(syncer::SESSIONS))
       .WillByDefault(testing::Return(true));
   ON_CALL(*service, GetRegisteredDataTypes())
       .WillByDefault(testing::Return(syncer::UserTypes()));
@@ -130,15 +168,7 @@ void ExtensionSessionsTest::CreateTestProfileSyncService() {
       testing::ReturnRef(no_error));
   ON_CALL(*service, GetActiveDataTypes()).WillByDefault(
       testing::Return(preferred_types));
-  ON_CALL(*service, GetLocalDeviceInfoMock()).WillByDefault(
-      testing::Return(new browser_sync::DeviceInfo(
-          std::string(kSessionTags[0]),
-          "machine name",
-          "Chromium 10k",
-          "Chrome 10k",
-          sync_pb::SyncEnums_DeviceType_TYPE_LINUX)));
-  ON_CALL(*service, GetLocalSyncCacheGUID()).WillByDefault(
-      testing::Return(std::string(kSessionTags[0])));
+
   EXPECT_CALL(*service, AddObserver(testing::_)).Times(testing::AnyNumber());
   EXPECT_CALL(*service, RemoveObserver(testing::_)).Times(testing::AnyNumber());
 
@@ -214,6 +244,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionSessionsTest, GetDevices) {
   for (size_t i = 0; i < devices->GetSize(); ++i) {
     EXPECT_TRUE(devices->GetDictionary(i, &device));
     EXPECT_EQ(kSessionTags[i], utils::GetString(device, "info"));
+    EXPECT_EQ(kSessionTags[i], utils::GetString(device, "deviceName"));
     EXPECT_TRUE(device->GetList("sessions", &sessions));
     EXPECT_EQ(0u, sessions->GetSize());
   }
@@ -235,6 +266,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionSessionsTest, GetDevicesMaxResults) {
   for (size_t i = 0; i < devices->GetSize(); ++i) {
     EXPECT_TRUE(devices->GetDictionary(i, &device));
     EXPECT_EQ(kSessionTags[i], utils::GetString(device, "info"));
+    EXPECT_EQ(kSessionTags[i], utils::GetString(device, "deviceName"));
     EXPECT_TRUE(device->GetList("sessions", &sessions));
     EXPECT_EQ(1u, sessions->GetSize());
   }