[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/extension_browsertest.h" |
| 6 | #include "chrome/browser/ui/browser.h" |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 7 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 8 | #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] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 11 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 12 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 13 | #include "extensions/common/extension.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 14 | |
| 15 | using content::WebContents; |
| 16 | using extensions::Extension; |
| 17 | |
| 18 | namespace { |
| 19 | |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 20 | const char kSubscribePage[] = "/subscribe.html"; |
| 21 | const char kFeedPageMultiRel[] = "files/feeds/feed_multi_rel.html"; |
| 22 | const char kValidFeedNoLinks[] = "files/feeds/feed_nolinks.xml"; |
| 23 | const char kValidFeed0[] = "files/feeds/feed_script.xml"; |
| 24 | const char kValidFeed1[] = "files/feeds/feed1.xml"; |
| 25 | const char kValidFeed2[] = "files/feeds/feed2.xml"; |
| 26 | const char kValidFeed3[] = "files/feeds/feed3.xml"; |
| 27 | const char kValidFeed4[] = "files/feeds/feed4.xml"; |
| 28 | const char kValidFeed5[] = "files/feeds/feed5.xml"; |
| 29 | const char kValidFeed6[] = "files/feeds/feed6.xml"; |
| 30 | const char kInvalidFeed1[] = "files/feeds/feed_invalid1.xml"; |
| 31 | const char kInvalidFeed2[] = "files/feeds/feed_invalid2.xml"; |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 32 | // 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] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 35 | const char kFeedTripleEncoded[] = "files/feeds/url%25255Fdecoding.html"; |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 36 | |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 37 | static const char kScriptFeedTitle[] = |
| 38 | "window.domAutomationController.send(" |
| 39 | " document.getElementById('title') ? " |
| 40 | " document.getElementById('title').textContent : " |
| 41 | " \"element 'title' not found\"" |
| 42 | ");"; |
| 43 | static 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 | ");"; |
| 49 | static 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 | ");"; |
| 55 | static const char kScriptError[] = |
| 56 | "window.domAutomationController.send(" |
| 57 | " document.getElementById('error') ? " |
| 58 | " document.getElementById('error').textContent : " |
| 59 | " \"No error\"" |
| 60 | ");"; |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 61 | |
[email protected] | ce7d0cbc | 2013-05-03 18:57:22 | [diff] [blame] | 62 | GURL GetFeedUrl(net::SpawnedTestServer* server, const std::string& feed_page, |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 63 | 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] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 68 | return GURL(std::string(extensions::kExtensionScheme) + |
[email protected] | fb4fe095 | 2014-06-05 09:44:24 | [diff] [blame] | 69 | url::kStandardSchemeSeparator + |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 70 | 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] | b27c362 | 2014-03-22 00:26:55 | [diff] [blame] | 79 | bool ValidatePageElement(content::RenderFrameHost* frame, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 80 | const std::string& javascript, |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 81 | const std::string& expected_value) { |
| 82 | std::string returned_value; |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 83 | |
[email protected] | b27c362 | 2014-03-22 00:26:55 | [diff] [blame] | 84 | if (!content::ExecuteScriptAndExtractString(frame, |
| 85 | javascript, |
| 86 | &returned_value)) |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 87 | 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] | ce7d0cbc | 2013-05-03 18:57:22 | [diff] [blame] | 97 | void NavigateToFeedAndValidate(net::SpawnedTestServer* server, |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 98 | 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] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 114 | WebContents* tab = browser->tab_strip_model()->GetActiveWebContents(); |
[email protected] | b27c362 | 2014-03-22 00:26:55 | [diff] [blame] | 115 | content::RenderFrameHost* frame = content::FrameMatchingPredicate( |
| 116 | tab, base::Bind(&content::FrameIsChildOfMainFrame)); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 117 | ASSERT_TRUE(ValidatePageElement( |
[email protected] | b27c362 | 2014-03-22 00:26:55 | [diff] [blame] | 118 | 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] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | } // namespace |
| 125 | |
| 126 | // Makes sure that the RSS detects RSS feed links, even when rel tag contains |
| 127 | // more than just "alternate". |
| 128 | IN_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] | b1258c8 | 2014-02-03 20:32:11 | [diff] [blame] | 143 | // This test is flaky on all platforms; see http://crbug.com/340354 |
| 144 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed1) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 145 | 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 Nissler | d3cba30 | 2015-03-20 09:07:44 | [diff] [blame^] | 159 | // This test is flaky on all platforms; see http://crbug.com/340354 |
| 160 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed2) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 161 | 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 Nissler | d3cba30 | 2015-03-20 09:07:44 | [diff] [blame^] | 175 | // This test is flaky on all platforms; see http://crbug.com/340354 |
| 176 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed3) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 177 | 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 Nissler | d3cba30 | 2015-03-20 09:07:44 | [diff] [blame^] | 191 | // This test is flaky on all platforms; see http://crbug.com/340354 |
| 192 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed4) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 193 | 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 Nissler | d3cba30 | 2015-03-20 09:07:44 | [diff] [blame^] | 207 | // This test is flaky on all platforms; see http://crbug.com/340354 |
| 208 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed0) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 209 | 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 Nissler | d3cba30 | 2015-03-20 09:07:44 | [diff] [blame^] | 225 | // This test is flaky on all platforms; see http://crbug.com/340354 |
| 226 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed5) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 227 | 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 Nissler | d3cba30 | 2015-03-20 09:07:44 | [diff] [blame^] | 242 | // This test is flaky on all platforms; see http://crbug.com/340354 |
| 243 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_RSSParseFeedValidFeed6) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 244 | 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] | efe5ba2 | 2014-01-07 13:23:27 | [diff] [blame] | 259 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSParseFeedInvalidFeed1) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 260 | 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] | efe5ba2 | 2014-01-07 13:23:27 | [diff] [blame] | 275 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSParseFeedInvalidFeed2) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 276 | 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] | efe5ba2 | 2014-01-07 13:23:27 | [diff] [blame] | 291 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSParseFeedInvalidFeed3) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 292 | 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] | efe5ba2 | 2014-01-07 13:23:27 | [diff] [blame] | 307 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSParseFeedInvalidFeed4) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 308 | 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 Nissler | d3cba30 | 2015-03-20 09:07:44 | [diff] [blame^] | 330 | // This test is flaky on all platforms; see http://crbug.com/340354 |
| 331 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, |
| 332 | DISABLED_RSSParseFeedValidFeedNoLinks) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 333 | 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 | } |