summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-30 20:57:17 +0000
committergab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-30 20:57:17 +0000
commit1038ecb77198ad02d6e6f8c4fbe46584a31f32fd (patch)
treee1fb814b66987590d8dfdc19701d10b3e7aaec41
parent172a3a8063c95204c3279e5a36dc0ecb4c1b50be (diff)
downloadchromium_src-1038ecb77198ad02d6e6f8c4fbe46584a31f32fd.zip
chromium_src-1038ecb77198ad02d6e6f8c4fbe46584a31f32fd.tar.gz
chromium_src-1038ecb77198ad02d6e6f8c4fbe46584a31f32fd.tar.bz2
Introduce BrowserIterator.
An iterator meant to iterate over all the browsers in BrowserListImpls across multiple desktops (i.e. multiple HostDesktopTypes). As a first step, used it in TabContentsIterator (pretty much bringing back the implementation to the one that was there prior to https://codereview.chromium.org/11316340/ -- except that the iterator is now aware of multiple desktops). Another CL will follow in which all BrowserList::const_iterator, etc. methods will be replaced by BrowserIterator. The interface of BrowserIterator is derived from the interface of TabContentsIterator for consistency (which is being slightly tweaked in parallel in https://codereview.chromium.org/12049038/). BUG=129187 Review URL: https://chromiumcodereview.appspot.com/12038053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179695 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/browser_iterator.cc33
-rw-r--r--chrome/browser/ui/browser_iterator.h71
-rw-r--r--chrome/browser/ui/browser_iterator_unittest.cc122
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_iterator.cc55
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_iterator.h29
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_iterator_unittest.cc55
-rw-r--r--chrome/chrome_browser_ui.gypi3
-rw-r--r--chrome/chrome_tests_unit.gypi2
-rw-r--r--chrome/test/base/browser_with_test_window_test.cc16
-rw-r--r--chrome/test/base/browser_with_test_window_test.h11
10 files changed, 315 insertions, 82 deletions
diff --git a/chrome/browser/ui/browser_iterator.cc b/chrome/browser/ui/browser_iterator.cc
new file mode 100644
index 0000000..73571d5
--- /dev/null
+++ b/chrome/browser/ui/browser_iterator.cc
@@ -0,0 +1,33 @@
+// Copyright (c) 2013 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/ui/browser_iterator.h"
+
+namespace chrome {
+
+BrowserIterator::BrowserIterator()
+ : current_browser_list_(
+ BrowserListImpl::GetInstance(HOST_DESKTOP_TYPE_FIRST)),
+ current_iterator_(current_browser_list_->begin()),
+ next_desktop_type_(
+ static_cast<HostDesktopType>(HOST_DESKTOP_TYPE_FIRST + 1)) {
+ NextBrowserListIfAtEnd();
+}
+
+void BrowserIterator::Next() {
+ ++current_iterator_;
+ NextBrowserListIfAtEnd();
+}
+
+void BrowserIterator::NextBrowserListIfAtEnd() {
+ // Make sure either |current_iterator_| is valid or done().
+ while (current_iterator_ == current_browser_list_->end() &&
+ next_desktop_type_ < HOST_DESKTOP_TYPE_COUNT) {
+ current_browser_list_ = BrowserListImpl::GetInstance(next_desktop_type_);
+ current_iterator_ = current_browser_list_->begin();
+ next_desktop_type_ = static_cast<HostDesktopType>(next_desktop_type_ + 1);
+ }
+}
+
+} // namespace chrome
diff --git a/chrome/browser/ui/browser_iterator.h b/chrome/browser/ui/browser_iterator.h
new file mode 100644
index 0000000..4911679
--- /dev/null
+++ b/chrome/browser/ui/browser_iterator.h
@@ -0,0 +1,71 @@
+// Copyright (c) 2013 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.
+
+#ifndef CHROME_BROWSER_UI_BROWSER_ITERATOR_H_
+#define CHROME_BROWSER_UI_BROWSER_ITERATOR_H_
+
+#include "chrome/browser/ui/browser_list_impl.h"
+#include "chrome/browser/ui/host_desktop.h"
+
+class Browser;
+
+namespace chrome {
+
+// Iterates over all existing browsers (potentially across multiple desktops).
+// Note: to iterate only over the browsers of a specific desktop, use the
+// const_iterator of a given BrowserListImpl instead.
+//
+// Example:
+// for (BrowserIterator iterator; !iterator.done(); iterator.Next()) {
+// Browser* cur = *iterator;
+// -or-
+// iterator->OperationOnBrowser();
+// ...
+// }
+class BrowserIterator {
+ public:
+ BrowserIterator();
+
+ // Returns true if we are past the last Browser.
+ bool done() const {
+ // |current_iterator_| is never at the end of a list unless it is done (it
+ // immediately moves to the next browser list upon hitting the end of the
+ // current list unless there are no remaining empty browser lists).
+ return current_iterator_ == current_browser_list_->end();
+ }
+
+ // Returns the current Browser, valid as long as !done().
+ Browser* operator->() const {
+ return *current_iterator_;
+ }
+ Browser* operator*() const {
+ return *current_iterator_;
+ }
+
+ // Advances |current_iterator_| to the next browser.
+ void Next();
+
+ private:
+ // If |current_iterator_| is at |current_browser_list_->end()|, advance to the
+ // next non-empty browser list. After a call to this method: either
+ // |current_iterator_| is valid or done().
+ void NextBrowserListIfAtEnd();
+
+ // The BrowserListImpl currently being iterated over. Instances of this class
+ // do not own this pointer.
+ BrowserListImpl* current_browser_list_;
+
+ // The underlying iterator over browsers in |current_browser_list_|.
+ BrowserListImpl::const_iterator current_iterator_;
+
+ // The next HostDesktopType to iterate over when |current_iterator_| reaches
+ // |current_browser_list_->end()|.
+ HostDesktopType next_desktop_type_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserIterator);
+};
+
+} // namespace chrome
+
+#endif // CHROME_BROWSER_UI_BROWSER_ITERATOR_H_
diff --git a/chrome/browser/ui/browser_iterator_unittest.cc b/chrome/browser/ui/browser_iterator_unittest.cc
new file mode 100644
index 0000000..33d3be2
--- /dev/null
+++ b/chrome/browser/ui/browser_iterator_unittest.cc
@@ -0,0 +1,122 @@
+// Copyright (c) 2013 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/ui/browser_iterator.h"
+
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list_impl.h"
+#include "chrome/browser/ui/host_desktop.h"
+#include "chrome/test/base/browser_with_test_window_test.h"
+
+typedef BrowserWithTestWindowTest BrowserIteratorTest;
+
+namespace {
+
+// BrowserWithTestWindowTest's default window is on the native desktop by
+// default. Force it to be on the Ash desktop to be able to test the iterator
+// in a situation with no browsers on the native desktop.
+class BrowserIteratorTestWithInitialWindowInAsh
+ : public BrowserWithTestWindowTest {
+ public:
+ BrowserIteratorTestWithInitialWindowInAsh()
+ : BrowserWithTestWindowTest(chrome::HOST_DESKTOP_TYPE_ASH) {
+ }
+};
+
+// Helper function to iterate and count all the browsers.
+size_t CountAllBrowsers() {
+ size_t count = 0;
+ for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next())
+ ++count;
+ return count;
+}
+
+}
+
+TEST_F(BrowserIteratorTest, BrowsersOnMultipleDesktops) {
+ Browser::CreateParams native_params(profile(),
+ chrome::HOST_DESKTOP_TYPE_NATIVE);
+ Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
+ // Note, browser 1 is on the native desktop.
+ scoped_ptr<Browser> browser2(
+ chrome::CreateBrowserWithTestWindowForParams(&native_params));
+ scoped_ptr<Browser> browser3(
+ chrome::CreateBrowserWithTestWindowForParams(&native_params));
+ scoped_ptr<Browser> browser4(
+ chrome::CreateBrowserWithTestWindowForParams(&ash_params));
+ scoped_ptr<Browser> browser5(
+ chrome::CreateBrowserWithTestWindowForParams(&ash_params));
+
+ // Sanity checks.
+ chrome::BrowserListImpl* native_list =
+ chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
+#if defined(OS_CHROMEOS)
+ // On Chrome OS, the native list and the ash list are the same.
+ EXPECT_EQ(5U, native_list->size());
+#else
+ chrome::BrowserListImpl* ash_list =
+ chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
+ EXPECT_EQ(3U, native_list->size());
+ EXPECT_EQ(2U, ash_list->size());
+#endif
+
+ // Make sure the iterator finds all 5 browsers regardless of which desktop
+ // they are on.
+ EXPECT_EQ(5U, CountAllBrowsers());
+}
+
+TEST_F(BrowserIteratorTest, NoBrowsersOnAshDesktop) {
+ Browser::CreateParams native_params(profile(),
+ chrome::HOST_DESKTOP_TYPE_NATIVE);
+ // Note, browser 1 is on the native desktop.
+ scoped_ptr<Browser> browser2(
+ chrome::CreateBrowserWithTestWindowForParams(&native_params));
+ scoped_ptr<Browser> browser3(
+ chrome::CreateBrowserWithTestWindowForParams(&native_params));
+
+ // Sanity checks.
+ chrome::BrowserListImpl* native_list =
+ chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
+ EXPECT_EQ(3U, native_list->size());
+#if !defined(OS_CHROMEOS)
+ // On non-Chrome OS platforms the Ash list is independent from the native
+ // list, double-check that it's empty.
+ chrome::BrowserListImpl* ash_list =
+ chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
+ EXPECT_EQ(0U, ash_list->size());
+#endif
+
+ // Make sure the iterator finds all 3 browsers on the native desktop and
+ // doesn't trip over the empty Ash desktop list.
+ EXPECT_EQ(3U, CountAllBrowsers());
+}
+
+TEST_F(BrowserIteratorTestWithInitialWindowInAsh, NoBrowsersOnNativeDesktop) {
+ Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
+ // Note, browser 1 is on the ash desktop.
+ scoped_ptr<Browser> browser2(
+ chrome::CreateBrowserWithTestWindowForParams(&ash_params));
+ scoped_ptr<Browser> browser3(
+ chrome::CreateBrowserWithTestWindowForParams(&ash_params));
+
+ chrome::BrowserListImpl* ash_list =
+ chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
+ EXPECT_EQ(3U, ash_list->size());
+#if !defined(OS_CHROMEOS)
+ // On non-Chrome OS platforms the native list is independent from the Ash
+ // list; double-check that it's empty.
+ chrome::BrowserListImpl* native_list =
+ chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
+ EXPECT_EQ(0U, native_list->size());
+#endif
+
+ // Make sure the iterator finds all 3 browsers on the ash desktop and
+ // doesn't trip over the empty native desktop list.
+ EXPECT_EQ(3U, CountAllBrowsers());
+}
+
+// Verify that the iterator still behaves if there are no browsers at all.
+TEST(BrowserIteratorTestWithNoTestWindow, NoBrowser) {
+ EXPECT_EQ(0U, CountAllBrowsers());
+}
diff --git a/chrome/browser/ui/tab_contents/tab_contents_iterator.cc b/chrome/browser/ui/tab_contents/tab_contents_iterator.cc
index e8b5034..bc03577 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_iterator.cc
+++ b/chrome/browser/ui/tab_contents/tab_contents_iterator.cc
@@ -11,68 +11,31 @@
TabContentsIterator::TabContentsIterator()
: web_view_index_(-1),
- cur_(NULL),
- desktop_browser_list_(chrome::BrowserListImpl::GetInstance(
- chrome::HOST_DESKTOP_TYPE_NATIVE)),
- ash_browser_list_(chrome::BrowserListImpl::GetInstance(
- chrome::HOST_DESKTOP_TYPE_ASH)),
- desktop_browser_iterator_(desktop_browser_list_->begin()),
- ash_browser_iterator_(ash_browser_list_->begin()) {
+ cur_(NULL) {
// Load the first WebContents into |cur_|.
Next();
}
-Browser* TabContentsIterator::browser() const {
- if (desktop_browser_iterator_ != desktop_browser_list_->end())
- return *desktop_browser_iterator_;
- // In some cases like Chrome OS the two browser lists are the same.
- if (desktop_browser_list_ != ash_browser_list_) {
- if (ash_browser_iterator_ != ash_browser_list_->end())
- return *ash_browser_iterator_;
- }
- return NULL;
-}
-
void TabContentsIterator::Next() {
// The current WebContents should be valid unless we are at the beginning.
- DCHECK(cur_ || (web_view_index_ == -1 &&
- desktop_browser_iterator_ == desktop_browser_list_->begin() &&
- ash_browser_iterator_ == ash_browser_list_->begin()))
- << "Trying to advance past the end";
-
- // First iterate over the Browser objects in the desktop environment and then
- // over those in the ASH environment.
- if (AdvanceBrowserIterator(&desktop_browser_iterator_,
- desktop_browser_list_))
- return;
-
- // In some cases like Chrome OS the two browser lists are the same.
- if (desktop_browser_list_ != ash_browser_list_)
- AdvanceBrowserIterator(&ash_browser_iterator_, ash_browser_list_);
-}
+ DCHECK(cur_ || web_view_index_ == -1) << "Trying to advance past the end";
-bool TabContentsIterator::AdvanceBrowserIterator(
- chrome::BrowserListImpl::const_iterator* list_iterator,
- chrome::BrowserListImpl* browser_list) {
- // Update cur_ to the next WebContents in the list.
- while (*list_iterator != browser_list->end()) {
- if (++web_view_index_ >=
- (**list_iterator)->tab_strip_model()->count()) {
+ // Update |cur_| to the next WebContents in the list.
+ while (!browser_iterator_.done()) {
+ if (++web_view_index_ >= browser_iterator_->tab_strip_model()->count()) {
// Advance to the next Browser in the list.
- ++(*list_iterator);
+ browser_iterator_.Next();
web_view_index_ = -1;
continue;
}
- content::WebContents* next_tab =
- (**list_iterator)->tab_strip_model()->GetWebContentsAt(
- web_view_index_);
+ content::WebContents* next_tab = browser_iterator_->tab_strip_model()
+ ->GetWebContentsAt(web_view_index_);
if (next_tab) {
cur_ = next_tab;
- return true;
+ return;
}
}
// Reached the end.
cur_ = NULL;
- return false;
}
diff --git a/chrome/browser/ui/tab_contents/tab_contents_iterator.h b/chrome/browser/ui/tab_contents/tab_contents_iterator.h
index 76ad9c2..818658f 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_iterator.h
+++ b/chrome/browser/ui/tab_contents/tab_contents_iterator.h
@@ -8,8 +8,7 @@
#include <set>
#include "base/basictypes.h"
-#include "chrome/browser/ui/browser_list_impl.h"
-#include "chrome/browser/ui/host_desktop.h"
+#include "chrome/browser/ui/browser_iterator.h"
namespace content {
class WebContents;
@@ -36,7 +35,11 @@ class TabContentsIterator {
// Returns the Browser instance associated with the current
// WebContents. Valid as long as !done().
- Browser* browser() const;
+ Browser* browser() const {
+ if (!browser_iterator_.done())
+ return *browser_iterator_;
+ return NULL;
+ }
// Returns the current WebContents, valid as long as !done().
content::WebContents* operator->() const {
@@ -52,13 +55,6 @@ class TabContentsIterator {
void Next();
private:
- // Helper function to iterate the BrowserList passed in.
- // Returns true if the iterator was successfully advanced.
- // TODO(gab): Remove this method when introducing BrowserIterator.
- bool AdvanceBrowserIterator(
- chrome::BrowserListImpl::const_iterator* list_iterator,
- chrome::BrowserListImpl* browser_list);
-
// Tab index into the current Browser of the current web view.
int web_view_index_;
@@ -67,17 +63,8 @@ class TabContentsIterator {
// cache this since the caller may access the current host many times.
content::WebContents* cur_;
- // The Desktop Browser list.
- chrome::BrowserListImpl* desktop_browser_list_;
-
- // The Ash Browser list.
- chrome::BrowserListImpl* ash_browser_list_;
-
- // Iterator over all the Browser objects in desktop mode.
- chrome::BrowserListImpl::const_iterator desktop_browser_iterator_;
-
- // Iterator over all the Browser objects in Ash mode.
- chrome::BrowserListImpl::const_iterator ash_browser_iterator_;
+ // An iterator over all the browsers.
+ chrome::BrowserIterator browser_iterator_;
DISALLOW_COPY_AND_ASSIGN(TabContentsIterator);
};
diff --git a/chrome/browser/ui/tab_contents/tab_contents_iterator_unittest.cc b/chrome/browser/ui/tab_contents/tab_contents_iterator_unittest.cc
index 616ed65..9f300bc 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_iterator_unittest.cc
+++ b/chrome/browser/ui/tab_contents/tab_contents_iterator_unittest.cc
@@ -8,7 +8,8 @@
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_commands.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_impl.h"
+#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/browser_with_test_window_test.h"
@@ -32,20 +33,33 @@ size_t CountAllTabs() {
TEST_F(BrowserListTest, TabContentsIteratorVerifyCount) {
// Make sure we have 1 window to start with.
- EXPECT_EQ(1U, BrowserList::size());
+ EXPECT_EQ(1U, chrome::BrowserListImpl::GetInstance(
+ chrome::HOST_DESKTOP_TYPE_NATIVE)->size());
EXPECT_EQ(0U, CountAllTabs());
// Create more browsers/windows.
scoped_ptr<Browser> browser2(
chrome::CreateBrowserWithTestWindowForProfile(profile()));
+ // Create browser 3 and 4 on the Ash desktop (the TabContentsIterator
+ // shouldn't see the difference).
+ Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
scoped_ptr<Browser> browser3(
- chrome::CreateBrowserWithTestWindowForProfile(profile()));
+ chrome::CreateBrowserWithTestWindowForParams(&ash_params));
scoped_ptr<Browser> browser4(
- chrome::CreateBrowserWithTestWindowForProfile(profile()));
+ chrome::CreateBrowserWithTestWindowForParams(&ash_params));
// Sanity checks.
- EXPECT_EQ(4U, BrowserList::size());
+#if defined(OS_CHROMEOS)
+ // The ash desktop is the native desktop on Chrome OS.
+ EXPECT_EQ(4U, chrome::BrowserListImpl::GetInstance(
+ chrome::HOST_DESKTOP_TYPE_NATIVE)->size());
+#else
+ EXPECT_EQ(2U, chrome::BrowserListImpl::GetInstance(
+ chrome::HOST_DESKTOP_TYPE_NATIVE)->size());
+ EXPECT_EQ(2U, chrome::BrowserListImpl::GetInstance(
+ chrome::HOST_DESKTOP_TYPE_ASH)->size());
+#endif
EXPECT_EQ(0, browser()->tab_strip_model()->count());
EXPECT_EQ(0, browser2->tab_strip_model()->count());
EXPECT_EQ(0, browser3->tab_strip_model()->count());
@@ -76,16 +90,29 @@ TEST_F(BrowserListTest, TabContentsIteratorVerifyCount) {
TEST_F(BrowserListTest, TabContentsIteratorVerifyBrowser) {
// Make sure we have 1 window to start with.
- EXPECT_EQ(1U, BrowserList::size());
+ EXPECT_EQ(1U, chrome::BrowserListImpl::GetInstance(
+ chrome::HOST_DESKTOP_TYPE_NATIVE)->size());
// Create more browsers/windows.
scoped_ptr<Browser> browser2(
chrome::CreateBrowserWithTestWindowForProfile(profile()));
+ // Create browser 3 on the Ash desktop (the TabContentsIterator shouldn't see
+ // the difference).
+ Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
scoped_ptr<Browser> browser3(
- chrome::CreateBrowserWithTestWindowForProfile(profile()));
+ chrome::CreateBrowserWithTestWindowForParams(&ash_params));
// Sanity checks.
- EXPECT_EQ(3U, BrowserList::size());
+#if defined(OS_CHROMEOS)
+ // The ash desktop is the native desktop on Chrome OS.
+ EXPECT_EQ(3U, chrome::BrowserListImpl::GetInstance(
+ chrome::HOST_DESKTOP_TYPE_NATIVE)->size());
+#else
+ EXPECT_EQ(2U, chrome::BrowserListImpl::GetInstance(
+ chrome::HOST_DESKTOP_TYPE_NATIVE)->size());
+ EXPECT_EQ(1U, chrome::BrowserListImpl::GetInstance(
+ chrome::HOST_DESKTOP_TYPE_ASH)->size());
+#endif
EXPECT_EQ(0, browser()->tab_strip_model()->count());
EXPECT_EQ(0, browser2->tab_strip_model()->count());
EXPECT_EQ(0, browser3->tab_strip_model()->count());
@@ -95,21 +122,23 @@ TEST_F(BrowserListTest, TabContentsIteratorVerifyBrowser) {
// Add some tabs.
for (size_t i = 0; i < 3; ++i)
chrome::NewTab(browser2.get());
- chrome::NewTab(browser3.get());
+ for (size_t i = 0; i < 2; ++i)
+ chrome::NewTab(browser3.get());
size_t count = 0;
for (TabContentsIterator iterator; !iterator.done(); iterator.Next(),
++count) {
if (count < 3)
EXPECT_EQ(browser2.get(), iterator.browser());
- else if (count == 3)
+ else if (count < 5)
EXPECT_EQ(browser3.get(), iterator.browser());
else
- EXPECT_TRUE(false);
+ ADD_FAILURE();
}
// Close some tabs.
browser2->tab_strip_model()->CloseAllTabs();
+ browser3->tab_strip_model()->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE);
count = 0;
for (TabContentsIterator iterator; !iterator.done(); iterator.Next(),
@@ -117,7 +146,7 @@ TEST_F(BrowserListTest, TabContentsIteratorVerifyBrowser) {
if (count == 0)
EXPECT_EQ(browser3.get(), iterator.browser());
else
- EXPECT_TRUE(false);
+ ADD_FAILURE();
}
// Now make it one tab per browser.
@@ -134,7 +163,7 @@ TEST_F(BrowserListTest, TabContentsIteratorVerifyBrowser) {
else if (count == 2)
EXPECT_EQ(browser3.get(), iterator.browser());
else
- EXPECT_TRUE(false);
+ ADD_FAILURE();
}
// Close all remaining tabs to keep all the destructors happy.
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index ba3fcbf..e093f62 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -256,6 +256,8 @@
'browser/ui/browser_finder.h',
'browser/ui/browser_instant_controller.cc',
'browser/ui/browser_instant_controller.h',
+ 'browser/ui/browser_iterator.cc',
+ 'browser/ui/browser_iterator.h',
'browser/ui/browser_list.cc',
'browser/ui/browser_list.h',
'browser/ui/browser_list_impl.cc',
@@ -2536,6 +2538,7 @@
'browser/ui/browser.cc',
'browser/ui/browser_command_controller.cc',
'browser/ui/browser_finder.cc',
+ 'browser/ui/browser_iterator.cc',
'browser/ui/browser_list.cc',
'browser/ui/browser_navigator.cc',
'browser/ui/browser_otr_state.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 4fa074c..d6b96b6 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1180,6 +1180,7 @@
'browser/ui/bookmarks/bookmark_prompt_controller_unittest.cc',
'browser/ui/bookmarks/bookmark_ui_utils_unittest.cc',
'browser/ui/browser_command_controller_unittest.cc',
+ 'browser/ui/browser_iterator_unittest.cc',
'browser/ui/chrome_select_file_policy_unittest.cc',
# It is safe to list */cocoa/* files in the "common" file list
# without an explicit exclusion since gyp is smart enough to
@@ -2126,6 +2127,7 @@
'browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc',
'browser/ui/bookmarks/bookmark_prompt_controller_unittest.cc',
'browser/ui/browser_command_controller_unittest.cc',
+ 'browser/ui/browser_iterator_unittest.cc',
'browser/ui/fullscreen/fullscreen_controller_state_unittest.cc',
'browser/ui/fullscreen/fullscreen_controller_unittest.cc',
'browser/ui/search/search_delegate_unittest.cc',
diff --git a/chrome/test/base/browser_with_test_window_test.cc b/chrome/test/base/browser_with_test_window_test.cc
index 6e34bd22..9169439 100644
--- a/chrome/test/base/browser_with_test_window_test.cc
+++ b/chrome/test/base/browser_with_test_window_test.cc
@@ -32,7 +32,19 @@ BrowserWithTestWindowTest::BrowserWithTestWindowTest()
db_thread_(BrowserThread::DB),
file_thread_(BrowserThread::FILE, message_loop()),
file_user_blocking_thread_(
- BrowserThread::FILE_USER_BLOCKING, message_loop()) {
+ BrowserThread::FILE_USER_BLOCKING, message_loop()),
+ host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE) {
+ db_thread_.Start();
+}
+
+BrowserWithTestWindowTest::BrowserWithTestWindowTest(
+ chrome::HostDesktopType host_desktop_type)
+ : ui_thread_(BrowserThread::UI, message_loop()),
+ db_thread_(BrowserThread::DB),
+ file_thread_(BrowserThread::FILE, message_loop()),
+ file_user_blocking_thread_(
+ BrowserThread::FILE_USER_BLOCKING, message_loop()),
+ host_desktop_type_(host_desktop_type) {
db_thread_.Start();
}
@@ -45,7 +57,7 @@ void BrowserWithTestWindowTest::SetUp() {
if (!window_.get())
window_.reset(new TestBrowserWindow);
- Browser::CreateParams params(profile());
+ Browser::CreateParams params(profile(), host_desktop_type_);
params.window = window_.get();
browser_.reset(new Browser(params));
#if defined(USE_AURA)
diff --git a/chrome/test/base/browser_with_test_window_test.h b/chrome/test/base/browser_with_test_window_test.h
index 76d7b4c..e23c920 100644
--- a/chrome/test/base/browser_with_test_window_test.h
+++ b/chrome/test/base/browser_with_test_window_test.h
@@ -8,6 +8,7 @@
#include "base/at_exit.h"
#include "base/message_loop.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/host_desktop.h"
#include "chrome/test/base/test_browser_window.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread.h"
@@ -57,7 +58,14 @@ class WebContents;
// for creating the various objects of this class.
class BrowserWithTestWindowTest : public testing::Test {
public:
+ // Creates a BrowserWithTestWindowTest for which the initial window will be
+ // created on the native desktop.
BrowserWithTestWindowTest();
+
+ // Creates a BrowserWithTestWindowTest for which the initial window will be
+ // created on the desktop of type |host_desktop_type|.
+ explicit BrowserWithTestWindowTest(chrome::HostDesktopType host_desktop_type);
+
virtual ~BrowserWithTestWindowTest();
virtual void SetUp() OVERRIDE;
@@ -136,6 +144,9 @@ class BrowserWithTestWindowTest : public testing::Test {
ui::ScopedOleInitializer ole_initializer_;
#endif
+ // The desktop to create the initial window on.
+ chrome::HostDesktopType host_desktop_type_;
+
DISALLOW_COPY_AND_ASSIGN(BrowserWithTestWindowTest);
};