summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 21:28:08 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 21:28:08 +0000
commit8ffb57c43c7201487920b159aba123b4a95c9735 (patch)
tree904a244aa6930875da3817712b89f331d2c5d223 /chrome/browser
parentfd8ca1c4c4bb82944e25fa50418a4c498e157ac3 (diff)
downloadchromium_src-8ffb57c43c7201487920b159aba123b4a95c9735.zip
chromium_src-8ffb57c43c7201487920b159aba123b4a95c9735.tar.gz
chromium_src-8ffb57c43c7201487920b159aba123b4a95c9735.tar.bz2
Ensure we have a valid profile when using
BrowserInit::LaunchWithProfile::OpenURLsInBrowser() directly and the browser passed in is a popup window. Original Review URL: http://codereview.chromium.org/160331 BUG=http://crbug.com/17520 TEST=see bug. Review URL: http://codereview.chromium.org/164341 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser_init.cc8
-rw-r--r--chrome/browser/browser_init_browsertest.cc60
2 files changed, 68 insertions, 0 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index acab527..9ca8f12 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -377,6 +377,7 @@ BrowserInit::LaunchWithProfile::LaunchWithProfile(
const CommandLine& command_line)
: cur_dir_(cur_dir),
command_line_(command_line),
+ profile_(NULL),
browser_init_(NULL) {
}
@@ -386,6 +387,7 @@ BrowserInit::LaunchWithProfile::LaunchWithProfile(
BrowserInit* browser_init)
: cur_dir_(cur_dir),
command_line_(command_line),
+ profile_(NULL),
browser_init_(browser_init) {
}
@@ -554,6 +556,12 @@ Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(
bool process_startup,
const std::vector<GURL>& urls) {
DCHECK(!urls.empty());
+ // If we don't yet have a profile, try to use the one we're given from
+ // |browser|. While we may not end up actually using |browser| (since it
+ // could be a popup window), we can at least use the profile.
+ if (!profile_ && browser)
+ profile_ = browser->profile();
+
int pin_count = 0;
if (!browser) {
std::wstring pin_count_string =
diff --git a/chrome/browser/browser_init_browsertest.cc b/chrome/browser/browser_init_browsertest.cc
new file mode 100644
index 0000000..7a32141
--- /dev/null
+++ b/chrome/browser/browser_init_browsertest.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_init.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/views/frame/browser_view.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class BrowserInitTest : public InProcessBrowserTest {
+};
+
+class OpenURLsPopupObserver : public BrowserList::Observer {
+ public:
+ OpenURLsPopupObserver() : added_browser_(NULL) { }
+
+ virtual void OnBrowserAdded(const Browser* browser) {
+ added_browser_ = browser;
+ }
+
+ virtual void OnBrowserRemoving(const Browser* browser) { }
+
+ const Browser* added_browser_;
+};
+
+// Test that when there is a popup as the active browser any requests to
+// BrowserInit::LaunchWithProfile::OpenURLsInBrowser don't crash because
+// there's no explicit profile given.
+IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenURLsPopup) {
+ std::vector<GURL> urls;
+ urls.push_back(GURL("http://www.google.com"));
+ urls.push_back(GURL("http://dev.chromium.org"));
+
+ // Note that in our testing we do not ever query the BrowserList for the "last
+ // active" browser. That's because the browsers are set as "active" by
+ // platform UI toolkit messages, and those messages are not sent during unit
+ // testing sessions.
+
+ OpenURLsPopupObserver observer;
+ BrowserList::AddObserver(&observer);
+
+ Browser* popup = Browser::CreateForPopup(browser()->profile());
+ ASSERT_EQ(popup->type(), Browser::TYPE_POPUP);
+ ASSERT_EQ(popup, observer.added_browser_);
+
+ CommandLine dummy((std::wstring()));
+ BrowserInit::LaunchWithProfile launch(std::wstring(), dummy);
+ // This should create a new window, but re-use the profile from |popup|. If
+ // it used a NULL or invalid profile, it would crash.
+ launch.OpenURLsInBrowser(popup, false, urls);
+ ASSERT_NE(popup, observer.added_browser_);
+ BrowserList::RemoveObserver(&observer);
+}
+
+} // namespace