OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/ui/native_app_window.h" | 5 #include "apps/ui/native_app_window.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | |
9 #include "chrome/browser/apps/app_browsertest_util.h" | 10 #include "chrome/browser/apps/app_browsertest_util.h" |
10 #include "chrome/browser/automation/automation_util.h" | 11 #include "chrome/browser/automation/automation_util.h" |
11 #include "chrome/browser/chrome_content_browser_client.h" | 12 #include "chrome/browser/chrome_content_browser_client.h" |
12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 13 #include "chrome/browser/extensions/extension_test_message_listener.h" |
13 #include "chrome/browser/prerender/prerender_link_manager.h" | 14 #include "chrome/browser/prerender/prerender_link_manager.h" |
14 #include "chrome/browser/prerender/prerender_link_manager_factory.h" | 15 #include "chrome/browser/prerender/prerender_link_manager_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | |
16 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/gpu_data_manager.h" | 21 #include "content/public/browser/gpu_data_manager.h" |
20 #include "content/public/browser/interstitial_page.h" | 22 #include "content/public/browser/interstitial_page.h" |
21 #include "content/public/browser/interstitial_page_delegate.h" | 23 #include "content/public/browser/interstitial_page_delegate.h" |
22 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/web_contents_delegate.h" | 26 #include "content/public/browser/web_contents_delegate.h" |
25 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
26 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
27 #include "content/public/test/fake_speech_recognition_manager.h" | 29 #include "content/public/test/fake_speech_recognition_manager.h" |
28 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
29 #include "extensions/common/extensions_client.h" | 31 #include "extensions/common/extensions_client.h" |
30 #include "net/test/embedded_test_server/embedded_test_server.h" | 32 #include "net/test/embedded_test_server/embedded_test_server.h" |
31 #include "net/test/embedded_test_server/http_request.h" | 33 #include "net/test/embedded_test_server/http_request.h" |
32 #include "net/test/embedded_test_server/http_response.h" | 34 #include "net/test/embedded_test_server/http_response.h" |
33 #include "ui/gl/gl_switches.h" | 35 #include "ui/gl/gl_switches.h" |
34 | 36 |
35 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
36 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 38 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
37 #include "chrome/browser/chromeos/accessibility/speech_monitor.h" | 39 #include "chrome/browser/chromeos/accessibility/speech_monitor.h" |
38 #endif | 40 #endif |
39 | 41 |
40 // For fine-grained suppression on flaky tests. | 42 // For fine-grained suppression on flaky tests. |
41 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
42 #include "base/win/windows_version.h" | 44 #include "base/win/windows_version.h" |
43 #endif | 45 #endif |
44 | 46 |
47 using extensions::MenuItem; | |
45 using prerender::PrerenderLinkManager; | 48 using prerender::PrerenderLinkManager; |
46 using prerender::PrerenderLinkManagerFactory; | 49 using prerender::PrerenderLinkManagerFactory; |
50 using ui::MenuModel; | |
47 | 51 |
48 namespace { | 52 namespace { |
49 const char kEmptyResponsePath[] = "/close-socket"; | 53 const char kEmptyResponsePath[] = "/close-socket"; |
50 const char kRedirectResponsePath[] = "/server-redirect"; | 54 const char kRedirectResponsePath[] = "/server-redirect"; |
51 const char kRedirectResponseFullPath[] = | 55 const char kRedirectResponseFullPath[] = |
52 "/extensions/platform_apps/web_view/shim/guest_redirect.html"; | 56 "/extensions/platform_apps/web_view/shim/guest_redirect.html"; |
53 | 57 |
54 // Platform-specific filename relative to the chrome executable. | 58 // Platform-specific filename relative to the chrome executable. |
55 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
56 const wchar_t library_name[] = L"ppapi_tests.dll"; | 60 const wchar_t library_name[] = L"ppapi_tests.dll"; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 detach_callback_.Run(); | 129 detach_callback_.Run(); |
126 } | 130 } |
127 | 131 |
128 private: | 132 private: |
129 base::Closure attach_callback_; | 133 base::Closure attach_callback_; |
130 base::Closure detach_callback_; | 134 base::Closure detach_callback_; |
131 | 135 |
132 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); | 136 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); |
133 }; | 137 }; |
134 | 138 |
139 // This test class helps us sidestep platform-specific issues with popping up a | |
140 // real context menu, while still running through the actual code in | |
141 // RenderViewContextMenu where extension items get added and executed. | |
142 class TestRenderViewContextMenu : public RenderViewContextMenu { | |
Yoyo Zhou
2014/03/07 02:40:30
This looks duplicated from ExtensionContextMenuBro
lazyboy
2014/03/07 06:38:03
I've made WebViewTest (this) and ExtensionContextM
| |
143 public: | |
144 TestRenderViewContextMenu(content::RenderFrameHost* render_frame_host, | |
145 const content::ContextMenuParams& params) | |
146 : RenderViewContextMenu(render_frame_host, params) {} | |
147 | |
148 virtual ~TestRenderViewContextMenu() {} | |
149 | |
150 // Searches for an menu item with |command_id|. If it's found, the return | |
151 // value is true and the model and index where it appears in that model are | |
152 // returned in |found_model| and |found_index|. Otherwise returns false. | |
153 bool GetMenuModelAndItemIndex(int command_id, | |
154 MenuModel** found_model, | |
155 int *found_index) { | |
156 std::vector<MenuModel*> models_to_search; | |
157 models_to_search.push_back(&menu_model_); | |
158 | |
159 while (!models_to_search.empty()) { | |
160 MenuModel* model = models_to_search.back(); | |
161 models_to_search.pop_back(); | |
162 for (int i = 0; i < model->GetItemCount(); i++) { | |
163 if (model->GetCommandIdAt(i) == command_id) { | |
164 *found_model = model; | |
165 *found_index = i; | |
166 return true; | |
167 } else if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) { | |
168 models_to_search.push_back(model->GetSubmenuModelAt(i)); | |
169 } | |
170 } | |
171 } | |
172 | |
173 return false; | |
174 } | |
175 | |
176 extensions::ContextMenuMatcher& extension_items() { | |
177 return extension_items_; | |
178 } | |
179 | |
180 protected: | |
181 // These two functions implement pure virtual methods of | |
182 // RenderViewContextMenu. | |
183 virtual bool GetAcceleratorForCommandId( | |
184 int command_id, | |
185 ui::Accelerator* accelerator) OVERRIDE { | |
186 // None of our commands have accelerators, so always return false. | |
187 return false; | |
188 } | |
189 virtual void PlatformInit() OVERRIDE {} | |
190 virtual void PlatformCancel() OVERRIDE {} | |
191 }; | |
192 | |
135 } // namespace | 193 } // namespace |
136 | 194 |
137 // This class intercepts media access request from the embedder. The request | 195 // This class intercepts media access request from the embedder. The request |
138 // should be triggered only if the embedder API (from tests) allows the request | 196 // should be triggered only if the embedder API (from tests) allows the request |
139 // in Javascript. | 197 // in Javascript. |
140 // We do not issue the actual media request; the fact that the request reached | 198 // We do not issue the actual media request; the fact that the request reached |
141 // embedder's WebContents is good enough for our tests. This is also to make | 199 // embedder's WebContents is good enough for our tests. This is also to make |
142 // the test run successfully on trybots. | 200 // the test run successfully on trybots. |
143 class MockWebContentsDelegate : public content::WebContentsDelegate { | 201 class MockWebContentsDelegate : public content::WebContentsDelegate { |
144 public: | 202 public: |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 const std::string& path, | 537 const std::string& path, |
480 const net::test_server::HttpRequest& request) { | 538 const net::test_server::HttpRequest& request) { |
481 if (StartsWithASCII(path, request.relative_url, true)) { | 539 if (StartsWithASCII(path, request.relative_url, true)) { |
482 return scoped_ptr<net::test_server::HttpResponse>( | 540 return scoped_ptr<net::test_server::HttpResponse>( |
483 new EmptyHttpResponse); | 541 new EmptyHttpResponse); |
484 } | 542 } |
485 | 543 |
486 return scoped_ptr<net::test_server::HttpResponse>(); | 544 return scoped_ptr<net::test_server::HttpResponse>(); |
487 } | 545 } |
488 | 546 |
547 TestRenderViewContextMenu* CreateMenu(Browser* browser, | |
548 const GURL& page_url, | |
549 content::WebContents* web_contents) { | |
550 content::ContextMenuParams params; | |
551 params.page_url = page_url; | |
552 params.link_url = GURL(); | |
553 params.frame_url = GURL(); | |
554 TestRenderViewContextMenu* menu = | |
555 new TestRenderViewContextMenu(web_contents->GetMainFrame(), params); | |
556 printf("menu->Init()\n"); | |
557 menu->Init(); | |
558 return menu; | |
559 } | |
560 | |
561 // Shortcut to return the current MenuManager. | |
562 extensions::MenuManager* menu_manager() { | |
563 return extensions::MenuManager::Get(browser()->profile()); | |
564 } | |
565 | |
566 // This gets all the items that any extension has registered for possible | |
567 // inclusion in context menus. | |
568 MenuItem::List GetItems() { | |
569 MenuItem::List result; | |
570 std::set<MenuItem::ExtensionKey> extension_ids = | |
571 menu_manager()->ExtensionIds(); | |
572 std::set<MenuItem::ExtensionKey>::iterator i; | |
573 for (i = extension_ids.begin(); i != extension_ids.end(); ++i) { | |
574 const MenuItem::List* list = menu_manager()->MenuItems(*i); | |
575 result.insert(result.end(), list->begin(), list->end()); | |
576 } | |
577 return result; | |
578 } | |
579 | |
489 enum TestServer { | 580 enum TestServer { |
490 NEEDS_TEST_SERVER, | 581 NEEDS_TEST_SERVER, |
491 NO_TEST_SERVER | 582 NO_TEST_SERVER |
492 }; | 583 }; |
493 | 584 |
494 void TestHelper(const std::string& test_name, | 585 void TestHelper(const std::string& test_name, |
495 const std::string& app_location, | 586 const std::string& app_location, |
496 TestServer test_server) { | 587 TestServer test_server) { |
497 // For serving guest pages. | 588 // For serving guest pages. |
498 if (test_server == NEEDS_TEST_SERVER) { | 589 if (test_server == NEEDS_TEST_SERVER) { |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1503 EXPECT_TRUE( | 1594 EXPECT_TRUE( |
1504 content::ExecuteScript( | 1595 content::ExecuteScript( |
1505 embedder_web_contents, | 1596 embedder_web_contents, |
1506 base::StringPrintf("startAllowTest('%s')", | 1597 base::StringPrintf("startAllowTest('%s')", |
1507 test_name.c_str()))); | 1598 test_name.c_str()))); |
1508 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | 1599 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
1509 | 1600 |
1510 mock->WaitForSetMediaPermission(); | 1601 mock->WaitForSetMediaPermission(); |
1511 } | 1602 } |
1512 | 1603 |
1604 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_Basic) { | |
1605 GuestContentBrowserClient new_client; | |
1606 content::ContentBrowserClient* old_client = | |
1607 SetBrowserClientForTesting(&new_client); | |
1608 | |
1609 ExtensionTestMessageListener launched_listener("Launched", false); | |
1610 launched_listener.AlsoListenForFailureMessage("TEST_FAILED"); | |
1611 LoadAndLaunchPlatformApp("web_view/context_menus/basic"); | |
1612 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
1613 | |
1614 content::WebContents* guest_web_contents = new_client.WaitForGuestCreated(); | |
1615 ASSERT_TRUE(guest_web_contents); | |
1616 SetBrowserClientForTesting(old_client); | |
1617 | |
1618 content::WebContents* embedder = GetFirstAppWindowWebContents(); | |
1619 ASSERT_TRUE(embedder); | |
1620 | |
1621 // 1. Basic property test. | |
1622 ExecuteScriptWaitForTitle(embedder, "checkProperties()", "ITEM_CHECKED"); | |
1623 | |
1624 // 2. Create a menu item and wait for created callback to be called. | |
1625 ExecuteScriptWaitForTitle(embedder, "createMenuItem()", "ITEM_CREATED"); | |
1626 | |
1627 // 3. Click the created item, wait for the click handlers to fire from JS. | |
1628 ExtensionTestMessageListener click_listener("ITEM_CLICKED", false); | |
1629 GURL page_url("http://www.google.com"); | |
1630 // Create and build our test context menu. | |
1631 scoped_ptr<TestRenderViewContextMenu> menu( | |
1632 CreateMenu(browser(), page_url, guest_web_contents)); | |
1633 // Look for the extension item in the menu, and execute it. | |
1634 int command_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; | |
1635 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); | |
1636 menu->ExecuteCommand(command_id, 0); | |
1637 | |
1638 // Wait for embedder's script to tell us its onclick fired, it does | |
1639 // chrome.test.sendMessage('ITEM_CLICKED') | |
1640 ASSERT_TRUE(click_listener.WaitUntilSatisfied()); | |
1641 | |
1642 // 4. Update the item's title and verify. | |
1643 ExecuteScriptWaitForTitle(embedder, "updateMenuItem()", "ITEM_UPDATED"); | |
1644 MenuItem::List items = GetItems(); | |
1645 ASSERT_EQ(1u, items.size()); | |
1646 MenuItem* item = items.at(0); | |
1647 EXPECT_EQ("new_title", item->title()); | |
1648 | |
1649 // 5. Remove the item. | |
1650 ExecuteScriptWaitForTitle(embedder, "removeItem()", "ITEM_REMOVED"); | |
1651 MenuItem::List items_after_removal = GetItems(); | |
1652 ASSERT_EQ(0u, items_after_removal.size()); | |
1653 | |
1654 // 6. Add some more items. | |
1655 ExecuteScriptWaitForTitle(embedder, "createThreeMenuItems()", | |
1656 "ITEM_MULTIPLE_CREATED"); | |
1657 MenuItem::List items_after_insertion = GetItems(); | |
1658 ASSERT_EQ(3u, items_after_insertion.size()); | |
1659 | |
1660 // 7. Test removeAll(). | |
1661 ExecuteScriptWaitForTitle(embedder, "removeAllItems()", "ITEM_ALL_REMOVED"); | |
1662 MenuItem::List items_after_all_removal = GetItems(); | |
1663 ASSERT_EQ(0u, items_after_all_removal.size()); | |
1664 } | |
1665 | |
1513 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) { | 1666 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) { |
1514 MediaAccessAPIAllowTestHelper("testAllow"); | 1667 MediaAccessAPIAllowTestHelper("testAllow"); |
1515 } | 1668 } |
1516 | 1669 |
1517 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) { | 1670 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) { |
1518 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny"); | 1671 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny"); |
1519 } | 1672 } |
1520 | 1673 |
1521 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowTwice) { | 1674 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowTwice) { |
1522 MediaAccessAPIAllowTestHelper("testAllowTwice"); | 1675 MediaAccessAPIAllowTestHelper("testAllowTwice"); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1885 } | 2038 } |
1886 | 2039 |
1887 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI) { | 2040 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI) { |
1888 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER); | 2041 TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER); |
1889 } | 2042 } |
1890 | 2043 |
1891 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) { | 2044 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) { |
1892 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER); | 2045 TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER); |
1893 } | 2046 } |
1894 | 2047 |
2048 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusClick) { | |
2049 ASSERT_TRUE(RunPlatformAppTestWithArg( | |
2050 "platform_apps/web_view/common", "context_menus_click")) << message_; | |
2051 } | |
2052 | |
1895 // <webview> screenshot capture fails with ubercomp. | 2053 // <webview> screenshot capture fails with ubercomp. |
1896 // See http://crbug.com/327035. | 2054 // See http://crbug.com/327035. |
1897 IN_PROC_BROWSER_TEST_P(WebViewCaptureTest, | 2055 IN_PROC_BROWSER_TEST_P(WebViewCaptureTest, |
1898 DISABLED_Shim_ScreenshotCapture) { | 2056 DISABLED_Shim_ScreenshotCapture) { |
1899 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER); | 2057 TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER); |
1900 } | 2058 } |
1901 | 2059 |
2060 | |
Yoyo Zhou
2014/03/07 02:40:30
nit: stray newline
lazyboy
2014/03/07 06:38:03
Done.
| |
1902 // Threaded compositing is always enabled on Aura and Mac. | 2061 // Threaded compositing is always enabled on Aura and Mac. |
1903 #if !defined(USE_AURA) && !defined(OS_MACOSX) | 2062 #if !defined(USE_AURA) && !defined(OS_MACOSX) |
1904 INSTANTIATE_TEST_CASE_P(WithoutThreadedCompositor, | 2063 INSTANTIATE_TEST_CASE_P(WithoutThreadedCompositor, |
1905 WebViewCaptureTest, | 2064 WebViewCaptureTest, |
1906 ::testing::Values(std::string(switches::kDisableThreadedCompositing))); | 2065 ::testing::Values(std::string(switches::kDisableThreadedCompositing))); |
1907 #endif | 2066 #endif |
1908 | 2067 |
1909 #if defined(USE_AURA) || defined(OS_MACOSX) | 2068 #if defined(USE_AURA) || defined(OS_MACOSX) |
1910 INSTANTIATE_TEST_CASE_P(WithThreadedCompositor, | 2069 INSTANTIATE_TEST_CASE_P(WithThreadedCompositor, |
1911 WebViewCaptureTest, | 2070 WebViewCaptureTest, |
1912 ::testing::Values(std::string(switches::kEnableThreadedCompositing))); | 2071 ::testing::Values(std::string(switches::kEnableThreadedCompositing))); |
1913 #endif | 2072 #endif |
OLD | NEW |