Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / browser_iterator_unittest.cc
blob61a64174f099d785344eb4e1c7f2337ab0ee4b42
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/browser_iterator.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_list.h"
9 #include "chrome/browser/ui/host_desktop.h"
10 #include "chrome/test/base/browser_with_test_window_test.h"
12 typedef BrowserWithTestWindowTest BrowserIteratorTest;
14 namespace {
16 // BrowserWithTestWindowTest's default window is on the native desktop by
17 // default. Force it to be on the Ash desktop to be able to test the iterator
18 // in a situation with no browsers on the native desktop.
19 class BrowserIteratorTestWithInitialWindowInAsh
20 : public BrowserWithTestWindowTest {
21 public:
22 BrowserIteratorTestWithInitialWindowInAsh()
23 : BrowserWithTestWindowTest(Browser::TYPE_TABBED,
24 chrome::HOST_DESKTOP_TYPE_ASH,
25 false) {
29 // Helper function to iterate and count all the browsers.
30 size_t CountAllBrowsers() {
31 size_t count = 0;
32 for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next())
33 ++count;
34 return count;
39 TEST_F(BrowserIteratorTest, BrowsersOnMultipleDesktops) {
40 Browser::CreateParams native_params(profile(),
41 chrome::HOST_DESKTOP_TYPE_NATIVE);
42 Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
43 // Note, browser 1 is on the native desktop.
44 scoped_ptr<Browser> browser2(
45 chrome::CreateBrowserWithTestWindowForParams(&native_params));
46 scoped_ptr<Browser> browser3(
47 chrome::CreateBrowserWithTestWindowForParams(&native_params));
48 scoped_ptr<Browser> browser4(
49 chrome::CreateBrowserWithTestWindowForParams(&ash_params));
50 scoped_ptr<Browser> browser5(
51 chrome::CreateBrowserWithTestWindowForParams(&ash_params));
53 // Sanity checks.
54 BrowserList* native_list =
55 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
56 #if defined(OS_CHROMEOS)
57 // On Chrome OS, the native list and the ash list are the same.
58 EXPECT_EQ(5U, native_list->size());
59 #else
60 BrowserList* ash_list =
61 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
62 EXPECT_EQ(3U, native_list->size());
63 EXPECT_EQ(2U, ash_list->size());
64 #endif
66 // Make sure the iterator finds all 5 browsers regardless of which desktop
67 // they are on.
68 EXPECT_EQ(5U, CountAllBrowsers());
71 TEST_F(BrowserIteratorTest, NoBrowsersOnAshDesktop) {
72 Browser::CreateParams native_params(profile(),
73 chrome::HOST_DESKTOP_TYPE_NATIVE);
74 // Note, browser 1 is on the native desktop.
75 scoped_ptr<Browser> browser2(
76 chrome::CreateBrowserWithTestWindowForParams(&native_params));
77 scoped_ptr<Browser> browser3(
78 chrome::CreateBrowserWithTestWindowForParams(&native_params));
80 // Sanity checks.
81 BrowserList* native_list =
82 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
83 EXPECT_EQ(3U, native_list->size());
84 #if !defined(OS_CHROMEOS)
85 // On non-Chrome OS platforms the Ash list is independent from the native
86 // list, double-check that it's empty.
87 BrowserList* ash_list =
88 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
89 EXPECT_EQ(0U, ash_list->size());
90 #endif
92 // Make sure the iterator finds all 3 browsers on the native desktop and
93 // doesn't trip over the empty Ash desktop list.
94 EXPECT_EQ(3U, CountAllBrowsers());
97 TEST_F(BrowserIteratorTestWithInitialWindowInAsh, NoBrowsersOnNativeDesktop) {
98 Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
99 // Note, browser 1 is on the ash desktop.
100 scoped_ptr<Browser> browser2(
101 chrome::CreateBrowserWithTestWindowForParams(&ash_params));
102 scoped_ptr<Browser> browser3(
103 chrome::CreateBrowserWithTestWindowForParams(&ash_params));
105 BrowserList* ash_list =
106 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
107 EXPECT_EQ(3U, ash_list->size());
108 #if !defined(OS_CHROMEOS)
109 // On non-Chrome OS platforms the native list is independent from the Ash
110 // list; double-check that it's empty.
111 BrowserList* native_list =
112 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
113 EXPECT_EQ(0U, native_list->size());
114 #endif
116 // Make sure the iterator finds all 3 browsers on the ash desktop and
117 // doesn't trip over the empty native desktop list.
118 EXPECT_EQ(3U, CountAllBrowsers());
121 // Verify that the iterator still behaves if there are no browsers at all.
122 TEST(BrowserIteratorTestWithNoTestWindow, NoBrowser) {
123 EXPECT_EQ(0U, CountAllBrowsers());