Index: content/renderer/dom_operations_browsertest.cc |
=================================================================== |
--- content/renderer/dom_operations_browsertest.cc (revision 195324) |
+++ content/renderer/dom_operations_browsertest.cc (working copy) |
@@ -2,87 +2,88 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "base/file_util.h" |
-#include "base/path_service.h" |
-#include "base/string_util.h" |
-#include "base/utf_string_conversions.h" |
+#include "base/bind.h" |
+#include "base/command_line.h" |
+#include "base/files/file_path.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/common/content_switches.h" |
+#include "content/public/renderer/render_view.h" |
+#include "content/shell/shell.h" |
+#include "content/test/content_browser_test.h" |
+#include "content/test/content_browser_test_utils.h" |
#include "net/base/net_util.h" |
-#include "net/url_request/url_request_context.h" |
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
#include "webkit/glue/dom_operations.h" |
-#include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
-#include "webkit/tools/test_shell/test_shell_test.h" |
-namespace { |
+namespace content { |
-class DomOperationsTests : public TestShellTest { |
+class DomOperationsTests : public ContentBrowserTest { |
public: |
+ virtual void SetUpCommandLine(CommandLine* command_line) { |
+ command_line->AppendSwitch(switches::kSingleProcess); |
+ } |
+ |
// Test function GetAllSavableResourceLinksForCurrentPage with a web page. |
// We expect result of GetAllSavableResourceLinksForCurrentPage exactly |
// matches expected_resources_set. |
- void GetSavableResourceLinksForPage(const base::FilePath& page_file_path, |
- const std::set<GURL>& expected_resources_set); |
+ void GetSavableResourceLinksForPage( |
+ const base::FilePath& page_file_path, |
+ const std::set<GURL>& expected_resources_set) { |
+ // Convert local file path to file URL. |
+ GURL file_url = net::FilePathToFileURL(page_file_path); |
+ // Load the test file. |
+ NavigateToURL(shell(), file_url); |
- protected: |
- // testing::Test |
- virtual void SetUp() { |
- TestShellTest::SetUp(); |
+ PostTaskToInProcessRendererAndWait( |
+ base::Bind(&DomOperationsTests::CheckResources, base::Unretained(this), |
+ page_file_path, expected_resources_set, file_url, |
+ shell()->web_contents()->GetRoutingID())); |
} |
- virtual void TearDown() { |
- TestShellTest::TearDown(); |
- } |
-}; |
+ void CheckResources(const base::FilePath& page_file_path, |
+ const std::set<GURL>& expected_resources_set, |
+ const GURL& file_url, |
+ int render_view_id) { |
+ // Get all savable resource links for the page. |
+ std::vector<GURL> resources_list; |
+ std::vector<GURL> referrer_urls_list; |
+ std::vector<WebKit::WebReferrerPolicy> referrer_policies_list; |
+ std::vector<GURL> frames_list; |
+ webkit_glue::SavableResourcesResult result(&resources_list, |
+ &referrer_urls_list, |
+ &referrer_policies_list, |
+ &frames_list); |
+ const char* savable_schemes[] = { |
+ "http", |
+ "https", |
+ "file", |
+ NULL |
+ }; |
-void DomOperationsTests::GetSavableResourceLinksForPage( |
- const base::FilePath& page_file_path, |
- const std::set<GURL>& expected_resources_set) { |
- // Convert local file path to file URL. |
- GURL file_url = net::FilePathToFileURL(page_file_path); |
- // Load the test file. |
- test_shell_->ResetTestController(); |
- test_shell_->LoadURL(file_url); |
- test_shell_->WaitTestFinished(); |
- // Get all savable resource links for the page. |
- std::vector<GURL> resources_list; |
- std::vector<GURL> referrer_urls_list; |
- std::vector<WebKit::WebReferrerPolicy> referrer_policies_list; |
- std::vector<GURL> frames_list; |
- webkit_glue::SavableResourcesResult result(&resources_list, |
- &referrer_urls_list, |
- &referrer_policies_list, |
- &frames_list); |
+ RenderView* render_view = RenderView::FromRoutingID(render_view_id); |
- const char* savable_schemes[] = { |
- "http", |
- "https", |
- "file", |
- NULL |
- }; |
- |
- ASSERT_TRUE(webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
- test_shell_->webView(), file_url, &result, savable_schemes)); |
- // Check all links of sub-resource |
- for (std::vector<GURL>::const_iterator cit = resources_list.begin(); |
- cit != resources_list.end(); ++cit) { |
- ASSERT_TRUE(expected_resources_set.find(*cit) != |
- expected_resources_set.end()); |
+ ASSERT_TRUE(webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
+ render_view->GetWebView(), file_url, &result, savable_schemes)); |
+ // Check all links of sub-resource |
+ for (std::vector<GURL>::const_iterator cit = resources_list.begin(); |
+ cit != resources_list.end(); ++cit) { |
+ ASSERT_TRUE(expected_resources_set.find(*cit) != |
+ expected_resources_set.end()); |
+ } |
+ // Check all links of frame. |
+ for (std::vector<GURL>::const_iterator cit = frames_list.begin(); |
+ cit != frames_list.end(); ++cit) { |
+ ASSERT_TRUE(expected_resources_set.find(*cit) != |
+ expected_resources_set.end()); |
+ } |
} |
- // Check all links of frame. |
- for (std::vector<GURL>::const_iterator cit = frames_list.begin(); |
- cit != frames_list.end(); ++cit) { |
- ASSERT_TRUE(expected_resources_set.find(*cit) != |
- expected_resources_set.end()); |
- } |
-} |
+}; |
// Test function GetAllSavableResourceLinksForCurrentPage with a web page |
// which has valid savable resource links. |
-TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasValidLinks) { |
+IN_PROC_BROWSER_TEST_F(DomOperationsTests, |
+ GetSavableResourceLinksWithPageHasValidLinks) { |
std::set<GURL> expected_resources_set; |
- // Set directory of test data. |
- base::FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); |
const char* expected_sub_resource_links[] = { |
"file:///c:/yt/css/base_all-vfl36460.css", |
@@ -99,21 +100,21 @@ |
// Add all expected links of frame to expected set. |
for (size_t i = 0; i < arraysize(expected_frame_links); ++i) { |
const base::FilePath expected_frame_url = |
- page_file_path.AppendASCII(expected_frame_links[i]); |
+ GetTestFilePath("dom_serializer", expected_frame_links[i]); |
expected_resources_set.insert( |
net::FilePathToFileURL(expected_frame_url)); |
} |
- page_file_path = page_file_path.AppendASCII("youtube_1.htm"); |
+ base::FilePath page_file_path = |
+ GetTestFilePath("dom_serializer", "youtube_1.htm"); |
GetSavableResourceLinksForPage(page_file_path, expected_resources_set); |
} |
// Test function GetAllSavableResourceLinksForCurrentPage with a web page |
// which does not have valid savable resource links. |
-TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasInvalidLinks) { |
+IN_PROC_BROWSER_TEST_F(DomOperationsTests, |
+ GetSavableResourceLinksWithPageHasInvalidLinks) { |
std::set<GURL> expected_resources_set; |
- // Set directory of test data. |
- base::FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); |
const char* expected_frame_links[] = { |
"youtube_2.htm" |
@@ -121,13 +122,14 @@ |
// Add all expected links of frame to expected set. |
for (size_t i = 0; i < arraysize(expected_frame_links); ++i) { |
base::FilePath expected_frame_url = |
- page_file_path.AppendASCII(expected_frame_links[i]); |
+ GetTestFilePath("dom_serializer", expected_frame_links[i]); |
expected_resources_set.insert( |
net::FilePathToFileURL(expected_frame_url)); |
} |
- page_file_path = page_file_path.AppendASCII("youtube_2.htm"); |
+ base::FilePath page_file_path = |
+ GetTestFilePath("dom_serializer", "youtube_2.htm"); |
GetSavableResourceLinksForPage(page_file_path, expected_resources_set); |
} |
-} // namespace |
+} // namespace content |