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.
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/public/browser/notification_registrar.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "grit/webui_resources.h"
17 class WebUIResourceBrowserTest
: public InProcessBrowserTest
{
19 // Runs all test functions in |file|, waiting for them to complete.
20 void RunTest(const base::FilePath
& file
) {
21 GURL url
= ui_test_utils::GetTestUrl(
22 base::FilePath(FILE_PATH_LITERAL("webui")), file
);
23 ui_test_utils::NavigateToURL(browser(), url
);
25 content::RenderViewHost
* rvh
= browser()->tab_strip_model()
26 ->GetActiveWebContents()->GetRenderViewHost();
28 EXPECT_TRUE(ExecuteWebUIResourceTest(rvh
, include_libraries_
));
31 // Queues the library corresponding to |resource_id| for injection into the
32 // test. The code injection is performed post-load, so any common test
33 // initialization that depends on the library should be placed in a setUp
35 void AddLibrary(int resource_id
) {
36 include_libraries_
.push_back(resource_id
);
40 // Resource IDs for internal javascript libraries to inject into the test.
41 std::vector
<int> include_libraries_
;
44 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, ArrayDataModelTest
) {
45 AddLibrary(IDR_WEBUI_JS_CR
);
46 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET
);
47 AddLibrary(IDR_WEBUI_JS_CR_UI_ARRAY_DATA_MODEL
);
48 RunTest(base::FilePath(FILE_PATH_LITERAL("array_data_model_test.html")));
51 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, PropertyTest
) {
52 AddLibrary(IDR_WEBUI_JS_CR
);
53 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET
);
54 RunTest(base::FilePath(FILE_PATH_LITERAL("cr_test.html")));
57 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, EventTargetTest
) {
58 AddLibrary(IDR_WEBUI_JS_CR
);
59 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET
);
60 RunTest(base::FilePath(FILE_PATH_LITERAL("event_target_test.html")));
63 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, GridTest
) {
64 AddLibrary(IDR_WEBUI_JS_CR
);
65 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET
);
66 AddLibrary(IDR_WEBUI_JS_CR_UI
);
67 AddLibrary(IDR_WEBUI_JS_CR_UI_ARRAY_DATA_MODEL
);
68 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST
);
69 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_ITEM
);
70 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_CONTROLLER
);
71 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_MODEL
);
72 // Grid must be the last addition as it depends on list libraries.
73 AddLibrary(IDR_WEBUI_JS_CR_UI_GRID
);
74 RunTest(base::FilePath(FILE_PATH_LITERAL("grid_test.html")));
77 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, LinkControllerTest
) {
78 AddLibrary(IDR_WEBUI_JS_CR
);
79 AddLibrary(IDR_WEBUI_JS_CR_LINK_CONTROLLER
);
80 RunTest(base::FilePath(FILE_PATH_LITERAL("link_controller_test.html")));
83 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, ListSelectionModelTest
) {
84 AddLibrary(IDR_WEBUI_JS_CR
);
85 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET
);
86 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SELECTION_MODEL
);
87 RunTest(base::FilePath(FILE_PATH_LITERAL("list_selection_model_test.html")));
90 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, ListSingleSelectionModelTest
) {
91 AddLibrary(IDR_WEBUI_JS_CR
);
92 AddLibrary(IDR_WEBUI_JS_CR_EVENT_TARGET
);
93 AddLibrary(IDR_WEBUI_JS_CR_UI_LIST_SINGLE_SELECTION_MODEL
);
94 RunTest(base::FilePath(FILE_PATH_LITERAL(
95 "list_single_selection_model_test.html")));
98 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, LocalStringsTest
) {
99 AddLibrary(IDR_WEBUI_JS_LOCAL_STRINGS
);
100 RunTest(base::FilePath(FILE_PATH_LITERAL("local_strings_test.html")));
103 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, MockTimerTest
) {
104 RunTest(base::FilePath(FILE_PATH_LITERAL("mock_timer_test.html")));
107 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, ParseHtmlSubsetTest
) {
108 AddLibrary(IDR_WEBUI_JS_PARSE_HTML_SUBSET
);
109 RunTest(base::FilePath(FILE_PATH_LITERAL("parse_html_subset_test.html")));
112 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, PositionUtilTest
) {
113 AddLibrary(IDR_WEBUI_JS_CR
);
114 AddLibrary(IDR_WEBUI_JS_CR_UI_POSITION_UTIL
);
115 RunTest(base::FilePath(FILE_PATH_LITERAL("position_util_test.html")));
118 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, PromiseTest
) {
119 AddLibrary(IDR_WEBUI_JS_CR
);
120 AddLibrary(IDR_WEBUI_JS_CR_PROMISE
);
121 RunTest(base::FilePath(FILE_PATH_LITERAL("promise_test.html")));
124 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, RepeatingButtonTest
) {
125 AddLibrary(IDR_WEBUI_JS_CR
);
126 AddLibrary(IDR_WEBUI_JS_CR_UI
);
127 AddLibrary(IDR_WEBUI_JS_CR_UI_REPEATING_BUTTON
);
128 RunTest(base::FilePath(FILE_PATH_LITERAL("repeating_button_test.html")));