OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/ref_counted.h" | 5 #include "base/ref_counted.h" |
6 #include "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
7 #include "chrome/browser/browser_list.h" | 7 #include "chrome/browser/browser_list.h" |
8 #include "chrome/browser/renderer_host/render_view_host.h" | 8 #include "chrome/browser/renderer_host/render_view_host.h" |
9 #include "chrome/browser/extensions/autoupdate_interceptor.h" | 9 #include "chrome/browser/extensions/autoupdate_interceptor.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/views/frame/browser_view.h" | 23 #include "chrome/browser/views/frame/browser_view.h" |
24 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/extensions/extension_error_reporter.h" | 25 #include "chrome/common/extensions/extension_error_reporter.h" |
26 #include "chrome/common/notification_service.h" | 26 #include "chrome/common/notification_service.h" |
27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
28 #include "chrome/test/ui_test_utils.h" | 28 #include "chrome/test/ui_test_utils.h" |
29 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
30 | 30 |
31 const std::wstring kSubscribePage = | 31 const std::wstring kSubscribePage = |
32 L"files/extensions/subscribe_page_action/subscribe.html"; | 32 L"files/extensions/subscribe_page_action/subscribe.html"; |
| 33 const std::wstring kFeedPage = L"files/feeds/feed.html"; |
| 34 const std::wstring kNoFeedPage = L"files/feeds/no_feed.html"; |
33 const std::wstring kValidFeed0 = L"files/feeds/feed_script.xml"; | 35 const std::wstring kValidFeed0 = L"files/feeds/feed_script.xml"; |
34 const std::wstring kValidFeed1 = L"files/feeds/feed1.xml"; | 36 const std::wstring kValidFeed1 = L"files/feeds/feed1.xml"; |
35 const std::wstring kValidFeed2 = L"files/feeds/feed2.xml"; | 37 const std::wstring kValidFeed2 = L"files/feeds/feed2.xml"; |
36 const std::wstring kValidFeed3 = L"files/feeds/feed3.xml"; | 38 const std::wstring kValidFeed3 = L"files/feeds/feed3.xml"; |
37 const std::wstring kValidFeed4 = L"files/feeds/feed4.xml"; | 39 const std::wstring kValidFeed4 = L"files/feeds/feed4.xml"; |
38 const std::wstring kValidFeed5 = L"files/feeds/feed5.xml"; | 40 const std::wstring kValidFeed5 = L"files/feeds/feed5.xml"; |
39 const std::wstring kInvalidFeed1 = L"files/feeds/feed_invalid1.xml"; | 41 const std::wstring kInvalidFeed1 = L"files/feeds/feed_invalid1.xml"; |
40 const std::wstring kInvalidFeed2 = L"files/feeds/feed_invalid2.xml"; | 42 const std::wstring kInvalidFeed2 = L"files/feeds/feed_invalid2.xml"; |
| 43 const std::wstring kLocalization = |
| 44 L"file/extensions/browsertest/title_localized_pa/simple.html"; |
| 45 const std::wstring kTestFile = L"file/extensions/test_file.html"; |
41 | 46 |
42 // Looks for an ExtensionHost whose URL has the given path component (including | 47 // Looks for an ExtensionHost whose URL has the given path component (including |
43 // leading slash). Also verifies that the expected number of hosts are loaded. | 48 // leading slash). Also verifies that the expected number of hosts are loaded. |
44 static ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager, | 49 static ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager, |
45 const std::string& path, | 50 const std::string& path, |
46 int expected_hosts) { | 51 int expected_hosts) { |
47 ExtensionHost* host = NULL; | 52 ExtensionHost* host = NULL; |
48 int num_hosts = 0; | 53 int num_hosts = 0; |
49 for (ExtensionProcessManager::const_iterator iter = manager->begin(); | 54 for (ExtensionProcessManager::const_iterator iter = manager->begin(); |
50 iter != manager->end(); ++iter) { | 55 iter != manager->end(); ++iter) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 result = false; | 206 result = false; |
202 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 207 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
203 browser()->GetSelectedTabContents()->render_view_host(), L"", | 208 browser()->GetSelectedTabContents()->render_view_host(), L"", |
204 L"testTabsAPI()", &result); | 209 L"testTabsAPI()", &result); |
205 EXPECT_TRUE(result); | 210 EXPECT_TRUE(result); |
206 } | 211 } |
207 | 212 |
208 #if defined(OS_WIN) || defined(OS_LINUX) | 213 #if defined(OS_WIN) || defined(OS_LINUX) |
209 // Tests that we can load page actions in the Omnibox. | 214 // Tests that we can load page actions in the Omnibox. |
210 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { | 215 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { |
| 216 HTTPTestServer* server = StartHTTPServer(); |
| 217 |
211 // This page action will not show an icon, since it doesn't specify one but | 218 // This page action will not show an icon, since it doesn't specify one but |
212 // is included here to test for a crash (http://crbug.com/25562). | 219 // is included here to test for a crash (http://crbug.com/25562). |
213 ASSERT_TRUE(LoadExtension( | 220 ASSERT_TRUE(LoadExtension( |
214 test_data_dir_.AppendASCII("browsertest") | 221 test_data_dir_.AppendASCII("browsertest") |
215 .AppendASCII("crash_25562"))); | 222 .AppendASCII("crash_25562"))); |
216 | 223 |
217 ASSERT_TRUE(LoadExtension( | 224 ASSERT_TRUE(LoadExtension( |
218 test_data_dir_.AppendASCII("subscribe_page_action"))); | 225 test_data_dir_.AppendASCII("subscribe_page_action"))); |
219 | 226 |
220 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); | 227 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); |
221 | 228 |
222 // Navigate to the feed page. | 229 // Navigate to the feed page. |
223 FilePath test_dir; | 230 GURL feed_url = server->TestServerPageW(kFeedPage); |
224 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); | 231 ui_test_utils::NavigateToURL(browser(), feed_url); |
225 FilePath feed = test_dir.AppendASCII("feeds") | |
226 .AppendASCII("feed.html"); | |
227 | |
228 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(feed)); | |
229 | |
230 // We should now have one page action ready to go in the LocationBar. | 232 // We should now have one page action ready to go in the LocationBar. |
231 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 233 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
232 | 234 |
233 FilePath no_feed = test_dir.AppendASCII("feeds") | 235 // Navigate to a page with no feed. |
234 .AppendASCII("nofeed.html"); | 236 GURL no_feed = server->TestServerPageW(kNoFeedPage); |
235 | 237 ui_test_utils::NavigateToURL(browser(), no_feed); |
236 // Make sure the page action goes away. | 238 // Make sure the page action goes away. |
237 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(no_feed)); | |
238 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); | 239 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); |
239 } | 240 } |
240 | 241 |
241 // Tests that the location bar forgets about unloaded page actions. | 242 // Tests that the location bar forgets about unloaded page actions. |
242 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { | 243 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { |
| 244 HTTPTestServer* server = StartHTTPServer(); |
| 245 |
243 FilePath extension_path(test_data_dir_.AppendASCII("subscribe_page_action")); | 246 FilePath extension_path(test_data_dir_.AppendASCII("subscribe_page_action")); |
244 ASSERT_TRUE(LoadExtension(extension_path)); | 247 ASSERT_TRUE(LoadExtension(extension_path)); |
245 | 248 |
246 // Navigation prompts the location bar to load page actions. | 249 // Navigation prompts the location bar to load page actions. |
247 FilePath test_dir; | 250 GURL feed_url = server->TestServerPageW(kFeedPage); |
248 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); | 251 ui_test_utils::NavigateToURL(browser(), feed_url); |
249 FilePath feed = test_dir.AppendASCII("feeds") | |
250 .AppendASCII("feed.html"); | |
251 | |
252 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(feed)); | |
253 ASSERT_TRUE(WaitForPageActionCountChangeTo(1)); | 252 ASSERT_TRUE(WaitForPageActionCountChangeTo(1)); |
254 | 253 |
255 UnloadExtension(last_loaded_extension_id_); | 254 UnloadExtension(last_loaded_extension_id_); |
256 | 255 |
257 // Make sure the page action goes away when it's unloaded. | 256 // Make sure the page action goes away when it's unloaded. |
258 ASSERT_TRUE(WaitForPageActionCountChangeTo(0)); | 257 ASSERT_TRUE(WaitForPageActionCountChangeTo(0)); |
259 } | 258 } |
260 | 259 |
261 // Tests that tooltips of a browser action icon can be specified using UTF8. | 260 // Tests that tooltips of a browser action icon can be specified using UTF8. |
262 // See http://crbug.com/25349. | 261 // See http://crbug.com/25349. |
(...skipping 12 matching lines...) Expand all Loading... |
275 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), | 274 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), |
276 extension->name().c_str()); | 275 extension->name().c_str()); |
277 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); | 276 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); |
278 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), | 277 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), |
279 extension->browser_action()->GetTitle(tab_id).c_str()); | 278 extension->browser_action()->GetTitle(tab_id).c_str()); |
280 } | 279 } |
281 | 280 |
282 // Tests that tooltips of a page action icon can be specified using UTF8. | 281 // Tests that tooltips of a page action icon can be specified using UTF8. |
283 // See http://crbug.com/25349. | 282 // See http://crbug.com/25349. |
284 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { | 283 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { |
| 284 HTTPTestServer* server = StartHTTPServer(); |
| 285 |
285 FilePath extension_path(test_data_dir_.AppendASCII("browsertest") | 286 FilePath extension_path(test_data_dir_.AppendASCII("browsertest") |
286 .AppendASCII("title_localized_pa")); | 287 .AppendASCII("title_localized_pa")); |
287 ASSERT_TRUE(LoadExtension(extension_path)); | 288 ASSERT_TRUE(LoadExtension(extension_path)); |
288 | 289 |
289 // Any navigation prompts the location bar to load the page action. | 290 // Any navigation prompts the location bar to load the page action. |
290 FilePath test_dir; | 291 GURL url = server->TestServerPageW(kLocalization); |
291 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); | 292 ui_test_utils::NavigateToURL(browser(), url); |
292 FilePath path = extension_path.AppendASCII("simple.html"); | |
293 | |
294 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(path)); | |
295 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 293 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
296 | 294 |
297 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 295 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
298 const ExtensionList* extensions = service->extensions(); | 296 const ExtensionList* extensions = service->extensions(); |
299 ASSERT_EQ(1u, extensions->size()); | 297 ASSERT_EQ(1u, extensions->size()); |
300 Extension* extension = extensions->at(0); | 298 Extension* extension = extensions->at(0); |
301 | 299 |
302 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), | 300 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), |
303 extension->description().c_str()); | 301 extension->description().c_str()); |
304 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), | 302 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 | 520 |
523 bool result = false; | 521 bool result = false; |
524 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 522 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
525 host->render_view_host(), L"", L"testLastError()", &result); | 523 host->render_view_host(), L"", L"testLastError()", &result); |
526 EXPECT_TRUE(result); | 524 EXPECT_TRUE(result); |
527 } | 525 } |
528 | 526 |
529 #if defined(OS_WIN) // TODO(port) - enable. | 527 #if defined(OS_WIN) // TODO(port) - enable. |
530 // Tests that message passing between extensions and content scripts works. | 528 // Tests that message passing between extensions and content scripts works. |
531 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MessagingContentScript) { | 529 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MessagingContentScript) { |
| 530 HTTPTestServer* server = StartHTTPServer(); |
| 531 |
532 ASSERT_TRUE(LoadExtension( | 532 ASSERT_TRUE(LoadExtension( |
533 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | 533 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
534 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") | 534 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") |
535 .AppendASCII("1.0"))); | 535 .AppendASCII("1.0"))); |
536 | 536 |
537 UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); | 537 UserScriptMaster* master = browser()->profile()->GetUserScriptMaster(); |
538 if (!master->ScriptsReady()) { | 538 if (!master->ScriptsReady()) { |
539 // Wait for UserScriptMaster to finish its scan. | 539 // Wait for UserScriptMaster to finish its scan. |
540 NotificationRegistrar registrar; | 540 NotificationRegistrar registrar; |
541 registrar.Add(this, NotificationType::USER_SCRIPTS_UPDATED, | 541 registrar.Add(this, NotificationType::USER_SCRIPTS_UPDATED, |
542 NotificationService::AllSources()); | 542 NotificationService::AllSources()); |
543 ui_test_utils::RunMessageLoop(); | 543 ui_test_utils::RunMessageLoop(); |
544 } | 544 } |
545 ASSERT_TRUE(master->ScriptsReady()); | 545 ASSERT_TRUE(master->ScriptsReady()); |
546 | 546 |
547 // Get the ExtensionHost that is hosting our toolstrip page. | 547 // Get the ExtensionHost that is hosting our toolstrip page. |
548 ExtensionProcessManager* manager = | 548 ExtensionProcessManager* manager = |
549 browser()->profile()->GetExtensionProcessManager(); | 549 browser()->profile()->GetExtensionProcessManager(); |
550 ExtensionHost* host = FindHostWithPath(manager, "/toolstrip.html", 1); | 550 ExtensionHost* host = FindHostWithPath(manager, "/toolstrip.html", 1); |
551 | 551 |
552 // Load the tab whose content script will communicate with our toolstrip. | 552 // Load the tab whose content script will communicate with our toolstrip. |
553 FilePath test_file; | 553 GURL url = server->TestServerPageW(kTestFile); |
554 PathService::Get(chrome::DIR_TEST_DATA, &test_file); | 554 ui_test_utils::NavigateToURL(browser(), url); |
555 test_file = test_file.AppendASCII("extensions") | |
556 .AppendASCII("test_file.html"); | |
557 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file)); | |
558 | 555 |
559 // Test extension->tab messaging. | 556 // Test extension->tab messaging. |
560 bool result = false; | 557 bool result = false; |
561 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 558 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
562 host->render_view_host(), L"", L"testPostMessage()", &result); | 559 host->render_view_host(), L"", L"testPostMessage()", &result); |
563 EXPECT_TRUE(result); | 560 EXPECT_TRUE(result); |
564 | 561 |
565 // Test port naming | 562 // Test port naming. |
566 result = false; | 563 result = false; |
567 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 564 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
568 host->render_view_host(), L"", L"testPortName()", &result); | 565 host->render_view_host(), L"", L"testPortName()", &result); |
569 EXPECT_TRUE(result); | 566 EXPECT_TRUE(result); |
570 | 567 |
571 // Test tab->extension messaging. | 568 // Test tab->extension messaging. |
572 result = false; | 569 result = false; |
573 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 570 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
574 host->render_view_host(), L"", L"testPostMessageFromTab()", &result); | 571 host->render_view_host(), L"", L"testPostMessageFromTab()", &result); |
575 EXPECT_TRUE(result); | 572 EXPECT_TRUE(result); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 | 869 |
873 // If the options page hasn't already come up, wait for it. | 870 // If the options page hasn't already come up, wait for it. |
874 if (tab_strip->count() == 1) { | 871 if (tab_strip->count() == 1) { |
875 ui_test_utils::WaitForNewTab(browser()); | 872 ui_test_utils::WaitForNewTab(browser()); |
876 } | 873 } |
877 ASSERT_EQ(2, tab_strip->count()); | 874 ASSERT_EQ(2, tab_strip->count()); |
878 | 875 |
879 EXPECT_EQ(extension->GetResourceURL("options.html"), | 876 EXPECT_EQ(extension->GetResourceURL("options.html"), |
880 tab_strip->GetTabContentsAt(1)->GetURL()); | 877 tab_strip->GetTabContentsAt(1)->GetURL()); |
881 } | 878 } |
OLD | NEW |