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 "base/files/file_path.h"
6 #include "base/files/file_util.h"
7 #include "base/path_service.h"
8 #include "content/grit/content_resources.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/common/content_paths.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/content_browser_test.h"
13 #include "content/public/test/content_browser_test_utils.h"
14 #include "content/shell/browser/shell.h"
15 #include "net/base/filename_util.h"
16 #include "ui/resources/grit/webui_resources.h"
20 class WebUIResourceBrowserTest
: public ContentBrowserTest
{
22 WebUIResourceBrowserTest() {}
23 ~WebUIResourceBrowserTest() override
{}
25 // Runs all test functions in |file|, waiting for them to complete.
26 void RunTest(const base::FilePath
& file
) {
27 ASSERT_TRUE(PathExists(file
));
28 NavigateToURL(shell(), net::FilePathToFileURL(file
));
30 content::WebContents
* web_contents
= shell()->web_contents();
31 ASSERT_TRUE(web_contents
);
32 EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents
, include_libraries_
));
35 void RunMediaInternalsTest(const base::FilePath::CharType
* file
) {
36 AddLibrary(IDR_WEBUI_JS_CR
);
37 AddLibrary(IDR_MEDIA_INTERNALS_JS
);
40 PathService::Get(DIR_TEST_DATA
, &path
);
41 RunTest(path
.Append(FILE_PATH_LITERAL("media"))
42 .Append(FILE_PATH_LITERAL("webui"))
46 // Queues the library corresponding to |resource_id| for injection into the
47 // test. The code injection is performed post-load, so any common test
48 // initialization that depends on the library should be placed in a setUp
50 void AddLibrary(int resource_id
) {
51 include_libraries_
.push_back(resource_id
);
55 // Resource IDs for internal javascript libraries to inject into the test.
56 std::vector
<int> include_libraries_
;
58 DISALLOW_COPY_AND_ASSIGN(WebUIResourceBrowserTest
);
61 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, MediaInternals_Integration
) {
62 RunMediaInternalsTest(FILE_PATH_LITERAL("integration_test.html"));
65 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, MediaInternals_PlayerInfo
) {
66 RunMediaInternalsTest(FILE_PATH_LITERAL("player_info_test.html"));
69 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest
, MediaInternals_Manager
) {
70 RunMediaInternalsTest(FILE_PATH_LITERAL("manager_test.html"));
73 } // namespace content