| 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/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_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 9 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 class PlatformAppBrowserTest : public ExtensionBrowserTest { | 44 class PlatformAppBrowserTest : public ExtensionBrowserTest { |
| 45 public: | 45 public: |
| 46 virtual void SetUpCommandLine(CommandLine* command_line) { | 46 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 47 ExtensionBrowserTest::SetUpCommandLine(command_line); | 47 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 48 command_line->AppendSwitch(switches::kEnablePlatformApps); | 48 command_line->AppendSwitch(switches::kEnablePlatformApps); |
| 49 } | 49 } |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 void LoadAndLaunchPlatformApp(const char* name) { | 52 void LoadAndLaunchPlatformApp(const char* name) { |
| 53 ui_test_utils::WindowedNotificationObserver app_loaded_observer( |
| 54 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 55 content::NotificationService::AllSources()); |
| 56 |
| 53 web_app::SetDisableShortcutCreationForTests(true); | 57 web_app::SetDisableShortcutCreationForTests(true); |
| 54 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps"). | 58 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps"). |
| 55 AppendASCII(name))); | 59 AppendASCII(name))); |
| 56 | 60 |
| 57 ExtensionService* service = browser()->profile()->GetExtensionService(); | 61 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 58 const Extension* extension = service->GetExtensionById( | 62 const Extension* extension = service->GetExtensionById( |
| 59 last_loaded_extension_id_, false); | 63 last_loaded_extension_id_, false); |
| 60 EXPECT_TRUE(extension); | 64 EXPECT_TRUE(extension); |
| 61 | 65 |
| 62 size_t platform_app_count = GetPlatformAppCount(); | 66 size_t platform_app_count = GetPlatformAppCount(); |
| 63 | 67 |
| 64 Browser::OpenApplication( | 68 Browser::OpenApplication( |
| 65 browser()->profile(), | 69 browser()->profile(), |
| 66 extension, | 70 extension, |
| 67 extension_misc::LAUNCH_SHELL, | 71 extension_misc::LAUNCH_SHELL, |
| 68 GURL(), | 72 GURL(), |
| 69 NEW_WINDOW); | 73 NEW_WINDOW); |
| 70 | 74 |
| 75 app_loaded_observer.Wait(); |
| 76 |
| 71 // Now we have a new platform app running. | 77 // Now we have a new platform app running. |
| 72 EXPECT_EQ(platform_app_count + 1, GetPlatformAppCount()); | 78 EXPECT_EQ(platform_app_count + 1, GetPlatformAppCount()); |
| 73 } | 79 } |
| 74 | 80 |
| 75 // Gets the number of platform apps that are running. | 81 // Gets the number of platform apps that are running. |
| 76 size_t GetPlatformAppCount() { | 82 size_t GetPlatformAppCount() { |
| 77 int count = 0; | 83 int count = 0; |
| 78 ExtensionProcessManager* process_manager = | 84 ExtensionProcessManager* process_manager = |
| 79 browser()->profile()->GetExtensionProcessManager(); | 85 browser()->profile()->GetExtensionProcessManager(); |
| 80 ExtensionProcessManager::const_iterator iter; | 86 ExtensionProcessManager::const_iterator iter; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 99 ++iter) { | 105 ++iter) { |
| 100 ExtensionHost* host = *iter; | 106 ExtensionHost* host = *iter; |
| 101 if (host->extension() && host->extension()->is_platform_app()) | 107 if (host->extension() && host->extension()->is_platform_app()) |
| 102 return host->host_contents(); | 108 return host->host_contents(); |
| 103 } | 109 } |
| 104 | 110 |
| 105 return NULL; | 111 return NULL; |
| 106 } | 112 } |
| 107 }; | 113 }; |
| 108 | 114 |
| 109 // Disabled until shell windows are implemented for non-GTK toolkits. | 115 // Disabled until shell windows are implemented for non-GTK, non-Views toolkits. |
| 110 #if defined(TOOLKIT_GTK) | 116 #if defined(TOOLKIT_GTK) || defined(TOOLKIT_VIEWS) |
| 111 #define MAYBE_OpenAppInShellContainer OpenAppInShellContainer | 117 #define MAYBE_OpenAppInShellContainer OpenAppInShellContainer |
| 112 #else | 118 #else |
| 113 #define MAYBE_OpenAppInShellContainer DISABLED_OpenAppInShellContainer | 119 #define MAYBE_OpenAppInShellContainer DISABLED_OpenAppInShellContainer |
| 114 #endif | 120 #endif |
| 115 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_OpenAppInShellContainer) { | 121 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_OpenAppInShellContainer) { |
| 116 ASSERT_EQ(0u, GetPlatformAppCount()); | 122 ASSERT_EQ(0u, GetPlatformAppCount()); |
| 117 LoadAndLaunchPlatformApp("empty"); | 123 LoadAndLaunchPlatformApp("empty"); |
| 118 ASSERT_EQ(1u, GetPlatformAppCount()); | 124 ASSERT_EQ(1u, GetPlatformAppCount()); |
| 119 | 125 |
| 120 UnloadExtension(last_loaded_extension_id_); | 126 UnloadExtension(last_loaded_extension_id_); |
| 121 ASSERT_EQ(0u, GetPlatformAppCount()); | 127 ASSERT_EQ(0u, GetPlatformAppCount()); |
| 122 } | 128 } |
| 123 | 129 |
| 124 // Disabled until shell windows are implemented for non-GTK toolkits. | 130 // Disabled until shell windows are implemented for non-GTK, non-Views toolkits. |
| 125 #if defined(TOOLKIT_GTK) | 131 #if defined(TOOLKIT_GTK) || defined(TOOLKIT_VIEWS) |
| 126 #define MAYBE_EmptyContextMenu EmptyContextMenu | 132 #define MAYBE_EmptyContextMenu EmptyContextMenu |
| 127 #else | 133 #else |
| 128 #define MAYBE_EmptyContextMenu DISABLED_EmptyContextMenu | 134 #define MAYBE_EmptyContextMenu DISABLED_EmptyContextMenu |
| 129 #endif | 135 #endif |
| 130 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_EmptyContextMenu) { | 136 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_EmptyContextMenu) { |
| 131 LoadAndLaunchPlatformApp("empty"); | 137 LoadAndLaunchPlatformApp("empty"); |
| 132 | 138 |
| 133 // The empty app doesn't add any context menu items, so its menu should | 139 // The empty app doesn't add any context menu items, so its menu should |
| 134 // be empty. | 140 // be empty. |
| 135 WebContents* web_contents = GetFirstPlatformAppWebContents(); | 141 WebContents* web_contents = GetFirstPlatformAppWebContents(); |
| 136 ASSERT_TRUE(web_contents); | 142 ASSERT_TRUE(web_contents); |
| 137 WebKit::WebContextMenuData data; | 143 WebKit::WebContextMenuData data; |
| 138 ContextMenuParams params(data); | 144 ContextMenuParams params(data); |
| 139 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, | 145 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, |
| 140 params); | 146 params); |
| 141 menu->Init(); | 147 menu->Init(); |
| 142 ASSERT_FALSE(menu->menu_model().GetItemCount()); | 148 ASSERT_FALSE(menu->menu_model().GetItemCount()); |
| 143 } | 149 } |
| 144 | 150 |
| 145 // Disabled until shell windows are implemented for non-GTK toolkits. | 151 // Disabled until shell windows are implemented for non-GTK, non-Views toolkits. |
| 146 #if defined(TOOLKIT_GTK) | 152 #if defined(TOOLKIT_GTK) || defined(TOOLKIT_VIEWS) |
| 147 #define MAYBE_AppWithContextMenu AppWithContextMenu | 153 #define MAYBE_AppWithContextMenu AppWithContextMenu |
| 148 #else | 154 #else |
| 149 #define MAYBE_AppWithContextMenu DISABLED_AppWithContextMenu | 155 #define MAYBE_AppWithContextMenu DISABLED_AppWithContextMenu |
| 150 #endif | 156 #endif |
| 151 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_AppWithContextMenu) { | 157 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_AppWithContextMenu) { |
| 152 ExtensionTestMessageListener listener1("created item", false); | 158 ExtensionTestMessageListener listener1("created item", false); |
| 153 LoadAndLaunchPlatformApp("context_menu"); | 159 LoadAndLaunchPlatformApp("context_menu"); |
| 154 | 160 |
| 155 // Wait for the extension to tell us it's created an item. | 161 // Wait for the extension to tell us it's created an item. |
| 156 ASSERT_TRUE(listener1.WaitUntilSatisfied()); | 162 ASSERT_TRUE(listener1.WaitUntilSatisfied()); |
| 157 | 163 |
| 158 // The context_menu app has one context menu item. This is all that should | 164 // The context_menu app has one context menu item. This is all that should |
| 159 // be in the menu, there should be no seperator. | 165 // be in the menu, there should be no seperator. |
| 160 WebContents* web_contents = GetFirstPlatformAppWebContents(); | 166 WebContents* web_contents = GetFirstPlatformAppWebContents(); |
| 161 ASSERT_TRUE(web_contents); | 167 ASSERT_TRUE(web_contents); |
| 162 WebKit::WebContextMenuData data; | 168 WebKit::WebContextMenuData data; |
| 163 ContextMenuParams params(data); | 169 ContextMenuParams params(data); |
| 164 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, | 170 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, |
| 165 params); | 171 params); |
| 166 menu->Init(); | 172 menu->Init(); |
| 167 ASSERT_EQ(1, menu->menu_model().GetItemCount()); | 173 ASSERT_EQ(1, menu->menu_model().GetItemCount()); |
| 168 } | 174 } |
| OLD | NEW |