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 std::string kSubscribePage = "/subscribe.html"; | 20 const char kSubscribePage[] = "/subscribe.html"; |
21 const std::string kFeedPageMultiRel = "files/feeds/feed_multi_rel.html"; | 21 const char kFeedPageMultiRel[] = "files/feeds/feed_multi_rel.html"; |
22 const std::string kValidFeedNoLinks = "files/feeds/feed_nolinks.xml"; | 22 const char kValidFeedNoLinks[] = "files/feeds/feed_nolinks.xml"; |
23 const std::string kValidFeed0 = "files/feeds/feed_script.xml"; | 23 const char kValidFeed0[] = "files/feeds/feed_script.xml"; |
24 const std::string kValidFeed1 = "files/feeds/feed1.xml"; | 24 const char kValidFeed1[] = "files/feeds/feed1.xml"; |
25 const std::string kValidFeed2 = "files/feeds/feed2.xml"; | 25 const char kValidFeed2[] = "files/feeds/feed2.xml"; |
26 const std::string kValidFeed3 = "files/feeds/feed3.xml"; | 26 const char kValidFeed3[] = "files/feeds/feed3.xml"; |
27 const std::string kValidFeed4 = "files/feeds/feed4.xml"; | 27 const char kValidFeed4[] = "files/feeds/feed4.xml"; |
28 const std::string kValidFeed5 = "files/feeds/feed5.xml"; | 28 const char kValidFeed5[] = "files/feeds/feed5.xml"; |
29 const std::string kValidFeed6 = "files/feeds/feed6.xml"; | 29 const char kValidFeed6[] = "files/feeds/feed6.xml"; |
30 const std::string kInvalidFeed1 = "files/feeds/feed_invalid1.xml"; | 30 const char kInvalidFeed1[] = "files/feeds/feed_invalid1.xml"; |
31 const std::string kInvalidFeed2 = "files/feeds/feed_invalid2.xml"; | 31 const char 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 std::string kFeedTripleEncoded = "files/feeds/url%25255Fdecoding.html"; | 35 const char kFeedTripleEncoded[] = "files/feeds/url%25255Fdecoding.html"; |
36 | 36 |
37 static const wchar_t* jscript_feed_title = | 37 static const char kScriptFeedTitle[] = |
38 L"window.domAutomationController.send(" | 38 "window.domAutomationController.send(" |
39 L" document.getElementById('title') ? " | 39 " document.getElementById('title') ? " |
40 L" document.getElementById('title').textContent : " | 40 " document.getElementById('title').textContent : " |
41 L" \"element 'title' not found\"" | 41 " \"element 'title' not found\"" |
42 L");"; | 42 ");"; |
43 static const wchar_t* jscript_anchor = | 43 static const char kScriptAnchor[] = |
44 L"window.domAutomationController.send(" | 44 "window.domAutomationController.send(" |
45 L" document.getElementById('anchor_0') ? " | 45 " document.getElementById('anchor_0') ? " |
46 L" document.getElementById('anchor_0').textContent : " | 46 " document.getElementById('anchor_0').textContent : " |
47 L" \"element 'anchor_0' not found\"" | 47 " \"element 'anchor_0' not found\"" |
48 L");"; | 48 ");"; |
49 static const wchar_t* jscript_desc = | 49 static const char kScriptDesc[] = |
50 L"window.domAutomationController.send(" | 50 "window.domAutomationController.send(" |
51 L" document.getElementById('desc_0') ? " | 51 " document.getElementById('desc_0') ? " |
52 L" document.getElementById('desc_0').textContent : " | 52 " document.getElementById('desc_0').textContent : " |
53 L" \"element 'desc_0' not found\"" | 53 " \"element 'desc_0' not found\"" |
54 L");"; | 54 ");"; |
55 static const wchar_t* jscript_error = | 55 static const char kScriptError[] = |
56 L"window.domAutomationController.send(" | 56 "window.domAutomationController.send(" |
57 L" document.getElementById('error') ? " | 57 " document.getElementById('error') ? " |
58 L" document.getElementById('error').textContent : " | 58 " document.getElementById('error').textContent : " |
59 L" \"No error\"" | 59 " \"No error\"" |
60 L");"; | 60 ");"; |
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::wstring& frame, | 80 const std::string& frame, |
81 const std::wstring& javascript, | 81 const std::string& 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, &returned_value)) | 89 javascript, |
| 90 &returned_value)) |
90 return false; | 91 return false; |
91 | 92 |
92 EXPECT_STREQ(expected_value.c_str(), returned_value.c_str()); | 93 EXPECT_STREQ(expected_value.c_str(), returned_value.c_str()); |
93 return expected_value == returned_value; | 94 return expected_value == returned_value; |
94 } | 95 } |
95 | 96 |
96 // Navigates to a feed page and, if |sniff_xml_type| is set, wait for the | 97 // Navigates to a feed page and, if |sniff_xml_type| is set, wait for the |
97 // extension to kick in, detect the feed and redirect to a feed preview page. | 98 // extension to kick in, detect the feed and redirect to a feed preview page. |
98 // |sniff_xml_type| is generally set to true if the feed is sniffable and false | 99 // |sniff_xml_type| is generally set to true if the feed is sniffable and false |
99 // for invalid feeds. | 100 // for invalid feeds. |
100 void NavigateToFeedAndValidate(net::TestServer* server, | 101 void NavigateToFeedAndValidate(net::TestServer* server, |
101 const std::string& url, | 102 const std::string& url, |
102 Browser* browser, | 103 Browser* browser, |
103 std::string extension_id, | 104 std::string extension_id, |
104 bool sniff_xml_type, | 105 bool sniff_xml_type, |
105 const std::string& expected_feed_title, | 106 const std::string& expected_feed_title, |
106 const std::string& expected_item_title, | 107 const std::string& expected_item_title, |
107 const std::string& expected_item_desc, | 108 const std::string& expected_item_desc, |
108 const std::string& expected_error) { | 109 const std::string& expected_error) { |
109 if (sniff_xml_type) { | 110 if (sniff_xml_type) { |
110 // TODO(finnur): Implement this is a non-flaky way. | 111 // TODO(finnur): Implement this is a non-flaky way. |
111 } | 112 } |
112 | 113 |
113 // Navigate to the subscribe page directly. | 114 // Navigate to the subscribe page directly. |
114 ui_test_utils::NavigateToURL(browser, | 115 ui_test_utils::NavigateToURL(browser, |
115 GetFeedUrl(server, url, true, extension_id)); | 116 GetFeedUrl(server, url, true, extension_id)); |
116 | 117 |
117 WebContents* tab = chrome::GetActiveWebContents(browser); | 118 WebContents* tab = chrome::GetActiveWebContents(browser); |
118 ASSERT_TRUE(ValidatePageElement(tab, | 119 ASSERT_TRUE(ValidatePageElement(tab, |
119 L"", | 120 "", |
120 jscript_feed_title, | 121 kScriptFeedTitle, |
121 expected_feed_title)); | 122 expected_feed_title)); |
122 ASSERT_TRUE(ValidatePageElement(tab, | 123 ASSERT_TRUE(ValidatePageElement(tab, |
123 L"//html/body/div/iframe[1]", | 124 "//html/body/div/iframe[1]", |
124 jscript_anchor, | 125 kScriptAnchor, |
125 expected_item_title)); | 126 expected_item_title)); |
126 ASSERT_TRUE(ValidatePageElement(tab, | 127 ASSERT_TRUE(ValidatePageElement(tab, |
127 L"//html/body/div/iframe[1]", | 128 "//html/body/div/iframe[1]", |
128 jscript_desc, | 129 kScriptDesc, |
129 expected_item_desc)); | 130 expected_item_desc)); |
130 ASSERT_TRUE(ValidatePageElement(tab, | 131 ASSERT_TRUE(ValidatePageElement(tab, |
131 L"//html/body/div/iframe[1]", | 132 "//html/body/div/iframe[1]", |
132 jscript_error, | 133 kScriptError, |
133 expected_error)); | 134 expected_error)); |
134 } | 135 } |
135 | 136 |
136 } // namespace | 137 } // namespace |
137 | 138 |
138 // Makes sure that the RSS detects RSS feed links, even when rel tag contains | 139 // Makes sure that the RSS detects RSS feed links, even when rel tag contains |
139 // more than just "alternate". | 140 // more than just "alternate". |
140 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSMultiRelLink) { | 141 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, RSSMultiRelLink) { |
141 ASSERT_TRUE(test_server()->Start()); | 142 ASSERT_TRUE(test_server()->Start()); |
142 | 143 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 std::string id = extension->id(); | 342 std::string id = extension->id(); |
342 | 343 |
343 // Valid feed but containing no links. | 344 // Valid feed but containing no links. |
344 NavigateToFeedAndValidate( | 345 NavigateToFeedAndValidate( |
345 test_server(), kValidFeedNoLinks, browser(), id, true, | 346 test_server(), kValidFeedNoLinks, browser(), id, true, |
346 "Feed for MyFeedTitle", | 347 "Feed for MyFeedTitle", |
347 "Title with no link", | 348 "Title with no link", |
348 "Desc", | 349 "Desc", |
349 "No error"); | 350 "No error"); |
350 } | 351 } |
OLD | NEW |