blob: 9774259f952c14f2f1117a87152866104f73ba0c [file] [log] [blame]
Michael Giuffridae522d042018-03-02 07:49:041// Copyright 2018 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 EXTENSIONS_BROWSER_BROWSERTEST_UTIL_H_
6#define EXTENSIONS_BROWSER_BROWSERTEST_UTIL_H_
7
8#include <string>
9
10namespace content {
11class BrowserContext;
12} // namespace content
13
14namespace extensions {
15namespace browsertest_util {
16
Mustaq Ahmedeedcfc92018-05-09 17:34:5317// Determine if a user activation notification should be triggered before
18// executing a script
19enum class ScriptUserActivation {
20 kActivate,
21 kDontActivate,
22};
23
Michael Giuffridae522d042018-03-02 07:49:0424// Waits until |script| calls "window.domAutomationController.send(result)",
25// where |result| is a string, and returns |result|. Fails the test and returns
26// an empty string if |extension_id| isn't installed in |context| or doesn't
Mustaq Ahmedeedcfc92018-05-09 17:34:5327// have a background page, or if executing the script fails. The argument
28// |script_user_activation| determines if the script should be executed after a
29// user activation.
30std::string ExecuteScriptInBackgroundPage(
31 content::BrowserContext* context,
32 const std::string& extension_id,
33 const std::string& script,
34 ScriptUserActivation script_user_activation =
35 ScriptUserActivation::kActivate);
Michael Giuffridae522d042018-03-02 07:49:0436
37// Same as ExecuteScriptInBackgroundPage, but doesn't wait for the script
38// to return a result. Fails the test and returns false if |extension_id|
39// isn't installed in |context| or doesn't have a background page, or if
40// executing the script fails.
41bool ExecuteScriptInBackgroundPageNoWait(content::BrowserContext* context,
42 const std::string& extension_id,
43 const std::string& script);
44
45} // namespace browsertest_util
46} // namespace extensions
47
48#endif // EXTENSIONS_BROWSER_BROWSERTEST_UTIL_H_