| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "chrome/browser/ui/webui/web_ui_test_handler.h" | 12 #include "chrome/browser/ui/webui/web_ui_test_handler.h" |
| 13 #include "chrome/test/in_process_browser_test.h" | 13 #include "chrome/test/in_process_browser_test.h" |
| 14 #include "chrome/test/test_navigation_observer.h" | 14 #include "chrome/test/test_navigation_observer.h" |
| 15 | 15 |
| 16 class WebUIMessageHandler; |
| 17 |
| 18 namespace base { |
| 16 class Value; | 19 class Value; |
| 17 class WebUIMessageHandler; | 20 } |
| 18 | 21 |
| 19 // This macro simplifies the declaration of simple javascript unit tests. | 22 // This macro simplifies the declaration of simple javascript unit tests. |
| 20 // Use: | 23 // Use: |
| 21 // WEB_UI_UNITTEST_F(MyWebUIPageTest, myJavascriptUnittest); | 24 // WEB_UI_UNITTEST_F(MyWebUIPageTest, myJavascriptUnittest); |
| 22 #define WEB_UI_UNITTEST_F(x, y) \ | 25 #define WEB_UI_UNITTEST_F(x, y) \ |
| 23 IN_PROC_BROWSER_TEST_F(x, y) { \ | 26 IN_PROC_BROWSER_TEST_F(x, y) { \ |
| 24 ASSERT_TRUE(RunJavascriptTest(#y)); \ | 27 ASSERT_TRUE(RunJavascriptTest(#y)); \ |
| 25 } | 28 } |
| 26 | 29 |
| 27 // The runner of WebUI javascript based tests. | 30 // The runner of WebUI javascript based tests. |
| 28 // See chrome/test/data/webui/test_api.js for the javascript side test API's. | 31 // See chrome/test/data/webui/test_api.js for the javascript side test API's. |
| 29 // | 32 // |
| 30 // These tests should follow the form given in: | 33 // These tests should follow the form given in: |
| 31 // chrome/test/data/webui/sample_downloads.js. | 34 // chrome/test/data/webui/sample_downloads.js. |
| 32 // and the lone test within this class. | 35 // and the lone test within this class. |
| 33 class WebUIBrowserTest | 36 class WebUIBrowserTest |
| 34 : public InProcessBrowserTest, | 37 : public InProcessBrowserTest, |
| 35 public TestNavigationObserver::JsInjectionReadyObserver { | 38 public TestNavigationObserver::JsInjectionReadyObserver { |
| 36 public: | 39 public: |
| 37 typedef std::vector<const Value*> ConstValueVector; | 40 typedef std::vector<const base::Value*> ConstValueVector; |
| 38 virtual ~WebUIBrowserTest(); | 41 virtual ~WebUIBrowserTest(); |
| 39 | 42 |
| 40 // Add a custom helper JS library for your test. | 43 // Add a custom helper JS library for your test. |
| 41 // If a relative path is specified, it'll be read | 44 // If a relative path is specified, it'll be read |
| 42 // as relative to the test data dir. | 45 // as relative to the test data dir. |
| 43 void AddLibrary(const FilePath& library_path); | 46 void AddLibrary(const FilePath& library_path); |
| 44 | 47 |
| 45 // Runs a javascript function in the context of all libraries. | 48 // Runs a javascript function in the context of all libraries. |
| 46 // Note that calls to functions in test_api.js are not supported. | 49 // Note that calls to functions in test_api.js are not supported. |
| 47 bool RunJavascriptFunction(const std::string& function_name); | 50 bool RunJavascriptFunction(const std::string& function_name); |
| 48 bool RunJavascriptFunction(const std::string& function_name, | 51 bool RunJavascriptFunction(const std::string& function_name, |
| 49 const Value& arg); | 52 const base::Value& arg); |
| 50 bool RunJavascriptFunction(const std::string& function_name, | 53 bool RunJavascriptFunction(const std::string& function_name, |
| 51 const Value& arg1, | 54 const base::Value& arg1, |
| 52 const Value& arg2); | 55 const base::Value& arg2); |
| 53 bool RunJavascriptFunction(const std::string& function_name, | 56 bool RunJavascriptFunction(const std::string& function_name, |
| 54 const ConstValueVector& function_arguments); | 57 const ConstValueVector& function_arguments); |
| 55 | 58 |
| 56 // Runs a test fixture that may include calls to functions in test_api.js. | 59 // Runs a test fixture that may include calls to functions in test_api.js. |
| 57 bool RunJavascriptTestF(const std::string& test_fixture, | 60 bool RunJavascriptTestF(const std::string& test_fixture, |
| 58 const std::string& test_name); | 61 const std::string& test_name); |
| 59 | 62 |
| 60 // Runs a test that may include calls to functions in test_api.js. | 63 // Runs a test that may include calls to functions in test_api.js. |
| 61 bool RunJavascriptTest(const std::string& test_name); | 64 bool RunJavascriptTest(const std::string& test_name); |
| 62 bool RunJavascriptTest(const std::string& test_name, | 65 bool RunJavascriptTest(const std::string& test_name, |
| 63 const Value& arg); | 66 const base::Value& arg); |
| 64 bool RunJavascriptTest(const std::string& test_name, | 67 bool RunJavascriptTest(const std::string& test_name, |
| 65 const Value& arg1, | 68 const base::Value& arg1, |
| 66 const Value& arg2); | 69 const base::Value& arg2); |
| 67 bool RunJavascriptTest(const std::string& test_name, | 70 bool RunJavascriptTest(const std::string& test_name, |
| 68 const ConstValueVector& test_arguments); | 71 const ConstValueVector& test_arguments); |
| 69 | 72 |
| 70 // Preloads the javascript libraries and sets the |libraries_preloaded| flag | 73 // Preloads the javascript libraries and sets the |libraries_preloaded| flag |
| 71 // to prevent re-loading at next javascript invocation. If | 74 // to prevent re-loading at next javascript invocation. If |
| 72 // |override_chrome_send| is true, then chrome.send is overridden for | 75 // |override_chrome_send| is true, then chrome.send is overridden for |
| 73 // javascript to register handlers. | 76 // javascript to register handlers. |
| 74 void PreLoadJavascriptLibraries(const std::string& preload_test_fixture, | 77 void PreLoadJavascriptLibraries(const std::string& preload_test_fixture, |
| 75 const std::string& preload_test_name); | 78 const std::string& preload_test_name); |
| 76 | 79 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // again. | 141 // again. |
| 139 bool libraries_preloaded_; | 142 bool libraries_preloaded_; |
| 140 | 143 |
| 141 // Saves the states of |test_fixture| and |test_name| for calling | 144 // Saves the states of |test_fixture| and |test_name| for calling |
| 142 // PreloadJavascriptLibraries(). | 145 // PreloadJavascriptLibraries(). |
| 143 std::string preload_test_fixture_; | 146 std::string preload_test_fixture_; |
| 144 std::string preload_test_name_; | 147 std::string preload_test_name_; |
| 145 }; | 148 }; |
| 146 | 149 |
| 147 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ | 150 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ |
| OLD | NEW |