OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/ui/browser_iterator.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include "build/build_config.h" | |
10 #include "chrome/browser/ui/browser.h" | |
11 #include "chrome/browser/ui/browser_list.h" | |
12 #include "chrome/browser/ui/host_desktop.h" | |
13 #include "chrome/test/base/browser_with_test_window_test.h" | |
14 | |
15 typedef BrowserWithTestWindowTest BrowserIteratorTest; | |
16 | |
17 namespace { | |
18 | |
19 // BrowserWithTestWindowTest's default window is on the native desktop by | |
20 // default. Force it to be on the Ash desktop to be able to test the iterator | |
21 // in a situation with no browsers on the native desktop. | |
22 class BrowserIteratorTestWithInitialWindowInAsh | |
23 : public BrowserWithTestWindowTest { | |
24 public: | |
25 BrowserIteratorTestWithInitialWindowInAsh() | |
26 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, | |
27 chrome::HOST_DESKTOP_TYPE_ASH, | |
28 false) { | |
29 } | |
30 }; | |
31 | |
32 // Helper function to iterate and count all the browsers. | |
33 size_t CountAllBrowsers() { | |
34 size_t count = 0; | |
35 for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) | |
36 ++count; | |
37 return count; | |
38 } | |
39 | |
40 } | |
41 | |
42 TEST_F(BrowserIteratorTest, BrowsersOnMultipleDesktops) { | |
43 Browser::CreateParams native_params(profile(), | |
44 chrome::HOST_DESKTOP_TYPE_NATIVE); | |
45 Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH); | |
46 // Note, browser 1 is on the native desktop. | |
47 scoped_ptr<Browser> browser2( | |
48 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | |
49 scoped_ptr<Browser> browser3( | |
50 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | |
51 scoped_ptr<Browser> browser4( | |
52 chrome::CreateBrowserWithTestWindowForParams(&ash_params)); | |
53 scoped_ptr<Browser> browser5( | |
54 chrome::CreateBrowserWithTestWindowForParams(&ash_params)); | |
55 | |
56 // Sanity checks. | |
57 BrowserList* native_list = | |
58 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE); | |
59 #if defined(OS_CHROMEOS) | |
60 // On Chrome OS, the native list and the ash list are the same. | |
61 EXPECT_EQ(5U, native_list->size()); | |
62 #else | |
63 BrowserList* ash_list = | |
64 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | |
65 EXPECT_EQ(3U, native_list->size()); | |
66 EXPECT_EQ(2U, ash_list->size()); | |
67 #endif | |
68 | |
69 // Make sure the iterator finds all 5 browsers regardless of which desktop | |
70 // they are on. | |
71 EXPECT_EQ(5U, CountAllBrowsers()); | |
72 } | |
73 | |
74 TEST_F(BrowserIteratorTest, NoBrowsersOnAshDesktop) { | |
75 Browser::CreateParams native_params(profile(), | |
76 chrome::HOST_DESKTOP_TYPE_NATIVE); | |
77 // Note, browser 1 is on the native desktop. | |
78 scoped_ptr<Browser> browser2( | |
79 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | |
80 scoped_ptr<Browser> browser3( | |
81 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | |
82 | |
83 // Sanity checks. | |
84 BrowserList* native_list = | |
85 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE); | |
86 EXPECT_EQ(3U, native_list->size()); | |
87 #if !defined(OS_CHROMEOS) | |
88 // On non-Chrome OS platforms the Ash list is independent from the native | |
89 // list, double-check that it's empty. | |
90 BrowserList* ash_list = | |
91 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | |
92 EXPECT_EQ(0U, ash_list->size()); | |
93 #endif | |
94 | |
95 // Make sure the iterator finds all 3 browsers on the native desktop and | |
96 // doesn't trip over the empty Ash desktop list. | |
97 EXPECT_EQ(3U, CountAllBrowsers()); | |
98 } | |
99 | |
100 TEST_F(BrowserIteratorTestWithInitialWindowInAsh, NoBrowsersOnNativeDesktop) { | |
101 Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH); | |
102 // Note, browser 1 is on the ash desktop. | |
103 scoped_ptr<Browser> browser2( | |
104 chrome::CreateBrowserWithTestWindowForParams(&ash_params)); | |
105 scoped_ptr<Browser> browser3( | |
106 chrome::CreateBrowserWithTestWindowForParams(&ash_params)); | |
107 | |
108 BrowserList* ash_list = | |
109 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | |
110 EXPECT_EQ(3U, ash_list->size()); | |
111 #if !defined(OS_CHROMEOS) | |
112 // On non-Chrome OS platforms the native list is independent from the Ash | |
113 // list; double-check that it's empty. | |
114 BrowserList* native_list = | |
115 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE); | |
116 EXPECT_EQ(0U, native_list->size()); | |
117 #endif | |
118 | |
119 // Make sure the iterator finds all 3 browsers on the ash desktop and | |
120 // doesn't trip over the empty native desktop list. | |
121 EXPECT_EQ(3U, CountAllBrowsers()); | |
122 } | |
123 | |
124 // Verify that the iterator still behaves if there are no browsers at all. | |
125 TEST(BrowserIteratorTestWithNoTestWindow, NoBrowser) { | |
126 EXPECT_EQ(0U, CountAllBrowsers()); | |
127 } | |
OLD | NEW |