Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/extensions/extension_browsertest.h" | 6 #include "chrome/browser/extensions/extension_browsertest.h" |
| 7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/extension_test_message_listener.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/tab_contents/render_view_context_menu.h" | |
| 9 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/extensions/extension_constants.h" | 14 #include "chrome/common/extensions/extension_constants.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/base/models/menu_model.h" | |
| 18 #include "webkit/glue/context_menu.h" | |
| 15 | 19 |
| 16 class PlaformAppBrowserTest : public ExtensionBrowserTest { | 20 namespace { |
| 21 // Non-abstract RenderViewContextMenu class. | |
| 22 class PlatformAppContextMenu : public RenderViewContextMenu { | |
| 23 public: | |
| 24 PlatformAppContextMenu(TabContents* tab_contents, | |
| 25 const ContextMenuParams& params) | |
| 26 : RenderViewContextMenu(tab_contents, params) {} | |
| 27 | |
| 28 protected: | |
| 29 // These two functions implement pure virtual methods of | |
| 30 // RenderViewContextMenu. | |
| 31 virtual bool GetAcceleratorForCommandId(int command_id, | |
| 32 ui::Accelerator* accelerator) { | |
| 33 return false; | |
| 34 } | |
| 35 virtual void PlatformInit() {} | |
| 36 }; | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 class PlatformAppBrowserTest : public ExtensionBrowserTest { | |
| 17 public: | 41 public: |
| 18 virtual void SetUpCommandLine(CommandLine* command_line) { | 42 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 19 ExtensionBrowserTest::SetUpCommandLine(command_line); | 43 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 20 command_line->AppendSwitch(switches::kEnablePlatformApps); | 44 command_line->AppendSwitch(switches::kEnablePlatformApps); |
| 21 } | 45 } |
| 22 | 46 |
| 23 void LoadAndLaunchPlatformApp(const char* name) { | 47 void LoadAndLaunchPlatformApp(const char* name) { |
| 24 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); | 48 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps"). |
| 49 AppendASCII(name))); | |
| 25 | 50 |
| 26 ExtensionService* service = browser()->profile()->GetExtensionService(); | 51 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 27 const Extension* extension = service->GetExtensionById( | 52 const Extension* extension = service->GetExtensionById( |
| 28 last_loaded_extension_id_, false); | 53 last_loaded_extension_id_, false); |
| 29 EXPECT_TRUE(extension); | 54 EXPECT_TRUE(extension); |
| 30 | 55 |
| 31 size_t browser_count = BrowserList::size(); | 56 size_t browser_count = BrowserList::size(); |
| 32 | 57 |
| 33 Browser::OpenApplication( | 58 Browser::OpenApplication( |
| 34 browser()->profile(), | 59 browser()->profile(), |
| 35 extension, | 60 extension, |
| 36 extension_misc::LAUNCH_SHELL, | 61 extension_misc::LAUNCH_SHELL, |
| 37 GURL(), | 62 GURL(), |
| 38 NEW_WINDOW); | 63 NEW_WINDOW); |
| 39 | 64 |
| 40 // Now we have a new browser instance. | 65 // Now we have a new browser instance. |
| 41 EXPECT_EQ(browser_count + 1, BrowserList::size()); | 66 EXPECT_EQ(browser_count + 1, BrowserList::size()); |
| 42 } | 67 } |
| 43 }; | 68 }; |
| 44 | 69 |
| 45 IN_PROC_BROWSER_TEST_F(PlaformAppBrowserTest, OpenAppInShellContainer) { | 70 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenAppInShellContainer) { |
| 46 // Start with one browser, new platform app will create another. | 71 // Start with one browser, new platform app will create another. |
| 47 ASSERT_EQ(1u, BrowserList::size()); | 72 ASSERT_EQ(1u, BrowserList::size()); |
| 48 | 73 |
| 49 LoadAndLaunchPlatformApp("platform_app"); | 74 LoadAndLaunchPlatformApp("empty"); |
| 50 | 75 |
| 51 // The launch should have created a new browser, so there should be 2 now. | 76 // The launch should have created a new browser, so there should be 2 now. |
| 52 ASSERT_EQ(2u, BrowserList::size()); | 77 ASSERT_EQ(2u, BrowserList::size()); |
| 53 | 78 |
| 54 // The new browser is the last one. | 79 // The new browser is the last one. |
| 55 BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end()); | 80 BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end()); |
| 56 Browser* new_browser = *(reverse_iterator++); | 81 Browser* new_browser = *(reverse_iterator++); |
| 57 | 82 |
| 58 ASSERT_TRUE(new_browser); | 83 ASSERT_TRUE(new_browser); |
| 59 ASSERT_TRUE(new_browser != browser()); | 84 ASSERT_TRUE(new_browser != browser()); |
| 60 | 85 |
| 61 // Expect an app in a shell window. | 86 // Expect an app in a shell window. |
| 62 EXPECT_TRUE(new_browser->is_app()); | 87 EXPECT_TRUE(new_browser->is_app()); |
| 63 EXPECT_TRUE(new_browser->is_type_shell()); | 88 EXPECT_TRUE(new_browser->is_type_shell()); |
| 64 } | 89 } |
| 90 | |
| 91 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { | |
| 92 // Start with one browser, new platform app will create another. | |
| 93 ASSERT_EQ(1u, BrowserList::size()); | |
| 94 | |
| 95 LoadAndLaunchPlatformApp("empty"); | |
| 96 | |
| 97 // The launch should have created a new browser, so there should be 2 now. | |
| 98 ASSERT_EQ(2u, BrowserList::size()); | |
| 99 | |
| 100 // The new browser is the last one. | |
| 101 BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end()); | |
| 102 Browser* new_browser = *(reverse_iterator++); | |
| 103 | |
| 104 ASSERT_TRUE(new_browser); | |
| 105 ASSERT_TRUE(new_browser != browser()); | |
| 106 | |
| 107 // The empty app doesn't add any context menu items, so its menu should | |
| 108 // be empty. | |
| 109 TabContents* tab_contents = new_browser->GetSelectedTabContents(); | |
| 110 WebKit::WebContextMenuData data; | |
| 111 ContextMenuParams params(data); | |
| 112 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.
| |
| 113 params); | |
| 114 menu->Init(); | |
| 115 ASSERT_FALSE(menu->menu_model().GetItemCount()); | |
| 116 } | |
| 117 | |
| 118 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { | |
| 119 // Start with one browser, new platform app will create another. | |
| 120 ASSERT_EQ(1u, BrowserList::size()); | |
| 121 | |
| 122 ExtensionTestMessageListener listener1("created item", false); | |
| 123 LoadAndLaunchPlatformApp("context_menu"); | |
| 124 | |
| 125 // Wait for the extension to tell us it's created an item. | |
| 126 ASSERT_TRUE(listener1.WaitUntilSatisfied()); | |
| 127 | |
| 128 // The launch should have created a new browser, so there should be 2 now. | |
| 129 ASSERT_EQ(2u, BrowserList::size()); | |
| 130 | |
| 131 // The new browser is the last one. | |
| 132 BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end()); | |
| 133 Browser* new_browser = *(reverse_iterator++); | |
| 134 | |
| 135 ASSERT_TRUE(new_browser); | |
| 136 ASSERT_TRUE(new_browser != browser()); | |
| 137 | |
| 138 // The context_menu app has one context menu item. This is all that should | |
| 139 // be in the menu, there should be no seperator. | |
| 140 TabContents* tab_contents = new_browser->GetSelectedTabContents(); | |
| 141 WebKit::WebContextMenuData data; | |
| 142 ContextMenuParams params(data); | |
| 143 PlatformAppContextMenu* menu = new PlatformAppContextMenu(tab_contents, | |
| 144 params); | |
| 145 menu->Init(); | |
| 146 ASSERT_EQ(1, menu->menu_model().GetItemCount()); | |
| 147 } | |
| OLD | NEW |