Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: webkit/glue/dom_operations_unittest.cc

Issue 63011: Monster FilePath patch! (Closed)
Patch Set: sync with trunk Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webkit/glue/context_menu_unittest.cc ('k') | webkit/glue/dom_serializer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "net/base/net_util.h" 8 #include "net/base/net_util.h"
9 #include "net/url_request/url_request_context.h" 9 #include "net/url_request/url_request_context.h"
10 #include "webkit/glue/dom_operations.h" 10 #include "webkit/glue/dom_operations.h"
11 #include "webkit/glue/webview.h" 11 #include "webkit/glue/webview.h"
12 #include "webkit/glue/webframe.h" 12 #include "webkit/glue/webframe.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 std::wstring& page_file_path, 23 void GetSavableResourceLinksForPage(const 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 std::wstring& page_file_path, 39 const 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 std::wstring file_wurl = ASCIIToWide(file_url.spec()); 45 std::wstring file_wurl = ASCIIToWide(file_url.spec());
46 test_shell_->LoadURL(file_wurl.c_str()); 46 test_shell_->LoadURL(file_wurl.c_str());
47 test_shell_->WaitTestFinished(); 47 test_shell_->WaitTestFinished();
48 // Get all savable resource links for the page. 48 // Get all savable resource links for the page.
49 std::vector<GURL> resources_list; 49 std::vector<GURL> resources_list;
(...skipping 18 matching lines...) Expand all
68 ASSERT_TRUE(expected_resources_set.find(*cit) != 68 ASSERT_TRUE(expected_resources_set.find(*cit) !=
69 expected_resources_set.end()); 69 expected_resources_set.end());
70 } 70 }
71 } 71 }
72 72
73 // Test function GetAllSavableResourceLinksForCurrentPage with a web page 73 // Test function GetAllSavableResourceLinksForCurrentPage with a web page
74 // which has valid savable resource links. 74 // which has valid savable resource links.
75 TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasValidLinks) { 75 TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasValidLinks) {
76 std::set<GURL> expected_resources_set; 76 std::set<GURL> expected_resources_set;
77 // Set directory of test data. 77 // Set directory of test data.
78 std::wstring page_file_path = data_dir_; 78 FilePath page_file_path = data_dir_.AppendASCII("dom_serializer");
79 file_util::AppendToPath(&page_file_path, L"dom_serializer");
80 79
81 const char* expected_sub_resource_links[] = { 80 const char* expected_sub_resource_links[] = {
82 "file:///c:/yt/css/base_all-vfl36460.css", 81 "file:///c:/yt/css/base_all-vfl36460.css",
83 "file:///c:/yt/js/base_all_with_bidi-vfl36451.js", 82 "file:///c:/yt/js/base_all_with_bidi-vfl36451.js",
84 "file:///c:/yt/img/pixel-vfl73.gif" 83 "file:///c:/yt/img/pixel-vfl73.gif"
85 }; 84 };
86 const wchar_t* expected_frame_links[] = { 85 const char* expected_frame_links[] = {
87 L"youtube_1.htm", 86 "youtube_1.htm",
88 L"youtube_2.htm" 87 "youtube_2.htm"
89 }; 88 };
90 // Add all expected links of sub-resource to expected set. 89 // Add all expected links of sub-resource to expected set.
91 for (size_t i = 0; i < arraysize(expected_sub_resource_links); ++i) 90 for (size_t i = 0; i < arraysize(expected_sub_resource_links); ++i)
92 expected_resources_set.insert(GURL(expected_sub_resource_links[i])); 91 expected_resources_set.insert(GURL(expected_sub_resource_links[i]));
93 // Add all expected links of frame to expected set. 92 // Add all expected links of frame to expected set.
94 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) { 93 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) {
95 std::wstring expected_frame_url = page_file_path; 94 const FilePath expected_frame_url =
96 file_util::AppendToPath(&expected_frame_url, expected_frame_links[i]); 95 page_file_path.AppendASCII(expected_frame_links[i]);
97 expected_resources_set.insert( 96 expected_resources_set.insert(
98 net::FilePathToFileURL(expected_frame_url)); 97 net::FilePathToFileURL(expected_frame_url));
99 } 98 }
100 99
101 file_util::AppendToPath(&page_file_path, std::wstring(L"youtube_1.htm")); 100 page_file_path = page_file_path.AppendASCII("youtube_1.htm");
102 GetSavableResourceLinksForPage(page_file_path, expected_resources_set); 101 GetSavableResourceLinksForPage(page_file_path, expected_resources_set);
103 } 102 }
104 103
105 // Test function GetAllSavableResourceLinksForCurrentPage with a web page 104 // Test function GetAllSavableResourceLinksForCurrentPage with a web page
106 // which does not have valid savable resource links. 105 // which does not have valid savable resource links.
107 TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasInvalidLinks) { 106 TEST_F(DomOperationsTests, GetSavableResourceLinksWithPageHasInvalidLinks) {
108 std::set<GURL> expected_resources_set; 107 std::set<GURL> expected_resources_set;
109 // Set directory of test data. 108 // Set directory of test data.
110 std::wstring page_file_path = data_dir_; 109 FilePath page_file_path = data_dir_.AppendASCII("dom_serializer");
111 file_util::AppendToPath(&page_file_path, L"dom_serializer");
112 110
113 const wchar_t* expected_frame_links[] = { 111 const char* expected_frame_links[] = {
114 L"youtube_2.htm" 112 "youtube_2.htm"
115 }; 113 };
116 // Add all expected links of frame to expected set. 114 // Add all expected links of frame to expected set.
117 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) { 115 for (size_t i = 0; i < arraysize(expected_frame_links); ++i) {
118 std::wstring expected_frame_url = page_file_path; 116 FilePath expected_frame_url =
119 file_util::AppendToPath(&expected_frame_url, expected_frame_links[i]); 117 page_file_path.AppendASCII(expected_frame_links[i]);
120 expected_resources_set.insert( 118 expected_resources_set.insert(
121 net::FilePathToFileURL(expected_frame_url)); 119 net::FilePathToFileURL(expected_frame_url));
122 } 120 }
123 121
124 file_util::AppendToPath(&page_file_path, std::wstring(L"youtube_2.htm")); 122 page_file_path = page_file_path.AppendASCII("youtube_2.htm");
125 GetSavableResourceLinksForPage(page_file_path, expected_resources_set); 123 GetSavableResourceLinksForPage(page_file_path, expected_resources_set);
126 } 124 }
127 125
128 // Tests ParseIconSizes with various input. 126 // Tests ParseIconSizes with various input.
129 TEST_F(DomOperationsTests, ParseIconSizes) { 127 TEST_F(DomOperationsTests, ParseIconSizes) {
130 struct TestData { 128 struct TestData {
131 const std::wstring input; 129 const std::wstring input;
132 const bool expected_result; 130 const bool expected_result;
133 const bool is_any; 131 const bool is_any;
134 const size_t expected_size_count; 132 const size_t expected_size_count;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 171 }
174 if (sizes.size() > 1) { 172 if (sizes.size() > 1) {
175 ASSERT_EQ(data[i].width2, sizes[1].width()); 173 ASSERT_EQ(data[i].width2, sizes[1].width());
176 ASSERT_EQ(data[i].height2, sizes[1].height()); 174 ASSERT_EQ(data[i].height2, sizes[1].height());
177 } 175 }
178 } 176 }
179 } 177 }
180 } 178 }
181 179
182 } // namespace 180 } // namespace
OLDNEW
« no previous file with comments | « webkit/glue/context_menu_unittest.cc ('k') | webkit/glue/dom_serializer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698