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

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

Issue 8985008: Don't use browser windows for platform app shell windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable platform app tests on non-GTK platforms. Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_test_message_listener.h" 9 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/tab_contents/render_view_context_menu.h" 11 #include "chrome/browser/tab_contents/render_view_context_menu.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/web_applications/web_app.h" 14 #include "chrome/browser/web_applications/web_app.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/extensions/extension_constants.h" 16 #include "chrome/common/extensions/extension_constants.h"
16 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
(...skipping 23 matching lines...) Expand all
40 41
41 } // namespace 42 } // namespace
42 43
43 class PlatformAppBrowserTest : public ExtensionBrowserTest { 44 class PlatformAppBrowserTest : public ExtensionBrowserTest {
44 public: 45 public:
45 virtual void SetUpCommandLine(CommandLine* command_line) { 46 virtual void SetUpCommandLine(CommandLine* command_line) {
46 ExtensionBrowserTest::SetUpCommandLine(command_line); 47 ExtensionBrowserTest::SetUpCommandLine(command_line);
47 command_line->AppendSwitch(switches::kEnablePlatformApps); 48 command_line->AppendSwitch(switches::kEnablePlatformApps);
48 } 49 }
49 50
51 protected:
50 void LoadAndLaunchPlatformApp(const char* name) { 52 void LoadAndLaunchPlatformApp(const char* name) {
51 web_app::SetDisableShortcutCreationForTests(true); 53 web_app::SetDisableShortcutCreationForTests(true);
52 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps"). 54 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps").
53 AppendASCII(name))); 55 AppendASCII(name)));
54 56
55 ExtensionService* service = browser()->profile()->GetExtensionService(); 57 ExtensionService* service = browser()->profile()->GetExtensionService();
56 const Extension* extension = service->GetExtensionById( 58 const Extension* extension = service->GetExtensionById(
57 last_loaded_extension_id_, false); 59 last_loaded_extension_id_, false);
58 EXPECT_TRUE(extension); 60 EXPECT_TRUE(extension);
59 61
60 size_t browser_count = BrowserList::size(); 62 size_t platform_app_count = GetPlatformAppCount();
61 63
62 Browser::OpenApplication( 64 Browser::OpenApplication(
63 browser()->profile(), 65 browser()->profile(),
64 extension, 66 extension,
65 extension_misc::LAUNCH_SHELL, 67 extension_misc::LAUNCH_SHELL,
66 GURL(), 68 GURL(),
67 NEW_WINDOW); 69 NEW_WINDOW);
68 70
69 // Now we have a new browser instance. 71 // Now we have a new platform app running.
70 EXPECT_EQ(browser_count + 1, BrowserList::size()); 72 EXPECT_EQ(platform_app_count + 1, GetPlatformAppCount());
73 }
74
75 // Gets the number of platform apps that are running.
76 size_t GetPlatformAppCount() {
77 int count = 0;
78 ExtensionProcessManager* process_manager =
79 browser()->profile()->GetExtensionProcessManager();
80 ExtensionProcessManager::const_iterator iter;
81 for (iter = process_manager->begin(); iter != process_manager->end();
82 ++iter) {
83 ExtensionHost* host = *iter;
84 if (host->extension() && host->extension()->is_platform_app())
85 count++;
86 }
87
88 return count;
89 }
90
91 // Gets the WebContents associated with the ExtensionHost of the first
92 // platform app that is found (most tests only deal with one platform
93 // app, so this is good enough).
94 WebContents* GetFirstPlatformAppWebContents() {
95 ExtensionProcessManager* process_manager =
96 browser()->profile()->GetExtensionProcessManager();
97 ExtensionProcessManager::const_iterator iter;
98 for (iter = process_manager->begin(); iter != process_manager->end();
99 ++iter) {
100 ExtensionHost* host = *iter;
101 if (host->extension() && host->extension()->is_platform_app())
102 return host->host_contents();
103 }
104
105 return NULL;
71 } 106 }
72 }; 107 };
73 108
74 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenAppInShellContainer) { 109 // Disabled until shell windows are implemented for non-GTK toolkits.
75 // Start with one browser, new platform app will create another. 110 #if defined(TOOLKIT_GTK)
76 ASSERT_EQ(1u, BrowserList::size()); 111 #define MAYBE_OpenAppInShellContainer OpenAppInShellContainer
77 112 #else
113 #define MAYBE_OpenAppInShellContainer DISABLED_OpenAppInShellContainer
114 #endif
115 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_OpenAppInShellContainer) {
116 ASSERT_EQ(0u, GetPlatformAppCount());
78 LoadAndLaunchPlatformApp("empty"); 117 LoadAndLaunchPlatformApp("empty");
79 118 ASSERT_EQ(1u, GetPlatformAppCount());
80 // The launch should have created a new browser, so there should be 2 now.
81 ASSERT_EQ(2u, BrowserList::size());
82
83 // The new browser is the last one.
84 BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end());
85 Browser* new_browser = *(reverse_iterator++);
86
87 ASSERT_TRUE(new_browser);
88 ASSERT_TRUE(new_browser != browser());
89
90 // Expect an app in a shell window.
91 EXPECT_TRUE(new_browser->is_app());
92 EXPECT_TRUE(new_browser->is_type_shell());
93 } 119 }
94 120
95 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { 121 // Disabled until shell windows are implemented for non-GTK toolkits.
96 // Start with one browser, new platform app will create another. 122 #if defined(TOOLKIT_GTK)
97 ASSERT_EQ(1u, BrowserList::size()); 123 #define MAYBE_EmptyContextMenu EmptyContextMenu
98 124 #else
125 #define MAYBE_EmptyContextMenu DISABLED_EmptyContextMenu
126 #endif
127 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_EmptyContextMenu) {
99 LoadAndLaunchPlatformApp("empty"); 128 LoadAndLaunchPlatformApp("empty");
100 129
101 // The launch should have created a new browser, so there should be 2 now.
102 ASSERT_EQ(2u, BrowserList::size());
103
104 // The new browser is the last one.
105 BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end());
106 Browser* new_browser = *(reverse_iterator++);
107
108 ASSERT_TRUE(new_browser);
109 ASSERT_TRUE(new_browser != browser());
110
111 // The empty app doesn't add any context menu items, so its menu should 130 // The empty app doesn't add any context menu items, so its menu should
112 // be empty. 131 // be empty.
113 WebContents* web_contents = new_browser->GetSelectedWebContents(); 132 WebContents* web_contents = GetFirstPlatformAppWebContents();
133 ASSERT_TRUE(web_contents);
114 WebKit::WebContextMenuData data; 134 WebKit::WebContextMenuData data;
115 ContextMenuParams params(data); 135 ContextMenuParams params(data);
116 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, 136 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents,
117 params); 137 params);
118 menu->Init(); 138 menu->Init();
119 ASSERT_FALSE(menu->menu_model().GetItemCount()); 139 ASSERT_FALSE(menu->menu_model().GetItemCount());
120 } 140 }
121 141
122 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { 142 // Disabled until shell windows are implemented for non-GTK toolkits.
123 // Start with one browser, new platform app will create another. 143 #if defined(TOOLKIT_GTK)
124 ASSERT_EQ(1u, BrowserList::size()); 144 #define MAYBE_AppWithContextMenu AppWithContextMenu
125 145 #else
146 #define MAYBE_AppWithContextMenu DISABLED_AppWithContextMenu
147 #endif
148 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_AppWithContextMenu) {
126 ExtensionTestMessageListener listener1("created item", false); 149 ExtensionTestMessageListener listener1("created item", false);
127 LoadAndLaunchPlatformApp("context_menu"); 150 LoadAndLaunchPlatformApp("context_menu");
128 151
129 // Wait for the extension to tell us it's created an item. 152 // Wait for the extension to tell us it's created an item.
130 ASSERT_TRUE(listener1.WaitUntilSatisfied()); 153 ASSERT_TRUE(listener1.WaitUntilSatisfied());
131 154
132 // The launch should have created a new browser, so there should be 2 now.
133 ASSERT_EQ(2u, BrowserList::size());
134
135 // The new browser is the last one.
136 BrowserList::const_reverse_iterator reverse_iterator(BrowserList::end());
137 Browser* new_browser = *(reverse_iterator++);
138
139 ASSERT_TRUE(new_browser);
140 ASSERT_TRUE(new_browser != browser());
141
142 // The context_menu app has one context menu item. This is all that should 155 // The context_menu app has one context menu item. This is all that should
143 // be in the menu, there should be no seperator. 156 // be in the menu, there should be no seperator.
144 WebContents* web_contents = new_browser->GetSelectedWebContents(); 157 WebContents* web_contents = GetFirstPlatformAppWebContents();
158 ASSERT_TRUE(web_contents);
145 WebKit::WebContextMenuData data; 159 WebKit::WebContextMenuData data;
146 ContextMenuParams params(data); 160 ContextMenuParams params(data);
147 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, 161 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents,
148 params); 162 params);
149 menu->Init(); 163 menu->Init();
150 ASSERT_EQ(1, menu->menu_model().GetItemCount()); 164 ASSERT_EQ(1, menu->menu_model().GetItemCount());
151 } 165 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_process_manager.cc ('k') | chrome/browser/tab_contents/render_view_context_menu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698