summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/javascript2webui.js
blob: b0fc9bdc3ca6f866ac6c0051f39062eea67da5db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2011 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.
if (arguments.length < 3) {
  print('usage: ' +
        arguments[0] + ' path-to-testfile.js testfile.js [output.cc]');
  quit(-1);
}
var jsFile = arguments[1];
var jsFileBase = arguments[2];
var outputFile = arguments[3];

// Generate the file to stdout.
print('// GENERATED FILE');
print('// ' + arguments.join(' '));
print('// PLEASE DO NOT HAND EDIT!');
print();
print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"');
print('#include "googleurl/src/gurl.h"');
print('#include "testing/gtest/include/gtest/gtest.h"');
print();

function GEN(code) {
  print(code);
}

var typedeffedCppFixtures = {};

function TEST_F(testFixture, testFunction, testBody) {
  var browsePreload = this[testFixture].prototype.browsePreload;
  var browsePrintPreload = this[testFixture].prototype.browsePrintPreload;
  var testGenPreamble = this[testFixture].prototype.testGenPreamble;
  var testGenPostamble = this[testFixture].prototype.testGenPostamble;
  var typedefCppFixture = this[testFixture].prototype.typedefCppFixture;

  if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) {
    print('typedef ' + typedefCppFixture + ' ' + testFixture + ';');
    typedeffedCppFixtures[testFixture] = typedefCppFixture;
  }

  print('IN_PROC_BROWSER_TEST_F(' + testFixture + ', ' + testFunction + ') {');
  if (testGenPreamble)
    testGenPreamble(testFixture, testFunction);
  print('  AddLibrary(FilePath(FILE_PATH_LITERAL("' + jsFileBase + '")));');
  if (browsePreload) {
    print('  BrowsePreload(GURL("' + browsePreload + '"), "' + testFixture +
          '", "' + testFunction + '");');
    }
  if (browsePrintPreload) {
    print('  BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' +
          '      FILE_PATH_LITERAL("' + browsePrintPreload + '"))),\n' +
          '      "' + testFixture + '", "' + testFunction + '");');
  }
  print('  ASSERT_TRUE(RunJavascriptTestF("' + testFixture + '", "' +
        testFunction + '"));');
  if (testGenPostamble)
    testGenPostamble(testFixture, testFunction);
  print('}');
  print();
}

var js = read(jsFile);
eval(js);