OLD | NEW |
---|---|
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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 // truncated. | 324 // truncated. |
325 GURL url("http://foo.com/"); | 325 GURL url("http://foo.com/"); |
326 scoped_ptr<TestRenderViewContextMenu> menu( | 326 scoped_ptr<TestRenderViewContextMenu> menu( |
327 CreateMenu(browser(), url, GURL(), GURL())); | 327 CreateMenu(browser(), url, GURL(), GURL())); |
328 | 328 |
329 string16 label; | 329 string16 label; |
330 ASSERT_TRUE(GetItemLabel(menu.get(), item->id(), &label)); | 330 ASSERT_TRUE(GetItemLabel(menu.get(), item->id(), &label)); |
331 ASSERT_TRUE(label.size() <= limit); | 331 ASSERT_TRUE(label.size() <= limit); |
332 } | 332 } |
333 | 333 |
334 // Checks that Context Menus are ordered alphabetically by their name when | |
335 // extensions have only one single Context Menu item and by the extension name | |
336 // when multiples Context Menu items are created. | |
337 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, TopLevel) { | |
338 // We expect to see the following items in the menu: | |
Yoyo Zhou
2013/03/20 21:54:13
nit: This would be clearer with 2-space indenting.
François Beaufort
2013/05/07 15:51:53
Done.
| |
339 // An Extension with multiple Context Menus | |
340 // Context Menu #1 | |
341 // Context Menu #2 | |
342 // Context Menu #1 - Extension #2 | |
343 // Context Menu #2 - Extension #3 | |
344 // Context Menu #3 - Extension #1 | |
345 // Ze Extension with multiple Context Menus | |
346 // Context Menu #1 | |
347 // Context Menu #2 | |
348 | |
349 // Load extensions and wait until it's created a single menu item. | |
350 ExtensionTestMessageListener listener1("created item", false); | |
351 ASSERT_TRUE(LoadContextMenuExtension("top_level_single1")); | |
Yoyo Zhou
2013/03/20 21:54:13
You can write another helper function like LoadCon
François Beaufort
2013/05/07 15:51:53
Done.
| |
352 ASSERT_TRUE(listener1.WaitUntilSatisfied()); | |
353 | |
354 ExtensionTestMessageListener listener2("created item", false); | |
355 ASSERT_TRUE(LoadContextMenuExtension("top_level_single2")); | |
356 ASSERT_TRUE(listener2.WaitUntilSatisfied()); | |
357 | |
358 ExtensionTestMessageListener listener3("created item", false); | |
359 ASSERT_TRUE(LoadContextMenuExtension("top_level_single3")); | |
360 ASSERT_TRUE(listener3.WaitUntilSatisfied()); | |
361 | |
362 // Load extensions and wait until it's created two menu items. | |
363 ExtensionTestMessageListener listener4("created items", false); | |
364 ASSERT_TRUE(LoadContextMenuExtension("top_level_multi4")); | |
365 ASSERT_TRUE(listener4.WaitUntilSatisfied()); | |
366 | |
367 ExtensionTestMessageListener listener5("created items", false); | |
368 ASSERT_TRUE(LoadContextMenuExtension("top_level_multi5")); | |
369 ASSERT_TRUE(listener5.WaitUntilSatisfied()); | |
370 | |
371 GURL url("http://foo.com/"); | |
372 scoped_ptr<TestRenderViewContextMenu> menu( | |
373 CreateMenu(browser(), url, GURL(), GURL())); | |
374 | |
375 int index = 0; | |
376 MenuModel* model = NULL; | |
377 | |
378 ASSERT_TRUE(menu->GetMenuModelAndItemIndex( | |
379 IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST, &model, &index)); | |
380 EXPECT_EQ(UTF8ToUTF16("An Extension with multiple Context Menus"), | |
381 model->GetLabelAt(index)); | |
Yoyo Zhou
2013/03/20 21:54:13
You should just be able to use
model = menu->menu_
François Beaufort
2013/05/07 15:51:53
model->GetLabelAt(0) actually returns &Back and so
| |
382 | |
383 ASSERT_TRUE(menu->GetMenuModelAndItemIndex( | |
384 IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 3, &model, &index)); | |
385 EXPECT_EQ(UTF8ToUTF16("Context Menu #1 - Extension #2"), | |
386 model->GetLabelAt(index)); | |
387 | |
388 ASSERT_TRUE(menu->GetMenuModelAndItemIndex( | |
389 IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 4, &model, &index)); | |
390 EXPECT_EQ(UTF8ToUTF16("Context Menu #2 - Extension #3"), | |
391 model->GetLabelAt(index)); | |
392 | |
393 ASSERT_TRUE(menu->GetMenuModelAndItemIndex( | |
394 IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 5, &model, &index)); | |
395 EXPECT_EQ(UTF8ToUTF16("Context Menu #3 - Extension #1"), | |
396 model->GetLabelAt(index)); | |
397 | |
398 ASSERT_TRUE(menu->GetMenuModelAndItemIndex( | |
399 IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 6, &model, &index)); | |
400 EXPECT_EQ(UTF8ToUTF16("Ze Extension with multiple Context Menus"), | |
401 model->GetLabelAt(index)); | |
402 } | |
403 | |
334 // Checks that in |menu|, the item at |index| has type |expected_type| and a | 404 // Checks that in |menu|, the item at |index| has type |expected_type| and a |
335 // label of |expected_label|. | 405 // label of |expected_label|. |
336 static void ExpectLabelAndType(const char* expected_label, | 406 static void ExpectLabelAndType(const char* expected_label, |
337 MenuModel::ItemType expected_type, | 407 MenuModel::ItemType expected_type, |
338 const MenuModel& menu, | 408 const MenuModel& menu, |
339 int index) { | 409 int index) { |
340 EXPECT_EQ(expected_type, menu.GetTypeAt(index)); | 410 EXPECT_EQ(expected_type, menu.GetTypeAt(index)); |
341 EXPECT_EQ(UTF8ToUTF16(expected_label), menu.GetLabelAt(index)); | 411 EXPECT_EQ(UTF8ToUTF16(expected_label), menu.GetLabelAt(index)); |
342 } | 412 } |
343 | 413 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); | 650 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); |
581 | 651 |
582 // Wait for the extension's processes to tell us they've created an item. | 652 // Wait for the extension's processes to tell us they've created an item. |
583 ASSERT_TRUE(created.WaitUntilSatisfied()); | 653 ASSERT_TRUE(created.WaitUntilSatisfied()); |
584 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); | 654 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); |
585 ASSERT_EQ(2u, GetItems().size()); | 655 ASSERT_EQ(2u, GetItems().size()); |
586 | 656 |
587 browser()->profile()->DestroyOffTheRecordProfile(); | 657 browser()->profile()->DestroyOffTheRecordProfile(); |
588 ASSERT_EQ(1u, GetItems().size()); | 658 ASSERT_EQ(1u, GetItems().size()); |
589 } | 659 } |
OLD | NEW |