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

Side by Side Diff: chrome/browser/extensions/extension_context_menu_browsertest.cc

Issue 10918103: Give platform apps control over launcher right-click context menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
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 "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/app/chrome_command_ids.h" 6 #include "chrome/app/chrome_command_ids.h"
7 #include "chrome/browser/extensions/extension_browsertest.h" 7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/extensions/extension_context_menu_model.h" 8 #include "chrome/browser/extensions/extension_context_menu_model.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
(...skipping 24 matching lines...) Expand all
35 public: 35 public:
36 TestRenderViewContextMenu(WebContents* web_contents, 36 TestRenderViewContextMenu(WebContents* web_contents,
37 const content::ContextMenuParams& params) 37 const content::ContextMenuParams& params)
38 : RenderViewContextMenu(web_contents, params) {} 38 : RenderViewContextMenu(web_contents, params) {}
39 39
40 virtual ~TestRenderViewContextMenu() {} 40 virtual ~TestRenderViewContextMenu() {}
41 41
42 bool HasExtensionItemWithLabel(const std::string& label) { 42 bool HasExtensionItemWithLabel(const std::string& label) {
43 string16 label16 = UTF8ToUTF16(label); 43 string16 label16 = UTF8ToUTF16(label);
44 std::map<int, MenuItem::Id>::iterator i; 44 std::map<int, MenuItem::Id>::iterator i;
45 for (i = extension_item_map_.begin(); i != extension_item_map_.end(); ++i) { 45 for (i = menu_manager_.map_begin(); i != menu_manager_.map_end(); ++i) {
46 const MenuItem::Id& id = i->second; 46 const MenuItem::Id& id = i->second;
47 string16 tmp_label; 47 string16 tmp_label;
48 EXPECT_TRUE(GetItemLabel(id, &tmp_label)); 48 EXPECT_TRUE(GetItemLabel(id, &tmp_label));
49 if (tmp_label == label16) 49 if (tmp_label == label16)
50 return true; 50 return true;
51 } 51 }
52 return false; 52 return false;
53 } 53 }
54 54
55 // Looks in the menu for an extension item with |id|, and if it is found and 55 // Looks in the menu for an extension item with |id|, and if it is found and
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 } 93 }
94 94
95 return false; 95 return false;
96 } 96 }
97 97
98 // Given an extension menu item id, tries to find the corresponding command id 98 // Given an extension menu item id, tries to find the corresponding command id
99 // in the menu. 99 // in the menu.
100 bool FindCommandId(const MenuItem::Id& id, int* command_id) { 100 bool FindCommandId(const MenuItem::Id& id, int* command_id) {
101 std::map<int, MenuItem::Id>::const_iterator i; 101 std::map<int, MenuItem::Id>::const_iterator i;
102 for (i = extension_item_map_.begin(); i != extension_item_map_.end(); ++i) { 102 for (i = menu_manager_.map_begin(); i != menu_manager_.map_end(); ++i) {
103 if (i->second == id) { 103 if (i->second == id) {
104 *command_id = i->first; 104 *command_id = i->first;
105 return true; 105 return true;
106 } 106 }
107 } 107 }
108 return false; 108 return false;
109 } 109 }
110 110
111 protected: 111 protected:
112 // These two functions implement pure virtual methods of 112 // These two functions implement pure virtual methods of
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Tests registering an item with a very long title that should get truncated in 295 // Tests registering an item with a very long title that should get truncated in
296 // the actual menu displayed. 296 // the actual menu displayed.
297 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, LongTitle) { 297 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, LongTitle) {
298 ExtensionTestMessageListener listener("created", false); 298 ExtensionTestMessageListener listener("created", false);
299 299
300 // Load the extension and wait until it's created a menu item. 300 // Load the extension and wait until it's created a menu item.
301 ASSERT_TRUE(LoadContextMenuExtension("long_title")); 301 ASSERT_TRUE(LoadContextMenuExtension("long_title"));
302 ASSERT_TRUE(listener.WaitUntilSatisfied()); 302 ASSERT_TRUE(listener.WaitUntilSatisfied());
303 303
304 // Make sure we have an item registered with a long title. 304 // Make sure we have an item registered with a long title.
305 size_t limit = RenderViewContextMenu::kMaxExtensionItemTitleLength; 305 size_t limit = extensions::ContextMenuManager::kMaxExtensionItemTitleLength;
306 MenuItem::List items = GetItems(); 306 MenuItem::List items = GetItems();
307 ASSERT_EQ(1u, items.size()); 307 ASSERT_EQ(1u, items.size());
308 MenuItem* item = items.at(0); 308 MenuItem* item = items.at(0);
309 ASSERT_GT(item->title().size(), limit); 309 ASSERT_GT(item->title().size(), limit);
310 310
311 // Create a context menu, then find the item's label. It should be properly 311 // Create a context menu, then find the item's label. It should be properly
312 // truncated. 312 // truncated.
313 GURL url("http://foo.com/"); 313 GURL url("http://foo.com/");
314 scoped_ptr<TestRenderViewContextMenu> menu( 314 scoped_ptr<TestRenderViewContextMenu> menu(
315 CreateMenu(browser(), url, GURL(), GURL())); 315 CreateMenu(browser(), url, GURL(), GURL()));
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 EXPECT_FALSE(menu->IsCommandIdChecked(command_id)); 584 EXPECT_FALSE(menu->IsCommandIdChecked(command_id));
585 585
586 // Executing the checkbox also fires the onClicked event. 586 // Executing the checkbox also fires the onClicked event.
587 ExtensionTestMessageListener listener("onClicked fired for checkbox1", false); 587 ExtensionTestMessageListener listener("onClicked fired for checkbox1", false);
588 menu->ExecuteCommand(command_id); 588 menu->ExecuteCommand(command_id);
589 checkbox_checked.WaitUntilClosed(); 589 checkbox_checked.WaitUntilClosed();
590 590
591 EXPECT_TRUE(menu->IsCommandIdChecked(command_id)); 591 EXPECT_TRUE(menu->IsCommandIdChecked(command_id));
592 ASSERT_TRUE(listener.WaitUntilSatisfied()); 592 ASSERT_TRUE(listener.WaitUntilSatisfied());
593 } 593 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698