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/file_util.h"
6 #include "base/files/file_path.h"
7 #include "base/path_service.h"
8 #include "content/public/browser/web_contents.h"
9 #include "content/public/common/content_paths.h"
10 #include "content/public/test/browser_test_utils.h"
11 #include "content/shell/browser/shell.h"
12 #include "content/test/content_browser_test.h"
13 #include "content/test/content_browser_test_utils.h"
14 #include "grit/content_resources.h"
15 #include "grit/webui_resources.h"
16 #include "net/base/net_util.h"
20 class WebUIResourceBrowserTest
: public ContentBrowserTest
{
22 WebUIResourceBrowserTest() {}
23 virtual ~WebUIResourceBrowserTest() {}
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 RenderViewHost
* rvh
= shell()->web_contents()->GetRenderViewHost();
32 EXPECT_TRUE(ExecuteWebUIResourceTest(rvh
, 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