Chromium Code Reviews| Index: chrome/browser/extensions/platform_app_browsertest.cc |
| diff --git a/chrome/browser/extensions/platform_app_browsertest.cc b/chrome/browser/extensions/platform_app_browsertest.cc |
| index 03b4d41ffc804abe54b0842c4c72def435c76792..24cc4a5931c5aa508b76d2aba77b58ffdaa29d4f 100644 |
| --- a/chrome/browser/extensions/platform_app_browsertest.cc |
| +++ b/chrome/browser/extensions/platform_app_browsertest.cc |
| @@ -5,15 +5,39 @@ |
| #include "base/command_line.h" |
| #include "chrome/browser/extensions/extension_browsertest.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/extensions/extension_test_message_listener.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/tab_contents/render_view_context_menu.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/extensions/extension_constants.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/base/models/menu_model.h" |
| +#include "webkit/glue/context_menu.h" |
| -class PlaformAppBrowserTest : public ExtensionBrowserTest { |
| +namespace { |
| +// Non-abstract RenderViewContextMenu class. |
| +class PlatformAppContextMenu : public RenderViewContextMenu { |
| + public: |
| + PlatformAppContextMenu(TabContents* tab_contents, |
| + const ContextMenuParams& params) |
| + : RenderViewContextMenu(tab_contents, params) {} |
| + |
| + protected: |
| + // These two functions implement pure virtual methods of |
| + // RenderViewContextMenu. |
| + virtual bool GetAcceleratorForCommandId(int command_id, |
| + ui::Accelerator* accelerator) { |
| + return false; |
| + } |
| + virtual void PlatformInit() {} |
| +}; |
| + |
| +} // namespace |
| + |
| +class PlatformAppBrowserTest : public ExtensionBrowserTest { |
| public: |
| virtual void SetUpCommandLine(CommandLine* command_line) { |
| ExtensionBrowserTest::SetUpCommandLine(command_line); |
| @@ -21,7 +45,8 @@ class PlaformAppBrowserTest : public ExtensionBrowserTest { |
| } |
| void LoadAndLaunchPlatformApp(const char* name) { |
| - EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); |
| + EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps"). |
| + AppendASCII(name))); |
| ExtensionService* service = browser()->profile()->GetExtensionService(); |
| const Extension* extension = service->GetExtensionById( |
| @@ -42,11 +67,11 @@ class PlaformAppBrowserTest : public ExtensionBrowserTest { |
| } |
| }; |
| -IN_PROC_BROWSER_TEST_F(PlaformAppBrowserTest, OpenAppInShellContainer) { |
| +IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenAppInShellContainer) { |
| // Start with one browser, new platform app will create another. |
| ASSERT_EQ(1u, BrowserList::size()); |
| - LoadAndLaunchPlatformApp("platform_app"); |
| + LoadAndLaunchPlatformApp("empty"); |
| // The launch should have created a new browser, so there should be 2 now. |
| ASSERT_EQ(2u, BrowserList::size()); |
| @@ -62,3 +87,61 @@ IN_PROC_BROWSER_TEST_F(PlaformAppBrowserTest, OpenAppInShellContainer) { |
| EXPECT_TRUE(new_browser->is_app()); |
| EXPECT_TRUE(new_browser->is_type_shell()); |
| } |
| + |
| +IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
| + // Start with one browser, new platform app will create another. |
| + ASSERT_EQ(1u, BrowserList::size()); |
| + |
| + LoadAndLaunchPlatformApp("empty"); |
| + |
| + // The launch should have created a new browser, so there should be 2 now. |
| + ASSERT_EQ(2u, BrowserList::size()); |
| + |
| + // The new browser is the last one. |
| + BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end()); |
| + Browser* new_browser = *(reverse_iterator++); |
| + |
| + ASSERT_TRUE(new_browser); |
| + ASSERT_TRUE(new_browser != browser()); |
| + |
| + // The empty app doesn't add any context menu items, so its menu should |
| + // be empty. |
| + TabContents* tab_contents = new_browser->GetSelectedTabContents(); |
| + WebKit::WebContextMenuData data; |
| + ContextMenuParams params(data); |
| + PlatformAppContextMenu* menu =new PlatformAppContextMenu(tab_contents, |
|
asargent_no_longer_on_chrome
2011/12/09 05:34:21
nit: "=new" -> "= new"
benwells
2011/12/12 05:30:39
Done.
|
| + params); |
| + menu->Init(); |
| + ASSERT_FALSE(menu->menu_model().GetItemCount()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
| + // Start with one browser, new platform app will create another. |
| + ASSERT_EQ(1u, BrowserList::size()); |
| + |
| + ExtensionTestMessageListener listener1("created item", false); |
| + LoadAndLaunchPlatformApp("context_menu"); |
| + |
| + // Wait for the extension to tell us it's created an item. |
| + ASSERT_TRUE(listener1.WaitUntilSatisfied()); |
| + |
| + // The launch should have created a new browser, so there should be 2 now. |
| + ASSERT_EQ(2u, BrowserList::size()); |
| + |
| + // The new browser is the last one. |
| + BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end()); |
| + Browser* new_browser = *(reverse_iterator++); |
| + |
| + ASSERT_TRUE(new_browser); |
| + ASSERT_TRUE(new_browser != browser()); |
| + |
| + // The context_menu app has one context menu item. This is all that should |
| + // be in the menu, there should be no seperator. |
| + TabContents* tab_contents = new_browser->GetSelectedTabContents(); |
| + WebKit::WebContextMenuData data; |
| + ContextMenuParams params(data); |
| + PlatformAppContextMenu* menu = new PlatformAppContextMenu(tab_contents, |
| + params); |
| + menu->Init(); |
| + ASSERT_EQ(1, menu->menu_model().GetItemCount()); |
| +} |