| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "net/base/net_util.h" | 9 #include "net/base/net_util.h" |
| 10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 12 #include "webkit/glue/dom_operations.h" | 12 #include "webkit/glue/dom_operations.h" |
| 13 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 13 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
| 14 #include "webkit/tools/test_shell/test_shell_test.h" | 14 #include "webkit/tools/test_shell/test_shell_test.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class DomOperationsTests : public TestShellTest { | 18 class DomOperationsTests : public TestShellTest { |
| 19 public: | 19 public: |
| 20 // Test function GetAllSavableResourceLinksForCurrentPage with a web page. | 20 // Test function GetAllSavableResourceLinksForCurrentPage with a web page. |
| 21 // We expect result of GetAllSavableResourceLinksForCurrentPage exactly | 21 // We expect result of GetAllSavableResourceLinksForCurrentPage exactly |
| 22 // matches expected_resources_set. | 22 // matches expected_resources_set. |
| 23 void GetSavableResourceLinksForPage(const FilePath& page_file_path, | 23 void GetSavableResourceLinksForPage(const base::FilePath& page_file_path, |
| 24 const std::set<GURL>& expected_resources_set); | 24 const std::set<GURL>& expected_resources_set); |
| 25 | 25 |
| 26 protected: | 26 protected: |
| 27 // testing::Test | 27 // testing::Test |
| 28 virtual void SetUp() { | 28 virtual void SetUp() { |
| 29 TestShellTest::SetUp(); | 29 TestShellTest::SetUp(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual void TearDown() { | 32 virtual void TearDown() { |
| 33 TestShellTest::TearDown(); | 33 TestShellTest::TearDown(); |
| 34 } | 34 } |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 | 37 |
| 38 void DomOperationsTests::GetSavableResourceLinksForPage( | 38 void DomOperationsTests::GetSavableResourceLinksForPage( |
| 39 const FilePath& page_file_path, | 39 const base::FilePath& page_file_path, |
| 40 const std::set<GURL>& expected_resources_set) { | 40 const std::set<GURL>& expected_resources_set) { |
| 41 // Convert local file path to file URL. | 41 // Convert local file path to file URL. |
| 42 GURL file_url = net::FilePathToFileURL(page_file_path); | 42 GURL file_url = net::FilePathToFileURL(page_file_path); |
| 43 // Load the test file. | 43 // Load the test file. |
| 44 test_shell_->ResetTestController(); | 44 test_shell_->ResetTestController(); |
| 45 test_shell_->LoadURL(file_url); | 45 test_shell_->LoadURL(file_url); |
| 46 test_shell_->WaitTestFinished(); | 46 test_shell_->WaitTestFinished(); |
| 47 // Get all savable resource links for the page. | 47 // Get all savable resource links for the page. |
| 48 std::vector<GURL> resources_list; | 48 std::vector<GURL> resources_list; |
| 49 std::vector<GURL> referrer_urls_list; | 49 std::vector<GURL> referrer_urls_list; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 75 ASSERT_TRUE(expected_resources_set.find(*cit) != | 75 ASSERT_TRUE(expected_resources_set.find(*cit) != |
| 76 expected_resources_set.end()); | 76 expected_resources_set.end()); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Test function GetAllSavableResourceLinksForCurrentPage with a web page | 80 // Test function GetAllSavableResourceLinksForCurrentPage with a web page |
| 81 // which has valid savable resource links. | 81 // which has valid savable resource links. |
| 82 TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasValidLinks) { | 82 TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasValidLinks) { |
| 83 std::set<GURL> expected_resources_set; | 83 std::set<GURL> expected_resources_set; |
| 84 // Set directory of test data. | 84 // Set directory of test data. |
| 85 FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); | 85 base::FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); |
| 86 | 86 |
| 87 const char* expected_sub_resource_links[] = { | 87 const char* expected_sub_resource_links[] = { |
| 88 "file:///c:/yt/css/base_all-vfl36460.css", | 88 "file:///c:/yt/css/base_all-vfl36460.css", |
| 89 "file:///c:/yt/js/base_all_with_bidi-vfl36451.js", | 89 "file:///c:/yt/js/base_all_with_bidi-vfl36451.js", |
| 90 "file:///c:/yt/img/pixel-vfl73.gif" | 90 "file:///c:/yt/img/pixel-vfl73.gif" |
| 91 }; | 91 }; |
| 92 const char* expected_frame_links[] = { | 92 const char* expected_frame_links[] = { |
| 93 "youtube_1.htm", | 93 "youtube_1.htm", |
| 94 "youtube_2.htm" | 94 "youtube_2.htm" |
| 95 }; | 95 }; |
| 96 // Add all expected links of sub-resource to expected set. | 96 // Add all expected links of sub-resource to expected set. |
| 97 for (size_t i = 0; i < arraysize(expected_sub_resource_links); ++i) | 97 for (size_t i = 0; i < arraysize(expected_sub_resource_links); ++i) |
| 98 expected_resources_set.insert(GURL(expected_sub_resource_links[i])); | 98 expected_resources_set.insert(GURL(expected_sub_resource_links[i])); |
| 99 // Add all expected links of frame to expected set. | 99 // Add all expected links of frame to expected set. |
| 100 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) { | 100 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) { |
| 101 const FilePath expected_frame_url = | 101 const base::FilePath expected_frame_url = |
| 102 page_file_path.AppendASCII(expected_frame_links[i]); | 102 page_file_path.AppendASCII(expected_frame_links[i]); |
| 103 expected_resources_set.insert( | 103 expected_resources_set.insert( |
| 104 net::FilePathToFileURL(expected_frame_url)); | 104 net::FilePathToFileURL(expected_frame_url)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); | 107 page_file_path = page_file_path.AppendASCII("youtube_1.htm"); |
| 108 GetSavableResourceLinksForPage(page_file_path, expected_resources_set); | 108 GetSavableResourceLinksForPage(page_file_path, expected_resources_set); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Test function GetAllSavableResourceLinksForCurrentPage with a web page | 111 // Test function GetAllSavableResourceLinksForCurrentPage with a web page |
| 112 // which does not have valid savable resource links. | 112 // which does not have valid savable resource links. |
| 113 TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasInvalidLinks) { | 113 TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasInvalidLinks) { |
| 114 std::set<GURL> expected_resources_set; | 114 std::set<GURL> expected_resources_set; |
| 115 // Set directory of test data. | 115 // Set directory of test data. |
| 116 FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); | 116 base::FilePath page_file_path = data_dir_.AppendASCII("dom_serializer"); |
| 117 | 117 |
| 118 const char* expected_frame_links[] = { | 118 const char* expected_frame_links[] = { |
| 119 "youtube_2.htm" | 119 "youtube_2.htm" |
| 120 }; | 120 }; |
| 121 // Add all expected links of frame to expected set. | 121 // Add all expected links of frame to expected set. |
| 122 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) { | 122 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) { |
| 123 FilePath expected_frame_url = | 123 base::FilePath expected_frame_url = |
| 124 page_file_path.AppendASCII(expected_frame_links[i]); | 124 page_file_path.AppendASCII(expected_frame_links[i]); |
| 125 expected_resources_set.insert( | 125 expected_resources_set.insert( |
| 126 net::FilePathToFileURL(expected_frame_url)); | 126 net::FilePathToFileURL(expected_frame_url)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); | 129 page_file_path = page_file_path.AppendASCII("youtube_2.htm"); |
| 130 GetSavableResourceLinksForPage(page_file_path, expected_resources_set); | 130 GetSavableResourceLinksForPage(page_file_path, expected_resources_set); |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace | 133 } // namespace |
| OLD | NEW |