| 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 197842fba79e52529b753e9fc60696b4a2802093..5edc5665fc938d95037ed6b3b57171d2fd17f2d0 100644
|
| --- a/chrome/browser/extensions/platform_app_browsertest.cc
|
| +++ b/chrome/browser/extensions/platform_app_browsertest.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "base/command_line.h"
|
| #include "chrome/browser/extensions/extension_browsertest.h"
|
| +#include "chrome/browser/extensions/extension_host.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/extension_test_message_listener.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| @@ -45,6 +46,7 @@ class PlatformAppBrowserTest : public ExtensionBrowserTest {
|
| command_line->AppendSwitch(switches::kEnablePlatformApps);
|
| }
|
|
|
| + protected:
|
| void LoadAndLaunchPlatformApp(const char* name) {
|
| web_app::SetDisableShortcutCreationForTests(true);
|
| EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps").
|
| @@ -55,7 +57,7 @@ class PlatformAppBrowserTest : public ExtensionBrowserTest {
|
| last_loaded_extension_id_, false);
|
| EXPECT_TRUE(extension);
|
|
|
| - size_t browser_count = BrowserList::size();
|
| + size_t platform_app_count = GetPlatformAppCount();
|
|
|
| Browser::OpenApplication(
|
| browser()->profile(),
|
| @@ -64,51 +66,57 @@ class PlatformAppBrowserTest : public ExtensionBrowserTest {
|
| GURL(),
|
| NEW_WINDOW);
|
|
|
| - // Now we have a new browser instance.
|
| - EXPECT_EQ(browser_count + 1, BrowserList::size());
|
| + // Now we have a new platform app running.
|
| + EXPECT_EQ(platform_app_count + 1, GetPlatformAppCount());
|
| + }
|
| +
|
| + // Gets the number of platform apps that are running.
|
| + size_t GetPlatformAppCount() {
|
| + int count = 0;
|
| + ExtensionProcessManager* process_manager =
|
| + browser()->profile()->GetExtensionProcessManager();
|
| + ExtensionProcessManager::const_iterator iter;
|
| + for (iter = process_manager->begin(); iter != process_manager->end();
|
| + ++iter) {
|
| + ExtensionHost* host = *iter;
|
| + if (host->extension() && host->extension()->is_platform_app())
|
| + count++;
|
| + }
|
| +
|
| + return count;
|
| + }
|
| +
|
| + // Gets the TabContents associated with the ExtensionHost of the first
|
| + // platform app that is found (most tests only deal with one platform
|
| + // app, so this is good enough).
|
| + TabContents* GetFirstPlatformAppTabContents() {
|
| + ExtensionProcessManager* process_manager =
|
| + browser()->profile()->GetExtensionProcessManager();
|
| + ExtensionProcessManager::const_iterator iter;
|
| + for (iter = process_manager->begin(); iter != process_manager->end();
|
| + ++iter) {
|
| + ExtensionHost* host = *iter;
|
| + if (host->extension() && host->extension()->is_platform_app())
|
| + return host->host_contents();
|
| + }
|
| +
|
| + return NULL;
|
| }
|
| };
|
|
|
| IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenAppInShellContainer) {
|
| - // Start with one browser, new platform app will create another.
|
| - ASSERT_EQ(1u, BrowserList::size());
|
| -
|
| + ASSERT_EQ(0u, GetPlatformAppCount());
|
| 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());
|
| -
|
| - // Expect an app in a shell window.
|
| - EXPECT_TRUE(new_browser->is_app());
|
| - EXPECT_TRUE(new_browser->is_type_shell());
|
| + ASSERT_EQ(1u, GetPlatformAppCount());
|
| }
|
|
|
| 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();
|
| + TabContents* tab_contents = GetFirstPlatformAppTabContents();
|
| + ASSERT_TRUE(tab_contents);
|
| WebKit::WebContextMenuData data;
|
| ContextMenuParams params(data);
|
| PlatformAppContextMenu* menu = new PlatformAppContextMenu(tab_contents,
|
| @@ -118,28 +126,16 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
|
| }
|
|
|
| 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();
|
| + TabContents* tab_contents = GetFirstPlatformAppTabContents();
|
| + ASSERT_TRUE(tab_contents);
|
| WebKit::WebContextMenuData data;
|
| ContextMenuParams params(data);
|
| PlatformAppContextMenu* menu = new PlatformAppContextMenu(tab_contents,
|
|
|