| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/perf_insights/function_handle.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| test('moduleToLoadExactlyOneHrefOrFilename', function() { |
| assert.throws(function() {pi.ModuleToLoad('foo', 'foo')}); |
| assert.throws(pi.ModuleToLoad); |
| }); |
| |
| test('moduleToLoadAsDictTest', function() { |
| var mtl0 = new pi.ModuleToLoad('/foo'); |
| var mtl1 = new pi.ModuleToLoad(undefined, 'foo.html'); |
| |
| assert.deepEqual(mtl0.asDict(), {'href': '/foo'}); |
| assert.deepEqual(mtl1.asDict(), {'filename': 'foo.html'}); |
| }); |
| |
| test('moduleToLoadFromDictTest', function() { |
| var moduleDict0 = { |
| href: '/foo' |
| }; |
| var moduleDict1 = { |
| filename: 'foo.html' |
| }; |
| |
| var mtl0 = pi.ModuleToLoad.fromDict(moduleDict0); |
| var mtl1 = pi.ModuleToLoad.fromDict(moduleDict1); |
| |
| assert.equal(mtl0.href, '/foo'); |
| assert.isUndefined(mtl0.filename); |
| assert.equal(mtl1.filename, 'foo.html'); |
| assert.isUndefined(mtl1.href); |
| }); |
| |
| test('moduleToLoadToStringTest', function() { |
| var mtl0 = new pi.ModuleToLoad('/foo'); |
| var mtl1 = new pi.ModuleToLoad(undefined, 'foo.html'); |
| |
| assert.equal( |
| mtl0.toString(), |
| 'ModuleToLoad(href="/foo")'); |
| assert.equal( |
| mtl1.toString(), |
| 'ModuleToLoad(filename="foo.html")'); |
| }); |
| |
| test('modulesToLoadMustBeArrayTest', function() { |
| assert.throws(pi.FunctionHandle); |
| }); |
| |
| test('functionNameMustBeStringTest', function() { |
| assert.throws(function() {pi.FunctionHandle([], 3);}); |
| }); |
| |
| test('asDictTest', function() { |
| var module = new pi.ModuleToLoad('/foo'); |
| var handle = new pi.FunctionHandle([module], 'Bar', {'a': 'b'}); |
| |
| assert.deepEqual(handle.asDict(), { |
| modules_to_load: [{href: '/foo'}], |
| function_name: 'Bar', |
| options: {'a': 'b'} |
| }); |
| }); |
| |
| test('fromDictTest', function() { |
| var handleDict = { |
| modules_to_load: [{href: '/foo'}], |
| function_name: 'Bar' |
| }; |
| |
| var handle = pi.FunctionHandle.fromDict(handleDict); |
| |
| assert.equal(handle.modulesToLoad.length, 1); |
| assert.equal(handle.modulesToLoad[0].href, '/foo'); |
| assert.equal(handle.functionName, 'Bar'); |
| }); |
| |
| test('hasHrefsTest', function() { |
| var module0 = new pi.ModuleToLoad('/foo'); |
| var handle0 = new pi.FunctionHandle([module0], 'Bar'); |
| var module1 = new pi.ModuleToLoad(undefined, 'foo.html'); |
| var handle1 = new pi.FunctionHandle([module1], 'Bar'); |
| |
| assert.isTrue(handle0.hasHrefs()); |
| assert.isFalse(handle1.hasHrefs()); |
| }); |
| |
| test('loadFailsWithHrefs', function() { |
| var module = new pi.ModuleToLoad('/foo'); |
| var handle = new pi.FunctionHandle([module], 'railMapFunction'); |
| |
| assert.throws(handle.load); |
| }); |
| |
| test('loadFailsUnregistered', function() { |
| var handle = new pi.FunctionHandle([], 'Bar'); |
| |
| assert.throws(handle.load); |
| }); |
| |
| test('toStringTest', function() { |
| var module = new pi.ModuleToLoad('/foo'); |
| var handle = new pi.FunctionHandle([module], 'Bar', {'a': 'b'}); |
| |
| assert.equal( |
| handle.toString(), |
| 'FunctionHandle(modulesToLoad=[ModuleToLoad(href="/foo")], ' + |
| 'functionName="Bar", options="{"a":"b"}")'); |
| }); |
| }); |
| |
| </script> |