| 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 "chrome/browser/extensions/extension_browsertest.h" | 5 #include "chrome/browser/extensions/extension_browsertest.h" |
| 6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/browser_tabstrip.h" | 7 #include "chrome/browser/ui/browser_tabstrip.h" |
| 8 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/test/browser_test_utils.h" | 12 #include "content/public/test/browser_test_utils.h" |
| 13 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
| 14 | 14 |
| 15 using content::WebContents; | 15 using content::WebContents; |
| 16 using extensions::Extension; | 16 using extensions::Extension; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const char kSubscribePage[] = "/subscribe.html"; | 20 const std::string kSubscribePage = "/subscribe.html"; |
| 21 const char kFeedPageMultiRel[] = "files/feeds/feed_multi_rel.html"; | 21 const std::string kFeedPageMultiRel = "files/feeds/feed_multi_rel.html"; |
| 22 const char kValidFeedNoLinks[] = "files/feeds/feed_nolinks.xml"; | 22 const std::string kValidFeedNoLinks = "files/feeds/feed_nolinks.xml"; |
| 23 const char kValidFeed0[] = "files/feeds/feed_script.xml"; | 23 const std::string kValidFeed0 = "files/feeds/feed_script.xml"; |
| 24 const char kValidFeed1[] = "files/feeds/feed1.xml"; | 24 const std::string kValidFeed1 = "files/feeds/feed1.xml"; |
| 25 const char kValidFeed2[] = "files/feeds/feed2.xml"; | 25 const std::string kValidFeed2 = "files/feeds/feed2.xml"; |
| 26 const char kValidFeed3[] = "files/feeds/feed3.xml"; | 26 const std::string kValidFeed3 = "files/feeds/feed3.xml"; |
| 27 const char kValidFeed4[] = "files/feeds/feed4.xml"; | 27 const std::string kValidFeed4 = "files/feeds/feed4.xml"; |
| 28 const char kValidFeed5[] = "files/feeds/feed5.xml"; | 28 const std::string kValidFeed5 = "files/feeds/feed5.xml"; |
| 29 const char kValidFeed6[] = "files/feeds/feed6.xml"; | 29 const std::string kValidFeed6 = "files/feeds/feed6.xml"; |
| 30 const char kInvalidFeed1[] = "files/feeds/feed_invalid1.xml"; | 30 const std::string kInvalidFeed1 = "files/feeds/feed_invalid1.xml"; |
| 31 const char kInvalidFeed2[] = "files/feeds/feed_invalid2.xml"; | 31 const std::string kInvalidFeed2 = "files/feeds/feed_invalid2.xml"; |
| 32 // We need a triple encoded string to prove that we are not decoding twice in | 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 | 33 // subscribe.js because one layer is also stripped off when subscribe.js passes |
| 34 // it to the XMLHttpRequest object. | 34 // it to the XMLHttpRequest object. |
| 35 const char kFeedTripleEncoded[] = "files/feeds/url%25255Fdecoding.html"; | 35 const std::string kFeedTripleEncoded = "files/feeds/url%25255Fdecoding.html"; |
| 36 | 36 |
| 37 static const char kScriptFeedTitle[] = | 37 static const wchar_t* jscript_feed_title = |
| 38 "window.domAutomationController.send(" | 38 L"window.domAutomationController.send(" |
| 39 " document.getElementById('title') ? " | 39 L" document.getElementById('title') ? " |
| 40 " document.getElementById('title').textContent : " | 40 L" document.getElementById('title').textContent : " |
| 41 " \"element 'title' not found\"" | 41 L" \"element 'title' not found\"" |
| 42 ");"; | 42 L");"; |
| 43 static const char kScriptAnchor[] = | 43 static const wchar_t* jscript_anchor = |
| 44 "window.domAutomationController.send(" | 44 L"window.domAutomationController.send(" |
| 45 " document.getElementById('anchor_0') ? " | 45 L" document.getElementById('anchor_0') ? " |
| 46 " document.getElementById('anchor_0').textContent : " | 46 L" document.getElementById('anchor_0').textContent : " |
| 47 " \"element 'anchor_0' not found\"" | 47 L" \"element 'anchor_0' not found\"" |
| 48 ");"; | 48 L");"; |
| 49 static const char kScriptDesc[] = | 49 static const wchar_t* jscript_desc = |
| 50 "window.domAutomationController.send(" | 50 L"window.domAutomationController.send(" |
| 51 " document.getElementById('desc_0') ? " | 51 L" document.getElementById('desc_0') ? " |
| 52 " document.getElementById('desc_0').textContent : " | 52 L" document.getElementById('desc_0').textContent : " |
| 53 " \"element 'desc_0' not found\"" | 53 L" \"element 'desc_0' not found\"" |
| 54 ");"; | 54 L");"; |
| 55 static const char kScriptError[] = | 55 static const wchar_t* jscript_error = |
| 56 "window.domAutomationController.send(" | 56 L"window.domAutomationController.send(" |
| 57 " document.getElementById('error') ? " | 57 L" document.getElementById('error') ? " |
| 58 " document.getElementById('error').textContent : " | 58 L" document.getElementById('error').textContent : " |
| 59 " \"No error\"" | 59 L" \"No error\"" |
| 60 ");"; | 60 L");"; |
| 61 | 61 |
| 62 GURL GetFeedUrl(net::TestServer* server, const std::string& feed_page, | 62 GURL GetFeedUrl(net::TestServer* server, const std::string& feed_page, |
| 63 bool direct_url, std::string extension_id) { | 63 bool direct_url, std::string extension_id) { |
| 64 GURL feed_url = server->GetURL(feed_page); | 64 GURL feed_url = server->GetURL(feed_page); |
| 65 if (direct_url) { | 65 if (direct_url) { |
| 66 // We navigate directly to the subscribe page for feeds where the feed | 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. | 67 // sniffing won't work, in other words, as is the case for malformed feeds. |
| 68 return GURL(std::string(extensions::kExtensionScheme) + | 68 return GURL(std::string(extensions::kExtensionScheme) + |
| 69 content::kStandardSchemeSeparator + | 69 content::kStandardSchemeSeparator + |
| 70 extension_id + std::string(kSubscribePage) + std::string("?") + | 70 extension_id + std::string(kSubscribePage) + std::string("?") + |
| 71 feed_url.spec() + std::string("&synchronous")); | 71 feed_url.spec() + std::string("&synchronous")); |
| 72 } else { | 72 } else { |
| 73 // Navigate to the feed content (which will cause the extension to try to | 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. | 74 // sniff the type and display the subscribe page in another tab. |
| 75 return GURL(feed_url.spec()); | 75 return GURL(feed_url.spec()); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool ValidatePageElement(WebContents* tab, | 79 bool ValidatePageElement(WebContents* tab, |
| 80 const std::string& frame, | 80 const std::wstring& frame, |
| 81 const std::string& javascript, | 81 const std::wstring& javascript, |
| 82 const std::string& expected_value) { | 82 const std::string& expected_value) { |
| 83 std::string returned_value; | 83 std::string returned_value; |
| 84 std::string error; | 84 std::string error; |
| 85 | 85 |
| 86 if (!content::ExecuteJavaScriptAndExtractString( | 86 if (!content::ExecuteJavaScriptAndExtractString( |
| 87 tab->GetRenderViewHost(), | 87 tab->GetRenderViewHost(), |
| 88 frame, | 88 frame, |
| 89 javascript, | 89 javascript, &returned_value)) |
| 90 &returned_value)) | |
| 91 return false; | 90 return false; |
| 92 | 91 |
| 93 EXPECT_STREQ(expected_value.c_str(), returned_value.c_str()); | 92 EXPECT_STREQ(expected_value.c_str(), returned_value.c_str()); |
| 94 return expected_value == returned_value; | 93 return expected_value == returned_value; |
| 95 } | 94 } |
| 96 | 95 |
| 97 // Navigates to a feed page and, if |sniff_xml_type| is set, wait for the | 96 // Navigates to a feed page and, if |sniff_xml_type| is set, wait for the |
| 98 // extension to kick in, detect the feed and redirect to a feed preview page. | 97 // extension to kick in, detect the feed and redirect to a feed preview page. |
| 99 // |sniff_xml_type| is generally set to true if the feed is sniffable and false | 98 // |sniff_xml_type| is generally set to true if the feed is sniffable and false |
| 100 // for invalid feeds. | 99 // for invalid feeds. |
| 101 void NavigateToFeedAndValidate(net::TestServer* server, | 100 void NavigateToFeedAndValidate(net::TestServer* server, |
| 102 const std::string& url, | 101 const std::string& url, |
| 103 Browser* browser, | 102 Browser* browser, |
| 104 std::string extension_id, | 103 std::string extension_id, |
| 105 bool sniff_xml_type, | 104 bool sniff_xml_type, |
| 106 const std::string& expected_feed_title, | 105 const std::string& expected_feed_title, |
| 107 const std::string& expected_item_title, | 106 const std::string& expected_item_title, |
| 108 const std::string& expected_item_desc, | 107 const std::string& expected_item_desc, |
| 109 const std::string& expected_error) { | 108 const std::string& expected_error) { |
| 110 if (sniff_xml_type) { | 109 if (sniff_xml_type) { |
| 111 // TODO(finnur): Implement this is a non-flaky way. | 110 // TODO(finnur): Implement this is a non-flaky way. |
| 112 } | 111 } |
| 113 | 112 |
| 114 // Navigate to the subscribe page directly. | 113 // Navigate to the subscribe page directly. |
| 115 ui_test_utils::NavigateToURL(browser, | 114 ui_test_utils::NavigateToURL(browser, |
| 116 GetFeedUrl(server, url, true, extension_id)); | 115 GetFeedUrl(server, url, true, extension_id)); |
| 117 | 116 |
| 118 WebContents* tab = chrome::GetActiveWebContents(browser); | 117 WebContents* tab = chrome::GetActiveWebContents(browser); |
| 119 ASSERT_TRUE(ValidatePageElement(tab, | 118 ASSERT_TRUE(ValidatePageElement(tab, |
| 120 "", | 119 L"", |
| 121 kScriptFeedTitle, | 120 jscript_feed_title, |
| 122 expected_feed_title)); | 121 expected_feed_title)); |
| 123 ASSERT_TRUE(ValidatePageElement(tab, | 122 ASSERT_TRUE(ValidatePageElement(tab, |
| 124 "//html/body/div/iframe[1]", | 123 L"//html/body/div/iframe[1]", |
| 125 kScriptAnchor, | 124 jscript_anchor, |
| 126 expected_item_title)); | 125 expected_item_title)); |
| 127 ASSERT_TRUE(ValidatePageElement(tab, | 126 ASSERT_TRUE(ValidatePageElement(tab, |
| 128 "//html/body/div/iframe[1]", | 127 L"//html/body/div/iframe[1]", |
| 129 kScriptDesc, | 128 jscript_desc, |
| 130 expected_item_desc)); | 129 expected_item_desc)); |
| 131 ASSERT_TRUE(ValidatePageElement(tab, | 130 ASSERT_TRUE(ValidatePageElement(tab, |
| 132 "//html/body/div/iframe[1]", | 131 L"//html/body/div/iframe[1]", |
| 133 kScriptError, | 132 jscript_error, |
| 134 expected_error)); | 133 expected_error)); |
| 135 } | 134 } |
| 136 | 135 |
| 137 } // namespace | 136 } // namespace |
| 138 | 137 |
| 139 // Makes sure that the RSS detects RSS feed links, even when rel tag contains | 138 // Makes sure that the RSS detects RSS feed links, even when rel tag contains |
| 140 // more than just "alternate". | 139 // more than just "alternate". |
| 141 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSMultiRelLink) { | 140 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSMultiRelLink) { |
| 142 ASSERT_TRUE(test_server()->Start()); | 141 ASSERT_TRUE(test_server()->Start()); |
| 143 | 142 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 std::string id = extension->id(); | 341 std::string id = extension->id(); |
| 343 | 342 |
| 344 // Valid feed but containing no links. | 343 // Valid feed but containing no links. |
| 345 NavigateToFeedAndValidate( | 344 NavigateToFeedAndValidate( |
| 346 test_server(), kValidFeedNoLinks, browser(), id, true, | 345 test_server(), kValidFeedNoLinks, browser(), id, true, |
| 347 "Feed for MyFeedTitle", | 346 "Feed for MyFeedTitle", |
| 348 "Title with no link", | 347 "Title with no link", |
| 349 "Desc", | 348 "Desc", |
| 350 "No error"); | 349 "No error"); |
| 351 } | 350 } |
| OLD | NEW |