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

Side by Side Diff: chrome_frame/test/html_util_unittests.cc

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome_frame/test/html_util_test_data/quotes_test.html ('k') | chrome_frame/test/http_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2009 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 <windows.h>
6 #include <atlsecurity.h>
7 #include <shellapi.h>
8
9 #include "base/basictypes.h"
10 #include "base/file_util.h"
11 #include "base/message_loop.h"
12 #include "base/path_service.h"
13 #include "base/process_util.h"
14 #include "base/ref_counted.h"
15 #include "base/scoped_handle.h"
16 #include "base/task.h"
17 #include "base/win_util.h"
18 #include "net/base/net_util.h"
19
20 #include "chrome_frame/test/chrome_frame_unittests.h"
21 #include "chrome_frame/chrome_frame_automation.h"
22 #include "chrome_frame/chrome_frame_delegate.h"
23 #include "chrome_frame/html_utils.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25
26 class HtmlUtilUnittest : public testing::Test {
27 protected:
28 // Constructor
29 HtmlUtilUnittest() {}
30
31 // Returns the test path given a test case.
32 virtual bool GetTestPath(const std::wstring& test_case, std::wstring* path) {
33 if (!path) {
34 NOTREACHED();
35 return false;
36 }
37
38 std::wstring test_path;
39 if (!PathService::Get(base::DIR_SOURCE_ROOT, &test_path)) {
40 NOTREACHED();
41 return false;
42 }
43
44 file_util::AppendToPath(&test_path, L"chrome_frame");
45 file_util::AppendToPath(&test_path, L"test");
46 file_util::AppendToPath(&test_path, L"html_util_test_data");
47 file_util::AppendToPath(&test_path, test_case);
48
49 *path = test_path;
50 return true;
51 }
52
53 virtual bool GetTestData(const std::wstring& test_case, std::wstring* data) {
54 if (!data) {
55 NOTREACHED();
56 return false;
57 }
58
59 std::wstring path;
60 if (!GetTestPath(test_case, &path)) {
61 NOTREACHED();
62 return false;
63 }
64
65 std::string raw_data;
66 file_util::ReadFileToString(path, &raw_data);
67
68 // Convert to wide using the "best effort" assurance described in
69 // string_util.h
70 data->assign(UTF8ToWide(raw_data));
71 return true;
72 }
73 };
74
75 TEST_F(HtmlUtilUnittest, BasicTest) {
76 std::wstring test_data;
77 GetTestData(L"basic_test.html", &test_data);
78
79 HTMLScanner scanner(test_data.c_str());
80
81 // Grab the meta tag from the document and ensure that we get exactly one.
82 HTMLScanner::StringRangeList tag_list;
83 scanner.GetTagsByName(L"meta", &tag_list, L"body");
84 ASSERT_EQ(1, tag_list.size());
85
86 // Pull out the http-equiv attribute and check its value:
87 HTMLScanner::StringRange attribute_value;
88 EXPECT_TRUE(tag_list[0].GetTagAttribute(L"http-equiv", &attribute_value));
89 EXPECT_TRUE(attribute_value.Equals(L"X-UA-Compatible"));
90
91 // Pull out the content attribute and check its value:
92 EXPECT_TRUE(tag_list[0].GetTagAttribute(L"content", &attribute_value));
93 EXPECT_TRUE(attribute_value.Equals(L"chrome=1"));
94 }
95
96 TEST_F(HtmlUtilUnittest, QuotesTest) {
97 std::wstring test_data;
98 GetTestData(L"quotes_test.html", &test_data);
99
100 HTMLScanner scanner(test_data.c_str());
101
102 // Grab the meta tag from the document and ensure that we get exactly one.
103 HTMLScanner::StringRangeList tag_list;
104 scanner.GetTagsByName(L"meta", &tag_list, L"body");
105 ASSERT_EQ(1, tag_list.size());
106
107 // Pull out the http-equiv attribute and check its value:
108 HTMLScanner::StringRange attribute_value;
109 EXPECT_TRUE(tag_list[0].GetTagAttribute(L"http-equiv", &attribute_value));
110 EXPECT_TRUE(attribute_value.Equals(L"X-UA-Compatible"));
111
112 // Pull out the content attribute and check its value:
113 EXPECT_TRUE(tag_list[0].GetTagAttribute(L"content", &attribute_value));
114 EXPECT_TRUE(attribute_value.Equals(L"chrome=1"));
115 }
116
117 TEST_F(HtmlUtilUnittest, DegenerateCasesTest) {
118 std::wstring test_data;
119 GetTestData(L"degenerate_cases_test.html", &test_data);
120
121 HTMLScanner scanner(test_data.c_str());
122
123 // Scan for meta tags in the document. We expect not to pick up the one
124 // that appears to be there since it is technically inside a quote block.
125 HTMLScanner::StringRangeList tag_list;
126 scanner.GetTagsByName(L"meta", &tag_list, L"body");
127 EXPECT_TRUE(tag_list.empty());
128 }
129
130 TEST_F(HtmlUtilUnittest, MultipleTagsTest) {
131 std::wstring test_data;
132 GetTestData(L"multiple_tags.html", &test_data);
133
134 HTMLScanner scanner(test_data.c_str());
135
136 // Grab the meta tag from the document and ensure that we get exactly three.
137 HTMLScanner::StringRangeList tag_list;
138 scanner.GetTagsByName(L"meta", &tag_list, L"body");
139 EXPECT_EQ(7, tag_list.size());
140
141 // Pull out the content attribute for each tag and check its value:
142 HTMLScanner::StringRange attribute_value;
143 HTMLScanner::StringRangeList::const_iterator tag_list_iter(
144 tag_list.begin());
145 int valid_tag_count = 0;
146 for (; tag_list_iter != tag_list.end(); tag_list_iter++) {
147 HTMLScanner::StringRange attribute_value;
148 if (tag_list_iter->GetTagAttribute(L"http-equiv", &attribute_value) &&
149 attribute_value.Equals(L"X-UA-Compatible")) {
150 EXPECT_TRUE(tag_list_iter->GetTagAttribute(L"content", &attribute_value));
151 EXPECT_TRUE(attribute_value.Equals(L"chrome=1"));
152 valid_tag_count++;
153 }
154 }
155 EXPECT_EQ(3, valid_tag_count);
156 }
157
158 TEST_F(HtmlUtilUnittest, ShortDegenerateTest1) {
159 std::wstring test_data(
160 L"<foo><META http-equiv=X-UA-Compatible content='chrome=1'");
161
162 HTMLScanner scanner(test_data.c_str());
163
164 // Scan for meta tags in the document. We expect not to pick up the one
165 // that is there since it is not properly closed.
166 HTMLScanner::StringRangeList tag_list;
167 scanner.GetTagsByName(L"meta", &tag_list, L"body");
168 EXPECT_TRUE(tag_list.empty());
169 }
170
171 TEST_F(HtmlUtilUnittest, ShortDegenerateTest2) {
172 std::wstring test_data(
173 L"<foo <META http-equiv=X-UA-Compatible content='chrome=1'/>");
174
175 HTMLScanner scanner(test_data.c_str());
176
177 // Scan for meta tags in the document. We expect not to pick up the one
178 // that appears to be there since it is inside a non-closed tag.
179 HTMLScanner::StringRangeList tag_list;
180 scanner.GetTagsByName(L"meta", &tag_list, L"body");
181 EXPECT_TRUE(tag_list.empty());
182 }
183
184 TEST_F(HtmlUtilUnittest, QuoteInsideHTMLCommentTest) {
185 std::wstring test_data(
186 L"<!-- comment' --><META http-equiv=X-UA-Compatible content='chrome=1'/>");
187
188 HTMLScanner scanner(test_data.c_str());
189
190 // Grab the meta tag from the document and ensure that we get exactly one.
191 HTMLScanner::StringRangeList tag_list;
192 scanner.GetTagsByName(L"meta", &tag_list, L"body");
193 ASSERT_EQ(1, tag_list.size());
194
195 // Pull out the http-equiv attribute and check its value:
196 HTMLScanner::StringRange attribute_value;
197 EXPECT_TRUE(tag_list[0].GetTagAttribute(L"http-equiv", &attribute_value));
198 EXPECT_TRUE(attribute_value.Equals(L"X-UA-Compatible"));
199
200 // Pull out the content attribute and check its value:
201 EXPECT_TRUE(tag_list[0].GetTagAttribute(L"content", &attribute_value));
202 EXPECT_TRUE(attribute_value.Equals(L"chrome=1"));
203 }
204
205 TEST_F(HtmlUtilUnittest, CloseTagInsideHTMLCommentTest) {
206 std::wstring test_data(
207 L"<!-- comment> <META http-equiv=X-UA-Compatible content='chrome=1'/>-->");
208
209 HTMLScanner scanner(test_data.c_str());
210
211 // Grab the meta tag from the document and ensure that we get exactly one.
212 HTMLScanner::StringRangeList tag_list;
213 scanner.GetTagsByName(L"meta", &tag_list, L"body");
214 ASSERT_TRUE(tag_list.empty());
215 }
OLDNEW
« no previous file with comments | « chrome_frame/test/html_util_test_data/quotes_test.html ('k') | chrome_frame/test/http_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698