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

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

Issue 12299013: Fix top-level context menus sorting by name (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: I have no excuse here... Created 7 years, 6 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
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_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_system.h" 9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/extensions/extension_test_message_listener.h" 10 #include "chrome/browser/extensions/extension_test_message_listener.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 public: 87 public:
88 // Helper to load an extension from context_menus/|subdirectory| in the 88 // Helper to load an extension from context_menus/|subdirectory| in the
89 // extensions test data dir. 89 // extensions test data dir.
90 const extensions::Extension* LoadContextMenuExtension( 90 const extensions::Extension* LoadContextMenuExtension(
91 std::string subdirectory) { 91 std::string subdirectory) {
92 base::FilePath extension_dir = 92 base::FilePath extension_dir =
93 test_data_dir_.AppendASCII("context_menus").AppendASCII(subdirectory); 93 test_data_dir_.AppendASCII("context_menus").AppendASCII(subdirectory);
94 return LoadExtension(extension_dir); 94 return LoadExtension(extension_dir);
95 } 95 }
96 96
97 // Helper to load an extension from context_menus/top_level/|subdirectory| in
98 // the extensions test data dir.
99 const extensions::Extension* LoadTopLevelContextMenuExtension(
100 std::string subdirectory) {
101 base::FilePath extension_dir =
102 test_data_dir_.AppendASCII("context_menus").AppendASCII("top_level");
103 extension_dir = extension_dir.AppendASCII(subdirectory);
104 return LoadExtension(extension_dir);
105 }
106
97 const extensions::Extension* LoadContextMenuExtensionIncognito( 107 const extensions::Extension* LoadContextMenuExtensionIncognito(
98 std::string subdirectory) { 108 std::string subdirectory) {
99 base::FilePath extension_dir = 109 base::FilePath extension_dir =
100 test_data_dir_.AppendASCII("context_menus").AppendASCII(subdirectory); 110 test_data_dir_.AppendASCII("context_menus").AppendASCII(subdirectory);
101 return LoadExtensionIncognito(extension_dir); 111 return LoadExtensionIncognito(extension_dir);
102 } 112 }
103 113
104 TestRenderViewContextMenu* CreateMenu(Browser* browser, 114 TestRenderViewContextMenu* CreateMenu(Browser* browser,
105 const GURL& page_url, 115 const GURL& page_url,
106 const GURL& link_url, 116 const GURL& link_url,
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // truncated. 334 // truncated.
325 GURL url("http://foo.com/"); 335 GURL url("http://foo.com/");
326 scoped_ptr<TestRenderViewContextMenu> menu( 336 scoped_ptr<TestRenderViewContextMenu> menu(
327 CreateMenu(browser(), url, GURL(), GURL())); 337 CreateMenu(browser(), url, GURL(), GURL()));
328 338
329 string16 label; 339 string16 label;
330 ASSERT_TRUE(GetItemLabel(menu.get(), item->id(), &label)); 340 ASSERT_TRUE(GetItemLabel(menu.get(), item->id(), &label));
331 ASSERT_TRUE(label.size() <= limit); 341 ASSERT_TRUE(label.size() <= limit);
332 } 342 }
333 343
344 // Checks that Context Menus are ordered alphabetically by their name when
345 // extensions have only one single Context Menu item and by the extension name
346 // when multiples Context Menu items are created.
347 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, TopLevel) {
348 // We expect to see the following items in the menu:
349 // An Extension with multiple Context Menus
350 // Context Menu #1
351 // Context Menu #2
352 // Context Menu #1 - Extension #2
353 // Context Menu #2 - Extension #3
354 // Context Menu #3 - Extension #1
355 // Ze Extension with multiple Context Menus
356 // Context Menu #1
357 // Context Menu #2
358
359 // Load extensions and wait until it's created a single menu item.
360 ExtensionTestMessageListener listener1("created item", false);
361 ASSERT_TRUE(LoadTopLevelContextMenuExtension("single1"));
362 ASSERT_TRUE(listener1.WaitUntilSatisfied());
363
364 ExtensionTestMessageListener listener2("created item", false);
365 ASSERT_TRUE(LoadTopLevelContextMenuExtension("single2"));
366 ASSERT_TRUE(listener2.WaitUntilSatisfied());
367
368 ExtensionTestMessageListener listener3("created item", false);
369 ASSERT_TRUE(LoadTopLevelContextMenuExtension("single3"));
370 ASSERT_TRUE(listener3.WaitUntilSatisfied());
371
372 // Load extensions and wait until it's created two menu items.
373 ExtensionTestMessageListener listener4("created items", false);
374 ASSERT_TRUE(LoadTopLevelContextMenuExtension("multi4"));
375 ASSERT_TRUE(listener4.WaitUntilSatisfied());
376
377 ExtensionTestMessageListener listener5("created items", false);
378 ASSERT_TRUE(LoadTopLevelContextMenuExtension("multi5"));
379 ASSERT_TRUE(listener5.WaitUntilSatisfied());
380
381 GURL url("http://foo.com/");
382 scoped_ptr<TestRenderViewContextMenu> menu(
383 CreateMenu(browser(), url, GURL(), GURL()));
384
385 int index = 0;
386 MenuModel* model = NULL;
387
388 ASSERT_TRUE(menu->GetMenuModelAndItemIndex(
389 IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST, &model, &index));
390 EXPECT_EQ(UTF8ToUTF16("An Extension with multiple Context Menus"),
391 model->GetLabelAt(index++));
392 EXPECT_EQ(UTF8ToUTF16("Context Menu #1 - Extension #2"),
393 model->GetLabelAt(index++));
394 EXPECT_EQ(UTF8ToUTF16("Context Menu #2 - Extension #3"),
395 model->GetLabelAt(index++));
396 EXPECT_EQ(UTF8ToUTF16("Context Menu #3 - Extension #1"),
397 model->GetLabelAt(index++));
398 EXPECT_EQ(UTF8ToUTF16("Ze Extension with multiple Context Menus"),
399 model->GetLabelAt(index++));
400 }
401
334 // Checks that in |menu|, the item at |index| has type |expected_type| and a 402 // Checks that in |menu|, the item at |index| has type |expected_type| and a
335 // label of |expected_label|. 403 // label of |expected_label|.
336 static void ExpectLabelAndType(const char* expected_label, 404 static void ExpectLabelAndType(const char* expected_label,
337 MenuModel::ItemType expected_type, 405 MenuModel::ItemType expected_type,
338 const MenuModel& menu, 406 const MenuModel& menu,
339 int index) { 407 int index) {
340 EXPECT_EQ(expected_type, menu.GetTypeAt(index)); 408 EXPECT_EQ(expected_type, menu.GetTypeAt(index));
341 EXPECT_EQ(UTF8ToUTF16(expected_label), menu.GetLabelAt(index)); 409 EXPECT_EQ(UTF8ToUTF16(expected_label), menu.GetLabelAt(index));
342 } 410 }
343 411
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); 648 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito"));
581 649
582 // Wait for the extension's processes to tell us they've created an item. 650 // Wait for the extension's processes to tell us they've created an item.
583 ASSERT_TRUE(created.WaitUntilSatisfied()); 651 ASSERT_TRUE(created.WaitUntilSatisfied());
584 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); 652 ASSERT_TRUE(created_incognito.WaitUntilSatisfied());
585 ASSERT_EQ(2u, GetItems().size()); 653 ASSERT_EQ(2u, GetItems().size());
586 654
587 browser()->profile()->DestroyOffTheRecordProfile(); 655 browser()->profile()->DestroyOffTheRecordProfile();
588 ASSERT_EQ(1u, GetItems().size()); 656 ASSERT_EQ(1u, GetItems().size());
589 } 657 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/context_menu_matcher.cc ('k') | chrome/browser/tab_contents/render_view_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698