blob: 6603acc26270fbd5b813c2c004064a8115431091 [file] [log] [blame]
Chris Craikf516a622015-04-01 17:52:39 -07001<!DOCTYPE html>
2<!--
3Copyright 2015 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
Chris Craik44c28202015-05-12 17:25:16 -07008<link rel="import" href="/base/event_target.html">
Chris Craikf516a622015-04-01 17:52:39 -07009<link rel="import" href="/core/scripting_controller.html">
10<link rel="import" href="/core/test_utils.html">
11<link rel="import" href="/core/timeline_track_view.html">
12
13<script>
14'use strict';
15
16tv.b.unittest.testSuite(function() {
Chris Craik44c28202015-05-12 17:25:16 -070017 function FakeSelectionController() {
18 tv.b.EventTarget.call(this);
19
20 this.addAllEventsMatchingFilterToSelectionReturnValue = [];
21
22 this.viewport = undefined;
23 this.model = undefined;
24 this.selection = new tv.c.Selection();
25 this.highlight = new tv.c.Selection();
26 }
27 FakeSelectionController.prototype = {
28 __proto__: tv.b.EventTarget.prototype
29 };
30
Chris Craikf516a622015-04-01 17:52:39 -070031 test('scriptingControllerBasicArithmetic', function() {
Chris Craik44c28202015-05-12 17:25:16 -070032 var selectionController = new FakeSelectionController();
33 var controller = new tv.c.ScriptingController(selectionController);
Chris Craikf516a622015-04-01 17:52:39 -070034 var result = controller.executeCommand('1 + 1');
35 assert.equal(result, 2);
36 });
37
38 test('scriptingControllerNonLocalContext', function() {
Chris Craik44c28202015-05-12 17:25:16 -070039 var selectionController = new FakeSelectionController();
40 var controller = new tv.c.ScriptingController(selectionController);
Chris Craikf516a622015-04-01 17:52:39 -070041 var x = 1;
42 controller.executeCommand('x = 2');
43 assert.equal(x, 1);
44 });
45
46 test('scriptingControllerModifyGlobalContext', function() {
Chris Craik44c28202015-05-12 17:25:16 -070047 var selectionController = new FakeSelectionController();
48 var controller = new tv.c.ScriptingController(selectionController);
Chris Craikf516a622015-04-01 17:52:39 -070049 window._x = 1;
50 controller.executeCommand('_x = 2');
51 assert.equal(window._x, 2);
52 delete window._x;
53 });
54
55 test('scriptingControllerPersistentContext', function() {
Chris Craik44c28202015-05-12 17:25:16 -070056 var selectionController = new FakeSelectionController();
57 var controller = new tv.c.ScriptingController(selectionController);
Chris Craikf516a622015-04-01 17:52:39 -070058 controller.executeCommand('a = 42');
59 var result = controller.executeCommand('a');
60 assert.equal(result, 42);
61 });
62
63 test('scriptingControllerAddScriptObject', function() {
Chris Craik44c28202015-05-12 17:25:16 -070064 var selectionController = new FakeSelectionController();
65 var controller = new tv.c.ScriptingController(selectionController);
Chris Craikf516a622015-04-01 17:52:39 -070066 controller.addScriptObject('z', 123);
67 var result = controller.executeCommand('z');
68 assert.equal(result, 123);
69 });
Chris Craik44c28202015-05-12 17:25:16 -070070
71 test('scriptingControllerObjectRegistry', function() {
72 var selectionController = new FakeSelectionController();
73
74 tv.c.ScriptingObjectRegistry.register(
75 function() { return 123; },
76 {
77 name: 'testFunctionName'
78 }
79 );
80 var controller = new tv.c.ScriptingController(selectionController);
81 var result = controller.executeCommand('testFunctionName()');
82 assert.equal(result, 123);
83 });
Chris Craikf516a622015-04-01 17:52:39 -070084});
85</script>
86