1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_TEST_BASE_JAVASCRIPT_BROWSER_TEST_H_
6#define CHROME_TEST_BASE_JAVASCRIPT_BROWSER_TEST_H_
7
8#include "base/memory/scoped_vector.h"
9#include "base/strings/string16.h"
10#include "base/values.h"
11#include "chrome/test/base/in_process_browser_test.h"
12
13// A base class providing construction of javascript testing assets.
14class JavaScriptBrowserTest : public InProcessBrowserTest {
15 public:
16  static const base::FilePath::CharType kA11yAuditLibraryJSPath[];
17  static const base::FilePath::CharType kMockJSPath[];
18  static const base::FilePath::CharType kWebUILibraryJS[];
19  static const base::FilePath::CharType kWebUITestFolder[];
20
21  typedef ScopedVector<const base::Value> ConstValueVector;
22
23  // Add a custom helper JS library for your test.
24  // If a relative path is specified, it'll be read
25  // as relative to the test data dir.
26  void AddLibrary(const base::FilePath& library_path);
27
28 protected:
29  JavaScriptBrowserTest();
30
31  virtual ~JavaScriptBrowserTest();
32
33  // InProcessBrowserTest overrides.
34  virtual void SetUpOnMainThread() OVERRIDE;
35
36  // Builds a vector of strings of all added javascript libraries suitable for
37  // execution by subclasses.
38  void BuildJavascriptLibraries(std::vector<base::string16>* libraries);
39
40  // Builds a string with a call to the runTest JS function, passing the
41  // given |is_async|, |test_name| and its |args|.
42  // This is then suitable for execution by subclasses in a
43  // |RunJavaScriptBrowserTestF| call.
44  base::string16 BuildRunTestJSCall(bool is_async,
45                                    const std::string& test_name,
46                                    const ConstValueVector& args);
47
48 private:
49  // User added libraries.
50  std::vector<base::FilePath> user_libraries_;
51
52  // User library search paths.
53  std::vector<base::FilePath> library_search_paths_;
54
55  DISALLOW_COPY_AND_ASSIGN(JavaScriptBrowserTest);
56};
57
58#endif  // CHROME_TEST_BASE_JAVASCRIPT_BROWSER_TEST_H_
59