Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/ui/webui/web_ui_browsertest.h

Issue 8586009: Allow WebUI Tests to use preLoad in HtmlDialogUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert to patch set 4. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/string16.h" 12 #include "base/string16.h"
13 #include "chrome/browser/ui/webui/web_ui_test_handler.h" 13 #include "chrome/browser/ui/webui/web_ui_test_handler.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/test_navigation_observer.h" 15 #include "chrome/test/base/js_injection_ready_observer.h"
16 #include "chrome/test/base/test_navigation_observer.h"
16 17
17 class RenderViewHost; 18 class RenderViewHost;
18 class WebUIMessageHandler; 19 class WebUIMessageHandler;
19 20
20 namespace base { 21 namespace base {
21 class Value; 22 class Value;
22 } 23 }
23 24
24 // This macro simplifies the declaration of simple javascript unit tests. 25 // This macro simplifies the declaration of simple javascript unit tests.
25 // Use: 26 // Use:
26 // WEB_UI_UNITTEST_F(MyWebUIPageTest, myJavascriptUnittest); 27 // WEB_UI_UNITTEST_F(MyWebUIPageTest, myJavascriptUnittest);
27 #define WEB_UI_UNITTEST_F(x, y) \ 28 #define WEB_UI_UNITTEST_F(x, y) \
28 IN_PROC_BROWSER_TEST_F(x, y) { \ 29 IN_PROC_BROWSER_TEST_F(x, y) { \
29 ASSERT_TRUE(RunJavascriptTest(#y)); \ 30 ASSERT_TRUE(RunJavascriptTest(#y)); \
30 } 31 }
31 32
32 // The runner of WebUI javascript based tests. 33 // The runner of WebUI javascript based tests.
33 // See chrome/test/data/webui/test_api.js for the javascript side test API's. 34 // See chrome/test/data/webui/test_api.js for the javascript side test API's.
34 // 35 //
35 // These tests should follow the form given in: 36 // These tests should follow the form given in:
36 // chrome/test/data/webui/sample_downloads.js. 37 // chrome/test/data/webui/sample_downloads.js.
37 // and the lone test within this class. 38 // and the lone test within this class.
38 class WebUIBrowserTest 39 class WebUIBrowserTest
39 : public InProcessBrowserTest, 40 : public InProcessBrowserTest,
40 public TestNavigationObserver::JsInjectionReadyObserver { 41 public JsInjectionReadyObserver {
41 public: 42 public:
42 typedef std::vector<const base::Value*> ConstValueVector; 43 typedef std::vector<const base::Value*> ConstValueVector;
43 virtual ~WebUIBrowserTest(); 44 virtual ~WebUIBrowserTest();
44 45
45 // Add a custom helper JS library for your test. 46 // Add a custom helper JS library for your test.
46 // If a relative path is specified, it'll be read 47 // If a relative path is specified, it'll be read
47 // as relative to the test data dir. 48 // as relative to the test data dir.
48 void AddLibrary(const FilePath& library_path); 49 void AddLibrary(const FilePath& library_path);
49 50
50 // Runs a javascript function in the context of all libraries. 51 // Runs a javascript function in the context of all libraries.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // sets the |libraries_preloaded| flag to prevent re-loading at next 95 // sets the |libraries_preloaded| flag to prevent re-loading at next
95 // javascript invocation. 96 // javascript invocation.
96 void PreLoadJavascriptLibraries(const std::string& preload_test_fixture, 97 void PreLoadJavascriptLibraries(const std::string& preload_test_fixture,
97 const std::string& preload_test_name, 98 const std::string& preload_test_name,
98 RenderViewHost* preload_host); 99 RenderViewHost* preload_host);
99 100
100 // Called by javascript-generated test bodies to browse to a page and preload 101 // Called by javascript-generated test bodies to browse to a page and preload
101 // the javascript for the given |preload_test_fixture| and 102 // the javascript for the given |preload_test_fixture| and
102 // |preload_test_name|. chrome.send will be overridden to allow javascript 103 // |preload_test_name|. chrome.send will be overridden to allow javascript
103 // handler mocking. 104 // handler mocking.
104 void BrowsePreload(const GURL& browse_to, 105 void BrowsePreload(const GURL& browse_to);
105 const std::string& preload_test_fixture,
106 const std::string& preload_test_name);
107 106
108 // Called by javascript-generated test bodies to browse to a page and preload 107 // Called by javascript-generated test bodies to browse to a page and preload
109 // the javascript for the given |preload_test_fixture| and 108 // the javascript for the given |preload_test_fixture| and
110 // |preload_test_name|. chrome.send will be overridden to allow javascript 109 // |preload_test_name|. chrome.send will be overridden to allow javascript
111 // handler mocking. 110 // handler mocking.
112 void BrowsePrintPreload(const GURL& browse_to, 111 void BrowsePrintPreload(const GURL& browse_to);
113 const std::string& preload_test_fixture,
114 const std::string& preload_test_name);
115 112
116 protected: 113 protected:
117 // URL to dummy WebUI page for testing framework. 114 // URL to dummy WebUI page for testing framework.
118 static const char kDummyURL[]; 115 static const char kDummyURL[];
119 116
120 WebUIBrowserTest(); 117 WebUIBrowserTest();
121 118
119 // Accessors for preload test fixture and name.
120 void set_preload_test_fixture(const std::string& preload_test_fixture) {
121 preload_test_fixture_ = preload_test_fixture;
James Hawkins 2011/11/22 23:03:29 Move the implementation the .cc file.
Sheridan Rawlins 2011/11/23 20:10:07 Done.
122 }
123 void set_preload_test_name(const std::string& preload_test_name) {
124 preload_test_name_ = preload_test_name;
125 }
126
122 // Set up & tear down console error catching. 127 // Set up & tear down console error catching.
123 virtual void SetUpOnMainThread() OVERRIDE; 128 virtual void SetUpOnMainThread() OVERRIDE;
124 virtual void CleanUpOnMainThread() OVERRIDE; 129 virtual void CleanUpOnMainThread() OVERRIDE;
125 130
126 // Set up test path & override for |kDummyURL|. 131 // Set up test path & override for |kDummyURL|.
127 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; 132 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
128 133
129 // Tear down override for |kDummyURL|. 134 // Tear down override for |kDummyURL|.
130 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE; 135 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE;
131 136
132 // Set a WebUI instance to run tests on. 137 // Set a WebUI instance to run tests on.
133 void SetWebUIInstance(WebUI* web_ui); 138 void SetWebUIInstance(WebUI* web_ui);
134 139
135 // Returns a mock WebUI object under test (if any). 140 // Returns a mock WebUI object under test (if any).
136 virtual WebUIMessageHandler* GetMockMessageHandler(); 141 virtual WebUIMessageHandler* GetMockMessageHandler();
137 142
138 // Returns a file:// GURL constructed from |path| inside the test data dir for 143 // Returns a file:// GURL constructed from |path| inside the test data dir for
139 // webui tests. 144 // webui tests.
140 static GURL WebUITestDataPathToURL(const FilePath::StringType& path); 145 static GURL WebUITestDataPathToURL(const FilePath::StringType& path);
141 146
142 private: 147 private:
143 // TestNavigationObserver::JsInjectionReadyObserver implementation. 148 // JsInjectionReadyObserver implementation.
144 virtual void OnJsInjectionReady(RenderViewHost* render_view_host) OVERRIDE; 149 virtual void OnJsInjectionReady(RenderViewHost* render_view_host) OVERRIDE;
145 150
146 // Builds a string containing all added javascript libraries. 151 // Builds a string containing all added javascript libraries.
147 void BuildJavascriptLibraries(string16* content); 152 void BuildJavascriptLibraries(string16* content);
148 153
149 // Builds a string with a call to the runTest JS function, passing the 154 // Builds a string with a call to the runTest JS function, passing the
150 // given |is_async|, |test_name| and its |args|. 155 // given |is_async|, |test_name| and its |args|.
151 string16 BuildRunTestJSCall(bool is_async, 156 string16 BuildRunTestJSCall(bool is_async,
152 const std::string& test_name, 157 const std::string& test_name,
153 const WebUIBrowserTest::ConstValueVector& args); 158 const WebUIBrowserTest::ConstValueVector& args);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // PreloadJavascriptLibraries(). 193 // PreloadJavascriptLibraries().
189 std::string preload_test_fixture_; 194 std::string preload_test_fixture_;
190 std::string preload_test_name_; 195 std::string preload_test_name_;
191 196
192 // When this is non-NULL, this is The WebUI instance used for testing. 197 // When this is non-NULL, this is The WebUI instance used for testing.
193 // Otherwise the selected tab's web_ui is used. 198 // Otherwise the selected tab's web_ui is used.
194 WebUI* override_selected_web_ui_; 199 WebUI* override_selected_web_ui_;
195 }; 200 };
196 201
197 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_ 202 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_BROWSERTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698