Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / storage / settings_apitest.cc
index 2cf74da..2a3120f 100644 (file)
@@ -7,22 +7,24 @@
 #include "base/memory/ref_counted.h"
 #include "base/run_loop.h"
 #include "base/values.h"
-#include "chrome/browser/extensions/api/storage/settings_frontend.h"
-#include "chrome/browser/extensions/api/storage/settings_namespace.h"
 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
 #include "chrome/browser/extensions/extension_apitest.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_system.h"
 #include "chrome/browser/extensions/extension_system_factory.h"
-#include "chrome/browser/extensions/extension_test_message_listener.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/ui/browser.h"
-#include "chrome/test/base/ui_test_utils.h"
+#include "extensions/browser/api/storage/settings_namespace.h"
+#include "extensions/browser/api/storage/storage_frontend.h"
+#include "extensions/browser/extension_system.h"
 #include "extensions/common/value_builder.h"
+#include "extensions/test/extension_test_message_listener.h"
+#include "extensions/test/result_catcher.h"
+#include "sync/api/fake_sync_change_processor.h"
 #include "sync/api/sync_change.h"
 #include "sync/api/sync_change_processor.h"
+#include "sync/api/sync_change_processor_wrapper_for_test.h"
 #include "sync/api/sync_error_factory.h"
 #include "sync/api/sync_error_factory_mock.h"
+#include "sync/api/syncable_service.h"
 #include "testing/gmock/include/gmock/gmock.h"
 
 #if defined(ENABLE_CONFIGURATION_POLICY)
@@ -59,49 +61,6 @@ const syncer::ModelType kModelType = syncer::EXTENSION_SETTINGS;
 // the extension.
 const char kManagedStorageExtensionId[] = "kjmkgkdkpedkejedfhmfcenooemhbpbo";
 
