Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/apps/web_view_browsertest.cc

Issue 186213003: <webview>: Context menu API implementation CL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/context_menus/context_menus_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
18 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
16 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/public/browser/gpu_data_manager.h" 22 #include "content/public/browser/gpu_data_manager.h"
20 #include "content/public/browser/interstitial_page.h" 23 #include "content/public/browser/interstitial_page.h"
21 #include "content/public/browser/interstitial_page_delegate.h" 24 #include "content/public/browser/interstitial_page_delegate.h"
22 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/render_process_host.h" 26 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/web_contents_delegate.h" 27 #include "content/public/browser/web_contents_delegate.h"
25 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
26 #include "content/public/test/browser_test_utils.h" 29 #include "content/public/test/browser_test_utils.h"
27 #include "content/public/test/fake_speech_recognition_manager.h" 30 #include "content/public/test/fake_speech_recognition_manager.h"
28 #include "extensions/common/extension.h" 31 #include "extensions/common/extension.h"
29 #include "extensions/common/extensions_client.h" 32 #include "extensions/common/extensions_client.h"
30 #include "net/test/embedded_test_server/embedded_test_server.h" 33 #include "net/test/embedded_test_server/embedded_test_server.h"
31 #include "net/test/embedded_test_server/http_request.h" 34 #include "net/test/embedded_test_server/http_request.h"
32 #include "net/test/embedded_test_server/http_response.h" 35 #include "net/test/embedded_test_server/http_response.h"
33 #include "ui/gl/gl_switches.h" 36 #include "ui/gl/gl_switches.h"
34 37
35 #if defined(OS_CHROMEOS) 38 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 39 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
37 #include "chrome/browser/chromeos/accessibility/speech_monitor.h" 40 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
38 #endif 41 #endif
39 42
40 // For fine-grained suppression on flaky tests. 43 // For fine-grained suppression on flaky tests.
41 #if defined(OS_WIN) 44 #if defined(OS_WIN)
42 #include "base/win/windows_version.h" 45 #include "base/win/windows_version.h"
43 #endif 46 #endif
44 47
48 using extensions::MenuItem;
45 using prerender::PrerenderLinkManager; 49 using prerender::PrerenderLinkManager;
46 using prerender::PrerenderLinkManagerFactory; 50 using prerender::PrerenderLinkManagerFactory;
51 using ui::MenuModel;
47 52
48 namespace { 53 namespace {
49 const char kEmptyResponsePath[] = "/close-socket"; 54 const char kEmptyResponsePath[] = "/close-socket";
50 const char kRedirectResponsePath[] = "/server-redirect"; 55 const char kRedirectResponsePath[] = "/server-redirect";
51 const char kRedirectResponseFullPath[] = 56 const char kRedirectResponseFullPath[] =
52 "/extensions/platform_apps/web_view/shim/guest_redirect.html"; 57 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
53 58
54 // Platform-specific filename relative to the chrome executable. 59 // Platform-specific filename relative to the chrome executable.
55 #if defined(OS_WIN) 60 #if defined(OS_WIN)
56 const wchar_t library_name[] = L"ppapi_tests.dll"; 61 const wchar_t library_name[] = L"ppapi_tests.dll";
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 const std::string& path, 484 const std::string& path,
480 const net::test_server::HttpRequest& request) { 485 const net::test_server::HttpRequest& request) {
481 if (StartsWithASCII(path, request.relative_url, true)) { 486 if (StartsWithASCII(path, request.relative_url, true)) {
482 return scoped_ptr<net::test_server::HttpResponse>( 487 return scoped_ptr<net::test_server::HttpResponse>(
483 new EmptyHttpResponse); 488 new EmptyHttpResponse);
484 } 489 }
485 490
486 return scoped_ptr<net::test_server::HttpResponse>(); 491 return scoped_ptr<net::test_server::HttpResponse>();
487 } 492 }
488 493
494 // Shortcut to return the current MenuManager.
495 extensions::MenuManager* menu_manager() {
496 return extensions::MenuManager::Get(browser()->profile());
497 }
498
499 // This gets all the items that any extension has registered for possible
500 // inclusion in context menus.
501 MenuItem::List GetItems() {
502 MenuItem::List result;
503 std::set<MenuItem::ExtensionKey> extension_ids =
504 menu_manager()->ExtensionIds();
505 std::set<MenuItem::ExtensionKey>::iterator i;
506 for (i = extension_ids.begin(); i != extension_ids.end(); ++i) {
507 const MenuItem::List* list = menu_manager()->MenuItems(*i);
508 result.insert(result.end(), list->begin(), list->end());
509 }
510 return result;
511 }
512
489 enum TestServer { 513 enum TestServer {
490 NEEDS_TEST_SERVER, 514 NEEDS_TEST_SERVER,
491 NO_TEST_SERVER 515 NO_TEST_SERVER
492 }; 516 };
493 517
494 void TestHelper(const std::string& test_name, 518 void TestHelper(const std::string& test_name,
495 const std::string& app_location, 519 const std::string& app_location,
496 TestServer test_server) { 520 TestServer test_server) {
497 // For serving guest pages. 521 // For serving guest pages.
498 if (test_server == NEEDS_TEST_SERVER) { 522 if (test_server == NEEDS_TEST_SERVER) {
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 EXPECT_TRUE( 1527 EXPECT_TRUE(
1504 content::ExecuteScript( 1528 content::ExecuteScript(
1505 embedder_web_contents, 1529 embedder_web_contents,
1506 base::StringPrintf("startAllowTest('%s')", 1530 base::StringPrintf("startAllowTest('%s')",
1507 test_name.c_str()))); 1531 test_name.c_str())));
1508 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); 1532 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
1509 1533
1510 mock->WaitForSetMediaPermission(); 1534 mock->WaitForSetMediaPermission();
1511 } 1535 }
1512 1536
1537 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_Basic) {
1538 GuestContentBrowserClient new_client;
1539 content::ContentBrowserClient* old_client =
1540 SetBrowserClientForTesting(&new_client);
1541
1542 ExtensionTestMessageListener launched_listener("Launched", false);
1543 launched_listener.AlsoListenForFailureMessage("TEST_FAILED");
1544 LoadAndLaunchPlatformApp("web_view/context_menus/basic");
1545 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
1546
1547 content::WebContents* guest_web_contents = new_client.WaitForGuestCreated();
1548 ASSERT_TRUE(guest_web_contents);
1549 SetBrowserClientForTesting(old_client);
1550
1551 content::WebContents* embedder = GetFirstAppWindowWebContents();
1552 ASSERT_TRUE(embedder);
1553
1554 // 1. Basic property test.
1555 ExecuteScriptWaitForTitle(embedder, "checkProperties()", "ITEM_CHECKED");
1556
1557 // 2. Create a menu item and wait for created callback to be called.
1558 ExecuteScriptWaitForTitle(embedder, "createMenuItem()", "ITEM_CREATED");
1559
1560 // 3. Click the created item, wait for the click handlers to fire from JS.
1561 ExtensionTestMessageListener click_listener("ITEM_CLICKED", false);
1562 GURL page_url("http://www.google.com");
1563 // Create and build our test context menu.
1564 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create(
1565 guest_web_contents, page_url, GURL(), GURL()));
1566
1567 // Look for the extension item in the menu, and execute it.
1568 int command_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST;
1569 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id));
1570 menu->ExecuteCommand(command_id, 0);
1571
1572 // Wait for embedder's script to tell us its onclick fired, it does
1573 // chrome.test.sendMessage('ITEM_CLICKED')
1574 ASSERT_TRUE(click_listener.WaitUntilSatisfied());
1575
1576 // 4. Update the item's title and verify.
1577 ExecuteScriptWaitForTitle(embedder, "updateMenuItem()", "ITEM_UPDATED");
1578 MenuItem::List items = GetItems();
1579 ASSERT_EQ(1u, items.size());
1580 MenuItem* item = items.at(0);
1581 EXPECT_EQ("new_title", item->title());
1582
1583 // 5. Remove the item.
1584 ExecuteScriptWaitForTitle(embedder, "removeItem()", "ITEM_REMOVED");
1585 MenuItem::List items_after_removal = GetItems();
1586 ASSERT_EQ(0u, items_after_removal.size());
1587
1588 // 6. Add some more items.
1589 ExecuteScriptWaitForTitle(
1590 embedder, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1591 MenuItem::List items_after_insertion = GetItems();
1592 ASSERT_EQ(3u, items_after_insertion.size());
1593
1594 // 7. Test removeAll().
1595 ExecuteScriptWaitForTitle(embedder, "removeAllItems()", "ITEM_ALL_REMOVED");
1596 MenuItem::List items_after_all_removal = GetItems();
1597 ASSERT_EQ(0u, items_after_all_removal.size());
1598 }
1599
1513 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) { 1600 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) {
1514 MediaAccessAPIAllowTestHelper("testAllow"); 1601 MediaAccessAPIAllowTestHelper("testAllow");
1515 } 1602 }
1516 1603
1517 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) { 1604 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) {
1518 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny"); 1605 MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
1519 } 1606 }
1520 1607
1521 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowTwice) { 1608 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowTwice) {
1522 MediaAccessAPIAllowTestHelper("testAllowTwice"); 1609 MediaAccessAPIAllowTestHelper("testAllowTwice");
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 INSTANTIATE_TEST_CASE_P(WithoutThreadedCompositor, 1979 INSTANTIATE_TEST_CASE_P(WithoutThreadedCompositor,
1893 WebViewCaptureTest, 1980 WebViewCaptureTest,
1894 ::testing::Values(std::string(switches::kDisableThreadedCompositing))); 1981 ::testing::Values(std::string(switches::kDisableThreadedCompositing)));
1895 #endif 1982 #endif
1896 1983
1897 #if defined(USE_AURA) || defined(OS_MACOSX) 1984 #if defined(USE_AURA) || defined(OS_MACOSX)
1898 INSTANTIATE_TEST_CASE_P(WithThreadedCompositor, 1985 INSTANTIATE_TEST_CASE_P(WithThreadedCompositor,
1899 WebViewCaptureTest, 1986 WebViewCaptureTest,
1900 ::testing::Values(std::string(switches::kEnableThreadedCompositing))); 1987 ::testing::Values(std::string(switches::kEnableThreadedCompositing)));
1901 #endif 1988 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/context_menus/context_menus_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698