Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / server2 / cron_servlet_test.py
index 371d100..dda11cb 100755 (executable)
@@ -5,27 +5,33 @@
 
 import unittest
 
-from appengine_wrappers import GetAppVersion
 from app_yaml_helper import AppYamlHelper
+from content_providers import IgnoreMissingContentProviders
 from cron_servlet import CronServlet
 from empty_dir_file_system import EmptyDirFileSystem
+from environment import GetAppVersion
+from extensions_paths import (
+    APP_YAML, CONTENT_PROVIDERS, CHROME_EXTENSIONS, PUBLIC_TEMPLATES, SERVER2,
+    STATIC_DOCS)
+from fake_fetchers import ConfigureFakeFetchers
+from gcs_file_system_provider import CloudStorageFileSystemProvider
 from github_file_system_provider import GithubFileSystemProvider
 from host_file_system_provider import HostFileSystemProvider
 from local_file_system import LocalFileSystem
 from mock_file_system import MockFileSystem
 from servlet import Request
-from svn_constants import JSON_PATH
 from test_branch_utility import TestBranchUtility
-from test_file_system import TestFileSystem
+from test_file_system import MoveTo, TestFileSystem
 from test_util import EnableLogging, ReadFile
 
+
 # NOTE(kalman): The ObjectStore created by the CronServlet is backed onto our
 # fake AppEngine memcache/datastore, so the tests aren't isolated. Of course,
 # if the host file systems have different identities, they will be, sort of.
 class _TestDelegate(CronServlet.Delegate):
   def __init__(self, create_file_system):
     self.file_systems = []
-    # A callback taking a revision and returning a file system.
+    # A callback taking a commit and returning a file system.
     self._create_file_system = create_file_system
     self._app_version = GetAppVersion()
 
@@ -34,18 +40,21 @@ class _TestDelegate(CronServlet.Delegate):
 
   def CreateHostFileSystemProvider(self,
                                   object_store_creator,
-                                  max_trunk_revision=None):
-    def constructor(branch=None, revision=None):
-      file_system = self._create_file_system(revision)
+                                  pinned_commit=None):
+    def constructor(branch=None, commit=None):
+      file_system = self._create_file_system(commit)
       self.file_systems.append(file_system)
       return file_system
     return HostFileSystemProvider(object_store_creator,
-                                  max_trunk_revision=max_trunk_revision,
+                                  pinned_commit=pinned_commit,
                                   constructor_for_test=constructor)
 
   def CreateGithubFileSystemProvider(self, object_store_creator):
     return GithubFileSystemProvider.ForEmpty()
 
+  def CreateGCSFileSystemProvider(self, object_store_creator):
+    return CloudStorageFileSystemProvider.ForEmpty()
+
   def GetAppVersion(self):
     return self._app_version
 
@@ -82,38 +91,67 @@ class CronServletTest(unittest.TestCase):
           read_count=0,
           stat_count=first_run_file_systems[i].GetStatCount()))
 
