OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
9 #include "chrome/browser/browser_window.h" | 9 #include "chrome/browser/browser_window.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
11 #include "chrome/browser/sidebar/sidebar_manager.h" | 11 #include "chrome/browser/sidebar/sidebar_manager.h" |
12 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
14 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
18 #include "chrome/test/in_process_browser_test.h" | 19 #include "chrome/test/in_process_browser_test.h" |
19 #include "chrome/test/ui_test_utils.h" | 20 #include "chrome/test/ui_test_utils.h" |
20 #include "net/test/test_server.h" | 21 #include "net/test/test_server.h" |
21 | 22 |
22 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
(...skipping 19 matching lines...) Expand all Loading... |
43 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extension_path)); | 44 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extension_path)); |
44 extension_path = extension_path.AppendASCII("sidebar"); | 45 extension_path = extension_path.AppendASCII("sidebar"); |
45 | 46 |
46 ASSERT_TRUE(LoadExtension(extension_path)); | 47 ASSERT_TRUE(LoadExtension(extension_path)); |
47 | 48 |
48 // For now content_id == extension_id. | 49 // For now content_id == extension_id. |
49 content_id_ = last_loaded_extension_id_; | 50 content_id_ = last_loaded_extension_id_; |
50 } | 51 } |
51 | 52 |
52 void ShowSidebarForCurrentTab() { | 53 void ShowSidebarForCurrentTab() { |
53 ShowSidebar(browser()->GetSelectedTabContents()); | 54 ShowSidebar(browser()->GetSelectedTabContentsWrapper()); |
54 } | 55 } |
55 | 56 |
56 void ExpandSidebarForCurrentTab() { | 57 void ExpandSidebarForCurrentTab() { |
57 ExpandSidebar(browser()->GetSelectedTabContents()); | 58 ExpandSidebar(browser()->GetSelectedTabContentsWrapper()); |
58 } | 59 } |
59 | 60 |
60 void CollapseSidebarForCurrentTab() { | 61 void CollapseSidebarForCurrentTab() { |
61 CollapseSidebar(browser()->GetSelectedTabContents()); | 62 CollapseSidebar(browser()->GetSelectedTabContentsWrapper()); |
62 } | 63 } |
63 | 64 |
64 void HideSidebarForCurrentTab() { | 65 void HideSidebarForCurrentTab() { |
65 HideSidebar(browser()->GetSelectedTabContents()); | 66 HideSidebar(browser()->GetSelectedTabContentsWrapper()); |
66 } | 67 } |
67 | 68 |
68 void NavigateSidebarForCurrentTabTo(const std::string& test_page) { | 69 void NavigateSidebarForCurrentTabTo(const std::string& test_page) { |
69 GURL url = test_server()->GetURL(test_page); | 70 GURL url = test_server()->GetURL(test_page); |
70 | 71 |
71 TabContents* tab = browser()->GetSelectedTabContents(); | 72 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
72 | 73 |
73 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | 74 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); |
74 | 75 |
75 sidebar_manager->NavigateSidebar(tab, content_id_, url); | 76 sidebar_manager->NavigateSidebar(tab, content_id_, url); |
76 | 77 |
77 SidebarContainer* sidebar_container = | 78 SidebarContainer* sidebar_container = |
78 sidebar_manager->GetSidebarContainerFor(tab, content_id_); | 79 sidebar_manager->GetSidebarContainerFor(tab, content_id_); |
79 | 80 |
80 TabContents* client_contents = sidebar_container->sidebar_contents(); | 81 TabContents* client_contents = sidebar_container->sidebar_contents(); |
81 ui_test_utils::WaitForNavigation(&client_contents->controller()); | 82 ui_test_utils::WaitForNavigation(&client_contents->controller()); |
82 } | 83 } |
83 | 84 |
84 void ShowSidebar(TabContents* tab) { | 85 void ShowSidebar(TabContentsWrapper* tab) { |
85 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | 86 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); |
86 sidebar_manager->ShowSidebar(tab, content_id_); | 87 sidebar_manager->ShowSidebar(tab, content_id_); |
87 } | 88 } |
88 | 89 |
89 void ExpandSidebar(TabContents* tab) { | 90 void ExpandSidebar(TabContentsWrapper* tab) { |
90 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | 91 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); |
91 sidebar_manager->ExpandSidebar(tab, content_id_); | 92 sidebar_manager->ExpandSidebar(tab, content_id_); |
92 if (browser()->GetSelectedTabContents() == tab) | 93 if (browser()->GetSelectedTabContentsWrapper() == tab) |
93 EXPECT_GT(browser_view()->GetSidebarWidth(), 0); | 94 EXPECT_GT(browser_view()->GetSidebarWidth(), 0); |
94 } | 95 } |
95 | 96 |
96 void CollapseSidebar(TabContents* tab) { | 97 void CollapseSidebar(TabContentsWrapper* tab) { |
97 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | 98 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); |
98 sidebar_manager->CollapseSidebar(tab, content_id_); | 99 sidebar_manager->CollapseSidebar(tab, content_id_); |
99 if (browser()->GetSelectedTabContents() == tab) | 100 if (browser()->GetSelectedTabContentsWrapper() == tab) |
100 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); | 101 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); |
101 } | 102 } |
102 | 103 |
103 void HideSidebar(TabContents* tab) { | 104 void HideSidebar(TabContentsWrapper* tab) { |
104 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | 105 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); |
105 sidebar_manager->HideSidebar(tab, content_id_); | 106 sidebar_manager->HideSidebar(tab, content_id_); |
106 if (browser()->GetSelectedTabContents() == tab) | 107 if (browser()->GetSelectedTabContentsWrapper() == tab) |
107 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); | 108 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); |
108 } | 109 } |
109 | 110 |
110 TabContents* tab_contents(int i) { | 111 TabContentsWrapper* tab(int i) { |
111 return browser()->GetTabContentsAt(i); | 112 return browser()->GetTabContentsWrapperAt(i); |
112 } | 113 } |
113 | 114 |
114 BrowserView* browser_view() const { | 115 BrowserView* browser_view() const { |
115 return static_cast<BrowserView*>(browser()->window()); | 116 return static_cast<BrowserView*>(browser()->window()); |
116 } | 117 } |
117 | 118 |
118 private: | 119 private: |
119 std::string content_id_; | 120 std::string content_id_; |
120 }; | 121 }; |
121 | 122 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 HideSidebarForCurrentTab(); | 160 HideSidebarForCurrentTab(); |
160 } | 161 } |
161 | 162 |
162 IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarOnInactiveTab) { | 163 IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarOnInactiveTab) { |
163 ShowSidebarForCurrentTab(); | 164 ShowSidebarForCurrentTab(); |
164 ExpandSidebarForCurrentTab(); | 165 ExpandSidebarForCurrentTab(); |
165 | 166 |
166 browser()->NewTab(); | 167 browser()->NewTab(); |
167 | 168 |
168 // Hide sidebar on inactive (first) tab. | 169 // Hide sidebar on inactive (first) tab. |
169 HideSidebar(tab_contents(0)); | 170 HideSidebar(tab(0)); |
170 | 171 |
171 // Switch back to the first tab. | 172 // Switch back to the first tab. |
172 browser()->SelectNumberedTab(0); | 173 browser()->SelectNumberedTab(0); |
173 | 174 |
174 // Make sure sidebar is not visbile anymore. | 175 // Make sure sidebar is not visbile anymore. |
175 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); | 176 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); |
176 | 177 |
177 // Show sidebar on inactive (second) tab. | 178 // Show sidebar on inactive (second) tab. |
178 ShowSidebar(tab_contents(1)); | 179 ShowSidebar(tab(1)); |
179 ExpandSidebar(tab_contents(1)); | 180 ExpandSidebar(tab(1)); |
180 // Make sure sidebar is not visible yet. | 181 // Make sure sidebar is not visible yet. |
181 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); | 182 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); |
182 | 183 |
183 // Switch back to the second tab. | 184 // Switch back to the second tab. |
184 browser()->SelectNumberedTab(1); | 185 browser()->SelectNumberedTab(1); |
185 // Make sure sidebar is visible now. | 186 // Make sure sidebar is visible now. |
186 EXPECT_GT(browser_view()->GetSidebarWidth(), 0); | 187 EXPECT_GT(browser_view()->GetSidebarWidth(), 0); |
187 | 188 |
188 HideSidebarForCurrentTab(); | 189 HideSidebarForCurrentTab(); |
189 } | 190 } |
190 | 191 |
191 IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarNavigate) { | 192 IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarNavigate) { |
192 ASSERT_TRUE(test_server()->Start()); | 193 ASSERT_TRUE(test_server()->Start()); |
193 | 194 |
194 ShowSidebarForCurrentTab(); | 195 ShowSidebarForCurrentTab(); |
195 | 196 |
196 NavigateSidebarForCurrentTabTo(kSimplePage); | 197 NavigateSidebarForCurrentTabTo(kSimplePage); |
197 | 198 |
198 HideSidebarForCurrentTab(); | 199 HideSidebarForCurrentTab(); |
199 } | 200 } |
200 | 201 |
201 } // namespace | 202 } // namespace |
202 | 203 |
OLD | NEW |