Michael Giuffrida | e522d04 | 2018-03-02 07:49:04 | [diff] [blame] | 1 | // 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 | |
| 10 | namespace content { |
| 11 | class BrowserContext; |
| 12 | } // namespace content |
| 13 | |
| 14 | namespace extensions { |
| 15 | namespace browsertest_util { |
| 16 | |
Mustaq Ahmed | eedcfc9 | 2018-05-09 17:34:53 | [diff] [blame] | 17 | // Determine if a user activation notification should be triggered before |
| 18 | // executing a script |
| 19 | enum class ScriptUserActivation { |
| 20 | kActivate, |
| 21 | kDontActivate, |
| 22 | }; |
| 23 | |
Michael Giuffrida | e522d04 | 2018-03-02 07:49:04 | [diff] [blame] | 24 | // 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 Ahmed | eedcfc9 | 2018-05-09 17:34:53 | [diff] [blame] | 27 | // 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. |
| 30 | std::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 Giuffrida | e522d04 | 2018-03-02 07:49:04 | [diff] [blame] | 36 | |
| 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. |
| 41 | bool 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_ |