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 | 15 |
15 class Value; | 16 class Value; |
16 class WebUIMessageHandler; | 17 class WebUIMessageHandler; |
17 | 18 |
18 // This macro simplifies the declaration of simple javascript unit tests. | 19 // This macro simplifies the declaration of simple javascript unit tests. |
19 // Use: | 20 // Use: |
20 // WEB_UI_UNITTEST_F(MyWebUIPageTest, myJavascriptUnittest); | 21 // WEB_UI_UNITTEST_F(MyWebUIPageTest, myJavascriptUnittest); |
21 #define WEB_UI_UNITTEST_F(x, y) \ | 22 #define WEB_UI_UNITTEST_F(x, y) \ |
22 IN_PROC_BROWSER_TEST_F(x, y) { \ | 23 IN_PROC_BROWSER_TEST_F(x, y) { \ |
23 ASSERT_TRUE(RunJavascriptTest(#y)); \ | 24 ASSERT_TRUE(RunJavascriptTest(#y)); \ |
24 } | 25 } |
25 | 26 |
26 // The runner of WebUI javascript based tests. | 27 // The runner of WebUI javascript based tests. |
27 // See chrome/test/data/webui/test_api.js for the javascript side test API's. | 28 // See chrome/test/data/webui/test_api.js for the javascript side test API's. |
28 // | 29 // |
29 // These tests should follow the form given in: | 30 // These tests should follow the form given in: |
30 // chrome/test/data/webui/sample_downloads.js. | 31 // chrome/test/data/webui/sample_downloads.js. |
31 // and the lone test within this class. | 32 // and the lone test within this class. |
32 class WebUIBrowserTest : public InProcessBrowserTest { | 33 class WebUIBrowserTest : public InProcessBrowserTest, |
34 public TestNavigationObserver::LoadStartObserver { | |
33 public: | 35 public: |
34 typedef std::vector<const Value*> ConstValueVector; | 36 typedef std::vector<const Value*> ConstValueVector; |
35 virtual ~WebUIBrowserTest(); | 37 virtual ~WebUIBrowserTest(); |
36 | 38 |
37 // Add a custom helper JS library for your test. | 39 // Add a custom helper JS library for your test. |
38 // If a relative path is specified, it'll be read | 40 // If a relative path is specified, it'll be read |
39 // as relative to the test data dir. | 41 // as relative to the test data dir. |
40 void AddLibrary(const FilePath& library_path); | 42 void AddLibrary(const FilePath& library_path); |
41 | 43 |
42 // Runs a javascript function in the context of all libraries. | 44 // Runs a javascript function in the context of all libraries. |
(...skipping 16 matching lines...) Expand all Loading... | |
59 const Value& arg2); | 61 const Value& arg2); |
60 bool RunJavascriptTest(const std::string& test_name, | 62 bool RunJavascriptTest(const std::string& test_name, |
61 const ConstValueVector& test_arguments); | 63 const ConstValueVector& test_arguments); |
62 | 64 |
63 // Preloads the javascript libraries and sets the |libraries_preloaded| flag | 65 // Preloads the javascript libraries and sets the |libraries_preloaded| flag |
64 // to prevent re-loading at next javascript invocation. If | 66 // to prevent re-loading at next javascript invocation. If |
65 // |override_chrome_send| is true, then chrome.send is overridden for | 67 // |override_chrome_send| is true, then chrome.send is overridden for |
66 // javascript to register handlers. | 68 // javascript to register handlers. |
67 void PreLoadJavascriptLibraries(bool override_chrome_send); | 69 void PreLoadJavascriptLibraries(bool override_chrome_send); |
68 | 70 |
71 // Called by javascript-generated test bodies to browse to a page and preload | |
72 // the javascript. chrome.send will be overridden if |override_chrome_send| is | |
73 // set. | |
74 void BrowsePreload(const GURL& browse_to, bool override_chrome_send); | |
75 | |
76 // Saves the state of |override_chrome_send| for calling | |
77 // PreloadJavascriptLibrarie(). | |
David Tseng
2011/07/07 19:26:28
Librarie -> Library?
Sheridan Rawlins
2011/07/07 23:39:23
Done.
| |
78 bool override_chrome_send_; | |
79 | |
69 protected: | 80 protected: |
70 WebUIBrowserTest(); | 81 WebUIBrowserTest(); |
71 | 82 |
72 // Setup test path. | 83 // Setup test path. |
73 virtual void SetUpInProcessBrowserTestFixture(); | 84 virtual void SetUpInProcessBrowserTestFixture(); |
74 | 85 |
75 // Returns a mock WebUI object under test (if any). | 86 // Returns a mock WebUI object under test (if any). |
76 virtual WebUIMessageHandler* GetMockMessageHandler(); | 87 virtual WebUIMessageHandler* GetMockMessageHandler(); |
77 | 88 |
78 // Skip this test with |skip_test_message|. | 89 // Skip this test with |skip_test_message|. |
79 void skipTest(const std::string& skip_test_message); | 90 void skipTest(const std::string& skip_test_message); |
80 | 91 |
81 // Returns a file:// GURL constructed from |path| inside the test data dir for | 92 // Returns a file:// GURL constructed from |path| inside the test data dir for |
82 // webui tests. | 93 // webui tests. |
83 static GURL WebUITestDataPathToURL(const FilePath::StringType& path); | 94 static GURL WebUITestDataPathToURL(const FilePath::StringType& path); |
84 | 95 |
85 private: | 96 private: |
97 // TestNavigationObserver::LoadStartObserver: | |
98 virtual void OnLoadStart() OVERRIDE; | |
99 | |
86 // Builds a string containing all added javascript libraries. | 100 // Builds a string containing all added javascript libraries. |
87 void BuildJavascriptLibraries(std::string* content); | 101 void BuildJavascriptLibraries(std::string* content); |
88 | 102 |
89 // Builds a string with a call to the runTest JS function, passing the | 103 // Builds a string with a call to the runTest JS function, passing the |
90 // given test and its arguments. | 104 // given test and its arguments. |
91 string16 BuildRunTestJSCall(const std::string& test_name, | 105 string16 BuildRunTestJSCall(const std::string& test_name, |
92 const WebUIBrowserTest::ConstValueVector& args); | 106 const WebUIBrowserTest::ConstValueVector& args); |
93 | 107 |
94 // Calls the specified function with all libraries available. If |is_test| | 108 // Calls the specified function with all libraries available. If |is_test| |
95 // is true, the framework listens for pass fail messages from javascript. | 109 // is true, the framework listens for pass fail messages from javascript. |
(...skipping 16 matching lines...) Expand all Loading... | |
112 | 126 |
113 // Indicates that the libraries have been pre-loaded and to not load them | 127 // Indicates that the libraries have been pre-loaded and to not load them |
114 // again. | 128 // again. |
115 bool libraries_preloaded_; | 129 bool libraries_preloaded_; |
116 | 130 |
117 bool skip_test_; | 131 bool skip_test_; |
118 std::string skip_test_message_; | 132 std::string skip_test_message_; |
119 }; | 133 }; |
120 | 134 |
121 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ | 135 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ |
OLD | NEW |