+  @IgnoreMissingContentProviders
   def testSafeRevision(self):
     test_data = {
-      'api': {
-        '_manifest_features.json': '{}'
+      'extensions': {
+        'browser': {
+          'api': {}
+        }
       },
-      'docs': {
-        'examples': {
-          'examples.txt': 'examples.txt contents'
-        },
-        'server2': {
-          'app.yaml': AppYamlHelper.GenerateAppYaml('2-0-8')
+      'chrome': {
+        'browser': {
+          'extensions': {
+            'OWNERS': '',
+            'api': {}
+          }
         },
-        'static': {
-          'static.txt': 'static.txt contents'
-        },
-        'templates': {
-          'public': {
-            'apps': {
-              'storage.html': 'storage.html contents'
-            },
-            'extensions': {
-              'storage.html': 'storage.html contents'
+        'common': {
+          'extensions': {
+            'api': {
+              '_api_features.json': '{}',
+              '_manifest_features.json': '{}',
+              '_permission_features.json': '{}',
             },
-          },
-          'json': {
-            'content_providers.json': ReadFile('%s/content_providers.json' %
-                                               JSON_PATH),
-            'manifest.json': '{}',
-            'strings.json': '{}',
-            'apps_sidenav.json': '{}',
-            'extensions_sidenav.json': '{}',
-          },
+            'docs': {
+              'examples': {
+                'examples.txt': 'examples.txt contents'
+              },
+              'server2': {
+                'app.yaml': AppYamlHelper.GenerateAppYaml('2-0-8')
+              },
+              'static': {
+                'static.txt': 'static.txt contents'
+              },
+              'templates': {
+                'articles': {
+                  'activeTab.html': 'activeTab.html contents'
+                },
+                'intros': {
+                  'browserAction.html': 'activeTab.html contents'
+                },
+                'private': {
+                  'table_of_contents.html': 'table_of_contents.html contents',
+                },
+                'public': {
+                  'apps': {
+                    'storage.html': '<h1>storage.html</h1> contents'
+                  },
+                  'extensions': {
+                    'storage.html': '<h1>storage.html</h1> contents'
+                  },
+                },
+                'json': {
+                  'chrome_sidenav.json': '{}',
+                  'content_providers.json': ReadFile(CONTENT_PROVIDERS),
+                  'manifest.json': '{}',
+                  'permissions.json': '{}',
+                  'strings.json': '{}',
+                  'whats_new.json': '{}',
+                },
+              }
+            }
+          }
         }
       }
     }
@@ -121,30 +159,29 @@ class CronServletTest(unittest.TestCase):
     updates = []
 
     def app_yaml_update(version):
-      return {'docs': {'server2': {
+      return MoveTo(SERVER2, {
         'app.yaml': AppYamlHelper.GenerateAppYaml(version)
-      }}}
+      })
     def storage_html_update(update):
-      return {'docs': {'templates': {'public': {'apps': {
-        'storage.html': update
-      }}}}}
+      return MoveTo(PUBLIC_TEMPLATES, {
+        'apps': {'storage.html': update}
+      })
     def static_txt_update(update):
-      return {'docs': {'static': {
+      return MoveTo(STATIC_DOCS, {
         'static.txt': update
-      }}}
+      })
 
-    app_yaml_path = 'docs/server2/app.yaml'
-    storage_html_path = 'docs/templates/public/apps/storage.html'
-    static_txt_path = 'docs/static/static.txt'
+    storage_html_path = PUBLIC_TEMPLATES + 'apps/storage.html'
+    static_txt_path = STATIC_DOCS + 'static.txt'
 
-    def create_file_system(revision=None):
-      '''Creates a MockFileSystem at |revision| by applying that many |updates|
+    def create_file_system(commit=None):
+      '''Creates a MockFileSystem at |commit| by applying that many |updates|
       to it.
       '''
       mock_file_system = MockFileSystem(TestFileSystem(test_data))
-      updates_for_revision = (
-          updates if revision is None else updates[:int(revision)])
-      for update in updates_for_revision:
+      updates_for_commit = (
+          updates if commit is None else updates[:int(commit)])
+      for update in updates_for_commit:
         mock_file_system.Update(update)
       return mock_file_system
 
@@ -156,25 +193,25 @@ class CronServletTest(unittest.TestCase):
     # No updates applied yet.
     CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
     self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
-                     file_systems[-1].ReadSingle(app_yaml_path).Get())
-    self.assertEqual('storage.html contents',
+                     file_systems[-1].ReadSingle(APP_YAML).Get())
+    self.assertEqual('<h1>storage.html</h1> contents',
                      file_systems[-1].ReadSingle(storage_html_path).Get())
 
     # Apply updates to storage.html.
     updates.append(storage_html_update('interim contents'))
-    updates.append(storage_html_update('new contents'))
+    updates.append(storage_html_update('<h1>new</h1> contents'))
 
     CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
     self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
-                     file_systems[-1].ReadSingle(app_yaml_path).Get())
-    self.assertEqual('new contents',
+                     file_systems[-1].ReadSingle(APP_YAML).Get())
+    self.assertEqual('<h1>new</h1> contents',
                      file_systems[-1].ReadSingle(storage_html_path).Get())
 
     # Apply several updates to storage.html and app.yaml. The file system
     # should be pinned at the version before app.yaml changed.
-    updates.append(storage_html_update('stuck here contents'))
+    updates.append(storage_html_update('<h1>stuck here</h1> contents'))
 
-    double_update = storage_html_update('newer contents')
+    double_update = storage_html_update('<h1>newer</h1> contents')
     double_update.update(app_yaml_update('2-0-10'))
     updates.append(double_update)
 
@@ -182,17 +219,17 @@ class CronServletTest(unittest.TestCase):
 
     CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
     self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
-                     file_systems[-1].ReadSingle(app_yaml_path).Get())
-    self.assertEqual('stuck here contents',
+                     file_systems[-1].ReadSingle(APP_YAML).Get())
+    self.assertEqual('<h1>stuck here</h1> contents',
                      file_systems[-1].ReadSingle(storage_html_path).Get())
 
     # Further pushes to storage.html will keep it pinned.
-    updates.append(storage_html_update('y u not update!'))
+    updates.append(storage_html_update('<h1>y</h1> u not update!'))
 
     CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
     self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
-                     file_systems[-1].ReadSingle(app_yaml_path).Get())
-    self.assertEqual('stuck here contents',
+                     file_systems[-1].ReadSingle(APP_YAML).Get())
+    self.assertEqual('<h1>stuck here</h1> contents',
                      file_systems[-1].ReadSingle(storage_html_path).Get())
 
     # Likewise app.yaml.
@@ -200,8 +237,8 @@ class CronServletTest(unittest.TestCase):
 
     CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
     self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
-                     file_systems[-1].ReadSingle(app_yaml_path).Get())
-    self.assertEqual('stuck here contents',
+                     file_systems[-1].ReadSingle(APP_YAML).Get())
+    self.assertEqual('<h1>stuck here</h1> contents',
                      file_systems[-1].ReadSingle(storage_html_path).Get())
 
     # And updates to other content won't happen either.
@@ -209,8 +246,8 @@ class CronServletTest(unittest.TestCase):
 
     CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
     self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
-                     file_systems[-1].ReadSingle(app_yaml_path).Get())
-    self.assertEqual('stuck here contents',
+                     file_systems[-1].ReadSingle(APP_YAML).Get())
+    self.assertEqual('<h1>stuck here</h1> contents',
                      file_systems[-1].ReadSingle(storage_html_path).Get())
     self.assertEqual('static.txt contents',
                      file_systems[-1].ReadSingle(static_txt_path).Get())
@@ -220,11 +257,12 @@ class CronServletTest(unittest.TestCase):
     delegate.SetAppVersion('2-1-0')
     CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
     self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'),
-                     file_systems[-1].ReadSingle(app_yaml_path).Get())
-    self.assertEqual('y u not update!',
+                     file_systems[-1].ReadSingle(APP_YAML).Get())
+    self.assertEqual('<h1>y</h1> u not update!',
                      file_systems[-1].ReadSingle(storage_html_path).Get())
     self.assertEqual('important content!',
                      file_systems[-1].ReadSingle(static_txt_path).Get())
 
+
 if __name__ == '__main__':
   unittest.main()