blob: 1e9c7b62f6fb4ae37e4ca055548263488817d0a3 [file] [log] [blame]
[email protected]fad73672012-06-15 23:26:061// 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
3// found in the LICENSE file.
4
5#include "chrome/browser/extensions/extension_browsertest.h"
6#include "chrome/browser/ui/browser.h"
[email protected]617ee962013-01-29 20:49:127#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]fad73672012-06-15 23:26:068#include "chrome/common/url_constants.h"
9#include "chrome/test/base/ui_test_utils.h"
10#include "content/public/browser/web_contents.h"
[email protected]7d478cb2012-07-24 17:19:4211#include "content/public/test/browser_test_utils.h"
[email protected]885c0e92012-11-13 20:27:4212#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4113#include "extensions/common/extension.h"
[email protected]fad73672012-06-15 23:26:0614
15using content::WebContents;
16using extensions::Extension;
17
18namespace {
19
[email protected]06bc5d92013-01-02 22:44:1320const char kSubscribePage[] = "/subscribe.html";
21const char kFeedPageMultiRel[] = "files/feeds/feed_multi_rel.html";
22const char kValidFeedNoLinks[] = "files/feeds/feed_nolinks.xml";
23const char kValidFeed0[] = "files/feeds/feed_script.xml";
24const char kValidFeed1[] = "files/feeds/feed1.xml";
25const char kValidFeed2[] = "files/feeds/feed2.xml";
26const char kValidFeed3[] = "files/feeds/feed3.xml";
27const char kValidFeed4[] = "files/feeds/feed4.xml";
28const char kValidFeed5[] = "files/feeds/feed5.xml";
29const char kValidFeed6[] = "files/feeds/feed6.xml";
30const char kInvalidFeed1[] = "files/feeds/feed_invalid1.xml";
31const char kInvalidFeed2[] = "files/feeds/feed_invalid2.xml";
[email protected]fad73672012-06-15 23:26:0632// We need a triple encoded string to prove that we are not decoding twice in
33// subscribe.js because one layer is also stripped off when subscribe.js passes
34// it to the XMLHttpRequest object.
[email protected]06bc5d92013-01-02 22:44:1335const char kFeedTripleEncoded[] = "files/feeds/url%25255Fdecoding.html";
[email protected]fad73672012-06-15 23:26:0636
[email protected]06bc5d92013-01-02 22:44:1337static const char kScriptFeedTitle[] =
38 "window.domAutomationController.send("
39 " document.getElementById('title') ? "
40 " document.getElementById('title').textContent : "
41 " \"element 'title' not found\""
42 ");";
43static const char kScriptAnchor[] =
44 "window.domAutomationController.send("
45 " document.getElementById('anchor_0') ? "
46 " document.getElementById('anchor_0').textContent : "
47 " \"element 'anchor_0' not found\""
48 ");";
49static const char kScriptDesc[] =
50 "window.domAutomationController.send("
51 " document.getElementById('desc_0') ? "
52 " document.getElementById('desc_0').textContent : "
53 " \"element 'desc_0' not found\""
54 ");";
55static const char kScriptError[] =
56 "window.domAutomationController.send("
57 " document.getElementById('error') ? "
58 " document.getElementById('error').textContent : "
59 " \"No error\""
60 ");";
[email protected]fad73672012-06-15 23:26:0661
[email protected]ce7d0cbc2013-05-03 18:57:2262GURL GetFeedUrl(net::SpawnedTestServer* server, const std::string& feed_page,
[email protected]fad73672012-06-15 23:26:0663 bool direct_url, std::string extension_id) {
64 GURL feed_url = server->GetURL(feed_page);
65 if (direct_url) {
66 // We navigate directly to the subscribe page for feeds where the feed
67 // sniffing won't work, in other words, as is the case for malformed feeds.
[email protected]885c0e92012-11-13 20:27:4268 return GURL(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:2469 url::kStandardSchemeSeparator +
[email protected]fad73672012-06-15 23:26:0670 extension_id + std::string(kSubscribePage) + std::string("?") +
71 feed_url.spec() + std::string("&synchronous"));
72 } else {
73 // Navigate to the feed content (which will cause the extension to try to
74 // sniff the type and display the subscribe page in another tab.
75 return GURL(feed_url.spec());
76 }
77}
78
[email protected]b27c3622014-03-22 00:26:5579bool ValidatePageElement(content::RenderFrameHost* frame,
[email protected]06bc5d92013-01-02 22:44:1380 const std::string& javascript,
[email protected]fad73672012-06-15 23:26:0681 const std::string& expected_value) {
82 std::string returned_value;
[email protected]fad73672012-06-15 23:26:0683
[email protected]b27c3622014-03-22 00:26:5584 if (!content::ExecuteScriptAndExtractString(frame,
85 javascript,
86 &returned_value))
[email protected]fad73672012-06-15 23:26:0687 return false;
88
89 EXPECT_STREQ(expected_value.c_str(), returned_value.c_str());
90 return expected_value == returned_value;
91}
92
93// Navigates to a feed page and, if |sniff_xml_type| is set, wait for the
94// extension to kick in, detect the feed and redirect to a feed preview page.
95// |sniff_xml_type| is generally set to true if the feed is sniffable and false
96// for invalid feeds.
[email protected]ce7d0cbc2013-05-03 18:57:2297void NavigateToFeedAndValidate(net::SpawnedTestServer* server,
[email protected]fad73672012-06-15 23:26:0698 const std::string& url,
99 Browser* browser,
100 std::string extension_id,
101 bool sniff_xml_type,
102 const std::string& expected_feed_title,
103 const std::string& expected_item_title,
104 const std::string& expected_item_desc,
105 const std::string& expected_error) {
106 if (sniff_xml_type) {
107 // TODO(finnur): Implement this is a non-flaky way.
108 }
109
110 // Navigate to the subscribe page directly.
111 ui_test_utils::NavigateToURL(browser,
112 GetFeedUrl(server, url, true, extension_id));
113
[email protected]617ee962013-01-29 20:49:12114 WebContents* tab = browser->tab_strip_model()->GetActiveWebContents();
[email protected]b27c3622014-03-22 00:26:55115 content::RenderFrameHost* frame = content::FrameMatchingPredicate(
116 tab, base::Bind(&content::FrameIsChildOfMainFrame));
[email protected]007b3f82013-04-09 08:46:45117 ASSERT_TRUE(ValidatePageElement(
[email protected]b27c3622014-03-22 00:26:55118 tab->GetMainFrame(), kScriptFeedTitle, expected_feed_title));
119 ASSERT_TRUE(ValidatePageElement(frame, kScriptAnchor, expected_item_title));
120 ASSERT_TRUE(ValidatePageElement(frame, kScriptDesc, expected_item_desc));
121 ASSERT_TRUE(ValidatePageElement(frame, kScriptError, expected_error));
[email protected]fad73672012-06-15 23:26:06122}
123
124} // namespace
125
126// Makes sure that the RSS detects RSS feed links, even when rel tag contains
127// more than just "alternate".
128IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSMultiRelLink) {
129 ASSERT_TRUE(test_server()->Start());
130
131 ASSERT_TRUE(LoadExtension(
132 test_data_dir_.AppendASCII("subscribe_page_action")));
133
134 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0));
135
136 // Navigate to the feed page.
137 GURL feed_url = test_server()->GetURL(kFeedPageMultiRel);
138 ui_test_utils::NavigateToURL(browser(), feed_url);
139 // We should now have one page action ready to go in the LocationBar.
140 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
141}
142
[email protected]b1258c82014-02-03 20:32:11143// This test is flaky on all platforms; see http://crbug.com/340354
144IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed1) {
[email protected]fad73672012-06-15 23:26:06145 ASSERT_TRUE(test_server()->Start());
146
147 const Extension* extension = LoadExtension(
148 test_data_dir_.AppendASCII("subscribe_page_action"));
149 ASSERT_TRUE(extension);
150 std::string id = extension->id();
151
152 NavigateToFeedAndValidate(test_server(), kValidFeed1, browser(), id, true,
153 "Feed for MyFeedTitle",
154 "Title 1",
155 "Desc",
156 "No error");
157}
158
Mattias Nisslerd3cba302015-03-20 09:07:44159// This test is flaky on all platforms; see http://crbug.com/340354
160IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed2) {
[email protected]fad73672012-06-15 23:26:06161 ASSERT_TRUE(test_server()->Start());
162
163 const Extension* extension = LoadExtension(
164 test_data_dir_.AppendASCII("subscribe_page_action"));
165 ASSERT_TRUE(extension);
166 std::string id = extension->id();
167
168 NavigateToFeedAndValidate(test_server(), kValidFeed2, browser(), id, true,
169 "Feed for MyFeed2",
170 "My item title1",
171 "This is a summary.",
172 "No error");
173}
174
Mattias Nisslerd3cba302015-03-20 09:07:44175// This test is flaky on all platforms; see http://crbug.com/340354
176IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed3) {
[email protected]fad73672012-06-15 23:26:06177 ASSERT_TRUE(test_server()->Start());
178
179 const Extension* extension = LoadExtension(
180 test_data_dir_.AppendASCII("subscribe_page_action"));
181 ASSERT_TRUE(extension);
182 std::string id = extension->id();
183
184 NavigateToFeedAndValidate(test_server(), kValidFeed3, browser(), id, true,
185 "Feed for Google Code buglist rss feed",
186 "My dear title",
187 "My dear content",
188 "No error");
189}
190
Mattias Nisslerd3cba302015-03-20 09:07:44191// This test is flaky on all platforms; see http://crbug.com/340354
192IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed4) {
[email protected]fad73672012-06-15 23:26:06193 ASSERT_TRUE(test_server()->Start());
194
195 const Extension* extension = LoadExtension(
196 test_data_dir_.AppendASCII("subscribe_page_action"));
197 ASSERT_TRUE(extension);
198 std::string id = extension->id();
199
200 NavigateToFeedAndValidate(test_server(), kValidFeed4, browser(), id, true,
201 "Feed for Title chars <script> %23 stop",
202 "Title chars %23 stop",
203 "My dear content %23 stop",
204 "No error");
205}
206
Mattias Nisslerd3cba302015-03-20 09:07:44207// This test is flaky on all platforms; see http://crbug.com/340354
208IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed0) {
[email protected]fad73672012-06-15 23:26:06209 ASSERT_TRUE(test_server()->Start());
210
211 const Extension* extension = LoadExtension(
212 test_data_dir_.AppendASCII("subscribe_page_action"));
213 ASSERT_TRUE(extension);
214 std::string id = extension->id();
215
216 // Try a feed with a link with an onclick handler (before r27440 this would
217 // trigger a NOTREACHED).
218 NavigateToFeedAndValidate(test_server(), kValidFeed0, browser(), id, true,
219 "Feed for MyFeedTitle",
220 "Title 1",
221 "Desc VIDEO",
222 "No error");
223}
224
Mattias Nisslerd3cba302015-03-20 09:07:44225// This test is flaky on all platforms; see http://crbug.com/340354
226IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed5) {
[email protected]fad73672012-06-15 23:26:06227 ASSERT_TRUE(test_server()->Start());
228
229 const Extension* extension = LoadExtension(
230 test_data_dir_.AppendASCII("subscribe_page_action"));
231 ASSERT_TRUE(extension);
232 std::string id = extension->id();
233
234 // Feed with valid but mostly empty xml.
235 NavigateToFeedAndValidate(test_server(), kValidFeed5, browser(), id, true,
236 "Feed for Unknown feed name",
237 "element 'anchor_0' not found",
238 "element 'desc_0' not found",
239 "This feed contains no entries.");
240}
241
Mattias Nisslerd3cba302015-03-20 09:07:44242// This test is flaky on all platforms; see http://crbug.com/340354
243IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed6) {
[email protected]fad73672012-06-15 23:26:06244 ASSERT_TRUE(test_server()->Start());
245
246 const Extension* extension = LoadExtension(
247 test_data_dir_.AppendASCII("subscribe_page_action"));
248 ASSERT_TRUE(extension);
249 std::string id = extension->id();
250
251 // Feed that is technically invalid but still parseable.
252 NavigateToFeedAndValidate(test_server(), kValidFeed6, browser(), id, true,
253 "Feed for MyFeedTitle",
254 "Title 1",
255 "Desc",
256 "No error");
257}
258
[email protected]efe5ba22014-01-07 13:23:27259IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSParseFeedInvalidFeed1) {
[email protected]fad73672012-06-15 23:26:06260 ASSERT_TRUE(test_server()->Start());
261
262 const Extension* extension = LoadExtension(
263 test_data_dir_.AppendASCII("subscribe_page_action"));
264 ASSERT_TRUE(extension);
265 std::string id = extension->id();
266
267 // Try an empty feed.
268 NavigateToFeedAndValidate(test_server(), kInvalidFeed1, browser(), id, false,
269 "Feed for Unknown feed name",
270 "element 'anchor_0' not found",
271 "element 'desc_0' not found",
272 "This feed contains no entries.");
273}
274
[email protected]efe5ba22014-01-07 13:23:27275IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSParseFeedInvalidFeed2) {
[email protected]fad73672012-06-15 23:26:06276 ASSERT_TRUE(test_server()->Start());
277
278 const Extension* extension = LoadExtension(
279 test_data_dir_.AppendASCII("subscribe_page_action"));
280 ASSERT_TRUE(extension);
281 std::string id = extension->id();
282
283 // Try a garbage feed.
284 NavigateToFeedAndValidate(test_server(), kInvalidFeed2, browser(), id, false,
285 "Feed for Unknown feed name",
286 "element 'anchor_0' not found",
287 "element 'desc_0' not found",
288 "This feed contains no entries.");
289}
290
[email protected]efe5ba22014-01-07 13:23:27291IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSParseFeedInvalidFeed3) {
[email protected]fad73672012-06-15 23:26:06292 ASSERT_TRUE(test_server()->Start());
293
294 const Extension* extension = LoadExtension(
295 test_data_dir_.AppendASCII("subscribe_page_action"));
296 ASSERT_TRUE(extension);
297 std::string id = extension->id();
298
299 // Try a feed that doesn't exist.
300 NavigateToFeedAndValidate(test_server(), "foo.xml", browser(), id, false,
301 "Feed for Unknown feed name",
302 "element 'anchor_0' not found",
303 "element 'desc_0' not found",
304 "This feed contains no entries.");
305}
306
[email protected]efe5ba22014-01-07 13:23:27307IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSParseFeedInvalidFeed4) {
[email protected]fad73672012-06-15 23:26:06308 ASSERT_TRUE(test_server()->Start());
309
310 const Extension* extension = LoadExtension(
311 test_data_dir_.AppendASCII("subscribe_page_action"));
312 ASSERT_TRUE(extension);
313 std::string id = extension->id();
314
315 // subscribe.js shouldn't double-decode the URL passed in. Otherwise feed
316 // links such as http://search.twitter.com/search.atom?lang=en&q=%23chrome
317 // will result in no feed being downloaded because %23 gets decoded to # and
318 // therefore #chrome is not treated as part of the Twitter query. This test
319 // uses an underscore instead of a hash, but the principle is the same. If
320 // we start erroneously double decoding again, the path (and the feed) will
321 // become valid resulting in a failure for this test.
322 NavigateToFeedAndValidate(
323 test_server(), kFeedTripleEncoded, browser(), id, true,
324 "Feed for Unknown feed name",
325 "element 'anchor_0' not found",
326 "element 'desc_0' not found",
327 "This feed contains no entries.");
328}
329
Mattias Nisslerd3cba302015-03-20 09:07:44330// This test is flaky on all platforms; see http://crbug.com/340354
331IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
332 DISABLED_RSSParseFeedValidFeedNoLinks) {
[email protected]fad73672012-06-15 23:26:06333 ASSERT_TRUE(test_server()->Start());
334
335 const Extension* extension = LoadExtension(
336 test_data_dir_.AppendASCII("subscribe_page_action"));
337 ASSERT_TRUE(extension);
338 std::string id = extension->id();
339
340 // Valid feed but containing no links.
341 NavigateToFeedAndValidate(
342 test_server(), kValidFeedNoLinks, browser(), id, true,
343 "Feed for MyFeedTitle",
344 "Title with no link",
345 "Desc",
346 "No error");
347}