diff options
author | creis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 03:47:11 +0000 |
---|---|---|
committer | creis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 03:47:11 +0000 |
commit | d292d8a82d12129d1e061f469b8edee035be8b97 (patch) | |
tree | aa0e706189af2477088e0211e1d8c7dd3844750c /chrome/browser/task_manager | |
parent | 9dade396bc7bcd363ba481fb2c328c93f226858d (diff) | |
download | chromium_src-d292d8a82d12129d1e061f469b8edee035be8b97.zip chromium_src-d292d8a82d12129d1e061f469b8edee035be8b97.tar.gz chromium_src-d292d8a82d12129d1e061f469b8edee035be8b97.tar.bz2 |
Swap processes on reload if a hosted app has been installed/uninstalled.
Also ensure the task manager only shows "App" if the process is an app process.
BUG=80621
TEST=AppApiTest.ReloadIntoAppProcess
TEST=TaskManagerBrowserTest.NoticeHostedAppTabs
Review URL: http://codereview.chromium.org/7063015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86566 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/task_manager')
-rw-r--r-- | chrome/browser/task_manager/task_manager_browsertest.cc | 53 | ||||
-rw-r--r-- | chrome/browser/task_manager/task_manager_resource_providers.cc | 16 |
2 files changed, 63 insertions, 6 deletions
diff --git a/chrome/browser/task_manager/task_manager_browsertest.cc b/chrome/browser/task_manager/task_manager_browsertest.cc index 537efb8..4bd10d4 100644 --- a/chrome/browser/task_manager/task_manager_browsertest.cc +++ b/chrome/browser/task_manager/task_manager_browsertest.cc @@ -27,6 +27,7 @@ #include "chrome/test/ui_test_utils.h" #include "content/common/page_transition_types.h" #include "grit/generated_resources.h" +#include "net/base/mock_host_resolver.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/l10n/l10n_util.h" @@ -304,7 +305,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { // a tab contents and an extension. The title should start with "App:". ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); - ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); + ASSERT_TRUE(model()->GetResourceExtension(2) == extension); string16 prefix = l10n_util::GetStringFUTF16( IDS_TASK_MANAGER_APP_PREFIX, string16()); ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); @@ -314,6 +315,56 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { WaitForResourceChange(2); } +IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { + // Show the task manager. This populates the model, and helps with debugging + // (you see the task manager). + browser()->window()->ShowTaskManager(); + + // Browser and the New Tab Page. + WaitForResourceChange(2); + + // The app under test acts on URLs whose host is "localhost", + // so the URLs we navigate to must have host "localhost". + host_resolver()->AddRule("*", "127.0.0.1"); + ASSERT_TRUE(test_server()->Start()); + GURL::Replacements replace_host; + std::string host_str("localhost"); // must stay in scope with replace_host + replace_host.SetHostStr(host_str); + GURL base_url = test_server()->GetURL( + "files/extensions/api_test/app_process/"); + base_url = base_url.ReplaceComponents(replace_host); + + // Open a new tab to an app URL before the app is loaded. + GURL url(base_url.Resolve("path1/empty.html")); + AddTabAtIndex(0, url, PageTransition::TYPED); + ui_test_utils::WaitForNavigation( + &browser()->GetSelectedTabContents()->controller()); + + // Check that the third entry's title starts with "Tab:". + string16 tab_prefix = l10n_util::GetStringFUTF16( + IDS_TASK_MANAGER_TAB_PREFIX, string16()); + ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), tab_prefix, true)); + + // Load the hosted app and make sure it still starts with "Tab:", + // since it hasn't changed to an app process yet. + ASSERT_TRUE(LoadExtension( + test_data_dir_.AppendASCII("api_test").AppendASCII("app_process"))); + ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), tab_prefix, true)); + + // Now reload and check that the third entry's title now starts with "App:". + ui_test_utils::NavigateToURL(browser(), url); + string16 app_prefix = l10n_util::GetStringFUTF16( + IDS_TASK_MANAGER_APP_PREFIX, string16()); + ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), app_prefix, true)); + + // Disable extension and reload page. + DisableExtension(last_loaded_extension_id_); + ui_test_utils::NavigateToURL(browser(), url); + + // The third entry's title should be back to a normal tab. + ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), tab_prefix, true)); +} + IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeNotificationChanges) { EXPECT_EQ(0, model()->ResourceCount()); diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc index 99cb938..f3989c0 100644 --- a/chrome/browser/task_manager/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager/task_manager_resource_providers.cc @@ -197,9 +197,11 @@ TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const { string16 TaskManagerTabContentsResource::GetTitle() const { // Fall back on the URL if there's no title. - string16 tab_title = tab_contents_->tab_contents()->GetTitle(); + TabContents* contents = tab_contents_->tab_contents(); + string16 tab_title = contents->GetTitle(); + GURL url = contents->GetURL(); if (tab_title.empty()) { - tab_title = UTF8ToUTF16(tab_contents_->tab_contents()->GetURL().spec()); + tab_title = UTF8ToUTF16(url.spec()); // Force URL to be LTR. tab_title = base::i18n::GetDisplayStringInLTRDirectionality(tab_title); } else { @@ -215,13 +217,17 @@ string16 TaskManagerTabContentsResource::GetTitle() const { base::i18n::AdjustStringForLocaleDirection(&tab_title); } + // Only classify as an app if the URL is an app and the tab is hosting an + // extension process. (It's possible to be showing the URL from before it + // was installed as an app.) ExtensionService* extensions_service = tab_contents_->profile()->GetExtensionService(); + bool is_app = extensions_service->IsInstalledApp(url) && + contents->GetRenderProcessHost()->is_extension_process(); int message_id = GetMessagePrefixID( - extensions_service->IsInstalledApp( - tab_contents_->tab_contents()->GetURL()), - tab_contents_->tab_contents()->HostsExtension(), + is_app, + contents->HostsExtension(), tab_contents_->profile()->IsOffTheRecord(), IsPrerendering()); return l10n_util::GetStringFUTF16(message_id, tab_title); |