Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / webui / webui_resource_browsertest.cc
blob3f376b427a203efa3921e07a9ed8fc0da55bad7d
1 // Copyright 2013 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.
5 #include <vector>
7 #include "base/path_service.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/grit/options_test_resources.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "chrome/test/data/grit/webui_test_resources.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/resources/grit/webui_resources.h"
20 class WebUIResourceBrowserTest : public InProcessBrowserTest {
21 public:
22 void SetUpOnMainThread() override {
23 // Load resources that are only used by browser_tests.
24 base::FilePath pak_path;
25 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &pak_path));
26 pak_path = pak_path.AppendASCII("browser_tests.pak");
27 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
28 pak_path, ui::SCALE_FACTOR_NONE);
31 // Runs all test functions in |file|, waiting for them to complete.
32 void LoadFile(const base::FilePath& file) {
33 base::FilePath webui(FILE_PATH_LITERAL("webui"));
34 RunTest(ui_test_utils::GetTestUrl(webui, file));
37 void LoadResource(int idr) {
38 ResourceBundle& bundle = ResourceBundle::GetSharedInstance();
39 base::StringPiece resource = bundle.GetRawDataResource(idr);
40 RunTest(GURL(std::string("data:text/html,") + resource.as_string()));
43 // Queues the library corresponding to |resource_id| for injection into the
44 // test. The code injection is performed post-load, so any common test
45 // initialization that depends on the library should be placed in a setUp
46 // function.
47 void AddLibrary(int resource_id) {
48 include_libraries_.push_back(resource_id);
51 private:
52 void RunTest(const GURL& url) {
53 ui_test_utils::NavigateToURL(browser(), url);
54 content::WebContents* web_contents =
55 browser()->tab_strip_model()->GetActiveWebContents();
56 ASSERT_TRUE(web_contents);
57 EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents, include_libraries_));
60 // Resource IDs for internal javascript libraries to inject into the test.
61 std::vector<int> include_libraries_;
64 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, ArrayDataModelTest) {
65 AddLibrary(IDR_WEBUI_JS_CR);
66 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
67 AddLibrary(IDR_WEBUI_JS_CR_UI_ARRAY_DATA_MODEL);
68 LoadFile(base::FilePath(FILE_PATH_LITERAL("array_data_model_test.html")));
71 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, CrTest) {
72 AddLibrary(IDR_WEBUI_JS_CR);
73 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
74 LoadFile(base::FilePath(FILE_PATH_LITERAL("cr_test.html")));
77 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, EventTargetTest) {
78 AddLibrary(IDR_WEBUI_JS_CR);
79 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
80 LoadFile(base::FilePath(FILE_PATH_LITERAL("event_target_test.html")));
83 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, I18nProcessCssTest) {
84 LoadResource(IDR_WEBUI_TEST_I18N_PROCESS_CSS_TEST);
87 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, I18nProcessTest) {
88 AddLibrary(IDR_WEBUI_JS_LOAD_TIME_DATA);
89 AddLibrary(IDR_WEBUI_JS_I18N_TEMPLATE_NO_PROCESS);
90 AddLibrary(IDR_WEBUI_JS_UTIL);
91 LoadFile(base::FilePath(FILE_PATH_LITERAL("i18n_process_test.html")));
94 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, ListTest) {
95 AddLibrary(IDR_WEBUI_JS_CR);
96 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
97 AddLibrary(IDR_WEBUI_JS_CR_UI);
98 AddLibrary(IDR_WEBUI_JS_CR_UI_ARRAY_DATA_MODEL);
99 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_ITEM);
100 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_CONTROLLER);
101 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_MODEL);
102 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST);
103 LoadFile(base::FilePath(FILE_PATH_LITERAL("list_test.html")));
106 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, GridTest) {
107 AddLibrary(IDR_WEBUI_JS_CR);
108 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
109 AddLibrary(IDR_WEBUI_JS_CR_UI);
110 AddLibrary(IDR_WEBUI_JS_CR_UI_ARRAY_DATA_MODEL);
111 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST);
112 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_ITEM);
113 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_CONTROLLER);
114 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_MODEL);
115 // Grid must be the last addition as it depends on list libraries.
116 AddLibrary(IDR_WEBUI_JS_CR_UI_GRID);
117 LoadFile(base::FilePath(FILE_PATH_LITERAL("grid_test.html")));
120 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, LinkControllerTest) {
121 AddLibrary(IDR_WEBUI_JS_CR);
122 AddLibrary(IDR_WEBUI_JS_CR_LINK_CONTROLLER);
123 LoadFile(base::FilePath(FILE_PATH_LITERAL("link_controller_test.html")));
126 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, ListSelectionModelTest) {
127 AddLibrary(IDR_WEBUI_JS_CR);
128 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
129 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_MODEL);
130 LoadFile(base::FilePath(FILE_PATH_LITERAL("list_selection_model_test.html")));
133 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, ListSingleSelectionModelTest) {
134 AddLibrary(IDR_WEBUI_JS_CR);
135 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
136 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SINGLE_SELECTION_MODEL);
137 LoadFile(base::FilePath(FILE_PATH_LITERAL(
138 "list_single_selection_model_test.html")));
141 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, InlineEditableListTest) {
142 AddLibrary(IDR_WEBUI_JS_CR);
143 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
144 AddLibrary(IDR_WEBUI_JS_CR_UI);
145 AddLibrary(IDR_WEBUI_JS_CR_UI_ARRAY_DATA_MODEL);
146 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_ITEM);
147 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_CONTROLLER);
148 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_MODEL);
149 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST);
150 AddLibrary(IDR_WEBUI_JS_LOAD_TIME_DATA);
151 AddLibrary(IDR_OPTIONS_DELETABLE_ITEM_LIST);
152 AddLibrary(IDR_OPTIONS_INLINE_EDITABLE_LIST);
153 LoadFile(base::FilePath(FILE_PATH_LITERAL(
154 "inline_editable_list_test.html")));
157 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, MenuTest) {
158 AddLibrary(IDR_WEBUI_JS_ASSERT);
159 AddLibrary(IDR_WEBUI_JS_CR);
160 AddLibrary(IDR_WEBUI_JS_CR_UI);
161 AddLibrary(IDR_WEBUI_JS_CR_UI_COMMAND);
162 AddLibrary(IDR_WEBUI_JS_CR_UI_MENU_ITEM);
163 AddLibrary(IDR_WEBUI_JS_CR_UI_MENU);
164 LoadFile(base::FilePath(FILE_PATH_LITERAL("menu_test.html")));
167 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, MockTimerTest) {
168 LoadFile(base::FilePath(FILE_PATH_LITERAL("mock_timer_test.html")));
171 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, ParseHtmlSubsetTest) {
172 AddLibrary(IDR_WEBUI_JS_PARSE_HTML_SUBSET);
173 LoadFile(base::FilePath(FILE_PATH_LITERAL("parse_html_subset_test.html")));
176 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, PositionUtilTest) {
177 AddLibrary(IDR_WEBUI_JS_CR);
178 AddLibrary(IDR_WEBUI_JS_CR_UI_POSITION_UTIL);
179 LoadFile(base::FilePath(FILE_PATH_LITERAL("position_util_test.html")));
182 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, RepeatingButtonTest) {
183 AddLibrary(IDR_WEBUI_JS_CR);
184 AddLibrary(IDR_WEBUI_JS_CR_UI);
185 AddLibrary(IDR_WEBUI_JS_CR_UI_REPEATING_BUTTON);
186 LoadFile(base::FilePath(FILE_PATH_LITERAL("repeating_button_test.html")));
189 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, CommandTest) {
190 AddLibrary(IDR_WEBUI_JS_ASSERT);
191 AddLibrary(IDR_WEBUI_JS_CR);
192 AddLibrary(IDR_WEBUI_JS_CR_UI);
193 AddLibrary(IDR_WEBUI_JS_CR_UI_COMMAND);
194 LoadFile(base::FilePath(FILE_PATH_LITERAL("command_test.html")));
197 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, ContextMenuHandlerTest) {
198 AddLibrary(IDR_WEBUI_JS_ASSERT);
199 AddLibrary(IDR_WEBUI_JS_EVENT_TRACKER);
200 AddLibrary(IDR_WEBUI_JS_CR);
201 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET);
202 AddLibrary(IDR_WEBUI_JS_CR_UI);
203 AddLibrary(IDR_WEBUI_JS_CR_UI_POSITION_UTIL);
204 AddLibrary(IDR_WEBUI_JS_CR_UI_MENU_ITEM);
205 AddLibrary(IDR_WEBUI_JS_CR_UI_MENU_BUTTON);
206 AddLibrary(IDR_WEBUI_JS_CR_UI_MENU);
207 AddLibrary(IDR_WEBUI_JS_CR_UI_CONTEXT_MENU_HANDLER);
208 LoadFile(base::FilePath(FILE_PATH_LITERAL("context_menu_handler_test.html")));
211 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, MenuButtonTest) {
212 AddLibrary(IDR_WEBUI_JS_ASSERT);
213 AddLibrary(IDR_WEBUI_JS_EVENT_TRACKER);
214 AddLibrary(IDR_WEBUI_JS_CR);
215 AddLibrary(IDR_WEBUI_JS_CR_UI);
216 AddLibrary(IDR_WEBUI_JS_CR_UI_POSITION_UTIL);
217 AddLibrary(IDR_WEBUI_JS_CR_UI_MENU_BUTTON);
218 AddLibrary(IDR_WEBUI_JS_CR_UI_MENU);
219 LoadFile(base::FilePath(FILE_PATH_LITERAL("menu_button_test.html")));