Home | History | Annotate | Download | only in test
      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.
      4 
      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/public/test/content_browser_test.h"
     12 #include "content/public/test/content_browser_test_utils.h"
     13 #include "content/shell/browser/shell.h"
     14 #include "grit/content_resources.h"
     15 #include "grit/webui_resources.h"
     16 #include "net/base/filename_util.h"
     17 
     18 namespace content {
     19 
     20 class WebUIResourceBrowserTest : public ContentBrowserTest {
     21  public:
     22   WebUIResourceBrowserTest() {}
     23   virtual ~WebUIResourceBrowserTest() {}
     24 
     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));
     29 
     30     content::WebContents* web_contents = shell()->web_contents();
     31     ASSERT_TRUE(web_contents);
     32     EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents, include_libraries_));
     33   }
     34 
     35   void RunMediaInternalsTest(const base::FilePath::CharType* file) {
     36     AddLibrary(IDR_WEBUI_JS_CR);
     37     AddLibrary(IDR_MEDIA_INTERNALS_JS);
     38 
     39     base::FilePath path;
     40     PathService::Get(DIR_TEST_DATA, &path);
     41     RunTest(path.Append(FILE_PATH_LITERAL("media"))
     42         .Append(FILE_PATH_LITERAL("webui"))
     43         .Append(file));
     44   }
     45 
     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
     49   // function.
     50   void AddLibrary(int resource_id) {
     51     include_libraries_.push_back(resource_id);
     52   }
     53 
     54  private:
     55   // Resource IDs for internal javascript libraries to inject into the test.
     56   std::vector<int> include_libraries_;
     57 
     58   DISALLOW_COPY_AND_ASSIGN(WebUIResourceBrowserTest);
     59 };
     60 
     61 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, MediaInternals_Integration) {
     62   RunMediaInternalsTest(FILE_PATH_LITERAL("integration_test.html"));
     63 }
     64 
     65 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, MediaInternals_PlayerInfo) {
     66   RunMediaInternalsTest(FILE_PATH_LITERAL("player_info_test.html"));
     67 }
     68 
     69 IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, MediaInternals_Manager) {
     70   RunMediaInternalsTest(FILE_PATH_LITERAL("manager_test.html"));
     71 }
     72 
     73 }  // namespace content
     74