summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-03 03:33:21 +0000
committerskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-03 03:33:21 +0000
commit461522024ee5081139acb9232b653aeb14d51903 (patch)
tree477b6870a56834dc3b4a42c44a9848823ca45dc6 /chrome/browser
parent2bd6e0576e5a799283587142fdb39fa696a008ae (diff)
downloadchromium_src-461522024ee5081139acb9232b653aeb14d51903.zip
chromium_src-461522024ee5081139acb9232b653aeb14d51903.tar.gz
chromium_src-461522024ee5081139acb9232b653aeb14d51903.tar.bz2
Revert 46208 - Focus an existing app tab when an app is clicked on the new tab page or invoked using appid=...
Reverting due to massive buildbot failure. BUG=none TEST=BrowserAppRefocusTest.* Review URL: http://codereview.chromium.org/1693006 TBR=skerner@chromium.org Review URL: http://codereview.chromium.org/1836002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser.cc112
-rw-r--r--chrome/browser/browser_browsertest.cc234
2 files changed, 0 insertions, 346 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 940d69c..43e1e61 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -152,112 +152,6 @@ static bool CompareURLsIgnoreRef(const GURL& url, const GURL& other) {
return url_no_ref == other_no_ref;
}
-// Helper for FindOpenAppInstance(), defined below. Given a browser, test
-// if it runs under |profile| and hosts app |extension_app|. If
-// |find_panel_or_window| is true, check that |browser| is an app window
-// or panel, otherwise check that it is not. Set |out_tab_idx| to
-// the index of the tab that hosts the app. If the entire browser hosts
-// app, |out_tab_idx| is set to kNoTab.
-bool FindOpenAppInstanceInBrowser(Browser* browser,
- Profile* profile,
- Extension* extension_app,
- bool find_panel_or_window,
- int* out_tab_idx) {
- if (browser->profile() != profile)
- return false;
-
- // If we are looking for an app panel or app window and |browser| is not
- // one of those types, or vise-versa, then return.
- Browser::Type type = browser->type();
- if (find_panel_or_window != ((type == Browser::TYPE_EXTENSION_APP) ||
- (type == Browser::TYPE_APP_PANEL)))
- return false;
-
- if (browser->extension_app() &&
- browser->extension_app() == extension_app) {
- DCHECK(find_panel_or_window) << "Non-app window has an extension app?";
- *out_tab_idx = TabStripModel::kNoTab; // The whole window contains the app.
- return true;
- }
-
- for (int tab_idx = 0; tab_idx < browser->tab_count(); ++tab_idx) {
- TabContents* tab_contents = browser->GetTabContentsAt(tab_idx);
- if (!tab_contents)
- continue;
-
- if (tab_contents->app_extension() != extension_app)
- continue;
-
- *out_tab_idx = tab_idx;
- return true;
- }
- return false;
-}
-
-// Find a tab in an open browser window which is running an application
-// |extension_app|. The browser must use profile |profile|, and be an
-// app window or panel if and only if |find_panel_or_window| is true.
-// Sets |out_browser| and |out_tab_idx| to the browser and tab index of
-// the matching tab on success. |out_tab_idx| will be kNoTab if the
-// browser is an app window.
-bool FindOpenAppInstance(Profile* profile,
- Extension* extension_app,
- bool find_panel_or_window,
- Browser** out_browser,
- int* out_tab_idx) {
- // Test the focused browser first.
- Browser* browser = BrowserList::GetLastActive();
- if (browser && FindOpenAppInstanceInBrowser(browser,
- profile,
- extension_app,
- find_panel_or_window,
- out_tab_idx)) {
- *out_browser = browser;
- return true;
- }
-
- BrowserList::const_iterator browser_all;
- for (browser_all = BrowserList::begin();
- browser_all != BrowserList::end();
- ++browser_all) {
- if (FindOpenAppInstanceInBrowser(*browser_all,
- profile,
- extension_app,
- find_panel_or_window,
- out_tab_idx)) {
- *out_browser = *browser_all;
- return true;
- }
- }
- return false;
-}
-
-// Find an existing browser window running under |profile| and hosting
-// the app |extension_app|. Focus it, and return the TabContents of the
-// focused tab.
-TabContents* FocusExistingAppInstance(Profile* profile,
- Extension* extension_app) {
- Browser* browser;
- int tab_idx;
-
- // Fist, search for app windows or panels. If none are found, search
- // for app tabs.
- if (FindOpenAppInstance(profile, extension_app, true, &browser, &tab_idx) ||
- FindOpenAppInstance(profile, extension_app, false, &browser, &tab_idx)) {
-
- // If the entire window is owned by the app, then select the first
- // tab. TODO(skerner): Does it make more sense to not change the
- // focused tab? Reconsider this after using apps for a week or two.
- if (tab_idx == TabStripModel::kNoTab)
- tab_idx = 0;
-
- browser->SelectTabContentsAt(tab_idx, false);
- browser->window()->Show();
- return browser->GetTabContentsAt(tab_idx);
- }
- return NULL;
-}
-
} // namespace
///////////////////////////////////////////////////////////////////////////////
@@ -520,12 +414,6 @@ TabContents* Browser::OpenApplication(Profile* profile,
if (!extension)
return NULL;
- // If the app is loaded in an existing window or tab, Focus it.
- TabContents* tab = FocusExistingAppInstance(profile, extension);
- if (tab)
- return tab;
-
- // The app is not yet open. Load it.
return OpenApplication(profile, extension, extension->launch_container());
}
diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc
index 807a2a9..d09be56 100644
--- a/chrome/browser/browser_browsertest.cc
+++ b/chrome/browser/browser_browsertest.cc
@@ -14,7 +14,6 @@
#include "chrome/browser/browser_init.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/browser_window.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extensions_service.h"
@@ -584,236 +583,3 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) {
app_extension);
}
#endif // !defined(OS_CHROMEOS)
-
-class BrowserAppRefocusTest : public ExtensionBrowserTest {
- public:
- BrowserAppRefocusTest(): server_(NULL),
- app_extension_(NULL),
- profile_(NULL) {}
-
- protected:
- virtual void SetUpCommandLine(CommandLine* command_line) {
- ExtensionBrowserTest::SetUpCommandLine(command_line);
- command_line->AppendSwitch(switches::kEnableExtensionApps);
- }
-
- // Common setup for all tests. Can't use SetUpInProcessBrowserTestFixture
- // because starting the http server crashes if called from that function.
- // The IO thread is not set up at that point.
- virtual void SetUpAppExtension() {
- server_ = StartHTTPServer();
- ASSERT_TRUE(server_);
- host_resolver()->AddRule("www.example.com", "127.0.0.1");
- url_ = GURL(server_->TestServerPage("empty.html"));
-
- profile_ = browser()->profile();
- ASSERT_TRUE(profile_);
-
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/")));
-
- // Save a pointer to the loaded extension in |app_extension_|.
- const ExtensionList* extensions =
- profile_->GetExtensionsService()->extensions();
-
- for (size_t i = 0; i < extensions->size(); ++i) {
- if ((*extensions)[i]->name() == "App Test")
- app_extension_ =(*extensions)[i];
- }
- ASSERT_TRUE(app_extension_) << "App Test extension not loaded.";
- }
-
- HTTPTestServer* server_;
- Extension* app_extension_;
- Profile* profile_;
- GURL url_;
-};
-
-#if defined(OS_MACOSX)
-// Crashes on mac, http://crbug.com/42865
-#define OpenTab DISABLED_OpenTab
-#define OpenPanel DISABLED_OpenPanel
-#define OpenWindow DISABLED_OpenWindow
-#define WindowBeforeTab DISABLED_WindowBeforeTab
-#define PanelBeforeTab DISABLED_PanelBeforeTab
-#define TabInFocusedWindow DISABLED_TabInFocusedWindow
-#endif
-
-// Test that launching an app refocuses a tab already hosting the app.
-IN_PROC_BROWSER_TEST_F(BrowserAppRefocusTest, OpenTab) {
- SetUpAppExtension();
-
- ui_test_utils::NavigateToURL(browser(), url_);
- ASSERT_EQ(1, browser()->tab_count());
-
- // Open a tab with the app.
- Browser::OpenApplicationTab(profile_, app_extension_);
- ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
- ASSERT_EQ(2, browser()->tab_count());
- int app_tab_index = browser()->selected_index();
- ASSERT_EQ(0, app_tab_index) << "App tab should be the left most tab.";
-
- // Open the same app. The existing tab should stay focused.
- Browser::OpenApplication(profile_, app_extension_->id());
- ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
- ASSERT_EQ(2, browser()->tab_count());
- ASSERT_EQ(app_tab_index, browser()->selected_index());
-
- // Focus the other tab, and reopen the app. The existing tab should
- // be refocused.
- browser()->SelectTabContentsAt(1, false);
- Browser::OpenApplication(profile_, app_extension_->id());
- ASSERT_EQ(2, browser()->tab_count());
- ASSERT_EQ(app_tab_index, browser()->selected_index());
-}
-
-// Test that launching an app refocuses a panel running the app.
-IN_PROC_BROWSER_TEST_F(BrowserAppRefocusTest, OpenPanel) {
- SetUpAppExtension();
-
- ui_test_utils::NavigateToURL(browser(), url_);
- ASSERT_EQ(1, browser()->tab_count());
-
- // Open the app in a panel.
- Browser::OpenApplicationWindow(profile_, app_extension_,
- Extension::LAUNCH_PANEL, GURL());
- Browser* app_panel = BrowserList::GetLastActive();
- ASSERT_TRUE(app_panel);
- ASSERT_NE(app_panel, browser()) << "New browser should have opened.";
- ASSERT_EQ(app_panel, BrowserList::GetLastActive());
-
- // Focus the initial browser.
- browser()->window()->Show();
- ASSERT_EQ(browser(), BrowserList::GetLastActive());
-
- // Open the app.
- Browser::OpenApplication(profile_, app_extension_->id());
-
- // Focus should move to the panel.
- ASSERT_EQ(app_panel, BrowserList::GetLastActive());
-
- // No new tab should have been created in the initial browser.
- ASSERT_EQ(1, browser()->tab_count());
-}
-
-// Test that launching an app refocuses a window running the app.
-IN_PROC_BROWSER_TEST_F(BrowserAppRefocusTest, OpenWindow) {
- SetUpAppExtension();
-
- ui_test_utils::NavigateToURL(browser(), url_);
- ASSERT_EQ(1, browser()->tab_count());
-
- // Open a window with the app.
- Browser::OpenApplicationWindow(profile_, app_extension_,
- Extension::LAUNCH_WINDOW, GURL());
- Browser* app_window = BrowserList::GetLastActive();
- ASSERT_TRUE(app_window);
- ASSERT_NE(app_window, browser()) << "New browser should have opened.";
-
- // Focus the initial browser.
- browser()->window()->Show();
- ASSERT_EQ(browser(), BrowserList::GetLastActive());
-
- // Open the app.
- Browser::OpenApplication(profile_, app_extension_->id());
-
- // Focus should move to the window.
- ASSERT_EQ(app_window, BrowserList::GetLastActive());
-
- // No new tab should have been created in the initial browser.
- ASSERT_EQ(1, browser()->tab_count());
-}
-
-// Test that if an app is opened while running in a window and a tab,
-// the window is focused.
-IN_PROC_BROWSER_TEST_F(BrowserAppRefocusTest, WindowBeforeTab) {
- SetUpAppExtension();
-
- ui_test_utils::NavigateToURL(browser(), url_);
- ASSERT_EQ(1, browser()->tab_count());
-
- // Open a tab with the app.
- Browser::OpenApplicationTab(profile_, app_extension_);
- ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
- ASSERT_EQ(2, browser()->tab_count());
- int app_tab_index = browser()->selected_index();
- ASSERT_EQ(0, app_tab_index) << "App tab should be the left most tab.";
-
- // Open a window with the app.
- Browser::OpenApplicationWindow(profile_, app_extension_,
- Extension::LAUNCH_WINDOW, GURL());
- Browser* app_window = BrowserList::GetLastActive();
- ASSERT_TRUE(app_window);
- ASSERT_NE(app_window, browser()) << "New browser should have opened.";
-
- // Focus the initial browser.
- browser()->window()->Show();
-
- // Open the app. Focus should move to the window.
- Browser::OpenApplication(profile_, app_extension_->id());
- ASSERT_EQ(app_window, BrowserList::GetLastActive());
-}
-
-// Test that if an app is opened while running in a panel and a tab,
-// the panel is focused.
-IN_PROC_BROWSER_TEST_F(BrowserAppRefocusTest, PanelBeforeTab) {
- SetUpAppExtension();
-
- ui_test_utils::NavigateToURL(browser(), url_);
- ASSERT_EQ(1, browser()->tab_count());
-
- // Open a tab with the app.
- Browser::OpenApplicationTab(profile_, app_extension_);
- ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
- ASSERT_EQ(2, browser()->tab_count());
- int app_tab_index = browser()->selected_index();
- ASSERT_EQ(0, app_tab_index) << "App tab should be the left most tab.";
-
- // Open a panel with the app.
- Browser::OpenApplicationWindow(profile_, app_extension_,
- Extension::LAUNCH_PANEL, GURL());
- Browser* app_panel = BrowserList::GetLastActive();
- ASSERT_TRUE(app_panel);
- ASSERT_NE(app_panel, browser()) << "New browser should have opened.";
-
- // Focus the initial browser.
- browser()->window()->Show();
-
- // Open the app. Focus should move to the panel.
- Browser::OpenApplication(profile_, app_extension_->id());
- ASSERT_EQ(app_panel, BrowserList::GetLastActive());
-}
-
-// Test that if multiple tabs host an app, and that app is opened,
-// the tab in the current window gets focus.
-IN_PROC_BROWSER_TEST_F(BrowserAppRefocusTest, TabInFocusedWindow) {
- SetUpAppExtension();
-
- ui_test_utils::NavigateToURL(browser(), url_);
- ASSERT_EQ(1, browser()->tab_count());
-
- Browser::OpenApplicationTab(profile_, app_extension_);
- ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
- ASSERT_EQ(2, browser()->tab_count());
- int app_tab_index = browser()->selected_index();
- ASSERT_EQ(0, app_tab_index) << "App tab should be the left most tab.";
-
- // Open a new browser window, add an app tab.
- Browser* extra_browser = CreateBrowser(profile_);
- ASSERT_EQ(extra_browser, BrowserList::GetLastActive());
-
- Browser::OpenApplicationTab(profile_, app_extension_);
- ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(extra_browser));
- ASSERT_EQ(2, extra_browser->tab_count());
- app_tab_index = extra_browser->selected_index();
- ASSERT_EQ(0, app_tab_index) << "App tab should be the left most tab";
-
- // Open the app. Focus should move to the panel.
- Browser::OpenApplication(profile_, app_extension_->id());
- ASSERT_EQ(extra_browser, BrowserList::GetLastActive());
- ASSERT_EQ(2, extra_browser->tab_count());
-
- browser()->window()->Show();
- Browser::OpenApplication(profile_, app_extension_->id());
- ASSERT_EQ(browser(), BrowserList::GetLastActive());
- ASSERT_EQ(2, browser()->tab_count());
-}