def testBasic(self): manifest_file = os.path.join(unittest_data_dir, 'simple-working-app', 'manifest.json') app = chromeapp.App('simple-working-app', manifest_file, chromeapp_profiles_dir=self._profiles_dir) with TrackingAppInstance(app, ['hello']) as app_instance: ret = app_instance.Run() self.assertEquals(ret, 42)
def __init__(self, options, db, initial_filter): manifest_file = os.path.join(os.path.dirname(__file__), 'chrome_app', 'manifest.json') self.app = chromeapp.App('quickopen', manifest_file) self.print_results_cb = None # This postTask is needed because OpenDialog's base class assigns # print_results_cb after we return from the constructor, assuming # that the message loop is running. Le sigh. message_loop.post_task(self.Run, options, db, initial_filter)
def testAppThatPrints(self): manifest_file = os.path.join(unittest_data_dir, 'app-that-prints', 'manifest.json') app = chromeapp.App('app-that-prints', manifest_file, chromeapp_profiles_dir=self._profiles_dir) test = self class MyAppInstance(chromeapp.AppInstance): def _OnPrint(self, contents): try: test.assertEquals(len(contents), 1) test.assertEquals(contents[0], 'Hello world') finally: self.ExitRunLoop(0) with MyAppInstance(app) as app_instance: ret = app_instance.Run()
def testAppSideUncaughtErrorObject(self): manifest_file = os.path.join(unittest_data_dir, 'intentionally-failing-app', 'manifest.json') app = chromeapp.App('intentionally-failing-app', manifest_file, chromeapp_profiles_dir=self._profiles_dir) test = self class MyAppInstance(chromeapp.AppInstance): def _OnUncaughtError(self, error): try: test.assertEquals(error['error'], 'Uncaught Error: intentional failure') finally: self.ExitRunLoop(0) with MyAppInstance(app, '--throw-error-object') as app_instance: ret = app_instance.Run()
def Main(args): parser = optparse.OptionParser('%prog <filename>') parser.add_option('--debug', dest='debug_mode', action='store_true', default=False, help='Enables debugging features') options, args = parser.parse_args(args) if len(args) != 1: parser.error("argument required") if not os.path.exists(args[0]): parser.error("%s does not exist" % args[0]) manifest_file = os.path.join(os.path.dirname(__file__), 'app', 'manifest.json') app = chromeapp.App('cc-frame-viewer', manifest_file, debug_mode=options.debug_mode) def OnLoad(req): with open(args[0], 'r') as f: return f.read() input_filenames = [os.path.join(srcdir, f) for f in ['base.js', 'model_view.js']] view_js_file = os.path.join(os.path.dirname(__file__), 'app', 'model_view.js') view_css_file = os.path.join(os.path.dirname(__file__), 'app', 'model_view.css') with open(view_js_file, 'w') as f: f.write(generate_js(input_filenames)) with open(view_css_file, 'w') as f: f.write(generate_css(input_filenames)) with chromeapp.AppInstance(app, []) as app_instance: app_instance.AddListener('load', OnLoad) try: return app_instance.Run() finally: if os.path.exists(view_js_file): os.unlink(view_js_file) if os.path.exists(view_css_file): os.unlink(view_css_file)
def testAppThatSendsEvent(self): manifest_file = os.path.join(unittest_data_dir, 'app-that-sends-event', 'manifest.json') app = chromeapp.App('app-that-sends-event', manifest_file, chromeapp_profiles_dir=self._profiles_dir) got_event = [False] def OnEvent(args): arg1, arg2 = args self.assertEquals(arg1, [1, 2, 3]) self.assertEquals(arg2, True) got_event[0] = True return [314, 'hi'] with chromeapp.AppInstance(app) as app_instance: self.assertFalse(app_instance.HasListener('hello-world', OnEvent)) app_instance.AddListener('hello-world', OnEvent) self.assertTrue(app_instance.HasListener('hello-world', OnEvent)) ret = app_instance.Run() self.assertEquals(0, ret) app_instance.RemoveListener('hello-world', OnEvent) self.assertTrue(got_event[0])