-class NoopSyncChangeProcessor : public syncer::SyncChangeProcessor {
- public:
-  virtual syncer::SyncError ProcessSyncChanges(
-      const tracked_objects::Location& from_here,
-      const syncer::SyncChangeList& change_list) OVERRIDE {
-    return syncer::SyncError();
-  }
-
-  virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
-      OVERRIDE {
-    return syncer::SyncDataList();
-  }
-
-  virtual ~NoopSyncChangeProcessor() {};
-};
-
-class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor {
- public:
-  explicit SyncChangeProcessorDelegate(syncer::SyncChangeProcessor* recipient)
-      : recipient_(recipient) {
-    DCHECK(recipient_);
-  }
-  virtual ~SyncChangeProcessorDelegate() {}
-
-  // syncer::SyncChangeProcessor implementation.
-  virtual syncer::SyncError ProcessSyncChanges(
-      const tracked_objects::Location& from_here,
-      const syncer::SyncChangeList& change_list) OVERRIDE {
-    return recipient_->ProcessSyncChanges(from_here, change_list);
-  }
-
-  virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
-      OVERRIDE {
-    return recipient_->GetAllSyncData(type);
-  }
-
- private:
-  // The recipient of all sync changes.
-  syncer::SyncChangeProcessor* recipient_;
-
-  DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate);
-};
-
 class MockSchemaRegistryObserver : public policy::SchemaRegistry::Observer {
  public:
   MockSchemaRegistryObserver() {}
@@ -115,7 +74,7 @@ class MockSchemaRegistryObserver : public policy::SchemaRegistry::Observer {
 
 class ExtensionSettingsApiTest : public ExtensionApiTest {
  protected:
-  virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
+  void SetUpInProcessBrowserTestFixture() override {
     ExtensionApiTest::SetUpInProcessBrowserTestFixture();
 
 #if defined(ENABLE_CONFIGURATION_POLICY)
@@ -156,20 +115,19 @@ class ExtensionSettingsApiTest : public ExtensionApiTest {
         settings_namespace, normal_action, incognito_action, NULL, true);
   }
 
+  syncer::SyncableService* GetSyncableService() {
+    return settings_sync_util::GetSyncableService(browser()->profile(),
+                                                  kModelType);
+  }
+
   void InitSync(syncer::SyncChangeProcessor* sync_processor) {
     base::MessageLoop::current()->RunUntilIdle();
-    InitSyncWithSyncableService(
-        sync_processor,
-        browser()->profile()->GetExtensionService()->settings_frontend()->
-              GetBackendForSync(kModelType));
+    InitSyncWithSyncableService(sync_processor, GetSyncableService());
   }
 
   void SendChanges(const syncer::SyncChangeList& change_list) {
     base::MessageLoop::current()->RunUntilIdle();
-    SendChangesToSyncableService(
-        change_list,
-        browser()->profile()->GetExtensionService()->settings_frontend()->
-              GetBackendForSync(kModelType));
+    SendChangesToSyncableService(change_list, GetSyncableService());
   }
 
 #if defined(ENABLE_CONFIGURATION_POLICY)
@@ -229,13 +187,17 @@ class ExtensionSettingsApiTest : public ExtensionApiTest {
   void InitSyncWithSyncableService(
       syncer::SyncChangeProcessor* sync_processor,
       syncer::SyncableService* settings_service) {
-    EXPECT_FALSE(settings_service->MergeDataAndStartSyncing(
-        kModelType,
-        syncer::SyncDataList(),
-        scoped_ptr<syncer::SyncChangeProcessor>(
-            new SyncChangeProcessorDelegate(sync_processor)),
-        scoped_ptr<syncer::SyncErrorFactory>(
-            new syncer::SyncErrorFactoryMock())).error().IsSet());
+    EXPECT_FALSE(
+        settings_service->MergeDataAndStartSyncing(
+                              kModelType,
+                              syncer::SyncDataList(),
+                              scoped_ptr<syncer::SyncChangeProcessor>(
+                                  new syncer::SyncChangeProcessorWrapperForTest(
+                                      sync_processor)),
+                              scoped_ptr<syncer::SyncErrorFactory>(
+                                  new syncer::SyncErrorFactoryMock()))
+            .error()
+            .IsSet());
   }
 
   void SendChangesToSyncableService(
@@ -263,8 +225,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, SplitModeIncognito) {
   // We need 2 ResultCatchers because we'll be running the same test in both
   // regular and incognito mode.
   ResultCatcher catcher, catcher_incognito;
-  catcher.RestrictToProfile(browser()->profile());
-  catcher_incognito.RestrictToProfile(
+  catcher.RestrictToBrowserContext(browser()->profile());
+  catcher_incognito.RestrictToBrowserContext(
       browser()->profile()->GetOffTheRecordProfile());
 
   LoadAndReplyWhenSatisfied(SYNC,
@@ -287,8 +249,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
   // We need 2 ResultCatchers because we'll be running the same test in both
   // regular and incognito mode.
   ResultCatcher catcher, catcher_incognito;
-  catcher.RestrictToProfile(browser()->profile());
-  catcher_incognito.RestrictToProfile(
+  catcher.RestrictToBrowserContext(browser()->profile());
+  catcher_incognito.RestrictToBrowserContext(
       browser()->profile()->GetOffTheRecordProfile());
 
   LoadAndReplyWhenSatisfied(SYNC,
@@ -310,8 +272,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
   // We need 2 ResultCatchers because we'll be running the same test in both
   // regular and incognito mode.
   ResultCatcher catcher, catcher_incognito;
-  catcher.RestrictToProfile(browser()->profile());
-  catcher_incognito.RestrictToProfile(
+  catcher.RestrictToBrowserContext(browser()->profile());
+  catcher_incognito.RestrictToBrowserContext(
       browser()->profile()->GetOffTheRecordProfile());
 
   LoadAndReplyWhenSatisfied(SYNC,
@@ -361,8 +323,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
   // We need 2 ResultCatchers because we'll be running the same test in both
   // regular and incognito mode.
   ResultCatcher catcher, catcher_incognito;
-  catcher.RestrictToProfile(browser()->profile());
-  catcher_incognito.RestrictToProfile(
+  catcher.RestrictToBrowserContext(browser()->profile());
+  catcher_incognito.RestrictToBrowserContext(
       browser()->profile()->GetOffTheRecordProfile());
 
   const Extension* extension =
@@ -370,7 +332,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
           "assertNoNotifications", "assertNoNotifications", "split_incognito");
   const std::string& extension_id = extension->id();
 
-  NoopSyncChangeProcessor sync_processor;
+  syncer::FakeSyncChangeProcessor sync_processor;
   InitSync(&sync_processor);
 
   // Set "foo" to "bar" via sync.
@@ -406,8 +368,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
   // We need 2 ResultCatchers because we'll be running the same test in both
   // regular and incognito mode.
   ResultCatcher catcher, catcher_incognito;
-  catcher.RestrictToProfile(browser()->profile());
-  catcher_incognito.RestrictToProfile(
+  catcher.RestrictToBrowserContext(browser()->profile());
+  catcher_incognito.RestrictToBrowserContext(
       browser()->profile()->GetOffTheRecordProfile());
 
   const Extension* extension =
@@ -415,7 +377,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
           "assertNoNotifications", "assertNoNotifications", "split_incognito");
   const std::string& extension_id = extension->id();
 
-  NoopSyncChangeProcessor sync_processor;
+  syncer::FakeSyncChangeProcessor sync_processor;
   InitSync(&sync_processor);
 
   // Set "foo" to "bar" via sync.
@@ -441,8 +403,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
 }
 
 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, IsStorageEnabled) {
-  SettingsFrontend* frontend =
-      browser()->profile()->GetExtensionService()->settings_frontend();
+  StorageFrontend* frontend = StorageFrontend::Get(browser()->profile());
   EXPECT_TRUE(frontend->IsStorageEnabled(LOCAL));
   EXPECT_TRUE(frontend->IsStorageEnabled(SYNC));
 
@@ -458,8 +419,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, IsStorageEnabled) {
 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ExtensionsSchemas) {
   // Verifies that the Schemas for the extensions domain are created on startup.
   Profile* profile = browser()->profile();
-  ExtensionSystem* extension_system =
-      ExtensionSystemFactory::GetForProfile(profile);
+  ExtensionSystem* extension_system = ExtensionSystem::Get(profile);
   if (!extension_system->ready().is_signaled()) {
     // Wait until the extension system is ready.
     base::RunLoop run_loop;
@@ -473,7 +433,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ExtensionsSchemas) {
   message_.clear();
 
   policy::SchemaRegistry* registry =
-      policy::SchemaRegistryServiceFactory::GetForContext(profile);
+      policy::SchemaRegistryServiceFactory::GetForContext(profile)->registry();
   ASSERT_TRUE(registry);
   EXPECT_FALSE(registry->schema_map()->GetSchema(policy::PolicyNamespace(
       policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId)));
@@ -611,8 +571,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorageDisabled) {
   // Disable the 'managed' namespace. This is redundant when
   // ENABLE_CONFIGURATION_POLICY is not defined.
-  SettingsFrontend* frontend =
-      browser()->profile()->GetExtensionService()->settings_frontend();
+  StorageFrontend* frontend = StorageFrontend::Get(browser()->profile());
   frontend->DisableStorageForTesting(MANAGED);
   EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED));
   // Now run the extension.